/* Линия CRM — dark "чертёжная доска" theme.
   Palette (from design brief): bg_page #15171a, bg_card #1e2126,
   text_primary #f0ece4, text_muted #b7aea1, accent #8fbdaf, brand #c6a36a. */

:root {
  --bg-page: #15171a;
  --bg-card: #1e2126;
  --bg-card-2: #262a30;
  --line: #34383f;
  --line-soft: #2a2e34;
  --text-primary: #f0ece4;
  --text-muted: #b7aea1;
  --accent: #8fbdaf;
  --accent-ink: #12231e;
  --brand: #c6a36a;
  --brand-soft: #3a2f20;
  --danger: #e08a7a;
  --radius: 0.7rem;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", "Nimbus Roman", serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 0.4rem;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.4rem; }

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}
.container-narrow { max-width: 760px; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.5rem; color: var(--text-primary); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 2rem; height: 2rem; border-radius: 0.35rem;
  background: var(--brand); color: #1a140b;
  display: grid; place-items: center; font-weight: 800;
}
.brand-name { font-family: var(--font-display); font-size: 1.3rem; letter-spacing: 0.02em; }

.topnav { display: flex; align-items: center; gap: 0.25rem; flex: 1; flex-wrap: wrap; }
.topnav a {
  color: var(--text-muted); padding: 0.45rem 0.8rem; border-radius: 0.4rem;
  font-weight: 500;
}
.topnav a:hover { color: var(--text-primary); background: var(--bg-card-2); text-decoration: none; }
.topnav a.active { color: var(--brand); background: var(--brand-soft); }
.topnav a.nav-cta {
  color: var(--accent-ink); background: var(--accent); font-weight: 700;
}
.topnav a.nav-cta:hover { background: #a3d0c2; }

.user-box { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.user-name { color: var(--text-muted); font-size: 0.9rem; white-space: nowrap; }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; padding: 0.25rem 0; text-decoration: underline;
}
.link-btn:hover { color: var(--text-primary); }

/* Page header */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-sub { color: var(--text-muted); margin: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.55rem 1.1rem; border-radius: 0.5rem;
  border: 1px solid transparent; font: inherit; font-weight: 600;
  cursor: pointer; transition: background 0.15s ease, color 0.15s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #a3d0c2; text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text-primary); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-card-2); text-decoration: none; }
.btn-block { width: 100%; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.card-title { color: var(--text-primary); margin-bottom: 1rem; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-label { color: var(--text-muted); font-size: 0.85rem; font-weight: 600; }
input, select, textarea {
  background: var(--bg-card-2); color: var(--text-primary);
  border: 1px solid var(--line); border-radius: 0.5rem;
  padding: 0.6rem 0.75rem; font: inherit; width: 100%;
}
input::placeholder, textarea::placeholder { color: #8a857b; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: none; }
.form-actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.25rem; }
.form-error {
  background: #3a2420; color: #f0c0b5; border: 1px solid #5a332c;
  border-radius: 0.5rem; padding: 0.7rem 0.9rem; margin-bottom: 1rem;
}
.note-form { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.25rem; }
.note-form textarea { resize: vertical; }

/* Toolbar / search */
.toolbar { margin-bottom: 1rem; }
.search-form { display: flex; gap: 0.5rem; }
.search-form input { max-width: 360px; }

/* Status line (the signature "линейка") */
.status-line {
  display: flex; flex-wrap: wrap; gap: 0.35rem;
  padding: 0.75rem 0; border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 1.25rem;
}
.status-notch {
  position: relative; color: var(--text-muted); font-size: 0.85rem;
  padding: 0.4rem 0.7rem; border-radius: 0.4rem; cursor: pointer;
  background: transparent; border: none;
}
.status-notch::before {
  content: ""; position: absolute; left: 0.55rem; top: -0.75rem;
  width: 1px; height: 0.7rem; background: var(--line);
}
.status-notch:hover { color: var(--text-primary); }
.status-notch.active { color: var(--brand); font-weight: 700; }
.status-notch.active::before { background: var(--brand); width: 2px; left: 0.52rem; }
.status-notch.current { background: var(--brand-soft); }

/* Lead table */
.lead-table { display: flex; flex-direction: column; border-radius: var(--radius); overflow: hidden; }
.lead-row {
  display: grid; grid-template-columns: 1.6fr 1.4fr 0.7fr 0.9fr 0.8fr 0.9fr;
  gap: 0.75rem; align-items: center; padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line-soft); color: var(--text-primary);
}
.lead-row:not(.lead-row-head) { background: var(--bg-card); }
.lead-row:not(.lead-row-head):hover { background: var(--bg-card-2); text-decoration: none; }
.lead-row-head {
  color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 700; border-bottom: 1px solid var(--line);
}
.lead-cell { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-name { display: flex; flex-direction: column; white-space: normal; }
.lead-name small { color: var(--text-muted); font-size: 0.82rem; }

/* Status badges */
.badge {
  display: inline-block; padding: 0.2rem 0.6rem; border-radius: 0.35rem;
  font-size: 0.8rem; font-weight: 600; background: var(--bg-card-2); color: var(--text-muted);
}
.badge-new { background: #22302c; color: #9fd0c2; }
.badge-consult { background: #2a2a34; color: #a8b0d0; }
.badge-measure { background: #322a22; color: #d0b990; }
.badge-contract { background: #3a2f20; color: #e0c28a; }
.badge-inwork { background: #243039; color: #9cc3d0; }
.badge-closed { background: #252a25; color: #a0b898; }
.badge-rejected { background: #382320; color: #d08a80; }

/* Empty state */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state h1 { color: var(--text-primary); }
.empty-art { color: var(--line); max-width: 160px; margin: 0 auto 1rem; }
.empty-art svg { width: 100%; height: auto; }
.empty-hint { color: var(--text-muted); margin-top: 0.5rem; }

/* Notes */
.note-list { list-style: none; margin: 0; padding: 0; }
.note-item { padding: 1rem 0; border-bottom: 1px solid var(--line-soft); }
.note-item:last-child { border-bottom: none; }
.note-meta { display: flex; gap: 0.75rem; margin-bottom: 0.35rem; }
.note-author { color: var(--text-primary); font-weight: 600; }
.note-date { color: var(--text-muted); font-size: 0.82rem; }
.note-body { margin: 0; color: var(--text-muted); white-space: pre-wrap; }

/* Report */
.month-nav { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.month-label { font-family: var(--font-display); font-size: 1.3rem; min-width: 10rem; text-align: center; }
.report-grid { display: flex; flex-direction: column; gap: 0.9rem; }
.report-bar { display: grid; grid-template-columns: 8rem 1fr 3rem; gap: 1rem; align-items: center; }
.report-bar-label { color: var(--text-muted); text-align: right; }
.report-bar-track { background: var(--bg-card-2); border-radius: 0.3rem; height: 1rem; overflow: hidden; }
.report-bar-fill { background: var(--accent); height: 100%; border-radius: 0.3rem; min-width: 0; transition: width 0.3s ease; }
.report-bar-count { color: var(--text-primary); font-weight: 600; text-align: right; }
.report-summary { color: var(--text-muted); margin-top: 1.5rem; }

/* Managers */
.manager-list { display: flex; flex-direction: column; gap: 0.75rem; }
.manager-card { display: flex; align-items: center; gap: 1rem; margin-bottom: 0; }
.manager-avatar {
  width: 2.75rem; height: 2.75rem; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700;
}
.manager-info { display: flex; flex-direction: column; flex: 1; }
.manager-info span { color: var(--text-muted); font-size: 0.85rem; }
.manager-leads { color: var(--accent) !important; }
.manager-toggle { flex: none; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-wrap { text-align: center; max-width: 380px; width: 100%; padding: 2rem 1.5rem; }
.login-brand { margin-bottom: 2rem; }
.login-brand .brand-mark { width: 3rem; height: 3rem; font-size: 1.5rem; margin: 0 auto 0.5rem; }
.login-brand .brand-name { font-size: 2rem; }
.login-brand .brand-sub { color: var(--text-muted); }
.login-card { text-align: left; }
.login-card .field { margin-bottom: 1rem; }
.login-hint { color: var(--text-muted); margin: -0.2rem 0 1.25rem; }

/* Error */
.error-wrap { padding-top: 4rem; }

/* Responsive */
@media (max-width: 720px) {
  .container { padding: 1.25rem 1rem 3rem; }
  .topbar { padding: 0.6rem 1rem; flex-wrap: wrap; }
  .topnav { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; }
  .user-box { margin-left: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .lead-row { grid-template-columns: 1fr; gap: 0.2rem; padding: 0.9rem 1rem; }
  .lead-row-head { display: none; }
  .lead-cell { white-space: normal; }
  .report-bar { grid-template-columns: 6rem 1fr 2.5rem; }
  .search-form input { max-width: 100%; }
  .page-head { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
