/* ── Variables ──────────────────────────────────────────────────── */
:root {
    --primary: #1e3a5f;
    --primary-light: #2a5080;
    --primary-dark: #0f2440;
    --accent: #e8a838;
    --accent-light: #f0c060;
    --bg: #f5f3ef;
    --bg-card: #ffffff;
    --bg-sidebar: #1a1a2e;
    --bg-sidebar-hover: #25253f;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --text-sidebar: #c4c4d4;
    --text-sidebar-active: #ffffff;
    --border: #e2e0dc;
    --border-light: #f0eee9;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --font: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition: 150ms ease;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
table { border-collapse: collapse; }

/* ── Layout ────────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text {
    color: #fff;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
}

.nav-section {
    color: rgba(255,255,255,0.35);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 16px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 6px;
    color: var(--text-sidebar);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.nav-item.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin-bottom: 4px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

.user-details { flex: 1; min-width: 0; }
.user-name { color: #fff; font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--text-sidebar); font-size: 0.72rem; text-transform: capitalize; }

.logout-btn { color: #ef4444 !important; }
.logout-btn:hover { background: rgba(239,68,68,0.12) !important; }

/* ── Main content ──────────────────────────────────────────────── */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 24px;
    overflow-x: auto;
}

/* ── Flash messages ────────────────────────────────────────────── */
.flash-messages { margin-bottom: 16px; }
.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    animation: slideDown 200ms ease;
}
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.flash-close { background: none; border: none; cursor: pointer; font-size: 1.2rem; opacity: 0.6; }
.flash-close:hover { opacity: 1; }

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

/* ── Page headers ──────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 2px;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: var(--accent-light); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #fff; border-color: var(--primary); }
.btn-danger { background: #fee2e2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-icon { padding: 6px; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.card-body {
    padding: 20px;
}

/* ── Stats grid ────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--primary);
    font-family: var(--font-mono);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-top: 4px;
}

/* ── Tables ────────────────────────────────────────────────────── */
.data-table {
    width: 100%;
    font-size: 0.85rem;
}

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

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

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

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 4px;
    color: var(--text);
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: border-color var(--transition);
    background: var(--bg-card);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30,58,95,0.08);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.form-inline {
    display: flex;
    gap: 8px;
    align-items: end;
}

/* ── Color swatch ──────────────────────────────────────────────── */
.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 2px solid var(--border);
    display: inline-block;
    vertical-align: middle;
}

.color-input {
    width: 50px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2px;
    cursor: pointer;
}

/* ── Badge ─────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fee2e2; color: #991b1b; }
.badge-admin { background: #ede9fe; color: #5b21b6; }

/* ── Planning Grid ─────────────────────────────────────────────── */
.planning-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.planning-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.planning-nav .month-label {
    font-size: 1.2rem;
    font-weight: 700;
    min-width: 200px;
    text-align: center;
    letter-spacing: -0.02em;
}

.planning-legend {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 500;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Planning table */
.planning-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
}

.planning-table {
    width: 100%;
    font-size: 0.72rem;
    border-collapse: collapse;
    min-width: 1200px;
}

.planning-table th,
.planning-table td {
    border: 1px solid var(--border-light);
    padding: 0;
    text-align: center;
    vertical-align: top;
}

.planning-table thead th {
    background: var(--primary-dark);
    color: #fff;
    font-weight: 600;
    font-size: 0.7rem;
    padding: 6px 2px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.planning-table thead th.weekend {
    background: #374151;
}

.planning-table thead th.today-col {
    background: var(--accent);
    color: var(--primary-dark);
}

.planning-table .employee-name-col {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--bg-card);
    min-width: 130px;
    max-width: 150px;
    text-align: left;
    padding: 6px 10px;
    font-weight: 600;
    font-size: 0.78rem;
    border-right: 2px solid var(--border);
}

.planning-table thead .employee-name-col {
    background: var(--primary-dark);
    z-index: 15;
}

.planning-table td.weekend {
    background: #f9fafb;
}

.planning-table td.today-col {
    background: #fffbeb;
}

/* Cell content */
.cell-content {
    min-height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2px;
    cursor: pointer;
    transition: background var(--transition);
    position: relative;
}

.cell-content:hover {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    z-index: 2;
}

.cell-content.has-assignment {
    font-size: 0.68rem;
    line-height: 1.3;
    font-weight: 500;
}

.cell-text {
    padding: 2px 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

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

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 480px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 200ms ease;
}

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

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-weight: 700;
    font-size: 1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Login page ────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, #2a5080 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 380px;
    max-width: 100%;
    padding: 40px 32px;
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 32px;
}

.login-logo-text {
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.03em;
}

.login-form .form-group { margin-bottom: 20px; }
.login-form .btn { width: 100%; justify-content: center; padding: 10px; font-size: 0.95rem; }

/* ── Display page (Raspberry Pi) ───────────────────────────────── */
.display-page {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: #0a0a1a;
    color: #fff;
    min-height: 100vh;
}

.display-header {
    background: linear-gradient(90deg, var(--primary-dark), var(--primary));
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.display-title {
    font-size: 1.4rem;
    font-weight: 700;
}

.display-date {
    font-size: 0.9rem;
    opacity: 0.8;
}

.display-grid {
    padding: 8px;
    overflow-x: auto;
}

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

.display-table th,
.display-table td {
    border: 1px solid #1e293b;
    padding: 4px 3px;
    text-align: center;
    vertical-align: middle;
}

.display-table thead th {
    background: #1e293b;
    color: #94a3b8;
    font-weight: 600;
    padding: 8px 3px;
    font-size: 0.7rem;
}

.display-table thead th.today-col {
    background: var(--accent);
    color: #000;
}

.display-table .emp-col {
    text-align: left;
    padding: 6px 10px;
    font-weight: 600;
    background: #111827;
    min-width: 120px;
    white-space: nowrap;
    font-size: 0.8rem;
}

.display-table td {
    background: #0f172a;
    min-height: 36px;
}

.display-table td.weekend {
    background: #0c1322;
    opacity: 0.6;
}

.display-table td.today-col {
    background: rgba(232, 168, 56, 0.08);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.display-cell {
    font-size: 0.65rem;
    line-height: 1.3;
    padding: 3px 2px;
    border-radius: 3px;
    font-weight: 500;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 16px; }
    .page-title { font-size: 1.3rem; }
}

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.95rem;
}

/* ── Utilities ─────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.82rem; }
.text-xs { font-size: 0.72rem; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mono { font-family: var(--font-mono); }
