/* ============================================================
   СтройФинанс — стили дашборда
   ============================================================ */

:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f8;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e6ebf2;
  --line-strong: #d7dfea;
  --accent: #ea7a1f;
  --accent-2: #f59e0b;
  --accent-soft: #fff3e5;
  --accent-ink: #ffffff;
  --green: #0e9f74;
  --green-soft: #e6f7f0;
  --red: #dc2f4b;
  --red-soft: #fdecef;
  --amber: #b7791f;
  --amber-soft: #fdf6e3;
  --blue: #2f6fed;
  --blue-soft: #eaf1fe;
  --violet: #7c5cf4;
  --teal: #0ea5a4;
  --slate: #64748b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 28px -18px rgba(15, 23, 42, .22);
  --shadow-lg: 0 24px 60px -24px rgba(15, 23, 42, .35);
  --sidebar: 244px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #080e1a;
  --surface: #101a2b;
  --surface-2: #0c1524;
  --surface-3: #17233a;
  --ink: #e9eefb;
  --ink-2: #c3cde1;
  --muted: #8b9ab5;
  --faint: #6c7c98;
  --line: #1d2a42;
  --line-strong: #2a3a57;
  --accent: #f59e0b;
  --accent-2: #fbbf24;
  --accent-soft: #2a2110;
  --accent-ink: #1a1204;
  --green: #2dd4a0;
  --green-soft: #0d2a24;
  --red: #fb7185;
  --red-soft: #2c1219;
  --amber: #fbbf24;
  --amber-soft: #2a2210;
  --blue: #7aa2ff;
  --blue-soft: #131f3a;
  --violet: #a68bff;
  --teal: #2dd4bf;
  --slate: #94a3b8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px -20px rgba(0, 0, 0, .7);
  --shadow-lg: 0 30px 70px -25px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

svg { display: block; }

/* ---------- Layout ---------- */

.app { min-height: 100%; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  background:
    radial-gradient(120% 60% at 0% 0%, rgba(245, 158, 11, .08), transparent 60%),
    linear-gradient(180deg, #0d1626 0%, #0a111e 100%);
  border-right: 1px solid rgba(255, 255, 255, .05);
  color: #94a3b8;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 22px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, #f59e0b, #d97706);
  color: #1a1204;
  box-shadow: 0 6px 18px -6px rgba(245, 158, 11, .7);
}
.brand-mark svg { width: 21px; height: 21px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #f1f5fb; font-size: 15px; letter-spacing: .1px; }
.brand-text span { font-size: 10.5px; color: #7c8aa5; text-transform: uppercase; letter-spacing: .08em; margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 3px; }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 10px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #93a1ba;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav-item:hover { background: rgba(255, 255, 255, .05); color: #e2e8f4; }
.nav-item.is-active {
  background: linear-gradient(90deg, rgba(245, 158, 11, .18), rgba(245, 158, 11, .06));
  color: #fff;
}
.nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: #f59e0b;
}
.nav-item.is-active svg { color: #fbbf24; opacity: 1; }

.sidebar-spacer { flex: 1; min-height: 24px; }

.sidebar-company {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .06);
}
.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #1c2b45;
  color: #fbbf24;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
}
.sidebar-company-text { min-width: 0; display: flex; flex-direction: column; }
.sidebar-company-text strong {
  color: #e8eefb;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-company-text span { font-size: 10.5px; color: #7c8aa5; margin-top: 2px; }

.sidebar-links { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, .06); }
.nav-item--small { min-height: 36px; font-size: 12.5px; color: #8291ac; }
.nav-item--small svg { width: 15px; height: 15px; }

.sidebar-overlay { position: fixed; inset: 0; background: rgba(5, 9, 17, .55); z-index: 35; backdrop-filter: blur(2px); }

.main {
  margin-left: var(--sidebar);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 26px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar { background: var(--bg); }
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.page-heading h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.015em; }
.page-heading p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.filters { display: flex; gap: 8px; }

.content {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 26px 28px;
  flex: 1;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 26px 22px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
  color: var(--faint);
  font-size: 11.5px;
}

/* ---------- Controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .12s, background .15s, border-color .15s, box-shadow .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(180deg, #f2921f, #e2760f);
  color: #fff;
  box-shadow: 0 6px 16px -8px rgba(226, 118, 15, .8), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn-primary:hover { background: linear-gradient(180deg, #f89b2c, #e87c12); }

.btn-ghost {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-2);
  box-shadow: 0 1px 1px rgba(15, 23, 42, .03);
}
.btn-ghost:hover { border-color: var(--faint); color: var(--ink); }

.btn-soft {
  background: var(--surface-3);
  color: var(--ink-2);
  border-color: transparent;
}
.btn-soft:hover { background: var(--line); }

.btn-danger { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn-danger:hover { border-color: var(--red); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--faint); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.menu-btn { display: none; }

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-3);
  flex: none;
}
.theme-switch button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}
.theme-switch button svg { width: 14px; height: 14px; flex: none; }
.theme-switch button:hover { color: var(--ink); }
.theme-switch button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .14);
}
.theme-switch button[data-theme-choice="light"].is-active svg { color: #e08a00; }
.theme-switch button[data-theme-choice="dark"].is-active svg { color: #6f8dff; }
[data-theme="dark"] .theme-switch button.is-active { box-shadow: 0 1px 3px rgba(0, 0, 0, .45); }

.select-wrap { position: relative; display: inline-flex; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 11px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select {
  appearance: none;
  height: 38px;
  padding: 0 30px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  max-width: 210px;
  text-overflow: ellipsis;
}
select:hover { border-color: var(--faint); }
select:focus-visible, input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}

.add-wrap { position: relative; }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 288px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
}
.menu button:hover { background: var(--surface-3); }
.menu-ic {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.menu button span:last-child { display: flex; flex-direction: column; }
.menu strong { font-size: 12.5px; font-weight: 600; }
.menu small { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-title { margin: 0; font-size: 14.5px; font-weight: 650; letter-spacing: -.005em; }
.card-sub { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.card-actions { display: flex; gap: 6px; flex-shrink: 0; }

.section { margin-bottom: 16px; }

.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2.05fr) minmax(0, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; }
.grid-half { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* ---------- KPI ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  position: relative;
  overflow: hidden;
  padding: 14px 15px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.kpi::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--kpi-color, var(--accent)), transparent 85%);
  opacity: .85;
}
.kpi-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value {
  margin-top: 7px;
  font-size: 22px;
  font-weight: 660;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kpi-value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.kpi-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; min-height: 20px; }
.kpi-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-spark { width: 84px; height: 26px; flex: none; opacity: .9; }

.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }
.delta svg { width: 11px; height: 11px; }

/* ---------- Alerts strip ---------- */

.alerts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 12px;
  line-height: 1.4;
  background: var(--surface);
}
.alert .alert-ic {
  width: 20px;
  height: 20px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  margin-top: 1px;
}
.alert strong { font-weight: 650; }
.alert span { color: var(--muted); display: block; margin-top: 1px; }
.alert-warn { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 22%, transparent); }
.alert-warn .alert-ic { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.alert-bad { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 20%, transparent); }
.alert-bad .alert-ic { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.alert-ok { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 20%, transparent); }
.alert-ok .alert-ic { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }

/* ---------- Charts ---------- */

.chart { position: relative; width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0 0 10px;
  font-size: 11.5px;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.legend-line { width: 12px; height: 3px; border-radius: 2px; flex: none; }

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 150px;
  padding: 9px 11px;
  border-radius: 10px;
  background: #0d1626;
  color: #eef3fc;
  font-size: 11.5px;
  box-shadow: 0 14px 30px -12px rgba(0, 0, 0, .5);
  pointer-events: none;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity .12s ease, transform .12s ease;
}
.chart-tooltip.is-visible { opacity: 1; transform: none; }
.chart-tooltip .tt-title { color: #9fb0c9; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 7px; line-height: 1.7; }
.chart-tooltip .tt-row b { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }

.donut-flex { display: flex; align-items: center; gap: 18px; }
.donut-svg { flex: none; width: 172px; max-width: 45%; }
.donut-legend { display: flex; flex-direction: column; gap: 7px; min-width: 0; flex: 1; }
.donut-row { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); min-width: 0; }
.donut-row .legend-dot { width: 7px; height: 7px; }
.donut-row .dl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-row .dl-val { margin-left: auto; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.donut-center-val { font-size: 15px; font-weight: 650; fill: var(--ink); }
.donut-center-sub { font-size: 9px; fill: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  margin: 0 -20px -18px;
  padding: 0 20px 6px;
  scrollbar-width: thin;
}
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  min-width: 640px;
}
table.data th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  padding: 8px 10px;
  text-align: right;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data th .sort-arrow { opacity: .4; margin-left: 3px; font-size: 9px; }
table.data th.is-sorted .sort-arrow { opacity: 1; color: var(--accent); }
table.data td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
  white-space: nowrap;
}
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.num { font-variant-numeric: tabular-nums; }
table.data .cell-name { min-width: 220px; max-width: 320px; }
table.data .cell-name strong { font-weight: 600; font-size: 13px; display: block; }
table.data .cell-name span { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }

table.data tr.row-total td { font-weight: 650; background: var(--surface-2); border-bottom: 1px solid var(--line); }
table.data tr.row-sub td:first-child { padding-left: 24px; color: var(--ink-2); }
table.data tr.row-sub td { color: var(--ink-2); }
table.data tr.row-spacer td { height: 8px; padding: 0; border: 0; background: transparent; }
table.data td.neg { color: var(--red); }
table.data .muted { color: var(--muted); }

.table-projects tbody tr { cursor: pointer; }
.table-projects tbody tr:hover td { background: var(--accent-soft); }

/* progress */
.progress {
  position: relative;
  height: 5px;
  border-radius: 4px;
  background: var(--surface-3);
  width: 96px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}
.progress > span { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--accent); }
.progress.green > span { background: var(--green); }
.progress.gray > span { background: var(--faint); }
.progress-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.progress-cell b { font-weight: 600; font-size: 11.5px; min-width: 34px; text-align: right; }

/* badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-active { background: var(--green-soft); color: var(--green); }
.badge-completed { background: var(--blue-soft); color: var(--blue); }
.badge-paused { background: var(--amber-soft); color: var(--amber); }
.badge-neutral { background: var(--surface-3); color: var(--muted); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-green { background: var(--green-soft); color: var(--green); }

/* ---------- Projects screen ---------- */

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  padding: 13px 15px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.stat span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.stat b { display: block; margin-top: 5px; font-size: 19px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.search {
  position: relative;
  flex: 1;
  max-width: 320px;
  min-width: 180px;
}
.search svg { position: absolute; left: 11px; top: 50%; width: 15px; height: 15px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 12.5px;
}
.search input::placeholder { color: var(--faint); }

/* ---------- Settings ---------- */

.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.field input, .field select, .field textarea {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 13px;
}
.field textarea { height: auto; min-height: 70px; padding: 9px 11px; resize: vertical; }
.field .hint { font-size: 10.5px; color: var(--faint); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.info-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 9px; }
.info-list li { display: flex; gap: 9px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.info-list li b { color: var(--ink); font-weight: 600; }
.info-list .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex: none; margin-top: 6px; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 12, 22, .58);
  backdrop-filter: blur(4px);
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }

.modal {
  width: min(590px, 100%);
  max-height: min(88vh, 880px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: modal-in .18s cubic-bezier(.2, .8, .3, 1);
  overflow: hidden;
}
.modal--wide { width: min(780px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.985); } }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.modal-head p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.modal-close {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--muted);
  flex: none;
}
.modal-close:hover { color: var(--ink); }
.modal-close svg { width: 16px; height: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-3);
  gap: 2px;
  width: 100%;
}
.seg button {
  flex: 1;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background .15s, color .15s, box-shadow .15s;
}
.seg button.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.seg button[data-dir="in"].is-active { color: var(--green); }
.seg button[data-dir="out"].is-active { color: var(--red); }

.modal-note {
  margin-top: 12px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.detail-logo {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}
.detail-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.detail-head p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.detail-cell { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.detail-cell span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.detail-cell b { display: block; margin-top: 4px; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }

.detail-list { margin-top: 6px; }
.detail-list h4 { margin: 0 0 8px; font-size: 12px; font-weight: 650; color: var(--ink-2); }
.op-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.op-row:last-child { border-bottom: 0; }
.op-row .op-date { color: var(--muted); font-size: 11px; width: 74px; flex: none; }
.op-row .op-cat { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op-row .op-amt { font-weight: 650; font-variant-numeric: tabular-nums; }
.op-row .op-amt.in { color: var(--green); }
.op-row .op-amt.out { color: var(--red); }

/* ---------- Empty / toast ---------- */

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.empty b { display: block; color: var(--ink); font-size: 14px; margin-bottom: 4px; }

.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  border-radius: 11px;
  background: #0d1626;
  color: #eef3fc;
  font-size: 12.5px;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .6);
  animation: toast-in .2s ease-out;
  max-width: 360px;
}
.toast .t-ic { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: var(--green); color: #06231a; font-size: 11px; font-weight: 800; flex: none; }
.toast.err .t-ic { background: var(--red); color: #2a050c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Responsive ---------- */

@media (max-width: 1440px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1120px) {
  .grid-2-1, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 12px 18px; }
  .content { padding: 18px; }
  .footer { padding: 12px 18px 20px; }
}

@media (max-width: 1300px) {
  .theme-switch button span { display: none; }
  .theme-switch button { padding: 0 7px; }
}

@media (max-width: 980px) {
  :root { --sidebar: 0px; }
  .sidebar {
    width: 250px;
    transform: translateX(-102%);
    transition: transform .22s cubic-bezier(.2, .8, .3, 1);
    box-shadow: 20px 0 60px rgba(0, 0, 0, .35);
  }
  .sidebar.is-open { transform: none; }
  .main { margin-left: 0; }
  .icon-btn.menu-btn { display: inline-grid; }
  .sidebar-overlay[hidden] { display: none; }
  .page-heading h1 { font-size: 18px; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .topbar-actions { margin-left: auto; }
  .filters { flex: 1; min-width: 0; }
  .filters .select-wrap { flex: 1; min-width: 0; }
  .filters select { width: 100%; max-width: none; }
  .grid-half { grid-template-columns: minmax(0, 1fr); }
  .stats-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 20px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 14px 14px; border-radius: 14px; }
  .table-wrap { margin: 0 -14px -14px; padding: 0 14px 4px; }
  .donut-flex { flex-direction: column; align-items: stretch; }
  .donut-svg { align-self: center; width: 160px; }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .btn span { display: none; }
  .btn-primary span { display: inline; }
  .modal { max-height: 92vh; }
  .content { padding: 14px; }
  .footer { padding: 12px 14px 18px; }
}

@media (max-width: 460px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .stats-strip { grid-template-columns: minmax(0, 1fr); }
  .topbar-actions { gap: 6px; }
  .icon-btn, .btn { height: 36px; }
  .icon-btn { width: 36px; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Print ---------- */

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .topbar, .footer, .toast-root, .add-wrap, .menu, .modal-backdrop { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .card, .kpi, .stat { box-shadow: none; border-color: #d9dee7; break-inside: avoid; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .grid-2-1, .grid-2 { grid-template-columns: 1fr; }
  .chart svg { max-height: 220px; }
  .table-wrap { overflow: visible; margin: 0; padding: 0; }
  table.data { font-size: 9.5px; min-width: 0; }
  .badge { border: 1px solid #ccd3de; }
}

/* ---------- Дополнительные элементы ---------- */

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 15px;
}
.kpi-label { min-width: 0; }
.delta small { font-size: 9px; font-weight: 500; opacity: .7; margin-left: 1px; }

.stat b.pos { color: var(--green); }
.stat b.neg { color: var(--red); }

.table-note {
  margin: 18px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
}
.table-note:last-child { margin-bottom: 2px; }

table.data th:first-child,
table.data td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}
table.data th:first-child { z-index: 3; }
table.data tbody tr:hover td:first-child { background: var(--surface-2); }
table.data tr.row-total td:first-child { background: var(--surface-2); }
table.data tr.row-group td:first-child { background: var(--surface-2); }

table.data tr.row-group td {
  padding: 13px 10px 5px;
  background: var(--surface-2);
  border-bottom: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
}

table.data .cell-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.amt-in { color: var(--green); font-weight: 600; }
.amt-out { color: var(--red); font-weight: 600; }

.row-del {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--faint);
  transition: color .15s, background .15s;
}
.row-del:hover { color: var(--red); background: var(--red-soft); }
.row-del svg { width: 15px; height: 15px; }

.cat-label { display: inline-flex; align-items: center; gap: 7px; }
.share-bar {
  width: 112px;
  height: 6px;
  margin-left: auto;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}
.share-bar span { display: block; height: 100%; border-radius: 4px; }

.rank-list { display: flex; flex-direction: column; }
.rank-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.rank-row:first-child { padding-top: 2px; }
.rank-row:last-child { border-bottom: 0; padding-bottom: 0; }
.rank-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}
.rank-name {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-val { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; font-size: 11.5px; }
.rank-bar {
  height: 5px;
  margin-top: 7px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}
.rank-bar span { display: block; height: 100%; border-radius: 4px; }
.rank-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--muted);
}
.rank-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.data-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.data-stats > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.data-stats span { font-size: 11px; color: var(--muted); }
.data-stats b { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }

.op-note {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .share-bar { width: 64px; }
  .data-stats { grid-template-columns: minmax(0, 1fr); }
  .op-note { max-width: 140px; }
  .table-note { font-size: 10.5px; }
}

@media print {
  table.data th:first-child,
  table.data td:first-child { position: static; }
  .rank-list { break-inside: avoid; }
}

/* Плотнее таблица проектов, чтобы все колонки помещались */
.table-projects { font-size: 12px; }
.table-projects th, .table-projects td { padding-left: 8px; padding-right: 8px; }
.table-projects .cell-name { min-width: 190px; max-width: 250px; }
.table-projects th { font-size: 9.5px; letter-spacing: .03em; }

.donut-flex { justify-content: center; }
.donut-legend { max-width: 300px; }

/* ---------- Мобильные карточки проектов ---------- */

.project-cards { display: none; }

.p-card {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.p-card:hover { border-color: var(--line-strong); }
.p-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.p-card-name { min-width: 0; }
.p-card-name strong { display: block; font-size: 13px; font-weight: 650; line-height: 1.35; }
.p-card-name span { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-card-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 11px 0 10px; }
.p-card-stats span { display: block; font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.p-card-stats b { display: block; margin-top: 2px; font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.p-card-stats b.pos { color: var(--green); }
.p-card-stats b.neg { color: var(--red); }
.p-card-stats b.warn { color: var(--amber); }
.p-card-stats b.muted { color: var(--muted); }
.p-card-foot { display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--muted); }
.p-card-foot .progress { flex: 1; width: auto; }
.p-card-progress-label { flex: none; }
.p-card-rev { margin-left: auto; flex: none; color: var(--ink-2); }

@media (max-width: 980px) {
  .projects-desktop { display: none; }
  .project-cards { display: grid; gap: 8px; }
}

@media (max-width: 760px) {
  .topbar-right { align-items: stretch; }
  .filters { flex: 1 1 100%; order: 1; }
  .topbar-actions { order: 2; width: 100%; justify-content: flex-end; }
}

@media (max-width: 460px) {
  .stats-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .p-card-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .p-card-rev { display: none; }
}

/* На ноутбуках скрываем второстепенную колонку «План/факт», чтобы таблица не скроллилась */
@media (max-width: 1480px) {
  .table-projects th:nth-child(8),
  .table-projects td:nth-child(8) { display: none; }
  .table-projects th, .table-projects td { padding-left: 7px; padding-right: 7px; }
}

@media (max-width: 1480px) {
  .table-projects th, .table-projects td { padding-left: 6px; padding-right: 6px; }
}

.grid-half table.data { min-width: 0; }
@media (max-width: 1480px) {
  .table-projects .cell-name { min-width: 180px; }
}

@media (max-width: 1480px) {
  .table-projects th, .table-projects td { padding-left: 5px; padding-right: 5px; }
}

@media (max-width: 1480px) {
  .table-projects th, .table-projects td { padding-left: 4px; padding-right: 4px; }
}

/* ---------- Объект на продажу: НЗП, счета, этапы ---------- */

.info-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  margin-bottom: 16px;
  border-radius: 12px;
  background: var(--blue-soft);
  border: 1px solid color-mix(in srgb, var(--blue) 22%, transparent);
  font-size: 12px;
  line-height: 1.5;
}
.info-banner .ib-icon {
  width: 20px;
  height: 20px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: color-mix(in srgb, var(--blue) 16%, transparent);
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  margin-top: 1px;
}
.info-banner strong { display: block; color: var(--ink); font-weight: 650; }
.info-banner span { color: var(--muted); }

.wip-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 4px;
}
.wip-item {
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.wip-item > span {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}
.wip-item > b {
  display: block;
  margin-top: 3px;
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.wip-item .progress { width: 100%; margin-top: 7px; }

table.data tr.row-memo td {
  padding-top: 10px;
  color: var(--muted);
  font-style: italic;
  border-top: 1px dashed var(--line-strong);
}

.account-list { display: flex; flex-direction: column; gap: 2px; }
.account-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.account-row:last-child { border-bottom: 0; }
.account-row .acc-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .acc-kind { color: var(--muted); font-size: 10.5px; flex: none; }
.account-row .acc-sum { font-weight: 650; font-variant-numeric: tabular-nums; flex: none; }
.account-total {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line-strong);
  font-size: 12.5px;
  font-weight: 650;
}

.stage-list { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.stage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.stage-row:last-child { border-bottom: 0; }
.stage-row .st-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-row .progress { width: 90px; flex: none; }
.stage-row .st-pct { width: 38px; text-align: right; color: var(--muted); font-size: 11px; flex: none; }
.stage-row .st-plan { width: 92px; text-align: right; color: var(--muted); font-size: 11px; flex: none; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .wip-panel { grid-template-columns: minmax(0, 1fr); }
  .stage-row .st-plan { display: none; }
}
