/* ==================== Reset & Base ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; line-height: 1.6; color: #2d3748; background: #f0f2f5; }

/* ==================== Visibility Utilities ==================== */
.desktop-only { display: block; }
.mobile-only { display: none; }

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

/* ==================== Sidebar ==================== */
.sidebar {
    background: #1a1a2e;
    color: white;
    width: 230px;
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}
.nav-brand {
    font-weight: 700;
    font-size: 1.05rem;
    padding: 0 1.25rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 0.75rem;
    letter-spacing: -0.01em;
    color: #e2e8f0;
}
.nav-links { display: flex; flex-direction: column; flex: 1; gap: 2px; padding: 0 0.5rem; }
.nav-bottom { border-top: 1px solid rgba(255,255,255,0.08); padding: 0.75rem 0.5rem 0; margin-top: 0.5rem; }
.sidebar a {
    color: #a0aec0;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.55rem 0.85rem;
    display: block;
    border-radius: 6px;
    transition: all 0.15s ease;
}
.sidebar a:hover { color: #fff; background: rgba(255,255,255,0.08); }
.sidebar a.active { color: #fff; background: rgba(255,255,255,0.12); }

/* ==================== Main Content ==================== */
main {
    flex: 1;
    margin-left: 230px;
    padding: 2rem 2.5rem;
    min-width: 0;
}

h1 { margin-bottom: 1.25rem; color: #1a202c; font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { margin: 1.75rem 0 0.75rem; color: #2d3748; font-size: 1.15rem; font-weight: 600; }

a { color: #3182ce; }
a:hover { color: #2c5282; }

/* ==================== Cards & Panels ==================== */
.card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* ==================== Tables ==================== */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
th, td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid #edf2f7; }
th { background: #f7fafc; font-weight: 600; color: #4a5568; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f7fafc; }

/* ==================== Stats Grid ==================== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s ease;
}
.stat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.stat-value { font-size: 2rem; font-weight: 700; color: #1a202c; line-height: 1.2; }
.stat-label { font-size: 0.75rem; color: #718096; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.25rem; }
.stat-error .stat-value { color: #e53e3e; }

/* ==================== Status Banners ==================== */
.status-healthy { background: #f0fff4; color: #276749; padding: 0.85rem 1rem; border-radius: 8px; margin: 1rem 0; border: 1px solid #c6f6d5; font-weight: 500; }
.status-warning { background: #fffff0; color: #975a16; padding: 0.85rem 1rem; border-radius: 8px; margin: 1rem 0; border: 1px solid #fefcbf; }
.status-warning a { color: #975a16; font-weight: 600; }
.error { background: #fff5f5; color: #c53030; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid #fed7d7; font-weight: 500; }

/* ==================== Filter & Tab Bars ==================== */
.filter-bar { margin-bottom: 1.25rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.filter-bar a {
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    text-decoration: none;
    color: #4a5568;
    background: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid #e2e8f0;
    transition: all 0.15s ease;
}
.filter-bar a:hover { background: #edf2f7; color: #2d3748; }
.filter-bar a.active { background: #1a1a2e; color: white; border-color: #1a1a2e; }

.tab-bar { margin-bottom: 1rem; display: flex; gap: 0; border-bottom: 2px solid #e2e8f0; }
.tab-bar .tab {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: #718096;
    font-size: 0.85rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s ease;
}
.tab-bar .tab:hover { color: #2d3748; }
.tab-bar .tab.active { color: #1a1a2e; border-bottom-color: #1a1a2e; }

/* ==================== Forms ==================== */
form { margin-bottom: 1.5rem; }
label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; color: #4a5568; font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    width: 100%;
    max-width: 320px;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    color: #2d3748;
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus { outline: none; border-color: #3182ce; box-shadow: 0 0 0 3px rgba(49,130,206,0.15); }

button, .btn-retry {
    padding: 0.5rem 1.1rem;
    background: #1a1a2e;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s ease;
}
button:hover, .btn-retry:hover { background: #2d2d5e; box-shadow: 0 1px 4px rgba(0,0,0,0.12); }

/* ==================== Login ==================== */
.login-container {
    max-width: 380px;
    margin: 6rem auto;
    padding: 2.5rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    border: 1px solid #e2e8f0;
}
.login-container h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.4rem; }
.login-container input { max-width: 100%; }
.login-container button { width: 100%; padding: 0.65rem; font-size: 0.95rem; margin-top: 0.5rem; }

/* ==================== Schedule Info ==================== */
.schedule-info {
    background: #fff;
    padding: 1.1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.schedule-info p { margin-bottom: 0.3rem; font-size: 0.9rem; }
.schedule-info strong { color: #4a5568; }

.actions {
    background: #fff;
    padding: 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.maintenance-section {
    background: #fff;
    padding: 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.maintenance-section p { font-size: 0.9rem; color: #718096; margin-bottom: 0.75rem; }

/* ==================== Conflict / Preview ==================== */
.conflict-warning { background: #fffff0; color: #975a16; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid #fefcbf; }
.no-conflicts { background: #f0fff4; color: #276749; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid #c6f6d5; }
.conflict-row { background: #fffff0; }
.conflict-row:hover { background: #fefcbf; }
.preview-actions { margin-top: 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.preview-actions em { font-size: 0.85rem; color: #718096; }
.reschedule-summary { background: #ebf8ff; color: #2a4365; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-weight: 500; border: 1px solid #bee3f8; }
.conflict-adjust-hint { font-style: italic; color: #975a16; font-size: 0.9rem; margin-bottom: 1rem; }
.reschedule-result { margin-top: 1rem; }

/* ==================== HTMX ==================== */
.htmx-indicator { display: none; font-size: 0.85rem; color: #718096; font-style: italic; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* ==================== Calendar Toolbar ==================== */
.calendar-toolbar {
    background: #fff;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.toolbar-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.toolbar-row + .toolbar-row { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid #edf2f7; }
.schedule-filter-wrapper { flex: 1; min-width: 0; }
.schedule-filter-wrapper select { padding: 0.4rem 0.6rem; border: 1px solid #cbd5e0; border-radius: 6px; font-size: 0.85rem; width: 100%; margin-bottom: 0; background: #fff; }
.view-tabs { display: flex; gap: 0; }
.view-tab {
    padding: 0.4rem 1rem;
    text-decoration: none;
    color: #4a5568;
    background: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid #cbd5e0;
    transition: all 0.15s ease;
}
.view-tab:first-child { border-radius: 6px 0 0 6px; }
.view-tab:last-child { border-radius: 0 6px 6px 0; }
.view-tab + .view-tab { border-left: none; }
.view-tab:hover { background: #edf2f7; }
.view-tab.active { background: #1a1a2e; color: white; border-color: #1a1a2e; }
.date-nav { display: flex; gap: 0.35rem; }
.nav-btn {
    padding: 0.4rem 0.85rem;
    text-decoration: none;
    color: #4a5568;
    background: #fff;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid #cbd5e0;
    transition: all 0.15s ease;
}
.nav-btn:hover { background: #edf2f7; color: #2d3748; }
.date-label { font-weight: 600; font-size: 1.05rem; color: #1a202c; }

/* ==================== Day View ==================== */
.day-view-widget {
    margin-bottom: 1.5rem;
}
.day-view-grid {
    display: grid;
    grid-template-columns: 55px 1fr;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.day-view-grid .time-slot {
    height: 60px;
    padding: 2px 6px;
    font-size: 0.7rem;
    color: #a0aec0;
    border-bottom: 1px solid #edf2f7;
    text-align: right;
}
.day-view-grid .day-column {
    border-left: 1px solid #e2e8f0;
}
.day-view-grid .day-body {
    position: relative;
}
.day-view-grid .appointment-block {
    font-size: 0.85rem;
    padding: 6px 10px;
    border-left-width: 4px;
}
.day-view-grid .appt-name {
    font-size: 0.9rem;
}
.day-view-grid .appt-time {
    font-size: 0.75rem;
}
.day-empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: #718096;
    font-size: 0.9rem;
}

/* ==================== Week View ==================== */
.schedule-widget { overflow-x: auto; margin-bottom: 1.5rem; }
.schedule-grid {
    display: grid;
    grid-template-columns: 65px repeat(7, 1fr);
    min-width: 700px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.time-column { background: #f7fafc; }
.day-header-spacer { height: 40px; border-bottom: 1px solid #e2e8f0; }
.time-slot { height: 60px; padding: 2px 8px; font-size: 0.7rem; color: #a0aec0; border-bottom: 1px solid #edf2f7; text-align: right; }
.day-column { border-left: 1px solid #e2e8f0; }
.day-column.today-column { background: #ebf8ff; }
.day-header {
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #4a5568;
    background: #f7fafc;
    border-bottom: 1px solid #e2e8f0;
}
.today-column .day-header { background: #bee3f8; color: #2a4365; }
.day-body { position: relative; }
.hour-slot { height: 60px; border-bottom: 1px solid #edf2f7; }
.appointment-block {
    position: absolute;
    left: 2px; right: 2px;
    background: hsl(var(--appt-hue, 210), 55%, 90%);
    border-left: 3px solid hsl(var(--appt-hue, 210), 55%, 50%);
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 0.7rem;
    line-height: 1.2;
    overflow: hidden;
    text-decoration: none;
    color: #2d3748;
    cursor: pointer;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: filter 0.1s ease, box-shadow 0.1s ease;
}
.appointment-block:hover { filter: brightness(0.93); z-index: 2; box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.appointment-block:focus-visible { outline: 2px solid #3182ce; outline-offset: 1px; z-index: 3; box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.appt-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-time { font-size: 0.65rem; color: #4a5568; white-space: nowrap; }
.appt-status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; position: absolute; top: 3px; right: 4px; }
.appt-status-dot.status-booked { background: #38a169; }
.appt-status-dot.status-cancelled { background: #e53e3e; }
.appt-status-dot.status-not_found { background: #dd6b20; }
.appt-status-dot.status-pending { background: #718096; }

/* ==================== Month View ==================== */
.month-grid {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    margin-bottom: 1.5rem;
}
.month-header-row { display: grid; grid-template-columns: repeat(7, 1fr); background: #f7fafc; }
.month-day-header { text-align: center; padding: 0.5rem; font-size: 0.8rem; font-weight: 600; color: #4a5568; border-bottom: 1px solid #e2e8f0; }
.month-week-row { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-day-cell {
    min-height: 90px;
    border-bottom: 1px solid #edf2f7;
    border-right: 1px solid #edf2f7;
    padding: 6px 8px;
    text-decoration: none;
    color: #2d3748;
    display: block;
    transition: background 0.1s ease;
}
.month-day-cell:hover { background: #ebf8ff; }
.month-day-cell.empty-cell { background: #f7fafc; }
.month-day-cell.empty-cell:hover { background: #f7fafc; }
.month-day-cell.today-cell { background: #ebf8ff; }
.month-day-number { font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.month-day-badge { background: #3182ce; color: white; font-size: 0.65rem; padding: 1px 6px; border-radius: 9px; font-weight: 600; }
.month-day-names { font-size: 0.7rem; color: #718096; }
.month-day-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }

/* ==================== Year View ==================== */
.year-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.year-month {
    background: #fff;
    border-radius: 8px;
    padding: 0.85rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.year-month-header { display: block; text-align: center; font-weight: 600; font-size: 0.9rem; color: #1a202c; text-decoration: none; margin-bottom: 0.5rem; }
.year-month-header:hover { color: #3182ce; }
.mini-month { font-size: 0.7rem; }
.mini-header-row { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; color: #a0aec0; font-weight: 600; margin-bottom: 2px; }
.mini-week-row { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.heat-cell { padding: 2px 0; border-radius: 3px; min-height: 18px; line-height: 18px; transition: background 0.1s ease; }
.heat-cell.empty-heat { }
.heat-cell.today-heat { outline: 2px solid #3182ce; outline-offset: -1px; font-weight: 700; }

/* ==================== Schedule Cards (Mobile) ==================== */
.schedule-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.schedule-card {
    display: block;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.85rem 1rem;
    text-decoration: none;
    color: #2d3748;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s ease;
    min-height: 44px;
}
.schedule-card:active {
    background: #f7fafc;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.schedule-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.schedule-card-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: #2d3748;
}
.schedule-card-status {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 9px;
}
.status-badge-active { background: #f0fff4; color: #276749; }
.status-badge-cancelled { background: #fff5f5; color: #c53030; }
.schedule-card-meta {
    font-size: 0.8rem;
    color: #718096;
    line-height: 1.4;
}

/* ==================== Schedules Page Structure ==================== */
.schedules-container {
    width: 100%;
}
.calendar-group {
    width: 100%;
}
.calendar-group-body {
    width: 100%;
}
.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

/* ==================== Inline Schedule Detail ==================== */
.detail-cell {
    padding: 0 !important;
    border-top: none !important;
}
.detail-content {
    width: 100%;
}
.schedule-detail-inline {
    width: 100%;
    padding: 1rem 1.25rem;
    background: #fafbfc;
    border-top: 2px solid #e2e8f0;
    box-sizing: border-box;
}
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.detail-header h3 {
    margin: 0;
    font-size: 1rem;
}
.schedule-detail-inline h3 {
    font-size: 1rem;
    margin: 0.75rem 0 0.5rem;
}
.schedule-info-compact {
    margin-bottom: 1rem;
}
.schedule-info-compact p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
}
.detail-appointments-section {
    width: 100%;
}
.appointments-container {
    width: 100%;
}
.appointments-tabs {
    margin-bottom: 0.75rem;
}
.appointments-table-wrapper {
    width: 100%;
    overflow-x: auto;
}
.detail-close-btn {
    background: none;
    border: 1px solid #cbd5e0;
    color: #718096;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
}
.detail-close-btn:hover {
    background: #edf2f7;
    color: #2d3748;
}
.detail-row td {
    background: #fafbfc;
}
.detail-mobile .schedule-detail-inline {
    border-radius: 0 0 8px 8px;
    border: 1px solid #e2e8f0;
    border-top: none;
    margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
    .schedule-detail-inline {
        padding: 0.75rem;
    }
}

/* ==================== Appointment List (Mobile) ==================== */
.appointment-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}
.appointment-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #edf2f7;
    min-height: 44px;
}
.appointment-list-item:last-child { border-bottom: none; }
.appt-list-date {
    font-size: 0.85rem;
    color: #2d3748;
}
.appt-list-status {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #718096;
}
.status-text-booked { color: #38a169; }
.status-text-cancelled { color: #e53e3e; }
.status-text-not_found { color: #dd6b20; }
.status-text-pending { color: #616e7c; }
.status-text-succeeded { color: #38a169; }
.appointment-list-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: #718096;
    font-size: 0.9rem;
}

/* ==================== Details / Collapsible Sections ==================== */
details { margin-bottom: 1.5rem; }
details summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
    color: #2d3748;
    padding: 0.5rem 0;
}
details summary:hover { color: #1a202c; }

/* ==================== Responsive ==================== */
@media (max-width: 900px) {
    .year-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ==================== Mobile: Bottom Tab Bar & Layout ==================== */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }

    .app-layout {
        flex-direction: column;
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    }

    .sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: calc(60px + env(safe-area-inset-bottom, 0px));
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        padding: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        z-index: 1000;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    }

    .nav-brand { display: none; }

    .nav-links {
        flex-direction: row;
        flex: 1;
        justify-content: space-around;
        padding: 0;
        gap: 0;
    }

    .nav-bottom {
        border-top: none;
        padding: 0;
        margin: 0;
    }

    .sidebar a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 6px 16px;
        font-size: 0.7rem;
        min-height: 44px;
        min-width: 44px;
        border-radius: 0;
    }

    .sidebar a.active {
        color: #63b3ed;
        background: rgba(99,179,237,0.12);
    }

    main {
        margin-left: 0;
        padding: 1rem 0.75rem;
        padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    }

    h1 {
        font-size: 1.3rem;
        margin-bottom: 0.75rem;
    }
}

/* ==================== Mobile: Touch Targets & Small Screen ==================== */
@media (max-width: 600px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    table { font-size: 0.8rem; }
    th, td { padding: 0.4rem 0.5rem; }
    .year-grid { grid-template-columns: 1fr; }

    /* Calendar toolbar */
    .toolbar-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .view-tabs {
        display: flex;
        width: 100%;
    }

    .view-tab {
        flex: 1;
        text-align: center;
        padding: 0.55rem 0.5rem;
        font-size: 0.85rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .schedule-filter-wrapper {
        margin-left: 0;
        width: 100%;
    }

    .schedule-filter-wrapper select {
        width: 100%;
        max-width: 100%;
        min-height: 44px;
        font-size: 1rem; /* Prevent iOS zoom on focus */
    }

    .date-nav {
        display: flex;
        width: 100%;
    }

    .nav-btn {
        flex: 1;
        text-align: center;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.9rem;
    }

    .date-label {
        text-align: center;
        font-size: 1rem;
        padding: 0.25rem 0;
    }

    /* Week view still scrollable */
    .schedule-grid { min-width: 550px; }
    .schedule-widget { -webkit-overflow-scrolling: touch; }

    /* Month view compact */
    .month-day-cell {
        min-height: 60px;
        padding: 4px 4px;
    }

    .month-day-header {
        font-size: 0.7rem;
        padding: 0.35rem 0.25rem;
    }

    .month-day-names { display: none; }

    .month-day-badge { font-size: 0.6rem; }

    /* Tab bar scrollable */
    .tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 0;
        scrollbar-width: none;
    }

    .tab-bar::-webkit-scrollbar { display: none; }

    .tab-bar .tab {
        white-space: nowrap;
        padding: 0.55rem 0.75rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Filter bar */
    .filter-bar a {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 0.5rem 0.85rem;
    }

    /* Schedule info */
    .schedule-info p { font-size: 0.85rem; }
}

/* ==================== Touch Device Optimizations ==================== */
@media (pointer: coarse) {
    .sidebar a, .nav-btn, .view-tab, .filter-bar a, .tab-bar .tab {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: rgba(0,0,0,0.05);
    }
}
