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

body {
    font-family: var(--font-body);
    font-size: 14px;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.app-container {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
}

/* Avatars */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.avatar-primary { background: var(--primary); color: #FFFFFF; }
.avatar-soft { background: var(--primary-light); color: var(--primary); }
.tone-1 { background: #EDE9FE; color: #5B21B6; }
.tone-2 { background: #DBEAFE; color: #1D4ED8; }
.tone-3 { background: #DCFCE7; color: #15803D; }
.tone-4 { background: #FEF3C7; color: #B45309; }
.tone-5 { background: #FCE7F3; color: #BE185D; }

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    height: 100vh;
    position: sticky;
    top: 0;
    padding: var(--space-4) var(--space-3);
    background: var(--surface-low);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.sb-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 40px;
    padding: 0 var(--space-2);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text-main);
    text-decoration: none;
}
.sb-brand .material-symbols-outlined { color: var(--primary); font-size: 24px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sb-label {
    padding: 0 var(--space-2) var(--space-2);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 36px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-md);
    color: var(--on-surface-variant);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-item .material-symbols-outlined { font-size: 20px; }
.nav-item:hover { background: var(--surface-high); color: var(--text-main); }
.nav-item.active {
    background: var(--surface-solid);
    color: var(--text-main);
    box-shadow: 0 0 0 1px var(--border);
}
.nav-item.active .material-symbols-outlined { color: var(--primary); font-variation-settings: 'FILL' 1; }

.nav-count {
    margin-left: auto;
    min-width: 22px;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    background: var(--surface-high);
    font-size: 11px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    color: var(--on-surface-variant);
    font-variant-numeric: tabular-nums;
}
.nav-count:empty { display: none; }

.sidebar-bottom { display: flex; flex-direction: column; gap: var(--space-2); }

.sb-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-2) 0;
    border-top: 1px solid var(--border);
}
.sb-user-text { display: flex; flex-direction: column; min-width: 0; }
.sb-user-text strong, .sb-user-text span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sb-user-text strong { font-size: 13px; font-weight: 600; }
.sb-user-text span { font-size: 12px; color: var(--text-muted); }

/* Main + header */
.main-content { display: flex; flex-direction: column; min-width: 0; }

.view-section { padding: 24px; }

.top-header {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    height: 60px;
    padding: 0 24px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.breadcrumb { display: flex; align-items: center; gap: var(--space-1); font-size: 14px; white-space: nowrap; }
.crumb-root { color: var(--text-muted); }
.crumb-sep { font-size: 18px; color: var(--grey); }
.crumb-page { font-weight: 600; color: var(--text-main); }

.search-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 36px;
    padding: 0 var(--space-3);
    background: var(--surface-low);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    min-width: 0;
    transition: border-color 0.15s, background 0.15s;
}
.search-bar:focus-within { background: var(--surface-solid); border-color: var(--primary); }
.search-bar .material-symbols-outlined { font-size: 18px; color: var(--text-muted); }
.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text-main);
    width: 100%;
    min-width: 0;
}
.header-search { margin-left: auto; width: 280px; }

.header-actions { display: flex; align-items: center; gap: var(--space-1); position: relative; flex-shrink: 0; }

.notification-btn .badge {
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger);
    color: #FFFFFF;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    border: 2px solid var(--surface-solid);
    box-sizing: content-box;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: var(--space-2);
    padding: 2px 4px 2px 2px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
}
.user-menu:hover { background: var(--bg-color); }
.user-menu .material-symbols-outlined { font-size: 18px; }

/* Page heads */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}
.page-head h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.page-head p { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

/* Panels */
.card,
.panel {
    background: var(--surface-solid);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--border);
    min-width: 0;
}
.panel-flush { padding: 0; overflow: hidden; }

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}
.panel-title h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.panel-title p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.panel-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.panel-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: 12px 20px;
    background: var(--surface-low);
    border-top: 1px solid var(--border);
}

.count-chip {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: var(--surface-low);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 500;
    color: var(--on-surface-variant);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.link-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--primary);
    cursor: pointer;
}
.link-btn:hover { background: var(--primary-light); }
.link-btn .material-symbols-outlined { font-size: 16px; }

/* KPIs */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}
.kpi {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: 20px;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    min-width: 0;
}
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.kpi-label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.kpi-body { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); min-height: 56px; }
.kpi-value {
    font-family: var(--font-head);
    font-size: 30px;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
}
.kpi-visual { width: 112px; height: 48px; flex-shrink: 0; }
.kpi-gauge { width: 96px; height: 52px; }

.trend {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    border: 1px solid transparent;
}
.trend .material-symbols-outlined { font-size: 14px; }
.trend.up { background: var(--success-light); color: #15803D; }
.trend.warn { background: var(--warning-light); color: #B45309; }

/* Dashboard grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--space-4);
    align-items: start;
}
.main-column, .side-column { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }

/* Segmented control */
.segmented {
    display: inline-flex;
    padding: 2px;
    border-radius: var(--radius-md);
    background: var(--surface-low);
    border: 1px solid var(--border);
}
.segmented button {
    height: 28px;
    padding: 0 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.segmented button:hover { color: var(--text-main); }
.segmented button.active { background: var(--surface-solid); color: var(--text-main); box-shadow: 0 0 0 1px var(--border); }

/* Chart */
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-bottom: var(--space-3); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.legend-swatch { width: 14px; height: 0; border-top: 2px solid var(--primary); }
.legend-swatch.dashed { border-top: 2px dashed #B6ABEF; }
.chart-container { height: 260px; width: 100%; }

#chartjs-tooltip {
    opacity: 0;
    position: absolute;
    background: var(--text-main);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    pointer-events: none;
    transform: translate(-50%, 0);
    transition: opacity 0.1s ease;
    z-index: 1000;
    font-size: 12px;
    font-family: var(--font-body);
    color: #FFFFFF;
    white-space: nowrap;
}
#chartjs-tooltip .tooltip-title { font-weight: 600; margin-bottom: 2px; }
#chartjs-tooltip .tooltip-body { color: rgba(255, 255, 255, 0.75); }

/* Tables */
.table-wrap { overflow-x: auto; position: relative; }
.history-section .table-wrap { margin: 0 -20px -20px; }
.data-table { width: 100%; min-width: 560px; border-collapse: collapse; }
.data-table th {
    text-align: left;
    padding: 10px 20px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    background: var(--surface-low);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 20px;
    font-size: 14px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-low); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .muted { color: var(--on-surface-variant); }
.data-table .actions-col { width: 56px; text-align: right; }
.cell-person { display: inline-flex; align-items: center; gap: var(--space-3); font-weight: 500; }
.table-empty { text-align: center; color: var(--text-muted); padding: 32px 20px !important; }

.table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    padding: 12px 20px;
}
.table-toolbar .search-bar { width: 280px; max-width: 100%; }
.table-foot {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-badge.overdue { background: #FEF2F2; border-color: #FECACA; color: #B91C1C; }
.status-badge.completed { background: #F0FDF4; border-color: #BBF7D0; color: #15803D; }

/* Appointments */
.appointment-list { display: flex; flex-direction: column; margin: 0 -8px; }
.appointment-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: 10px 8px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}
.appointment-row:hover { background: var(--surface-low); }
.appointment-row.active { background: var(--primary-light); }
.appt-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.appt-info strong { font-size: 14px; font-weight: 600; }
.appt-info span { font-size: 12px; color: var(--text-muted); }
.appointment-row.active .appt-info span { color: var(--primary); }
.appt-arrow { font-size: 18px; color: var(--grey); }
.appointment-row.active .appt-arrow { color: var(--primary); }

/* Tasks */
.task-list { display: flex; flex-direction: column; margin: 0 -8px; }
.task-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background 0.15s;
}
.task-row:hover { background: var(--surface-low); }
.task-check { display: flex; align-items: flex-start; gap: var(--space-3); flex: 1; min-width: 0; cursor: pointer; }
.task-check input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.task-text { display: flex; flex-direction: column; min-width: 0; }
.task-text strong { font-size: 14px; font-weight: 500; }
.task-text span { font-size: 12px; color: var(--text-muted); }
.task-row.done .task-text strong { text-decoration: line-through; color: var(--text-muted); }
.priority { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.priority.high { background: var(--danger); }
.priority.medium { background: var(--warning); }
.priority.low { background: var(--blue); }
.priority.none { background: transparent; }

.row-remove { opacity: 0; color: var(--text-muted); }
.task-row:hover .row-remove,
.staff-row:hover .row-remove,
.data-table tr:hover .row-remove,
.row-remove:focus-visible { opacity: 1; }
.row-remove:hover { color: var(--danger); background: var(--danger-light); }
@media (hover: none) { .row-remove { opacity: 1; } }

.task-add {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}
.task-add .form-control { height: 34px; padding: 6px 10px; }

.list-empty { padding: 16px 8px; font-size: 13px; color: var(--text-muted); }

/* Reports empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    width: 100%;
    min-height: calc(100vh - 60px - 48px);
    padding: var(--space-8);
    border: 1px dashed var(--grey);
    border-radius: var(--radius-lg);
    background: var(--surface-solid);
    text-align: center;
}
.empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-2);
    border-radius: var(--radius-lg);
    background: var(--primary-light);
    color: var(--primary);
    font-size: 26px;
}
.empty-state.in-page { min-height: calc(100vh - 60px - 48px - 76px); }
.empty-state h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.empty-state p { font-size: 14px; color: var(--text-muted); margin-bottom: var(--space-3); }

/* Settings */
.settings-stack { display: flex; flex-direction: column; gap: var(--space-4); max-width: 960px; }
.settings-row { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--space-6); padding: 24px; }
.settings-intro { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-3); }
.settings-intro h3 { font-size: 15px; font-weight: 600; }
.settings-fields { display: flex; flex-direction: column; gap: var(--space-4); }
.settings-fields .form-group { margin-bottom: 0; }
.settings-help { font-size: 14px; color: var(--on-surface-variant); max-width: 60ch; }
.save-note { font-size: 13px; font-weight: 500; color: #15803D; }

.staff-list { display: flex; flex-direction: column; }
.staff-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.staff-row:first-child { padding-top: 0; }
.staff-row:last-child { border-bottom: none; }
.staff-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.staff-info strong { font-size: 14px; font-weight: 600; }
.staff-info span { font-size: 13px; color: var(--text-muted); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    height: 38px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface-solid);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control::placeholder { color: #94A3B8; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(94, 74, 209, 0.15); }
.select-sm { width: auto; height: 36px; padding: 0 32px 0 12px; cursor: pointer; }

/* Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 2000;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    padding: 24px;
    box-shadow: var(--shadow-xl);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }

/* Dropdowns */
.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 48px;
    min-width: 220px;
    padding: 4px;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    z-index: 1000;
}
.dropdown-menu.dropdown-right { right: 0; min-width: 180px; }
.dropdown-menu.active { display: flex; }
.dropdown-header { padding: 8px 10px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.dropdown-item {
    padding: 8px 10px;
    border-radius: var(--radius-md);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}
.dropdown-item:hover { background: var(--surface-low); }

/* Responsive */
@media (max-width: 1200px) {
    .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
    .side-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
}

@media (max-width: 1024px) {
    .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-row .kpi:last-child { grid-column: span 2; }
    .settings-row { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
}

.hamburger-menu-btn { display: none; }

@media (max-width: 768px) {
    .app-container { grid-template-columns: minmax(0, 1fr); }
    .view-section { padding: 16px; }
    .top-header { padding: 0 12px; gap: var(--space-2); }
    .hamburger-menu-btn { display: inline-flex; }
    .crumb-root, .crumb-sep { display: none; }
    .header-search { width: auto; flex: 1; }
    .header-actions > .icon-btn:first-child { display: none; }
    .side-column { grid-template-columns: minmax(0, 1fr); }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 260px;
        z-index: 9999;
        transition: left 0.25s var(--ease-out);
        background: var(--surface-solid);
        box-shadow: var(--shadow-xl);
    }
    .sidebar.drawer-open { left: 0; }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.4);
        z-index: 9998;
        display: none;
    }
    .sidebar-backdrop.active { display: block; }
    .empty-state { min-height: calc(100vh - 60px - 32px); }
}

@media (max-width: 560px) {
    .kpi-row { grid-template-columns: minmax(0, 1fr); }
    .kpi-row .kpi:last-child { grid-column: auto; }
}
