/* =====================================================================
   Routing Admin Dashboard - same palette as playground + map UI
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --bg-input-focus: #ffffff;
    --bg-elevated: #f1f5f9;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-focus: #93c5fd;
    --success: #10b981;
    --warn: #f59e0b;
    --err: #ef4444;
    --err-hover: #dc2626;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.15);
    --radius-sm: 6px;
    --radius-md: 8px;
    --transition: 0.18s ease-in-out;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
}
body { overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
code {
    font-family: "SF Mono", Menlo, Consolas, monospace;
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: 1px 6px; border-radius: 4px;
    font-size: 0.85em;
    border: 1px solid var(--border);
}

/* ───── Top nav ───── */
.page-nav {
    position: fixed; top: 16px; right: 16px; z-index: 1000;
    display: flex; gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 4px;
    box-shadow: var(--shadow-md);
}
.page-nav a {
    color: var(--text-secondary);
    padding: 6px 14px; border-radius: var(--radius-sm);
    font-size: 0.85rem; font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.page-nav a:hover { background: var(--bg-elevated); color: var(--text-primary); }
.page-nav a.active { background: var(--accent); color: white; }

/* ───── Auth screen ───── */
.auth-screen {
    display: flex; align-items: center; justify-content: center;
    height: 100vh;
    padding: 20px;
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}
.auth-header { margin-bottom: 24px; }
.auth-header h1 { font-size: 1.4rem; font-weight: 600; margin-bottom: 4px; }
.auth-header .subtitle { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-error {
    background: #fef2f2; color: #991b1b;
    border: 1px solid #fecaca; border-radius: var(--radius-sm);
    padding: 8px 12px; font-size: 0.85rem;
    text-align: center;
}

/* ───── Form rows (shared) ───── */
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row label {
    font-size: 0.75rem; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.form-row input[type=text],
.form-row input[type=password],
.form-row input[type=email] {
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    transition: all var(--transition);
}
.form-row input:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.2);
}

/* ───── Buttons (shared) ───── */
.btn {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.88rem; font-weight: 500;
    font-family: inherit;
    transition: all var(--transition);
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); }
.btn-danger { background: var(--err); color: white; border-color: var(--err); }
.btn-danger:hover { background: var(--err-hover); border-color: var(--err-hover); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ───── Dashboard layout ───── */
.dashboard {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: 100vh;
}

/* ───── Sidebar ───── */
.sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 20px;
    display: flex; flex-direction: column; gap: 12px;
}
.brand { padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.brand h1 { font-size: 1.05rem; font-weight: 600; }
.brand .subtitle { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
    color: var(--text-secondary);
    padding: 8px 10px; border-radius: var(--radius-sm);
    font-size: 0.88rem; font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.side-nav a:hover { background: var(--bg-elevated); color: var(--text-primary); }
.side-nav a.active { background: var(--bg-elevated); color: var(--accent); }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

/* ───── Content ───── */
.content {
    overflow-y: auto;
    padding: 28px 32px;
    scroll-behavior: smooth;
}
.content-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 22px 26px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    scroll-margin-top: 8px;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}
.card-header h2 { font-size: 1.1rem; font-weight: 600; }
.card-actions { display: flex; align-items: center; gap: 10px; }

.checkbox-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.82rem; color: var(--text-secondary);
    cursor: pointer; user-select: none;
}
.checkbox-label input { cursor: pointer; }
.search-input {
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    width: 240px;
    font-family: inherit;
    transition: all var(--transition);
}
.search-input:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
}

/* ───── Summary cards ───── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}
.stat {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}
.stat-label {
    font-size: 0.72rem; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
}
.stat-value {
    font-size: 1.6rem; font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* ───── Keys table ───── */
.table-wrap { overflow-x: auto; }
.keys-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.keys-table th {
    text-align: left;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.keys-table th.num { text-align: right; }
.keys-table td {
    padding: 12px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}
.keys-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.keys-table tr:last-child td { border-bottom: none; }
.keys-table tr:hover { background: var(--bg-elevated); }
.keys-table tr.revoked td { color: var(--text-muted); }

.label-cell { font-weight: 500; color: var(--text-primary); }
.label-cell .email-line { font-size: 0.72rem; color: var(--text-muted); font-weight: 400; margin-top: 2px; }
.key-preview {
    font-family: "SF Mono", Menlo, Consolas, monospace;
    color: var(--text-primary);
    background: var(--bg-elevated);
    padding: 3px 8px; border-radius: 4px;
    font-size: 0.78rem;
}
.creator-cell { font-size: 0.82rem; }
.creator-cell .ip { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; font-family: monospace; }
.time-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }

.status-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.72rem; font-weight: 600;
}
.status-active { background: #d1fae5; color: #047857; }
.status-revoked { background: #fee2e2; color: #991b1b; }

.row-actions { white-space: nowrap; text-align: right; }
.action-btn {
    background: transparent;
    color: var(--err);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.78rem; font-weight: 500;
    font-family: inherit;
    transition: all var(--transition);
}
.action-btn:hover { background: var(--err); color: white; border-color: var(--err); }

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px !important;
    font-style: italic;
}

/* ───── Modals ───── */
.modal {
    position: fixed; inset: 0; z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
/* The HTML `hidden` attribute defaults to display:none in user-agent
   CSS, but class selectors with display:flex above outrank it. Restore
   hidden behaviour explicitly. Same trick for any [hidden] inside modal. */
.modal[hidden], [hidden] { display: none !important; }
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, 0.5);
}
.modal-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    width: 100%;
    max-width: 460px;
}
.modal-card h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 12px; }
.modal-card p { color: var(--text-secondary); font-size: 0.9rem; line-height: 1.55; margin-bottom: 16px; }
.modal-actions {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 20px;
}
.key-shown-once {
    font-weight: 500; color: var(--text-primary) !important;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin: 12px 0 8px !important;
}
.key-value-row {
    display: flex; gap: 8px; align-items: stretch;
    margin-bottom: 8px;
}
.key-value-row code {
    flex: 1;
    background: var(--bg-elevated);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    user-select: all;
    word-break: break-all;
    border: 1px solid var(--border);
}

/* ───── Toasts ───── */
.toast-container {
    position: fixed; top: 72px; right: 20px; z-index: 2100;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    transition: opacity 0.3s, transform 0.3s;
    min-width: 240px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--err); }

/* ───── Responsive ───── */
@media (max-width: 760px) {
    .dashboard { grid-template-columns: 1fr; height: auto; }
    body { overflow: auto; }
    .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
    .content { padding: 20px; }
    .search-input { width: 160px; }
}
