:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #172033;
  --muted: #667085;
  --border: #dfe4ec;
  --primary: #1f5eff;
  --primary-dark: #1648c8;
  --positive: #14804a;
  --danger: #c72f3f;
  --warning: #a96500;
  --shadow: 0 8px 28px rgba(20, 30, 55, .08);
  --radius: 16px;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", Arial, sans-serif; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select, textarea { font: inherit; }
input, select, textarea { width: 100%; border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 10px; padding: 11px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 94, 255, .12); }
textarea { resize: vertical; }
label { display: grid; gap: 6px; font-weight: 600; color: #344054; }
small, .muted { color: var(--muted); font-weight: 400; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.65rem, 3vw, 2.35rem); margin-bottom: 6px; }
h2 { font-size: 1.2rem; margin-bottom: 12px; }
.topbar { position: sticky; top: 0; z-index: 30; min-height: 66px; display: flex; align-items: center; gap: 24px; padding: 10px max(18px, calc((100vw - 1440px) / 2)); background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 800; white-space: nowrap; }
.brand-mark, .auth-logo { display: inline-grid; place-items: center; background: linear-gradient(135deg, #1f5eff, #1738a3); color: #fff; font-weight: 900; letter-spacing: .05em; border-radius: 10px; }
.brand-mark { width: 48px; height: 40px; font-size: .78rem; }
.desktop-nav { display: flex; gap: 4px; flex: 1; }
.desktop-nav a { color: #475467; padding: 10px 11px; border-radius: 9px; font-weight: 600; }
.desktop-nav a:hover { background: var(--surface-2); color: var(--text); }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-menu form { margin: 0; }
.user-name { color: var(--muted); font-size: .92rem; white-space: nowrap; }
.page-shell { width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: 30px 0 96px; }
.page-shell-auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.heading-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 7px; color: var(--muted); font-weight: 600; }
.panel, .auth-card, .narrow-card, .mobile-client-card, .queue-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 20px; }
.panel-spaced { margin-top: 22px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.panel-heading h2 { margin-bottom: 2px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; border: 1px solid transparent; border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 700; text-align: center; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); }
.button-call { background: #168b52; color: #fff; }
.button-call:hover { background: #0f7041; }
.button-ghost { background: #fff; color: #344054; border-color: var(--border); }
.button-ghost:hover { background: var(--surface-2); }
.button-danger { background: var(--danger); color: #fff; }
.button-small { min-height: 34px; padding: 6px 10px; font-size: .88rem; }
.button-large { min-height: 48px; padding: 12px 18px; }
.button-wide { width: 100%; }
.notice { border-radius: 12px; padding: 12px 14px; margin-bottom: 18px; border: 1px solid; }
.notice-success { color: #0b6338; background: #eaf8f0; border-color: #bde7ce; }
.notice-error { color: #8b1e2b; background: #fff0f2; border-color: #fac5cc; }
.notice-info { color: #234a86; background: #edf4ff; border-color: #c8dcff; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stats-grid-wide { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card { display: grid; gap: 4px; min-height: 112px; padding: 17px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.stat-card span { color: var(--muted); font-weight: 650; }
.stat-card strong { font-size: 2rem; line-height: 1; }
.stat-card small { margin-top: auto; }
.stat-card-positive { border-left: 5px solid var(--positive); }
.stat-card-negative { border-left: 5px solid var(--danger); }
.dashboard-grid, .reminder-grid, .client-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, .9fr); gap: 22px; align-items: start; }
.client-layout { grid-template-columns: minmax(0, 2.1fr) minmax(300px, .8fr); }
.client-main, .client-sidebar { display: grid; gap: 20px; }
.lead-list { display: grid; }
.lead-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.lead-row:last-child { border-bottom: 0; }
.lead-main { min-width: 0; }
.lead-actions, .table-actions, .mobile-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.phone-link { color: var(--text); font-weight: 800; font-size: 1.05rem; white-space: nowrap; }
.phone-large { font-size: 1.3rem; }
.lead-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 5px; color: var(--muted); font-size: .9rem; }
.status-badge { display: inline-flex; align-items: center; width: fit-content; padding: 4px 9px; border-radius: 999px; font-size: .82rem; font-weight: 750; background: #edf0f5; color: #475467; }
.status-new { background: #e9f0ff; color: #184cbd; }
.status-queue { background: #edf4ff; color: #285c9e; }
.status-work { background: #fff1d8; color: #875200; }
.status-noanswer { background: #f0f1f4; color: #505968; }
.status-thinking { background: #f4ecff; color: #6f3caf; }
.status-visit, .status-arrived, .status-done { background: #e7f8ef; color: #0d7040; }
.status-refused { background: #fff0f2; color: #ad2435; }
.status-paused { background: #eef1f5; color: #5d6673; }
.compact-list { display: grid; }
.compact-list a { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; padding: 12px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.compact-list a:last-child { border-bottom: 0; }
.compact-list small { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state, .empty-cell { padding: 22px; text-align: center; color: var(--muted); }
.empty-state-large { padding: 56px 24px; text-align: center; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: middle; padding: 12px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: #fafbfc; }
.truncate-cell { max-width: 330px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.block { display: block; }
.filter-panel { margin-bottom: 18px; }
.filter-form { display: flex; align-items: end; gap: 12px; }
.grow { flex: 1; }
.inline-details { margin-top: 14px; }
.inline-details summary, details summary { cursor: pointer; font-weight: 700; }
.inline-form { display: flex; gap: 10px; margin-top: 12px; }
.inline-form input { flex: 1; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 20px; margin-top: 20px; }
.mobile-client-list { display: none; }
.quick-panel { border-top: 5px solid var(--primary); }
.quick-status-form { display: grid; grid-template-columns: 1.4fr .7fr auto; gap: 12px; align-items: end; }
.quick-buttons { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 9px; }
.quick-button { border: 0; border-radius: 10px; padding: 12px 8px; cursor: pointer; font-weight: 800; color: #263246; }
.quick-work { background: #ffe9bd; }
.quick-noanswer { background: #e8ebef; }
.quick-thinking { background: #eadcff; }
.quick-visit { background: #ccefdc; }
.quick-refuse { background: #ffd9df; }
.editor-form { display: grid; gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.span-2 { grid-column: 1 / -1; }
.checkbox-group { display: grid; gap: 9px; align-content: center; }
.check-label { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check-label input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; }
.compact-dl, .read-card dl { display: grid; grid-template-columns: minmax(110px, .65fr) 1.35fr; gap: 10px 14px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 600; }
.preserve-lines { white-space: pre-wrap; }
.history-list { display: grid; gap: 14px; }
.history-list article { position: relative; display: grid; gap: 3px; padding-left: 15px; border-left: 2px solid var(--border); }
.history-list time { color: var(--muted); font-size: .82rem; }
.history-list p { margin: 3px 0 0; white-space: pre-wrap; }
.danger-panel { border-color: #f2c2c8; }
.queue-stack { display: grid; gap: 14px; }
.queue-card { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 18px; align-items: center; padding: 18px; }
.queue-card.priority-1 { border-left: 6px solid var(--danger); }
.queue-card.priority-3 { opacity: .85; }
.queue-number { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); font-weight: 900; }
.queue-content h3 { margin: 9px 0 3px; }
.queue-actions { display: grid; gap: 8px; min-width: 170px; }
.count-pill { display: inline-grid; place-items: center; min-width: 34px; height: 34px; border-radius: 999px; background: var(--surface-2); font-weight: 800; }
.count-danger { color: var(--danger); background: #fff0f2; }
.overdue-time { color: var(--danger); font-weight: 700; }
.stats-list { display: grid; }
.stats-list > div { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.status-dot { display: inline-block; width: 9px; height: 9px; margin-right: 9px; border-radius: 50%; background: currentColor; }
.footnote { color: var(--muted); font-size: .9rem; margin-top: 18px; }
.upload-panel { max-width: 850px; }
.stack-form { display: grid; gap: 16px; }
.drop-zone { min-height: 220px; display: grid; place-items: center; align-content: center; gap: 7px; padding: 24px; border: 2px dashed #afbdd2; border-radius: 16px; background: #f9fbff; text-align: center; cursor: pointer; }
.drop-zone.dragover { background: #edf4ff; border-color: var(--primary); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-icon { font-size: 2.6rem; color: var(--primary); }
.file-count { margin-top: 8px; color: var(--primary); font-weight: 700; }
.file-result-list { display: grid; gap: 10px; }
.file-result-list article { padding: 12px; border: 1px solid var(--border); border-radius: 11px; }
.file-result-list article > div:first-child { display: flex; justify-content: space-between; gap: 14px; }
.phone-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.phone-chips span { padding: 5px 8px; border-radius: 8px; background: var(--surface-2); font-family: ui-monospace, Consolas, monospace; }
.text-error { color: var(--danger); }
.auth-page { background: radial-gradient(circle at 20% 10%, #dbe7ff, transparent 35%), radial-gradient(circle at 90% 80%, #dceee5, transparent 35%), #eef2f8; }
.auth-card, .narrow-card { width: min(460px, 100%); padding: 30px; }
.auth-card { text-align: center; }
.auth-card label { text-align: left; }
.auth-logo { width: 78px; height: 62px; margin: 0 auto 18px; }
.auth-note { margin: 18px 0 0; color: var(--muted); font-size: .84rem; }
.narrow-card { margin: 20px auto; }
.mobile-nav { display: none; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

@media (max-width: 1050px) {
  .desktop-nav { display: none; }
  .topbar { justify-content: space-between; }
  .dashboard-grid, .client-layout, .reminder-grid { grid-template-columns: 1fr; }
  .stats-grid, .stats-grid-wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .topbar { min-height: 58px; padding: 8px 13px; }
  .brand > span:last-child, .user-name, .user-menu form { display: none; }
  .page-shell { width: min(100% - 22px, 760px); padding-top: 18px; padding-bottom: 24px; }
  .page-heading { align-items: stretch; flex-direction: column; gap: 12px; }
  .heading-actions .button { flex: 1; }
  .stats-grid, .stats-grid-wide { gap: 9px; }
  .stat-card { min-height: 96px; padding: 13px; }
  .stat-card strong { font-size: 1.65rem; }
  .panel { padding: 15px; border-radius: 13px; }
  .lead-row { align-items: stretch; flex-direction: column; gap: 10px; }
  .lead-actions .button { flex: 1; }
  .desktop-client-table { display: none; }
  .mobile-client-list { display: grid; gap: 10px; }
  .mobile-client-card { padding: 15px; }
  .mobile-client-head { display: flex; justify-content: space-between; gap: 10px; }
  .mobile-card-actions .button { flex: 1; }
  .filter-form { align-items: stretch; flex-direction: column; }
  .inline-form { flex-direction: column; }
  .quick-status-form { grid-template-columns: 1fr; }
  .quick-buttons { grid-column: 1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-buttons .quick-visit { grid-column: span 1; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: 1; }
  .queue-card { grid-template-columns: 34px minmax(0, 1fr); align-items: start; padding: 14px; }
  .queue-number { width: 32px; height: 32px; }
  .queue-actions { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; min-width: 0; }
  .compact-dl, .read-card dl { grid-template-columns: 1fr; gap: 3px; }
  .compact-dl dd, .read-card dd { margin-bottom: 9px; }
  .mobile-nav { position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); padding: 7px 6px calc(7px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.98); border-top: 1px solid var(--border); box-shadow: 0 -8px 26px rgba(20,30,55,.09); }
  .mobile-nav a { display: grid; place-items: center; gap: 1px; color: #667085; }
  .mobile-nav span { font-size: 1.25rem; line-height: 1; }
  .mobile-nav small { font-size: .69rem; }
  .mobile-nav-primary span { width: 38px; height: 38px; display: grid; place-items: center; margin-top: -17px; border-radius: 50%; background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(31,94,255,.35); }
  .auth-card { padding: 24px 18px; }
}
