/* ==========================================================================
   Telegram Shop — Admin panel styles (vanilla CSS, light & dark themes)
   ========================================================================== */

:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-soft: #dbeafe;
    --success: #059669;
    --success-soft: #d1fae5;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --info: #0284c7;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
    --sidebar-w: 248px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #111a2c;
    --surface-2: #16213a;
    --border: #243049;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #60a5fa;
    --primary-soft: rgba(96, 165, 250, .15);
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, .14);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, .14);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .14);
    --info: #38bdf8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }

.boot-screen {
    display: grid;
    place-items: center;
    height: 100vh;
    gap: 16px;
    color: var(--text-muted);
}

/* ---------------------------------- layout -------------------------------- */

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

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 12px;
}
.brand-logo {
    width: 38px; height: 38px; border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav { padding: 6px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 14px 10px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 10px; color: var(--text);
    font-size: 13.5px; cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-icon { width: 20px; text-align: center; }
.nav-badge {
    margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px;
    font-size: 11px; padding: 0 7px; min-width: 20px; text-align: center;
}

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

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary);
    display: grid; place-items: center; font-weight: 700;
}
.content { padding: 18px 20px 40px; max-width: 1400px; width: 100%; }

.menu-toggle { display: none; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0;
        transform: translateX(-100%); transition: transform .2s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: inline-flex; }
    .content { padding: 14px 12px 90px; }
    .topbar { padding: 10px 12px; }
}

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

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

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { flex: 1; }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--text-muted); font-size: 12.5px; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat-sub { font-size: 12px; color: var(--text-muted); }
.stat-delta { font-size: 12px; font-weight: 600; }
.up { color: var(--success); }
.down { color: var(--danger); }
.flat { color: var(--text-muted); }
.kpi-icon { font-size: 18px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); }

/* --------------------------------- controls ------------------------------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 550;
    cursor: pointer; transition: .15s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
html[data-theme="dark"] .btn.primary { color: #0b1220; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.icon { padding: 8px; width: 36px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.input, .select, .textarea {
    width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit;
    outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { min-height: 90px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 11.5px; color: var(--text-muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } }
.checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--primary); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .input { max-width: 280px; }
.toolbar .select { max-width: 180px; }
.spacer { flex: 1; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.seg button { border: none; background: none; color: var(--text-muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }

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

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--border);
    background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
td.num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.strong { font-weight: 650; }

.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
}
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.amber { background: var(--warning-soft); color: var(--warning); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.gray { background: var(--surface-2); color: var(--text-muted); }

.pagination { display: flex; align-items: center; gap: 8px; padding: 12px; justify-content: flex-end; }
.pagination span { color: var(--text-muted); font-size: 12.5px; }

.empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }
.empty-icon { font-size: 34px; margin-bottom: 8px; }

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

.chart { width: 100%; height: 220px; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; font-size: 13px; }
.bar-track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 4px; grid-column: 1 / -1; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), #7c3aed); }

.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }

/* ---------------------------------- modal --------------------------------- */

.modal-root:empty { display: none; }
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(2, 6, 23, .55); z-index: 100;
    display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px);
}
.modal {
    background: var(--surface); color: var(--text); border-radius: 16px; width: 100%;
    max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 25px 50px rgba(0,0,0,.35);
}
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); gap: 10px; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }

/* ---------------------------------- toast --------------------------------- */

.toast-stack { position: fixed; right: 16px; top: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-left: 4px solid var(--primary); border-radius: 10px; padding: 11px 14px; min-width: 240px; max-width: 380px;
    box-shadow: var(--shadow); font-size: 13.5px; animation: slideIn .18s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }

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

.spinner {
    width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { display: grid; place-items: center; padding: 50px; }

.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; } .kv dt { margin-top: 6px; } }

.chat { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; padding: 4px; }
.bubble { padding: 9px 12px; border-radius: 12px; max-width: 85%; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { background: var(--surface-2); align-self: flex-start; border-top-left-radius: 4px; }
.bubble.admin { background: var(--primary-soft); color: var(--text); align-self: flex-end; border-top-right-radius: 4px; }
.bubble time { display: block; font-size: 10.5px; color: var(--text-muted); margin-top: 3px; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item .main-part { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, monospace; font-size: 12.5px; white-space: pre-wrap; word-break: break-all; max-height: 260px; overflow: auto; }

.thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb-wrap { position: relative; }
.thumb-wrap .del { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 11px; }

.divider { height: 1px; background: var(--border); margin: 14px 0; border: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notice { padding: 10px 12px; border-radius: 10px; font-size: 13px; border: 1px solid var(--border); background: var(--surface-2); }
.notice.warn { background: var(--warning-soft); border-color: transparent; color: var(--text); }
.notice.danger { background: var(--danger-soft); border-color: transparent; color: var(--text); }
.notice a { font-weight: 600; }

.theme-toggle { cursor: pointer; }

.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }

.tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 12px; border: none; background: none; color: var(--text-muted); font-size: 13.5px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
