/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Dark theme (default) */
    --bg:             #07090f;
    --surface:        #0d1117;
    --surface-2:      #111827;
    --surface-3:      #1a2235;
    --border:         #1e2d42;
    --border-subtle:  #162032;

    --accent:         #3b82f6;
    --accent-dim:     rgba(59,130,246,.12);
    --accent-hover:   #2563eb;

    --green:          #10b981;
    --green-dim:      rgba(16,185,129,.12);
    --red:            #ef4444;
    --red-dim:        rgba(239,68,68,.12);
    --amber:          #f59e0b;
    --amber-dim:      rgba(245,158,11,.12);
    --purple:         #8b5cf6;
    --purple-dim:     rgba(139,92,246,.12);

    --text-1:         #e2e8f0;
    --text-2:         #94a3b8;
    --text-3:         #4b6280;

    --sidebar-w:      220px;
    --topbar-h:       56px;
    --radius:         10px;
    --radius-sm:      6px;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text-1);
    background: var(--bg);
}

/* ── Light theme ── */
[data-theme="light"] {
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --surface-3:     #f1f5f9;
    --border:        #e2e8f0;
    --border-subtle: #f0f4f8;

    --accent-dim:    rgba(59,130,246,.10);
    --green-dim:     rgba(16,185,129,.10);
    --red-dim:       rgba(239,68,68,.10);
    --amber-dim:     rgba(245,158,11,.10);
    --purple-dim:    rgba(139,92,246,.10);

    --text-1:        #0f172a;
    --text-2:        #475569;
    --text-3:        #94a3b8;
}

/* Smooth transition when switching themes */
*, *::before, *::after {
    transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

body { min-height: 100vh; }

/* ── Login ── */
.fullscreen-center {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse 60% 40% at 50% 0%, rgba(59,130,246,.08) 0%, transparent 70%);
}

.login-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
    max-width: 380px;
    padding: 24px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    flex-shrink: 0;
}

.brand-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-1);
    letter-spacing: -.3px;
}

.login-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
}

.login-card-header {
    padding: 28px 28px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.login-card-header h1 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-1);
    margin-bottom: 4px;
}

.login-card-header p {
    font-size: 13px;
    color: var(--text-2);
}

.login-card-body {
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.login-error {
    font-size: 13px;
    color: var(--red);
    text-align: center;
    background: var(--red-dim);
    border: 1px solid rgba(239,68,68,.2);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    width: 100%;
}

.login-footer {
    font-size: 12px;
    color: var(--text-3);
}

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

/* ── Sidebar ── */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 18px 16px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.brand-mark-sm {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.nav-item:hover { background: var(--surface-2); color: var(--text-1); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 12px;
    border-top: 1px solid var(--border-subtle);
}

.admin-profile {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.admin-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;
}

.admin-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.admin-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.admin-email {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-role {
    font-size: 11px;
    color: var(--text-3);
}

.btn-logout {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    cursor: pointer;
    transition: background .15s, color .15s;
}

.btn-logout:hover { background: var(--red-dim); color: var(--red); }

/* ── Main wrap ── */
.main-wrap {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
}

/* ── Topbar ── */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-title h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-1);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.btn-icon:hover { background: var(--surface-3); color: var(--text-1); border-color: var(--border); }
.btn-icon.spinning svg { animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Content ── */
.content {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
}

/* ── Stats ── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-1);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-value.stat-green { color: var(--green); }
.stat-value.stat-red   { color: var(--red); }
.stat-value.stat-blue  { color: var(--accent); }
.stat-value.stat-amber { color: var(--amber); }

.stat-sub {
    font-size: 12px;
    color: var(--text-3);
}

/* ── Table card ── */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.table-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-1);
}

.table-count {
    font-size: 12px;
    color: var(--text-3);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 10px;
}

.table-scroll { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

thead tr {
    background: var(--surface-2);
}

th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-subtle);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.row-blocked { opacity: .55; }

/* User cell */
.user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-3);
    flex-shrink: 0;
}

.user-avatar-initials {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}

.user-meta { display: flex; flex-direction: column; }

.user-email {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-1);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-green  { background: var(--green-dim);  color: var(--green);  }
.badge-red    { background: var(--red-dim);    color: var(--red);    }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-gray   { background: var(--surface-3);  color: var(--text-2); border: 1px solid var(--border); }

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Credits pill */
.credits-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-1);
}

.credits-pill.credits-used { color: var(--amber); }

.credits-num { font-variant-numeric: tabular-nums; }

/* Time */
.time-text {
    font-size: 12.5px;
    color: var(--text-2);
}

/* Action buttons */
.actions-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
    white-space: nowrap;
}

.btn-action:hover { background: var(--surface-3); color: var(--text-1); }

.btn-action.btn-plus  { border-color: rgba(16,185,129,.3); color: var(--green); }
.btn-action.btn-plus:hover  { background: var(--green-dim); border-color: var(--green); }

.btn-action.btn-minus { border-color: rgba(245,158,11,.25); color: var(--amber); }
.btn-action.btn-minus:hover { background: var(--amber-dim); border-color: var(--amber); }

.btn-action.btn-block { border-color: rgba(245,158,11,.25); color: var(--amber); }
.btn-action.btn-block:hover { background: var(--amber-dim); border-color: var(--amber); }

.btn-action.btn-unblock { border-color: rgba(16,185,129,.3); color: var(--green); }
.btn-action.btn-unblock:hover { background: var(--green-dim); border-color: var(--green); }

.btn-action.btn-delete { border-color: rgba(239,68,68,.25); color: var(--red); }
.btn-action.btn-delete:hover { background: var(--red-dim); border-color: var(--red); }

/* Divider between action groups */
.actions-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
    flex-shrink: 0;
}

/* ── Theme float button (login screen) ── */
.btn-theme-float {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: background .15s, color .15s, border-color .15s;
}
.btn-theme-float:hover { color: var(--text-1); background: var(--surface-2); }

/* ── Utilities ── */
.hidden { display: none !important; }
