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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    color: #2c5aa0;
    margin-bottom: 30px;
    font-size: 1.8rem;
}

h2 {
    color: #2c5aa0;
    margin-bottom: 15px;
    font-size: 1.2rem;
    border-bottom: 2px solid #2c5aa0;
    padding-bottom: 5px;
}

.section {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Side-by-side section rows */
.section-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.section-row > .section {
    flex: 1;
    margin-bottom: 0;
    min-width: 0;
}

.section-row > .section-form {
    flex: 0 0 420px;
}

.section-row > .section-list {
    flex: 1;
    overflow: hidden;
}

/* Patient Entry Form */
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group.flex-1 {
    flex: 1;
    min-width: 200px;
}

.form-group label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #555;
}

.form-group input[type="text"],
.form-group select,
.form-group textarea {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.nurse-checkbox {
    background: #fff3cd;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid #ffc107;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.btn-primary {
    background: #2c5aa0;
    color: white;
}

.btn-primary:hover {
    background: #1e3f73;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
}

.btn-edit {
    background: #17a2b8;
    color: white;
    padding: 5px 10px;
    font-size: 0.85rem;
}

.btn-edit:hover {
    background: #138496;
}

/* Patient List Table */
.table-container {
    overflow: auto;
    max-height: 420px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th, td {
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid #ddd;
    vertical-align: middle;
}

th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
    z-index: 1;
}

tr:hover {
    background: #f8f9fa;
}

.status-indicator {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-success {
    background: #d4edda;
    color: #155724;
}

.status-pending {
    background: #fff3cd;
    color: #856404;
}

.status-failed {
    background: #f8d7da;
    color: #721c24;
}

.nurse-badge {
    background: #e2e3ff;
    color: #3f51b5;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-left: 5px;
}

.actions-wrap {
    display: flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
}

/* Schedule Generator */
.generator-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 20px;
}

.generator-controls .form-group {
    min-width: 150px;
}

/* Weekly Schedule View */
.schedule-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 15px;
}

.day-column {
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
}

.day-header {
    background: #2c5aa0;
    color: white;
    padding: 12px;
    text-align: center;
    font-weight: 600;
}

.day-patients {
    padding: 10px;
    min-height: 150px;
}

.patient-card {
    background: white;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-left: 4px solid #2c5aa0;
    cursor: pointer;
    transition: transform 0.1s;
}

.patient-card:hover {
    transform: translateX(3px);
}

.patient-card.nurse-required {
    border-left-color: #ffc107;
    background: #fffdf5;
}

.patient-card .name {
    font-weight: 600;
    margin-bottom: 3px;
}

.patient-card .address {
    font-size: 0.8rem;
    color: #666;
}

.patient-card .cluster-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-top: 5px;
}

/* Cluster colors */
.cluster-0 { background: #e3f2fd; color: #1565c0; border-left-color: #1565c0; }
.cluster-1 { background: #e8f5e9; color: #2e7d32; border-left-color: #2e7d32; }
.cluster-2 { background: #fff3e0; color: #ef6c00; border-left-color: #ef6c00; }
.cluster-3 { background: #fce4ec; color: #c2185b; border-left-color: #c2185b; }
.cluster-4 { background: #f3e5f5; color: #7b1fa2; border-left-color: #7b1fa2; }
.cluster-5 { background: #e0f7fa; color: #00838f; border-left-color: #00838f; }
.cluster-6 { background: #fff8e1; color: #ff8f00; border-left-color: #ff8f00; }
.cluster-7 { background: #efebe9; color: #5d4037; border-left-color: #5d4037; }

.warning-box {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 10px 15px;
    margin-bottom: 15px;
    color: #856404;
}

.info-box {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    border-radius: 4px;
    padding: 10px 15px;
    margin-bottom: 15px;
    color: #0c5460;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #888;
}

/* Tooltip */
.tooltip {
    position: fixed;
    background: #333;
    color: white;
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 0.85rem;
    max-width: 300px;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2c5aa0;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 5px;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.geocode-queue {
    font-size: 0.85rem;
    color: #666;
    margin-top: 10px;
}

/* Visit order badge */
.visit-order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #2c5aa0;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-right: 6px;
}

/* Card action bar */
.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 8px;
    margin-top: 8px;
    border-top: 1px solid #e0e0e0;
}

.btn-move {
    padding: 3px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid #2c5aa0;
    color: #2c5aa0;
    background: white;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-move:hover:not(:disabled) {
    background: #e8f0fe;
}

.btn-move:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-remove {
    padding: 3px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid #dc3545;
    color: #dc3545;
    background: white;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-remove:hover {
    background: #fde8ea;
}

.patient-card.selected {
    box-shadow: 0 0 0 2px #2c5aa0;
}

.btn-reorder {
    padding: 3px 7px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid #6c757d;
    color: #6c757d;
    background: white;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-reorder:hover:not(:disabled) {
    background: #f0f0f0;
}

.btn-reorder:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.action-separator {
    width: 1px;
    background: #ddd;
    margin: 0 2px;
    align-self: stretch;
}

/* Info icon + hover tooltip */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #2c5aa0;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    font-style: italic;
    cursor: help;
    vertical-align: middle;
    margin-left: 6px;
    position: relative;
}

/* Bulk actions */
.bulk-actions {
    display: none;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

/* Custom Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

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

.modal-box {
    background: white;
    border-radius: 10px;
    padding: 28px 32px 20px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
    animation: modalIn 0.15s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-box p {
    font-size: 1rem;
    margin-bottom: 20px;
    line-height: 1.5;
    color: #333;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-buttons .btn {
    min-width: 90px;
}

/* Patient search */
.patient-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.patient-search:focus {
    outline: none;
    border-color: #2c5aa0;
    box-shadow: 0 0 0 2px rgba(44, 90, 160, 0.15);
}

/* Drive time stats */
.day-stats {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
    font-weight: 400;
    margin-top: 2px;
}

.leg-distance {
    font-size: 0.7rem;
    color: #999;
    margin-top: 2px;
}

/* Google Maps directions button */
.btn-directions {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    margin-left: 6px;
    vertical-align: middle;
}

.btn-directions:hover {
    background: rgba(255,255,255,0.35);
}

/* Lock day */
.day-header.locked {
    background: #5a6f8a;
}

.btn-lock {
    display: inline-block;
    padding: 1px 6px;
    font-size: 0.75rem;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 3px;
    cursor: pointer;
    margin-left: 6px;
    vertical-align: middle;
}

.btn-lock:hover {
    background: rgba(255,255,255,0.35);
}

/* Drag and drop */
.patient-card.dragging {
    opacity: 0.4;
    border: 2px dashed #2c5aa0;
}

.day-patients.drag-over {
    background: #e3f0ff;
    border-radius: 4px;
}

.day-column.locked .day-patients.drag-over {
    background: inherit;
}

/* Week navigation */
.week-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 15px;
    padding: 8px 0;
}

#weekLabel {
    font-weight: 600;
    font-size: 1rem;
    color: #2c5aa0;
    min-width: 180px;
    text-align: center;
}

/* Map controls */
.map-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.map-controls select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Leaflet marker number labels */
.map-marker-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.map-marker-home {
    background: #28a745;
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    border: 3px solid white;
    box-shadow: 0 3px 10px rgba(0,0,0,0.4);
}

/* This Week toggle */
.week-toggle {
    position: relative;
    width: 40px;
    height: 22px;
    display: inline-block;
}

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

.week-toggle .slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc;
    border-radius: 22px;
    transition: background 0.2s;
}

.week-toggle .slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.week-toggle input:checked + .slider {
    background: #2c5aa0;
}

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

tr.patient-excluded {
    opacity: 0.45;
}

/* Clickable geocode badge */
.status-indicator[onclick] {
    cursor: pointer;
}

.status-indicator[onclick]:hover {
    filter: brightness(0.9);
}

/* Responsive */
@media (max-width: 1024px) {
    .section-row {
        flex-direction: column;
    }

    .section-row > .section-form {
        flex: 1;
    }
}

@media (max-width: 768px) {
    .schedule-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        flex-direction: column;
    }

    .form-group.flex-1 {
        min-width: 100%;
    }
}
