/* Medical Health Records — Styles
   Color scheme: darker, medical-appropriate — distinct from brain's imPower branding
   Primary: Deep Navy #1e3a5f, Accent: Teal #0891b2, Warning: Amber #f59e0b
*/

:root {
    --primary: #1e3a5f;
    --primary-light: #2d5a8e;
    --accent: #0891b2;
    --accent-light: #22d3ee;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --bg: #f0f4f8;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-light: #6b7280;
    --border: #e2e8f0;
    --danger: #ef4444;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

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

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

/* ─── Screens ────────────────────────────────────────────── */

.screen {
    display: none;
    flex-direction: column;
    height: 100%;
}

.screen.active {
    display: flex;
}

/* ─── Login Screen ───────────────────────────────────────── */

#login-screen {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

#login-box {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

#login-header {
    text-align: center;
    margin-bottom: 24px;
}

#login-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--bg);
    color: var(--accent);
    margin-bottom: 12px;
}

#login-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}

#login-header p {
    font-size: 14px;
    color: var(--text-light);
    margin-top: 4px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#login-form input {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
}

#login-form input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--card-bg);
}

#login-btn {
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 4px;
}

#login-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

#login-error {
    text-align: center;
    color: var(--danger);
    font-size: 14px;
    padding: 4px;
}

#login-disclaimer {
    text-align: center;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 16px;
}

/* ─── Header ─────────────────────────────────────────────── */

#header {
    background: var(--primary);
    color: white;
    padding: 12px 16px 0;
    flex-shrink: 0;
}

#header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#header-top h1 {
    font-size: 20px;
    font-weight: 600;
}

#logout-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.3);
    background: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#logout-btn:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

#person-tabs {
    display: flex;
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.person-tab {
    flex: 1;
    min-width: 0;
    padding: 10px 8px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    text-transform: capitalize;
}

.person-tab.active {
    color: white;
    border-bottom-color: var(--accent-light);
}

/* ─── Safety Banner ──────────────────────────────────────── */

#safety-banner {
    background: var(--warning-bg);
    color: #92400e;
    padding: 8px 16px;
    font-size: 12px;
    text-align: center;
    flex-shrink: 0;
    border-bottom: 1px solid #fde68a;
}

/* ─── Chat Messages ──────────────────────────────────────── */

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.system-message {
    text-align: center;
    color: var(--text-light);
    font-size: 14px;
    padding: 20px;
    line-height: 1.5;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 8px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-bubble.user {
    background: var(--accent);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    background: var(--card-bg);
    border: 1px solid var(--border);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.chat-bubble.assistant .sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-light);
}

.chat-bubble.assistant .safety-flag {
    margin-top: 8px;
    padding: 6px 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    font-size: 13px;
    color: #991b1b;
}

.chat-bubble.assistant .disclaimer {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-light);
    font-style: italic;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    max-width: 60px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    margin-bottom: 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing 1.4s infinite both;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ─── Chat Input ─────────────────────────────────────────── */

#chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
}

#chat-input:focus {
    outline: none;
    border-color: var(--accent);
}

#chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

#chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ─── Toast ──────────────────────────────────────────────── */

#toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1000;
    transition: opacity 0.3s;
    pointer-events: none;
}

#toast.hidden {
    opacity: 0;
}

/* ─── Scrollbar ──────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 0;
}

/* ─── Standalone mode padding ────────────────────────────── */

@media (display-mode: standalone) {
    #header {
        padding-top: calc(var(--safe-top) + 12px);
    }
    #login-screen {
        padding-top: calc(var(--safe-top) + 20px);
    }
}

/* ─── Hidden utility ─────────────────────────────────────── */

.hidden {
    display: none !important;
}
