/* Gate — Dark Theme Stylesheet */

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #16161f;
    --bg-input: #1a1a25;
    --bg-hover: #1e1e2a;
    --border: #2a2a3a;
    --border-focus: #5b5bd6;
    --text-primary: #ededf0;
    --text-secondary: #a0a0b0;
    --text-muted: #6b6b80;
    --accent: #6c6cf0;
    --accent-hover: #5b5bd6;
    --accent-glow: rgba(108, 108, 240, 0.15);
    --danger: #e5484d;
    --danger-hover: #d13438;
    --success: #30a46c;
    --warning: #f5a623;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ─── Login Page ─── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(108, 108, 240, 0.08) 0%, transparent 60%),
        var(--bg-primary);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 2rem 1.5rem;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-icon {
    margin: 0 auto 1.5rem;
    width: 56px;
    height: 56px;
    background: var(--accent-glow);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(108, 108, 240, 0.1); }
    50% { box-shadow: 0 0 0 8px rgba(108, 108, 240, 0.05); }
}

.login-icon svg {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.login-logo {
    margin: 0 auto 1.5rem;
}

.login-logo img {
    max-height: 48px;
    max-width: 200px;
}

.login-title {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    letter-spacing: -0.01em;
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.input-group {
    position: relative;
}

.login-input {
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.login-input::placeholder {
    color: var(--text-muted);
}

.login-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: var(--font);
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.login-button:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-button:active {
    transform: scale(0.98);
}

.login-button svg {
    width: 16px;
    height: 16px;
    transition: transform var(--transition);
}

.login-button:hover svg {
    transform: translateX(2px);
}

.login-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    color: var(--danger);
    background: rgba(229, 72, 77, 0.08);
    border: 1px solid rgba(229, 72, 77, 0.2);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    animation: shakeIn 0.4s ease-out;
}

@keyframes shakeIn {
    0% { transform: translateX(-8px); opacity: 0; }
    25% { transform: translateX(6px); }
    50% { transform: translateX(-4px); }
    75% { transform: translateX(2px); }
    100% { transform: translateX(0); opacity: 1; }
}

.login-error svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ─── Admin Layout ─── */

.admin-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    margin-right: 1rem;
}

.nav-logo {
    width: 20px;
    height: 20px;
    color: var(--accent);
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    transition: color var(--transition), background var(--transition);
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-user {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

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

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.admin-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* ─── Cards ─── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

/* ─── Stats Grid ─── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stat-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-glow);
    border-radius: 10px;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 20px;
    height: 20px;
    color: var(--accent);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ─── Table ─── */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th {
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 0.75rem;
    border-bottom: 1px solid rgba(42, 42, 58, 0.5);
    vertical-align: middle;
}

.table tbody tr:hover {
    background: var(--bg-hover);
}

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

/* ─── Badges ─── */

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 500;
    border-radius: 20px;
    white-space: nowrap;
}

.badge-admin {
    background: rgba(108, 108, 240, 0.15);
    color: var(--accent);
}

.badge-user {
    background: rgba(48, 164, 108, 0.15);
    color: var(--success);
}

.badge-success, .badge-login_success {
    background: rgba(48, 164, 108, 0.15);
    color: var(--success);
}

.badge-muted, .badge-logout {
    background: rgba(107, 107, 128, 0.15);
    color: var(--text-muted);
}

.badge-login_failed, .badge-login_locked, .badge-login_rate_limited {
    background: rgba(229, 72, 77, 0.15);
    color: var(--danger);
}

.badge-code_created, .badge-code_revoked, .badge-session_revoked, .badge-code_create_failed {
    background: rgba(245, 166, 35, 0.15);
    color: var(--warning);
}

/* ─── Buttons ─── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: var(--font);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: rgba(229, 72, 77, 0.3);
}

.btn-danger:hover {
    background: rgba(229, 72, 77, 0.1);
}

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

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* ─── Modal (Dialog) ─── */

dialog.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 0;
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
}

dialog.modal::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* ─── Forms ─── */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.form-input {
    width: 100%;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b6b80' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

/* ─── Settings ─── */

.settings-grid {
    display: grid;
    gap: 1rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(42, 42, 58, 0.5);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.setting-value {
    font-size: 0.9rem;
    font-weight: 500;
}

.env-block {
    padding: 1rem;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow-x: auto;
    white-space: pre;
    line-height: 1.8;
}

/* ─── Utilities ─── */

.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); font-size: 0.85em; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }
.text-truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: rgba(229, 72, 77, 0.1);
    border: 1px solid rgba(229, 72, 77, 0.2);
    color: var(--danger);
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
    .admin-nav {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .nav-links {
        order: 3;
        width: 100%;
        overflow-x: auto;
        padding-bottom: 0.25rem;
    }

    .nav-link {
        white-space: nowrap;
    }

    .admin-main {
        padding: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .setting-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 2rem 1.5rem;
    }
}
