/* ============================================================
   MIRRIM for Brands — Cabinet/Admin Design System
   SaaS-дашборд: светлая тема, доверительный, но игровой бренд.
   Подключается тегом <link> на cabinet.html / admin/brand.html /
   me/brand-collection.html. Публичные лендинги (apply/claim) тоже
   используют его поверх Mirrim-палитры.
   ============================================================ */

:root {
  /* — Surfaces & neutrals — */
  --bg:       #F7F8FA;
  --surface:  #FFFFFF;
  --surface-2:#FBFBFD;
  --ink:      #111418;
  --ink-2:    #5B6470;
  --ink-3:    #8A93A0;
  --border:   #E6E8EC;
  --border-2: #EFF1F4;

  /* — Status — */
  --ok:    #1F9D55;  --ok-bg:    #E7F6EE;
  --danger:#D64545;  --danger-bg:#FBEAEA;
  --warn:  #C77700;  --warn-bg:  #FBF1E1;
  --info:  #2563EB;  --info-bg:  #E8F0FE;

  /* — Brand accent (default; overridden per-brand via brandTheme) — */
  --brand:    #5B5BD6;
  --brand-600:#4B4BC4;
  --brand-50: #EEEEFB;
  --brand-on: #FFFFFF;

  /* — Mirrim house accents (public/marketing flourish) — */
  --mirrim-purple: #7C3AED;
  --mirrim-lime:   #C6F432;

  /* — Type — */
  --font: "Manrope", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* — Radii — */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 20px; --r-pill: 999px;

  /* — Elevation — */
  --sh-1: 0 1px 3px rgba(17,20,24,.08);
  --sh-2: 0 4px 16px rgba(17,20,24,.08);
  --sh-3: 0 18px 50px -16px rgba(17,20,24,.28);

  /* — Spacing scale (8pt) — */
  --s1:8px; --s2:16px; --s3:24px; --s4:32px; --s5:40px;
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::selection { background: color-mix(in oklch, var(--brand) 24%, transparent); }

/* ── App shell ── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 24px; }

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,255,255,.86); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-in { height: 64px; display: flex; align-items: center; gap: 20px; }
.brandmark { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; }
.brandmark .logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--mirrim-purple); color: var(--mirrim-lime); font-weight: 800; font-size: 17px;
}
.brandmark .sub { font-weight: 600; color: var(--ink-3); font-size: 13px; }
.topbar-spacer { flex: 1; }
.topbar-acct { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand); font-weight: 700; font-size: 13px;
}

/* ── Page header ── */
.page-head { padding: 28px 0 4px; }
.page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.page-head .crumbs { font-size: 13px; color: var(--ink-3); margin-bottom: 8px; display: flex; gap: 6px; align-items: center; }
.page-head .lede { color: var(--ink-2); margin-top: 6px; max-width: 60ch; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 18px 0 24px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; background: none; border: none; cursor: pointer;
  padding: 12px 14px; font-weight: 600; font-size: 14px; color: var(--ink-2);
  border-bottom: 2px solid transparent; white-space: nowrap; transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.tab .count { font-size: 12px; color: var(--ink-3); margin-left: 6px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1); }
.card-pad { padding: 20px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-2); }
.card-h h3 { font-size: 16px; font-weight: 700; }
.card-h .meta { font-size: 13px; color: var(--ink-3); }

/* ── Stat tiles ── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px 20px; box-shadow: var(--sh-1); }
.tile .k { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.tile .v { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin-top: 8px; line-height: 1; }
.tile .d { font-size: 12px; margin-top: 8px; color: var(--ink-3); }
.tile .d.up { color: var(--ok); } .tile .d.down { color: var(--danger); }
.tile .ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: var(--r-pill); cursor: pointer;
  font-weight: 700; font-size: 14px; border: 1px solid transparent; white-space: nowrap;
  transition: transform .15s ease, box-shadow .15s ease, background .15s, border-color .15s, color .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--p { background: var(--brand); color: var(--brand-on); box-shadow: 0 8px 18px -10px color-mix(in oklch, var(--brand) 80%, black); }
.btn--p:hover:not(:disabled) { background: var(--brand-600); transform: translateY(-1px); }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn--ghost:hover:not(:disabled) { border-color: var(--ink-3); }
.btn--danger { background: var(--danger-bg); color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn--sm { height: 34px; padding: 0 14px; font-size: 13px; }
.btn--lg { height: 50px; padding: 0 26px; font-size: 16px; }
.btn--block { width: 100%; }
.btn--lime { background: var(--mirrim-lime); color: #0A0A0A; }
.btn--lime:hover:not(:disabled) { filter: brightness(1.04); transform: translateY(-1px); }

/* ── Forms ── */
.field { display: block; margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field .req { color: var(--danger); }
.input, .textarea, .select {
  width: 100%; height: 44px; padding: 0 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md); font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; padding: 12px 14px; min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand) 18%, transparent); }
.field.invalid .input, .field.invalid .textarea { border-color: var(--danger); }
.field .err { font-size: 12px; color: var(--danger); margin-top: 6px; display: none; }
.field.invalid .err { display: block; }
.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 560px){ .form-grid { grid-template-columns: 1fr; } }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: 12px; font-weight: 700; line-height: 1;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--ok { color: var(--ok); background: var(--ok-bg); }
.badge--danger { color: var(--danger); background: var(--danger-bg); }
.badge--warn { color: var(--warn); background: var(--warn-bg); }
.badge--info { color: var(--info); background: var(--info-bg); }
.badge--mute { color: var(--ink-2); background: var(--border-2); }
.badge--brand { color: var(--brand); background: var(--brand-50); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 13px 14px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
.tbl tbody tr:nth-child(odd) td { background: var(--surface-2); }
.tbl tbody tr:hover td { background: var(--brand-50); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Responsive table → cards (add data-label to td) */
@media (max-width: 680px){
  .tbl.responsive thead { display: none; }
  .tbl.responsive, .tbl.responsive tbody, .tbl.responsive tr, .tbl.responsive td { display: block; width: 100%; }
  .tbl.responsive tr { border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 12px; overflow: hidden; }
  .tbl.responsive tbody tr:nth-child(odd) td { background: var(--surface); }
  .tbl.responsive td { display: flex; justify-content: space-between; gap: 16px; text-align: right; border-bottom: 1px solid var(--border-2); }
  .tbl.responsive td::before { content: attr(data-label); font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; text-align: left; }
  .tbl.responsive td.actions { justify-content: flex-end; }
  .tbl.responsive td.actions::before { content: ""; }
}

/* ── Progress ── */
.progress { height: 8px; border-radius: var(--r-pill); background: var(--border-2); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: var(--brand); transition: width .4s cubic-bezier(.2,.7,.3,1); }
.progress.lime > i { background: var(--mirrim-lime); }
.progress.ok > i { background: var(--ok); }

/* ── State blocks ── */
.state { display: grid; place-items: center; text-align: center; padding: 56px 24px; color: var(--ink-2); }
.state .glyph { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); margin-bottom: 16px; }
.state h4 { font-size: 17px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.state p { max-width: 42ch; margin-bottom: 16px; }
.state--error .glyph { background: var(--danger-bg); color: var(--danger); }

/* Skeleton */
.sk { background: linear-gradient(90deg, var(--border-2) 25%, #f3f4f7 37%, var(--border-2) 63%); background-size: 400% 100%; animation: skl 1.3s ease infinite; border-radius: 8px; }
@keyframes skl { 0%{ background-position: 100% 0; } 100%{ background-position: -100% 0; } }
.sk-line { height: 12px; margin: 8px 0; }
.sk-tile { height: 96px; border-radius: var(--r-lg); }

/* Spinner */
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--brand); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ── */
#toaster { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r-md);
  background: var(--ink); color: #fff; box-shadow: var(--sh-3); font-size: 14px; font-weight: 600;
  animation: toastIn .2s ease both;
}
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.toast--error .dot { background: var(--danger-soft, #FCA5A5); }
.toast--error { background: #2A1414; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ── Modal ── */
.modal-back {
  position: fixed; inset: 0; z-index: 80; background: rgba(17,20,24,.42);
  display: grid; place-items: center; padding: 20px; animation: fade .15s ease both;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 440px; background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--sh-3); padding: 24px; animation: pop .18s cubic-bezier(.2,.7,.3,1) both;
}
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } }
.modal h3 { font-size: 19px; font-weight: 800; margin-bottom: 8px; }
.modal p { color: var(--ink-2); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Helpers ── */
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.muted { color: var(--ink-2); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.stack { display: grid; gap: 16px; }
.stack-sm { display: grid; gap: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.hidden { display: none !important; }
.pill-tabs { display: inline-flex; background: var(--border-2); border-radius: var(--r-pill); padding: 4px; gap: 4px; }
.pill-tabs button { appearance: none; border: none; background: none; cursor: pointer; padding: 7px 14px; border-radius: var(--r-pill); font-weight: 600; font-size: 13px; color: var(--ink-2); }
.pill-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin-bottom: 12px; }

/* Demo ribbon */
.demo-ribbon {
  position: fixed; left: 0; bottom: 0; z-index: 70; font-size: 11px; font-weight: 700;
  background: var(--warn-bg); color: var(--warn); padding: 4px 12px; border-top-right-radius: 8px;
  border: 1px solid var(--warn); border-left: none; border-bottom: none; letter-spacing: .03em;
}

/* Footer */
.foot { padding: 32px 0; color: var(--ink-3); font-size: 13px; border-top: 1px solid var(--border); margin-top: 48px; }

@media (max-width: 600px){
  .page-head h1 { font-size: 22px; }
  .tile .v { font-size: 26px; }
}
