:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success-bg: #ecfdf5;
    --success-text: #047857;
    --error-bg: #fef2f2;
    --error-text: #b91c1c;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --radius: 12px;
}

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

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

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 20px;
}

.page {
    padding-top: 8px;
}

/* Auth */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(145deg, #eef2ff 0%, #f8fafc 45%, #ede9fe 100%);
}

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 50px rgba(79, 70, 229, 0.08);
}

.auth-brand {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 28px;
}

.auth-logo,
.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.auth-brand h1,
.brand-title {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.subtitle,
.brand-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Topbar */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    padding-bottom: 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.card-desc {
    color: var(--text-muted);
    font-size: 0.92rem;
    margin-bottom: 18px;
}

.card-header-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.card-header-row h2 {
    margin-bottom: 0;
}

.count-badge {
    background: #eef2ff;
    color: #4338ca;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
}

.toolbar-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Forms */
.label-text {
    display: block;
    font-size: 0.88rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}

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

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: end;
}

.form-grid .span-2 {
    grid-column: span 2;
}

.form-grid-action,
.form-grid-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
    outline: none;
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Buttons */
.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

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

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

.btn-secondary {
    background: #eef2ff;
    color: #3730a3;
}

.btn-secondary:hover {
    background: #e0e7ff;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: #f8fafc;
    color: var(--text);
}

.btn-outline {
    background: #fff;
    color: var(--primary);
    border: 1px solid #c7d2fe;
}

.btn-outline:hover,
.btn-outline.is-active {
    background: #eef2ff;
    border-color: #818cf8;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
    border: 1px solid #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.action-box-danger {
    border-color: #fecaca;
    background: #fffafa;
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid #fecaca;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid #a7f3d0;
}

.hint {
    color: var(--text-muted);
    font-size: 0.92rem;
}

/* Table */
.card-table {
    padding-top: 18px;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

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

.data-table th,
.data-table td {
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr:not(.actions-row):hover {
    background: #fafbff;
}

.data-table th {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    color: #475569;
    background: #f8fafc;
}

.data-table tbody tr:last-child td,
.data-table tbody tr.actions-row td {
    border-bottom: none;
}

.code-cell code {
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: #f1f5f9;
    padding: 6px 10px;
    border-radius: 6px;
    color: #0f172a;
}

.nowrap {
    white-space: nowrap;
}

.users-cell {
    min-width: 180px;
}

.user-line {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

.user-line:last-child {
    margin-bottom: 0;
}

.user-name {
    font-weight: 600;
    color: #334155;
}

.muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-expired { background: #fee2e2; color: #991b1b; }
.badge-used { background: #dbeafe; color: #1e40af; }

/* Actions panel */
.actions-row.hidden {
    display: none;
}

.actions-row td {
    background: #f8fafc;
    padding-top: 0;
    padding-bottom: 18px;
}

.action-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    padding-top: 4px;
}

.action-box {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
}

.action-box h3 {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.action-hint {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 12px;
}

.action-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.action-form input,
.action-form select {
    flex: 1;
    min-width: 0;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #475569;
}

.empty-state .muted {
    margin-top: 6px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.pagination-info {
    font-size: 0.92rem;
    color: var(--text-muted);
    font-weight: 500;
}

.btn.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

@media (max-width: 960px) {
    .toolbar-grid,
    .action-panel {
        grid-template-columns: 1fr;
    }

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

    .form-grid .span-2 {
        grid-column: span 1;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 16px 12px;
    }

    .auth-card,
    .card {
        padding: 18px 16px;
    }

    .data-table th,
    .data-table td {
        padding: 10px 12px;
    }

    .action-form {
        flex-direction: column;
        align-items: stretch;
    }
}
