:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --error: #dc2626;
    --error-light: #fef2f2;
    --error-border: #fecaca;
    --success: #15803d;
    --success-light: #f0fdf4;
    --success-border: #bbf7d0;
    --text: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    padding: 28px 16px 56px;
}

/* ========================
   Layout
   ======================== */

.container {
    max-width: 800px;
    margin: 0 auto;
}

header {
    margin-bottom: 28px;
}

header h1 {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

header .subtitle {
    color: var(--text-muted);
    font-size: 15px;
}

/* ========================
   Cards
   ======================== */

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.card h2 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 18px;
    color: var(--text);
}

.card.collapsible {
    padding: 0;
    overflow: hidden;
}

.card.collapsible > summary {
    padding: 20px 24px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}

.card.collapsible > summary::-webkit-details-marker {
    display: none;
}

.card.collapsible > summary::before {
    content: '\25B6';
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform 0.15s ease;
    display: inline-block;
}

.card.collapsible[open] > summary::before {
    transform: rotate(90deg);
}

.card.collapsible > summary h2 {
    margin-bottom: 0;
    flex: 1;
}

.collapsible-body {
    padding: 0 24px 24px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

/* ========================
   Form elements
   ======================== */

.form-group {
    margin-bottom: 18px;
}

.form-group:last-child {
    margin-bottom: 0;
}

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

@media (max-width: 560px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.required {
    color: var(--error);
    margin-left: 1px;
}

.optional {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-muted);
}

input[type="text"],
input[type="number"],
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input.invalid,
textarea.invalid {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

/* ========================
   File input
   ======================== */

.file-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-file {
    padding: 9px 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    color: var(--text);
}

.btn-file:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.file-display {
    font-size: 14px;
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-display.has-file {
    color: var(--text);
    font-weight: 500;
}

/* ========================
   Checkbox
   ======================== */

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.align-end {
    display: flex;
    align-items: flex-end;
    padding-bottom: 2px;
}

/* ========================
   Hints
   ======================== */

.hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 5px;
    line-height: 1.4;
}

/* ========================
   Section headers (with toggle)
   ======================== */

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

.section-header h2,
.section-header h3 {
    margin-bottom: 0;
}

.card .section-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.subsection {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.subsection h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0;
}

/* ========================
   Dict / key-value tables
   ======================== */

.dict-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 8px;
    font-size: 14px;
}

.dict-table th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0 8px 8px 0;
    border-bottom: 1px solid var(--border);
}

.dict-table td {
    padding: 5px 8px 5px 0;
    vertical-align: middle;
}

.dict-table td:nth-child(2) {
    width: 110px;
}

.dict-table td:last-child {
    width: 36px;
    padding-right: 0;
}

.key-input {
    width: 100%;
}

.val-input {
    width: 100%;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    padding: 5px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.12s, background 0.12s;
    display: block;
    width: 100%;
    text-align: center;
}

.btn-remove:hover {
    color: var(--error);
    background: var(--error-light);
}

.btn-add {
    background: none;
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 12px;
    width: 100%;
    text-align: center;
    margin-top: 4px;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-add:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.btn-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 12px;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.json-editor {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
    min-height: 120px;
    resize: vertical;
    background: #f9fafb;
    line-height: 1.6;
}

/* ========================
   Error & success banners
   ======================== */

.error-banner,
.success-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    font-size: 14px;
    border: 1px solid;
}

.error-banner {
    background: var(--error-light);
    border-color: var(--error-border);
    color: var(--error);
}

.success-banner {
    background: var(--success-light);
    border-color: var(--success-border);
    color: var(--success);
}

.error-icon,
.success-icon {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

.field-error {
    font-size: 13px;
    color: var(--error);
    margin-top: 5px;
    min-height: 1em;
    line-height: 1.3;
}

/* ========================
   Submit button
   ======================== */

.submit-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 11px 28px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

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

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-primary:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

/* ========================
   Loading spinner
   ======================== */

.spinner {
    width: 17px;
    height: 17px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

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

.hidden {
    display: none !important;
}

/* ========================
   Login page
   ======================== */

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

.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.10), 0 1px 4px 0 rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border);
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    text-align: center;
    letter-spacing: -0.3px;
}

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

/* Password input type */
input[type="password"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    appearance: none;
}

input[type="password"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input[type="password"].invalid {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.btn-full {
    width: 100%;
    justify-content: center;
    margin-top: 8px;
}

/* ========================
   Header with logout
   ======================== */

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    gap: 16px;
}

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

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 7px 14px;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-logout:hover {
    border-color: var(--error);
    color: var(--error);
    background: var(--error-light);
}

/* ========================
   Stats
   ======================== */

.stats-actions {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 16px;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 9px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--primary-light);
}

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

.spinner-dark {
    border-color: rgba(37, 99, 235, 0.25);
    border-top-color: var(--primary);
}

.stats-panel h2 {
    margin-bottom: 16px;
}

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

.stat-card {
    background: var(--bg);
    border-radius: 6px;
    padding: 14px 16px;
    text-align: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stats-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.stats-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.stats-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 6px 10px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.stats-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
}

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

.stats-table .timeslot-name {
    font-weight: 500;
    white-space: nowrap;
}

.stats-table .num {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.stats-table .num-zero {
    color: var(--text-muted);
}

.stats-table .num-high {
    font-weight: 600;
    color: var(--primary);
}
