/* ── Emergencia PWA — Clinical Futurism Design System ─────────────────────── */
/* Dark surgical HUD with luminous accents — forked from Visita PWA           */
/* Adapted for emergency medicine: urgency-coded cards, triage prominence     */

/* ── Fonts ───────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Syne:wght@600;700;800&display=swap');

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

:root {
    /* ── Core palette ── */
    --bg-deep:        #060a14;
    --bg-base:        #0a0e1a;
    --bg-surface:     #111827;
    --bg-elevated:    #1a2236;
    --bg-glass:       rgba(17, 24, 39, 0.72);

    /* ── Accent: clinical cyan ── */
    --accent:         #00e5ff;
    --accent-dim:     rgba(0, 229, 255, 0.15);
    --accent-glow:    rgba(0, 229, 255, 0.35);
    --accent-border:  rgba(0, 229, 255, 0.25);

    /* ── Triage palette ── */
    --triage-atencao:       #ff1744;
    --triage-atencao-dim:   rgba(255, 23, 68, 0.15);
    --triage-atencao-glow:  rgba(255, 23, 68, 0.35);
    --triage-retaguarda:    #ff9100;
    --triage-retaguarda-dim: rgba(255, 145, 0, 0.15);
    --triage-manter:        #2979ff;
    --triage-manter-dim:    rgba(41, 121, 255, 0.15);
    --triage-alta:          #00e676;
    --triage-alta-dim:      rgba(0, 230, 118, 0.15);

    /* ── Semantic ── */
    --success:        #00e676;
    --success-dim:    rgba(0, 230, 118, 0.12);
    --warning:        #ffab40;
    --warning-dim:    rgba(255, 171, 64, 0.12);
    --error:          #ff5252;
    --error-dim:      rgba(255, 82, 82, 0.12);

    /* ── Text ── */
    --text-primary:   #e8ecf4;
    --text-secondary: #7b8794;
    --text-muted:     #4a5568;

    /* ── Structure ── */
    --border:         rgba(255, 255, 255, 0.06);
    --border-accent:  rgba(0, 229, 255, 0.12);
    --divider:        rgba(255, 255, 255, 0.04);

    /* ── Elevation ── */
    --shadow-sm:      0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md:      0 4px 12px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg:      0 12px 40px rgba(0,0,0,0.6), 0 4px 12px rgba(0,0,0,0.4);
    --shadow-glow:    0 0 20px rgba(0, 229, 255, 0.15), 0 0 60px rgba(0, 229, 255, 0.05);

    /* ── Radius ── */
    --radius-sm:      6px;
    --radius-md:      10px;
    --radius-lg:      16px;
    --radius-xl:      20px;

    /* ── Motion ── */
    --ease-out:       cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring:    cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition:     0.2s var(--ease-out);
    --transition-slow: 0.4s var(--ease-out);

    /* ── Safe areas ── */
    --safe-top:       env(safe-area-inset-top, 0px);
    --safe-bottom:    env(safe-area-inset-bottom, 0px);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(80px + var(--safe-bottom));
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Subtle scan-line texture overlay ────────────────────────────────────── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10000;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 229, 255, 0.008) 2px,
        rgba(0, 229, 255, 0.008) 4px
    );
}

[hidden] { display: none !important; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
    position: sticky;
    top: 0;
    height: 56px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    padding-top: var(--safe-top);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-title {
    font-family: 'Syne', sans-serif;
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.header-title span {
    color: var(--accent);
}

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

/* ── Context toggle ──────────────────────────────────────────────────────── */
.ctx-toggle {
    display: flex;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    padding: 2px;
    gap: 2px;
}

.ctx-btn {
    padding: 5px 14px;
    border: none;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.ctx-btn.active {
    background: var(--accent);
    color: var(--bg-deep);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.25);
}

.ctx-btn:not(.active):hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.04);
}

/* ── Doctor identity bar ─────────────────────────────────────────────────── */
.doctor-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.doctor-photo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid var(--accent-border);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.1);
}

.doctor-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-settings {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: color var(--transition);
}

.btn-settings:hover { color: var(--accent); }

/* ── Auth section ─────────────────────────────────────────────────────────── */
.auth-section {
    min-height: calc(100vh - 56px);
    min-height: calc(100dvh - 56px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 229, 255, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(0, 229, 255, 0.04), transparent);
}

.auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-glow);
    padding: 48px 36px;
    text-align: center;
    max-width: 380px;
    width: 100%;
    position: relative;
    overflow: hidden;
    animation: fadeInUp 0.6s var(--ease-out) both;
}

.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    border-radius: 1px;
}

.auth-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: 0 0 30px rgba(0, 229, 255, 0.15);
}

.auth-title {
    font-family: 'Syne', sans-serif;
    font-size: 26px;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.5;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 28px;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    transition: all var(--transition);
    cursor: pointer;
}

.btn-google:hover, .btn-google:focus {
    border-color: var(--accent-border);
    box-shadow: var(--shadow-glow);
    background: rgba(0, 229, 255, 0.05);
    outline: none;
}

.btn-google:active { transform: scale(0.98); }

.google-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* ── Main area ────────────────────────────────────────────────────────────── */
.main-area {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 0 16px 0;
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 8px;
    gap: 8px;
}

.patient-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 64px 24px;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-text {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-hint {
    font-size: 14px;
    color: var(--text-muted);
}

/* ── Patient list ────────────────────────────────────────────────────────── */
.patient-list {
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── Patient row (tappable) ──────────────────────────────────────────────── */
.patient-row {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    animation: fadeInUp 0.4s var(--ease-out) both;
    -webkit-tap-highlight-color: transparent;
}

.patient-row:hover, .patient-row:active {
    border-color: var(--accent-border);
    background: var(--bg-elevated);
}

/* Triage-coded row accents */
.patient-row[data-flag="ATENCAO"] {
    border-left: 3px solid var(--triage-atencao);
}
.patient-row[data-flag="CANDIDATO RETAGUARDA"] {
    border-left: 3px solid var(--triage-retaguarda);
}
.patient-row[data-flag="MANTER"] {
    border-left: 3px solid var(--triage-manter);
}
.patient-row[data-flag="ALTA HOJE"] {
    border-left: 3px solid var(--triage-alta);
}

.row-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.row-nome {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
    letter-spacing: 0.2px;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-leito {
    flex-shrink: 0;
    font-family: 'DM Sans', monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    text-transform: uppercase;
}

.row-footer {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Triage flag badges ──────────────────────────────────────────────────── */
.card-flag {
    font-family: 'DM Sans', sans-serif;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.flag-atencao {
    background: var(--triage-atencao-dim);
    color: var(--triage-atencao);
    border: 1px solid rgba(255, 23, 68, 0.3);
    box-shadow: 0 0 8px var(--triage-atencao-dim);
    animation: pulse-flag 2s ease-in-out infinite;
}

.flag-retaguarda {
    background: var(--triage-retaguarda-dim);
    color: var(--triage-retaguarda);
    border: 1px solid rgba(255, 145, 0, 0.3);
}

.flag-manter {
    background: var(--triage-manter-dim);
    color: var(--triage-manter);
    border: 1px solid rgba(41, 121, 255, 0.3);
}

.flag-alta {
    background: var(--triage-alta-dim);
    color: var(--triage-alta);
    border: 1px solid rgba(0, 230, 118, 0.3);
}

.flag-none {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

@keyframes pulse-flag {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.card-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.card-contexto {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

/* ── Status badge ────────────────────────────────────────────────────────── */
.card-status {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}

.status-em_atendimento {
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid var(--accent-border);
}

.status-evolucao_gerada {
    color: var(--success);
    background: var(--success-dim);
    border: 1px solid rgba(0, 230, 118, 0.3);
}

/* ── Patient detail view (D-31) ──────────────────────────────────────────── */
.detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.btn-back {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

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

.detail-nome {
    font-weight: 700;
    font-size: 16px;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.detail-leito {
    font-family: 'DM Sans', monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent-border);
    text-transform: uppercase;
}

.detail-leito:empty { display: none; }

.detail-flag {
    font-size: 10px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.detail-flag:empty { display: none; }

/* ── Collect textarea (D-24) ─────────────────────────────────────────────── */
.collect-textarea {
    width: 100%;
    min-height: 120px;
    padding: 14px 16px;
    margin: 12px 0 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: 'DM Sans', sans-serif;
    font-size: 16px;
    color: var(--text-primary);
    line-height: 1.5;
    resize: vertical;
    transition: border-color var(--transition);
    box-sizing: border-box;
}

.collect-textarea:focus {
    outline: none;
    border-color: var(--accent-border);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.1);
}

.collect-textarea::placeholder {
    color: var(--text-muted);
}

/* ── Collect action buttons (D-23) ───────────────────────────────────────── */
.collect-actions {
    display: flex;
    gap: 8px;
    padding: 12px 0;
}

.collect-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 48px;
    padding: 10px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.collect-btn:hover, .collect-btn:active {
    border-color: var(--accent-border);
    background: var(--bg-elevated);
}

.collect-btn.recording {
    border-color: var(--triage-atencao);
    background: var(--triage-atencao-dim);
    color: var(--triage-atencao);
}

.collect-icon {
    font-size: 18px;
    line-height: 1;
}

/* ── Recording indicator ─────────────────────────────────────────────────── */
.recording-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--triage-atencao-dim);
    border: 1px solid rgba(255, 23, 68, 0.3);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.rec-dot {
    width: 10px;
    height: 10px;
    background: var(--triage-atencao);
    border-radius: 50%;
    animation: pulse-flag 1s ease-in-out infinite;
    flex-shrink: 0;
}

#rec-timer {
    font-family: 'DM Sans', monospace;
    font-size: 18px;
    font-weight: 700;
    color: var(--triage-atencao);
    flex: 1;
    letter-spacing: 1px;
}

.btn-stop {
    background: var(--triage-atencao);
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 700;
    -webkit-tap-highlight-color: transparent;
}

/* ── Confirm continue dialog ─────────────────────────────────────────────── */
.confirm-continue {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--warning-dim);
    border: 1px solid rgba(255, 171, 64, 0.3);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--warning);
}

.confirm-continue span { flex: 1; }

.btn-confirm-yes {
    background: var(--success);
    color: var(--bg-deep);
    border: none;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 700;
}

.btn-confirm-no {
    background: transparent;
    color: var(--warning);
    border: 1px solid rgba(255, 171, 64, 0.3);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
}

/* ── Media counters (D-25) ───────────────────────────────────────────────── */
.media-counters {
    font-size: 14px;
    color: var(--text-secondary);
    padding: 4px 0 8px;
    letter-spacing: 0.5px;
    min-height: 20px;
}

/* ── Evolution area ──────────────────────────────────────────────────────── */
.evolution-header {
    font-family: 'Syne', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 12px 0 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ── Media file list ──────────────────────────────────────────────────── */
.media-file-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
}
.media-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    font-size: 13px;
}
.mf-label {
    flex: 1;
    font-weight: 500;
}
.mf-status {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
}
.mf-sent { color: #2ecc71; background: rgba(46,204,113,0.15); }
.mf-pending { color: #95a5a6; background: rgba(149,165,166,0.15); }
.mf-uploading { color: var(--accent); background: rgba(0,200,200,0.15); }
.mf-error { color: #e74c3c; background: rgba(231,76,60,0.15); }
.mf-corrupted { color: #e67e22; background: rgba(230,126,34,0.15); }
.mf-action {
    font-size: 12px;
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
}
.mf-action:hover { background: var(--bg-elevated); border-color: var(--accent); }
.mf-action:disabled { opacity: 0.5; cursor: not-allowed; }

.evolution-text {
    font-family: 'DM Sans', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    white-space: pre-wrap;
    word-wrap: break-word;
    user-select: text;
    -webkit-user-select: text;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0;
}

.evolution-editor {
    width: 100%;
    min-height: 150px;
    max-height: 60vh;
    font-family: 'DM Sans', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    white-space: pre-wrap;
    word-wrap: break-word;
    resize: vertical;
    overflow-y: auto;
    margin: 0;
    box-sizing: border-box;
}

/* ── Generate/Complement buttons (D-18, D-19) ────────────────────────────── */
.generate-actions {
    padding: 12px 0 16px;
}

.btn-generate {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--accent), #00b8d4);
    color: var(--bg-deep);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.3px;
    transition: all var(--transition);
    box-shadow: 0 4px 16px rgba(0, 229, 255, 0.25);
    -webkit-tap-highlight-color: transparent;
}

.btn-generate:hover {
    box-shadow: 0 6px 24px rgba(0, 229, 255, 0.4);
    transform: translateY(-1px);
}

.btn-generate:active { transform: scale(0.98); }

.btn-generate:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-complement {
    width: 100%;
    padding: 12px 24px;
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 600;
    transition: all var(--transition);
    margin-top: 8px;
    -webkit-tap-highlight-color: transparent;
}

.btn-complement:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
}

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

/* ── Detail view padding ─────────────────────────────────────────────────── */
#patient-detail-view {
    padding: 0 12px;
}

#patient-detail-view .detail-header {
    margin: 0 -12px;
}

/* ── FAB — Adicionar paciente ────────────────────────────────────────────── */
.fab {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    right: 24px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #00b8d4);
    color: var(--bg-deep);
    border: none;
    box-shadow: 0 4px 16px rgba(0, 229, 255, 0.35), 0 0 40px rgba(0, 229, 255, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    line-height: 1;
    transition: all var(--transition);
    z-index: 200;
    -webkit-tap-highlight-color: transparent;
}

.fab:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 24px rgba(0, 229, 255, 0.45), 0 0 60px rgba(0, 229, 255, 0.2);
}

.fab:active { transform: scale(0.93); }

.fab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: 300;
    margin-top: -1px;
}

/* ── New patient modal ───────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 500;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
    animation: fadeIn 0.2s var(--ease-out);
}

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-xl);
    padding: 28px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: slideUp 0.3s var(--ease-spring);
}

.modal-card h2 {
    font-family: 'Syne', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.form-field {
    margin-bottom: 14px;
}

.form-field label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
}

.form-field input,
.form-field textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color var(--transition);
}

.form-field input:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--accent-border);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.1);
}

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

.form-field textarea {
    min-height: 70px;
    resize: vertical;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    justify-content: flex-end;
}

/* ── Shared button variants ──────────────────────────────────────────────── */
.btn-primary {
    background: var(--accent);
    color: var(--bg-deep);
    border: none;
    padding: 10px 22px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.3px;
    transition: all var(--transition);
}

.btn-primary:hover {
    box-shadow: 0 0 16px rgba(0, 229, 255, 0.3);
    transform: translateY(-1px);
}

.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 10px 22px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
}

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

/* ── Settings dialog ─────────────────────────────────────────────────────── */
.settings-dialog {
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 400px;
    width: 90%;
    background: var(--bg-surface);
    color: var(--text-primary);
}

.settings-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.settings-dialog h2 {
    font-family: 'Syne', sans-serif;
    margin: 0 0 14px;
    font-size: 18px;
    font-weight: 700;
}

.settings-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0 1rem;
}

.btn-logout-full {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(255, 82, 82, 0.3);
    color: var(--error);
    border-radius: var(--radius-md);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-logout-full:hover {
    background: var(--error-dim);
    border-color: rgba(255, 82, 82, 0.5);
}

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

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

/* Stagger patient cards */
.patient-card:nth-child(1) { animation-delay: 0ms; }
.patient-card:nth-child(2) { animation-delay: 60ms; }
.patient-card:nth-child(3) { animation-delay: 120ms; }
.patient-card:nth-child(4) { animation-delay: 180ms; }
.patient-card:nth-child(5) { animation-delay: 240ms; }
.patient-card:nth-child(6) { animation-delay: 300ms; }

/* ── Tablet / Desktop ────────────────────────────────────────────────────── */
@media (min-width: 768px) {
    .main-area {
        max-width: 800px;
        padding-top: 8px;
    }

    .patient-list {
        padding: 0;
    }

    .toolbar {
        padding: 16px 0 8px;
    }

    .fab {
        right: 32px;
        bottom: 32px;
        width: 62px;
        height: 62px;
    }

    .doctor-bar {
        padding: 10px 24px;
    }

    .doctor-photo {
        width: 38px;
        height: 38px;
    }

    .modal-overlay {
        align-items: center;
    }

    .collect-textarea {
        min-height: 150px;
    }

    .evolution-text {
        font-size: 14px;
    }
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}

/* ============================================================
   PHASE 8 — Mobile defaults: hide desktop-only elements
   ============================================================ */
.sidebar { display: none; }
.divider-horizontal { display: none; }
#btn-sidebar-toggle { display: none; }
#btn-sidebar-collapse { display: none; }
#btn-plantao-end { display: none; }
#btn-handoff { display: none; }
.pending-badge { display: none; }
.save-indicator { display: none; }
.conflict-banner { display: none; }
.save-error-banner { display: none; }

/* ============================================================
   PHASE 8 — Desktop layout (>= 1024px)
   Sidebar colapsavel + split horizontal coleta/evolucao
   ============================================================ */
@media (min-width: 1024px) {
    .sidebar { display: block; }
    .divider-horizontal { display: block; }
    #btn-sidebar-toggle { display: inline-flex; }
    #btn-sidebar-collapse { display: inline-flex; }
    #btn-plantao-end { display: inline-block; }
    #btn-handoff { display: inline-block; }
    .pending-badge { display: inline-flex; }
    .save-indicator { display: block; }
    .conflict-banner { display: flex; }
    .save-error-banner { display: flex; }
    body { padding-bottom: 0; }
    .main-area { max-width: 100%; padding: 0; }

    /* Layout geral: sidebar + area principal */
    .desktop-layout {
        display: grid;
        grid-template-columns: 280px 1fr;
        height: calc(100vh - var(--header-h, 56px));
        gap: 0;
    }
    .desktop-layout.sidebar-collapsed {
        grid-template-columns: 0 1fr;
    }

    /* Sidebar */
    .sidebar {
        background: var(--bg-surface);
        border-right: 1px solid var(--border);
        overflow-y: auto;
        overflow-x: hidden;
        transition: width 180ms ease;
    }
    .sidebar-collapsed .sidebar { width: 0; border-right: none; }

    .sidebar-header {
        padding: 12px 16px;
        font-weight: 600;
        border-bottom: 1px solid var(--border);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .sidebar-patient {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border);
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    .sidebar-patient:hover { background: var(--bg-elevated); }
    .sidebar-patient.active { background: var(--bg-elevated); border-left: 3px solid var(--accent); }
    .sidebar-patient .dot {
        width: 8px; height: 8px; border-radius: 50%;
        background: var(--border);
        flex-shrink: 0;
    }
    .sidebar-patient .dot.yellow { background: #e0b900; }
    .sidebar-patient .dot.red { background: #d94141; }

    /* Painel principal split horizontal */
    .split-panel {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
    }
    .split-top {
        overflow-y: auto;
        padding: 16px;
        min-height: 120px;
    }
    .split-bottom {
        flex: 1 1 auto;
        overflow-y: auto;
        padding: 16px;
        min-height: 120px;
        border-top: 1px solid var(--border);
        display: flex;
        flex-direction: column;
    }
    .divider-horizontal {
        height: 6px;
        background: var(--border);
        cursor: row-resize;
        flex-shrink: 0;
        transition: background 120ms;
    }
    .divider-horizontal:hover, .divider-horizontal.dragging { background: var(--accent); }

    /* Textarea editavel da evolucao */
    .evolution-editor {
        flex: 1 1 auto;
        width: 100%;
        min-height: 200px;
        font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
        font-size: 14px;
        line-height: 1.5;
        padding: 12px;
        border: 1px solid var(--border);
        border-radius: 6px;
        background: var(--bg-surface);
        color: var(--fg);
        resize: none;
    }
    .save-indicator {
        font-size: 12px;
        color: #888;
        padding: 4px 0;
        min-height: 18px;
    }
    .save-indicator.saving { color: #e0b900; }
    .save-indicator.saved { color: #3bb273; }
    .save-indicator.error { color: #d94141; }

    /* Banner de conflito (novos dados no celular) */
    .conflict-banner {
        background: #fff6d6;
        color: #574300;
        border: 1px solid #e0b900;
        padding: 10px 14px;
        border-radius: 6px;
        margin-bottom: 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .conflict-banner button {
        background: #e0b900;
        color: #000;
        border: none;
        padding: 6px 12px;
        border-radius: 4px;
        cursor: pointer;
        font-weight: 600;
    }

    /* Banner fallback localStorage (save falhou) */
    .save-error-banner {
        background: #ffe6e6;
        color: #701414;
        border: 1px solid #d94141;
        padding: 10px 14px;
        border-radius: 6px;
        margin-bottom: 12px;
    }

    /* Header buttons de plantao */
    .header-right .btn-plantao {
        margin-left: 8px;
        padding: 6px 12px;
        border-radius: 4px;
        border: 1px solid var(--border);
        background: var(--bg-surface);
        cursor: pointer;
        color: var(--fg);
        font-size: 14px;
    }
    .header-right .btn-plantao-start { background: var(--accent); color: white; border-color: var(--accent); }
    .header-right .btn-plantao-end { background: #d94141; color: white; border-color: #d94141; }

    /* Hamburger button */
    #btn-sidebar-toggle {
        margin-right: 8px;
        padding: 6px 10px;
        border-radius: 4px;
        border: 1px solid var(--border);
        background: var(--bg-surface);
        color: var(--fg);
        cursor: pointer;
        font-size: 16px;
    }

    /* Evolution actions row */
    .evolution-actions {
        display: flex;
        gap: 8px;
        margin-top: 8px;
        flex-wrap: wrap;
    }
    .evolution-actions button {
        padding: 6px 14px;
        border-radius: 4px;
        border: 1px solid var(--border);
        background: var(--bg-surface);
        color: var(--fg);
        cursor: pointer;
        font-size: 13px;
    }
    .evolution-actions button:hover { background: var(--bg-elevated); }

    /* Pending badge */
    .pending-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 20px;
        height: 20px;
        border-radius: 10px;
        background: #e0b900;
        color: #000;
        font-size: 11px;
        font-weight: 700;
        padding: 0 5px;
        margin-left: 4px;
    }
}

/* Toast "Copiado!" — fora do @media, funciona em mobile e desktop */
.toast-copied {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #3bb273;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: toast-fadein 200ms;
}
.toast-copied.fading { animation: toast-fadeout 300ms forwards; }
@keyframes toast-fadein { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toast-fadeout { to { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ── Plan 04: Pending badge colors (global — badge is always in header) ── */
.pending-badge.green { background: #3bb273; color: #fff; }
.pending-badge.yellow { background: #e0b900; color: #000; }
.pending-badge.red { background: #d94141; color: #fff; }

/* ── Plan 04: I-PASS handoff modal ───────────────────────────────────── */
.handoff-modal:not([open]) { display: none; }
.handoff-modal[open] {
    width: min(700px, 94vw);
    max-height: 85vh;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-surface);
    color: var(--fg);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.handoff-modal::backdrop { background: rgba(0,0,0,0.55); }
.handoff-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
}
.handoff-header h2 { margin: 0; font-size: 17px; }
.handoff-header button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.handoff-header button:hover { background: var(--bg-elevated); }
.handoff-warning {
    background: #fff6d6;
    color: #574300;
    border-bottom: 1px solid #e0b900;
    padding: 10px 20px;
    font-size: 13px;
}
.handoff-text {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    margin: 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--bg-base);
}
.handoff-actions {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}
.handoff-actions button {
    padding: 7px 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--fg);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}
.handoff-actions button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Plan 04: Pendencias modal ───────────────────────────────────────── */
.pending-modal:not([open]) { display: none; }
.pending-modal[open] {
    width: min(700px, 94vw);
    max-height: 85vh;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-surface);
    color: var(--fg);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.pending-modal::backdrop { background: rgba(0,0,0,0.55); }
.pending-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
}
.pending-header h2 { margin: 0; font-size: 17px; }
.pending-header button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.pending-header button:hover { background: var(--bg-elevated); }
.pending-401-banner {
    background: #ffe6e6;
    color: #701414;
    border-bottom: 1px solid #d94141;
    padding: 10px 20px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.pending-401-banner button {
    background: #d94141;
    color: #fff;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
#pending-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}
.pending-section {
    margin-bottom: 16px;
    border-left: 4px solid var(--border);
    padding-left: 12px;
}
.pending-section.red   { border-left-color: #d94141; }
.pending-section.yellow{ border-left-color: #e0b900; }
.pending-section.blue  { border-left-color: #60a5fa; }
.pending-section.gray  { border-left-color: #6b7280; }
.pending-section h3 {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
}
.pending-section.red h3    { color: #d94141; }
.pending-section.yellow h3 { color: #c89800; }
.pending-section.blue h3   { color: #60a5fa; }
.pending-section.gray h3   { color: #9ca3af; }
.pending-section ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.pending-section li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    padding: 4px 0;
}
.pending-section li span { flex: 1; }
.pending-section li button {
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--fg);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.pending-section li button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.pending-section li button:disabled { opacity: 0.5; cursor: not-allowed; }
.pending-empty {
    text-align: center;
    color: #3bb273;
    font-weight: 600;
    padding: 24px 0;
    font-size: 15px;
}
.pending-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-wrap: wrap;
}
.pending-footer-right {
    display: flex;
    gap: 8px;
}
#btn-pending-force-sync {
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--fg);
    cursor: pointer;
    font-size: 13px;
}
#btn-pending-force-sync:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
#btn-pending-force-sync:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    padding: 7px 16px;
    border-radius: 6px;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary {
    padding: 7px 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--fg);
    cursor: pointer;
    font-size: 14px;
}
.btn-secondary:hover { background: var(--bg-surface); }
