@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Montserrat:wght@600;700&display=swap");

:root {
  --bg: #f0f2ef;
  --surface: #fff;
  --primary: #1b3022;
  --primary-soft: #2d4a38;
  --accent: #c4a962;
  --muted: #5a5a52;
  --border: #d9d4cc;
  --danger: #b54a4a;
  --radius: 10px;
  --sidebar-w: 240px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", system-ui, sans-serif;
  font-size: 14px;
  color: #2c2c2c;
  background: var(--bg);
}

h1,
h2,
h3 {
  font-family: "Montserrat", sans-serif;
  color: var(--primary);
}

a {
  color: var(--primary-soft);
}

/* Экраны: логин / приложение */
#login-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#login-screen.is-visible {
  display: flex;
}

#app-shell {
  display: none;
  min-height: 100vh;
}

#app-shell.is-visible {
  display: flex !important;
}

/* Login */
.login-wrap {
  width: 100%;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(27, 48, 34, 0.12);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 24px;
  color: var(--muted);
}

/* Layout */
.app-shell {
  width: 100%;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}

.sidebar__brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 12px;
}

.sidebar__brand strong {
  display: block;
  font-family: "Montserrat", sans-serif;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.sidebar__brand span {
  font-size: 11px;
  opacity: 0.75;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.85);
  text-align: left;
  padding: 12px 20px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.nav-btn:hover,
.nav-btn--active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar__logout {
  margin: 12px 16px 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius);
  background: none;
  color: #fff;
  font: inherit;
  cursor: pointer;
}

.main {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 24px 28px 40px;
  overflow-x: auto;
  max-width: 1200px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.page-head h1 {
  margin: 0;
  font-size: 24px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* Forms */
input,
select,
textarea {
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  width: 100%;
  max-width: 100%;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.field {
  margin-bottom: 12px;
}

.field--inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field--inline input[type="checkbox"] {
  width: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--secondary {
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--border);
}

.btn--danger {
  background: #fce8e8;
  color: var(--danger);
}

.btn--sm {
  padding: 4px 10px;
  font-size: 12px;
}

.table-actions {
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Table */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(27, 48, 34, 0.06);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #fafaf8;
}

tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge--active {
  background: #e8f0eb;
  color: var(--primary);
}

.badge--inactive {
  background: #f5ebe0;
  color: #9a6b2f;
}

.badge--expired {
  background: #fce8e8;
  color: var(--danger);
}

.badge--blocked {
  background: #2a2a2a;
  color: #f5f5f0;
}

/* Cards grid stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(27, 48, 34, 0.06);
}

.stat-card__value {
  font-family: "Montserrat", sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 4px;
}

.stat-card__label {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .panel-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(27, 48, 34, 0.06);
}

.card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.field-label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
}

.file-picker {
  display: inline-block;
  margin: 4px 0 8px;
  cursor: pointer;
}

.file-picker input[type="file"] {
  position: absolute;
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.file-picker__btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px dashed var(--primary);
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
}

.file-picker:hover .file-picker__btn {
  background: #e8f0eb;
}

.field-details {
  margin-top: 10px;
}

.field-details summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.field-details input {
  width: 100%;
}

.image-preview {
  margin: 10px 0;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.image-preview img {
  display: block;
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 6px;
}

.image-preview__caption {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal--wide {
  max-width: 720px;
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.modal__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.options-editor .option-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
}

.page {
  display: none;
}

.page--active {
  display: block;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }

  .sidebar__brand {
    width: 100%;
    border: none;
    padding-bottom: 8px;
  }

  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }

  .nav-btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  .sidebar__logout {
    width: 100%;
  }

  .main {
    padding: 16px;
  }
}

.ref-preview-box {
  margin: 16px 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f7f7f5;
}

.ref-preview-box__label {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.ref-preview-box__cmd {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  background: #1b3022;
  color: #d4bc6a;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-all;
  text-decoration: none;
}

.ref-preview-box__cmd:hover {
  color: #f0e2b8;
  text-decoration: underline;
}

.ref-preview-box__warn {
  margin: 8px 0 0;
  font-size: 12px;
  color: #9a6b00;
}

.ref-preview-box__note {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.checkbox-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

label.checkbox-list__item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

label.checkbox-list__item:hover {
  border-color: #b8b8b0;
}

label.checkbox-list__item:has(input:checked) {
  border-color: #1b3022;
  background: #f3f6f4;
}

label.checkbox-list__item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  accent-color: #1b3022;
}

.checkbox-list__text {
  flex: 1;
  min-width: 0;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.crm-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.crm-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  padding: 8px 16px;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.crm-tab:hover,
.crm-tab--active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.crm-panels {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.crm-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.crm-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.crm-list li:last-child {
  border-bottom: none;
}

.crm-list__val {
  margin-left: auto;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.crm-profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 640px) {
  .crm-profile-grid {
    grid-template-columns: 1fr;
  }
}

.modal--wide {
  max-width: 860px;
}

.stat-card--accent {
  border-left: 4px solid var(--primary);
}

.stat-card--gold {
  border-left: 4px solid var(--accent);
}

.stat-card--accent .stat-card__value .muted,
.stat-card__value .muted {
  font-size: 16px;
  font-weight: 500;
  color: var(--muted);
}

.ref-crm-kpis .stat-card {
  min-height: 96px;
}

.ref-crm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.ref-crm-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 2px 14px rgba(27, 48, 34, 0.08);
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ref-crm-card--inactive {
  opacity: 0.72;
  border-color: var(--border);
}

.ref-crm-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.ref-crm-card__head h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.ref-crm-card__payout {
  background: #f5f0e4;
  color: #7a5c1a;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.ref-crm-card__metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ref-crm-card__metrics strong {
  display: block;
  font-size: 15px;
  color: var(--primary);
}

.ref-crm-card__subjects {
  margin: 0;
  line-height: 1.4;
}

.ref-crm-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.ref-funnel__steps {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ref-funnel__step {
  display: flex;
  flex-direction: column;
  min-width: 72px;
}

.ref-funnel__step--accent .ref-funnel__num {
  color: var(--accent);
}

.ref-funnel__num {
  font-family: "Montserrat", sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.ref-funnel__lbl {
  font-size: 11px;
  color: var(--muted);
}

.ref-funnel__arrow {
  color: var(--muted);
  font-size: 18px;
  padding: 0 2px;
}

.ref-funnel__bar {
  height: 6px;
  background: #eceae4;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.ref-funnel__bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-soft), var(--accent));
  border-radius: 999px;
  min-width: 4px;
}

.ref-crm-detail-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.ref-crm-detail-kpis strong {
  display: block;
  font-size: 18px;
  color: var(--primary);
}

.ref-crm-teaser {
  background: linear-gradient(135deg, #f8faf7 0%, #f5f0e6 100%);
  border: 1px solid #e5dfd0;
}

.ref-crm-teaser__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.ref-crm-teaser__head h3 {
  margin: 0;
}

.ref-crm-teaser__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  font-size: 14px;
}

.ref-crm-teaser__stats strong {
  color: var(--primary);
  font-size: 18px;
  margin-right: 4px;
}

.ref-tag {
  display: inline-block;
  background: #eef4ef;
  color: var(--primary-soft);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
