/* ============================================================================
   Компоненты веб-админки TarsAuto. Порядок: reset → base → layout → sidebar →
   topbar → content → карточки → кнопки → поля → алерты → логин → адаптив.
   Все значения — через токены из tokens.css. Никакого inline-CSS в шаблонах
   (CSP: style-src 'self', без unsafe-inline).
   ============================================================================ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; letter-spacing: -.011em; }
h1 { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: -.022em; text-wrap: balance; }
h2 { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.02em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; flex-shrink: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 3px; }

.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- LAYOUT --- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.app.is-rail { --sidebar-w: 68px; }

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

/* --------------------------------------------------------------- SIDEBAR --- */

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1rem .7rem;
  overflow-x: hidden;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .4rem .5rem 1.1rem;
  color: #fff;
  font-weight: 700;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.sidebar__brand .glyph {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: .8rem;
  font-weight: 700;
}
.is-rail .sidebar__brand .word { opacity: 0; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
  padding: .9rem .7rem .35rem;
  white-space: nowrap;
}
.is-rail .nav__label { opacity: 0; }

.nav a {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem .65rem;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--sidebar-hover); color: #EDE7E0; text-decoration: none; }
.nav a[aria-current="page"] {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  font-weight: 600;
}
.nav a[aria-current="page"] svg { color: var(--brand); }
.nav a .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav a.is-disabled { pointer-events: none; opacity: .55; }
.is-rail .nav a .txt,
.is-rail .nav a .soon { opacity: 0; }

.soon {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--faint);
  border: 1px solid var(--sidebar-line);
  border-radius: var(--r-pill);
  padding: .1rem .4rem;
}

.sidebar__foot {
  margin-top: auto;
  padding-top: .8rem;
  border-top: 1px solid var(--sidebar-line);
}
.userchip {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .6rem;
  white-space: nowrap;
}
.userchip .av {
  width: 28px; height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand-wash);
  color: var(--brand);
  display: grid;
  place-items: center;
  font-size: .72rem;
  font-weight: 700;
}
.userchip .who { overflow: hidden; }
.userchip .who b { display: block; font-size: var(--fs-xs); color: #EDE7E0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.userchip .who span { font-size: 10px; color: var(--faint); }
.is-rail .userchip .who { opacity: 0; }

.logout {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  margin-top: .3rem;
  padding: .5rem .65rem;
  background: transparent;
  border: 0;
  border-radius: 9px;
  color: var(--sidebar-text);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
}
.logout:hover { background: var(--sidebar-hover); color: #fff; }
.is-rail .logout .txt { opacity: 0; }

/* backdrop for the off-canvas drawer on mobile */
.nav-scrim { display: none; }

/* ---------------------------------------------------------------- TOPBAR --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: 0 1.3rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar__title {
  flex: 1;
  font-weight: 600;
  font-size: var(--fs-lg);
  letter-spacing: -.015em;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--line); }
.icon-btn [data-theme-icon] { display: contents; }
.toggle-eye [data-eye] { display: contents; }

/* -------------------------------------------------------------- CONTENT --- */

.content {
  flex: 1;
  padding: 1.6rem;
  max-width: 1160px;
  width: 100%;
}
@media (min-width: 1100px) { .content { padding: 2rem 2.2rem; } }

.page-head { margin-bottom: 1.6rem; }
.page-head p { color: var(--muted); margin-top: .35rem; }
.page-head p .num { color: var(--text); }

/* ---------------------------------------------------------------- CARDS --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--sh-1);
}
.card > h3 { font-size: var(--fs-base); margin-bottom: .8rem; }

.sec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: .9rem;
}
.sec-card {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 1rem;
  box-shadow: var(--sh-1);
}
.sec-card .ico {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
}
.sec-card h4 { font-size: var(--fs-base); }
.sec-card p { font-size: var(--fs-xs); color: var(--muted); }
.sec-card .tag {
  position: absolute;
  top: .8rem; right: .8rem;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--faint);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: .12rem .45rem;
}

/* live rates widget */
.rates { margin-top: 1.4rem; }
.rates__head {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .4rem;
}
.rates__head .stamp { font-size: var(--fs-xs); color: var(--faint); }
.rates table { width: 100%; border-collapse: collapse; }
.rates th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--faint);
  padding: .3rem .4rem;
}
.rates td { padding: .5rem .4rem; border-top: 1px solid var(--line); font-size: var(--fs-sm); }
.rates td:last-child, .rates th:last-child { text-align: right; }
.rates .cur { display: flex; align-items: center; gap: .55rem; font-weight: 500; }
.rates .badge {
  width: 22px; height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
}
/* Декоративные цвета валют — узнаваемые, НЕ несут смысла (совпадают по духу
   с CURRENCY_BADGE в src/rates/rates_image.py). С семантикой ok/danger не путать. */
.badge--usd { background: #C0392B; }
.badge--eur { background: #2F6FB0; }
.badge--cny { background: #C77D1E; }
.badge--jpy { background: #2E8B8B; }
.badge--krw { background: #7A5AA8; }

.empty-hint {
  margin-top: 1.4rem;
  font-size: var(--fs-sm);
  color: var(--muted);
}

/* -------------------------------------------------------------- BUTTONS --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font: inherit;
  font-weight: 600;
  font-size: var(--fs-base);
  line-height: 1;
  cursor: pointer;
  border-radius: var(--r);
  padding: .64rem 1.1rem;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--brand-press); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn--ghost:hover:not(:disabled) { border-color: var(--faint); background: var(--surface-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--block { width: 100%; }
.btn--lg { padding: .8rem 1.2rem; }

/* ---------------------------------------------------------------- FIELDS --- */

.field { margin-bottom: 1rem; }
.field > label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  margin-bottom: .4rem;
}
.input-shell { position: relative; display: flex; }
.input {
  width: 100%;
  font: inherit;
  font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: .62rem .8rem;
}
.input::placeholder { color: var(--faint); }
.input:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
  background: var(--surface);
}
.input.has-toggle { padding-right: 2.6rem; }

.toggle-eye {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
}
.toggle-eye:hover { color: var(--text); background: var(--surface); }

/* ---------------------------------------------------------------- ALERTS --- */

.alert {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  font-size: var(--fs-sm);
  padding: .65rem .8rem;
  border-radius: var(--r);
  border: 1px solid;
  margin-bottom: 1rem;
}
.alert svg { margin-top: 1px; }
.alert__text { flex: 1; }
.alert__close {
  border: 0;
  background: transparent;
  color: inherit;
  opacity: .7;
  cursor: pointer;
  padding: 0;
  line-height: 0;
}
.alert__close:hover { opacity: 1; }
.alert--error { background: var(--danger-wash); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.alert--warn  { background: var(--warn-wash);  border-color: color-mix(in srgb, var(--warn) 30%, transparent);  color: var(--warn); }
.alert--ok    { background: var(--ok-wash);    border-color: color-mix(in srgb, var(--ok) 30%, transparent);    color: var(--ok); }
.alert--info  { background: var(--surface-2);  border-color: var(--line); color: var(--muted); }

/* ---------------------------------------------------------------- LOGIN --- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(140% 90% at 50% -10%, var(--brand-wash) 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 2rem 1.9rem 1.8rem;
  box-shadow: var(--sh-2);
}
.brandmark {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin-bottom: 1.4rem;
}
.brandmark .glyph {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .02em;
  box-shadow: 0 2px 10px var(--brand-ring);
}
.brandmark .word { font-weight: 700; font-size: var(--fs-lg); letter-spacing: -.02em; }
.brandmark .word span { display: block; font-weight: 500; font-size: var(--fs-xs); color: var(--muted); letter-spacing: 0; }

.login-foot {
  margin-top: 1.1rem;
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--faint);
}

/* ---------------------------------------------------------------- ADAPTIVE --- */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    z-index: 40;
    left: 0; top: 0;
    width: 264px;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--sh-pop);
  }
  .app.is-rail { --sidebar-w: 244px; }
  .app.is-rail .sidebar { transform: none; }
  .app.is-rail .sidebar .word,
  .app.is-rail .nav__label,
  .app.is-rail .nav a .txt,
  .app.is-rail .nav a .soon,
  .app.is-rail .userchip .who,
  .app.is-rail .logout .txt { opacity: 1; }

  .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, .4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .app.is-rail .nav-scrim { opacity: 1; pointer-events: auto; }

  .content { padding: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
