/* ========================================
   Roster Predictor - Global Stylesheet (Refactored)
   ======================================== */

/* --- CSS Variables --- */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success-bg: #ecfdf5;
    --success-text: #065f46;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --warning-bg: rgba(234, 179, 8, 0.1);
    --warning-border: rgba(234, 179, 8, 0.3);
    --warning-text: #ca8a04;
    
    /* Shift Specific Colors */
    --shift-missing-bg: rgba(128, 128, 128, 0.05);
    --shift-override-border: #ca8a04;
}

/* Dark Mode Support */
.dark-mode .toggle-slider {
    background-color: var(--text-muted);
}

.dark-mode .toggle-slider:before {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.dark-mode,
html.dark-mode {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --bg: #111827;
    --card-bg: #1f2937;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --border: #374151;
    --success-bg: #064e3b;
    --success-text: #d1fae5;
    --error-bg: #450a0a;
    --error-text: #fecaca;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning-bg: rgba(234, 179, 8, 0.2);
    --warning-border: rgba(234, 179, 8, 0.4);
    --warning-text: #fbbf24;
    --shift-missing-bg: rgba(128, 128, 128, 0.1);
}

/* --- Toggle Switch Styling --- */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.toggle-row:last-of-type {
    border-bottom: none;
}

.toggle-label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.toggle-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}

.toggle-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 26px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: 0.3s ease-in-out;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s ease-in-out;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Visual feedback when trying to click a disabled input due to auto-switch */
.rota-select-disabled {
    cursor: not-allowed;
    background-color: var(--bg); /* Slightly different bg */
}

/* Simple shake animation for error feedback */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake-error {
    animation: shake 0.3s ease-in-out;
    border-color: var(--danger) !important;
}

/* Checked State */
.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

.toggle-switch:hover .toggle-slider {
    background-color: var(--primary-hover);
    opacity: 0.8;
}

/* Message Feedback Area */
.message-area {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    min-height: 1.5rem;
    color: var(--success-text);
    font-weight: 500;
}

/* --- Reset & Base --- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   HEADER & NAVIGATION STYLES
   ======================================== */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 70px; /* Fixed height for consistency */
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.025em;
    flex-shrink: 0; /* Prevents logo from shrinking */
}

/* --- Main Navigation Group (Center-Right) --- */
.nav-primary {
    display: flex;
    gap: 0.5rem;
    margin-left: auto; /* Pushes this group to the right of the logo */
    margin-right: 2rem; /* CRITICAL: The "little gap" before user section */
}

.nav-btn {
    min-width: auto;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* --- User Controls Group (Far Right) --- */
.user-controls {
    display: flex;
    align-items: center;
    flex-shrink: 0; /* Prevents user section from collapsing */
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- User Dropdown Styles --- */
.user-dropdown {
    position: relative;
}

.user-menu-trigger {
    background: transparent;
    border: none;
    padding: 0.4rem;
    cursor: pointer;
    color: var(--text-main);
    border-radius: 6px;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-menu-trigger:hover {
    background: rgba(128, 128, 128, 0.1);
}

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-5px);
    transition: all 0.2s ease;
    z-index: 1000;
    padding: 0.5rem 0;
}

.user-dropdown:hover .user-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-menu a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.15s;
}

.user-dropdown-menu a:hover {
    background: rgba(37, 99, 235, 0.08);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0;
}

.logout-link {
    color: #dc2626 !important;
}

.logout-link:hover {
    background: rgba(220, 38, 38, 0.08) !important;
}

/* --- Mobile Responsive Adjustments --- */
@media (max-width: 900px) {
    header {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.75rem;
    }

    .logo {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .nav-primary {
        order: 3;
        width: 100%;
        margin-left: 0;
        margin-right: 0;
        justify-content: center;
        margin-top: 0.5rem;
    }

    .user-controls {
        order: 2;
        margin-left: auto; /* Keeps user on right in middle row */
    }

    .user-name {
        display: none; /* Hide text on small screens, keep icon only */
    }
    
    .login-btn {
        display: inline-flex; /* Show login button clearly */
    }
}

@media (max-width: 480px) {
    .nav-primary {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .user-controls {
        width: 100%;
        justify-content: flex-end;
    }
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    text-decoration: none;
}

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

.btn-secondary {
    background-color: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-secondary:hover {
    background-color: var(--bg);
    color: var(--text-main);
    border-color: var(--text-muted);
}

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

/* --- Main Layout --- */
main {
    flex: 1;
    max-width: 600px;
    width: 100%;
    margin: 2rem auto;
    padding: 0 1rem;
}

main.wide {
    max-width: 1200px;
}

/* --- Cards --- */
.card {
    background-color: var(--card-bg);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 2rem;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

/* --- Typography --- */
h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 2rem;
}

h2 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

h3 {
    margin-top: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

/* --- Forms --- */
label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

input[type="text"],
input[type="number"],
input[type="date"], 
select {
    width: 100%;
    padding: 0.625rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background-color: var(--card-bg); 
    color: var(--text-main); 
    box-sizing: border-box;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
input[type="date"]:focus {
    outline: none;
    border-color: var(--primary);
}

.hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

.hint-tight {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: -0.5rem;
    margin-bottom: 1rem;
}

/* --- Alerts --- */
.alert {
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.alert-success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid transparent;
}

.alert-error {
    background-color: var(--error-bg);
    color: var(--error-text);
    border: 1px solid transparent;
}

/* --- Result Card (Home Page) --- */
.result-card {
    border-radius: 0.75rem;
    text-align: center;
    animation: fadeIn 0.3s ease-in-out;
}

.result-success {
    background-color: var(--card-bg);
    color: var(--text-main);
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
}

.result-error {
    background-color: var(--error-bg);
    color: var(--error-text);
    border-left: 4px solid var(--danger);
    padding: 1.5rem;
    text-align: left;
}

#result {
    margin-top: 2rem;
}

/* --- Reference Items --- */
.ref-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
    padding: 0.75rem;
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
}

/* --- Calendar Table --- */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.table-container {
    overflow-x: auto;
    margin-bottom: 2rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

th, td {
    padding: 12px 16px;
    border: 1px solid var(--border);
    text-align: left;
    font-size: 0.9rem;
}

th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-main);
}

.week-date {
    font-weight: 600;
    color: var(--primary);
    min-width: 120px;
}

.line-num {
    text-align: center;
    font-family: monospace;
    font-size: 1rem;
}

.empty-cell {
    color: var(--text-muted);
    font-style: italic;
}

.line-has-details {
    cursor: pointer;
    position: relative;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    color: var(--primary);
    font-weight: 600 !important;
}

.line-has-details:hover {
    opacity: 0.8;
    text-decoration-style: solid;
}

.line-no-details {
    color: var(--text-muted);
}

/* --- Popup (Calendar Shift Details) --- */
.popup-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

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

.popup-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    padding: 1.5rem;
    width: 95%;
    max-width: 520px;
    color: var(--text-main);
    max-height: 90vh;
    overflow-y: auto;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.popup-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.popup-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

.popup-close:hover {
    color: var(--text-main);
}

.popup-meta {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 500;
}

/* --- NEW: Unified Shift Grid & Card Styles --- */

/* Shift Grid Container */
.shift-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    width: 100%;
}

/* Individual Day Cell */
.shift-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    aspect-ratio: 1 / 1.3;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--shift-missing-bg); /* Default for missing/out-of-range */
    border: 1px solid transparent;
    cursor: default;
    box-sizing: border-box;
    overflow: hidden;
    transition: transform 0.1s, border-color 0.2s;
}

.shift-day.is-clickable {
    cursor: pointer;
}

.shift-day.is-clickable:hover {
    transform: translateY(-2px);
    z-index: 10;
    border-color: var(--primary);
}

.shift-day.is-override {
    border-color: var(--shift-override-border);
}

/* Shift Day Content Styling */
.shift-day__day-name {
    font-weight: 700;
    font-size: 0.55rem;
    text-transform: uppercase;
    color: var(--text-muted);
    line-height: 1.2;
    margin-bottom: 2px;
    text-align: center;
}

.shift-day__date {
    font-size: 0.6rem;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 4px;
    text-align: center;
}

.shift-day__status {
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-main);
    margin: 2px 0;
    text-transform: uppercase;
    text-align: center;
}

.shift-day__status--missing {
    color: var(--text-muted);
}

.shift-day__time {
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 500;
    margin-top: 4px;
    line-height: 1.2;
    text-align: center;
}

.shift-day__divider {
    margin-top: 8px;
    height: 1px;
    width: 80%;
    background: var(--border);
}

/* Shift Card (Daily Summary) */
.shift-card {
    background: var(--card-bg);
    border-left: 4px solid var(--border);
    padding: 1.25rem;
    border-radius: 0.5rem;
    text-align: left;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    margin-bottom: 1rem;
}

.shift-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.shift-card__day-info {
    flex: 1;
    margin-right: 8px;
}

.shift-card__day-label {
    font-weight: 700;
    font-size: 0.6rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.shift-card__date {
    font-size: 0.65rem;
    color: var(--text-main);
    font-weight: 600;
}

.shift-card__status {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.shift-card__times {
    display: flex;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    align-items: center;
    flex-wrap: wrap;
    min-height: 1.5rem;
}

/* --- Day Cell Layout (Matches Homepage Overview) --- */
.day-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    aspect-ratio: 1 / 1.3; /* Restored compact height */
    padding: 5px 6px;
    border-radius: 5px;
    border: 1px solid transparent;
    box-sizing: border-box;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.2s;
    background: rgba(128, 128, 128, 0.05);
}

.day-cell:hover {
    transform: translateY(-2px);
    z-index: 10;
    border-color: var(--primary);
}

.day-cell--override {
    border-color: #ca8a04;
}

.day-cell--empty {
    cursor: default;
    background: rgba(128, 128, 128, 0.03);
}

.day-cell--empty:hover {
    transform: none;
    border-color: transparent;
}

/* --- Typography --- */
.day-cell__name {
    font-weight: 700;
    font-size: 0.5rem;
    text-transform: uppercase;
    color: var(--text-muted);
    line-height: 1.2;
    margin-bottom: 1px;
    text-align: center;
}

.day-cell__date {
    font-size: 0.55rem;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 3px;
    text-align: center;
}

.day-cell__status {
    font-weight: 700;
    font-size: 0.65rem;
    color: var(--text-main);
    text-transform: uppercase;
    text-align: center;
    line-height: 1.1;
    margin-bottom: 4px; /* Gap before times/duty */
}

.day-cell__times {
    color: var(--text-muted);
    font-size: 0.55rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    margin-top: 2px;
    white-space: nowrap;
}

/* Container that pushes the badge to the bottom */
.day-cell__duty-container {
    margin-top: auto; /* Pushes content to the bottom of the flex column */
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 2px; /* Small gap from the very bottom edge */
}

/* --- Duty Badge (Pill Style) --- */
.day-cell__duty-badge {
        display: inline-block;
        background: var(--primary); 
        color: white;
        font-size: 0.5rem;
        font-weight: 700;
        padding: 2px 6px; /* Slightly taller padding now that text is longer */
        border-radius: 3px;
        line-height: 1;
    }

/* Duty Badge - Matches Homepage Style */
.day-cell__duty-badge {
    display: inline-block;
    background: var(--primary);
    color: white;
    font-size: 0.5rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    margin-top: 3px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-right: 0.25rem;
}

.badge--duty {
    background: var(--primary);
    color: white;
}

.badge--override {
    background: rgba(234, 179, 8, 0.15);
    color: #ca8a04;
    border: 1px solid rgba(234, 179, 8, 0.4);
    padding: 2px 6px;
    border-radius: 10px;
    white-space: nowrap;
}

/* Week Navigation */
.week-nav {
    margin-top: 1.5rem;
    border-top: 1px solid currentColor;
    padding-top: 1rem;
}

.week-nav__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.week-nav__label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Toast Notification */
#toast {
    position: fixed; 
    bottom: 2rem; 
    left: 50%; 
    transform: translateX(-50%);
    background-color: var(--card-bg); 
    color: var(--text-main); 
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem; 
    font-size: 0.875rem; 
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); 
    opacity: 0; 
    transition: opacity 0.3s ease-in-out; 
    pointer-events: none; 
    z-index: 9999;
    border: 1px solid var(--border);
}

/* Lookup Toggle */
.lookup-header {
    cursor: pointer;
    user-select: none;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}
.lookup-header:hover { color: var(--primary); }
.lookup-content { transition: opacity 0.3s, max-height 0.3s; opacity: 1; overflow: hidden; max-height: 500px; }
.lookup-content.collapsed { opacity: 0; max-height: 0; margin-top: 0; }
.lookup-container {
    margin-bottom: 1rem;
    border-radius: 0.5rem;
}

.lookup-container > .lookup-header {
    padding: 0.75rem 1.25rem !important;
    border-bottom: 1px solid var(--border);
}

.lookup-container > #lookupContent {
    padding: 1rem 1.25rem !important;
}

#lookupContent form {
    max-width: 320px;
    margin: 0 auto;
}

#lookupContent label[for="target_date"] {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

#lookupContent input[type="date"] {
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
    border-radius: 0.4rem;
    margin-bottom: 0;
}

#lookupContent .hint {
    font-size: 0.7rem;
    margin-top: 0.3rem;
    margin-bottom: 0;
}

/* Remove excessive spacing from deprecated groups */
#rota-group,
#ref-group {
    display: none !important;
}

@media (max-width: 768px) {
    .lookup-container > .lookup-header { padding: 1rem; }
    .lookup-container > #lookupContent { padding: 1rem; }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Adjustments (Mobile) */
@media (max-width: 768px) {
    body { max-width: 100vw; overflow-x: hidden; }
    header { flex-direction: column; height: auto; padding: 0.75rem 0.5rem; gap: 0.75rem; }
    .nav-buttons { width: 100%; display: flex; gap: 0.5rem; justify-content: stretch; }
    .btn { flex: 1; min-width: 0; font-size: 0.85rem; padding: 0.55rem 0.5rem; }
    main, main.wide { width: 100%; margin: 0 auto; padding: 0.25rem; box-sizing: border-box; }
    .card { padding: 1rem; margin-bottom: 1rem; }
    h1 { font-size: 1.4rem; margin-top: 0.5rem; margin-bottom: 1rem; text-align: center; }
    h2 { font-size: 1.1rem; margin-bottom: 1rem; }
    .controls { flex-direction: column; gap: 0.5rem; align-items: stretch; margin-bottom: 1rem; }
    .controls select { width: 100%; margin: 0; }
    table { min-width: 380px; font-size: 0.8rem; }
    th, td { padding: 8px 10px; font-size: 0.8rem; }
    input, select { font-size: 16px; padding: 0.6rem; }
    .result-card { padding: 1.25rem; }
    .popup-card { width: 95%; max-width: 520px; padding: 1rem; }
    .shift-grid { min-width: 380px; }
    .shift-day > div { font-size: 0.65rem !important; }
}

@media (min-width: 769px) {
    .popup-card { width: auto; min-width: 580px; max-width: 650px; margin: auto; }
    .shift-day { font-size: 0.75rem; padding: 10px 8px; }
}