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

:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1a202c;
    --text-muted: #718096;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --error: #dc2626;
    --warning: #d97706;
    --radius: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* ===== Navbar ===== */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 52px;
    position: relative;
}

.nav-brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--primary);
}

.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: var(--text);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary);
}

.nav-logout button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
}

.nav-logout button:hover { color: var(--error); }

/* ===== Container ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== Cards ===== */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.card-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.card-value {
    font-size: 28px;
    font-weight: 700;
}

.card-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== Tables ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 24px;
}

.table-wrap table {
    margin-bottom: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    font-size: 13px;
}

th, td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    background: var(--bg);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

/* Allow text columns to wrap on narrow screens */
td.wrap { white-space: normal; min-width: 100px; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: "Cascadia Code", "Fira Code", monospace; font-size: 12px; }

.totals-row { background: var(--bg); }
.totals-row td { border-top: 2px solid var(--border); }

/* ===== Forms ===== */
.filter-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.form-group input,
.form-group select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--surface);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.form-actions {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
}

.checkbox { flex-direction: row; align-items: center; }
.checkbox label { display: flex; align-items: center; gap: 6px; font-size: 14px; }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 6px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

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

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

.btn-secondary:hover { background: var(--bg); }

.btn-full { width: 100%; text-align: center; }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.alert-success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }
.alert-token { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ===== Token display ===== */
.token-display {
    display: block;
    margin: 8px 0;
    padding: 8px 12px;
    background: #1e293b;
    color: #e2e8f0;
    border-radius: var(--radius);
    font-family: "Cascadia Code", "Fira Code", monospace;
    font-size: 13px;
    word-break: break-all;
    user-select: all;
}

.token-warning {
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.badge-active { background: #ecfdf5; color: var(--success); }
.badge-revoked { background: #fef2f2; color: var(--error); }

/* ===== Action buttons ===== */
.action-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-small {
    padding: 3px 10px;
    font-size: 12px;
}

.btn-danger {
    background: var(--surface);
    color: var(--error);
    border-color: var(--error);
}

.btn-danger:hover { background: #fef2f2; }

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 32px 16px;
}

/* ===== Login page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 24px;
    color: var(--primary);
}

.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { margin-top: 8px; }

/* ===== Headings ===== */
h1 { font-size: 22px; margin-bottom: 16px; }
h2 { font-size: 16px; margin: 24px 0 12px; color: var(--text-muted); }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
    margin: 16px 0;
}

.page-link {
    display: inline-block;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
}

.page-link:hover:not(.disabled):not(.active) {
    background: var(--bg);
    border-color: var(--primary);
}

.page-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-link.disabled {
    color: var(--text-muted);
    cursor: default;
    opacity: 0.5;
}

/* ===== Inline rename ===== */
.inline-rename { display: inline-flex; align-items: center; gap: 0.25rem; }
.rename-input { padding: 0.2rem 0.4rem; font-size: 0.9rem; width: 200px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    /* Navbar: hamburger toggle */
    .nav-toggle {
        display: block;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 52px;
        left: 0;
        right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        padding: 12px 24px;
        gap: 8px;
        z-index: 100;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    }

    .nav-links.open {
        display: flex;
    }

    .nav-links a {
        padding: 8px 12px;
        font-size: 15px;
    }

    .nav-logout {
        border-top: 1px solid var(--border);
        padding-top: 8px;
    }

    .nav-logout button {
        padding: 8px 12px;
        font-size: 15px;
    }

    /* Container */
    .container {
        padding: 16px 12px;
    }

    /* Cards */
    .card-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-bottom: 24px;
    }

    .card { padding: 12px; }
    .card-value { font-size: 22px; }

    /* Forms */
    .filter-row { flex-direction: column; }

    .form-group {
        width: 100%;
    }

    .form-group input,
    .form-group select {
        width: 100%;
    }

    .form-actions {
        flex-direction: row;
        width: 100%;
    }

    .form-actions .btn {
        flex: 1;
        text-align: center;
    }

    /* Tables */
    table { font-size: 12px; }
    th, td { padding: 6px 8px; }

    /* Headings */
    h1 { font-size: 18px; }
    h2 { font-size: 14px; }

    /* Action buttons: stack vertically on mobile */
    .action-buttons {
        flex-direction: column;
        gap: 4px;
    }

    /* Inline rename */
    .inline-rename {
        flex-direction: column;
        align-items: stretch;
    }

    .rename-input {
        width: 100%;
    }

    .inline-rename .btn-small {
        text-align: center;
    }

    /* Login */
    .login-card {
        margin: 16px;
        padding: 24px;
    }

    /* Alerts */
    .alert { font-size: 13px; }

    .token-display { font-size: 11px; }
}

@media (max-width: 400px) {
    .card-grid {
        grid-template-columns: 1fr;
    }

    .card-value { font-size: 20px; }
}
