/* ═══════════════════════════════════════════════════════════════
   Patient Task Tracker — Stylesheet
═══════════════════════════════════════════════════════════════ */

/* ── Reset / Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --clr-primary:   #2563eb;
    --clr-primary-h: #1d4ed8;
    --clr-danger:    #ef4444;
    --clr-danger-h:  #dc2626;
    --clr-green:     #22c55e;
    --clr-yellow:    #f59e0b;
    --clr-red:       #ef4444;
    --clr-surface:   #ffffff;
    --clr-bg:        #f3f4f6;
    --clr-border:    #e5e7eb;
    --clr-text:      #111827;
    --clr-muted:     #6b7280;
    --radius:        0.5rem;
    --shadow:        0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg:     0 10px 25px rgba(0,0,0,.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--clr-bg);
    color: var(--clr-text);
    min-height: 100vh;
    font-size: 0.9375rem;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    text-decoration: none;
}
.btn-primary { background: var(--clr-primary); color: #fff; }
.btn-primary:hover { background: var(--clr-primary-h); }
.btn-ghost   { background: transparent; color: var(--clr-text); border-color: var(--clr-border); }
.btn-ghost:hover { background: var(--clr-border); }
.btn-danger  { background: var(--clr-danger); color: #fff; }
.btn-danger:hover { background: var(--clr-danger-h); }
.btn-full    { width: 100%; justify-content: center; padding: .65rem; }
.btn-icon    {
    padding: 0.3rem 0.55rem;
    background: transparent;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    color: var(--clr-muted);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background .15s, color .15s;
}
.btn-icon:hover { background: #fee2e2; color: var(--clr-danger); border-color: #fca5a5; }

/* ── Alerts ──────────────────────────────────────────────────── */
.alert { padding: .65rem 1rem; border-radius: var(--radius); font-size: .875rem; margin-bottom: 1rem; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── Form elements ───────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: .06em;
    color: var(--clr-muted);
    margin-bottom: .35rem;
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"] {
    width: 100%;
    padding: .6rem .85rem;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    font-size: .9375rem;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

/* ════════════════════════════════════════════════════════════════
   LOGIN PAGE
════════════════════════════════════════════════════════════════ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}

.login-card {
    background: var(--clr-surface);
    border-radius: 1rem;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.login-title    { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: .3rem; }
.login-subtitle { text-align: center; color: var(--clr-muted); margin-bottom: 1.5rem; font-size: .875rem; }
.login-hint     { text-align: center; color: var(--clr-muted); font-size: .78rem; margin-top: 1.2rem; }

/* ════════════════════════════════════════════════════════════════
   HEADER
════════════════════════════════════════════════════════════════ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    background: var(--clr-surface);
    padding: 1rem 1.75rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.app-title { font-size: 1.35rem; font-weight: 700; white-space: nowrap; }

.header-controls {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.search-wrap .search-icon {
    position: absolute;
    left: .7rem;
    font-size: .85rem;
    pointer-events: none;
}
#searchInput {
    padding: .45rem .75rem .45rem 2rem;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    font-size: .875rem;
    width: 200px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
#searchInput:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

#filterSelect {
    padding: .45rem .75rem;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    font-size: .875rem;
    background: var(--clr-surface);
    cursor: pointer;
    outline: none;
}

.user-label { font-weight: 600; color: var(--clr-text); font-size: .875rem; }

/* ════════════════════════════════════════════════════════════════
   TABLE
════════════════════════════════════════════════════════════════ */
.table-wrap  { padding: 1.5rem 1.75rem; }
.table-scroll { overflow-x: auto; }

.patient-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--clr-surface);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.patient-table thead tr {
    border-bottom: 2px solid var(--clr-border);
}
.patient-table th {
    padding: .85rem 1rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--clr-muted);
    text-align: left;
    white-space: nowrap;
}
.patient-table td {
    padding: .9rem 1rem;
    border-bottom: 1px solid var(--clr-border);
    vertical-align: middle;
}
.patient-table tbody tr:last-child td { border-bottom: none; }
.patient-table tbody tr:hover { background: #f9fafb; }

.col-name { min-width: 170px; font-weight: 600; }

.loading-cell, .empty-cell {
    text-align: center;
    color: var(--clr-muted);
    padding: 3rem 1rem;
    font-size: .95rem;
}

/* ── Checkbox toggle ─────────────────────────────────────────── */
.task-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: .4rem;
    border: 1.5px solid #d1d5db;
    cursor: pointer;
    background: var(--clr-surface);
    font-size: .9rem;
    transition: background .18s, border-color .18s, transform .1s;
    user-select: none;
}
.task-toggle:hover { transform: scale(1.1); }
.task-toggle.checked {
    background: var(--clr-green);
    border-color: var(--clr-green);
    color: #fff;
}
.task-toggle.unchecked { color: #9ca3af; }
.task-toggle.loading { opacity: .5; pointer-events: none; }

/* ── Deadline badge ──────────────────────────────────────────── */
.deadline-badge {
    display: inline-block;
    padding: .3rem .75rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
    white-space: nowrap;
    color: #fff;
}
.badge-green  { background: var(--clr-green); }
.badge-yellow { background: var(--clr-yellow); }
.badge-red    { background: var(--clr-red);   }

/* ── Clinic badge ────────────────────────────────────────────── */
.clinic-badge {
    display: inline-block;
    padding: .2rem .65rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
}
.clinic-jarva { background: #dbeafe; color: #1e40af; }
.clinic-satra { background: #fae8ff; color: #7e22ce; }

/* ── Updated by cell ─────────────────────────────────────────── */
.updated-by { color: var(--clr-muted); font-size: .875rem; }

/* ── Sortable headers ────────────────────────────────────────── */
th[data-sort] {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
th[data-sort]:hover { color: var(--clr-text); background: #f3f4f6; }
th[data-sort]::after {
    content: ' ⇅';
    font-size: .68rem;
    opacity: .3;
}
th[data-sort].sort-asc::after  { content: ' ↑'; opacity: 1; color: var(--clr-primary); }
th[data-sort].sort-desc::after { content: ' ↓'; opacity: 1; color: var(--clr-primary); }

/* ── Notes cell ─────────────────────────────────────────────── */
.col-notes { min-width: 160px; }
.notes-cell-inner {
    display: flex;
    align-items: center;
    gap: .4rem;
}
.note-text {
    flex: 1;
    cursor: text;
    font-size: .875rem;
    color: var(--clr-text);
    padding: .28rem .5rem;
    border-radius: .35rem;
    min-height: 1.8rem;
    display: inline-flex;
    align-items: center;
    border: 1px solid transparent;
    transition: background .13s, border-color .13s;
    word-break: break-word;
}
.note-text:hover {
    background: #f3f4f6;
    border-color: var(--clr-border);
}
.note-placeholder { color: var(--clr-muted); font-style: normal; font-size: .8rem; }
.note-input {
    flex: 1;
    min-width: 0;
    padding: .3rem .5rem;
    border: 1.5px solid var(--clr-primary);
    border-radius: .35rem;
    font-size: .875rem;
    font-family: inherit;
    outline: none;
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* ════════════════════════════════════════════════════════════════
   MODALS
════════════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 1rem;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
    background: var(--clr-surface);
    border-radius: 1rem;
    padding: 2rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    animation: modalIn .18s ease;
}
@keyframes modalIn {
    from { transform: translateY(-12px); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

.modal-card h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: .25rem; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: .65rem;
    margin-top: 1.5rem;
}

.delete-confirm-msg { color: var(--clr-muted); margin-bottom: 0.5rem; }

/* ── Add Patient modal enhancements ─────────────────────────── */
.modal-card--add { max-width: 440px; }

.modal-header {
    display: flex;
    align-items: center;
    gap: .9rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--clr-border);
}
.modal-icon {
    font-size: 2rem;
    width: 3.2rem;
    height: 3.2rem;
    background: #f0fdf4;
    border-radius: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.modal-subtitle {
    font-size: .82rem;
    color: var(--clr-muted);
    margin-top: .15rem;
}

/* ── Input with leading icon ─────────────────────────────────── */
.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.input-icon {
    position: absolute;
    left: .75rem;
    font-size: .9rem;
    pointer-events: none;
    z-index: 1;
}
.form-group input.has-icon,
.form-group input[type="date"].has-icon {
    width: 100%;
    padding: .65rem .85rem .65rem 2.4rem;
    border: 1.5px solid var(--clr-border);
    border-radius: var(--radius);
    font-size: .9375rem;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    background: var(--clr-surface);
}
.form-group input.has-icon:focus,
.form-group input[type="date"].has-icon:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── Clinic radio buttons ─────────────────────────────────────── */
.clinic-radio-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
}
.clinic-radio-option {
    cursor: pointer;
}
.clinic-radio-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.clinic-radio-card {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    border: 2px solid var(--clr-border);
    background: #f9fafb;
    transition: border-color .15s, background .15s, box-shadow .15s;
    user-select: none;
}
.clinic-radio-dot {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: border-color .15s, background .15s;
}
.clinic-radio-dot::after {
    content: '';
    width: .45rem;
    height: .45rem;
    border-radius: 50%;
    background: transparent;
    transition: background .15s;
}
.clinic-radio-name {
    font-size: .9375rem;
    font-weight: 600;
}

/* Jarva selected — sky */
.clinic-radio-option input[type="radio"][value="Jarva"]:checked ~ .clinic-radio-jarva {
    border-color: #0ea5e9;
    background: #f0f9ff;
    box-shadow: 0 0 0 3px rgba(14,165,233,.12);
}
.clinic-radio-option input[type="radio"][value="Jarva"]:checked ~ .clinic-radio-jarva .clinic-radio-dot {
    border-color: #0ea5e9;
    background: #0ea5e9;
}
.clinic-radio-option input[type="radio"][value="Jarva"]:checked ~ .clinic-radio-jarva .clinic-radio-dot::after {
    background: #fff;
}
.clinic-radio-jarva .clinic-radio-name { color: #0369a1; }

/* Satra selected — green */
.clinic-radio-option input[type="radio"][value="Satra"]:checked ~ .clinic-radio-satra {
    border-color: #22c55e;
    background: #f0fdf4;
    box-shadow: 0 0 0 3px rgba(34,197,94,.12);
}
.clinic-radio-option input[type="radio"][value="Satra"]:checked ~ .clinic-radio-satra .clinic-radio-dot {
    border-color: #22c55e;
    background: #22c55e;
}
.clinic-radio-option input[type="radio"][value="Satra"]:checked ~ .clinic-radio-satra .clinic-radio-dot::after {
    background: #fff;
}
.clinic-radio-satra .clinic-radio-name { color: #15803d; }

/* Hover state for unselected */
.clinic-radio-card:hover {
    border-color: #9ca3af;
    background: #f3f4f6;
}

/* ════════════════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════════════════ */
@media (max-width: 700px) {
    .app-header { padding: .85rem 1rem; }
    .table-wrap { padding: 1rem; }
    #searchInput { width: 140px; }
    .app-title { font-size: 1.1rem; }
    .patient-table th,
    .patient-table td { padding: .65rem .6rem; }
}
