/* Stewart chat -- phone-first single-pane layout. */

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    /* Lock the document scroll. The flex layout below already gives
       .messages its own internal scroll. Without overflow:hidden here,
       mobile browsers let the whole body slide -- which takes the
       header and composer with it. */
    overflow: hidden;
}
body {
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
    color: #1F2329;
    background: #F2F2F4;
}

.page {
    display: flex;
    flex-direction: column;
    /* Pin to the viewport with position: fixed instead of height: 100vh
       / 100dvh. The pure-height approach worked on desktop but on
       Android Chrome the composer kept floating off the bottom edge --
       the dynamic viewport calculation lags the address bar showing /
       hiding, so a 100dvh page is taller than what's actually visible
       and the bottom of the flex column slides under the chrome.
       Fixed-positioning bypasses the calculation: top:0 to bottom:0
       is exactly the visible area, period. left/right pin horizontally
       too, with max-width centering on tablets via the transform. */
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 720px;
    margin: 0 auto;
    background: #FAFAFB;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.topbar {
    flex: 0 0 auto;
    background: linear-gradient(180deg, #2A2A2A 0%, #1F1F1F 100%);
    color: #fff;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
}
.topbar .title {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}
.topbar .brand {
    font-weight: 700; font-size: 14pt; letter-spacing: 0.2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .sub {
    font-size: 9pt; color: #C6C9D0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Header icon buttons -- hamburger on the left, kebab/menu on the right. */
.icon-btn {
    background: transparent;
    color: #fff;
    border: 0;
    border-radius: 8px;
    width: 36px; height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
}
.icon-btn:hover  { background: rgba(255,255,255,0.10); }
.icon-btn:active { background: rgba(255,255,255,0.18); }
.icon-btn.primary {
    background: #2A6FE3; color: #fff;
}
.icon-btn.primary:hover { background: #1F58BD; }

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.07);
    padding: 5px 10px;
    border-radius: 12px;
    font-size: 10pt;
    /* Keep the pill on a single line. The "LeonardoWeb DOWN" string was
       wrapping to two lines on a narrow phone topbar, which made the whole
       header grow taller and pushed the title up out of the visible area.
       The brand title has its own ellipsis (line 53) so it can give up
       width gracefully instead. */
    white-space: nowrap;
    flex-shrink: 0;
}
.status .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #6E7480;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.25);
}
.status.up    .dot { background: #2EBD66; }
.status.down  .dot { background: #E5484D; }
.status .label { color: #DDE2EA; }

.messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Classic flexbox-scroll fix: a flex item with content (the bubbles)
       refuses to shrink below its content height unless min-height: 0 is
       explicit. Without this, the messages list grows to its full content
       height and pushes the topbar above the viewport and the composer
       below it -- which is what Tony saw when LeonardoWeb went down and
       the status pill grew. With min-height: 0, the flex column enforces
       the 100dvh constraint and overflow-y: auto handles the scroll. */
    min-height: 0;
}
.empty {
    color: #8A93A6;
    text-align: center;
    padding: 40px 16px;
    font-style: italic;
}

.bubble {
    max-width: 86%;
    padding: 10px 14px;
    border-radius: 14px;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.bubble .who {
    font-size: 9pt;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    opacity: 0.82;
    margin-bottom: 4px;
}
.bubble .content { /* the message text */
    /* inherits whitespace handling from .bubble */
}
.bubble .meta {
    font-size: 9pt;
    color: #6B7280;
    margin-top: 4px;
}

/* Tony -- right-aligned, dark blue (existing). The human at the keyboard. */
.bubble.tony {
    align-self: flex-end;
    background: #2A6FE3;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.bubble.tony .meta { color: rgba(255, 255, 255, 0.78); }
.bubble.tony .who  { color: rgba(255, 255, 255, 0.92); }

/* Felix -- right-aligned, tinted blue. The interactive Claude persona;
   same "user side" as Tony but distinct. */
.bubble.felix {
    align-self: flex-end;
    background: #3A8CB8;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.bubble.felix .meta { color: rgba(255, 255, 255, 0.78); }
.bubble.felix .who  { color: rgba(255, 255, 255, 0.92); }

/* Claude -- left-aligned, white (existing). Headless Claude through Stewart. */
.bubble.claude {
    align-self: flex-start;
    background: #fff;
    color: #1F2329;
    border-bottom-left-radius: 4px;
}
.bubble.claude .who { color: #4A5568; }

/* Stewart's own voice -- centered, soft yellow (existing).
   Status pings, soft-fail notes, watchdog alerts. */
.bubble.stewart {
    align-self: center;
    background: #FFF3D6;
    color: #5A4214;
    font-size: 11pt;
    font-style: italic;
    max-width: 94%;
}
.bubble.stewart .who { color: #5A4214; font-style: normal; }

.composer {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) 10px;
    background: #fff;
    border-top: 1px solid #E2E5EA;
    /* Bottom-anchor the mic + send buttons. As the textarea grows during
       dictation the row gets taller; without this the Send button stretches
       vertically with it (looks awful) and the mic floats away from the
       keyboard. Flex-end keeps both buttons pinned to the bottom edge near
       where Tony's thumb is. */
    align-items: flex-end;
}
.composer textarea {
    flex: 1 1 auto;
    resize: none;
    border: 1px solid #C9D0D9;
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    color: #1F2329;
    background: #fff;
    min-height: 42px;
    /* Grow as content does (chat.js sets style.height on input/dictation)
       up to this ceiling, then a scrollbar appears inside the textarea.
       70vh keeps a few lines of the most-recent chat history visible
       above the composer when the input is at its tallest -- enough so
       Tony can review a long dictation without losing context. */
    max-height: 70vh;
    overflow-y: auto;
}
.composer textarea:focus {
    border-color: #2A6FE3;
    outline: none;
    box-shadow: 0 0 0 3px rgba(42, 111, 227, 0.15);
}
.composer button {
    flex: 0 0 auto;
    background: #2A6FE3;
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: 0 18px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    min-width: 68px;
}
.composer button:hover { background: #1F58BD; }
.composer button:disabled {
    background: #C2C7D1;
    cursor: not-allowed;
}

/* Send button gets a fixed height so it matches the mic and never stretches
   with the textarea. Also a relative position so the .sending spinner can
   absolute-position inside it. */
#sendBtn {
    height: 44px;
    position: relative;
}
/* Busy state -- shown while the message is in flight. The "Sending..." text
   stays in the DOM (screen readers still announce it) but goes transparent
   so the CSS spinner shows in its place. No clicks while busy. */
#sendBtn.sending {
    color: transparent;
    pointer-events: none;
}
#sendBtn.sending::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 16px; height: 16px;
    margin-left: -8px; margin-top: -8px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Desktop wait-cursor while a message is being sent. Phone users get the
   spinning Send button as the cue; this is for the mouse-driven case. */
body.busy, body.busy * { cursor: wait !important; }

/* ---- Services panel (start / stop / restart cards) -------------------- */
.services-sheet { max-width: 480px; }
.services-sheet .services-help {
    font-size: 10pt;
    color: #4A5263;
    margin: 6px 0 14px 0;
    line-height: 1.45;
}
.svc-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    max-height: 60vh;
    overflow-y: auto;
}
.svc-card {
    border: 1px solid #E2E5EA;
    border-radius: 10px;
    padding: 10px 12px;
    background: #FAFAFB;
}
.svc-card .svc-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.svc-card .svc-name {
    flex: 1 1 auto;
    font-weight: 600;
    color: #1F2329;
    /* Long service names like "MSSQL$SQL2012EXPRESS" must not push the
       status badge off the right edge of the card on narrow screens. */
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.svc-badge {
    flex: 0 0 auto;
    font-size: 9pt;
    padding: 3px 8px;
    border-radius: 10px;
    background: #E2E5EA;
    color: #4A5263;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.svc-badge.running { background: #D6F5E0; color: #1F7A3F; }
.svc-badge.stopped { background: #FBD9DA; color: #9C2D31; }
.svc-badge.pending { background: #FFEBC4; color: #7C5A12; }
.svc-actions {
    display: flex;
    gap: 6px;
}
.svc-actions button {
    flex: 1 1 auto;
    border: 1px solid #C9D0D9;
    background: #fff;
    color: #1F2329;
    border-radius: 8px;
    padding: 8px 0;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.svc-actions button:hover { background: #F4F6F8; }
.svc-actions button:disabled {
    color: #A0A4AD;
    background: #F2F2F4;
    border-color: #E2E5EA;
    cursor: not-allowed;
}
.svc-actions button.destructive { color: #9C2D31; border-color: #FBD9DA; }
.svc-actions button.destructive:hover { background: #FFF1F2; }
.menu-divider {
    border-top: 1px solid #E2E5EA;
    margin: 8px 0;
}

/* ---- Auth login card --------------------------------------------------
   Visual port of LeonardoWeb's login card so the two surfaces feel like
   the same family. White card on the dark .overlay backdrop, soft
   shadow, centered title, big dark biometric button, "or" divider,
   collapsed paste-field fallback. */
.login-card {
    background: #FFFFFF;
    border: 1px solid #E0E0E2;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
    padding: 36px 40px 32px 40px;
    width: min(360px, 90vw);
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: #1F2329;
    /* No margin-top: the overlay's align-items is now center (see the
       .overlay rule near the top of this file -- this card uses
       align-items: center via a sibling override). On a phone with a
       dynamic address bar that can scroll into view, "center" is the
       only position guaranteed to stay visible without the user
       having to scroll. */
}
/* Override the overlay's default flex-start alignment ONLY when the
   sheet inside is the login card. Other overlays (conv list, conv
   actions, services panel) keep flex-start so long content scrolls
   from the top. */
.overlay:has(> .login-card) { align-items: center; }
.login-card h1 {
    margin: 0 0 6px 0;
    font-size: 18pt;
    font-weight: 600;
    color: #1A1A1A;
    text-align: center;
}
.login-card .subtitle {
    text-align: center;
    color: #5A5A5A;
    font-size: 11pt;
    margin: 0 0 4px 0;
}
.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    font-size: 12pt;
    border: 1px solid #C9D0D9;
    border-radius: 4px;
    box-sizing: border-box;
}
.login-card input[type="text"]:focus {
    border-color: #2A6FE3;
    outline: none;
    box-shadow: 0 0 0 3px rgba(42, 111, 227, 0.15);
}
.login-card button {
    width: 100%;
    padding: 11px;
    font: inherit;
    font-size: 12pt;
    font-weight: 600;
    background: #3C3C3C;
    color: #FFFFFF;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}
.login-card button:hover:not(:disabled) { background: #4A4A4A; }
.login-card button:disabled            { background: #A0A0A4; cursor: default; }
.login-card .divider {
    text-align: center;
    color: #888;
    font-size: 10pt;
    margin: 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.login-card .divider::before,
.login-card .divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #E0E0E2;
}
.login-card .pw-toggle {
    text-align: center;
    color: #0A66C2;
    font-size: 11pt;
    cursor: pointer;
    user-select: none;
    padding: 4px;
}
.login-card .pw-toggle:hover { text-decoration: underline; }
.login-card .pw-area {
    display: none;
    flex-direction: column;
    gap: 10px;
}
.login-card .pw-area.show { display: flex; }
.login-card .pw-hint {
    font-size: 9pt;
    color: #888;
    text-align: center;
    margin: -4px 0 0 0;
}
.login-card .error-msg {
    color: #C00000;
    font-size: 10pt;
    text-align: center;
    margin: 6px 0 0 0;
    min-height: 1em;
}
.login-card .auth-diag {
    margin-top: 10px;
    font-size: 9pt;
    color: #B0B5C0;
    text-align: right;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
}

/* Mic button -- left of the textarea. Always visible by default (Tony
   should not have to "turn it on" first). Whisper.cpp on the server
   handles punctuation + capitalization; this surface just records audio
   and uploads it. */
.composer .mic-btn {
    width: 44px; min-width: 44px; height: 44px;
    padding: 0;
    background: #fff;
    color: #4A5263;
    border: 1px solid #C9D0D9;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}
.composer .mic-btn:hover {
    background: #F4F6F8;
    color: #1F58BD;
}
.composer .mic-btn:disabled {
    background: #F2F2F4;
    color: #A0A4AD;
    cursor: not-allowed;
}
/* Recording state -- red pulse so it's obvious the mic is hot. */
.composer .mic-btn.recording {
    background: #E5484D;
    color: #fff;
    border-color: #E5484D;
    animation: mic-pulse 1.2s ease-in-out infinite;
}
.composer .mic-btn.uploading {
    background: #FFA500;
    color: #fff;
    border-color: #FFA500;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.55); }
    50%      { box-shadow: 0 0 0 10px rgba(229, 72, 77, 0); }
}

/* ---- Overlays / drawers / modal cards ----------------------------- */

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
}
.overlay-sheet {
    background: #fff;
    color: #1F2329;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

/* Conversation list -- slides in from the left as a full-height panel
   on mobile, max-width on larger screens. */
.conv-list-sheet {
    width: 100%;
    max-width: 480px;
    height: 100dvh;
    margin-right: auto;
    display: flex;
    flex-direction: column;
    border-radius: 0 12px 12px 0;
}
.conv-list-sheet .overlay-header {
    background: #2A2A2A;
    color: #fff;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}
.conv-list-sheet .overlay-header h2 {
    font-size: 14pt;
    font-weight: 600;
    margin: 0;
    flex: 1 1 auto;
}
.conv-list-sheet .filter-chips {
    display: flex; gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid #E2E5EA;
    flex: 0 0 auto;
}
.conv-list-sheet .filter-chips .chip {
    background: #F4F6F8;
    color: #4A5263;
    border: 1px solid #DDE0E6;
    border-radius: 14px;
    padding: 5px 12px;
    font: inherit;
    font-size: 10.5pt;
    cursor: pointer;
}
.conv-list-sheet .filter-chips .chip.active {
    background: #2A6FE3;
    color: #fff;
    border-color: #2A6FE3;
}

.conv-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 8px 16px;
}
.conv-list .empty {
    color: #8A93A6;
    text-align: center;
    padding: 32px 16px;
    font-style: italic;
}
.conv-card {
    background: #fff;
    border: 1px solid #E0E3E8;
    border-radius: 10px;
    padding: 10px 14px;
    margin: 6px 4px;
    cursor: pointer;
}
.conv-card:hover { background: #F0F6FF; border-color: #B6D4FF; }
.conv-card.current {
    background: #EAF1FC;
    border-color: #2A6FE3;
}
.conv-card .card-top {
    display: flex; align-items: baseline; gap: 8px;
}
.conv-card .card-title {
    font-weight: 600;
    color: #1F2329;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-card .card-when {
    font-size: 9.5pt;
    color: #8A93A6;
    flex: 0 0 auto;
}
.conv-card .card-preview {
    font-size: 10.5pt;
    color: #4A5263;
    margin-top: 4px;
    word-break: break-word;
    /* clamp at 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.conv-card .card-meta {
    font-size: 9pt;
    color: #8A93A6;
    margin-top: 4px;
}
.conv-card .badge {
    display: inline-block;
    font-size: 8.5pt;
    background: #F4F6F8;
    color: #6B7280;
    border-radius: 6px;
    padding: 1px 6px;
    margin-left: 6px;
    vertical-align: middle;
}
.conv-card .badge.closed { background: #FFE7A3; color: #6A4B0A; }

/* Centered modal cards -- new conv form + actions menu. */
.menu-sheet, .new-conv-sheet {
    border-radius: 12px;
    width: min(440px, 92vw);
    margin: 8vh auto auto;
    padding: 18px 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.menu-sheet h2, .new-conv-sheet h2 {
    margin: 0 0 4px;
    font-size: 14pt;
    font-weight: 600;
    color: #1F2329;
}
.menu-item {
    background: #fff;
    color: #2A6FE3;
    border: 1px solid #C9D0D9;
    border-radius: 8px;
    padding: 11px 14px;
    font: inherit;
    font-weight: 500;
    font-size: 11.5pt;
    text-align: left;
    cursor: pointer;
}
.menu-item:hover { background: #F0F6FF; }
.menu-item.primary {
    background: #2A6FE3;
    color: #fff;
    border-color: #2A6FE3;
    font-weight: 600;
}
.menu-item.primary:hover { background: #1F58BD; }
.menu-item.destructive {
    color: #B00020;
    border-color: #F0CCD2;
}
.menu-item.destructive:hover { background: #FBEAEC; }
.menu-item.cancel {
    color: #4A5263;
    background: #F4F6F8;
    border-color: #DDE0E6;
    font-weight: 500;
    text-align: center;
}
.menu-item.cancel:hover { background: #ECEDF1; }
.menu-item:disabled { opacity: 0.5; cursor: not-allowed; }
.menu-actions { display: flex; gap: 8px; margin-top: 10px; }
.menu-actions .menu-item { flex: 1 1 auto; text-align: center; }

.field-label {
    font-size: 10pt;
    font-weight: 600;
    color: #4A5263;
    margin-top: 6px;
}
.field-input {
    width: 100%;
    padding: 9px 11px;
    font: inherit;
    color: #1F2329;
    background: #fff;
    border: 1px solid #C9D0D9;
    border-radius: 6px;
    resize: vertical;
}
.field-input:focus {
    border-color: #2A6FE3;
    outline: none;
    box-shadow: 0 0 0 3px rgba(42, 111, 227, 0.15);
}
