/* ==========================================================================
   Barterific — admin panel
   Uses the same gray + purple tokens; its own light/dark cookie.
   ========================================================================== */

:root {
    --a-bg: #f2f2f6;
    --a-sidebar: #17171f;
    --a-sidebar-2: #1f1f2b;
    --a-sidebar-text: #b9b9c9;
    --a-sidebar-active: #2a2440;
    --a-surface: #ffffff;
    --a-surface-2: #fafafc;
    --a-text: #17171c;
    --a-text-2: #55555f;
    --a-muted: #86868f;
    --a-border: #e4e4ec;
    --a-border-strong: #d3d3de;
    --a-accent: #7c5cfc;
    --a-accent-ink: #5738e6;
    --a-accent-soft: #efeafd;
    --a-ok: #1f9d63;
    --a-warn: #b7791f;
    --a-danger: #d1374a;
    --a-radius: 14px;
    --a-shadow: 0 1px 2px rgba(18, 18, 28, .05), 0 6px 20px rgba(18, 18, 28, .05);
    --a-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --a-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --a-heading: var(--a-sans);
}

[data-theme="dark"] {
    --a-bg: #0d0d12;
    --a-sidebar: #121219;
    --a-sidebar-2: #1a1a24;
    --a-sidebar-text: #a3a3b5;
    --a-sidebar-active: #241f3a;
    --a-surface: #17171f;
    --a-surface-2: #1d1d27;
    --a-text: #ededf4;
    --a-text-2: #b0b0c0;
    --a-muted: #8a8a9c;
    --a-border: #292935;
    --a-border-strong: #3a3a49;
    --a-accent: #a58bff;
    --a-accent-ink: #c3b1ff;
    --a-accent-soft: #241d3d;
    --a-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

body.adm {
    margin: 0;
    background: var(--a-bg);
    color: var(--a-text);
    font-family: var(--a-sans);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--a-accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; letter-spacing: -.02em; font-family: var(--a-heading, var(--a-sans)); }
img { max-width: 100%; }
code { font-family: var(--a-mono); font-size: .88em; background: var(--a-surface-2); padding: 2px 6px; border-radius: 6px; }

.adm-shell { display: flex; min-height: 100vh; }

/* ---------------------------------------------------------------- sidebar */

.adm-sidebar {
    width: 246px;
    flex: 0 0 246px;
    background: var(--a-sidebar);
    color: var(--a-sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.adm-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; color: #fff; font-weight: 700; letter-spacing: -.02em; }
.adm-brand:hover { text-decoration: none; }
.adm-brand svg { color: var(--a-accent); flex: 0 0 auto; }
.adm-brand small { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: #7b7b8f; margin-top: -2px; }
.adm-nav { padding: 6px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.adm-nav__group { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #6c6c80; padding: 16px 12px 6px; font-weight: 700; }
.adm-nav__link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: 9px;
    color: var(--a-sidebar-text);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}
.adm-nav__link:hover { background: var(--a-sidebar-2); color: #fff; text-decoration: none; }
.adm-nav__link.is-active { background: var(--a-sidebar-active); color: #fff; }
.adm-nav__link.is-active svg { color: var(--a-accent); }
.adm-nav__link svg { flex: 0 0 auto; opacity: .9; }
.adm-nav__badge { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.09); padding: 1px 7px; border-radius: 999px; }
.adm-sidebar__foot { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255,255,255,.07); display: flex; gap: 8px; flex-wrap: wrap; }
.adm-sidebar__foot a, .adm-sidebar__foot button {
    flex: 1;
    min-width: 90px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,.12);
    background: transparent;
    color: var(--a-sidebar-text);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
}
.adm-sidebar__foot a:hover, .adm-sidebar__foot button:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }

/* ------------------------------------------------------------------- main */

.adm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.adm-topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 28px;
    background: var(--a-surface);
    border-bottom: 1px solid var(--a-border);
    position: sticky;
    top: 0;
    z-index: 30;
}
.adm-topbar__title { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.adm-topbar__sub { font-size: 12.5px; color: var(--a-muted); margin: 0; }
.adm-topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.adm-content { padding: 26px 28px 60px; max-width: 1280px; width: 100%; }

.adm-toggle { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--a-border); background: var(--a-surface); color: var(--a-text-2); cursor: pointer; font: inherit; font-size: 13px; }
.adm-toggle:hover { border-color: var(--a-accent); color: var(--a-accent-ink); }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

.adm-menu-btn { display: none; }

/* ------------------------------------------------------------------ cards */

.a-card { background: var(--a-surface); border: 1px solid var(--a-border); border-radius: var(--a-radius); box-shadow: var(--a-shadow); }
.a-card + .a-card { margin-top: 20px; }
.a-card__head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--a-border); }
.a-card__title { font-size: 15px; font-weight: 700; margin: 0; }
.a-card__sub { font-size: 12.5px; color: var(--a-muted); margin: 2px 0 0; }
.a-card__actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.a-card__body { padding: 20px; }
.a-card__body--flush { padding: 0; }

.a-grid { display: grid; gap: 18px; }
.a-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.a-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.a-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat { padding: 18px 20px; }
.stat__label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--a-muted); font-weight: 700; }
.stat__value { font-size: 27px; font-weight: 750; letter-spacing: -.03em; margin: 6px 0 2px; }
.stat__meta { font-size: 12.5px; color: var(--a-muted); }
.stat__trend { font-size: 12px; font-weight: 700; }
.stat__trend.is-up { color: var(--a-ok); }
.stat__trend.is-down { color: var(--a-danger); }

/* ---------------------------------------------------------------- buttons */

.a-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 15px;
    border-radius: 9px;
    border: 1px solid var(--a-border-strong);
    background: var(--a-surface);
    color: var(--a-text);
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.a-btn:hover { text-decoration: none; border-color: var(--a-accent); color: var(--a-accent-ink); }
.a-btn--primary { background: var(--a-accent); border-color: var(--a-accent); color: #fff; }
.a-btn--primary:hover { background: var(--a-accent-ink); border-color: var(--a-accent-ink); color: #fff; }
[data-theme="dark"] .a-btn--primary, [data-theme="dark"] .a-btn--primary:hover { color: #14101f; }
.a-btn--soft { background: var(--a-accent-soft); border-color: transparent; color: var(--a-accent-ink); }
.a-btn--danger { background: var(--a-danger); border-color: var(--a-danger); color: #fff; }
.a-btn--sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.a-btn--block { width: 100%; }
.a-btn--ghost { background: transparent; }

/* ------------------------------------------------------------------ forms */

.a-field { margin-bottom: 16px; }
.a-label { display: block; font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--a-muted); margin-bottom: 6px; }
.a-input, .a-textarea, .a-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--a-border-strong);
    border-radius: 9px;
    background: var(--a-surface);
    color: var(--a-text);
    font-family: inherit;
    font-size: 14.5px;
}
.a-input:focus, .a-textarea:focus, .a-select:focus { outline: none; border-color: var(--a-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--a-accent) 16%, transparent); }
.a-textarea { min-height: 96px; resize: vertical; }
.a-input--mono { font-family: var(--a-mono); font-size: 13px; }
.a-help { font-size: 12px; color: var(--a-muted); margin: 5px 0 0; }
.a-input--sm { padding: 7px 10px; font-size: 13px; border-radius: 8px; }
.a-grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.a-check { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; color: var(--a-text-2); margin-bottom: 8px; }
.a-check input { margin-top: 4px; accent-color: var(--a-accent); }
.a-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }

/* switch */
.a-switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13.5px; color: var(--a-text-2); }
.a-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.a-switch__track { width: 38px; height: 22px; border-radius: 999px; background: var(--a-border-strong); position: relative; transition: background .16s; flex: 0 0 auto; }
.a-switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .16s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.a-switch input:checked + .a-switch__track { background: var(--a-accent); }
.a-switch input:checked + .a-switch__track::after { transform: translateX(16px); }

/* -------------------------------------------------------------- tab strip */

.a-tabs { display: flex; gap: 4px; padding: 6px; background: var(--a-surface-2); border: 1px solid var(--a-border); border-radius: 11px; margin-bottom: 20px; flex-wrap: wrap; }
.a-tabs a { padding: 8px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--a-text-2); text-decoration: none; }
.a-tabs a:hover { background: var(--a-surface); color: var(--a-text); text-decoration: none; }
.a-tabs a.is-active { background: var(--a-surface); color: var(--a-accent-ink); box-shadow: var(--a-shadow); }

/* ----------------------------------------------------------------- tables */

.a-table-wrap { overflow-x: auto; }
table.a-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.a-table th { text-align: left; padding: 11px 14px; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--a-muted); border-bottom: 1px solid var(--a-border); background: var(--a-surface-2); white-space: nowrap; }
table.a-table td { padding: 11px 14px; border-bottom: 1px solid var(--a-border); vertical-align: middle; }
table.a-table tr:last-child td { border-bottom: 0; }
table.a-table tr:hover td { background: var(--a-surface-2); }
table.a-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.a-thumb { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; background: var(--a-surface-2); }
.a-thumb--round { border-radius: 50%; }

.a-pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; background: var(--a-surface-2); color: var(--a-text-2); border: 1px solid var(--a-border); }
.a-pill--ok { background: color-mix(in srgb, var(--a-ok) 14%, var(--a-surface)); color: var(--a-ok); border-color: transparent; }
.a-pill--warn { background: color-mix(in srgb, var(--a-warn) 16%, var(--a-surface)); color: var(--a-warn); border-color: transparent; }
.a-pill--danger { background: color-mix(in srgb, var(--a-danger) 14%, var(--a-surface)); color: var(--a-danger); border-color: transparent; }
.a-pill--accent { background: var(--a-accent-soft); color: var(--a-accent-ink); border-color: transparent; }

/* --------------------------------------------------------------- notices */

.a-alert { padding: 12px 15px; border-radius: 10px; border: 1px solid var(--a-border); background: var(--a-surface); font-size: 14px; margin-bottom: 18px; }
.a-alert--success { border-color: color-mix(in srgb, var(--a-ok) 35%, var(--a-border)); background: color-mix(in srgb, var(--a-ok) 8%, var(--a-surface)); }
.a-alert--error { border-color: color-mix(in srgb, var(--a-danger) 35%, var(--a-border)); background: color-mix(in srgb, var(--a-danger) 8%, var(--a-surface)); }
.a-alert--info { border-color: color-mix(in srgb, var(--a-accent) 35%, var(--a-border)); background: var(--a-accent-soft); color: var(--a-accent-ink); }
.a-alert--warning { border-color: color-mix(in srgb, var(--a-warn) 35%, var(--a-border)); background: color-mix(in srgb, var(--a-warn) 10%, var(--a-surface)); }

/* --------------------------------------------------------------- sorting */

.sort-list { display: flex; flex-direction: column; gap: 10px; }
.sort-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--a-border); border-radius: 11px; background: var(--a-surface); }
.sort-item.is-dragging { opacity: .45; border-style: dashed; }
.sort-item__handle { cursor: grab; color: var(--a-muted); display: inline-flex; }
.sort-item__handle:active { cursor: grabbing; }

.menu-editor-row { border: 1px solid var(--a-border); border-radius: 11px; background: var(--a-surface); padding: 12px; margin-bottom: 10px; }
.menu-editor-row.is-dragging { opacity: .4; border-style: dashed; }
.menu-editor-row__top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.menu-editor-row__grid { display: grid; grid-template-columns: 1fr 1.4fr auto auto auto; gap: 10px; align-items: center; }
.menu-editor-row__foot { display: flex; align-items: center; gap: 16px; margin-top: 9px; flex-wrap: wrap; }

/* ------------------------------------------------------------ range input */

.a-range-row { display: flex; align-items: center; gap: 14px; }
.a-range { flex: 1; accent-color: var(--a-accent); }
.a-range-value { font-family: var(--a-mono); font-size: 13px; color: var(--a-text-2); min-width: 56px; text-align: right; }

/* ---------------------------------------------------------------- charts */

.chart-box { position: relative; width: 100%; }
.chart-box canvas { width: 100%; height: 230px; display: block; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--a-text-2); margin-bottom: 10px; }
.chart-legend__dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.chart-legend__dot--views { background: var(--a-accent); }
.chart-legend__dot--uniques { background: var(--a-ok); }

/* -------------------------------------------------------- section editor */

.section-editor { border: 1px solid var(--a-border); border-radius: var(--a-radius); background: var(--a-surface); margin-bottom: 14px; overflow: hidden; }
.section-editor__head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; cursor: pointer; }
.section-editor__head:hover { background: var(--a-surface-2); }
.section-editor__title { font-weight: 700; font-size: 14.5px; margin: 0; }
.section-editor__key { font-family: var(--a-mono); font-size: 11.5px; color: var(--a-muted); }
.section-editor__toggle { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.section-editor__body { border-top: 1px solid var(--a-border); padding: 18px; display: none; }
.section-editor.is-open .section-editor__body { display: block; }
.section-editor__chev { transition: transform .18s; color: var(--a-muted); }
.section-editor.is-open .section-editor__chev { transform: rotate(90deg); }

/* ------------------------------------------------------------ login page */

.adm-login { min-height: 100vh; display: grid; place-items: center; padding: 30px; background: var(--a-bg); }
.adm-login__card { width: 100%; max-width: 400px; background: var(--a-surface); border: 1px solid var(--a-border); border-radius: 18px; padding: 32px; box-shadow: var(--a-shadow); }
.adm-login__title { font-size: 22px; letter-spacing: -.03em; margin: 0 0 4px; }
.adm-login__sub { font-size: 13.5px; color: var(--a-muted); margin: 0 0 22px; }
.adm-login__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; color: var(--a-accent); font-weight: 700; }
.adm-login__foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: 12.5px; color: var(--a-muted); }

/* --------------------------------------------------------------- misc */

.a-empty { text-align: center; padding: 40px 20px; color: var(--a-muted); }
.a-flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.a-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.a-muted { color: var(--a-muted); }
.a-small { font-size: 12.5px; }
.a-mono { font-family: var(--a-mono); font-size: 12.5px; }
.a-mt { margin-top: 18px; }
.a-taglist { display: flex; flex-wrap: wrap; gap: 6px; }
.a-tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--a-accent-soft); color: var(--a-accent-ink); font-size: 12px; font-weight: 600; }
.a-tag button { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 0; font: inherit; opacity: .7; }
.a-tag button:hover { opacity: 1; }
.a-kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; font-size: 13.5px; }
.a-kv dt { color: var(--a-muted); }
.a-kv dd { margin: 0; }
.a-media-preview { width: 120px; height: 80px; border-radius: 10px; border: 1px dashed var(--a-border-strong); background: var(--a-surface-2); display: grid; place-items: center; overflow: hidden; font-size: 11px; color: var(--a-muted); }
.a-media-preview img { width: 100%; height: 100%; object-fit: contain; }

@media (max-width: 1100px) {
    .a-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .a-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
    .adm-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 80; transform: translateX(-100%); transition: transform .2s; }
    body.adm.sidebar-open .adm-sidebar { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.4); }
    .adm-menu-btn { display: inline-flex; }
    .adm-topbar, .adm-content { padding-left: 16px; padding-right: 16px; }
    .a-grid--2, .a-grid--3, .a-grid--4 { grid-template-columns: minmax(0, 1fr); }
    .a-grid-form { grid-template-columns: minmax(0, 1fr); }
    .menu-editor-row__grid { grid-template-columns: 1fr 1fr; }
}

/* ---------------------------------------------- sticky rich text toolbar */
.adm .rte { overflow: visible; }
.adm .rte__toolbar {
    position: sticky;
    top: 68px;
    z-index: 25;
    box-shadow: 0 6px 14px -10px rgba(0, 0, 0, .35);
}
.adm .rte__surface { border-radius: 0 0 var(--radius-sm) var(--radius-sm); }

/* --------------------------------------------- menu drag & drop feedback */
.menu-editor-row.is-drop-target { border-color: var(--a-accent); box-shadow: 0 0 0 2px var(--a-accent-soft, rgba(124, 92, 252, .18)); }
.menu-editor-row [data-sortable-handle] { user-select: none; }

/* ------------------------------------------------- bottom-right notices */
.adm .toast {
    background: var(--a-surface);
    border-color: var(--a-border-strong);
    color: var(--a-text);
    box-shadow: 0 12px 30px -14px rgba(0, 0, 0, .5);
}
.adm .toast__close { color: var(--a-muted); }
.adm .toast__close:hover { color: var(--a-text); }
.adm .toast--success { border-left-color: var(--a-ok); }
.adm .toast--error { border-left-color: var(--a-danger); }
.adm .toast--warning { border-left-color: var(--a-warn); }
.adm .toast--info { border-left-color: var(--a-accent); }

.a-pill--info { background: color-mix(in srgb, var(--a-accent, #7c5cfc) 16%, transparent); color: var(--a-accent, #7c5cfc); }

.a-grid--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .a-grid--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { .a-grid--5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
