/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
    /* Deep navy palette */
    --bg:            #06061a;
    --bg2:           #0b0b24;
    --surface:       rgba(255,255,255,0.06);
    --surface-solid: #0f0f28;
    --surface2:      rgba(255,255,255,0.09);
    --surface3:      rgba(255,255,255,0.13);
    --border:        rgba(255,255,255,0.10);
    --border-bright: rgba(255,255,255,0.22);
    /* Chrome — header, sidebar, drawers, sensor bar. Overridden per skin. */
    --chrome-bg:     rgba(8,8,24,0.85);

    /* Accent — vivid purple → blue */
    --accent:        #7c3aed;
    --accent2:       #2563eb;
    --accent-glow:   rgba(124,58,237,0.55);
    --accent-hover:  #6d28d9;

    /* Text */
    --text:          #f0f0fa;
    --text-muted:    rgba(240,240,250,0.58);
    --text-dim:      rgba(240,240,250,0.30);

    /* Semantic */
    --success:       #22c55e;
    --warning:       #f59e0b;
    --error:         #ef4444;

    /* Message bubbles — vivid, high contrast */
    --user-bg:       #ffffff;
    --user-text:     #0a0a20;
    --asst-grad:     linear-gradient(135deg, rgba(109,40,217,0.72), rgba(37,99,235,0.62));
    --asst-border:   rgba(139,92,246,0.45);
    --asst-glow:     rgba(109,40,217,0.30);

    /* Layout */
    --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --mono:          'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
    --radius:        18px;
    --radius-sm:     12px;
    --radius-xs:     7px;
    --sidebar-w:     270px;
    --header-h:      56px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Ambient background — vivid neon glows like the inspiration */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 70% 55% at -5% 5%,  rgba(109,40,217,0.42), transparent 55%),
        radial-gradient(ellipse 55% 45% at 105% 10%, rgba(37,99,235,0.32),  transparent 55%),
        radial-gradient(ellipse 50% 40% at 50% 105%, rgba(124,58,237,0.22), transparent 55%);
    pointer-events: none;
    z-index: 0;
}

/* ── App Shell ─────────────────────────────────────────────────────────────── */
#app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    position: relative;
    z-index: 1;
}

/* ── Glassmorphism helper ───────────────────────────────────────────────────── */
.glass {
    background: var(--surface);
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    border: 1px solid var(--border);
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--chrome-bg);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
    backdrop-filter: blur(3px);
}
.sidebar-overlay.visible { display: block; }

.sidebar-header {
    height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 0 16px 8px;
    padding-top: env(safe-area-inset-top, 0px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    font-size: 14px;
    font-weight: 800;
    background: linear-gradient(135deg, #a78bfa, #60a5fa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 4px;
    user-select: none;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 6px;
}

.conv-item {
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 2px;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.conv-item:hover  { background: var(--surface2); color: var(--text); }
.conv-item.active {
    background: rgba(124,58,237,0.20);
    color: var(--text);
    border: 1px solid rgba(139,92,246,0.40);
    box-shadow: 0 0 12px rgba(109,40,217,0.18) inset;
}

/* Conversation title + delete button */
.conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-delete-btn {
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 5px;
    padding: 3px;
    transition: color 0.15s, background 0.15s;
}
.conv-item:hover .conv-delete-btn { display: flex; }
.conv-delete-btn:hover {
    color: var(--error);
    background: rgba(239,68,68,0.12);
}

/* ── Connector dots ── */
.connector-dots {
    padding: 8px 14px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-top: 1px solid var(--border);
}
.connector-dots:empty { display: none; }

.conn-dot {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    cursor: default;
    padding: 4px 8px;
    border-radius: 20px;
    background: var(--surface2);
    border: 1px solid var(--border);
    transition: background 0.15s;
}
.conn-dot:hover { background: var(--surface3); color: var(--text); }
.conn-dot.off    { color: var(--text-dim); }

.conn-pip {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.conn-pip.ok      { background: var(--success); box-shadow: 0 0 5px var(--success); }
.conn-pip.warn    { background: var(--warning); box-shadow: 0 0 5px var(--warning); }
.conn-pip.off     { background: var(--text-dim); }

/* ── Sidebar footer ── */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 4px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 0 0 2px rgba(124,58,237,0.35), 0 0 12px rgba(109,40,217,0.4);
}
.avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 11px;
    box-shadow: 0 0 0 1.5px rgba(124,58,237,0.25);
}
.avatar-lg {
    width: 42px;
    height: 42px;
    font-size: 16px;
    box-shadow: 0 0 0 2.5px rgba(124,58,237,0.4), 0 0 16px rgba(109,40,217,0.5);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}
.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-role {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-footer-actions {
    display: flex;
    gap: 6px;
}

.user-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-select {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}
.user-select:focus { border-color: var(--accent); }

/* ── Main ──────────────────────────────────────────────────────────────────── */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
#header {
    /* Total height = content row + status bar inset so content is never behind notch/Dynamic Island */
    height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
    padding: 0 12px;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--chrome-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    padding-bottom: 8px;
    gap: 6px;
    flex-shrink: 0;
}

.header-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    user-select: none;
    background: linear-gradient(135deg, #c4b5fd, #93c5fd);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ── Status dot ────────────────────────────────────────────────────────────── */
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
    transition: background 0.3s;
    -webkit-text-fill-color: initial;
}
.status-dot.connected    { background: var(--success); box-shadow: 0 0 5px rgba(34,197,94,0.6); }
.status-dot.disconnected { background: var(--error); }

/* ── Sensor bar ────────────────────────────────────────────────────────────── */
.sensor-bar {
    background: var(--chrome-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 8px 14px;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}
.sensor-bar::-webkit-scrollbar { display: none; }

.sensor-grid {
    display: flex;
    gap: 8px;
    min-width: max-content;
}

.sensor-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 13px;
    min-width: 84px;
    text-align: center;
    flex-shrink: 0;
    transition: border-color 0.2s;
}
.sensor-card:hover { border-color: var(--border-bright); }
.sensor-card.stale { opacity: 0.45; }

.sensor-icon  { font-size: 16px; line-height: 1; }
.sensor-label { font-size: 10px; color: var(--text-muted); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.4px; }
.sensor-value { font-size: 15px; font-weight: 700; margin-top: 2px; color: var(--text); }

/* ── Messages ──────────────────────────────────────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* ── Welcome state ─────────────────────────────────────────────────────────── */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 0 24px;
    text-align: center;
    color: var(--text-muted);
    user-select: none;
}
.welcome-logo {
    font-size: 40px;
    font-weight: 800;
    background: linear-gradient(135deg, #c4b5fd 0%, #818cf8 40%, #60a5fa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 6px;
    filter: drop-shadow(0 0 16px rgba(124,58,237,0.4));
    margin-bottom: 2px;
}
.welcome-tagline {
    font-size: 14px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.welcome-hint    { font-size: 13px; color: var(--text-dim); }

/* ── Empty-state Dashboard ───────────────────────────────────────────────────── */
.dash-stack {
    width: 100%;
    max-width: 560px;
    margin: 8px auto 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
}

.dash-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.dash-head {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 10px;
}
.dash-head-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.dash-head-voice {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}

.dash-empty {
    font-size: 13px;
    color: var(--text-dim);
    padding: 4px 0;
}

.dash-tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.dash-tile {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 10px 12px;
    transition: border-color 0.15s, background 0.15s;
}
.dash-tile:hover { border-color: var(--border-bright); }
.dash-tile-icon { font-size: 22px; line-height: 1; flex-shrink: 0; }
.dash-tile-body { display: flex; flex-direction: column; min-width: 0; }
.dash-tile-val  { font-size: 17px; font-weight: 700; color: var(--text); line-height: 1.1; }
.dash-tile-lbl  { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-top: 2px; }

.dash-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.dash-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: none;
    border: 0;
    color: var(--text);
    text-align: left;
    padding: 9px 10px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 13.5px;
    transition: background 0.12s;
}
.dash-row:hover { background: var(--surface2); }
.dash-row-static { cursor: default; }
.dash-row-static:hover { background: none; }
.dash-row-icon { flex-shrink: 0; font-size: 15px; }
.dash-row-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-row-time { font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.dash-row-chev { color: var(--text-dim); flex-shrink: 0; }

.dash-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 4px 16px;
    text-align: center;
}
.dash-suggest-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
}
.dash-suggest-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}
.dash-chip {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    padding: 6px 14px;
    font-size: 12.5px;
    cursor: pointer;
    transition: all 0.15s;
}
.dash-chip:hover {
    background: var(--surface3);
    color: var(--text);
    border-color: var(--border-bright);
}

@media (max-width: 480px) {
    .dash-stack { max-width: 100%; padding: 0 8px; }
    .dash-tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .dash-panel { padding: 12px 14px; }
    .dash-tile-val { font-size: 16px; }
}

/* ── Tool-call cards (collapsible) ──────────────────────────────────────────── */
.tool-card {
    max-width: 480px;
    margin: 4px 0 4px 44px;
    border-radius: var(--radius-xs);
    border: 1px solid rgba(124,58,237,0.25);
    background: rgba(124,58,237,0.06);
    overflow: hidden;
    font-size: 12px;
}
.tool-card-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 7px 10px;
    background: none;
    border: none;
    color: #a78bfa;
    font-family: var(--mono);
    font-size: 11.5px;
    cursor: pointer;
    text-align: left;
    gap: 8px;
}
.tool-card-toggle:hover { background: rgba(124,58,237,0.1); }
.tool-card-meta { color: var(--text-dim); flex-shrink: 0; }
.tool-card-body { display: none; padding: 0 10px 8px; }
.tool-card-body.open { display: block; }
.tool-card-body pre {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 160px;
    overflow-y: auto;
}

/* ── HA entity tiles (inline in tool-call cards) ────────────────────────────── */
.ha-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 10px 4px;
}
.ha-tile {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border-radius: 8px;
    font-size: 11.5px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.03);
}
.ha-tile.on  { border-color: rgba(34,197,94,0.4); background: rgba(34,197,94,0.08); }
.ha-tile.off { border-color: rgba(255,255,255,0.07); opacity: 0.65; }
.ha-tile-icon { font-size: 13px; }
.ha-tile-name { color: var(--text-muted); max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ha-tile-state { font-weight: 600; font-size: 11px; }
.ha-tile.on  .ha-tile-state { color: #4ade80; }
.ha-tile.off .ha-tile-state { color: var(--text-dim); }
.ha-tile.neutral .ha-tile-state { color: #fbbf24; }

/* ── Prompt suggestion cards ────────────────────────────────────────────────── */
.prompt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 560px;
    margin-top: 8px;
    padding: 0 4px;
}
.prompt-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12.5px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    backdrop-filter: blur(12px);
}
.prompt-card:hover {
    background: rgba(124,58,237,0.14);
    border-color: rgba(124,58,237,0.4);
    color: var(--text);
}
.prompt-icon { font-size: 18px; line-height: 1; }
.prompt-label { font-weight: 500; }

/* ── Message bubbles ────────────────────────────────────────────────────────── */
.message {
    display: flex;
    flex-direction: column;
    max-width: 78%;
}
.message.user      { align-self: flex-end;   align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

/* Row with avatar + bubble side by side */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.message.user .message-row      { flex-direction: row-reverse; }
.message.assistant .message-row { flex-direction: row; }

.message-role {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.message-bubble {
    padding: 11px 15px;
    border-radius: var(--radius);
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 44px;
    position: relative;
}

.message.user .message-bubble {
    background: var(--user-bg);
    color: var(--user-text);
    border-bottom-right-radius: 5px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.35), 0 1px 0 rgba(255,255,255,0.1) inset;
    font-weight: 500;
}

.message.assistant .message-bubble {
    background: var(--asst-grad);
    border: 1px solid var(--asst-border);
    border-bottom-left-radius: 5px;
    box-shadow: 0 4px 24px var(--asst-glow), 0 1px 0 rgba(255,255,255,0.08) inset;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* Attachment thumbnail inside bubble */
.attachment-thumb {
    max-width: 220px;
    max-height: 160px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: block;
    object-fit: cover;
}
.attachment-file {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.2);
    border-radius: var(--radius-xs);
    padding: 5px 9px;
    margin-bottom: 6px;
}

/* ── Typing indicator ──────────────────────────────────────────────────────── */
.typing-bubble {
    background: var(--asst-grad);
    border: 1px solid var(--asst-border);
    border-radius: var(--radius);
    border-bottom-left-radius: 4px;
    padding: 13px 18px;
    display: flex;
    gap: 5px;
    align-items: center;
}
.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(167,139,250,0.6);
    animation: bounce 1.3s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

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

/* ── Tool indicator ─────────────────────────────────────────────────────────── */
.tool-indicator {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.tool-spinner {
    width: 10px;
    height: 10px;
    border: 1.5px solid rgba(124,58,237,0.3);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Approval card ──────────────────────────────────────────────────────────── */
.approval-card {
    background: rgba(245,158,11,0.06);
    border: 1px solid rgba(245,158,11,0.2);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius);
    padding: 14px 16px;
    max-width: 380px;
    align-self: flex-start;
    backdrop-filter: blur(8px);
}

.approval-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--warning);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 10px;
}

.approval-row {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: flex;
    gap: 6px;
}
.approval-row strong { color: var(--text); font-weight: 600; min-width: 60px; }

.approval-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.btn-reject {
    flex: 1;
    padding: 9px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font);
    transition: border-color 0.15s, color 0.15s;
}
.btn-reject:hover { border-color: var(--error); color: var(--error); }

.btn-approve {
    flex: 1;
    padding: 9px;
    background: var(--success);
    border: none;
    color: #fff;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    transition: background 0.15s;
}
.btn-approve:hover { background: #16a34a; }

/* ── Proposal card ──────────────────────────────────────────────────────────── */
.proposal-card {
    background: rgba(124,58,237,0.06);
    border: 1px solid rgba(124,58,237,0.2);
    border-left: 3px solid #7c3aed;
    border-radius: var(--radius);
    padding: 14px 16px;
    max-width: 560px;
    width: 100%;
    align-self: flex-start;
    backdrop-filter: blur(8px);
}

.proposal-title {
    font-size: 11px;
    font-weight: 700;
    color: #a78bfa;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 10px;
}

.proposal-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
    margin-bottom: 12px;
}
.proposal-meta dt { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.proposal-meta dd { font-size: 12px; color: var(--text); font-family: var(--mono); }

.proposal-code-toggle {
    font-size: 12px;
    color: #a78bfa;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 0;
    margin-bottom: 8px;
    font-family: var(--font);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.proposal-code-toggle:hover { color: #c4b5fd; }

.proposal-code {
    background: rgba(0,0,0,0.35);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    overflow: auto;
    max-height: 360px;
    margin-bottom: 12px;
    display: none;
}
.proposal-code.visible { display: block; }

.proposal-code code {
    font-family: var(--mono);
    font-size: 0.82em;
    color: #e2e8f0;
    white-space: pre;
    display: block;
}

.proposal-warning {
    font-size: 12px;
    color: var(--warning);
    margin-bottom: 10px;
    line-height: 1.4;
}

/* ── Markdown content ────────────────────────────────────────────────────────── */
.message-bubble p  { margin: 0 0 6px; }
.message-bubble p:last-child { margin-bottom: 0; }

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 { margin: 10px 0 4px; line-height: 1.3; }
.message-bubble h1 { font-size: 1.15em; }
.message-bubble h2 { font-size: 1.05em; }
.message-bubble h3 { font-size: 0.95em; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); }

.message-bubble strong { font-weight: 700; }
.message-bubble em     { font-style: italic; }

.message-bubble code {
    font-family: var(--mono);
    font-size: 0.87em;
    background: rgba(0,0,0,0.3);
    padding: 1px 5px;
    border-radius: 4px;
}
.message.user .message-bubble code { background: rgba(0,0,0,0.15); color: #1e1e3f; }

.message-bubble pre {
    background: rgba(0,0,0,0.35);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    overflow-x: auto;
    margin: 8px 0;
}
.message-bubble pre code {
    background: transparent;
    padding: 0;
    font-size: 0.84em;
    white-space: pre;
    display: block;
    color: #e2e8f0;
}

.message-bubble ul,
.message-bubble ol {
    padding-left: 18px;
    margin: 4px 0;
}
.message-bubble li { margin: 2px 0; }

.message-bubble blockquote {
    border-left: 3px solid rgba(124,58,237,0.4);
    margin: 8px 0;
    padding: 4px 10px;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Input area ──────────────────────────────────────────────────────────────── */
.input-area {
    padding: 14px 18px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--chrome-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    flex-shrink: 0;
}

/* Upload preview bar */
#upload-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
#upload-preview:empty { display: none; }

.upload-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 8px 3px 6px;
    font-size: 12px;
    color: var(--text-muted);
}
.upload-chip img {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    object-fit: cover;
}
.upload-chip-remove {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 1px;
    line-height: 1;
    font-size: 14px;
    transition: color 0.1s;
}
.upload-chip-remove:hover { color: var(--error); }

#chat-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 10px 10px 10px 18px;
    transition: border-color 0.25s, box-shadow 0.25s, background 0.25s;
}
#chat-form:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow), 0 4px 24px var(--accent-glow);
    background: var(--surface3);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 160px;
    overflow-y: auto;
}
#message-input::placeholder { color: var(--text-dim); }

.send-btn {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 0 0 0 transparent;
}
.send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 0 16px var(--accent-glow), 0 4px 12px var(--accent-glow);
}
.send-btn:disabled { background: var(--surface3); box-shadow: none; cursor: not-allowed; opacity: 0.4; }

/* Upload button */
.upload-btn {
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.1s, background 0.1s;
    flex-shrink: 0;
}
.upload-btn:hover { color: var(--accent); background: var(--surface2); }
#file-input { display: none; }

/* ── Mic button ──────────────────────────────────────────────────────────────── */
@keyframes mic-pulse { 0%,100% { opacity:1; } 50% { opacity:0.4; } }
.mic-btn.active { color: var(--accent); animation: mic-pulse 1s ease-in-out infinite; }

/* ── Voice waveform overlay ──────────────────────────────────────────────────── */
#voice-overlay {
    position: fixed;
    inset: 0;
    background: var(--chrome-bg);
    backdrop-filter: blur(20px);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
#voice-overlay.active { opacity: 1; pointer-events: auto; }
.voice-waveform {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 60px;
}
.voice-bar {
    width: 4px;
    border-radius: 2px;
    background: linear-gradient(180deg, #a78bfa, #60a5fa);
    animation: wave-bar 0.8s ease-in-out infinite;
    transform-origin: bottom;
}
.voice-bar:nth-child(1) { height: 20px; animation-delay: 0s; }
.voice-bar:nth-child(2) { height: 35px; animation-delay: 0.1s; }
.voice-bar:nth-child(3) { height: 50px; animation-delay: 0.2s; }
.voice-bar:nth-child(4) { height: 40px; animation-delay: 0.15s; }
.voice-bar:nth-child(5) { height: 25px; animation-delay: 0.05s; }
.voice-bar:nth-child(6) { height: 45px; animation-delay: 0.25s; }
.voice-bar:nth-child(7) { height: 30px; animation-delay: 0.1s; }
@keyframes wave-bar { 0%,100% { transform: scaleY(0.4); } 50% { transform: scaleY(1); } }
.voice-label { font-size: 15px; font-weight: 600; color: #c4b5fd; letter-spacing: 0.5px; }
.voice-hint  { font-size: 12px; color: rgba(196,181,253,0.55); }
.voice-cancel {
    padding: 10px 24px;
    background: rgba(239,68,68,0.15);
    border: 1px solid rgba(239,68,68,0.35);
    border-radius: 10px;
    color: #fca5a5;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font);
}

/* ── Icon button ─────────────────────────────────────────────────────────────── */
.btn-icon {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.1s, color 0.1s;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.active { color: #a78bfa; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar          { width: 4px; height: 4px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: rgba(255,255,255,0.1); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Mobile ──────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 100;
        width: min(var(--sidebar-w), 85vw);
        transform: translateX(-110%);
        transition: transform 0.25s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .message { max-width: 92%; }
    .ha-site-select { max-width: 90px; font-size: 11px; }
    .model-badge    { display: none; }
    .prompt-grid { grid-template-columns: repeat(2, 1fr); }
    .tool-card { margin-left: 36px; }
}

@media (max-width: 480px) {
    :root { --header-h: 50px; }
    #header { padding: 0 8px; gap: 4px; }
    #sensors-btn, #tts-btn, #audit-btn, #export-btn, .ha-site-row { display: none; }
    .message-bubble { font-size: 14px; }
    .input-area { padding: 10px 10px; }
    #chat-form textarea { font-size: 16px; } /* must stay ≥16px — prevents iOS auto-zoom */
    .welcome-logo { font-size: 38px; letter-spacing: 5px; }
    .prompt-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .prompt-card { padding: 10px 11px; font-size: 12px; }
    .prompt-icon { font-size: 16px; }
    .approval-card, .proposal-card { padding: 12px; }
}

/* ── iPhone Pro / Pro Max (390–430px) ───────────────────────────────────────── */
@media (max-width: 430px) and (min-width: 381px) {
    .message { max-width: 94%; }
    .message-bubble { font-size: 14px; }
    .ha-site-select { max-width: 80px; font-size: 11px; }
}

/* ── iPhone SE / small Android (≤375px) ─────────────────────────────────────── */
@media (max-width: 375px) {
    :root { --header-h: 46px; }
    .message { max-width: 96%; }
    .message-bubble { font-size: 13px; padding: 9px 12px; }
    .input-row { gap: 6px; }
    .send-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
}

@media (min-width: 769px) {
    #menu-btn { display: none; }
}

/* ── Reduced motion ──────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .typing-dot, .tool-spinner { animation: none; }
    * { transition: none !important; }
}

/* ── Insights badge + drawer ─────────────────────────────────────────────────── */
.insights-badge {
    position: absolute;
    top: 4px; right: 4px;
    background: var(--error);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    pointer-events: none;
}
#insights-btn { position: relative; }

.insights-drawer {
    position: absolute;
    top: var(--header-h);
    right: 0; left: 0;
    z-index: 50;
    background: var(--chrome-bg);
    backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border);
    max-height: 55vh;
    display: flex;
    flex-direction: column;
}
.insights-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.insights-list {
    overflow-y: auto;
    padding: 8px 0;
}
.insights-empty {
    padding: 20px 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}
.insight-card {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    cursor: default;
}
.insight-card:last-child { border-bottom: none; }
.insight-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.insight-priority {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 4px;
}
.insight-priority.high   { background: rgba(239,68,68,0.15); color: #ef4444; }
.insight-priority.medium { background: rgba(245,158,11,0.15); color: #f59e0b; }
.insight-priority.low    { background: rgba(100,116,139,0.15); color: #64748b; }
.insight-title   { font-size: 13px; font-weight: 600; color: var(--text); }
.insight-detail  { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-bottom: 2px; }
.insight-action  { font-size: 12px; color: #a78bfa; font-style: italic; }
.insight-time    { font-size: 11px; color: var(--text-dim); margin-left: auto; }

/* ── Update Banner ───────────────────────────────────────────────────────────── */
.update-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(245,158,11,0.1);
    border-bottom: 1px solid rgba(245,158,11,0.22);
    padding: 9px 16px;
    font-size: 13px;
    color: var(--warning);
    flex-shrink: 0;
}
.update-banner button {
    background: none;
    border: none;
    color: var(--warning);
    cursor: pointer;
    font-size: 14px;
    opacity: 0.6;
    flex-shrink: 0;
}
.update-banner button:hover { opacity: 1; }

/* ── Model Badge ─────────────────────────────────────────────────────────────── */
.model-badge {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(167,139,250,0.7);
    background: rgba(124,58,237,0.12);
    border: 1px solid rgba(124,58,237,0.2);
    border-radius: 4px;
    padding: 1px 6px;
    margin-left: 4px;
    -webkit-text-fill-color: initial;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.model-badge.provider-anthropic { color: rgba(255,150,50,0.9);  background: rgba(255,150,50,0.1);  border-color: rgba(255,150,50,0.3);  }
.model-badge.provider-google    { color: rgba(66,133,244,0.9);  background: rgba(66,133,244,0.1);  border-color: rgba(66,133,244,0.3);  }
.model-badge.provider-xai       { color: rgba(16,185,129,0.9);  background: rgba(16,185,129,0.1);  border-color: rgba(16,185,129,0.3);  }
.model-badge.provider-groq      { color: rgba(249,115,22,0.9);  background: rgba(249,115,22,0.1);  border-color: rgba(249,115,22,0.3);  }
.model-badge.provider-openrouter{ color: rgba(139,92,246,0.9);  background: rgba(139,92,246,0.12); border-color: rgba(139,92,246,0.3);  }

/* ── Thinking Block ──────────────────────────────────────────────────────────── */
.thinking-block {
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(124,58,237,0.05);
    border: 1px solid rgba(124,58,237,0.15);
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}
.thinking-block summary {
    cursor: pointer;
    padding: 5px 10px;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}
.thinking-block summary::-webkit-details-marker { display: none; }
.thinking-block[open] summary { border-bottom: 1px solid rgba(124,58,237,0.1); }
.thinking-block.thinking-live { border-color: rgba(124,58,237,0.4); }
.thinking-block.thinking-live summary { color: rgba(167,139,250,0.9); }
.thinking-pulse {
    display: inline-block;
    margin-left: 4px;
    animation: pulse-fade 1s ease-in-out infinite;
}
@keyframes pulse-fade { 0%,100%{opacity:.3} 50%{opacity:1} }
.thinking-block-body {
    padding: 8px 10px;
    white-space: pre-wrap;
    font-family: var(--font);
    max-height: 220px;
    overflow-y: auto;
    line-height: 1.5;
}

/* ── Settings Drawer ─────────────────────────────────────────────────────────── */
.settings-body {
    padding: 4px 0 16px;
    overflow-y: auto;
    flex: 1;
}
.settings-section {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }
.settings-section-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.settings-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    line-height: 1.5;
}
.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.settings-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 60px;
    flex-shrink: 0;
}
.settings-select, .settings-input {
    font-size: 12px;
    font-family: var(--font);
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    flex: 1;
}
.settings-select:focus, .settings-input:focus {
    outline: none;
    border-color: var(--accent);
}
.toggle-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.toggle-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
}
.toggle-item input[type=checkbox] { accent-color: var(--accent); }
.settings-save-hint {
    text-align: center;
    font-size: 11px;
    color: #22c55e;
    padding: 6px;
    opacity: 0;
    transition: opacity 0.3s;
}

/* ── Skin Selector ───────────────────────────────────────────────────────────── */
.skin-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.skin-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 8px 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-muted);
    transition: border-color 0.2s, color 0.2s;
}
.skin-btn:hover { border-color: var(--accent); color: var(--text); }
.skin-btn.active { border-color: var(--accent); color: var(--accent); }
.skin-preview {
    width: 36px;
    height: 22px;
    border-radius: 4px;
    display: block;
}
.skin-default  { background: linear-gradient(135deg, #06061a 50%, #7c3aed 50%); }
.skin-vapor    { background: linear-gradient(135deg, #1a0033 0%, #ff006e 50%, #00f5ff 100%); }
.skin-terminal { background: #000; border: 1px solid #00ff41; box-shadow: inset 0 0 8px rgba(0,255,65,0.6); }
.skin-paper    { background: linear-gradient(135deg, #f7f1e3 60%, #1e3a5f 60%); }
.skin-aurora   { background: linear-gradient(120deg, #7c3aed, #22d3ee 45%, #ec4899); }
.skin-bondi    { background: linear-gradient(180deg, #38bdf8 55%, #fde68a 55%); }

/* ── Thinking Depth Selector ─────────────────────────────────────────────────── */
.depth-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}
.depth-btn {
    padding: 6px 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, color 0.2s;
}
.depth-btn:hover { border-color: var(--accent); color: var(--text); }
.depth-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(124,58,237,0.1); }
.depth-cost-hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ── Skin CSS variables (applied to :root via JS) ─────────────────────────────
   Arctic skin needs light overrides for surfaces/text */
[data-skin="arctic"] {
    --surface:  #ffffff;
    --surface2: #f1f5f9;
    --border:   rgba(0,0,0,0.12);
    --text:     #1e293b;
    --text-muted: #64748b;
}

/* ── HA Site Selector ────────────────────────────────────────────────────────── */
.ha-site-row {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-right: 2px;
}
.ha-site-select {
    font-size: 12px;
    font-family: var(--font);
    color: var(--text-muted);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 6px;
    cursor: pointer;
    max-width: 140px;
    outline: none;
    transition: border-color 0.15s, color 0.15s;
}
.ha-site-select:hover,
.ha-site-select:focus {
    border-color: rgba(124,58,237,0.5);
    color: var(--text);
}
.add-site-btn {
    width: 26px;
    height: 26px;
    min-width: 26px;
    padding: 0;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
}
.add-site-btn:hover { color: #a78bfa; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
    background: rgba(13,13,34,0.95);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius);
    width: 100%;
    max-width: 420px;
    box-shadow: 0 32px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(124,58,237,0.08);
    overflow: hidden;
    backdrop-filter: blur(24px);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    font-weight: 700;
    background: linear-gradient(135deg, rgba(124,58,237,0.08), rgba(59,130,246,0.06));
}
.modal-body {
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.modal-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-top: 4px;
}
.modal-input {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    padding: 9px 12px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}
.modal-input:focus {
    border-color: rgba(124,58,237,0.5);
    box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}
.modal-error {
    margin: 0 22px;
    padding: 8px 12px;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.25);
    border-radius: var(--radius-sm);
    color: var(--error);
    font-size: 12px;
}
.modal-error.hidden { display: none; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
}
.modal-btn-cancel {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    padding: 7px 14px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.modal-btn-cancel:hover { border-color: var(--border-bright); color: var(--text); }
.modal-btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 16px;
    cursor: pointer;
    transition: opacity 0.15s;
    box-shadow: 0 2px 8px var(--accent-glow);
}
.modal-btn-primary:hover    { opacity: 0.9; }
.modal-btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Preferences Drawer ───────────────────────────────────────────────────── */

.prefs-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 190;
}
.prefs-overlay.hidden { display: none; }

.prefs-drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(380px, 100vw);
    background: var(--chrome-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-left: 1px solid var(--border-bright);
    display: flex;
    flex-direction: column;
    z-index: 195;
    transform: translateX(110%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 40px rgba(0,0,0,0.6);
}
.prefs-drawer.open { transform: translateX(0); }

.prefs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}
.prefs-title {
    font-size: 14px;
    font-weight: 700;
    color: #a78bfa;
    letter-spacing: 0.02em;
}

.prefs-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.prefs-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(167,139,250,0.7);
    margin-top: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.prefs-label {
    font-size: 12px;
    color: var(--text-muted, #94a3b8);
    margin-top: 2px;
}
.prefs-input,
.prefs-select,
.prefs-textarea {
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text, #e2e8f0);
    font-size: 13px;
    padding: 8px 10px;
    box-sizing: border-box;
    transition: border-color 0.15s;
    font-family: inherit;
}
.prefs-input:focus,
.prefs-select:focus,
.prefs-textarea:focus {
    outline: none;
    border-color: rgba(124,58,237,0.6);
}
.prefs-select { cursor: pointer; }
.prefs-textarea { resize: vertical; min-height: 80px; }

.prefs-save-btn {
    margin-top: 8px;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 0;
    cursor: pointer;
    transition: opacity 0.15s;
    box-shadow: 0 2px 10px rgba(124,58,237,0.4);
}
.prefs-save-btn:hover { opacity: 0.88; }

.prefs-status {
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 6px;
    text-align: center;
}
.prefs-status.hidden { display: none; }
.prefs-status-ok  { background: rgba(16,185,129,0.15); color: #6ee7b7; }
.prefs-status-err { background: rgba(239,68,68,0.12);  color: #fca5a5; }

/* ── Reaction bar ───────────────────────────────────────────────────────────── */
/* ── Inline message meta (model + cost) ────────────────────────────────────── */
.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    margin-left: 40px; /* align with bubble */
    opacity: 0;
    transition: opacity 0.2s;
}
.assistant-msg:hover .msg-meta { opacity: 1; }
.msg-meta-model {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid currentColor;
    opacity: 0.8;
}
.msg-meta-cost {
    font-size: 10px;
    color: var(--text-muted, rgba(255,255,255,0.35));
}
/* provider colours reused from .model-badge */
.msg-meta-model.provider-anthropic { color: rgba(255,150,50,0.9);  background: rgba(255,150,50,0.08);  border-color: rgba(255,150,50,0.25);  }
.msg-meta-model.provider-google    { color: rgba(66,133,244,0.9);  background: rgba(66,133,244,0.08);  border-color: rgba(66,133,244,0.25);  }
.msg-meta-model.provider-groq      { color: rgba(249,115,22,0.9);  background: rgba(249,115,22,0.08);  border-color: rgba(249,115,22,0.25);  }
.msg-meta-model.provider-xai       { color: rgba(16,185,129,0.9);  background: rgba(16,185,129,0.08);  border-color: rgba(16,185,129,0.25);  }
.msg-meta-model.provider-openrouter{ color: rgba(139,92,246,0.9);  background: rgba(139,92,246,0.08);  border-color: rgba(139,92,246,0.25);  }

.reaction-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}
.assistant-msg:hover .reaction-bar { opacity: 1; }
.reaction-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    padding: 2px 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.4;
}
.reaction-btn:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.15); }
.reaction-btn.reacted { background: rgba(124,58,237,0.2); border-color: rgba(124,58,237,0.4); }
.reaction-hint { font-size: 11px; color: var(--text-muted, #94a3b8); margin-left: 6px; }

/* ── Mobile: iOS keyboard + touch target fixes ───────────────────────────────── */

/* Ensure textarea never triggers iOS auto-zoom (requires font-size ≥ 16px) */
#message-input {
    font-size: 16px;
}

/* iOS safe-area keyboard clearance — env() is already on .input-area but
   reinforce it so the input row clears the software keyboard on iPhone */
@supports (padding: max(0px)) {
    .input-area {
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
}

/* Minimum 44×44px touch targets on all interactive input-area buttons */
.upload-btn, .mic-btn, .send-btn {
    min-width: 44px;
    min-height: 44px;
}
.send-btn {
    width: 44px;
    height: 44px;
}

/* Landscape mode: compress header so message area gets maximum vertical space */
@media (max-height: 500px) and (max-width: 900px) {
    :root { --header-h: 44px; }
    #header { padding: 0 6px; gap: 2px; }
    #header .logo-text { font-size: 12px; letter-spacing: 2px; }
    #sensors-btn, #insights-btn, #tts-btn, #audit-btn, #export-btn { display: none; }
    .input-area { padding: 6px 10px; }
    #message-input { font-size: 16px; max-height: 80px; }
}

/* Extra-small phones (≤380px) — e.g. iPhone SE, Galaxy S series */
@media (max-width: 380px) {
    :root { --header-h: 48px; }
    #header { padding: 0 6px; gap: 2px; }
    .ha-site-select { display: none; }
    .message { max-width: 96%; }
    .message-bubble { font-size: 13px; }
    .prompt-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .prompt-card { padding: 8px 9px; font-size: 11px; }
    .input-area { padding: 8px 8px; }
    #message-input { font-size: 16px; }
}

/* Prevent long URLs and code in messages from causing horizontal overflow */
.message-bubble pre, .message-bubble code {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ── iOS PWA — global touch improvements ─────────────────────────────────── */

/* Momentum scroll on every overflow-y container */
#messages, .conversation-list, .insights-list, .settings-body,
.artifacts-list, .ha-dashboard, .ha-grid {
    -webkit-overflow-scrolling: touch;
}

/* Remove default tap highlight on all interactive elements */
a, button, [role="button"], input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}

/* Sidebar bottom: clear home indicator on devices without a home button */
.sidebar {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* New-conversation button (bottom of sidebar) clears home indicator */
.sidebar-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* Settings/audit drawer mobile full-height fix */
@media (max-width: 600px) {
    .insights-drawer {
        position: fixed !important;
        inset: 0 !important;
        top: calc(var(--header-h) + env(safe-area-inset-top, 0px)) !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-height: none !important;
        border-radius: 0 !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* iPad (768–1024) — show sidebar always, wider input, bigger text */
@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-w: 220px; }
    #messages { padding: 28px 28px; }
    .message { max-width: 78%; }
    .message-bubble { font-size: 15px; }
}

/* Notch / Dynamic Island: ensure header always clears the sensor strip */
@supports (padding-top: env(safe-area-inset-top)) {
    #header {
        padding-top: max(env(safe-area-inset-top, 0px), 0px);
    }
    .sidebar-header {
        padding-top: max(env(safe-area-inset-top, 0px), 0px);
    }
}

/* iPhone Pro Max (430px) — slightly larger bubbles */
@media (min-width: 428px) and (max-width: 432px) {
    .message { max-width: 88%; }
    #messages { padding: 20px 14px; }
}

/* Focus ring for keyboard navigation (accessibility) */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Prevent overscroll bounce showing white background on dark app */
html, body { overscroll-behavior: none; }
#messages   { overscroll-behavior-y: contain; }

/* ═══════════════════════════════════════════════════════════════════════════════
   SKINS — complete palette per body[data-skin]
   Each redefines ~20 vars; some also add fonts, overlays, or animated bg.
═══════════════════════════════════════════════════════════════════════════════ */

/* ── VAPOR — synthwave dreamspace ──────────────────────────────────────────── */
body[data-skin="vapor"] {
    --bg:            #14002a;
    --bg2:           #2a0050;
    --surface:       rgba(255,0,170,0.06);
    --surface-solid: #1c0033;
    --surface2:      rgba(0,245,255,0.07);
    --surface3:      rgba(0,245,255,0.14);
    --border:        rgba(255,0,170,0.30);
    --border-bright: rgba(0,245,255,0.55);
    --chrome-bg:     rgba(20,0,42,0.78);
    --accent:        #ff006e;
    --accent2:       #00f5ff;
    --accent-glow:   rgba(255,0,170,0.55);
    --accent-hover:  #d4005c;
    --text:          #ffe5f7;
    --text-muted:    rgba(255,229,247,0.66);
    --text-dim:      rgba(255,229,247,0.38);
    --success:       #00ff9f;
    --warning:       #ffcb00;
    --error:         #ff4757;
    --user-bg:       linear-gradient(135deg, #00f5ff, #ff006e);
    --user-text:     #14002a;
    --asst-grad:     linear-gradient(135deg, rgba(255,0,110,0.42), rgba(0,245,255,0.30));
    --asst-border:   rgba(255,0,170,0.55);
    --asst-glow:     rgba(255,0,170,0.45);
    background:
        radial-gradient(ellipse at 50% 100%, rgba(255,0,110,0.35), transparent 60%),
        radial-gradient(ellipse at 50% 0%,   rgba(0,245,255,0.18), transparent 55%),
        linear-gradient(180deg, #14002a 0%, #2a0050 70%, #4a0080 100%);
    background-attachment: fixed;
}
body[data-skin="vapor"] .welcome-logo {
    background: linear-gradient(180deg, #fff 0%, #ff006e 50%, #00f5ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    filter: drop-shadow(0 0 14px rgba(0,245,255,0.7)) drop-shadow(0 0 28px rgba(255,0,110,0.5));
}
body[data-skin="vapor"]::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 999;
    background: repeating-linear-gradient(
        180deg,
        transparent 0px,
        transparent 2px,
        rgba(255,255,255,0.025) 3px
    );
}

/* ── TERMINAL — CRT phosphor ───────────────────────────────────────────────── */
body[data-skin="terminal"] {
    --bg:            #000;
    --bg2:           #001a00;
    --surface:       rgba(0,255,65,0.04);
    --surface-solid: #001100;
    --surface2:      rgba(0,255,65,0.08);
    --surface3:      rgba(0,255,65,0.14);
    --border:        rgba(0,255,65,0.30);
    --border-bright: rgba(0,255,65,0.65);
    --chrome-bg:     rgba(0,0,0,0.92);
    --accent:        #00ff41;
    --accent2:       #00cc33;
    --accent-glow:   rgba(0,255,65,0.55);
    --accent-hover:  #00cc33;
    --text:          #00ff41;
    --text-muted:    rgba(0,255,65,0.66);
    --text-dim:      rgba(0,255,65,0.38);
    --success:       #00ff41;
    --warning:       #ffcc00;
    --error:         #ff3030;
    --user-bg:       #00ff41;
    --user-text:     #000;
    --asst-grad:     transparent;
    --asst-border:   rgba(0,255,65,0.55);
    --asst-glow:     rgba(0,255,65,0.30);
    --font:          'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
    background: #000;
    text-shadow: 0 0 2px rgba(0,255,65,0.55);
}
body[data-skin="terminal"] .welcome-logo {
    background: none;
    -webkit-background-clip: initial;
    background-clip: initial;
    -webkit-text-fill-color: #00ff41;
    color: #00ff41;
    text-shadow: 0 0 6px rgba(0,255,65,0.9), 0 0 16px rgba(0,255,65,0.5);
    filter: none;
    font-family: var(--mono);
}
body[data-skin="terminal"] .welcome-tagline::after {
    content: '_';
    margin-left: 4px;
    animation: term-blink 1s steps(2) infinite;
}
@keyframes term-blink { 0%,49% { opacity: 1 } 50%,100% { opacity: 0 } }
body[data-skin="terminal"]::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 999;
    background: repeating-linear-gradient(
        180deg,
        rgba(0,0,0,0) 0px,
        rgba(0,0,0,0) 2px,
        rgba(0,0,0,0.18) 3px
    );
}

/* ── PAPER — analog notebook (light theme) ─────────────────────────────────── */
body[data-skin="paper"] {
    --bg:            #f5efe0;
    --bg2:           #ece4d0;
    --surface:       rgba(255,255,255,0.65);
    --surface-solid: #fffaef;
    --surface2:      rgba(120,90,40,0.06);
    --surface3:      rgba(120,90,40,0.12);
    --border:        rgba(60,40,20,0.18);
    --border-bright: rgba(60,40,20,0.40);
    --chrome-bg:     rgba(255,250,239,0.85);
    --accent:        #b8451f;
    --accent2:       #1e3a5f;
    --accent-glow:   rgba(184,69,31,0.25);
    --accent-hover:  #9a3a17;
    --text:          #1e3a5f;
    --text-muted:    rgba(30,58,95,0.66);
    --text-dim:      rgba(30,58,95,0.38);
    --success:       #15803d;
    --warning:       #b45309;
    --error:         #b91c1c;
    --user-bg:       #1e3a5f;
    --user-text:     #f5efe0;
    --asst-grad:     #fffaef;
    --asst-border:   rgba(60,40,20,0.25);
    --asst-glow:     rgba(60,40,20,0.10);
    --font:          'Iowan Old Style', 'Georgia', 'Palatino', serif;
    background:
        repeating-linear-gradient(
            180deg,
            transparent 0px,
            transparent 27px,
            rgba(30,58,95,0.07) 28px
        ),
        var(--bg);
    background-attachment: fixed;
}
body[data-skin="paper"] .welcome-logo {
    background: none;
    -webkit-background-clip: initial;
    background-clip: initial;
    -webkit-text-fill-color: #b8451f;
    color: #b8451f;
    filter: none;
    font-family: 'Iowan Old Style', Georgia, serif;
    letter-spacing: 3px;
}

/* ── AURORA — living gradient ──────────────────────────────────────────────── */
body[data-skin="aurora"] {
    --bg:            #0d0420;
    --bg2:           #1a0a40;
    --surface:       rgba(255,255,255,0.08);
    --surface-solid: #1a0a40;
    --surface2:      rgba(255,255,255,0.12);
    --surface3:      rgba(255,255,255,0.18);
    --border:        rgba(255,255,255,0.20);
    --border-bright: rgba(255,255,255,0.45);
    --chrome-bg:     rgba(13,4,32,0.55);
    --accent:        #22d3ee;
    --accent2:       #ec4899;
    --accent-glow:   rgba(34,211,238,0.55);
    --accent-hover:  #06b6d4;
    --text:          #ffffff;
    --text-muted:    rgba(255,255,255,0.72);
    --text-dim:      rgba(255,255,255,0.42);
    --success:       #34d399;
    --warning:       #fbbf24;
    --error:         #f87171;
    --user-bg:       rgba(255,255,255,0.92);
    --user-text:     #1a0a40;
    --asst-grad:     linear-gradient(135deg, rgba(34,211,238,0.30), rgba(236,72,153,0.30));
    --asst-border:   rgba(255,255,255,0.35);
    --asst-glow:     rgba(34,211,238,0.30);
    background:
        linear-gradient(120deg, #7c3aed 0%, #22d3ee 50%, #ec4899 100%);
    background-size: 300% 300%;
    background-attachment: fixed;
    animation: aurora-shift 24s ease infinite;
}
@keyframes aurora-shift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
body[data-skin="aurora"] .welcome-logo {
    background: linear-gradient(135deg, #fff, #fce7f3 50%, #cffafe);
    -webkit-background-clip: text;
    background-clip: text;
    filter: drop-shadow(0 0 18px rgba(255,255,255,0.7));
}
body[data-skin="aurora"] .dash-panel,
body[data-skin="aurora"] #header,
body[data-skin="aurora"] .sidebar,
body[data-skin="aurora"] .message-bubble.message-assistant {
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
}

/* ── BONDI — beach (light theme) ───────────────────────────────────────────── */
body[data-skin="bondi"] {
    --bg:            #e0f2fe;
    --bg2:           #fef3c7;
    --surface:       rgba(255,255,255,0.70);
    --surface-solid: #ffffff;
    --surface2:      rgba(2,132,199,0.08);
    --surface3:      rgba(2,132,199,0.16);
    --border:        rgba(2,132,199,0.20);
    --border-bright: rgba(2,132,199,0.45);
    --chrome-bg:     rgba(255,255,255,0.70);
    --accent:        #ef4444;
    --accent2:       #0284c7;
    --accent-glow:   rgba(239,68,68,0.40);
    --accent-hover:  #dc2626;
    --text:          #0c4a6e;
    --text-muted:    rgba(12,74,110,0.66);
    --text-dim:      rgba(12,74,110,0.38);
    --success:       #059669;
    --warning:       #d97706;
    --error:         #dc2626;
    --user-bg:       #0284c7;
    --user-text:     #ffffff;
    --asst-grad:     linear-gradient(135deg, #ffffff, #fef3c7);
    --asst-border:   rgba(2,132,199,0.30);
    --asst-glow:     rgba(253,224,71,0.40);
    background:
        linear-gradient(180deg, #7dd3fc 0%, #e0f2fe 45%, #fef3c7 100%);
    background-attachment: fixed;
}
body[data-skin="bondi"] .welcome-logo {
    background: linear-gradient(135deg, #ef4444 0%, #0284c7 100%);
    -webkit-background-clip: text;
    background-clip: text;
    filter: drop-shadow(0 2px 8px rgba(2,132,199,0.35));
}

/* ── Light-theme fixes (PAPER + BONDI) ─────────────────────────────────────── */
body[data-skin="paper"] .message-bubble.message-user,
body[data-skin="bondi"] .message-bubble.message-user {
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
body[data-skin="paper"] code,
body[data-skin="bondi"] code {
    background: rgba(0,0,0,0.06);
    color: var(--text);
}
body[data-skin="paper"] input,
body[data-skin="paper"] textarea,
body[data-skin="paper"] select,
body[data-skin="bondi"] input,
body[data-skin="bondi"] textarea,
body[data-skin="bondi"] select {
    color: var(--text);
}
/* Sidebar overlay (mobile) — always dark so panel reads against it */
.sidebar-overlay { background: rgba(0,0,0,0.55); }

/* Export dropdown — themed */
.export-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--chrome-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    z-index: 100;
    min-width: 160px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.export-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: transparent;
    border: 0;
    color: var(--text);
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
}
.export-item:hover { background: var(--surface2); }

/* ── Welcome cards ──────────────────────────────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 16px;
  text-align: center;
}
.welcome-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text, #e8e8f8);
  margin-bottom: 6px;
}
.welcome-sub {
  font-size: 0.85rem;
  color: var(--muted, rgba(255,255,255,0.45));
  margin-bottom: 24px;
}
.welcome-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 640px;
}
@media (max-width: 600px) {
  .welcome-cards-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 380px) {
  .welcome-cards-grid { grid-template-columns: 1fr; }
}
.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface, rgba(255,255,255,0.04));
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  font-family: inherit;
  color: inherit;
}
.welcome-card:hover {
  border-color: rgba(124,58,237,0.4);
  background: rgba(124,58,237,0.08);
  transform: translateY(-2px);
}
.welcome-card-icon {
  font-size: 1.4rem;
  line-height: 1;
}
.welcome-card-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text, #e8e8f8);
  line-height: 1.3;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   NEW FEATURES — Living Dashboard, Follow-up Chips, Sidebar Feed,
   Streaming Shimmer, Context Strip
═══════════════════════════════════════════════════════════════════════════════ */

/* ── Welcome screen — new wordmark layout ────────────────────────────────────── */
.welcome-wordmark {
    font-size: 44px;
    font-weight: 900;
    background: linear-gradient(135deg, #c4b5fd 0%, #818cf8 40%, #60a5fa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 8px;
    filter: drop-shadow(0 0 20px rgba(124,58,237,0.45));
    margin-bottom: 2px;
    user-select: none;
}
.welcome-greeting {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}
.welcome-date {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    letter-spacing: 0.3px;
}

/* ── Living Dashboard section ────────────────────────────────────────────────── */
.dash-live-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}

.live-headline {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    text-align: center;
    margin: 0 0 4px;
    line-height: 1.35;
}

/* Live sensor tiles — 2-col on mobile, 4-col on wide */
.live-tiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
@media (min-width: 500px) {
    .live-tiles { grid-template-columns: repeat(4, 1fr); }
}

.live-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 14px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    backdrop-filter: blur(12px);
    cursor: pointer;
    transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
    min-height: 80px;
    -webkit-tap-highlight-color: transparent;
}
.live-tile:hover,
.live-tile:active { background: var(--surface2); border-color: var(--border-bright); }

.live-tile-icon { font-size: 22px; line-height: 1; }
.live-tile-val  { font-size: 18px; font-weight: 800; color: var(--text); line-height: 1.1; }
.live-tile-lbl  { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }

/* Glow variants */
.tile-glow-green {
    border-color: rgba(34,197,94,0.45);
    box-shadow: 0 0 16px rgba(34,197,94,0.18) inset, 0 0 8px rgba(34,197,94,0.12);
}
.tile-glow-amber {
    border-color: rgba(245,158,11,0.45);
    box-shadow: 0 0 16px rgba(245,158,11,0.15) inset;
}
.tile-glow-red {
    border-color: rgba(239,68,68,0.45);
    box-shadow: 0 0 16px rgba(239,68,68,0.15) inset;
}

/* Quick-action strip */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 4px 0 8px;
}
.quick-action {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    padding: 8px 16px;
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.quick-action:hover,
.quick-action:active {
    background: rgba(124,58,237,0.14);
    border-color: rgba(124,58,237,0.4);
    color: var(--text);
}

/* ── Follow-up chips ─────────────────────────────────────────────────────────── */
.followup-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    padding-left: 44px; /* align with bubble, past avatar */
    animation: chips-in 0.25s ease both;
    transition: opacity 0.2s;
}
@keyframes chips-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.followup-chip {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    padding: 7px 16px;
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
    min-height: 36px; /* thumb target */
}
.followup-chip:hover,
.followup-chip:active {
    background: rgba(124,58,237,0.15);
    border-color: rgba(139,92,246,0.55);
    color: var(--text);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124,58,237,0.2);
}
@media (max-width: 480px) {
    .followup-chips { padding-left: 0; }
    .followup-chip  { padding: 8px 14px; font-size: 12.5px; }
}

/* ── Streaming shimmer on assistant bubble ───────────────────────────────────── */
@keyframes shimmer-sweep {
    0%   { background-position: -200% center; }
    100% { background-position: 200% center; }
}
.streaming-content {
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0.85) 25%,
        rgba(255,255,255,1)    50%,
        rgba(255,255,255,0.85) 75%
    );
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer-sweep 2s linear infinite;
    will-change: background-position;
}
.streaming-content p,
.streaming-content li,
.streaming-content span { -webkit-text-fill-color: inherit; }

/* ── Sidebar tabs ────────────────────────────────────────────────────────────── */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 9px 4px;
    cursor: pointer;
    position: relative;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.sidebar-tab:hover { color: var(--text); }
.sidebar-tab.active {
    color: var(--text);
}
.sidebar-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 12%;
    right: 12%;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

/* Feed badge on sidebar tab */
.feed-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 8px;
    background: var(--error);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    margin-left: 4px;
    vertical-align: middle;
}

/* ── Sidebar feed pane items ─────────────────────────────────────────────────── */
.sidebar-feed-list {
    padding: 6px 0;
}
.feed-item {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: default;
}
.feed-item:last-child { border-bottom: none; }
.feed-item-header {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 4px;
}
.feed-item-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.feed-dot-high   { background: var(--error);   box-shadow: 0 0 5px var(--error); }
.feed-dot-medium { background: var(--warning);  box-shadow: 0 0 5px var(--warning); }
.feed-dot-low    { background: var(--text-dim); }
.feed-item-title { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-item-time  { font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.feed-item-body  { font-size: 12px; color: var(--text-muted); line-height: 1.45; }
.feed-action-btn {
    margin-top: 6px;
    background: none;
    border: 1px solid rgba(124,58,237,0.3);
    border-radius: 6px;
    color: #a78bfa;
    font-size: 11.5px;
    font-family: var(--font);
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.feed-action-btn:hover { background: rgba(124,58,237,0.12); border-color: rgba(124,58,237,0.55); }

/* ── Context strip above input ───────────────────────────────────────────────── */
.context-strip {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 6px 18px 0;
    background: var(--chrome-bg);
    border-top: 1px solid var(--border);
}
.context-strip.hidden { display: none; }
.ctx-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 11px;
    padding: 3px 9px;
    white-space: nowrap;
}
.ctx-pill-time { color: var(--text-dim); }

