:root {
  --paper: #F3F6F5;
  --surface: #FFFFFF;
  --ink: #17262B;
  --ink-2: #4E5F63;
  --line: #DCE4E2;
  --fresh: #2F7D6D;
  --fresh-soft: #DCEFE9;
  --amber: #A86F0E;
  --amber-soft: #FBF0D9;
  --danger: #B54141;
  --danger-soft: #F8E3E3;
  --side: #17262B;
  --side-ink: #E7EFED;
  --radius: 10px;
  --font: "Onest", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111A1C; --surface: #182427; --ink: #E4ECEA; --ink-2: #9DB0AD; --line: #2A3A3D;
    --fresh: #5BBFA6; --fresh-soft: #1D3B35; --amber: #E2B04F; --amber-soft: #3A2F17;
    --danger: #E07474; --danger-soft: #3D2222; --side: #0C1416; --side-ink: #D9E5E2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--paper); font-variant-numeric: tabular-nums; }
a { color: var(--fresh); }
h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .9rem; }
:focus-visible { outline: 2px solid var(--fresh); outline-offset: 2px; }

/* Обвивка */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 1.4rem 1rem; display: flex; flex-direction: column; gap: 1.6rem; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--side-ink); text-decoration: none; padding: .55rem .75rem; border-radius: 8px; opacity: .78; }
.side nav a:hover { opacity: 1; background: rgba(255,255,255,.06); }
.side nav a.on { opacity: 1; background: rgba(91,191,166,.18); box-shadow: inset 3px 0 0 #5BBFA6; }
.me { margin-top: auto; display: flex; flex-direction: column; font-size: .85rem; gap: 2px; }
.me span { opacity: .6; }
.me a { color: #5BBFA6; margin-top: .4rem; }
.main { padding: 2rem clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 1280px; width: 100%; }

.brand { display: flex; align-items: center; gap: .65rem; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand small { display: block; font-weight: 500; font-size: .72rem; opacity: .6; }
.brand-mark { width: 28px; height: 28px; border-radius: 50%; background: conic-gradient(from 210deg, #5BBFA6 0 50%, #2F7D6D 50% 75%, #E7EFED 75%); box-shadow: inset 0 0 0 6px var(--side); flex: none; }
.auth .brand-mark { box-shadow: inset 0 0 0 6px var(--surface); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.count { font-size: 1rem; font-weight: 500; color: var(--ink-2); margin-left: .3rem; }

/* Панели и решетки */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem 1.4rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.2rem; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 1.2rem; }
.layout-client { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 1.2rem; align-items: start; }

/* Статистика: една лента, не карти */
.stats { display: flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1.2rem; overflow: hidden; }
.stat { flex: 1 1 140px; padding: 1rem 1.3rem; text-decoration: none; color: var(--ink); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.stat:last-child { border-right: 0; }
.stat b { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat span { color: var(--ink-2); font-size: .85rem; }
a.stat:hover { background: var(--paper); }
.stat-active b { color: var(--fresh); }
.stat-money { flex-basis: 220px; background: var(--fresh-soft); }

/* Списъци */
.rows, .feed { list-style: none; margin: 0; padding: 0; }
.rows li { display: grid; grid-template-columns: 1fr auto auto; gap: 1rem; padding: .6rem 0; border-top: 1px solid var(--line); align-items: center; }
.rows li:first-child { border-top: 0; }
.feed li { padding: .8rem 0; border-top: 1px solid var(--line); position: relative; }
.feed li:first-child { border-top: 0; padding-top: 0; }
.feed p { margin: .15rem 0 .25rem; white-space: normal; }
.cname { display: inline-flex; align-items: center; gap: .55rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.cname i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cname.big i { width: 16px; height: 16px; border-radius: 5px; }
a.cname:hover { color: var(--fresh); }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.empty { color: var(--ink-2); margin: 0; }

/* Таблица */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel .table-wrap { border: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; font-weight: 600; color: var(--ink-2); padding: .7rem 1rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.off td { opacity: .5; }
.num { text-align: right; white-space: nowrap; }

/* Етикети */
.tag { display: inline-block; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--paper); color: var(--ink-2); white-space: nowrap; }
.tag-active { background: var(--fresh-soft); color: var(--fresh); }
.tag-lead { background: var(--amber-soft); color: var(--amber); }
.tag-former { background: var(--danger-soft); color: var(--danger); }
.tag-portal { background: var(--fresh-soft); color: var(--fresh); margin-left: .4rem; }

/* Форми */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--ink-2); margin-bottom: .9rem; }
input, select, textarea { font: inherit; font-size: .95rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--fresh); box-shadow: 0 0 0 3px var(--fresh-soft); }
input[type=color] { padding: 2px; height: 40px; }
input[type=checkbox] { width: auto; accent-color: var(--fresh); }
textarea { resize: vertical; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.span-2 { grid-column: span 2; }
.form h2:not(:first-of-type) { margin-top: 1.2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend { font-size: .85rem; font-weight: 500; color: var(--ink-2); margin-bottom: .5rem; padding: 0; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem; }
.checks legend { width: 100%; }
.checks label { flex-direction: row; align-items: center; gap: .4rem; margin: 0; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); cursor: pointer; }
.checks label:has(input:checked) { background: var(--fresh-soft); border-color: var(--fresh); }
label.inline { flex-direction: row; align-items: center; gap: .5rem; margin: 0; }
.actions { display: flex; gap: 1rem; align-items: center; margin-top: .4rem; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .5rem; }
.note-form { margin-bottom: 1rem; }
.inline-del { display: inline; margin-left: .6rem; }

/* Финансов блок: отличен визуално, защото е само за администратора */
.private { margin-top: 1.4rem; padding: 1.1rem 1.2rem .3rem; border-radius: var(--radius); background: var(--amber-soft); border: 1px dashed var(--amber); }
.form .private h2 { margin-top: 0; padding-top: 0; border-top: 0; display: flex; align-items: center; gap: .6rem; }
.lock { font-size: .75rem; font-weight: 500; color: var(--amber); }
.danger-zone { border-color: var(--danger-soft); }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1 1 260px; width: auto; }
.filters select { width: auto; }

/* Бутони */
.btn { font: inherit; font-weight: 600; font-size: .92rem; background: var(--fresh); color: #fff; border: 1px solid var(--fresh); padding: .6rem 1.1rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { filter: brightness(1.08); }
.btn-sm { padding: .4rem .8rem; font-size: .85rem; }
.btn-ghost { background: transparent; color: var(--fresh); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--fresh); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--danger); }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--fresh-soft); color: var(--ink); border-left: 4px solid var(--fresh); }
.flash-err { background: var(--danger-soft); border-left-color: var(--danger); }

.dl { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; margin: .8rem 0 0; }
.dl dt { color: var(--ink-2); }
.dl dd { margin: 0; }

/* Вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; width: 100%; max-width: 380px; }
.auth-card.wide { max-width: 520px; }
.auth-card .brand { margin-bottom: 1.6rem; }
.auth-card .btn { width: 100%; margin-top: .4rem; }
.auth-card h1 { margin-bottom: 1.2rem; font-size: 1.4rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .8rem 1.2rem; padding: .9rem 1rem; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .me { margin: 0 0 0 auto; flex-direction: row; gap: .8rem; align-items: center; }
  .me a { margin: 0; }
  .layout-client { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
