:root {
    --sidebar-bg: #111827;
    --sidebar-hover: #1f2937;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --bg: #f4f6fa;
    --card-bg: #ffffff;
    --border: #e5e9f0;
    --text: #1e293b;
    --muted: #64748b;
    --danger: #dc2626;
    --warn: #d97706;
    --success: #16a34a;
    --sidebar-w: 240px;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; margin: 0; padding: 0; }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    overflow-y: auto;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid #1f2937;
}
.sidebar-brand .logo-box {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 0.95rem;
    flex-shrink: 0;
}
.sidebar-brand .brand-text { line-height: 1.2; }
.sidebar-brand .brand-title { color: white; font-weight: 700; font-size: 0.95rem; }
.sidebar-brand .brand-sub { color: #64748b; font-size: 0.68rem; }

.sidebar-nav { flex: 1; padding: 14px 10px; }
.sidebar-nav .nav-section { margin-bottom: 2px; }
.sidebar-nav a.nav-link, .sidebar-nav span.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    color: #cbd5e1; font-size: 0.86rem; font-weight: 500;
    cursor: pointer;
}
.sidebar-nav a.nav-link:hover { background: var(--sidebar-hover); color: white; text-decoration: none; }
.sidebar-nav a.nav-link.active { background: var(--primary); color: white; }
.sidebar-nav .nav-icon { width: 18px; text-align: center; opacity: 0.9; }
.sidebar-nav .nav-badge {
    margin-left: auto; background: var(--danger); color: white;
    font-size: 0.68rem; font-weight: 700; border-radius: 10px;
    padding: 1px 7px;
}
.sidebar-nav .sub-links { padding-left: 30px; margin-top: 2px; margin-bottom: 6px; }
.sidebar-nav .sub-links a {
    display: block; padding: 6px 10px; font-size: 0.8rem; color: #94a3b8; border-radius: 6px;
}
.sidebar-nav .sub-links a:hover, .sidebar-nav .sub-links a.active { color: white; background: var(--sidebar-hover); text-decoration: none; }

.sidebar-footer {
    padding: 14px; border-top: 1px solid #1f2937;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.sidebar-user:hover { background: var(--sidebar-hover); }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: white; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.sidebar-user .u-name { color: white; font-size: 0.82rem; font-weight: 600; }
.sidebar-user .u-role { color: #64748b; font-size: 0.7rem; }

.main-area { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.topbar .page-sub { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-search {
    display: flex; align-items: center; gap: 8px;
    background: #f1f5f9; border-radius: 8px; padding: 8px 14px;
    font-size: 0.85rem; color: var(--muted); min-width: 220px;
    border: none;
}
.bell-wrap { position: relative; }
.bell-badge {
    position: absolute; top: -6px; right: -6px; background: var(--danger); color: white;
    font-size: 0.65rem; font-weight: 700; border-radius: 10px; padding: 1px 5px; min-width: 16px; text-align: center;
}

.container { max-width: 1400px; margin: 0 auto; padding: 24px 28px; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.88rem; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-success { background: #dcfce7; color: #166534; }

/* ---------------- Auth ---------------- */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #111827, #312e81);
}
.auth-card {
    max-width: 380px; width: 100%;
    background: var(--card-bg);
    padding: 36px;
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-card .logo-box { margin: 0 auto 16px; }
.auth-card h1 { font-size: 1.25rem; margin-bottom: 4px; text-align: center; }
.muted { color: var(--muted); font-size: 0.85rem; }
.auth-card .muted { text-align: center; margin-bottom: 20px; }

form label { display: block; margin: 14px 0 6px; font-size: 0.83rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    background: white;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }

.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    margin-top: 4px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary { background: #eef0f5; color: var(--text); }
.btn-block { width: 100%; margin-top: 18px; }
.link-btn { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; font-size: 0.85rem; text-decoration: underline; }

/* ---------------- Dashboard stat cards ---------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex; gap: 12px; align-items: flex-start;
}
.stat-icon {
    width: 42px; height: 42px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; flex-shrink: 0;
}
.stat-icon.blue { background: #e0e7ff; color: #4f46e5; }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.amber { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.stat-link { font-size: 0.76rem; margin-top: 4px; display: inline-block; }

/* ---------------- Panel grid ---------------- */
.panel-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
    align-items: start;
}
@media (max-width: 1100px) { .panel-grid { grid-template-columns: 1fr; } }

.panel {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.panel-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 14px;
}
.panel-header h3 { margin: 0; font-size: 0.95rem; }
.panel-header .view-all { font-size: 0.78rem; }

.donut-legend { margin-top: 12px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; padding: 4px 0; }
.donut-legend .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.donut-legend .leg-name { flex: 1; }
.donut-legend .leg-val { color: var(--muted); font-weight: 600; }

.upcoming-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: center; }
.upcoming-item:last-child { border-bottom: none; }
.upcoming-icon {
    width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 0.85rem; font-weight: 700; color: white;
}
.upcoming-info { flex: 1; min-width: 0; }
.upcoming-info .up-name { font-size: 0.84rem; font-weight: 600; }
.upcoming-info .up-sub { font-size: 0.74rem; color: var(--muted); }
.upcoming-right { text-align: right; }
.upcoming-right .days-pill {
    font-size: 0.68rem; font-weight: 700; padding: 2px 8px; border-radius: 10px;
    background: #fef3c7; color: #92400e; display: inline-block;
}
.upcoming-right .amt { font-size: 0.8rem; font-weight: 600; margin-top: 3px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.02em; }
.data-table tr:last-child td { border-bottom: none; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-due-soon { background: #fef3c7; color: #92400e; }
.badge-expired { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #e2e8f0; color: #475569; }

.warn-text { color: var(--warn); font-weight: 600; }
.danger-text { color: var(--danger); font-weight: 600; }

/* ---------------- Mini calendar ---------------- */
.mini-calendar { background: #0f172a; border-radius: 12px; padding: 18px; color: white; }
.mini-calendar .cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.mini-calendar .cal-header h3 { margin: 0; font-size: 0.9rem; color: white; }
.mini-calendar .cal-nav a { color: #94a3b8; padding: 4px 8px; font-size: 0.85rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid .cal-dow { color: #64748b; font-size: 0.68rem; font-weight: 600; padding: 4px 0; }
.cal-grid .cal-day {
    font-size: 0.76rem; padding: 7px 0; border-radius: 6px; position: relative; color: #cbd5e1;
}
.cal-grid .cal-day.today { background: var(--primary); color: white; font-weight: 700; }
.cal-grid .cal-day.has-event::after {
    content: ''; position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
    width: 4px; height: 4px; border-radius: 50%; background: #38bdf8;
}
.cal-grid .cal-day.today.has-event::after { background: white; }
.cal-grid .cal-day.empty { visibility: hidden; }

/* full calendar page */
.full-calendar { background: var(--card-bg); border-radius: 12px; padding: 20px; }
.full-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.full-cal-grid .fc-dow { text-align: center; font-size: 0.75rem; color: var(--muted); font-weight: 700; padding: 6px 0; }
.full-cal-grid .fc-day {
    min-height: 92px; border: 1px solid var(--border); border-radius: 8px; padding: 6px;
    font-size: 0.78rem;
}
.full-cal-grid .fc-day.empty { background: #fafbfc; border: none; }
.full-cal-grid .fc-day.today { border-color: var(--primary); background: #eef2ff; }
.full-cal-grid .fc-daynum { font-weight: 700; margin-bottom: 4px; }
.full-cal-grid .fc-event {
    font-size: 0.68rem; padding: 2px 5px; border-radius: 4px; margin-bottom: 2px;
    background: #ede9fe; color: #5b21b6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}
.full-cal-grid .fc-event.expired { background: #fee2e2; color: #991b1b; }

/* ---------------- Quick actions ---------------- */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}
.quick-action {
    background: var(--card-bg); border-radius: 12px; padding: 16px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.quick-action:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); text-decoration: none; }
.quick-action .qa-title { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.quick-action .qa-sub { font-size: 0.72rem; color: var(--muted); }

/* ---------------- Filter bar ---------------- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { width: auto; min-width: 170px; }
.filter-bar .btn { margin-top: 0; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 1.3rem; }

.chip-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
    padding: 6px 14px; border-radius: 20px; font-size: 0.8rem; font-weight: 600;
    background: white; color: var(--muted); border: 1px solid var(--border);
}
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.chip:hover { text-decoration: none; }

/* ---------------- Forms ---------------- */
.form-card { background: var(--card-bg); padding: 24px; border-radius: 12px; max-width: 760px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { margin-bottom: 4px; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; align-items: center; }

/* ---------------- Misc ---------------- */
.role-pill { padding: 3px 10px; border-radius: 6px; font-size: 0.72rem; font-weight: 700; }
.role-Admin { background: #ede9fe; color: #5b21b6; }
.role-Manager { background: #dbeafe; color: #1e40af; }
.role-Viewer { background: #f1f5f9; color: #475569; }

.notif-item { display: flex; gap: 12px; padding: 14px; border-radius: 10px; background: var(--card-bg); box-shadow: 0 1px 3px rgba(0,0,0,0.05); margin-bottom: 10px; align-items: center; }
.notif-icon { width: 38px; height: 38px; border-radius: 9px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-weight: 700; }
.notif-icon.expired { background: #fee2e2; color: #dc2626; }
.notif-icon.due-soon { background: #fef3c7; color: #d97706; }
.notif-body { flex: 1; }
.notif-body .n-title { font-size: 0.87rem; font-weight: 600; }
.notif-body .n-sub { font-size: 0.76rem; color: var(--muted); }

.error-page { text-align: center; padding: 80px 20px; }
.error-page h1 { font-size: 3rem; margin-bottom: 8px; }
