/**
 * AI Assistant — Kotlin-style, matches news/contacts/schedule
 * #F8FAFC, #1E293B, 48px tap targets
 */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --bg: #F8FAFC;
    --text: #1E293B;
    --muted: #64748B;
    --accent: #2563EB;
    --accent-hover: #1d4ed8;
    --success: #22c55e;
    --border: #e2e8f0;
    --card: #FFFFFF;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 18px;
    line-height: 1.5;
    overflow: hidden;
}

.top-nav {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.top-nav a {
    color: var(--muted);
    text-decoration: none;
}
.top-nav a:hover { color: var(--accent); }
.top-nav a[href*="aimate"] { color: var(--accent); font-weight: 600; }

.header-account {
    padding: 6px 16px 8px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.35;
}
.header-user-line {
    font-weight: 600;
    color: #475569;
    font-size: 0.85rem;
}
.header-stt-line {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.72rem;
    color: #64748b;
    margin-top: 2px;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    max-width: 480px;
    margin: 0 auto;
}

/* Personality + mic on same row */
.personality-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.personality-cell {
    flex: 1;
    min-width: 0;
}
.personality-select {
    width: 100%;
    min-height: 52px;
    padding: 12px 16px;
    font-size: 18px;
    font-weight: 500;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 44px;
}
.personality-select:focus {
    outline: none;
    border-color: var(--accent);
}
/* Transcript sections */
.transcript-section {
    margin-bottom: 16px;
}
.section-label {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}
.transcript-box {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    min-height: 60px;
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text);
    border: 1px solid var(--border);
}
.transcript-box.placeholder { color: var(--muted); }
.transcript-box.raw-input { min-height: 80px; }
.transcript-box.mic-buffer { background: rgba(37, 99, 235, 0.06); }
.transcript-box.ai-resolved { border-left: 4px solid var(--accent); }

/* Mic toggle — 56px tap target */
.hdr-mic-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    padding: 0;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.hdr-mic-btn:hover, .hdr-mic-btn:focus {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.08);
}
.hdr-mic-btn:active { transform: scale(0.96); }
.hdr-mic-btn.listening {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.12);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}
.hdr-mic-btn.listening .mic-icon { animation: pulse 1.2s ease-in-out infinite; }
.mic-icon { font-size: 1.75rem; line-height: 1; }
.mic-icon.mic-off { opacity: 0.6; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Mic bar — only while listening (no idle prompt) */
.mic-bar {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(34, 197, 94, 0.1);
    border-bottom: 1px solid var(--border);
}
.mic-bar.show {
    display: flex;
}
.mic-bar-text {
    font-size: 0.95rem;
    color: var(--text);
}
.mic-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
    opacity: 0;
    transition: opacity 0.2s;
}
.mic-bar.show .mic-dot {
    opacity: 1;
    animation: pulse 1.5s ease-in-out infinite;
}

/* Main — chat-first layout */
.main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 12px 16px 16px;
    gap: 8px;
}
.chat-thread-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.thread-status {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
    min-height: 1.2em;
}
.thread-status.error {
    color: #dc2626;
}
.stt-preview {
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
    font-style: italic;
    line-height: 1.35;
    max-height: 4.5em;
    overflow: hidden;
}
.stt-preview:not([hidden]) {
    display: block;
}

/* Input row — like ai_chat */
.input-row {
    display: flex;
    gap: 10px;
    align-items: center;
}
.input-row input {
    flex: 1;
    min-height: 48px;
    padding: 12px 16px;
    font-size: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    outline: none;
}
.input-row input:focus { border-color: var(--accent); }
.send-btn {
    min-height: 48px;
    min-width: 80px;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    z-index: 1000;
    opacity: 0;
    transition: transform 0.2s, opacity 0.2s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ── Persona avatars (hero + strip) ───────────────────────── */
.persona-visual {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 12px 16px 8px;
    background: linear-gradient(180deg, #f1f5f9 0%, var(--card) 100%);
    border-bottom: 1px solid var(--border);
}
.persona-visual[hidden] { display: none !important; }

.persona-hero-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.persona-hero {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg);
    border: 3px solid var(--card);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}
.persona-hero-label {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    text-align: center;
    max-width: 280px;
    line-height: 1.25;
}

.persona-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: 100%;
}
.persona-strip-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 4px;
    min-width: 56px;
    min-height: 56px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 12px;
    -webkit-tap-highlight-color: transparent;
}
.persona-strip-btn img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.persona-strip-btn span {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--muted);
    max-width: 72px;
    text-align: center;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.persona-strip-btn:hover img {
    border-color: var(--accent);
}
.persona-strip-btn.active img {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
}
.persona-strip-btn.active span {
    color: var(--accent);
}

/* Hero + avatar strip + hub tabs: reserve main area — show only while mic is on or TTS is playing */
.app:not(.aimate-talking) #personaVisual:not([hidden]) {
    display: none !important;
}
.app:not(.aimate-talking) #hubTabs:not(:empty) {
    display: none !important;
}
/* When badges are collapsed, use the legacy dropdown to pick AI (hub tabs still in DOM but hidden) */
.app:not(.aimate-talking) #personalityRow .personality-cell {
    display: block !important;
}

/* ── Select AI + Hub Tabs ─────────────────────────────────── */
.hub-toolbar {
    display: flex;
    align-items: center;
    padding: 10px 16px 8px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.btn-select-ai {
    min-height: 44px;
    padding: 8px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--bg);
    border: 2px solid var(--accent);
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
}
.btn-select-ai:active {
    transform: scale(0.98);
}

.ai-picker-modal.hidden { display: none !important; }
.ai-picker-modal:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding:
        max(8px, env(safe-area-inset-top, 0px))
        max(8px, env(safe-area-inset-right, 0px))
        max(8px, env(safe-area-inset-bottom, 0px))
        max(8px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
}
@media (min-width: 600px) {
    .ai-picker-modal:not(.hidden) {
        justify-content: center;
    }
}
.ai-picker-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}
/* Panel is a flex column: fixed max height, inner region scrolls (mobile-safe) */
.ai-picker-panel {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: 82vh; /* fallback older browsers */
    max-height: min(82dvh, 640px);
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--card);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--border);
    pointer-events: auto;
}
@media (min-width: 600px) {
    .ai-picker-panel {
        border-radius: 16px;
        max-height: 85vh;
        max-height: min(85dvh, 680px);
    }
}
.ai-picker-header {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 12px 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}
.ai-picker-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 12px 16px max(20px, env(safe-area-inset-bottom, 12px));
}
.ai-picker-close {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    margin: -6px -4px 0 0;
    border: none;
    background: var(--bg);
    font-size: 1.5rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    border-radius: 10px;
    border: 1px solid var(--border);
}
.ai-picker-title {
    margin: 4px 0 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.25;
    flex: 1;
    min-width: 0;
}
.ai-picker-hint {
    margin: 0 0 12px;
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.45;
}
.ai-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding-bottom: 8px;
}
@media (min-width: 400px) {
    .ai-picker-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.ai-picker-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    min-height: 0;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    text-align: center;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ai-picker-tile img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}
.ai-picker-tile:hover,
.ai-picker-tile:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}
.ai-picker-tile.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.hub-tabs-row {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.hub-tabs-row::-webkit-scrollbar { display: none; }
.hub-tabs-row:empty { display: none; }

.hub-tab {
    flex-shrink: 0;
    min-height: 48px;
    padding: 10px 20px;
    font-size: 16px;
    font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.hub-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.hub-tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

/* Hide personality dropdown when hub tabs are visible and we're in "talking" mode (badges shown) */
.app.aimate-talking .hub-tabs-row:not(:empty) ~ .personality-row .personality-cell { display: none !important; }

/* ── Chat thread (single scroll, like typical AI chat) ─────── */
.chat-thread {
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    -webkit-overflow-scrolling: touch;
}

.chat-bubble {
    max-width: 90%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 1rem;
    line-height: 1.5;
    word-wrap: break-word;
}
.chat-bubble.user {
    align-self: flex-end;
    margin-left: auto;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 6px;
}
.chat-bubble.assistant {
    align-self: flex-start;
    margin-right: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.chat-empty {
    text-align: center;
    color: var(--muted);
    font-size: 0.92rem;
    padding: 28px 12px;
    line-height: 1.45;
}

