/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --brand-purple: #7d3587;
    --brand-purple-dark: #672b6f;
    --brand-blue: #2a5cb5;
    --brand-blue-dark: #1764be;
    --brand-teal: #16BDCA;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --surface-border: #e8ecf0;
    --text-primary: #1a1f36;
    --text-secondary: #4a5568;
    --text-muted: #8492a6;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.07);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.13);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

body {
    font-family: Calibri, 'Segoe UI', sans-serif;
    background: linear-gradient(140deg, #1a3a6e 0%, #2a5cb5 40%, #7d3587 100%);
    min-height: 100vh;
    padding: 24px 20px;
    color: var(--text-primary);
}

/* ===== LAYOUT ===== */
.container {
    max-width: 1440px;
    margin: 0 auto;
}

/* ===== HEADER ===== */
header {
    background: var(--surface);
    padding: 22px 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    border-left: 5px solid var(--brand-purple);
}

header h1 {
    color: var(--brand-purple);
    font-size: 1.8em;
    margin-bottom: 2px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95em;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    padding: 24px 28px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--surface-border);
}

.card h2 {
    color: var(--text-primary);
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--brand-purple);
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== TWO-COLUMN LAYOUT FOR WIDE SCREENS ===== */
@media (min-width: 1200px) {
    .layout-split {
        display: grid;
        grid-template-columns: 420px 1fr;
        gap: 20px;
        align-items: start;
    }
    .layout-split-equal {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
        align-items: start;
    }
}

/* ===== FORM ELEMENTS ===== */
.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

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

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.88rem;
}

input[type="file"],
input[type="text"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #d1d8e0;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    transition: all 0.2s ease;
    background: #fff;
    color: var(--text-primary);
    font-family: Calibri, 'Segoe UI', sans-serif;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand-purple);
    box-shadow: 0 0 0 3px rgba(125, 53, 135, 0.10);
}

textarea {
    resize: vertical;
    font-family: Calibri, 'Segoe UI', sans-serif;
}

/* ===== SECTION PANELS (inside cards) ===== */
.section-panel {
    padding: 14px 16px;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    border-left: 4px solid var(--brand-purple);
}

.section-panel.green  { border-left-color: #10b981; }
.section-panel.amber  { border-left-color: #f59e0b; }
.section-panel.blue   { border-left-color: var(--brand-blue); }
.section-panel.teal   { border-left-color: var(--brand-teal); }

.section-panel h3 {
    margin: 0 0 10px 0;
    font-size: 11.5px;
    color: var(--brand-purple);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    font-weight: 700;
}

.section-panel.green h3  { color: #059669; }
.section-panel.amber h3  { color: #d97706; }
.section-panel.blue h3   { color: var(--brand-blue); }
.section-panel.teal h3   { color: #0694a2; }

/* ===== NOTE TYPE SELECTOR ===== */
.note-type-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: #f0f4ff;
    border-radius: var(--radius-sm);
}

.note-type-selector label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: white;
    border: 1.5px solid #d1d8e0;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.18s ease;
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 0;
    white-space: nowrap;
}

.note-type-selector label:hover {
    border-color: var(--brand-purple);
    background: #f7f0f8;
    color: var(--brand-purple);
}

.note-type-selector input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.note-type-selector input[type="checkbox"]:checked + label,
.note-type-selector label:has(input[type="checkbox"]:checked) {
    background: var(--brand-purple);
    color: white;
    border-color: var(--brand-purple);
}

/* ===== TABS ===== */
.notes-tabs {
    margin-top: 20px;
}

.tab-buttons {
    display: flex;
    gap: 4px;
    margin-bottom: 0;
    flex-wrap: wrap;
    border-bottom: 2px solid var(--surface-border);
    padding-bottom: 0;
}

.tab-btn {
    padding: 9px 18px;
    background: #f0f2f5;
    border: 1.5px solid #d1d8e0;
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.18s ease;
    color: var(--text-secondary);
    position: relative;
    top: 2px;
}

.tab-btn:hover {
    background: #e4e9f0;
    color: var(--brand-purple);
}

.tab-btn.active {
    background: var(--brand-purple);
    color: white;
    border-color: var(--brand-purple);
}

.tab-btn.error {
    background: #fff1f1;
    border-color: #fca5a5;
    color: #b91c1c;
}

.tab-pane {
    display: none;
    padding: 20px;
    background: #fafbfc;
    border: 1.5px solid var(--surface-border);
    border-radius: 0 var(--radius-md) var(--radius-md) var(--radius-md);
}

.tab-pane h3 {
    color: var(--brand-purple);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--brand-purple);
    font-size: 1rem;
}

.tab-pane .validation-results {
    margin-top: 14px;
    padding: 12px;
    background: #f7fafc;
    border-radius: var(--radius-sm);
    border: 1px solid #e2e8f0;
}

/* ===== PRESCRIPTION / AUTOMATION ===== */
.prescription-block,
.investigations-block,
.radiology-block,
.vitals-block {
    padding: 12px 14px;
    background: #f8fafc;
    border-radius: var(--radius-md);
    border: 1px solid #e2e8f0;
}

.prescription-pad {
    font-family: Calibri, 'Segoe UI', sans-serif;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.prescription-pad-header {
    background: #1e293b;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.4px;
    padding: 11px 16px;
    text-align: center;
}

.prescription-pad-body {
    padding: 14px 18px;
    font-size: 13.5px;
    line-height: 1.5;
    color: #334155;
}

.prescription-section {
    margin-bottom: 12px;
}

.prescription-section strong {
    display: block;
    margin-bottom: 3px;
    font-size: 12.5px;
    color: #475569;
}

.prescription-pad-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    margin-top: 8px;
}

.prescription-pad-table th {
    background: #f1f5f9;
    color: #334155;
    font-weight: 600;
    padding: 9px 11px;
    text-align: left;
    border: 1px solid #e2e8f0;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.prescription-pad-table td {
    padding: 9px 11px;
    border: 1px solid #e2e8f0;
    vertical-align: top;
}

.prescription-pad-table tbody tr:nth-child(even) {
    background: #fafafa;
}

/* ===== MEDICATION TABLES ===== */
.prescription-table,
.medication-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.prescription-table th,
.medication-table th {
    background: var(--brand-purple);
    color: white;
    font-weight: 600;
    padding: 11px 13px;
    text-align: left;
    white-space: nowrap;
    font-size: 12.5px;
}

.prescription-table td,
.medication-table td {
    padding: 10px 13px;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: top;
    font-size: 13px;
}

.prescription-table tbody tr:nth-child(even),
.medication-table tbody tr:nth-child(even) {
    background: #f8fafc;
}

.prescription-table tbody tr:hover,
.medication-table tbody tr:hover {
    background: #f7f0f8;
}

.prescription-table tbody tr:last-child td,
.medication-table tbody tr:last-child td {
    border-bottom: none;
}

.prescription-table-wrapper,
.medication-table-wrapper {
    overflow-x: auto;
    margin: 10px 0;
    border-radius: var(--radius-md);
}

.prescription-in-tab {
    margin-top: 14px;
    padding: 12px;
    background: #f7f0f8;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--brand-purple);
}

.note-edit-textarea {
    font-family: inherit !important;
}

/* ===== VALIDATION ===== */
.validation-summary {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
}

.validation-summary.passed {
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
}

.validation-summary.failed {
    background: #fef2f2;
    border: 1px solid #fca5a5;
}

.validation-summary h4 {
    margin: 0 0 4px 0;
    font-size: 15px;
    color: #1e293b;
}

.validation-summary p {
    margin: 2px 0 0 0;
    font-size: 12.5px;
    color: #4a5568;
    line-height: 1.3;
}

.validation-scores {
    margin-top: 4px;
}

.validation-scores h4 {
    margin: 0 0 4px 0;
    font-size: 12.5px;
    font-weight: 600;
    color: #1e293b;
}

.score-item {
    display: flex;
    align-items: center;
    margin-bottom: 3px;
    gap: 8px;
}

.validator-name {
    font-weight: 600;
    font-size: 12.5px;
    color: #4a5568;
    min-width: 200px;
}

.score-value {
    font-weight: bold;
    font-size: 12.5px;
    color: #1e293b;
    min-width: 45px;
}

.score-bar {
    flex: 1;
    height: 14px;
    background: #e8ecf0;
    border-radius: 7px;
    overflow: hidden;
}

.score-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 7px;
}

.validation-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.validator-card {
    background: var(--surface-alt);
    padding: 14px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--brand-purple);
}

.validator-card.passed {
    border-left-color: #10b981;
    background: #ecfdf5;
}

.validator-card.failed {
    border-left-color: #ef4444;
    background: #fef2f2;
}

.validator-score {
    font-size: 22px;
    font-weight: bold;
    color: var(--brand-purple);
}

.validator-card.passed .validator-score { color: #10b981; }
.validator-card.failed .validator-score { color: #ef4444; }

/* ===== BUTTONS ===== */
.btn {
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.22s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: Calibri, 'Segoe UI', sans-serif;
}

.btn-primary {
    background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-purple) 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(125, 53, 135, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(125, 53, 135, 0.38);
}

.btn-secondary {
    background: #f0f2f5;
    color: var(--text-secondary);
    border: 1.5px solid #d1d8e0;
}

.btn-secondary:hover {
    background: #e4e9f0;
    color: var(--text-primary);
}

.btn-success {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(16, 185, 129, 0.38);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
    width: 100%;
    height: 36px;
    background: #e8ecf0;
    border-radius: 18px;
    margin: 16px 0;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand-blue) 0%, var(--brand-purple) 100%);
    border-radius: 18px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: 700;
    font-size: 13px;
    color: #1a1f36;
    z-index: 1;
}

/* ===== TRANSCRIPT INFO ===== */
.transcript-info {
    background: var(--surface-alt);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    border: 1px solid var(--surface-border);
}

.transcript-info span { color: var(--text-muted); font-size: 13px; }
.transcript-info strong { color: var(--text-primary); }

/* ===== PROGRESS STEPS ===== */
.progress-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin: 16px 0;
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 10px;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    border: 1.5px solid #d1d8e0;
    transition: all 0.25s ease;
    text-align: center;
}

.progress-step.active {
    background: #fffbeb;
    border-color: #f59e0b;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

.progress-step.completed {
    background: #ecfdf5;
    border-color: #34d399;
}

.step-icon {
    font-size: 22px;
    margin-bottom: 6px;
}

.step-label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* ===== NOTE CONTENT ===== */
.note-content {
    background: #fafbfc;
    padding: 20px 24px;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--brand-purple);
    font-family: Calibri, 'Segoe UI', sans-serif;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 13px;
    color: #000;
    border: 1px solid var(--surface-border);
    border-left-width: 4px;
}

/* Incremental / resume text: <em> from *markdown* (see convertMdItalicToEmHtml in app.js) */
.note-content em,
.note-content-in-order em,
.note-editable-wrapper em,
.tab-pane .note-editable-wrapper em,
em.note-incremental {
    font-style: italic;
    font-synthesis: none;
}

/* ===== ERROR & HELPERS ===== */
.error-message {
    padding: 14px 18px;
    background: #fef2f2;
    border: 1.5px solid #fca5a5;
    border-radius: var(--radius-md);
    color: #b91c1c;
    font-weight: 600;
    font-size: 13.5px;
}

.help-text {
    display: block;
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

/* ===== FOOTER ===== */
footer {
    text-align: center;
    color: rgba(255,255,255,0.85);
    padding: 16px;
    margin-top: 24px;
    font-size: 13px;
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.progress-step.active .step-icon {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ===== STREAMING NOTE ===== */
.note-content-streaming {
    font-family: Calibri, 'Segoe UI', sans-serif;
    font-size: 12px;
    line-height: 1;
    color: #000;
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 100px;
    padding: 16px 20px;
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--surface-border);
}

.note-content-streaming.streaming::after {
    content: '|';
    animation: blink 1s infinite;
    color: var(--brand-purple);
    font-weight: bold;
    margin-left: 2px;
}

.note-content {
    font-family: Calibri, 'Segoe UI', sans-serif;
    font-size: 12px;
    line-height: 1;
    color: #000;
    white-space: pre-wrap;
    word-wrap: break-word;
    padding: 16px 20px;
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--surface-border);
    transition: all 0.3s ease;
}

#streamingNote {
    padding: 16px 20px;
}

.note-content .note-editable-wrapper,
.note-content-in-order,
#streamingNote .note-editable-wrapper,
.tab-pane .note-editable-wrapper {
    font-family: Calibri, 'Segoe UI', sans-serif;
    font-size: 12px;
    line-height: 1;
    color: #000;
}

.note-content .note-doc-title,
.note-content-in-order .note-doc-title,
#streamingNote .note-doc-title,
.note-content h1.note-doc-title,
.note-content-in-order h1.note-doc-title {
    font-size: 17px;
    font-weight: 700;
    color: #000;
    margin: 0 0 0.5em 0;
    padding-bottom: 0;
    letter-spacing: 0.4px;
}

.note-content .note-section-header,
.note-content-in-order .note-section-header,
#streamingNote .note-section-header,
.tab-pane .note-section-header {
    font-size: 13.5px;
    font-weight: 700;
    color: #000;
    display: block;
    padding-bottom: 0;
    margin: 0.2em 0;
    border-bottom: none;
    letter-spacing: 0.2px;
}

.note-content p:has(.note-section-header),
.note-content-in-order p:has(.note-section-header),
#streamingNote p:has(.note-section-header),
.tab-pane p:has(.note-section-header) {
    margin-bottom: 0.2em;
}

.note-content .note-section-header:first-of-type,
.note-content-in-order .note-section-header:first-of-type,
#streamingNote .note-section-header:first-of-type {
    margin-top: 0;
}

.note-content .note-editable-wrapper strong,
.note-content-in-order strong,
#streamingNote strong,
.tab-pane .note-editable-wrapper strong {
    font-weight: 700;
    color: #000;
}

.note-content .note-editable-wrapper p strong,
.note-content-in-order p strong,
#streamingNote p strong {
    font-size: 13.5px;
}

.note-content .note-editable-wrapper p,
.note-content-in-order p,
#streamingNote p,
.tab-pane .note-editable-wrapper p {
    margin: 0 0 0.5em 0;
    font-size: 12px;
    line-height: 1;
    font-weight: 400;
}

.note-content .note-editable-wrapper ul,
.note-content-in-order ul,
#streamingNote ul,
.tab-pane .note-editable-wrapper ul {
    margin: 0 0 0.2em 0;
    padding-left: 16px;
}

.note-content .note-editable-wrapper li,
.note-content-in-order li,
#streamingNote li,
.tab-pane .note-editable-wrapper li {
    margin: 0 0 0.2em 0;
    font-size: 12px;
    line-height: 1;
    font-weight: 400;
}

.note-content .note-editable-wrapper hr,
.note-content-in-order hr,
#streamingNote hr,
.tab-pane .note-editable-wrapper hr {
    margin: 0.5em 0;
    border: none;
    height: 0;
    visibility: hidden;
}

/* ===== STREAMING BADGE ===== */
.streaming-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--brand-purple);
    color: white;
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
    margin-left: 10px;
    animation: pulse 2s ease-in-out infinite;
}

.streaming-badge::before {
    content: '●';
    animation: pulse 1s ease-in-out infinite;
}

.note-content-streaming strong,
.note-content-streaming .note-section-header {
    font-weight: 700;
    font-size: 14px;
    color: #000;
}

.note-content-streaming p {
    margin: 0 0 8px 0;
    font-size: 13.5px;
    line-height: 1.5;
}

.note-content-streaming ul,
.note-content-streaming ol {
    margin: 0 0 18px 0;
    padding-left: 22px;
}

.note-content-streaming li {
    margin: 0 0 4px 0;
    font-size: 13.5px;
    line-height: 1.5;
}

/* ===== TABLES IN NOTE CONTENT ===== */
.note-content-streaming table,
.note-editable-wrapper table,
.prescription-in-tab table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    margin: 10px 0;
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.note-content-streaming th,
.note-editable-wrapper th,
.prescription-in-tab th {
    background: var(--brand-purple);
    color: white;
    font-weight: 600;
    padding: 10px 13px;
    text-align: left;
}

.note-content-streaming td,
.note-editable-wrapper td,
.prescription-in-tab td {
    padding: 10px 13px;
    border: 1px solid #e2e8f0;
}

.note-content-streaming tbody tr:nth-child(even),
.note-editable-wrapper tbody tr:nth-child(even),
.prescription-in-tab tbody tr:nth-child(even) {
    background: #f8fafc;
}

.note-content-streaming tbody tr:hover,
.note-editable-wrapper tbody tr:hover,
.prescription-in-tab tbody tr:hover {
    background: #f7f0f8;
}

.note-content-streaming * {
    animation: fadeIn 0.2s ease-in;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    body { padding: 12px; }
    header { padding: 16px 18px; }
    header h1 { font-size: 1.4em; }
    .card { padding: 16px 18px; }
    .note-content-streaming { font-size: 13px; padding: 12px; }
    .progress-steps { grid-template-columns: repeat(3, 1fr); }
}
