/* ============================
   Neuro EMR — Dark Theme
   ============================ */

[hidden] { display: none !important; }

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: #1e2a4a;
    --bg-input: #0d1b3e;
    --bg-hover: #253a5e;
    --bg-selected: #1a5276;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #6a6a7a;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --danger: #ef5350;
    --danger-hover: #e53935;
    --warning: #ffb74d;
    --success: #66bb6a;
    --border: #2a3a5e;
    --border-light: #354a6e;
    --shadow: rgba(0,0,0,0.3);
    --radius: 8px;
    --radius-sm: 4px;
    --sidebar-width: 280px;
    --topbar-height: 52px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
}

/* ---- Login Screen ---- */

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary));
}

.login-card {
    background: var(--bg-card);
    padding: 40px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px var(--shadow);
    text-align: center;
}

.login-card h1 {
    font-size: 28px;
    color: var(--accent);
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 28px;
    font-size: 13px;
}

/* ---- Forms ---- */

.form-group {
    margin-bottom: 14px;
    text-align: left;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.form-row {
    display: flex;
    gap: 12px;
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

input[type="search"] {
    -webkit-appearance: none;
}

/* ---- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    font-family: inherit;
    gap: 6px;
}

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

.btn-primary {
    background: var(--accent);
    color: #000;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-warning {
    background: var(--warning);
    color: #000;
}

.btn-small {
    padding: 5px 12px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
    margin-top: 6px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--bg-hover); }

/* ---- Error Messages ---- */

.error-msg {
    background: rgba(239,83,80,0.15);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin: 8px 0;
}

/* ---- App Shell ---- */

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ---- Top Bar ---- */

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Global search dropdown */
.global-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 350px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 1000;
    margin-top: 4px;
}
.global-search-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
.global-search-item:hover {
    background: var(--bg-hover);
}
.global-search-item:last-child {
    border-bottom: none;
}
.global-search-patient {
    font-weight: 700;
    color: var(--accent);
    font-size: 13px;
}
.global-search-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.global-search-snippet {
    font-size: 12px;
    color: var(--text-primary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
}

/* Whose session is open — readable from across the room on a shared PC. */
.signed-in-user {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--accent);
    border-radius: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
    flex-shrink: 0;           /* the name never gets squeezed by the buttons */
}
.top-bar-left { flex-shrink: 0; }
/* iPad portrait / narrow windows: keep the name, role moves to the tooltip. */
@media (max-width: 1100px) {
    .signed-in-role { display: none; }
    .top-bar-right { gap: 6px; }   /* make room for the name so Logout stays on screen */
}
@media (max-width: 480px) {
    .signed-in-user { max-width: 120px; font-size: 12px; }
}

.physician-badge {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border-radius: 12px;
}

.user-email {
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- App Body (sidebar + main) ---- */

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ---- Sidebar ---- */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.25s ease;
    /* iPad Safari: ensure flex children can scroll */
    min-height: 0;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header input {
    width: 100%;
}

.patient-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0;
}

.patient-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.patient-item:hover {
    background: var(--bg-hover);
}

.patient-item.selected {
    background: var(--bg-selected);
    border-left: 3px solid var(--accent);
}

.patient-item-name {
    font-weight: 500;
    font-size: 14px;
}

.patient-item-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.sidebar-footer {
    padding: 10px;
    border-top: 1px solid var(--border);
}
/* Add Patient button at top of sidebar header */
.sidebar-header .btn-full {
    flex-shrink: 0;
}

/* ---- Main Content ---- */

.main-content {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#patient-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 16px;
}

/* ---- Patient Toolbar (Row 1) ---- */

.patient-toolbar {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 6px;
}
.pt-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ---- Patient Dashboard (Row 2 + 3) ---- */

.patient-dashboard {
    flex-shrink: 0;
    padding: 8px 16px 6px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
}

.pt-name-banner {
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 6px;
    line-height: 1.2;
}

.dash-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.dash-btn {
    flex: 1;
    min-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.1s;
    font-family: inherit;
}
.dash-btn:hover { transform: translateY(-1px); }
.dash-btn:active { transform: translateY(0); }
.dash-btn.active { border-color: currentColor; background: var(--bg-selected); }

.dash-label {
    font-size: 12px;
    font-weight: 700;
}
.dash-count {
    font-size: 16px;
    font-weight: 800;
}

/* Dashboard button colors — bright/vivid */
.dash-vitals { color: #ff5252; border-color: rgba(255,82,82,0.4); }
.dash-vitals.active { border-color: #ff5252; }
.dash-notes { color: #69f0ae; border-color: rgba(105,240,174,0.4); }
.dash-notes.active { border-color: #69f0ae; }
.dash-attach { color: #80cbc4; border-color: rgba(128,203,196,0.4); }
.dash-attach.active { border-color: #80cbc4; }
.dash-rx { color: #ce93d8; border-color: rgba(206,147,216,0.4); }
.dash-rx.active { border-color: #ce93d8; }

.dash-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.dash-link:hover { color: var(--accent); }
.dash-link.active { color: var(--accent); font-weight: 700; }

/* ---- Tabs (hidden, kept for JS compat) ---- */

.tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    padding: 0 12px;
    flex-shrink: 0;
    overflow-x: auto;
}

.tab {
    padding: 14px 24px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s, filter 0.2s;
    font-family: inherit;
    white-space: nowrap;
    min-height: 48px;
}

/* Per-tab colors */
.tab[data-tab="demographics"] { color: #4fc3f7; }
.tab[data-tab="appointments"] { color: #ffb74d; }
.tab[data-tab="vitals"]       { color: #ef5350; }
.tab[data-tab="notes"]        { color: #66bb6a; }
.tab[data-tab="prescriptions"]{ color: #ab47bc; }
.tab[data-tab="attachments"]  { color: #78909c; }
.tab[data-tab="references"]   { color: #8d6e63; }

.tab:hover {
    filter: brightness(1.3);
}

.tab.active {
    filter: brightness(1);
}
.tab.active[data-tab="demographics"] { border-bottom-color: #4fc3f7; }
.tab.active[data-tab="appointments"] { border-bottom-color: #ffb74d; }
.tab.active[data-tab="vitals"]       { border-bottom-color: #ef5350; }
.tab.active[data-tab="notes"]        { border-bottom-color: #66bb6a; }
.tab.active[data-tab="prescriptions"]{ border-bottom-color: #ab47bc; }
.tab.active[data-tab="attachments"]  { border-bottom-color: #78909c; }
.tab.active[data-tab="references"]   { border-bottom-color: #8d6e63; }

.tab-panel-wrapper {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.tab-panel {
    display: none;
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    padding-bottom: 40px;
}

.tab-panel.active {
    display: block;
}

/* ---- Demographics ---- */

.demo-form {
    max-width: 720px;
}

.demo-form .form-group {
    margin-bottom: 16px;
}

.demo-form .form-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

.demo-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 20px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.demo-section-title:first-child {
    margin-top: 0;
}

/* ---- Notes List ---- */

.notes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.note-type-select {
    width: auto;
    min-width: 160px;
}

/* ---- Notes Action Buttons ---- */
.notes-btn-new,
.notes-btn-print,
.notes-btn-share {
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 700;
    border-radius: 8px;
    letter-spacing: 0.3px;
}

.notes-btn-new {
    background: var(--accent);
    color: #000;
}
.notes-btn-new:hover { background: var(--accent-hover); }

.notes-btn-print {
    background: #3b82f6;
    color: #fff;
}
.notes-btn-print:hover { background: #2563eb; }

.notes-btn-share {
    background: #8b5cf6;
    color: #fff;
}
.notes-btn-share:hover { background: #7c3aed; }

/* ---- Note Type Picker Grid ---- */
.ntp-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.ntp-tab {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.ntp-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ntp-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.ntp-panel {
    display: none;
}

.ntp-panel.active {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.ntp-type-btn {
    padding: 10px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}

.ntp-type-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.notes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.note-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.note-card:hover {
    border-color: var(--accent);
}

.note-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.note-card-type {
    font-weight: 600;
    color: var(--accent);
    font-size: 13px;
}

.note-card-date {
    font-size: 11px;
    color: var(--text-muted);
}

.note-card-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-badge-finalized {
    display: inline-block;
    font-size: 10px;
    background: var(--success);
    color: #000;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 8px;
    font-weight: 600;
}

.note-badge-signed {
    display: inline-block;
    font-size: 10px;
    background: #1f4e79;
    color: #fff;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    font-weight: 600;
}

.note-textarea {
    width: 100%;
    height: calc(100vh - 260px);
    resize: vertical;
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 14px;
}

/* ---- Reference Viewer Content ---- */

.ref-viewer-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-input);
    padding: 16px;
    border-radius: var(--radius-sm);
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    border: 1px solid var(--border);
}

/* ---- Note Editor: flex layout so toolbar + footer always visible ---- */

.note-editor-content {
    height: 95vh;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.note-editor-content .modal-header {
    flex-shrink: 0;
}

.note-editor-content .modal-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
    overflow: hidden;
    padding: 12px 20px 16px;
}

.note-editor-content .note-textarea {
    flex: 1 1 0;
    min-height: 0;
    height: auto;
}

.note-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 0 6px;
    border-top: 1px solid var(--border);
    margin-top: 6px;
    flex-shrink: 0;
}

.note-toolbar .btn {
    font-size: 12px;
    padding: 8px 14px;
}

.note-editor-content .modal-footer {
    flex-shrink: 0;
}

/* ---- Vitals ---- */

.vitals-entry-form {
    max-width: 600px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}

.vitals-entry-form h3 {
    margin-bottom: 14px;
    color: var(--accent);
    font-size: 14px;
}

.vitals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.vitals-grid .form-group {
    margin-bottom: 0;
}

.vitals-grid label {
    font-size: 11px;
}

.vitals-grid input {
    padding: 7px 10px;
    font-size: 13px;
}

.vitals-history h3 {
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 14px;
}

.vitals-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.vitals-table th,
.vitals-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.vitals-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
}

.vitals-table tr:hover td {
    background: var(--bg-hover);
}

/* ---- Vital Color Coding ---- */

.vital-normal {
    color: var(--success);
}

.vital-warning {
    color: var(--warning);
    font-weight: 700;
    background: rgba(255,183,77,0.15);
    border-radius: 3px;
    padding: 2px 6px;
}

.vital-abnormal {
    color: #ff1744;
    font-weight: 700;
    background: rgba(255,23,68,0.2);
    border-radius: 3px;
    padding: 2px 6px;
    animation: vital-pulse 2s ease-in-out infinite;
}

@keyframes vital-pulse {
    0%, 100% { background: rgba(255,23,68,0.2); }
    50% { background: rgba(255,23,68,0.35); }
}

/* Vitals alert summary banner */
.vitals-alert-banner {
    background: rgba(255,23,68,0.12);
    border: 1px solid rgba(255,23,68,0.4);
    border-left: 4px solid #ff1744;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text-primary);
}

.vitals-alert-banner strong {
    color: #ff1744;
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
}

.vitals-alert-item {
    padding: 2px 0;
    color: var(--text-secondary);
}

.vitals-alert-item .alert-value {
    color: #ff1744;
    font-weight: 700;
}

.vitals-alert-item .warning-value {
    color: var(--warning);
    font-weight: 600;
}

/* Vitals card list */
.vitals-card-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}

.vital-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    transition: border-color 0.2s;
}

.vital-card:hover {
    border-color: var(--accent);
}

.vital-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.vital-card-date {
    font-weight: 600;
    color: var(--accent);
    font-size: 12px;
}

.vital-card-body {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    font-size: 13px;
}

.vital-card-item {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.vital-card-label {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}

.vital-card-value {
    font-weight: 500;
}

.vital-card-pct {
    font-size: 10px;
    margin-left: 2px;
}

/* No percentile available — greyed "(--)", with the reason on hover, so a
   missing percentile never reads as a normal one. */
.vital-card-pct.vital-pct-none {
    color: var(--text-muted);
    cursor: help;
    border-bottom: 1px dotted var(--text-muted);
}

/* ---- Vitals Charts ---- */

.vitals-charts {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}

.vitals-charts h3 {
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 14px;
}

.chart-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.chart-tab {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg-input);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.chart-tab:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.chart-tab.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.chart-container {
    position: relative;
    height: 250px;
}

/* ---- Appointments ---- */

.appointments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.appt-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 8px;
}

.appt-card-time {
    font-weight: 600;
    color: var(--accent);
    font-size: 13px;
}

.appt-card-detail {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ---- Attachments ---- */

.attachment-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    margin-bottom: 20px;
    transition: border-color 0.2s, background 0.2s;
    color: var(--text-secondary);
    font-size: 13px;
}

.attachment-upload-area.drag-over {
    border-color: var(--accent);
    background: rgba(79,195,247,0.05);
}

.attachment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.attachment-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.attachment-card:hover {
    border-color: var(--accent);
}

/* Unread attachment (WhatsApp-style): green dot + bold name + green edge.
   Set by attachment-unread.js; cleared when the user opens it. */
.attachment-card { position: relative; }
.att-unread-dot { display: none; }
.attachment-card.attachment-unread {
    border-left: 4px solid #25d366;
    background: rgba(37, 211, 102, 0.06);
}
.attachment-card.attachment-unread .att-unread-dot {
    display: block;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #25d366;
    box-shadow: 0 0 0 2px var(--bg-card);
}
.attachment-card.attachment-unread .attachment-name { font-weight: 800; }
.dash-btn { position: relative; }
.dash-unread-badge,
.pt-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #25d366;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}
.dash-unread-badge {
    position: absolute;
    top: -8px;
    right: -6px;
    box-shadow: 0 0 0 2px var(--bg-card);
}
.att-unread-status {
    margin-left: 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    vertical-align: 2px;
}
.att-unread-status.has-unread { color: #25d366; font-weight: 800; }
.att-unread-status-dot {
    display: inline-block; width: 9px; height: 9px; border-radius: 50%;
    background: #25d366; vertical-align: 0;
}
.pt-unread-badge {
    margin-left: 6px;
    vertical-align: 1px;
}

.attachment-icon {
    font-size: 24px;
    min-width: 32px;
    text-align: center;
}

.attachment-info {
    flex: 1;
    min-width: 0;
}

.attachment-name {
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.attachment-actions {
    display: flex;
    gap: 4px;
}

/* ---- Physician Manager ---- */

.physician-list {
    margin-bottom: 20px;
}

.physician-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.physician-item:hover {
    border-color: var(--accent);
}

.physician-item.active-physician {
    border-color: var(--success);
    background: rgba(102,187,106,0.08);
}

.physician-item-info {
    flex: 1;
}

.physician-item-name {
    font-weight: 500;
}

.physician-item-detail {
    font-size: 11px;
    color: var(--text-muted);
}

.physician-item-actions {
    display: flex;
    gap: 6px;
}

.physician-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.physician-form h3 {
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 14px;
}

/* ---- Modals ---- */

.modal[hidden] {
    display: none !important;
}

#confirm-modal {
    z-index: 2000;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Keep modals clear of the notch / iPad home indicator so a bottom action
       button (e.g. Save Prescription) is never hidden under the home bar. */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    box-sizing: border-box;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    max-height: 90dvh;   /* iOS: dvh tracks the VISIBLE viewport (toolbars shown) */
    overflow-y: auto;
    box-shadow: 0 12px 40px var(--shadow);
}

.modal-large {
    max-width: 800px;
}

.modal-fullscreen {
    width: 96%;
    max-width: 1200px;
    max-height: 95vh;
    height: 95vh;
}

.modal-fullscreen img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.modal-fullscreen iframe,
.modal-fullscreen embed,
.modal-fullscreen object {
    width: 100%;
    height: calc(95vh - 70px);
    border: none;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 16px;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 20px;
    max-height: calc(100vh - 100px);
    /* dvh so on iOS the body constrains to the visible height and scrolls
       internally — otherwise a tall form (prescription) runs off the bottom of
       the screen and the Save button can't be reached. Sits inside the 90dvh
       modal-content, leaving room for the header. */
    max-height: calc(90dvh - 56px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    justify-content: flex-end;
}

/* ---- Confirm Modal ---- */

.modal-confirm {
    max-width: 400px;
}

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

/* ---- Scrollbar ---- */

::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        bottom: 0;
        z-index: 500;
        box-shadow: 4px 0 20px var(--shadow);
    }

    .sidebar.collapsed {
        margin-left: calc(-1 * var(--sidebar-width));
    }

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

    .top-bar-right .user-email {
        display: none;
    }

    .tab {
        padding: 10px 12px;
        font-size: 12px;
    }

    .vitals-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .attachment-grid {
        grid-template-columns: 1fr;
    }

    .modal-header-actions {
        gap: 4px;
    }

    .modal-header-actions .btn-small {
        padding: 4px 8px;
        font-size: 11px;
    }

    /* Attachment preview header: lots of buttons (Prev/Next/AI/Translate/
       Copy Text/Print/Share) that on iPhone get pushed off-screen because
       the parent .modal-header is display:flex with no wrap. Allow the
       header to wrap so the action row lands BELOW the title, and shrink
       the buttons + title so a full row fits inside ~390 px. */
    .modal-header {
        flex-wrap: wrap;
        padding: 10px 12px;
        gap: 6px;
    }
    .modal-header h2 {
        font-size: 14px;
        flex: 1 1 auto;
        min-width: 0;
        word-break: break-word;
    }
    .attachment-header-actions {
        flex-basis: 100%;
        flex-wrap: wrap;
        gap: 4px;
        order: 99;
    }
    .attachment-header-actions .btn-small {
        padding: 4px 8px;
        font-size: 11px;
    }

    /* Demographics: wrap save/delete/share buttons */
    .demo-form .form-actions {
        flex-wrap: wrap;
    }

    .modal-body {
        padding: 14px;
    }

    /* Dashboard buttons smaller on mobile */
    .dash-btn {
        min-width: 60px;
        padding: 6px 4px;
    }
    .dash-label { font-size: 11px; }
    .dash-count { font-size: 14px; }
    .pt-name-banner { font-size: 16px; }
    .patient-toolbar { padding: 4px 10px; }
    .patient-dashboard { padding: 6px 10px 4px; }
}

@media (max-width: 480px) {
    .login-card {
        margin: 16px;
        padding: 28px 20px;
    }

    .top-bar {
        padding: 0 10px;
    }

    .physician-badge {
        display: none;
    }

    .tab-panel {
        padding: 14px;
    }

    #backup-btn {
        display: none;
    }

    #global-search-wrapper {
        display: none;
    }

    .dash-link { font-size: 11px; }
}

/* ---- RTL support ---- */

[dir="rtl"] {
    text-align: right;
}

/* ---- Utility ---- */

.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.mt-10 { margin-top: 10px; }
.mb-10 { margin-bottom: 10px; }
.hidden { display: none !important; }

/* ---- Loading spinner ---- */

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ---- Toast notifications ---- */

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: 0 4px 12px var(--shadow);
    animation: toast-in 0.3s ease;
    max-width: 360px;
}

.toast-success { background: var(--success); color: #000; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--accent); color: #000; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Offline Banner ---- */

.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 8px 16px;
    background: var(--warning);
    color: #000;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    z-index: 2000;
    animation: toast-in 0.3s ease;
}

/* ---- Delete button in note cards ---- */

.note-card-actions {
    display: flex;
    align-items: center;
    gap: 18px;
}

.btn-delete-note {
    background: transparent;
    border: 1.5px solid var(--danger, #ef5350);
    color: var(--danger, #ef5350);
    cursor: pointer;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    flex-shrink: 0;
}

.btn-delete-note:hover {
    color: #fff;
    background: var(--danger, #ef5350);
}

.note-card {
    padding-right: 20px;
}

/* ---- References ---- */

.ref-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ref-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.ref-card:hover {
    border-color: var(--accent);
}

.ref-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.ref-card-title {
    font-weight: 600;
    color: var(--accent);
    font-size: 14px;
}

.ref-card-category {
    display: inline-block;
    font-size: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 8px;
    margin-left: 8px;
}

.ref-card-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ref-card-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.ref-card-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-fav {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
}

.btn-fav:hover {
    color: var(--warning);
}

.btn-fav.ref-fav-active {
    color: var(--warning);
}

/* ---- Allergy Banner ---- */
.allergy-banner {
    background: rgba(255,23,68,0.15);
    border: 1px solid rgba(255,23,68,0.4);
    color: #ff1744;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 12px;
}
.allergy-banner::before { content: "\26A0  ALLERGIES: "; }

/* ---- Allergy field: recognised-entry chips + suggestions (allergies.js) ---- */
.allergy-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.allergy-chip { font-size: 12px; padding: 2px 8px; border-radius: 10px; line-height: 1.5; }
.allergy-chip-ok { background: rgba(76,175,80,0.15); color: var(--success, #4caf50); border: 1px solid rgba(76,175,80,0.35); }
.allergy-chip-unknown { background: rgba(255,152,0,0.15); color: var(--warning, #ff9800); border: 1px solid rgba(255,152,0,0.4); }
.allergy-chip-unknown a { color: inherit; font-weight: 600; }
.allergy-chip-none { color: var(--text-muted); }
.allergy-ac { position: absolute; top: 100%; left: 0; right: 0; z-index: 50; margin-top: 2px;
    background: var(--bg-secondary, #1e293b); border: 1px solid var(--border, #334155); border-radius: var(--radius, 6px);
    max-height: 280px; overflow-y: auto; box-shadow: 0 6px 18px rgba(0,0,0,0.35); }
.allergy-ac-item { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; cursor: pointer; font-size: 13px; }
.allergy-ac-item.active, .allergy-ac-item:hover { background: rgba(100,181,246,0.15); }
.allergy-ac-kind { color: var(--text-muted); font-size: 11px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Drug Warnings ---- */
.rx-warnings { margin: 10px 0; }
.rx-warning-item {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    margin-bottom: 6px;
    line-height: 1.4;
}
.rx-warning-high {
    background: rgba(255,23,68,0.15);
    border: 1px solid rgba(255,23,68,0.4);
    color: #ff1744;
}
.rx-warning-high::before { content: "\26D4  "; }
.rx-warning-medium {
    background: rgba(255,152,0,0.15);
    border: 1px solid rgba(255,152,0,0.4);
    color: #ff9800;
}
.rx-warning-medium::before { content: "\26A0  "; }
.rx-warning-low {
    background: rgba(255,235,59,0.1);
    border: 1px solid rgba(255,235,59,0.3);
    color: #fdd835;
}
.rx-warning-low::before { content: "\2139  "; }
.rx-dose-info {
    background: var(--bg-secondary, rgba(127,127,127,0.08));
    border: 1px solid var(--border, rgba(127,127,127,0.3));
    color: var(--text-secondary, inherit);
}
.rx-dose-info::before { content: "\2139  "; }
.rx-warning-ack input[type="checkbox"] { width: auto; flex: 0 0 auto; margin: 0; }
.rx-warning-ack {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #ff1744;
}

/* ---- Prescriptions ---- */

.rx-header {
    /* Stack the H3 above the button row so Print Rx + Signature buttons
       don't get pushed off the right edge on narrow right-panel layouts
       (iPad portrait, split-screen). Buttons inside the button row still
       wrap on a second line if they exceed the available width. */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 16px;
    gap: 8px;
}

.rx-header > h3 {
    margin: 0;
}

.rx-header > div {
    /* the button row */
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.rx-section {
    margin-bottom: 24px;
}

.rx-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.rx-card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rx-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--success);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: border-color 0.2s;
}

.rx-card:hover {
    border-color: var(--accent);
    border-left-color: var(--accent);
}

.rx-card-inactive {
    border-left-color: var(--text-muted);
    opacity: 0.7;
}

.rx-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.rx-card-drug {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
}

.rx-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rx-card-date {
    font-size: 11px;
    color: var(--text-muted);
}

.rx-badge {
    display: inline-block;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    margin-left: 8px;
    vertical-align: middle;
}

.rx-badge-active {
    background: rgba(102,187,106,0.2);
    color: var(--success);
}

.rx-badge-inactive {
    background: rgba(160,160,176,0.15);
    color: var(--text-muted);
}

.rx-card-generic {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.rx-card-details {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 13px;
    margin-bottom: 6px;
}

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

.rx-detail strong {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 11px;
}

.rx-card-instructions {
    font-size: 12px;
    color: var(--warning);
    background: rgba(255,183,77,0.08);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

.rx-card-prescriber {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.rx-card-footer {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* ---- Drug Autocomplete Dropdown ---- */

.drug-autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1100;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 280px;
    overflow-y: auto;
    box-shadow: 0 8px 24px var(--shadow);
}

.drug-autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.drug-autocomplete-item:hover {
    background: var(--bg-hover);
}

.drug-autocomplete-item:last-child {
    border-bottom: none;
}

.drug-ac-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.drug-ac-brand {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.drug-ac-dismiss {
    padding: 10px 14px;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
    color: var(--warning);
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--warning);
    transition: background 0.15s;
}
.drug-ac-dismiss:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.drug-ac-empty {
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.drug-ac-online .drug-ac-name {
    color: var(--accent);
}

/* ---- Browse-by-class category filter ---- */
.rx-class-toggle {
    background: var(--bg-tertiary);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.rx-class-toggle:hover { background: var(--bg-hover); }
.rx-class-toggle.active { background: var(--accent); color: var(--bg-primary); }

.rx-class-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 10px;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 168px;
    overflow-y: auto;
}
.rx-class-chip {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.rx-class-chip:hover { background: var(--bg-hover); border-color: var(--border-light); }
.rx-class-chip.active { background: var(--bg-selected); border-color: var(--accent); }
.rx-class-chip-n {
    display: inline-block;
    margin-left: 4px;
    font-size: 10px;
    color: var(--text-muted);
}
.rx-class-chip.active .rx-class-chip-n { color: var(--accent); }

.drug-ac-tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 600;
    border-radius: 999px;
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 16%, transparent);
    border: 1px solid var(--warning);
    vertical-align: middle;
    white-space: nowrap;
}

.drug-ac-tag-allergen {
    color: var(--danger, #ef4444);
    background: color-mix(in srgb, var(--danger, #ef4444) 16%, transparent);
    border-color: var(--danger, #ef4444);
}

.drug-ac-cat-head {
    padding: 8px 14px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--accent);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}

/* ---- Daily Calendar ---- */

.modal-fullscreen {
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}
.modal-fullscreen .modal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.modal-fullscreen .modal-body {
    flex: 1;
    overflow: hidden;
    padding: 0;
    position: relative;
}

.cal-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}
.cal-nav input[type="date"] {
    width: 160px;
    padding: 5px 10px;
    font-size: 13px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
}

.cal-body {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* Left panel: patient list */
.cal-patient-panel {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
}
.cal-patient-panel-header {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}
.cal-patient-panel-header input {
    width: 100%;
    padding: 7px 10px;
    font-size: 13px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    outline: none;
}
.cal-patient-panel-header input:focus {
    border-color: var(--accent);
}
.cal-patient-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.cal-pl-item {
    padding: 8px 12px;
    cursor: grab;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    user-select: none;
}
.cal-pl-item:hover {
    background: var(--bg-hover);
}
.cal-pl-item:active {
    cursor: grabbing;
}
.cal-pl-selected {
    background: var(--bg-selected) !important;
    border-left: 3px solid var(--accent);
}
.cal-pl-name {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
}
.cal-pl-item { display: flex; align-items: center; gap: 6px; }
.cal-pl-info { flex: 1; min-width: 0; }
/* VIP / Church tag — big right-hand button, iPad tap target. */
.cal-pl-tag {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    margin: -6px -6px -6px 0;
    background: none;
    border: none;
    border-radius: 8px;
    font-size: 26px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}
.cal-pl-tag:hover { background: var(--bg-hover); }
.cal-pl-tag.is-vip { color: #f5b301; }
.cal-pl-tag.is-church { color: #f472b6; }
.cal-tag-menu {
    position: fixed;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 170px;
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px var(--shadow);
}
.cal-tag-menu-title {
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.cal-tag-opt {
    min-height: 44px;
    padding: 0 12px;
    text-align: left;
    font-size: 15px;
    font-weight: 600;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}
.cal-tag-opt-vip { color: #f5b301; }
.cal-tag-opt-church { color: #f472b6; }
.cal-tag-opt.is-current { border-width: 2px; border-color: currentColor; }
/* VIP / Church — calendar only: coloured ring + badge, the block keeps its tier colour. */
.cal-appt-block.cal-appt-vip { box-shadow: inset 0 0 0 2px #f5b301; }
.cal-appt-block.cal-appt-church { box-shadow: inset 0 0 0 2px #f472b6; }
.cal-appt-church-badge {
    display: inline-block;
    background: #f472b6;
    color: #3b0420;
    font-size: 10px;
    font-weight: 800;
    border-radius: 3px;
    padding: 0 4px;
    margin-right: 5px;
    vertical-align: 1px;
}
.cal-appt-vip-badge {
    display: inline-block;
    background: #f5b301;
    color: #1f1600;
    font-size: 10px;
    font-weight: 800;
    border-radius: 3px;
    padding: 0 4px;
    margin-right: 5px;
    vertical-align: 1px;
}
.cal-pl-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* Right panel: calendar grid */
.cal-grid-panel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.cal-grid {
    display: grid;
    grid-template-columns: 72px 1fr 1fr;
    min-height: 100%;
}

/* Two-lane calendar: sticky Clinic | EEG column headers */
.cal-col-head {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-primary);
    background: var(--bg-card, #14233a);
    border-bottom: 1px solid var(--border);
}
.cal-col-head-eeg { color: #c4b5fd; }
.cal-col-head-time { background: var(--bg-card, #14233a); }

/* Category chips on patient-tab appointment cards */
.appt-chip {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 4px;
    vertical-align: middle;
}
.appt-chip-eeg    { background: #4682b4; color: #fff; }
.appt-chip-tele   { background: #0f766e; color: #fff; }
.appt-chip-status { background: #475569; color: #fff; }

/* Clinic-wide registry tables (EEG / Teleconsults) */
.rg-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rg-table th {
    text-align: left;
    font-size: 11px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding: 6px 8px;
}
.rg-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.rg-row { cursor: pointer; }
.rg-row:hover { background: var(--bg-hover, rgba(255,255,255,0.04)); }

.cal-time-label {
    padding: 0 10px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    height: 40px;
    line-height: 40px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    user-select: none;
}
.cal-time-label-hour {
    color: var(--text-secondary);
    font-weight: 600;
}

.cal-slot {
    height: 40px;
    border-bottom: 1px solid var(--border);
    padding: 2px 8px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    display: flex;
    align-items: center;
}
.cal-slot:hover {
    background: var(--bg-hover);
}
.cal-slot-empty {
    cursor: crosshair;
}
.cal-slot-dragover {
    background: rgba(79,195,247,0.15) !important;
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

.cal-appt-block {
    position: absolute;
    left: 4px;
    right: 4px;
    top: 2px;
    background: #1b6b3a;
    border: 1px solid var(--accent);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    cursor: pointer;
    z-index: 10;
    overflow: hidden;
    transition: border-color 0.2s, background 0.2s;
}
.cal-appt-block:hover {
    background: #15522e;
    border-color: var(--accent-hover);
}
.cal-appt-delete {
    position: absolute;
    top: 2px;
    right: 4px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
    z-index: 11;
}
.cal-appt-delete:hover {
    color: #fff;
    background: rgba(0,0,0,0.3);
    border-radius: 3px;
}
.cal-appt-specialist {
    background: #15803d;        /* green — Specialist */
    border-color: #22c55e;
    border-left: 3px solid #22c55e;
}
.cal-appt-specialist:hover {
    background: #166534;
    border-color: #16a34a;
}
.cal-appt-consultant {
    background: #6d28d9;        /* purple — Consultant */
    border-color: #a78bfa;
    border-left: 3px solid #a78bfa;
}
.cal-appt-consultant:hover {
    background: #5b21b6;
    border-color: #7c3aed;
}
.cal-appt-eeg {
    background: #4682b4;        /* steel blue — EEG */
    border-color: #7ba7d0;
    border-left: 3px solid #7ba7d0;
}
.cal-appt-eeg:hover {
    background: #3a6d96;
    border-color: #5b9bd5;
}
.cal-appt-name {
    font-weight: 700;
    font-size: 14px;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-appt-notes {
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.cal-appt-duration {
    font-size: 9px;
    color: var(--text-muted);
}

.cal-now-line {
    position: absolute;
    left: 72px;
    right: 0;
    height: 2px;
    background: var(--danger);
    z-index: 20;
    pointer-events: none;
}
.cal-now-line::before {
    content: '';
    position: absolute;
    left: -5px;
    top: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
}

.cal-appt-popup {
    position: absolute;
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 16px;
    min-width: 220px;
    box-shadow: 0 8px 24px var(--shadow);
}
.cal-popup-header {
    font-weight: 600;
    font-size: 14px;
    color: var(--accent);
    margin-bottom: 4px;
}
.cal-popup-detail {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.toast-action {
    display: inline-block;
    margin-left: 10px;
    padding: 3px 10px;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}
.toast-action:hover {
    background: rgba(255,255,255,0.3);
}

@media (max-width: 768px) {
    .cal-body { flex-direction: column; }
    .cal-patient-panel { width: 100%; height: 160px; border-right: none; border-bottom: 1px solid var(--border); }
    .cal-grid { --cal-time-col: 56px; }
    .cal-time-label { font-size: 10px; padding: 0 6px; }
    .cal-nav input[type="date"] { width: 130px; }
    .cal-now-line { left: 56px; }
}

/* ---- Calendar view toggle (Outpatient / Inpatient) ---- */
.cal-view-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-wrap: wrap;
}
.cal-view-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
}
.cal-view-btn {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.cal-view-btn + .cal-view-btn { border-left: 1px solid var(--border); }
.cal-view-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.cal-view-active { background: var(--accent); color: #000 !important; }
.cal-inpatient-count {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- Inpatient roster panel ---- */
.cal-inpatient-panel {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 16px;
    background: var(--bg-primary);
}
.cal-inpatient-roster {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cal-inpatient-row {
    display: grid;
    grid-template-columns: minmax(180px, 1.3fr) minmax(140px, 1fr) minmax(120px, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: 4px solid #1f4e79;
    border-radius: var(--radius-sm);
}
.cal-inpatient-row.discharged { border-left-color: var(--text-muted); opacity: 0.85; }
.cal-inpatient-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}
/* The roster name opens the record, same action as the Open button. Styled as
   a link so it reads as clickable rather than as plain label text. */
.cal-inpatient-open {
    cursor: pointer;
    border-radius: 3px;
}
.cal-inpatient-open:hover,
.cal-inpatient-open:focus-visible {
    color: var(--accent, #1f4e79);
    text-decoration: underline;
}
.cal-inpatient-open:focus-visible { outline: 2px solid var(--accent, #1f4e79); outline-offset: 2px; }
.cal-inpatient-mrn { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.cal-inpatient-day {
    display: inline-block;
    background: #1f4e79;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}
.cal-inpatient-row.discharged .cal-inpatient-day { background: var(--text-muted); }
.cal-inpatient-dates { font-size: 12px; color: var(--text-secondary); }
.cal-inpatient-reason {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
}
.cal-inpatient-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.cal-inpatient-edit {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid #1f4e79;
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    margin-top: -10px;
}
.cal-inpatient-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
@media (max-width: 768px) {
    .cal-inpatient-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }
}

/* ---- Demographics admission section ---- */
.adm-active-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: rgba(31, 78, 121, 0.18);
    border: 1px solid #1f4e79;
    border-radius: var(--radius-sm);
    flex-wrap: wrap;
}
.adm-active-tag {
    background: #1f4e79;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.5px;
    padding: 3px 10px;
    border-radius: 999px;
    flex-shrink: 0;
}
.adm-active-detail { color: var(--text-secondary); font-size: 13px; }
.adm-past-details {
    margin-top: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}
.adm-past-details summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    user-select: none;
}
.adm-past-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.adm-past-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
}
.adm-past-dates { font-weight: 600; color: var(--text-primary); }
.adm-past-reason { color: var(--text-muted); margin-top: 2px; }
.adm-past-days { color: var(--text-secondary); font-size: 11px; flex-shrink: 0; }

/* ---- EEG Waveform Viewer ---- */

.eeg-viewer-header {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.eeg-nav-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.eeg-time-display {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 100px;
    text-align: center;
}
.eeg-ctrl-group {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    justify-content: center;
    flex-wrap: wrap;
}
.eeg-ctrl-label {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.eeg-select {
    padding: 4px 8px;
    font-size: 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.eeg-sens-btns {
    display: flex;
    align-items: center;
    gap: 4px;
}
.eeg-sens-value {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 70px;
    text-align: center;
}
/* Go-to-time panel (raw-trace window review) */
.eeg-goto-panel {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.eeg-goto-panel[hidden] { display: none; }
.eeg-goto-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.eeg-goto-input {
    width: 96px;
    padding: 6px 8px;
    font-size: 16px; /* ≥16px stops iPad Safari zooming on focus */
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
}
.eeg-goto-montages {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 13px;
    color: var(--text-primary);
}
.eeg-goto-montages label {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 32px; /* finger-sized tap target */
    cursor: pointer;
}
.eeg-goto-montages input { width: 18px; height: 18px; }
.eeg-goto-pages {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}
.eeg-goto-pages-label { font-size: 11px; color: var(--text-muted); }
.eeg-goto-hint { font-size: 12px; color: var(--text-muted); }
a.eeg-time-link {
    color: var(--accent);
    text-decoration: underline dotted;
    font-weight: 600;
    cursor: pointer;
}
.eeg-viewer-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}
.eeg-label-column {
    width: 120px;
    flex-shrink: 0;
    overflow-y: hidden;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
.eeg-channel-label {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#eeg-canvas {
    flex: 1;
    display: block;
    cursor: grab;
}
#eeg-canvas:active {
    cursor: grabbing;
}

/* EEG AI Action Menu */
.eeg-ai-menu {
    position: absolute;
    top: 8px;
    right: 60px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,0.3));
    z-index: 20;
    overflow: hidden;
}
.eeg-ai-menu-item {
    display: block;
    width: 100%;
    padding: 10px 18px;
    text-align: left;
    font-size: 13px;
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}
.eeg-ai-menu-item:hover {
    background: var(--bg-hover, rgba(255,255,255,0.06));
}
.eeg-ai-menu-sep {
    border-top: 1px solid var(--border);
}

/* EEG AI Result Panel */
.eeg-ai-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 50%;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    z-index: 15;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease;
}
.eeg-ai-panel[hidden] { display: none; }
.eeg-ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.eeg-ai-panel-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}
.eeg-ai-panel-actions {
    display: flex;
    gap: 6px;
}
.eeg-ai-result {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.6;
}
.eeg-ai-result pre {
    white-space: pre-wrap;
    font-family: inherit;
    margin: 0;
}
.eeg-ai-question-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.eeg-ai-question-row input {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.eeg-ai-question-row input::placeholder { color: var(--text-muted); }

@media (max-width: 768px) {
    .eeg-label-column { width: 80px; }
    .eeg-channel-label { font-size: 10px; padding: 0 4px; }
    .eeg-ctrl-group { gap: 8px; }
    .eeg-viewer-header { padding: 6px 8px; gap: 8px; }
    .eeg-ai-panel { max-height: 60%; }
    .eeg-ai-menu { right: 12px; }
}

/* ---- Print ---- */

@media print {
    body * { visibility: hidden; }
    .print-content, .print-content * { visibility: visible; }
    .print-content { position: absolute; left: 0; top: 0; }
}

/* Citation chip — rendered by expandCitations() in note preview / print / share */
.citation-chip {
    display: inline-block;
    font-size: 11px;
    padding: 1px 6px;
    margin: 0 1px;
    border-radius: 4px;
    background: rgba(255, 183, 77, 0.14);
    color: #ffb74d;
    border: 1px solid rgba(255, 183, 77, 0.4);
    text-decoration: none;
    cursor: pointer;
    line-height: 1.4;
    white-space: nowrap;
    transition: background 0.12s ease, color 0.12s ease;
}
.citation-chip:hover {
    background: rgba(255, 183, 77, 0.28);
    color: #fff;
    border-color: #ffb74d;
}
.citation-chip:visited { color: #ffb74d; }

/* Arabic → English name auto-transliteration hint (translit.js) */
.translit-hint {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
    font-style: italic;
}

/* Inpatient roster — the reason cell is where the physician enters and edits
   the reason for admission / consult (moved off the secretary's Demographics
   page). Tapping it opens the inline editor focused on that field. */
.cal-inpatient-reason-edit {
    cursor: pointer;
    border-bottom: 1px dashed var(--border);
}
.cal-inpatient-reason-edit:hover,
.cal-inpatient-reason-edit:focus-visible {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.cal-inpatient-reason-add {
    color: var(--text-muted);
    font-style: italic;
}
.cal-inpatient-reason-edit:hover .cal-inpatient-reason-add {
    color: var(--accent);
}
.adm-reason-readonly {
    padding: 7px 0;
    font-size: 13px;
    color: var(--text-primary);
}

/* ICH Score calculator (ich-score.js) */
.ich-row { padding: 9px 0; border-bottom: 1px solid var(--border); }
.ich-row:last-child { border-bottom: none; }
.ich-label { font-weight: 600; font-size: 13px; }
.ich-rule { color: var(--text-muted); font-weight: 400; font-size: 11px; margin-left: 6px; }
.ich-input { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 5px; }
.ich-input input[type="number"] {
    width: 96px; padding: 6px 8px; border: 1px solid var(--border);
    border-radius: 6px; background: var(--bg-primary); color: var(--text-primary);
}
.ich-input input.ich-abc { width: 74px; }
.ich-pts { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--accent); }
.ich-pts.zero { color: var(--text-muted); }
.ich-toggle {
    font-size: 12px; padding: 5px 14px; border: 1px solid var(--border);
    border-radius: 6px; background: var(--bg-primary); color: var(--text-secondary); cursor: pointer;
}
.ich-toggle.on { background: var(--accent); color: #000; font-weight: 700; border-color: var(--accent); }
.ich-auto { font-size: 10px; color: var(--success, #22c55e); }
.ich-missing { font-size: 10px; color: var(--warning, #f59e0b); }
.ich-from { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* ---- Inpatient medication verification ---- */

/* A medication a secretary transcribed and no clinician has confirmed yet.
   Amber, not red: it is not an error, it is simply not yet checked. */
.rx-badge.rx-unverified-badge {
    background: #b45309;
    color: #fff;
    margin-left: 4px;
}

.rx-card-unverified {
    color: #b45309;
    font-weight: 600;
}

.rx-verify-banner {
    border: 1px solid #b45309;
    border-left: 4px solid #b45309;
    background: rgba(180, 83, 9, 0.08);
    border-radius: 6px;
    padding: 8px 12px;
    margin: 10px 0;
    font-size: 12px;
    color: var(--text-primary);
}

.rx-verify-banner-note {
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 4px;
}

/* Medication chip on an inpatient roster row — the ward-round way into the
   same list that lives on the patient's Prescriptions tab. */
.cal-inpatient-meds {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    background: var(--bg-card);
}

.cal-inpatient-meds:hover {
    border-color: var(--accent);
}

.cal-meds-empty {
    color: var(--text-muted);
    font-weight: 500;
}

.cal-meds-pending {
    background: #b45309;
    color: #fff;
    border-radius: 8px;
    padding: 0 6px;
    font-size: 10px;
    font-weight: 700;
}

/* Prescriptions button while the patient is admitted — it opens the inpatient
   medication list, so it is coloured like every other inpatient affordance. */
.dash-btn.dash-inpatient {
    border-color: #b45309;
    box-shadow: inset 3px 0 0 #b45309;
}

.dash-btn.dash-inpatient .dash-label {
    color: #b45309;
    font-weight: 700;
}

/* ---- Inpatient medication table (drug chart) ---- */

.med-table-wrap {
    overflow-x: auto;          /* long drug names must not push the page sideways */
    margin-top: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.med-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.med-table thead th {
    text-align: left;
    font-size: 11px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    white-space: nowrap;
}

.med-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.med-table tbody tr:last-child td {
    border-bottom: none;
}

.med-col-num {
    width: 28px;
    color: var(--text-muted);
    font-weight: 700;
}

.med-drug-name {
    font-weight: 700;
    color: var(--text-primary);
}

.med-drug-brand,
.med-drug-indication,
.med-drug-note {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.med-drug-note {
    color: #b45309;
}

.med-col-dose,
.med-col-freq {
    white-space: nowrap;
}

.med-col-actions {
    text-align: right;
    white-space: nowrap;
}

/* A medication a secretary transcribed and nobody has verified yet. */
.med-table tr.med-row-unverified {
    background: rgba(180, 83, 9, 0.07);
}

.med-table tr.med-row-stopped .med-drug-name {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* Inline entry row — the chart is typed into directly. */
.med-table tr.med-row-entry td {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

.med-table tr.med-row-entry input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-input, var(--bg-card));
    border: 1px solid var(--border);
    border-radius: 5px;
}

.med-table tr.med-row-entry input:focus {
    outline: none;
    border-color: var(--accent);
}

.med-table tr.med-row-entry .med-col-num {
    color: var(--accent);
    font-size: 16px;
    font-weight: 700;
}

.med-table tr.med-row-empty td {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 14px 10px;
}

/* ---- Outpatient calendar: Specialist / Consultant columns ---- */

/* Column headers carry the tier colour used on the appointment blocks, so a
   block and its column are obviously the same thing. */
.cal-col-head-specialist { box-shadow: inset 0 -2px 0 #15803d; }
.cal-col-head-consultant { box-shadow: inset 0 -2px 0 #6d28d9; }

/* seen / total for the column, so the state of the list is readable without
   counting ticks down the day. */
.cal-col-tally {
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 5px;
}

/* The tick. Sits opposite the delete button, large enough to hit on a phone
   during a clinic without zooming. */
.cal-appt-seen {
    position: absolute;
    top: 2px;
    left: 2px;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 1px 3px;
    opacity: 0.85;
}

.cal-appt-seen:hover { opacity: 1; }
.cal-appt-seen.is-seen { opacity: 1; }

/* A patient already seen recedes, so what is LEFT to do is what stands out.
   This applies only to the doctor whose column the patient is in: a patient
   handed on to the other column is NOT struck through, because for that doctor
   the visit has not happened yet. */
.cal-appt-block.cal-appt-seen-block {
    opacity: 0.55;
}

.cal-appt-block.cal-appt-seen-block .cal-appt-name {
    text-decoration: line-through;
}

/* "Already seen by the other doctor in this session." A badge, not a strike:
   the name stays fully readable because this patient is still to be seen. */
.cal-appt-prior {
    display: inline-block;
    background: rgba(255, 255, 255, 0.92);
    color: #15803d;
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    margin-right: 4px;
    vertical-align: 1px;
    letter-spacing: 0.02em;
}


/* ---- Tap to move (iPad) ---- */

/* The move handle. Sits beside the seen tick on the left, leaving the right
   side to the existing check-in and delete buttons. */
.cal-appt-move {
    position: absolute;
    top: 2px;
    left: 20px;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 1px 3px;
    opacity: 0.85;
}

.cal-appt-move:hover { opacity: 1; }

/* The name clears both left-hand buttons. */
.cal-appt-block .cal-appt-name { padding-left: 36px; }

/* The appointment currently picked up. */
.cal-appt-block.cal-appt-picked {
    outline: 2px solid #fff;
    outline-offset: -2px;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

/* While something is held, free slots invite the second tap. */
.cal-grid.cal-placing .cal-slot-empty {
    background: rgba(34, 197, 94, 0.10);
    box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.35);
    cursor: pointer;
}

.cal-grid.cal-placing .cal-slot-empty:hover,
.cal-grid.cal-placing .cal-slot-empty:active {
    background: rgba(34, 197, 94, 0.24);
}

/* What is being moved, and the way out of a half-finished move. */
.cal-pending-bar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 14px;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100% - 24px);
    padding: 9px 14px;
    border-radius: 999px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    font-size: 13px;
    color: var(--text-primary);
}

.cal-pending-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Touch: the controls on an appointment block are finger-sized, and the whole
   block is taller, so a clinic list can be worked through without zooming. */
@media (pointer: coarse) {
    .cal-appt-seen,
    .cal-appt-move,
    .cal-appt-delete,
    .cal-appt-checkin {
        font-size: 17px;
        padding: 5px 7px;
    }
    .cal-appt-move { left: 34px; }
    .cal-appt-checkin { right: 34px !important; }
    .cal-appt-block .cal-appt-name { padding-left: 62px; }
    .cal-pending-bar { font-size: 15px; padding: 12px 18px; }
}

/* ---- Clinic Activity chart ---- */

.ca-chart-wrap {
    margin: 12px 0 6px;
    padding: 10px 12px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
}

.ca-chart-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.ca-chart-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Fixed height: the canvas needs a box to size against, and a chart that
   grows with the data would push the tables off the screen. */
.ca-chart-box {
    position: relative;
    height: 280px;
}

.ca-chart-key {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.5;
}

@media (max-width: 768px) {
    .ca-chart-box { height: 220px; }
    .ca-seg { margin-left: 0; }
}

/* Segmented controls in the Activity dialog — "Show [ … ] per [ … ]" reads as
   a sentence, so the chart's two questions are answered in the order they are
   asked rather than hidden behind dropdowns. */
.ca-seg {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.ca-metric-btn,
.ca-grain-btn {
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    cursor: pointer;
}

.ca-metric-btn:last-child,
.ca-grain-btn:last-child { border-right: none; }
.ca-metric-btn:hover,
.ca-grain-btn:hover { color: var(--text-primary); }

.ca-metric-btn.ca-metric-active,
.ca-grain-btn.ca-grain-active {
    background: var(--accent);
    color: #fff;
}

/* Quick date ranges next to Generate. */
.ca-quick { display: inline-flex; gap: 6px; }

.ca-quick-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    padding: 5px 9px;
    cursor: pointer;
}

.ca-quick-btn:hover { color: var(--text-primary); border-color: var(--accent); }

/* The sentence under the chart carries the meaning, so it is body text, not a
   footnote. */
#ca-chart-summary {
    font-size: 12px;
    color: var(--text-primary);
    line-height: 1.6;
}

/* ---- Narrow screens: the patient's NAME is the point ---- */
/*
 * Two changes collided here. The Specialist / Consultant split turned two
 * calendar columns into three, and finger-sized controls pushed the name 62px
 * to the right to clear them. On a phone a column is about 100px wide, so the
 * name had ~40px left and, being nowrap + overflow:hidden, vanished — the block
 * showed buttons and nothing else.
 *
 * On a narrow screen the buttons move to their own row and the name takes the
 * full width underneath. A tap target that hides the patient's name is not a
 * usable tap target.
 */
@media (max-width: 820px) {
    .cal-appt-seen,
    .cal-appt-move,
    .cal-appt-delete,
    .cal-appt-checkin {
        font-size: 14px;
        padding: 2px 4px;
    }

    .cal-appt-move { left: 24px; }
    .cal-appt-checkin { right: 22px !important; }

    .cal-appt-block .cal-appt-name {
        padding-left: 0;
        padding-top: 15px;        /* clears the button row above */
        font-size: 11px;
        line-height: 1.2;
    }

    /* The sequence number costs a third of the width on a phone; the name is
       worth more than the ordinal. */
    .cal-appt-seq { display: none; }

    /* No room for these beside a name at this width. */
    .cal-appt-notes,
    .cal-appt-duration { display: none; }

    /* Time column narrower so the three lanes get what is left. */
    .cal-grid { --cal-time-col: 44px; }
    .cal-col-head { font-size: 10px; }
}

/* ---- Note option sheet (Diagnosis: same as last visit / revised) ---- */
/*
 * A sheet rather than the usual chip picker: these two options need a line of
 * explanation each — what the previous diagnosis actually says, and that
 * "Revised" clears the field rather than pre-filling it.
 */
.note-option-sheet {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.note-option-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.note-option-panel {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 14px;
    width: min(440px, calc(100vw - 32px));
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.note-option-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.4px;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.note-option-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 11px 13px;
    margin-bottom: 8px;
    cursor: pointer;
    font-family: inherit;
}

.note-option-btn:hover { border-color: var(--accent); }

.note-option-btn.muted { opacity: 0.65; cursor: default; }
.note-option-btn.muted:hover { border-color: var(--border); }

.note-option-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* The previous diagnosis in full — the whole point is seeing what will be
   carried across BEFORE it is written into the note. */
.note-option-detail {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
    line-height: 1.45;
}

.note-option-cancel {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-family: inherit;
    padding: 8px;
    cursor: pointer;
}

.note-option-cancel:hover { color: var(--text-primary); }

/* Activity: a physician filter returning nothing should say why. */
.ca-nomatch {
    border: 1px solid #b45309;
    border-left: 4px solid #b45309;
    background: rgba(180, 83, 9, 0.08);
    border-radius: 6px;
    padding: 10px 12px;
    margin: 8px 0 10px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--text-primary);
}

/* ---- Time per patient (landing page) — from the secretary's clinic clock ----
   Cards echo the column colours so Specialist/Consultant read without a legend. */
.cal-day-summary {
    /* Lives inside .empty-state, which centres its text — the card needs its
       own left-aligned block or the numbers wander. */
    margin: 0 auto 28px;
    padding: 12px 14px;
    max-width: 760px;
    text-align: left;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.cal-day-summary-head {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
    margin-bottom: 10px;
}
.cal-time-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}
.cal-time-card {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
}
.cal-time-card .cal-time-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.cal-time-card .cal-time-value { font-size: 22px; font-weight: 700; line-height: 1.1; color: var(--text-primary); }
.cal-time-card .cal-time-sub   { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.cal-time-spec  { border-left: 3px solid #22c55e; }
.cal-time-cons  { border-left: 3px solid #a78bfa; }
.cal-time-total { border-left: 3px solid var(--accent); }
.cal-day-summary-note,
.cal-day-summary-none { margin-top: 9px; font-size: 10.5px; line-height: 1.5; color: var(--text-muted); }

/* Clinic clock chip on a calendar block. A button for the secretary (iPad —
   a real tap target), plain text for the doctor. Running = unmistakable. */
.cal-clock {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 7px;
    min-height: 20px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    background: rgba(0, 0, 0, 0.25);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
}
button.cal-clock { cursor: pointer; }
.cal-clock.is-running { background: #dc2626; border-color: #dc2626; }
.cal-clock.is-done { background: rgba(255, 255, 255, 0.18); border-color: transparent; font-weight: 600; }
.cal-clock-other { font-size: 10px; opacity: 0.85; margin-left: 3px; }

/* Secretary's clock: a big button filling the right end of the block, full
   height, finger-sized on the iPad — nowhere near the tap area that opens the
   patient. The block's own controls shift left to make room. */
.cal-clock-big {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 72px;
    min-height: 34px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    border: none;
    border-left: 2px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    cursor: pointer;
    z-index: 3;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    font-variant-numeric: tabular-nums;
}
.cal-clock-big-top { font-size: 17px; line-height: 1; }
.cal-clock-big-sub { font-size: 12px; font-weight: 800; letter-spacing: 0.04em; line-height: 1; }
.cal-clock-big.is-idle    { background: #2563eb; }
.cal-clock-big.is-idle:hover { background: #1d4ed8; }
.cal-clock-big.is-running { background: #dc2626; animation: cal-clock-pulse 2s ease-in-out infinite; }
.cal-clock-big.is-done    { background: rgba(0, 0, 0, 0.35); }
@keyframes cal-clock-pulse {
    0%, 100% { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0.0); }
    50%      { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.55); }
}
@media (prefers-reduced-motion: reduce) { .cal-clock-big.is-running { animation: none; } }
/* make room: text stops short of the button; × and 🩺 move left of it */
.cal-appt-block.has-clock { padding-right: 80px; }
.cal-appt-block.has-clock .cal-appt-delete { right: 78px; }
.cal-appt-block.has-clock .cal-appt-checkin { right: 96px !important; }
@media (pointer: coarse) {
    .cal-clock-big { width: 84px; }
    .cal-appt-block.has-clock { padding-right: 92px; }
    .cal-appt-block.has-clock .cal-appt-delete { right: 90px; }
    .cal-appt-block.has-clock .cal-appt-checkin { right: 122px !important; }
}

/* Phone: the clock must not eat the patient's name. A lane is ~115 px wide on
   an iPhone, so the 72–84 px button + its padding left nothing to read — the
   names "disappeared". Here the button shrinks to a thumb-sized square and the
   name keeps the rest. */
@media (max-width: 820px) {
    .cal-clock-big { width: 46px; border-left-width: 1px; }
    .cal-clock-big-top { font-size: 14px; }
    .cal-clock-big-sub { font-size: 10px; }
    .cal-appt-block.has-clock { padding-right: 50px; }
    .cal-appt-block.has-clock .cal-appt-delete { right: 52px; }
    .cal-appt-block.has-clock .cal-appt-checkin { right: 70px !important; }
    /* The name never gives up its last line: it truncates instead. */
    .cal-appt-block.has-clock .cal-appt-name { min-width: 48px; }
}

/* Date fields open a calendar on click — show that they are clickable. */
input[type="date"], input[type="datetime-local"], input[type="month"], input[type="time"] { cursor: pointer; }

/* ---- Pre-Visit Briefing: saved copy + pin beside the note ---- */
#previsit-brief-modal .modal-header { gap: 6px; }
#previsit-brief-modal .modal-header h2 { flex: 1; min-width: 0; }
.pvb-patient { font-weight: 400; font-size: 0.8em; color: var(--text-secondary); }
.pvb-head-btn {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    min-height: 36px;          /* iPad tap target */
    padding: 0 10px;
    cursor: pointer;
}
.pvb-only-pinned, .pvb-tab { display: none; }
.pvb-stamp { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.pvb-stamp-old { color: #f59e0b; font-weight: 600; }
#previsit-brief-modal.pvb-pinned {
    z-index: 1050;             /* above the note editor */
    pointer-events: none;      /* the page behind stays usable */
}
#previsit-brief-modal.pvb-pinned .modal-backdrop,
#previsit-brief-modal.pvb-pinned .pvb-intro,
#previsit-brief-modal.pvb-pinned #pvb-steps { display: none; }
#previsit-brief-modal.pvb-pinned .pvb-only-pinned { display: inline-block; }
#previsit-brief-modal.pvb-pinned .modal-content {
    pointer-events: auto;
    position: fixed;
    top: calc(env(safe-area-inset-top) + 10px);
    bottom: calc(env(safe-area-inset-bottom) + 10px);
    right: calc(env(safe-area-inset-right) + 10px);
    width: min(380px, 38vw);
    max-width: none;
    max-height: none;
    border: 2px solid #0f766e;
}
#previsit-brief-modal.pvb-pinned.pvb-min .modal-content { display: none; }
#previsit-brief-modal.pvb-pinned.pvb-min .pvb-tab {
    display: block;
    pointer-events: auto;
    position: fixed;
    right: calc(env(safe-area-inset-right) + 10px);
    bottom: calc(env(safe-area-inset-bottom) + 70px);
    background: #0f766e;
    color: #fff;
    border: none;
    border-radius: 22px;
    min-height: 44px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 14px var(--shadow);
    cursor: pointer;
}

/* ---- Per-instance switched-off features (config.js features:{}) ----
   app.js adds body.emr-off-<feature> when a feature is set to false. */
body.emr-off-ai .emr-ai,
body.emr-off-ai #note-ai-btn,
body.emr-off-ai #note-save-btn,
body.emr-off-ai #note-protocol-btn,
body.emr-off-ai #note-discharge-ai-btn,
body.emr-off-ai #note-spine-compare-exam-btn,
body.emr-off-ai #note-spine-compare-studies-btn,
body.emr-off-ai #note-stroke-compare-exam-btn,
body.emr-off-ai #note-stroke-compare-studies-btn,
body.emr-off-dictation #note-dictate-btn,
body.emr-off-dictation #note-dictate-lang,
body.emr-off-dictation #note-dictate-pause-btn { display: none !important; }

/* ---- Visit Status card (Demographics, secretary only) ---- */
.vs-card {
    margin: 18px 0 6px;
    padding: 12px 14px 14px;
    border: 2px solid var(--accent);
    border-radius: 14px;
    background: rgba(56, 189, 248, 0.06);
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.35), inset 0 0 10px rgba(56, 189, 248, 0.08);
}
.vs-title {
    font-size: 15px; font-weight: 800; color: var(--accent);
    text-transform: uppercase; letter-spacing: 0.5px;
    padding-bottom: 6px; margin-bottom: 10px; border-bottom: 1px solid var(--border);
}
.vs-label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 5px; color: var(--text-primary); }
.vs-req { color: var(--danger); }
.vs-visit-one { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.vs-select, .vs-input {
    width: 100%; min-height: 44px; padding: 8px 12px; font-size: 16px;
    border-radius: 10px; border: 1.5px solid var(--accent);
    background: var(--bg-input, rgba(15, 23, 42, 0.9)); color: var(--text-primary);
}
.vs-input { margin-top: 8px; }
.vs-toggle-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.vs-check {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    border: 3px solid var(--text-muted); color: var(--text-muted); font-size: 20px; font-weight: 900;
}
.vs-check.is-on { border-color: var(--success); color: var(--success); }
.vs-toggle-text { flex: 1; min-width: 0; }
.vs-toggle-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.vs-toggle-sub { font-size: 13px; color: var(--text-muted); }
.vs-switch {
    flex: 0 0 auto; position: relative; width: 60px; height: 34px; border-radius: 17px;
    border: none; background: #475569; cursor: pointer; transition: background .15s;
}
.vs-switch span {
    position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%;
    background: #fff; transition: left .15s;
}
.vs-switch.is-on { background: #1d8cf8; }
.vs-switch.is-on span { left: 29px; }
.vs-dd { position: relative; }
.vs-dd-btn {
    width: 100%; min-height: 44px; display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; font-size: 16px; text-align: left; cursor: pointer;
    border-radius: 10px; border: 1.5px solid var(--accent);
    background: var(--bg-input, rgba(15, 23, 42, 0.9)); color: var(--text-primary);
}
.vs-dd-btn.is-placeholder { color: var(--text-secondary, #cbd5e1); }
.vs-dd-caret { font-size: 18px; line-height: 1; }
.vs-dd-list {
    margin-top: 4px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
    background: #16213e;
}
.vs-dd-opt {
    display: block; width: 100%; text-align: left; padding: 9px 14px; cursor: pointer;
    background: transparent; border: none; border-bottom: 1px solid var(--border); color: var(--text-primary);
}
.vs-dd-opt:last-child { border-bottom: none; }
.vs-dd-opt.is-sel, .vs-dd-opt:hover { background: rgba(56, 189, 248, 0.14); }
.vs-dd-opt-t { display: block; font-size: 15px; font-weight: 600; }
.vs-dd-opt-d { display: block; font-size: 12.5px; color: var(--text-muted); }
.vs-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.vs-msg { font-size: 13px; color: var(--success); }

/* Cancelled / transferred visit on the calendar */
.cal-appt-block.cal-appt-cancelled { opacity: 0.6; filter: grayscale(0.55); }
.cal-appt-block.cal-appt-cancelled .cal-appt-name { text-decoration: line-through; }
.cal-appt-cxl {
    display: inline-block; margin-top: 2px; padding: 1px 6px; border-radius: 6px;
    font-size: 11px; font-weight: 700; background: rgba(239, 83, 80, 0.9); color: #fff;
}
.cal-popup-cxl { color: var(--danger); font-weight: 700; }
.appt-chip-cxl { background: rgba(239, 83, 80, 0.2); color: var(--danger); border-color: var(--danger); }

/* Demographics locked for a clinic patient (physician, not secretary/admin) */
.demo-locked-note {
    background: rgba(255, 183, 77, 0.12);
    border: 1px solid rgba(255, 183, 77, 0.5);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 6px 0 10px;
    font-size: 12.5px;
    color: var(--text-primary);
}
.demo-form input:disabled, .demo-form select:disabled { opacity: 0.6; cursor: not-allowed; }

/* Specialty packs (packs.js): markup tagged data-pack="<id>" for a pack this
   deployment does not run. !important beats the editor's own show/hide. */
.emr-pack-off { display: none !important; }
