/* ─────────────────────────────────────────────
   808 Hospitalist Schedule — Modern Responsive CSS
   ───────────────────────────────────────────── */

/* ── Reset & Variables ───────────────────────── */

:root {
    --color-bg:        #f8f9fa;
    --color-surface:   #ffffff;
    --color-border:    #dee2e6;
    --color-border-lt: #e9ecef;
    --color-text:      #212529;
    --color-text-muted:#868e96;
    --color-primary:   #2563eb;
    --color-primary-hover: #1d4ed8;

    --color-week-blue: #d6eaf8;
    --color-week-pink: #f5d5e0;
    --color-today:     #CDFECD;
    --color-marked:    #fee2e2;
    --color-highlight: yellow;
    --color-holiday:   #dc2626;

    --font-body:  'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono:  'SF Mono', 'Cascadia Code', 'Consolas', monospace;

    --radius:     6px;
    --shadow-sm:  0 1px 2px rgba(0,0,0,.05);
    --shadow-md:  0 4px 12px rgba(0,0,0,.08);

    --sidebar-width: 260px;
}

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

body {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.4;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

/* ── App Layout ──────────────────────────────── */

.app-layout {
    display: flex;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
}

.main-content {
    flex: 1;
    padding: 12px;
    overflow-x: auto;
    min-width: 0; /* allow flex child to shrink */
    max-width: 940px;
}

/* ── Schedule Table ──────────────────────────── */

.schedule-wrapper {
    border-radius: var(--radius);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.schedule-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}

/* Week header row */
.week-header th {
    padding: 6px 8px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 2;
    background: inherit;
}

/* Week colors — headers only, data rows stay white */
tr.week-header.week-blue th { background-color: var(--color-week-blue); }
tr.week-header.week-pink th { background-color: var(--color-week-pink); }
tr.week-data td { background-color: var(--color-surface); }

/* Wrap each week in a visual group via row coloring */
tr.week-header { border-top: 2px solid var(--color-border); }

/* Subtle left accent on data rows to echo the week color */
tr.week-data.week-blue > td:first-child { border-left: 3px solid var(--color-week-blue); }
tr.week-data.week-pink > td:first-child { border-left: 3px solid var(--color-week-pink); }

.week-label {
    text-align: left !important;
    white-space: nowrap;
    min-width: 90px;
    width: 90px;
}

.week-num {
    display: block;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.week-months {
    font-weight: 600;
    font-size: 12px;
}

.day-header {
    min-width: 80px;
}

.day-header .day-name {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    font-weight: 400;
}

.day-header .day-date {
    font-weight: 600;
}

.day-header.holiday {
    color: var(--color-holiday);
}

/* Data rows */
.week-data td {
    padding: 4px 6px;
    border-right: 1px solid var(--color-border-lt);
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
    font-size: 14px;
}

.role-labels {
    min-width: 90px;
    width: 90px;
    text-align: right;
    padding: 4px 10px 4px 6px !important;
}

.role-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
    height: 22px;
    line-height: 22px;
    font-family: var(--font-mono);
}

.role-label.role-muted {
    color: #adb5bd;
}

/* Day cells */
.day-cell {
    min-width: 80px;
}

.day-cell.today {
    background-color: var(--color-today) !important;
}

.day-cell.marked {
    background-color: var(--color-marked) !important;
}

/* Staff name entries */
.staff-name {
    white-space: nowrap;
    height: 22px;
    line-height: 22px;
    font-size: 14px;
}

.staff-name.highlighted {
    background-color: var(--color-highlight);
    border-radius: 2px;
    padding: 0 3px;
    margin: 0 -3px;
}

.staff-name.triage {
    font-weight: 700;
}

.staff-name.long-swing {
    color: #dc2626;
}

.staff-name.backup-standby {
    font-style: italic;
    color: var(--color-text-muted);
}

.staff-name.backup-active {
    text-decoration: underline;
}

.staff-name.hmk {
    color: #adb5bd;
}

/* ── Sidebar ─────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    box-shadow: var(--shadow-md);
}

.sidebar h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--color-text-muted);
    margin: 16px 0 8px;
}

.sidebar h3:first-child {
    margin-top: 0;
}

.sidebar-toggle {
    display: none; /* visible on mobile only */
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 1000;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--color-primary);
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    transition: transform 0.2s;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:active {
    transform: scale(0.92);
}

/* Semi-transparent backdrop when sidebar is open on mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 499;
}

.sidebar-backdrop.visible {
    display: block;
}

/* Navigation links */
.sidebar-nav a {
    display: block;
    padding: 3px 0;
    font-size: 12px;
    color: var(--color-primary);
    text-decoration: none;
}

.sidebar-nav a:hover {
    text-decoration: underline;
}

/* Form controls */
.schedule-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.schedule-controls label {
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-muted);
}

.control-row {
    display: flex;
    gap: 6px;
}

.control-row select {
    flex: 1;
}

select, input[type="number"], input[type="text"] {
    font-family: var(--font-body);
    font-size: 13px;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    width: 100%;
}

select:focus, input:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
    background: var(--color-bg);
    border-color: #ced4da;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    margin-top: 4px;
}

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

.btn-link {
    padding: 4px 10px;
    margin: 2px;
}

/* Quick links grid */
.quick-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
}

.quick-links h3 {
    width: 100%;
}

.quick-links hr {
    width: 100%;
    border: none;
    border-top: 1px solid var(--color-border-lt);
    margin: 6px 0;
}

/* iCal input */
.ical-link {
    margin-top: 8px;
}

.ical-url {
    font-family: var(--font-mono);
    font-size: 10px !important;
    padding: 4px 6px !important;
    cursor: text;
}

/* Announcements */
.announce-text {
    font-size: 12px;
    padding: 8px;
    background: var(--color-bg);
    border-radius: var(--radius);
    line-height: 1.5;
}

textarea {
    font-family: var(--font-mono);
    font-size: 12px;
    width: 100%;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    resize: vertical;
}

/* ── Responsive ──────────────────────────────── */

/* Tablet: sidebar collapses to overlay */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 500;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .main-content {
        padding: 8px;
    }
}

/* Phone: tighter spacing, card-style weeks */
@media (max-width: 640px) {
    :root {
        --sidebar-width: 100%;
    }

    .schedule-table {
        font-size: 11px;
        min-width: 600px;
    }

    .week-label, .role-labels {
        min-width: 60px;
        width: 60px;
    }

    .day-header {
        min-width: 60px;
    }

    .week-header th {
        padding: 4px;
    }

    .week-data td {
        padding: 2px 4px;
    }

    .sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--color-border);
    }
}

/* ── Print ───────────────────────────────────── */

@media print {
    .sidebar,
    .sidebar-toggle,
    .sidebar-backdrop {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }

    .schedule-wrapper {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .schedule-table {
        font-size: 10px;
    }

    body {
        background: white;
    }
}

/* ─────────────────────────────────────────────
   Admin Editor View
   ───────────────────────────────────────────── */

.admin-save-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--color-surface);
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
}

.btn-save {
    min-width: 120px;
}

.save-status {
    font-size: 12px;
    font-weight: 600;
}

.save-status.saving { color: var(--color-text-muted); }
.save-status.saved  { color: #16a34a; }
.save-status.error  { color: #dc2626; }

.autosave-hint {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-left: auto;
}

.admin-table {
    min-width: 900px;
}

/* Admin view needs full width — override layout constraints */
.app-layout.layout-wide {
    max-width: 1400px;
}

.app-layout.layout-wide .main-content {
    max-width: 1140px;
}

.admin-slot {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 24px;
}

/* Floating shared dropdown */
.floating-select {
    display: none;
    position: absolute;
    z-index: 100;
    font-family: var(--font-body);
    font-size: 13px;
    padding: 2px 4px;
    border: 2px solid var(--color-primary);
    border-radius: var(--radius);
    background: var(--color-surface);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-width: 120px;
}

/* Clickable staff name in each cell */
.admin-pick {
    flex: 1;
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid transparent;
    transition: border-color 0.15s, background 0.15s;
}

.admin-pick:hover {
    border-color: var(--color-border);
    background: rgba(0,0,0,0.02);
}

.admin-pick.changed {
    background: #fef9c3;
    border-color: #facc15;
}

.admin-pick.saved {
    background: #d1fae5;
    border-color: #34d399;
    transition: background 0.8s ease;
}

.admin-pick.is-triage {
    font-weight: 700;
}

.admin-cell {
    min-width: 120px !important;
}

.admin-role-label {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background 0.15s;
    height: 24px;
    line-height: 20px;
}

.admin-role-label:hover {
    background: rgba(0,0,0,0.06);
    color: var(--color-primary);
}

.admin-check {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 10px;
    font-weight: 700;
    color: var(--color-text-muted);
}

.admin-check input { width: 14px; height: 14px; margin: 0; }
.admin-check span  { margin-left: 1px; }

.triage-radio {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    accent-color: var(--color-primary);
}

/* ─────────────────────────────────────────────
   Triage View
   ───────────────────────────────────────────── */

.triage-slot {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 22px;
    line-height: 22px;
}

.triage-slot.highlighted .triage-name {
    background-color: var(--color-highlight);
    border-radius: 2px;
    padding: 0 3px;
}

.triage-slot.triage .triage-name {
    font-weight: 700;
}

.triage-name {
    flex: 1;
    white-space: nowrap;
    font-size: 14px;
}

/* ─────────────────────────────────────────────
   Raw Data View
   ───────────────────────────────────────────── */

.raw-table {
    min-width: 500px;
    table-layout: auto;
}

.raw-table thead th {
    position: sticky;
    top: 0;
    background: var(--color-surface);
    padding: 8px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    border-bottom: 2px solid var(--color-border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}

.raw-table td {
    padding: 4px 12px;
    border-bottom: 1px solid var(--color-border-lt);
    font-size: 12px;
    font-family: var(--font-mono);
}

.raw-table tbody tr:hover {
    background: var(--color-bg);
}

/* ─────────────────────────────────────────────
   Admin responsive
   ───────────────────────────────────────────── */

@media (max-width: 1024px) {
    .admin-save-bar {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        z-index: 600;
        border-top: 1px solid var(--color-border);
        border-bottom: none;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    }
}

@media print {
    .admin-save-bar {
        display: none !important;
    }
}

/* ─────────────────────────────────────────────
   Login Form
   ───────────────────────────────────────────── */

.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
    padding: 20px;
}

.login-box {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 32px;
    width: 100%;
    max-width: 340px;
}

.login-box h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
    color: var(--color-text);
}

.login-box label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    margin-top: 12px;
}

.login-box input[type="text"],
.login-box input[type="password"] {
    width: 100%;
    padding: 8px 10px;
    font-size: 14px;
}

.login-error {
    background: #fee2e2;
    color: #dc2626;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 8px;
}
