/* ==========================================================================
   MadStore Admin — stylesheet
   Same identity as the storefront: dark = black + purple/magenta, light = white + gold
   ========================================================================== */

:root {
  --font-display: "Bodoni Moda", "Didot", "Times New Roman", serif;
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --side-w: 264px;
  color-scheme: dark light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050308;
  --glow: radial-gradient(60rem 36rem at 0% -10%, rgba(106, 27, 184, .4), transparent 62%), radial-gradient(46rem 30rem at 100% 0, rgba(230, 26, 157, .2), transparent 60%);
  --side-bg: rgba(255, 255, 255, .03);
  --surface: rgba(255, 255, 255, .05);
  --surface-2: rgba(255, 255, 255, .085);
  --modal-bg: #0e0716;
  --line: rgba(255, 255, 255, .13);
  --line-strong: rgba(255, 255, 255, .26);
  --text: #fff;
  --text-soft: rgba(255, 255, 255, .88);
  --muted: rgba(255, 255, 255, .66);
  --accent: #ff4fb8;
  --accent-strong: #e61a9d;
  --grad: linear-gradient(120deg, #6a1bb8 0%, #c4189f 55%, #ff2fa6 100%);
  --on-grad: #fff;
  --focus: #ff8fd2;
  --ok: #5eea9a; --ok-bg: rgba(94, 234, 154, .14);
  --warn: #ffd166; --warn-bg: rgba(255, 209, 102, .14);
  --bad: #ff8a98; --bad-bg: rgba(255, 138, 152, .14);
  --shadow: 0 28px 70px rgba(0, 0, 0, .6);
  --ring: 0 0 0 4px rgba(255, 79, 184, .24);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fff;
  --glow: radial-gradient(56rem 32rem at 0% -10%, rgba(212, 175, 55, .22), transparent 60%), radial-gradient(44rem 28rem at 100% 0, rgba(212, 175, 55, .1), transparent 60%);
  --side-bg: #fdfaf1;
  --surface: #fff;
  --surface-2: #faf6ea;
  --modal-bg: #fff;
  --line: rgba(184, 137, 43, .34);
  --line-strong: rgba(184, 137, 43, .7);
  --text: #000;
  --text-soft: rgba(0, 0, 0, .84);
  --muted: rgba(0, 0, 0, .64);
  --accent: #8a6410;
  --accent-strong: #b8892b;
  --grad: linear-gradient(120deg, #f2d97f 0%, #d4af37 50%, #b8892b 100%);
  --on-grad: #000;
  --focus: #8a6410;
  --ok: #146c2e; --ok-bg: rgba(20, 108, 46, .1);
  --warn: #7a5600; --warn-bg: rgba(184, 137, 43, .16);
  --bad: #b3122d; --bad-bg: rgba(179, 18, 45, .1);
  --shadow: 0 24px 56px rgba(120, 90, 20, .2);
  --ring: 0 0 0 4px rgba(184, 137, 43, .25);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  position: relative; margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 500 15px/1.55 var(--font-ui); -webkit-font-smoothing: antialiased;
}
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--glow); pointer-events: none; }
body:has(dialog[open]) { overflow: hidden; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { overflow-wrap: anywhere; }
::selection { background: var(--accent-strong); color: var(--on-grad); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.icon { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border: 1px solid transparent; border-radius: 999px; background: none;
  font-weight: 800; font-size: 14px; line-height: 1; white-space: nowrap;
  transition: filter .2s, border-color .2s, background .2s;
}
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-primary { background: var(--grad); color: var(--on-grad); box-shadow: 0 10px 28px -12px var(--accent-strong); }
.btn-primary:hover:not([disabled]) { filter: brightness(1.08); }
.btn-ghost { background: var(--surface-2); border-color: var(--line); }
.btn-ghost:hover:not([disabled]) { border-color: var(--line-strong); }
.btn-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.btn-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.btn-ok:hover:not([disabled]), .btn-bad:hover:not([disabled]) { filter: brightness(1.15); }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; }
.btn-icon { width: 42px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }
.btn-block { width: 100%; }
.btn-lg { height: 52px; font-size: 16px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  position: relative; width: min(420px, 100%); padding: 36px 32px 32px; overflow: hidden;
  background: var(--modal-bg); border: 1px solid var(--line-strong); border-radius: 32px; box-shadow: var(--shadow);
}
.login-card::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--grad); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.login h1 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 600; font-size: 32px; line-height: 1.1; }
.login p { margin: 0 0 22px; color: var(--muted); }
.pw { position: relative; }
.pw input { padding-right: 52px; }
.pw button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.login-error { margin: 0 0 14px; color: var(--bad); font-weight: 700; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: none; object-fit: cover; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface-2); }
.brand strong { display: block; font-family: var(--font-display); font-size: 22px; line-height: 1.1; }
.brand small { display: block; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 22px; padding: 22px 16px;
  background: var(--side-bg); border-right: 1px solid var(--line); overflow-y: auto;
}
.nav { display: grid; gap: 4px; flex: 1; align-content: start; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 14px;
  color: var(--muted); font-weight: 700; border: 1px solid transparent;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); border-color: var(--line-strong); }
.nav a[aria-current="page"] .icon { color: var(--accent); }
.nav .count { margin-left: auto; min-width: 24px; padding: 1px 8px; border-radius: 99px; background: var(--grad); color: var(--on-grad); font-size: 12px; font-weight: 800; text-align: center; }
.side-foot { display: grid; gap: 8px; }
.scrim { position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .6); opacity: 0; pointer-events: none; transition: opacity .25s; }

.main { min-width: 0; padding: 0 clamp(16px, 3vw, 40px) 64px; }
.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 14px;
  margin: 0 calc(-1 * clamp(16px, 3vw, 40px)); padding: 16px clamp(16px, 3vw, 40px);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
@supports not (background: color-mix(in srgb, red, blue)) { .topbar { background: var(--bg); } }
.topbar h1 { flex: 1; margin: 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(24px, 3vw, 32px); letter-spacing: -.01em; }
#navToggle { display: none; }
.panel-view { padding-top: 28px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 18px; }
.panel-head p { margin: 0; color: var(--muted); max-width: 62ch; }

/* ---------- Cards, stats ---------- */
.card { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; }
.card h2 { margin: 0 0 14px; font-family: var(--font-display); font-weight: 600; font-size: 22px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; }
.stat dt { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat dd { margin: 4px 0 0; font-family: var(--font-display); font-size: 34px; font-weight: 600; line-height: 1.1; }
.stat small { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.stat.hot { border-color: var(--accent-strong); }
.two-col { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 232px; overflow-x: auto; }
.bar { flex: 1; min-width: 40px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; text-align: center; }
.bar span { font-size: 11px; font-weight: 800; color: var(--muted); white-space: nowrap; }
.bar i { display: block; width: 100%; height: calc(var(--p) * 1.6px); min-height: 3px; border-radius: 10px 10px 4px 4px; background: var(--grad); }
.bar b { font-size: 12px; color: var(--muted); font-weight: 700; }

.toplist { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.toplist li { display: grid; gap: 6px; }
.toplist .row { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; }
.toplist .row span:last-child { color: var(--muted); }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; width: var(--w); border-radius: 99px; background: var(--grad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th { padding: 14px 18px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .06em; text-align: left; text-transform: uppercase; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td small { display: block; color: var(--muted); font-size: 12.5px; }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions { display: table-cell; }
td.actions .btn + .btn { margin-left: 6px; }
.cell-app { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.cell-app img { width: 44px; height: 44px; flex: none; object-fit: cover; border-radius: 28%; border: 1px solid var(--line); background: var(--surface-2); }
.cell-app strong { display: block; }
.empty { padding: 48px 20px; color: var(--muted); text-align: center; }
.empty strong { display: block; margin-bottom: 4px; color: var(--text); font-family: var(--font-display); font-size: 22px; font-weight: 600; }

.pill { display: inline-flex; align-items: center; padding: 3px 11px; border-radius: 99px; font-size: 12px; font-weight: 800; border: 1px solid currentColor; }
.pill.pending { color: var(--warn); background: var(--warn-bg); }
.pill.approved, .pill.active, .pill.on { color: var(--ok); background: var(--ok-bg); }
.pill.rejected, .pill.off { color: var(--bad); background: var(--bad-bg); }
.pill.fmt { color: var(--accent); background: transparent; }

.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.tabs button { height: 34px; padding: 0 16px; border: 0; border-radius: 999px; background: none; color: var(--muted); font-weight: 800; font-size: 13px; }
.tabs button[aria-pressed="true"] { background: var(--grad); color: var(--on-grad); }

/* ---------- Row lists (categories, banners, broadcasts) ---------- */
.list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.item { display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; }
.item .grow { flex: 1; min-width: 0; }
.item .grow strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .grow small { display: block; color: var(--muted); }
.item .thumb { width: 150px; aspect-ratio: 21 / 8; flex: none; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.item .pos { width: 30px; flex: none; color: var(--muted); font-weight: 800; text-align: center; }
.item .tools { display: flex; align-items: center; gap: 6px; flex: none; }
.inline-form { display: flex; gap: 10px; margin-bottom: 16px; }
.inline-form input { flex: 1; }
.hint { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field > label, .field > .label { font-weight: 800; font-size: 13.5px; }
.field small { color: var(--muted); font-size: 12.5px; }
input[type="text"], input[type="password"], input[type="url"], input[type="number"], select, textarea {
  width: 100%; height: 46px; padding: 0 14px; outline: none;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
}
textarea { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; line-height: 1.55; }
select { appearance: none; -webkit-appearance: none; padding-right: 40px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
select option { background: var(--modal-bg); color: var(--text); }
input:focus, select:focus, textarea:focus { border-color: var(--accent-strong); box-shadow: var(--ring); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad); }
.err { color: var(--bad); font-size: 13px; font-weight: 700; }
.err:empty { display: none; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.check input { width: 18px; height: 18px; accent-color: var(--accent-strong); }

.file { display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 16px; }
.file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file:focus-within { border-color: var(--accent-strong); box-shadow: var(--ring); }
.file .pick { flex: none; }
.file .name { min-width: 0; color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { width: 100%; max-width: 280px; margin-top: 8px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); }
.preview.icon-prev { width: 84px; aspect-ratio: 1; border-radius: 28%; }
.preview.banner-prev { aspect-ratio: 21 / 8; }
.preview.qr-prev { max-width: 160px; aspect-ratio: 1; object-fit: contain; background: #fff; padding: 8px; }
.shot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; margin-top: 10px; }
.shot-grid:empty { display: none; }
.shot-item { position: relative; aspect-ratio: 9 / 16; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.shot-item img { width: 100%; height: 100%; object-fit: cover; }
.shot-item button { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .75); color: #fff; }
.progress { height: 10px; margin: 6px 0 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--grad); transition: width .15s linear; }
.form-error { margin: 0 0 14px; color: var(--bad); font-weight: 700; }

/* ---------- Dialogs ---------- */
dialog.modal {
  width: min(880px, calc(100vw - 24px)); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  margin: auto; padding: 0; overflow: auto;
  background: var(--modal-bg); color: var(--text); border: 1px solid var(--line-strong); border-radius: 28px; box-shadow: var(--shadow);
}
dialog.modal.sm { width: min(460px, calc(100vw - 24px)); }
dialog.modal.md { width: min(640px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(3, 1, 8, .72); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
dialog.modal[open] { animation: pop .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 26px; background: var(--modal-bg); border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 26px; }
.modal-body { padding: 24px 26px 8px; }
.modal-foot { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 16px 26px; background: var(--modal-bg); border-top: 1px solid var(--line); }
.modal-copy { padding: 26px; }
.modal-copy h2 { margin: 0 0 8px; font-family: var(--font-display); font-weight: 600; font-size: 26px; }
.modal-copy p { margin: 0 0 22px; color: var(--muted); }
.modal-copy .row-end { display: flex; justify-content: flex-end; gap: 10px; }
.section-title { margin: 8px 0 14px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.section-title:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 300; left: 50%; bottom: 22px; display: grid; gap: 10px; width: min(460px, calc(100vw - 28px)); transform: translateX(-50%); pointer-events: none; }
.toast { padding: 14px 18px; background: var(--modal-bg); border: 1px solid var(--line-strong); border-radius: 18px; box-shadow: var(--shadow); font-weight: 700; animation: pop .25s ease-out; }
.toast[data-kind="ok"] { border-color: var(--ok); }
.toast[data-kind="error"] { border-color: var(--bad); color: var(--bad); }

/* ---------- Responsive ---------- */
@media (max-width: 1060px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 100; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); background: var(--modal-bg); transform: translateX(-104%); visibility: hidden; transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s .3s; }
  body.nav-open .sidebar { transform: none; visibility: visible; transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s; }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  #navToggle { display: inline-flex; }
}
@media (max-width: 680px) {
  .grid-2 { grid-template-columns: 1fr; }
  .item { flex-wrap: wrap; }
  .item .thumb { width: 100%; }
  .inline-form { flex-direction: column; }
  .modal-head, .modal-body, .modal-foot, .modal-copy { padding-left: 18px; padding-right: 18px; }
}