:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --border: #e8e9ec;
    --text: #1a1a1a;
    --text-muted: #8a8f98;
    --primary: #1a1a1a;
    --primary-hover: #333;
    --accent: #2563eb;
    --accent-bg: #eff6ff;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --yellow: #ca8a04;
    --yellow-bg: #fef9c3;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 8px 32px rgba(16, 24, 40, 0.14);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    font-size: 17px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.container {
    max-width: 1500px;
    margin: 0 auto;
    padding: 24px 24px 60px;
}

/* ── User chip ── */
.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-muted);
}

.user-chip .role-badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 7px;
    border-radius: 20px;
    background: var(--accent-bg);
    color: var(--accent);
}

/* ── Buttons ── */
.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, opacity 0.15s, transform 0.05s;
}

.btn:active {
    transform: scale(0.97);
}

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

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

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

.btn-outline:hover {
    background: #fafafa;
}

.btn-danger-outline {
    background: #fff5f5;
    border: 1px solid #fecaca;
    color: var(--red);
}

.btn-danger-outline:hover {
    background: #fee2e2;
}

.btn-accent-outline {
    background: var(--accent-bg);
    border: 1px solid #dbeafe;
    color: var(--accent);
}

.btn-sm {
    padding: 5px 11px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Status cards ── */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

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

.card-value {
    font-size: 24px;
    font-weight: 600;
}

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 11px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-gray { background: #f3f4f6; color: #6b7280; }

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.dot-green { background: #22c55e; }
.dot-red { background: #ef4444; }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: #eceef1;
    padding: 4px;
    border-radius: 11px;
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
}

.tab {
    padding: 7px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-muted);
    white-space: nowrap;
    transition: all 0.15s;
}

.tab.active {
    background: #fff;
    color: var(--text);
    box-shadow: var(--shadow);
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Table ── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    padding: 11px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
}

tbody td {
    padding: 13px 16px;
    font-size: 14px;
    border-bottom: 1px solid #f5f5f5;
}

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

tbody tr:hover {
    background: #fafbfc;
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #eef0f3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    margin-right: 10px;
    flex-shrink: 0;
}

.name-cell {
    display: flex;
    align-items: center;
}

.empty {
    padding: 40px;
    text-align: center;
    color: #c3c6cc;
    font-size: 14px;
}

.hint-text {
    font-size: 12px;
    color: var(--text-muted);
}

.phase-badge {
    font-size: 11px;
    padding: 2px 9px;
    border-radius: 5px;
    font-weight: 500;
}

.phase-active { background: var(--green-bg); color: var(--green); }
.phase-expired { background: #f3f4f6; color: #9ca3af; }

/* ── Info banner ── */
.info-banner {
    font-size: 12px;
    color: #6b7280;
    background: #f8f9fb;
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    line-height: 1.5;
}

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 21, 0.4);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.open {
    display: flex;
}

.modal-box {
    background: #fff;
    border-radius: 16px;
    padding: 26px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-box.wide {
    max-width: 480px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.field {
    margin-bottom: 16px;
}

.field label {
    font-size: 12px;
    color: #666;
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

.field input,
.field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    background: #fff;
}

.field input:focus,
.field select:focus {
    border-color: var(--accent);
}

.form-error {
    display: none;
    color: var(--red);
    font-size: 13px;
    margin-bottom: 12px;
    background: var(--red-bg);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
}

.form-success {
    display: none;
    color: var(--green);
    font-size: 13px;
    margin-bottom: 12px;
    background: var(--green-bg);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 4px;
}

/* ── Toast ── */
#toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 300;
}

.toast {
    background: #1a1a1a;
    color: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    max-width: 320px;
    animation: toast-in 0.2s ease-out;
}

.toast.error { background: #dc2626; }
.toast.success { background: #16a34a; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Spinner ── */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Login page ── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.login-logo {
    font-size: 34px;
    text-align: center;
    margin-bottom: 8px;
}

.login-card h1 {
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 4px;
}

.login-card p.subtitle {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 28px;
}

.login-card .btn-dark {
    width: 100%;
    justify-content: center;
    padding: 11px;
    margin-top: 6px;
}

@media (max-width: 600px) {
    header {
        padding: 10px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }
    header h1 { font-size: 15px; }
    #last-updated { display: none; }
    .user-chip { font-size: 12px; gap: 6px; }
    .grid { grid-template-columns: 1fr 1fr; }
    .card-value { font-size: 19px; }
    thead th:nth-child(3), tbody td:nth-child(3) { display: none; }
}
