:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e3e6eb;
  --line-2: #d3d8df;
  --text: #17202c;
  --muted: #667085;
  --faint: #98a2b3;
  --brand: #0A2A55;
  --brand-ink: #ffffff;
  --brand-soft: #e6edf7;
  --brand-light: #5b96e8;
  --nav: #0A2A55;
  --nav-2: #143a6e;
  --nav-text: #cbd7e8;
  --nav-muted: #8aa1c2;
  --accent: #1d5bb8;
  --green: #12805c; --green-bg: #e3f5ed;
  --amber: #a15c00; --amber-bg: #fff3d6;
  --red: #c4302b; --red-bg: #fde8e7;
  --blue: #2259b8; --blue-bg: #e6eefc;
  --gray-bg: #eef0f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --font: 'Inter', -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --panel: #171e27; --panel-2: #1c2430; --line: #29323e; --line-2: #36414f;
    --text: #e6e9ee; --muted: #9aa5b3; --faint: #6f7b8a; --brand: #3f7fd9; --brand-soft: #14294a; --accent: #7aa7f5;
    --nav: #061a36; --nav-2: #0f2b53;
    --green: #4cc79a; --green-bg: #12352a; --amber: #f0b44c; --amber-bg: #3a2c10; --red: #f17a74; --red-bg: #3d1b1a;
    --blue: #7aa7f5; --blue-bg: #17284a; --gray-bg: #232c38;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --panel: #171e27; --panel-2: #1c2430; --line: #29323e; --line-2: #36414f;
  --text: #e6e9ee; --muted: #9aa5b3; --faint: #6f7b8a; --brand: #3f7fd9; --brand-soft: #14294a; --accent: #7aa7f5;
  --nav: #061a36; --nav-2: #0f2b53;
  --green: #4cc79a; --green-bg: #12352a; --amber: #f0b44c; --amber-bg: #3a2c10; --red: #f17a74; --red-bg: #3d1b1a;
  --blue: #7aa7f5; --blue-bg: #17284a; --gray-bg: #232c38;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* ——— Layout */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--nav); color: var(--nav-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: flex-end; gap: 10px; padding: 22px 20px 16px; color: #fff; }
.brand-sub { font-size: 10.5px; letter-spacing: .14em; color: var(--nav-muted); line-height: 1; padding-bottom: 1px; }
.nav { padding: 4px 10px 20px; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--nav-muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--nav-text); font-size: 13.5px; }
.nav a:hover { background: var(--nav-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--nav-2); color: #fff; box-shadow: inset 3px 0 0 var(--brand-light); }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav .count { margin-left: auto; font-size: 11px; background: var(--brand-light); color: #fff; border-radius: 10px; padding: 0 7px; }
.sidebar-foot { padding: 12px 18px; border-top: 1px solid var(--nav-2); font-size: 12px; color: var(--nav-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 10px 24px; }
.menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 520px; }
.search input { width: 100%; padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--faint); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-height: 70vh; overflow: auto; padding: 6px; }
.search-results .grp { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 8px 8px 4px; letter-spacing: .05em; }
.search-results a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text); }
.search-results a:hover { background: var(--panel-2); text-decoration: none; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-left: auto; cursor: pointer; position: relative; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.user-chip .who { line-height: 1.2; }
.user-chip .who small { color: var(--muted); display: block; font-size: 11.5px; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 200px; padding: 6px; z-index: 50; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--panel-2); text-decoration: none; }

.content { padding: 22px 24px 48px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

/* ——— Controls */
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line-2); border-radius: 7px; padding: 7px 10px; min-height: 34px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--brand); }
input[readonly] { background: var(--panel-2); color: var(--muted); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label.field.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; padding-top: 22px; }
label.field .req { color: var(--red); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--panel); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; min-height: 34px; }
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: none; }
.btn.small { padding: 4px 10px; min-height: 28px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

/* ——— Cards & grids */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-head h2 { flex: 1; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .wide { grid-column: 1 / -1; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; display: block; color: inherit; }
.kpi:hover { text-decoration: none; border-color: var(--line-2); }
.kpi .label { font-size: 12.5px; color: var(--muted); }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .hint.bad { color: var(--red); }
.kpi.accent { border-top: 3px solid var(--brand); }

/* ——— Details */
.props { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 20px; }
.prop .k { font-size: 12px; color: var(--muted); }
.prop .v { margin-top: 2px; word-break: break-word; white-space: pre-wrap; }
.prop.wide { grid-column: 1 / -1; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 11px 12px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .cnt { font-size: 11px; background: var(--gray-bg); border-radius: 10px; padding: 1px 6px; margin-left: 4px; color: var(--muted); }

/* ——— Tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); background: var(--panel-2); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.t th.sortable { cursor: pointer; user-select: none; }
table.t th.sortable:hover { color: var(--text); }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover td { background: var(--panel-2); }
table.t tfoot td { font-weight: 650; background: var(--panel-2); }
table.t td.num, table.t th.num { text-align: right; }
table.t .empty { text-align: center; color: var(--muted); padding: 28px; }
table.lines td { padding: 4px 6px; vertical-align: middle; }
table.lines input, table.lines select { min-height: 30px; padding: 4px 7px; }
table.lines td.idx { color: var(--faint); width: 28px; text-align: center; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar .q { min-width: 240px; flex: 1; max-width: 360px; }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: var(--muted); font-size: 13px; }
.pager .grow { flex: 1; }

/* ——— Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 550; white-space: nowrap; background: var(--gray-bg); color: var(--muted); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.stars { color: var(--brand); letter-spacing: 1px; }

/* ——— Ref picker */
.ref { position: relative; }
.ref input { padding-right: 52px; }
.ref .ref-actions { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: flex; }
.dropdown { position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 280px; overflow-y: auto; padding: 4px; min-width: 260px; }
.dropdown div { padding: 7px 9px; border-radius: 6px; cursor: pointer; color: var(--text); font-size: 13.5px; }
.dropdown div:hover, .dropdown div.hl { background: var(--panel-2); }
.dropdown .none { color: var(--muted); cursor: default; }

/* ——— Kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); min-height: 200px; }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.col-head b { display: block; }
.col-head small { color: var(--muted); }
.col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.col.over { outline: 2px dashed var(--brand); }
.deal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; cursor: grab; box-shadow: var(--shadow); }
.deal-card:hover { border-color: var(--line-2); }
.deal-card .t { font-weight: 600; font-size: 13.5px; }
.deal-card .c { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.deal-card .m { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12.5px; }

/* ——— Charts */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .b .stack { width: 100%; max-width: 38px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
.bars .b .s1 { background: var(--brand); }
.bars .b .s2 { background: color-mix(in srgb, var(--brand) 25%, var(--panel)); }
.bars .b small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.hbar { display: grid; grid-template-columns: minmax(110px, 170px) 1fr auto; gap: 10px; align-items: center; margin: 7px 0; font-size: 13px; }
.hbar .track { background: var(--gray-bg); border-radius: 4px; height: 10px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--brand); border-radius: 4px; }
.hbar .fill.blue { background: var(--accent); }
.hbar .fill.red { background: var(--red); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; gap: 10px; align-items: center; padding: 9px 16px; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border-bottom: 0; }
.list-plain .main-t { flex: 1; min-width: 0; }
.list-plain .main-t small { display: block; color: var(--muted); }
.empty-state { padding: 28px; text-align: center; color: var(--muted); }

/* ——— Modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 26, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(520px, 100%); max-height: 90vh; overflow: auto; }
.modal .card-head { border-bottom: 1px solid var(--line); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--nav); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 420px; font-size: 13.5px; animation: pop .18s ease-out; }
.toast.err { background: var(--red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.timeline { list-style: none; margin: 0; padding: 0 16px; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: 12px; }
.chg { color: var(--muted); }
.chg b { color: var(--text); font-weight: 550; }

.flow { display: flex; gap: 0; flex-wrap: wrap; margin-bottom: 16px; }
.flow span { padding: 6px 14px 6px 18px; background: var(--gray-bg); color: var(--muted); font-size: 12.5px; position: relative; clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%, 8px 50%); margin-right: -4px; }
.flow span:first-child { clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%); padding-left: 12px; border-radius: 6px 0 0 6px; }
.flow span.done { background: var(--green-bg); color: var(--green); }
.flow span.cur { background: var(--brand); color: #fff; font-weight: 600; }

.totals { display: flex; justify-content: flex-end; gap: 28px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.totals div { text-align: right; }
.totals small { display: block; color: var(--muted); font-size: 12px; }
.totals b { font-size: 16px; font-variant-numeric: tabular-nums; }

/* ——— Login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--nav); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art h1 { font-size: 34px; line-height: 1.15; max-width: 480px; margin-top: 40px; }
.login-art p { color: var(--nav-text); max-width: 460px; font-size: 15px; }
.login-art .stripe { position: absolute; right: -140px; bottom: -36px; color: #fff; opacity: .06; pointer-events: none; }
.login-form { display: grid; place-items: center; padding: 32px; background: var(--panel); }
.login-form form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }

/* ——— Print */
.print-page { background: #fff; color: #111; max-width: 860px; margin: 24px auto; padding: 48px 56px; box-shadow: var(--shadow-lg); font-size: 13px; }
.print-page h1 { font-size: 20px; margin: 18px 0 6px; }
.print-page table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.print-page th, .print-page td { border: 1px solid #bbb; padding: 6px 8px; text-align: left; vertical-align: top; }
.print-page th { background: #f1f1f1; font-size: 12px; }
.print-page .ph { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #0A2A55; padding-bottom: 14px; }
.print-page .terms td:first-child { width: 34%; color: #555; }
.print-bar { position: sticky; top: 0; display: flex; gap: 8px; justify-content: center; padding: 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
@media print {
  .print-bar { display: none; }
  body { background: #fff; }
  .print-page { box-shadow: none; margin: 0; padding: 0; max-width: none; }
}

/* ——— Responsive */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .props { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 90; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .g2, .g3, .g4, .form-grid, .props { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .user-chip .who { display: none; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .toolbar .q { max-width: none; }
  .print-page { padding: 20px; margin: 0; }
}
