/* ============================================================================
   PlayDen Staff Panel — Design System
   A fresh, higher-fidelity system (not the admin panel's CSS). Token-driven,
   light + dark, accessible. Everything keys off CSS custom properties so the
   whole panel re-themes from :root.
   ============================================================================ */

:root {
    /* Brand */
    --brand: #6d5efc;
    --brand-600: #5a4bf0;
    --brand-700: #4a3cd8;
    --brand-soft: rgba(109, 94, 252, 0.12);
    --accent: #17c3a2;

    /* Semantic */
    --danger: #e5484d;
    --danger-soft: rgba(229, 72, 77, 0.12);
    --warn: #f5a524;
    --warn-soft: rgba(245, 165, 36, 0.14);
    --ok: #30a46c;
    --ok-soft: rgba(48, 164, 108, 0.14);

    /* Surfaces (light) */
    --bg: #f4f5fb;
    --surface: #ffffff;
    --surface-2: #fafafe;
    --surface-hover: #f2f3fb;
    --border: #e7e8f0;
    --border-strong: #d7d9e6;

    /* Text */
    --text: #1a1c28;
    --text-2: #565a72;
    --text-3: #8a8fa8;
    --on-brand: #ffffff;

    /* Shape & motion */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(20, 22, 40, 0.06), 0 1px 3px rgba(20, 22, 40, 0.04);
    --shadow: 0 4px 16px rgba(20, 22, 40, 0.08);
    --shadow-lg: 0 12px 40px rgba(20, 22, 40, 0.16);
    --ring: 0 0 0 3px var(--brand-soft);
    --ease: cubic-bezier(0.4, 0, 0.2, 1);

    --sidebar-w: 248px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
}

:root[data-theme="dark"] {
    --bg: #0d0e14;
    --surface: #161822;
    --surface-2: #1b1d29;
    --surface-hover: #21232f;
    --border: #262835;
    --border-strong: #333648;
    --text: #eceef5;
    --text-2: #a2a7bd;
    --text-3: #6b7089;
    --brand-soft: rgba(109, 94, 252, 0.18);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
::selection { background: var(--brand-soft); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; }
.brand .logo {
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, var(--brand), var(--accent));
    display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 16px;
    box-shadow: var(--shadow-sm);
}
.brand .name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand .sub { font-size: 11px; color: var(--text-3); margin-top: -2px; }

.nav { padding: 8px 12px; flex: 1; overflow-y: auto; }
.nav-group-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); padding: 14px 12px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 500; cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease);
    user-select: none; margin-bottom: 2px;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
.nav-item.active svg { opacity: 1; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.user-chip .meta { min-width: 0; }
.user-chip .meta .n { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .meta .r { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Main ─────────────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 60px; display: flex; align-items: center; gap: 16px;
    padding: 0 24px; border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 80%, transparent);
    backdrop-filter: saturate(1.4) blur(8px);
    position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }

.search-trigger {
    display: flex; align-items: center; gap: 10px; min-width: 300px;
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface-2); color: var(--text-3); cursor: text;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger svg { width: 18px; height: 18px; flex: none; }
.search-trigger span { white-space: nowrap; }
.search-trigger kbd {
    margin-left: auto; font: 11px var(--mono); background: var(--surface); border: 1px solid var(--border);
    border-radius: 5px; padding: 1px 6px; color: var(--text-3);
}

.icon-btn {
    width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text-2); display: grid; place-items: center;
    cursor: pointer; transition: all 0.15s var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }

.content { padding: 24px; max-width: 1240px; width: 100%; }

/* ── Components ────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat .label { font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .ico { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.stat .ico svg { width: 20px; height: 20px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { font-size: 15px; font-weight: 700; margin: 0; }
.muted { color: var(--text-3); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: 9px; font-weight: 600; font-size: 13px; border: 1px solid transparent; cursor: pointer; transition: all 0.15s var(--ease); font-family: inherit; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-600); box-shadow: var(--shadow); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; padding: 11px 16px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); font-weight: 700; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; }
table.data td { padding: 13px 16px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background 0.12s var(--ease); cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-hover); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Inputs */
.input { width: 100%; padding: 10px 13px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); color: var(--text); font: inherit; transition: all 0.15s var(--ease); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); background: var(--surface); }
.input::placeholder { color: var(--text-3); }

/* Empty / skeleton */
.empty { text-align: center; padding: 56px 20px; color: var(--text-3); }
.empty svg { width: 44px; height: 44px; opacity: 0.4; margin-bottom: 12px; }
.skel { background: linear-gradient(90deg, var(--surface-hover) 25%, var(--border) 37%, var(--surface-hover) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Command palette */
.cmdk-overlay { position: fixed; inset: 0; background: rgba(10, 11, 18, 0.5); backdrop-filter: blur(3px); display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; z-index: 100; }
.cmdk-overlay.open { display: flex; animation: fade 0.15s var(--ease); }
.cmdk { width: min(600px, 92vw); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; }
.cmdk-input-row { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.cmdk-input-row svg { width: 20px; height: 20px; color: var(--text-3); }
.cmdk-input { flex: 1; border: none; background: none; font-size: 16px; color: var(--text); outline: none; font-family: inherit; }
.cmdk-results { max-height: 52vh; overflow-y: auto; padding: 8px; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; cursor: pointer; }
.cmdk-item:hover, .cmdk-item.sel { background: var(--brand-soft); }
.cmdk-empty { padding: 32px; text-align: center; color: var(--text-3); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Toast */
.toasts { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--surface); border: 1px solid var(--border-strong); border-left: 3px solid var(--brand); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 13px 16px; min-width: 260px; animation: slidein 0.2s var(--ease); font-size: 13px; }
.toast.ok { border-left-color: var(--ok); }
.toast.danger { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Detail view */
.detail-grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }
.mono { font-family: var(--mono); font-size: 12px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
    radial-gradient(1000px 500px at 10% -10%, var(--brand-soft), transparent),
    radial-gradient(900px 500px at 110% 110%, rgba(23,195,162,0.10), transparent), var(--bg); }
.login-card { width: min(400px, 94vw); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 32px; }
.login-card .brand { padding: 0; margin-bottom: 22px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.login-card p.sub { color: var(--text-3); margin: 0 0 22px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.form-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; min-height: 16px; }

@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .detail-grid { grid-template-columns: 1fr; }
    .search-trigger { min-width: 0; }
}
