:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #faf8f5;
  --text: #1c1d21;
  --muted: #6f6f76;
  --line: #e6e2db;
  --accent: #c8781e;
  --accent-soft: #f6e8d6;
  --up: #c2410c;
  --up-bg: #fde8dc;
  --down: #0f766e;
  --down-bg: #d9f1ed;
  --err: #b42318;
  --err-bg: #fde7e4;
  --ok-bg: #e2f3e8;
  --ok: #16794a;
  --info-bg: #eaf0fb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 25, 15, .05), 0 4px 16px rgba(30, 25, 15, .04);
  --side: 232px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --panel: #1b1c21; --panel-2: #212329; --text: #ecebe8; --muted: #9a9aa2;
    --line: #2c2e35; --accent: #e7a04a; --accent-soft: #3a2c1b; --up: #fb923c; --up-bg: #3b2418;
    --down: #2dd4bf; --down-bg: #123330; --err: #f87171; --err-bg: #3b1d1d; --ok-bg: #16301f; --ok: #4ade80;
    --info-bg: #1b2538; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
code, pre { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.center { justify-content: center; }
.ic { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.link { color: var(--accent); }
.link .ic { width: 13px; height: 13px; }

/* ---------- каркас ---------- */
.side {
  position: fixed; inset: 0 auto 0 0; width: var(--side); padding: 18px 14px;
  background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 34px; height: 34px; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { color: var(--muted); font-size: 12px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; gap: 11px; align-items: center; padding: 9px 11px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.side nav a:hover { background: var(--panel-2); color: var(--text); }
.side nav a.on { background: var(--accent-soft); color: var(--text); }
.side nav a.on .ic { color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.main { margin-left: var(--side); padding: 26px 30px 60px; max-width: 1320px; }
.topbar, .bottomnav { display: none; }

@media (max-width: 900px) {
  .side { display: none; }
  .main { margin: 0; padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .topbar {
    display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 10;
    padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  }
  .topbar .brand img { width: 28px; height: 28px; }
  .topbar-actions { display: flex; gap: 6px; align-items: center; }
  .bottomnav {
    display: flex; position: fixed; inset: auto 0 0 0; z-index: 10; background: var(--panel); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
  .bottomnav a .ic { width: 22px; height: 22px; }
  .bottomnav a.on { color: var(--accent); }
  h1 { font-size: 21px; }
}

/* ---------- элементы ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 + div { margin-top: 3px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 15px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { height: 32px; padding: 0 11px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.busy { opacity: .6; pointer-events: none; }
.btn.busy .ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.iconbtn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.iconbtn:hover, .iconbtn.on { background: var(--panel); border-color: var(--line); color: var(--text); }
.iconbtn.danger:hover { color: var(--err); }
.seg { display: inline-flex; padding: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.seg a { padding: 5px 11px; border-radius: 7px; color: var(--muted); font-weight: 550; font-size: 13px; }
.seg a.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.seg.small a { padding: 3px 9px; font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.block { margin-top: 26px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 26px; }
.two-col > .block { margin-top: 0; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--ok-bg); font-size: 14px; }
.flash.err { background: var(--err-bg); color: var(--err); }
.flash.info { background: var(--info-bg); }
.tag { display: inline-block; padding: 0 6px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line); font-size: 11px; text-transform: uppercase; }
.chg { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.chg.up { background: var(--up-bg); color: var(--up); }
.chg.down { background: var(--down-bg); color: var(--down); }
.chg.flat { background: var(--panel-2); color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.err { background: var(--err); } .dot.off { background: var(--line); }

/* ---------- курсы ---------- */
.fxbar { display: flex; flex-wrap: wrap; gap: 6px 22px; padding: 11px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; }
.fx-title { font-weight: 650; }

/* ---------- карточки ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; min-height: 148px;
}
a.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card.stale { opacity: .78; }
.card.stale .card-foot .muted::after { content: " ⏳"; }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-name { font-weight: 650; font-size: 14px; }
.card-main { display: flex; align-items: baseline; gap: 4px; margin-top: 4px; }
.big { font-size: 27px; font-weight: 700; letter-spacing: -.02em; }
.unit { color: var(--muted); font-size: 13px; }
.card-sub { font-size: 14px; color: var(--text); opacity: .85; }
.card-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; margin-top: auto; padding-top: 6px; }
.spark { width: 92px; height: 26px; color: var(--accent); flex: none; }
.others { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 4px; color: var(--muted); }
.minor-groups { display: flex; flex-wrap: wrap; gap: 0 18px; }
.minor-groups .cards { grid-template-columns: repeat(var(--n), minmax(232px, 280px)); }
@media (max-width: 600px) {
  .minor-groups { display: block; }
  .cards, .minor-groups .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 11px 12px 10px; min-height: 0; border-radius: 12px; }
  .big { font-size: 21px; }
  .card-name { font-size: 13px; }
  .card-sub { font-size: 12.5px; }
  .card-foot .spark { display: none; }
  .card-foot .small, .others { font-size: 11.5px; }
  .card-top .chg { font-size: 11px; padding: 0 5px; }
}
.card.empty { border-style: dashed; box-shadow: none; background: transparent; }
.card-empty { color: var(--muted); font-size: 20px; font-weight: 600; margin: 6px 0; }

/* ---------- регионы ---------- */
.regions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.region { padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); }
.region:hover { border-color: var(--accent); }
.region-name { font-weight: 600; font-size: 13.5px; }
.region-val { font-size: 19px; font-weight: 700; margin: 2px 0 4px; }
.region-flags { display: flex; flex-wrap: wrap; gap: 3px 10px; }

/* ---------- формы ---------- */
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; height: 40px; padding: 0 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font: inherit;
}
textarea { height: auto; padding: 9px 11px; font: 13px/1.45 ui-monospace, Menlo, monospace; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label > span, .filters label > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 560px) { .row3 { grid-template-columns: 1fr 1fr; } .row3 > :first-child { grid-column: 1 / -1; } }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.head-actions input[type=search] { width: 200px; height: 38px; }
.filters { display: flex; flex-direction: column; gap: 12px; }
.filters summary { cursor: pointer; font-weight: 550; }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filter-row label { min-width: 130px; }
.series-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.series-picker fieldset { border: 1px solid var(--line); border-radius: 11px; padding: 8px 12px 10px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.series-picker legend { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.pinrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pinrow .order { width: 62px; height: 30px; padding: 0 6px; text-align: center; }
.settings { display: flex; flex-direction: column; gap: 18px; }
.settings .two-col { margin-top: 0; }
.sticky-save { position: sticky; bottom: 12px; display: flex; justify-content: flex-end; }
@media (max-width: 900px) { .sticky-save { bottom: calc(80px + env(safe-area-inset-bottom)); } }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

/* ---------- таблицы ---------- */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; background: var(--panel-2); }
.tbl th, .tbl td { padding: 8px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; }
.tbl.small { font-size: 12.5px; }
.note-cell { max-width: 380px; }
.code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* ---------- графики ---------- */
.chart-panel { margin-top: 16px; }
.chart-wrap { position: relative; height: 380px; }
@media (max-width: 600px) { .chart-wrap { height: 300px; } }

/* ---------- мир ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 13.5px; font-weight: 550; }
.tabs a.on { background: var(--text); color: var(--panel); border-color: var(--text); }
.tabs a.on .muted { color: inherit; opacity: .6; }
.countries { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.country { padding: 0; }
.country summary {
  display: grid; grid-template-columns: 28px minmax(140px, 1.3fr) 1fr auto auto; gap: 12px; align-items: center;
  padding: 11px 16px; cursor: pointer; list-style: none;
}
.country summary::-webkit-details-marker { display: none; }
.country[open] summary { border-bottom: 1px solid var(--line); }
.country .tablewrap { border: 0; border-radius: 0 0 var(--radius) var(--radius); }
.c-flag { font-size: 20px; }
.country summary.grade-sum { grid-template-columns: minmax(150px, 1.2fr) repeat(4, minmax(90px, 1fr)); }
.g-cell { display: flex; flex-direction: column; text-align: right; white-space: nowrap; }
@media (max-width: 700px) { .country summary.grade-sum { grid-template-columns: 1fr 1fr; } .grade-sum .c-name { grid-column: 1 / -1; } .g-cell { text-align: left; } }
.c-name { font-weight: 600; }
.c-bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.c-bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; opacity: .75; }
.c-val { text-align: right; white-space: nowrap; }
.pad { padding: 10px 16px; }
@media (max-width: 700px) {
  .country summary { grid-template-columns: 26px 1fr auto; }
  .c-bar, .c-range { display: none; }
}

/* ---------- источники ---------- */
.srcs { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.src-head { display: flex; gap: 11px; align-items: center; }
.src-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.src-msg { margin-top: 8px; word-break: break-word; }

/* ---------- вход ---------- */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; text-align: center; align-items: center; }
.login-card h1 { margin-top: 4px; }
.login-card p { margin: -10px 0 4px; }
.login-card label { width: 100%; text-align: left; }
.login-card label span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.login-card .flash { width: 100%; }

/* ---------- импорт ЕС ---------- */
.tabs-label { align-self: center; margin-right: 4px; }
.tbl tr.hl td { background: var(--accent-soft); }
.tbl tr.total td { border-top: 2px solid var(--line); background: var(--panel-2); }
.link-plain:hover { color: var(--accent); }
