:root {
    --bg: #0a0a0f;
    --surface: #12121a;
    --surface2: #1a1a2a;
    --border: rgba(255, 255, 255, 0.07);
    --accent: #b400ff;
    --accent2: #8000cc;
    --text: #e8e8f0;
    --text-secondary: #7a7a9a;
    --success: #00e85a;
    --danger: #ff4444;
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Auth Gate ── */
#authGate {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 1rem;
}

#authGate h2 {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

#authGateError {
    color: var(--danger);
    font-size: 0.85rem;
}

/* ── Layout ── */
#dashboard {
    display: none;
    flex-direction: column;
    height: 100vh;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 2rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-left img {
    height: 30px;
}

.header-left h1 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-left: 1px solid var(--border);
    padding-left: 1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-badge {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--surface2);
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    border: 1px solid var(--border);
}

/* ── Stats ── */
.stats-bar {
    display: flex;
    gap: 1rem;
    padding: 1.25rem 2rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

/* ── Toolbar ── */
.toolbar {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 2rem;
    flex-shrink: 0;
    align-items: center;
}

.search-box {
    flex: 1;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.55rem 1rem;
    color: var(--text);
    font-size: 0.875rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.search-box:focus {
    border-color: rgba(180, 0, 255, 0.4);
}

.search-box::placeholder {
    color: var(--text-secondary);
}

/* ── Table ── */
.table-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 0 2rem 2rem;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

.table-wrapper::-webkit-scrollbar {
    width: 5px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

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

thead th {
    text-align: left;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 1;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

tbody tr:hover {
    background: var(--surface);
}

td {
    padding: 0.75rem;
    font-size: 0.875rem;
}

.token-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}

.token-badge.has-tokens {
    background: rgba(180, 0, 255, 0.15);
    color: var(--accent);
    border: 1px solid rgba(180, 0, 255, 0.3);
}

.token-badge.no-tokens {
    background: rgba(255, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(255, 68, 68, 0.2);
}

.email-text {
    font-family: monospace;
    font-size: 0.82rem;
}

/* ── Inline add form ── */
.add-form {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.token-input {
    width: 70px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    text-align: center;
    outline: none;
}

.token-input:focus {
    border-color: rgba(180, 0, 255, 0.4);
}

/* ── Buttons ── */
.btn {
    border: none;
    border-radius: 8px;
    padding: 0.45rem 0.9rem;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
}

.btn-primary:hover {
    opacity: 0.85;
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: default;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-ghost:hover {
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--text);
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
}

/* ── Loading / empty ── */
.loading-row td,
.empty-row td {
    text-align: center;
    color: var(--text-secondary);
    padding: 3rem;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Toast ── */
#toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    font-size: 0.85rem;
    z-index: 9999;
    transform: translateY(120%);
    transition: transform 0.3s ease;
    max-width: 300px;
}

#toast.show {
    transform: translateY(0);
}

#toast.success {
    border-color: rgba(0, 232, 90, 0.4);
    color: var(--success);
}

#toast.error {
    border-color: rgba(255, 68, 68, 0.4);
    color: var(--danger);
}
/* ── Token Costs Card ── */
.costs-card {
    margin: 1.5rem 2rem 2.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: visible;
}

.costs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.costs-header h2 { font-size: 0.95rem; font-weight: 600; }

.costs-sub {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.costs-grid {
    padding: 0.75rem 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.cost-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.cost-row:last-child { border-bottom: none; }

.cost-label { font-size: 0.82rem; color: var(--text); }

.cost-input-wrap { display: flex; align-items: center; gap: 0.5rem; }

.cost-input {
    width: 64px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 0.3rem 0.5rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}
.cost-input:focus { border-color: rgba(180,0,255,0.4); }

.cost-unit { font-size: 0.75rem; color: var(--text-secondary); min-width: 44px; }

/* ── Tab bar ── */
.tab-bar {
    display: flex;
    gap: 0.15rem;
    padding: 0.6rem 2rem 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg);
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.45rem 1rem 0.55rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ── Tab panels ── */
.tab-panel {
    display: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    flex-direction: column;
}

.tab-panel.active { display: flex; }

/* ── Overview grid ── */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    padding: 2rem;
}

.overview-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: border-color 0.2s;
}

.overview-card:hover { border-color: rgba(180, 0, 255, 0.25); }

.ov-icon {
    font-size: 1.6rem;
    opacity: 0.6;
    flex-shrink: 0;
}

.ov-body {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.ov-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.ov-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

/* ── Override: dashboard uses column flex, panels scroll individually ── */
#dashboard {
    height: 100vh;
    overflow: hidden;
}


/* ── Auth splash ── */
#splash {
    position: fixed;
    inset: 0;
    background: #0a0a0f;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.4s ease;
}
#splash.hiding { opacity: 0; pointer-events: none; }
.splash-logo {
    height: 48px;
    animation: splashPulse 1.4s ease-in-out infinite;
}
@keyframes splashPulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50%       { opacity: 1;   transform: scale(1.06); }
}

/* ── Prompt Editor ── */
.prompts-grid {
    padding: 1rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.prompt-row {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.prompt-row:last-child { border-bottom: none; padding-bottom: 0; }

.prompt-label-area {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.prompt-label {
    font-size: 0.82rem;
    color: var(--text);
    font-weight: 500;
}

.prompt-hint {
    font-size: 0.68rem;
    color: var(--text-secondary);
    font-style: italic;
}

.prompt-textarea {
    width: 100%;
    min-height: 80px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    color: var(--text);
    font-family: 'Inter', monospace;
    font-size: 0.8rem;
    line-height: 1.55;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
}

.prompt-textarea:focus {
    border-color: rgba(180, 0, 255, 0.4);
}

.prompt-reset {
    align-self: flex-end;
    opacity: 0.6;
    font-size: 0.7rem;
}
.prompt-reset:hover {
    opacity: 1;
}

/* ── Voucher Form ── */
.voucher-create-form {
    padding: 1rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.vcf-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.vcf-row label {
    min-width: 70px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.vcf-code-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.vcf-code {
    width: 170px !important;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-family: monospace;
}

.voucher-code {
    background: rgba(180, 0, 255, 0.08);
    color: var(--accent);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

.btn-danger {
    color: var(--danger) !important;
    border-color: rgba(255, 68, 68, 0.2) !important;
}
.btn-danger:hover {
    background: rgba(255, 68, 68, 0.1) !important;
}

/* ── Client Management ── */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input[type="text"]:focus,
.form-group textarea:focus {
    border-color: rgba(180, 0, 255, 0.4);
}
.form-group input[type="text"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.form-group input[type="color"] {
    width: 48px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}
.form-row {
    display: flex;
    gap: 1rem;
}
.form-row .form-group { flex: 1; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
}
.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status-badge.active {
    background: rgba(0, 232, 90, 0.12);
    color: var(--success);
    border: 1px solid rgba(0, 232, 90, 0.25);
}
.status-badge.inactive {
    background: rgba(255, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(255, 68, 68, 0.2);
}

/* ── Client Switcher ── */
.client-switcher select {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.3rem 0.6rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.78rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}
.client-switcher select:focus {
    border-color: rgba(180, 0, 255, 0.4);
}
