/* =========================================================================
   Линия CRM — design system
   Warm paper + graphite axes + deep green. Palette from the order brief.
   ========================================================================= */

/* ---- fonts: self-hosted woff2 with metric fallback ---- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/inter-cyrillic-400.woff2") format("woff2");
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/inter-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/inter-cyrillic-500.woff2") format("woff2");
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/inter-latin-500.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/inter-cyrillic-600.woff2") format("woff2");
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/inter-latin-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/inter-cyrillic-700.woff2") format("woff2");
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/playfair-cyrillic-500.woff2") format("woff2");
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/playfair-latin-500.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/playfair-cyrillic-600.woff2") format("woff2");
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/playfair-latin-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/playfair-cyrillic-700.woff2") format("woff2");
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/playfair-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Metric-compatible fallbacks so the swap does not shift layout. */
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial");
  size-adjust: 104%;
  ascent-override: 92%;
  descent-override: 24%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Playfair Fallback";
  src: local("Georgia");
  size-adjust: 104%;
  ascent-override: 92%;
  descent-override: 24%;
  line-gap-override: 0%;
}

/* ---- tokens ---- */
:root {
  --accent: #a5844e;
  --accent-ink: #201a10;
  --accent-soft: #ece3d0;
  --bg-card: #fffdf8;
  --bg-page: #f4f1ea;
  --brand: #2a4a3b;
  --brand-ink: #1d352b;
  --text-muted: #4d5450;
  --text-primary: #202724;
  --line: #d9d3c3;
  --danger: #8c352b;

  --font-body: "Inter", "Inter Fallback", system-ui, -apple-system, sans-serif;
  --font-head: "Playfair Display", "Playfair Fallback", Georgia, serif;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(32, 39, 36, 0.05), 0 4px 16px rgba(32, 39, 36, 0.06);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-primary);
  background-color: var(--bg-page);
  background-image:
    linear-gradient(rgba(42, 74, 59, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 74, 59, 0.028) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

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

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
  margin: 0 0 0.5em;
  text-wrap: balance;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 1em; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---- topbar / nav ---- */
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--brand);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
}
.nav a {
  display: inline-block;
  padding: 7px 13px;
  border-radius: 6px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}
.nav a:hover { text-decoration: none; background: var(--accent-soft); color: var(--text-primary); }
.nav a.active { background: var(--brand); color: #fff; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  white-space: nowrap;
}
.user-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-role { font-size: 0.75rem; color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: #93753f; }
.btn-outline { background: transparent; border-color: var(--line); color: var(--text-primary); }
.btn-outline:hover { background: var(--accent-soft); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--text-primary); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- forms ---- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-primary);
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  outline: none;
}
.field textarea { resize: vertical; min-height: 90px; }
.field-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.field-error { color: var(--danger); font-size: 0.85rem; margin-top: 4px; }
.field input.invalid, .field select.invalid { border-color: var(--danger); }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}
@media (max-width: 560px) {
  .field-grid { grid-template-columns: 1fr; }
}

/* ---- flash ---- */
.flash {
  margin: 16px 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-weight: 500;
}

/* ---- page header ---- */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 28px 0 20px;
}
.page-head h1 { margin-bottom: 0; }
.page-head .sub { color: var(--text-muted); font-size: 0.95rem; margin-top: 4px; }

/* ---- status axis colors (darkened for ≥4.5:1 text contrast on white) ---- */
.st-new      { --status: #2c5f91; }
.st-consult  { --status: #1f6b5c; }
.st-measure  { --status: #8a6206; }
.st-contract { --status: #23433a; }
.st-work     { --status: #a5561a; }
.st-closed   { --status: #4d5450; }
.st-reject   { --status: #8c352b; }

/* ---- lead list ---- */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { text-decoration: none; border-color: var(--accent); color: var(--text-primary); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .cnt { font-size: 0.75rem; opacity: 0.8; }

.search {
  display: flex;
  gap: 8px;
  max-width: 440px;
}
.search input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.95rem;
  background: #fff;
}

.lead-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}
@media (max-width: 560px) {
  .lead-grid { grid-template-columns: 1fr; }
}

.lead-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  overflow: hidden;
}
.lead-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(32, 39, 36, 0.1);
  text-decoration: none;
}
.lead-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--status);
  transition: width 0.15s ease;
}
.lead-card:hover::before { width: 7px; }

.lead-card .client { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; color: var(--text-primary); }
.lead-card .phone { color: var(--text-muted); font-size: 0.9rem; }
.lead-card .meta { color: var(--text-muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.lead-card .status-line {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--status);
}
.lead-card .status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--status);
}

.empty {
  text-align: center;
  padding: 48px 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-muted);
}
.empty h2 { color: var(--text-primary); }
.empty-illustration {
  width: 120px;
  height: 80px;
  color: var(--accent);
  margin-bottom: 12px;
  opacity: 0.75;
}

/* ---- lead detail ---- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 { margin-bottom: 14px; }
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--status);
}
.status-badge .status-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--status);
}

/* status changer — buttons */
.status-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.status-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-primary);
}
.status-btn:hover { border-color: var(--accent); }
.status-btn.current { background: var(--brand); border-color: var(--brand); color: #fff; }
.status-btn .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status); }

/* notes */
.note {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.note:last-child { border-bottom: none; }
.note .note-head { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
.note .note-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- report ---- */
.report-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .report-layout { grid-template-columns: 1fr; }
}
.report-aside {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.report-aside img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  display: block;
}
.report-aside .muted {
  margin: 12px 14px 14px;
  font-size: 0.85rem;
}
.report-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.report-controls .month-label {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
}
.report-total {
  font-family: var(--font-head);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--brand);
  line-height: 1;
}
.report-total small { font-size: 1rem; font-weight: 500; color: var(--text-muted); }

.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 42px; gap: 12px; align-items: center; }
@media (max-width: 560px) {
  .bar-row { grid-template-columns: 110px 1fr 34px; gap: 8px; }
}
.bar-label { font-size: 0.9rem; font-weight: 500; text-align: right; color: var(--text-primary); }
.bar-track { background: var(--accent-soft); border-radius: 6px; height: 26px; overflow: hidden; }
.bar-fill {
  height: 100%;
  background: var(--status);
  border-radius: 6px;
  transition: width 0.3s ease;
  min-width: 2px;
}
.bar-count { font-weight: 600; color: var(--text-primary); }

/* ---- managers ---- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 600; }
.table td { font-size: 0.95rem; }
.badge-role {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-manager { background: var(--accent-soft); color: #6b5629; }
.badge-admin { background: var(--brand); color: #fff; }

.manager-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
@media (max-width: 720px) {
  .manager-form { grid-template-columns: 1fr; }
}
.manager-form .field { margin-bottom: 0; }

/* ---- login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background-color: var(--brand);
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 32px 32px;
}
.login-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  max-width: 880px;
  width: 100%;
  background: var(--bg-card);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.login-visual {
  position: relative;
  min-height: 460px;
}
.login-visual picture,
.login-visual img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.login-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(18,28,23,0.05) 0%, rgba(18,28,23,0.72) 100%);
}
.login-visual-caption {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 24px;
  z-index: 2;
  color: #fff;
}
.login-visual-caption p {
  margin: 8px 0 0;
  font-size: 0.95rem;
  line-height: 1.4;
  max-width: 30ch;
  color: rgba(255,255,255,0.92);
}
.brand-inverse { color: #fff; }
.brand-inverse .brand-mark { background: #fff; color: var(--brand); }

.login-form {
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-form-head { margin-bottom: 20px; }
.login-form-head h1 { font-size: 1.6rem; margin-bottom: 6px; }
.login-form .tagline { color: var(--text-muted); font-size: 0.9rem; margin: 0; }
.login-error {
  background: #fbeae8;
  color: var(--danger);
  border: 1px solid #ecc9c4;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.login-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 16px 0 0;
  line-height: 1.45;
}

@media (max-width: 720px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-visual { min-height: 180px; }
  .login-visual-caption { left: 16px; right: 16px; bottom: 14px; }
  .login-visual-caption p { font-size: 0.85rem; }
  .login-form { padding: 28px 22px; }
}

/* ---- misc ---- */
.muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 32px 20px 40px;
}
