/* style.css — Fonzygrok Dashboard
 * Dark/light theme support with system preference detection.
 * No external frameworks. REF: SPR-019 T-070, SPR-020 T-070
 */

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

/* ── Theme Variables ─────────────────────────────────────────── */

/* Default: dark theme (matches original design) */
:root {
    --bg-primary:   #0f172a;
    --bg-secondary: #1e293b;
    --bg-card:      #1e293b;
    --bg-input:     #0f172a;
    --bg-hover:     #334155;
    --border:       #334155;
    --border-focus: #10b981;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted:   #64748b;
    --accent:       #10b981;
    --accent-hover: #059669;
    --accent-cyan:  #06b6d4;
    --danger:       #ef4444;
    --danger-hover: #dc2626;
    --warning:      #f59e0b;
    --success:      #10b981;
    --radius:       8px;
    --radius-sm:    4px;
    --mono:         'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --sans:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --shadow:       0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
    --transition:   150ms ease;
}

/* Light theme — applied via [data-theme="light"] or prefers-color-scheme */
[data-theme="light"] {
    --bg-primary:     #f8fafc;
    --bg-secondary:   #ffffff;
    --bg-card:        #ffffff;
    --bg-input:       #f1f5f9;
    --bg-hover:       #e2e8f0;
    --border:         #e2e8f0;
    --border-focus:   #10b981;
    --text-primary:   #0f172a;
    --text-secondary: #475569;
    --text-muted:     #94a3b8;
    --shadow:         0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
}

/* Dark theme — explicit override (when user manually selects dark) */
[data-theme="dark"] {
    --bg-primary:   #0f172a;
    --bg-secondary: #1e293b;
    --bg-card:      #1e293b;
    --bg-input:     #0f172a;
    --bg-hover:     #334155;
    --border:       #334155;
    --border-focus: #10b981;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted:   #64748b;
    --shadow:       0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
}

/* System preference: light — only when no explicit data-theme is set */
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg-primary:     #f8fafc;
        --bg-secondary:   #ffffff;
        --bg-card:        #ffffff;
        --bg-input:       #f1f5f9;
        --bg-hover:       #e2e8f0;
        --border:         #e2e8f0;
        --border-focus:   #10b981;
        --text-primary:   #0f172a;
        --text-secondary: #475569;
        --text-muted:     #94a3b8;
        --shadow:         0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    }
}

/* ── Base ─────────────────────────────────────────────────────── */
html { font-size: 15px; }
body {
    font-family: var(--sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover { color: var(--accent-hover); }

/* ── Layout ───────────────────────────────────────────────────── */
.shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.nav {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-family: var(--mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}
.nav-brand span { color: var(--text-muted); }

.nav-links {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    list-style: none;
}
.nav-links a, .nav-links button {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all var(--transition);
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--sans);
}
.nav-links a:hover, .nav-links button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.nav-links .active {
    color: var(--accent);
    background: rgba(16, 185, 129, 0.1);
}

.main {
    flex: 1;
    padding: 2rem 1.5rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

/* ── Theme Toggle Button ─────────────────────────────────────── */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--transition);
    line-height: 1;
}
.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    vertical-align: middle;
}
[data-theme="light"] td {
    border-bottom-color: rgba(226, 232, 240, 0.8);
}
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) td {
        border-bottom-color: rgba(226, 232, 240, 0.8);
    }
}
tr:hover td { background: rgba(51, 65, 85, 0.25); }
[data-theme="light"] tr:hover td { background: rgba(241, 245, 249, 0.8); }
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) tr:hover td { background: rgba(241, 245, 249, 0.8); }
}
.mono { font-family: var(--mono); font-size: 0.8rem; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}
input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--sans);
    transition: border-color var(--transition);
}
input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
}
input::placeholder { color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--sans);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ── Copy Button ──────────────────────────────────────────────── */
.copy-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.6rem;
    font-family: var(--mono);
    font-size: 0.8rem;
    word-break: break-all;
}
.copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    font-size: 0.9rem;
    transition: color var(--transition);
    flex-shrink: 0;
}
.copy-btn:hover { color: var(--accent); }
.copy-btn.copied { color: var(--success); }

/* ── Flash Messages ───────────────────────────────────────────── */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: flashIn 300ms ease;
}
.flash-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}
.flash-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Badge / Status ───────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}
.badge-revoked {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}
.badge-used {
    background: rgba(100, 116, 139, 0.2);
    color: var(--text-muted);
}
.badge-admin {
    background: rgba(6, 182, 212, 0.15);
    color: var(--accent-cyan);
}

/* ── Auth Pages (Login / Register) ────────────────────────────── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.auth-box {
    width: 100%;
    max-width: 400px;
}
.auth-box .card { padding: 2rem; }
.auth-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-logo h1 {
    font-family: var(--mono);
    font-size: 1.5rem;
    color: var(--accent);
}
.auth-logo p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}
.auth-footer {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ── Empty States ─────────────────────────────────────────────── */
.empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.empty code {
    display: block;
    margin-top: 0.75rem;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

/* ── Token Reveal ─────────────────────────────────────────────── */
.token-reveal {
    background: rgba(16, 185, 129, 0.05);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 0.75rem;
    animation: flashIn 300ms ease;
}
.token-reveal p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}
.token-reveal strong { color: var(--warning); }

/* ── HTMX indicator ───────────────────────────────────────────── */
.htmx-indicator {
    display: none;
    color: var(--accent);
    font-size: 0.8rem;
}
.htmx-request .htmx-indicator { display: inline; }

/* ── Inline Form ──────────────────────────────────────────────── */
.inline-form {
    display: flex;
    gap: 0.5rem;
    align-items: end;
    margin-top: 0.75rem;
}
.inline-form input {
    flex: 1;
    padding: 0.5rem 0.625rem;
}

/* ── Password strength ────────────────────────────────────────── */
.pw-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    .nav { padding: 0 1rem; }
    .main { padding: 1rem; }
    .card { padding: 1rem; }
    .auth-box .card { padding: 1.25rem; }
    table { font-size: 0.8rem; }
    th, td { padding: 0.5rem; }
    .inline-form { flex-direction: column; }
    .hide-mobile { display: none; }
}
