/* ==========================================================================
   rdirct — premium design system (white/blue light, dark mode)
   ========================================================================== */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --blue-600: #2563eb;
    --blue-700: #1d4ed8;
    --blue-50: #eff6ff;

    --bg: #f7f9fc;
    --surface: #ffffff;
    --surface-alt: #f1f5fb;
    --border: #e3e8f0;
    --text: #14171f;
    --text-muted: #6b7280;
    --primary: var(--blue-600);
    --primary-hover: var(--blue-700);
    --primary-contrast: #ffffff;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.08);
}

[data-theme="dark"] {
    --bg: #0b0e14;
    --surface: #131722;
    --surface-alt: #1a1f2e;
    --border: #262c3d;
    --text: #e8eaf0;
    --text-muted: #8b93a7;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-contrast: #0b0e14;
    --success: #4ade80;
    --success-bg: rgba(74, 222, 128, 0.1);
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.1);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s ease, color 0.2s ease;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { font-weight: 800; font-size: 1.3rem; display: flex; align-items: center; gap: 0.4rem; color: var(--text); text-decoration: none; }
.brand .dot { color: var(--primary); }

.topbar nav { display: flex; align-items: center; gap: 1.25rem; }
.topbar nav a { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; font-weight: 500; }
.topbar nav a:hover { color: var(--text); }

.btn-nav { background: var(--primary); color: var(--primary-contrast) !important; padding: 0.55rem 1.1rem; border-radius: var(--radius-sm); font-weight: 600 !important; }
.btn-nav:hover { background: var(--primary-hover); }

.theme-toggle {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px; height: 36px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.theme-toggle:hover { border-color: var(--primary); }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: inline; }

.hero {
    text-align: center;
    padding: 7rem 2rem 5rem;
    background: radial-gradient(circle at 20% 20%, var(--blue-50) 0%, transparent 45%), var(--bg);
}
[data-theme="dark"] .hero { background: radial-gradient(circle at 20% 20%, rgba(59,130,246,0.08) 0%, transparent 45%), var(--bg); }

.hero-badge {
    display: inline-flex; align-items: center; gap: 0.4rem;
    background: var(--surface); border: 1px solid var(--border);
    padding: 0.4rem 0.9rem; border-radius: 999px;
    font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1.5rem;
}

.hero h1 { font-size: 3.25rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 1rem; line-height: 1.1; }
.hero h1 span { color: var(--primary); }
.hero p { color: var(--text-muted); font-size: 1.15rem; max-width: 520px; margin: 0 auto 2rem; }

.btn-primary {
    display: inline-flex; align-items: center; gap: 0.5rem;
    background: var(--primary); color: var(--primary-contrast);
    text-decoration: none; padding: 0.85rem 2rem; border-radius: var(--radius-sm);
    font-weight: 600; border: none; cursor: pointer; font-size: 1rem; box-shadow: var(--shadow);
}
.btn-primary:hover { background: var(--primary-hover); }

.features { max-width: 1000px; margin: 0 auto; padding: 3rem 2rem 6rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.5rem; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.75rem; }
.feature-card i { color: var(--primary); margin-bottom: 0.75rem; font-size: 1.5rem; }
.feature-card h3 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.feature-card p { margin: 0; color: var(--text-muted); font-size: 0.9rem; line-height: 1.5; }

.auth-page { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 65px); padding: 2rem; }

.auth-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 2.5rem; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg);
}
.auth-card h1 { margin-top: 0; font-size: 1.5rem; }
.auth-card .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: -0.75rem; margin-bottom: 1.5rem; }

form label { display: block; font-size: 0.85rem; margin: 1rem 0 0.4rem; color: var(--text-muted); font-weight: 500; }

form input, form textarea, form select {
    width: 100%; padding: 0.65rem 0.85rem; background: var(--surface-alt);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); font-size: 0.95rem; font-family: inherit;
}
form input:focus, form textarea:focus, form select:focus { outline: none; border-color: var(--primary); }

form button[type="submit"], .btn-form {
    width: 100%; margin-top: 1.5rem; padding: 0.75rem;
    background: var(--primary); color: var(--primary-contrast); border: none;
    border-radius: var(--radius-sm); font-weight: 600; font-size: 0.95rem; cursor: pointer;
}
form button[type="submit"]:hover, .btn-form:hover { background: var(--primary-hover); }

.auth-switch { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; color: var(--text-muted); }
.auth-links { display: flex; justify-content: space-between; font-size: 0.85rem; margin-top: 0.5rem; }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.9rem; display: flex; align-items: flex-start; gap: 0.5rem; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid var(--error); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.alert-info { background: var(--blue-50); color: var(--blue-700); border: 1px solid var(--border); }
[data-theme="dark"] .alert-info { background: rgba(59,130,246,0.1); color: #93c5fd; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px; background: var(--surface); border-right: 1px solid var(--border);
    padding: 1.5rem 1rem; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
    display: flex; flex-direction: column;
}
.sidebar .brand { padding: 0 0.5rem 1.5rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar nav a { display: flex; align-items: center; gap: 0.65rem; padding: 0.6rem 0.75rem; border-radius: var(--radius-sm); color: var(--text-muted); text-decoration: none; font-size: 0.9rem; font-weight: 500; }
.sidebar nav a:hover { background: var(--surface-alt); color: var(--text); }
.sidebar nav a.active { background: var(--blue-50); color: var(--primary); }
[data-theme="dark"] .sidebar nav a.active { background: rgba(59,130,246,0.12); }
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); }

.main-content { flex: 1; padding: 2rem 2.5rem; max-width: 1200px; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.page-header h1 { margin: 0; font-size: 1.5rem; }
.page-header p { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.9rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.5rem; margin-bottom: 1.5rem; }
.card h2 { margin-top: 0; font-size: 1.05rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.25rem; }
.stat-card .label { color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; margin-top: 0.3rem; }
.stat-card i { color: var(--primary); }

.inline-form { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 180px; }
.inline-form button { background: var(--primary); color: var(--primary-contrast); border: none; padding: 0.65rem 1.25rem; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; }
.inline-form button:hover { background: var(--primary-hover); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.7rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--font-mono); font-size: 0.85em; }

.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-neutral { background: var(--surface-alt); color: var(--text-muted); }

.btn-sm { padding: 0.35rem 0.8rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 0.8rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 0.3rem; }
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm.danger:hover { border-color: var(--error); color: var(--error); }

.api-key-box {
    display: flex; align-items: center; gap: 0.75rem;
    background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 0.75rem 1rem; font-family: var(--font-mono); font-size: 0.85rem;
}
.api-key-box code { flex: 1; overflow-x: auto; white-space: nowrap; }

.pagination { display: flex; gap: 0.5rem; margin-top: 1rem; }

@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
    .sidebar nav { flex-direction: row; overflow-x: auto; }
    .main-content { padding: 1.25rem; }
    .hero h1 { font-size: 2.25rem; }
}
