/* Care Home Rota Scheduler - Mobile-first styles */

:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --header-bg: #1e293b;
    --header-text: #f8fafc;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --radius: 8px;
    --shift-e: #dbeafe;
    --shift-l: #fef3c7;
    --shift-n: #e0e7ff;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* Header */
.header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header .subtitle {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

.status-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.status-optimal { background: #166534; color: #bbf7d0; }
.status-feasible { background: #854d0e; color: #fef08a; }
.status-infeasible { background: #991b1b; color: #fecaca; }

/* Stats bar */
.stats-bar {
    display: flex;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
    font-size: 11px;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

/* Navigation */
.week-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.week-nav h2 {
    font-size: 14px;
    font-weight: 600;
}

.week-nav button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}

.week-nav button:disabled {
    opacity: 0.4;
    cursor: default;
}

.week-nav button:active {
    background: var(--primary-dark);
}

/* Day cards (mobile-first scroll) */
.days-container {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.day-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.day-header {
    padding: 10px 14px;
    font-weight: 600;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.day-header.today {
    background: var(--primary);
    color: white;
}

.day-header .date-label {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
}

.day-header.today .date-label {
    color: #bfdbfe;
}

/* Shifts within a day */
.shift-block {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
}

.shift-block:last-child {
    border-bottom: none;
}

.shift-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.shift-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.shift-dot.d { background: #3b82f6; }
.shift-dot.n { background: #6366f1; }

.staff-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.staff-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 500;
    background: #f1f5f9;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s;
}

.staff-chip:active {
    background: #e2e8f0;
}

.staff-chip.locked {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    position: relative;
    padding-left: 20px;
}

.staff-chip.locked::before {
    content: "🔒";
    position: absolute;
    left: 4px;
    font-size: 9px;
}

/* Dragging states */
.staff-chip.dragging {
    opacity: 0.4;
}

.drag-ghost {
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: rotate(2deg);
}

.shift-block.drag-over {
    background: #f0f9ff !important;
    border: 2px dashed var(--primary) !important;
    border-radius: var(--radius);
}

.shift-block.drag-over .staff-list {
    min-height: 40px;
}

.staff-chip .role-tag {
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
}

.role-team_leader { background: #dbeafe; color: #1e40af; }
.role-carer { background: #fce7f3; color: #9d174d; }

.shift-count {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
}

/* Empty state */
.empty-shift {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    padding: 4px 0;
}

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Violations */
.violations-banner {
    margin: 0 12px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: #991b1b;
    font-size: 12px;
}

.violations-banner strong {
    display: block;
    margin-bottom: 4px;
}

/* Action buttons */
.actions {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
}

.actions button {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

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

.btn-recompute:active {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text);
}

.btn-secondary:active {
    background: #e2e8f0;
}

.btn-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.btn-danger:active {
    background: #fee2e2;
}

/* Chip popup (inline lock/unlock) */
.chip-popup {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    width: 300px;
    max-width: calc(100vw - 32px);
    z-index: 300;
    overflow: hidden;
    animation: popup-in 0.15s ease-out;
}

@keyframes popup-in {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.chip-popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--header-bg);
    color: var(--header-text);
    font-size: 14px;
}

.chip-popup-header .role-tag {
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
}

.chip-popup-close {
    margin-left: auto;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.chip-popup-body {
    padding: 12px 14px;
}

.chip-popup-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

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

.chip-popup-actions {
    margin-top: 10px;
}

.popup-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.popup-btn-lock {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.popup-btn-lock:active {
    background: #dcfce7;
}

.popup-btn-unlock {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.popup-btn-unlock:active {
    background: #fee2e2;
}

.chip-popup-details {
    color: var(--primary);
    font-size: 12px;
    text-decoration: none;
}

/* Shift selector (radio button cards) */
.shift-selector {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.shift-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.1s;
    font-size: 13px;
}

.shift-option:has(input:checked) {
    border-color: var(--primary);
    background: #eff6ff;
}

.shift-option.shift-current {
    border-color: #93c5fd;
}

.shift-option.shift-locked {
    background: #fef3c7;
    border-color: #f59e0b;
}

.shift-option input[type="radio"] {
    accent-color: var(--primary);
}

.shift-option-label {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.shift-badge-current {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    background: #dbeafe;
    color: #1e40af;
    font-weight: 600;
}

.shift-badge-locked {
    font-size: 10px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

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

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    line-height: 1;
}

.modal-body {
    padding: 16px;
}

/* Staff detail */
.staff-detail-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.staff-detail-item:last-child {
    border-bottom: none;
}

.staff-detail-label {
    color: var(--text-secondary);
}

/* Leave indicator */
.leave-chip {
    background: #fef2f2;
    color: #991b1b;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}

/* Responsive: tablets+ get multi-column */
@media (min-width: 768px) {
    .days-container {
        flex-direction: row;
        flex-wrap: wrap;
        max-width: none;
    }

    .day-card {
        flex: 0 0 calc(50% - 12px);
    }
}

@media (min-width: 1024px) {
    .day-card {
        flex: 0 0 calc(33.33% - 12px);
    }
}

/* Print styles */
@media print {
    .header, .week-nav, .actions, .stats-bar { display: none; }
    .day-card { break-inside: avoid; }
    body { background: white; }
}
