@import url('/fonts/montserrat.css');

/* ── Токены ─────────────────────────────────────────────────────────────
   Акцент — янтарный #f8a80f с varnakov.site. Намеренно не синий. */
:root {
  --amber:        #f8a80f;
  --amber-deep:   #d98c00;
  --amber-soft:   #fdf1d8;
  --amber-line:   #f2d79a;

  --bg:           #faf8f4;
  --surface:      #ffffff;
  --surface-2:    #f4f1ea;
  --border:       #e8e3d8;
  --border-2:     #d6cfbf;

  --ink:          #1a1815;
  --ink-2:        #4a453d;
  --muted:        #8d867a;

  --ok:           #2f7a3f;
  --ok-bg:        #e9f4e9;
  --warn:         #b5710a;
  --warn-bg:      #fdf1d8;
  --bad:          #bd3a2c;
  --bad-bg:       #fbeae7;

  --sidebar:      #1c1b19;
  --sidebar-2:    #292724;
  --sidebar-ink:  #cfc9be;

  --r:            10px;
  --r-lg:         16px;
  --shadow:       0 1px 2px rgba(26,24,21,.05), 0 8px 24px -12px rgba(26,24,21,.12);
  --font:         'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--amber-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ── Вход ───────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 15% -10%, #fdf1d8 0%, transparent 60%),
    radial-gradient(700px 400px at 100% 110%, #f4f1ea 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 2.2rem 2rem; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.25rem; font-weight: 600; margin-bottom: .25rem; }
.login-card .sub { font-size: .82rem; color: var(--muted); margin-bottom: 1.6rem; }
.login-err {
  background: var(--bad-bg); color: var(--bad); border: 1px solid #f0cfc9;
  border-radius: var(--r); padding: .6rem .8rem; font-size: .82rem; margin-bottom: 1rem;
}

/* ── Каркас приложения ──────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex: 0 0 232px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  transition: width .18s ease, flex-basis .18s ease;
}
.sidebar.collapsed { width: 68px; flex-basis: 68px; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding-inline: 0; }

.brand {
  display: flex; align-items: center; padding: 1.35rem 1.1rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.07); min-height: 62px;
}
/* Компактная марка вместо словомарки в свёрнутом сайдбаре. */
.brand-compact {
  display: none; width: 30px; height: 30px; border-radius: 9px;
  background: var(--amber); color: #241c05; font-weight: 700; font-size: .95rem;
  place-items: center; margin: 0 auto;
}
.sidebar.collapsed .brand { justify-content: center; padding-inline: 0; }
.sidebar.collapsed .brand-logo { display: none; }
.sidebar.collapsed .brand-compact { display: grid; }
.brand-mark {
  width: 32px; height: 32px; flex: none; border-radius: 9px; background: var(--amber);
  color: #241c05; font-weight: 700; font-size: .82rem; letter-spacing: -.02em;
  display: grid; place-items: center;
}
.brand-text { line-height: 1.15; }
.brand-text b { display: block; color: #fff; font-size: .88rem; font-weight: 600; }
/* Ширину/высоту задаём и в атрибутах, и в CSS: без явных размеров
   WebKit обрезает SVG, вставленный через <img>. */
.brand-logo { display: block; width: 110px; height: 16px; }
.brand-text small { font-size: .68rem; color: #8d867a; }

.nav { padding: .7rem .6rem; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: .7rem; padding: .58rem .7rem;
  border-radius: 9px; color: var(--sidebar-ink); font-size: .84rem; font-weight: 500;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.active { background: var(--amber); color: #241c05; font-weight: 600; }
.nav-item svg { width: 17px; height: 17px; flex: none; }
.nav-sep { height: 1px; background: rgba(255,255,255,.07); margin: .55rem .7rem; }

.side-foot {
  padding: .6rem .6rem 1rem; border-top: 1px solid rgba(255,255,255,.07);
  display: flex; flex-direction: column; gap: 2px;
}

/* Аватар с именем — он же вход в профиль. */
.user-chip { padding-block: .5rem; }
.chip-avatar {
  width: 26px; height: 26px; border-radius: 8px; flex: none; object-fit: cover;
  background: var(--amber); color: #241c05; font-size: .68rem; font-weight: 700;
  display: grid; place-items: center; letter-spacing: -.02em;
}
.user-chip .nav-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip.active .chip-avatar { box-shadow: 0 0 0 2px rgba(36,28,5,.25); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 1rem; padding: 1rem 1.7rem;
  border-bottom: 1px solid var(--border); background: rgba(250,248,244,.9);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.05rem; font-weight: 600; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
  color: var(--ink-2); transition: border-color .12s, color .12s;
}
.icon-btn:hover { border-color: var(--border-2); color: var(--ink); }
.content { padding: 1.5rem 1.7rem 4rem; max-width: 1180px; width: 100%; }

/* ── Элементы ───────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1.1rem 1.25rem;
}
.card.pad0 { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; gap: .8rem; padding: .95rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: .92rem; font-weight: 600; }
.card-head .spacer { flex: 1; }

.sec-title {
  font-size: .7rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); display: flex; align-items: center; gap: .8rem; margin: 1.9rem 0 .75rem;
}
.sec-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.sec-title:first-child { margin-top: 0; }

.grid { display: grid; gap: 12px; }
.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)); }

.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 1rem 1.15rem; }
.kpi .lbl { font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kpi .val { font-size: 1.5rem; font-weight: 600; margin-top: .4rem; line-height: 1.15; letter-spacing: -.02em; }
.kpi .val.sm { font-size: 1.18rem; }
.kpi .sub { font-size: .76rem; color: var(--muted); margin-top: .3rem; }
.kpi.accent { background: linear-gradient(160deg, #fffaf0, var(--surface)); border-color: var(--amber-line); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .74rem; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  height: 38px; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--r); padding: 0 11px; width: 100%; transition: border-color .12s, box-shadow .12s;
  font-size: .87rem;
}
.field textarea { height: auto; min-height: 74px; padding: 9px 11px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(248,168,15,.16);
}
.field input[type=number] { text-align: right; }

.btn {
  height: 38px; padding: 0 1rem; border-radius: var(--r); border: 1px solid var(--border-2);
  background: var(--surface); font-size: .84rem; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  transition: border-color .12s, background .12s, opacity .12s;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn.amber { background: var(--amber); border-color: var(--amber); color: #241c05; font-weight: 600; }
.btn.amber:hover { background: var(--amber-deep); border-color: var(--amber-deep); }
.btn.sm { height: 31px; padding: 0 .7rem; font-size: .78rem; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); border-color: transparent; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }

.badge {
  display: inline-block; font-size: .67rem; font-weight: 600; padding: 2px 7px;
  border-radius: 5px; letter-spacing: .03em; border: 1px solid transparent;
}
.badge.amber { background: var(--amber-soft); color: var(--warn); border-color: var(--amber-line); }
.badge.ok    { background: var(--ok-bg); color: var(--ok); border-color: #cbe5cb; }
.badge.bad   { background: var(--bad-bg); color: var(--bad); border-color: #f0cfc9; }
.badge.grey  { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl th {
  font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: .6rem .95rem; background: var(--surface-2);
  text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl th.r, .tbl td.r { text-align: right; }
.tbl td { padding: .62rem .95rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: #fdfcfa; }
.tbl tr.total td { background: var(--surface-2); font-weight: 600; }
.tbl tr.hi td { background: var(--amber-soft); font-weight: 600; }
.tbl tr.hi.neg td { background: var(--bad-bg); color: var(--bad); }
.tbl input { height: 31px; border: 1px solid var(--border-2); border-radius: 7px; padding: 0 8px; text-align: right; width: 100%; max-width: 150px; font-size: .82rem; background: var(--surface); }
.tbl input:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 2px rgba(248,168,15,.16); }
.tbl-scroll { overflow-x: auto; }

.rowlist { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }
.rowitem {
  display: grid; grid-template-columns: 1fr 160px 62px; align-items: center; gap: 14px;
  padding: .6rem 1rem; border-bottom: 1px solid var(--border);
}
.rowitem:last-child { border-bottom: none; }
.rowitem:hover { background: #fdfcfa; }
.rowitem .nm { font-size: .86rem; font-weight: 500; }
.rowitem .nm small { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; margin-top: 2px; line-height: 1.35; }
.rowitem input { height: 33px; border: 1px solid var(--border-2); border-radius: 7px; padding: 0 9px; text-align: right; width: 100%; font-size: .84rem; background: var(--surface-2); }
.rowitem input:focus { outline: none; border-color: var(--amber); background: var(--surface); box-shadow: 0 0 0 2px rgba(248,168,15,.16); }

.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--amber); border-radius: 99px; }
.bar.ok > i { background: var(--ok); }

.stack { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.stack > i { display: block; height: 100%; }

.empty { padding: 2.4rem 1rem; text-align: center; color: var(--muted); font-size: .85rem; }
.chart { width: 100%; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-lbl { fill: var(--muted); font-size: 10px; }

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 100;
  background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: var(--r);
  font-size: .84rem; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px);
  transition: opacity .18s, transform .18s; pointer-events: none; max-width: 340px;
}
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); }

.modal-bg {
  position: fixed; inset: 0; background: rgba(26,24,21,.42); z-index: 60;
  display: grid; place-items: center; padding: 1.2rem; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: var(--r-lg); width: 100%; max-width: 520px;
  box-shadow: 0 24px 64px -20px rgba(26,24,21,.4); max-height: 92vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: .98rem; font-weight: 600; flex: 1; }
.modal-body { padding: 1.2rem 1.3rem; display: grid; gap: 12px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 1rem 1.3rem; border-top: 1px solid var(--border); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 1.1rem; overflow-x: auto; }
.tab {
  padding: .5rem .85rem; font-size: .83rem; font-weight: 500; color: var(--muted);
  border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab.active { color: var(--ink); border-bottom-color: var(--amber); font-weight: 600; }

.notice {
  display: flex; gap: .7rem; align-items: flex-start; padding: .85rem 1rem;
  border-radius: var(--r); font-size: .83rem; line-height: 1.45; margin-bottom: 1rem;
}
.notice.warn { background: var(--warn-bg); color: #7a4d06; border: 1px solid var(--amber-line); }
.notice.info { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }

@media (max-width: 980px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  html { font-size: 14px; }
  .sidebar { width: 60px; flex-basis: 60px; }
  .sidebar .nav-label, .sidebar .brand-text { display: none; }
  .sidebar .nav-item { justify-content: center; padding-inline: 0; }
  /* Словомарка в 60 px не помещается — показываем компактную марку. */
  .sidebar .brand { justify-content: center; padding-inline: 0; }
  .sidebar .brand-logo { display: none; }
  .sidebar .brand-compact { display: grid; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .content, .topbar { padding-inline: 1rem; }
  .rowitem { grid-template-columns: 1fr 120px; }
  .rowitem .cur { display: none; }
}

/* ── Курсы валют ────────────────────────────────────────────────────────── */
.fx-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.fx {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: .8rem .95rem; display: flex; flex-direction: column; gap: .15rem;
}
.fx .code { font-size: .7rem; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.fx .val { font-size: 1.15rem; font-weight: 600; letter-spacing: -.02em; }
.fx .val small { font-size: .72rem; font-weight: 500; color: var(--muted); margin-left: 2px; }
.fx .chg { font-size: .74rem; font-weight: 500; }
.fx-head { display: flex; align-items: baseline; gap: .6rem; }

/* ── Кольцевая диаграмма ────────────────────────────────────────────────── */
.donut-wrap { display: flex; align-items: center; gap: 1.4rem; flex-wrap: wrap; }
.donut { width: 168px; height: 168px; flex: none; position: relative; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .mid {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; pointer-events: none;
}
.donut .mid b { font-size: .95rem; font-weight: 600; letter-spacing: -.02em; }
.donut .mid span { font-size: .68rem; color: var(--muted); }
.donut path { transition: opacity .12s; cursor: default; }
.donut path:hover { opacity: .78; }
.legend { flex: 1; min-width: 190px; display: grid; gap: .5rem; }
.legend-row { display: flex; align-items: center; gap: .6rem; font-size: .82rem; }
.legend-row i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.legend-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .pc { color: var(--muted); font-size: .78rem; }
.legend-row b { white-space: nowrap; }

/* ── Профиль ────────────────────────────────────────────────────────────── */
.avatar-box { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.avatar {
  width: 84px; height: 84px; border-radius: 50%; flex: none; object-fit: cover;
  border: 1px solid var(--border); background: var(--amber); color: #241c05;
  display: grid; place-items: center; font-weight: 700; font-size: 1.6rem;
}
.side-avatar {
  width: 32px; height: 32px; border-radius: 9px; flex: none; object-fit: cover;
}

/* ── Аватар и кнопка обновления в сайдбаре ──────────────────────────────── */
.nav-item.busy { opacity: .55; pointer-events: none; }
.nav-item .spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 980px) { .fx-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) {
  .fx-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .donut-wrap { justify-content: center; }
  .donut { width: 140px; height: 140px; }
}
