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

:root {
    --bg:         #0a0a0f;
    --surface:    #13131a;
    --card:       #1c1c2e;
    --card-hover: #232338;
    --border:     #2a2a3e;
    --primary:    #7c6af7;
    --primary-h:  #9d8ff7;
    --danger:     #ef4444;
    --danger-h:   #f87171;
    --success:    #22c55e;
    --text:       #e2e2ef;
    --muted:      #6b6b8a;
    --user-msg:   #1e2a3a;
    --ai-msg:     #1a1a2e;
    --user-accent:#3b82f6;
    --ai-accent:  #7c6af7;
    --radius-sm:  8px;
    --radius:     14px;
    --radius-lg:  20px;
    --safe-b:     env(safe-area-inset-bottom, 0px);
}

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

.hidden { display: none !important; }

/* ── Password Gate ────────────────────────────────────────────── */
.gate-overlay {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
    z-index: 1000;
    padding: 24px;
}

.gate-card {
    width: 100%; max-width: 360px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 32px 36px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

.gate-icon  { font-size: 48px; margin-bottom: 12px; display: block; }
.gate-title { font-size: 24px; font-weight: 700; letter-spacing: -.3px; margin-bottom: 4px; }
.gate-subtitle { color: var(--muted); font-size: 14px; margin-bottom: 28px; }

.gate-form  { display: flex; flex-direction: column; gap: 12px; }

.gate-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    padding: 14px 16px;
    text-align: center;
    letter-spacing: 4px;
    outline: none;
    transition: border-color .2s;
}
.gate-input:focus { border-color: var(--primary); }

.gate-btn {
    background: var(--primary);
    border: none; border-radius: var(--radius);
    color: #fff;
    font-size: 16px; font-weight: 600;
    padding: 14px;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.gate-btn:hover  { background: var(--primary-h); }
.gate-btn:active { transform: scale(.98); }

.gate-error { color: var(--danger); font-size: 14px; }

/* ── App Layout ───────────────────────────────────────────────── */
.app {
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh;
    background: var(--bg);
}

.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left  { display: flex; align-items: center; gap: 8px; }
.header-logo  { font-size: 22px; }
.header-title { font-size: 17px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 10px; }

.voice-badge {
    background: rgba(124,106,247,.18);
    border: 1px solid rgba(124,106,247,.4);
    border-radius: 20px;
    color: var(--primary-h);
    font-size: 12px; font-weight: 600;
    padding: 3px 10px;
}

.icon-btn {
    background: none; border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 16px; padding: 6px 10px;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }

/* ── Usage Strip ──────────────────────────────────────────────── */
.usage-strip {
    display: flex; align-items: center; gap: 7px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 6px 14px;
    font-size: 12px; font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    user-select: none;
    transition: background .15s;
}
.usage-strip:hover { background: var(--card); }

.usage-icon  { font-size: 13px; }
.usage-today { color: var(--text); }
.usage-total { color: var(--muted); }
.usage-sep   { color: var(--border); }
.usage-toggle {
    margin-left: auto;
    font-size: 10px;
    transition: transform .2s;
}
.usage-toggle.open { transform: rotate(180deg); }

.usage-detail {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow: hidden;
    animation: slide-down .18s ease;
}
@keyframes slide-down {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}

.usage-detail-inner {
    display: flex;
    padding: 10px 14px 12px;
    gap: 0;
}

.usage-col {
    flex: 1;
    min-width: 0;
}

.usage-col-label {
    font-size: 11px; font-weight: 700; letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

.usage-divider {
    width: 1px;
    background: var(--border);
    margin: 0 14px;
    align-self: stretch;
}

.usage-rows { display: flex; flex-direction: column; gap: 4px; }

.usage-row {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 12px;
}
.usage-row-label { color: var(--muted); }
.usage-row-value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.usage-row-value.cost { color: #a3e635; }

/* ── Tab Bar ──────────────────────────────────────────────────── */
.tab-bar {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab {
    flex: 1;
    background: none; border: none;
    color: var(--muted);
    font-size: 14px; font-weight: 500;
    padding: 11px 8px;
    cursor: pointer;
    position: relative;
    transition: color .15s;
}
.tab::after {
    content: '';
    position: absolute; bottom: 0; left: 0; right: 0;
    height: 2px;
    background: var(--primary);
    transform: scaleX(0);
    transition: transform .2s;
}
.tab.active { color: var(--text); }
.tab.active::after { transform: scaleX(1); }

/* ── Views ────────────────────────────────────────────────────── */
.view {
    display: none;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(96px + var(--safe-b));
}
.view.active { display: flex; flex-direction: column; }

/* ── Prompt Card ──────────────────────────────────────────────── */
.prompt-card {
    margin: 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 20px 16px;
}

.prompt-loading {
    color: var(--muted); font-size: 14px;
    display: flex; align-items: center; gap: 8px;
}

.prompt-text {
    font-size: 17px; font-weight: 500;
    line-height: 1.55;
    color: var(--text);
    margin-bottom: 12px;
}

.hear-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 13px;
    padding: 6px 12px;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.hear-btn:hover { color: var(--primary-h); border-color: var(--primary); }

/* ── Conversation ─────────────────────────────────────────────── */
.conversation {
    display: flex; flex-direction: column;
    gap: 12px;
    padding: 4px 16px 8px;
}

.msg {
    border-radius: var(--radius);
    padding: 14px 16px;
    max-width: 100%;
    animation: msg-in .25s ease;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.msg-user {
    background: var(--user-msg);
    border-left: 3px solid var(--user-accent);
    align-self: flex-start;
}

.msg-assistant {
    background: var(--ai-msg);
    border-left: 3px solid var(--ai-accent);
    align-self: flex-start;
}

.msg-label {
    font-size: 11px; font-weight: 700; letter-spacing: .6px;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.msg-user      .msg-label { color: var(--user-accent); }
.msg-assistant .msg-label { color: var(--ai-accent); }

.msg-text { font-size: 15px; line-height: 1.6; }

.msg-speak-btn {
    background: none; border: none;
    color: var(--ai-accent);
    font-size: 14px;
    padding: 4px 2px 0;
    margin-top: 4px;
    cursor: pointer;
    opacity: 0.5;
    display: block;
    transition: opacity .15s;
}
.msg-speak-btn:hover { opacity: 1; }

/* ── Live Transcript ──────────────────────────────────────────── */
.live-transcript {
    margin: 0 16px;
    padding: 14px 16px;
    background: rgba(59,130,246,.08);
    border: 1px dashed rgba(59,130,246,.35);
    border-radius: var(--radius);
    font-size: 15px; color: var(--text);
    min-height: 52px;
    line-height: 1.6;
}

.cursor-blink {
    animation: blink 1s step-end infinite;
    color: var(--user-accent);
    font-weight: 700;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Processing ───────────────────────────────────────────────── */
.processing {
    display: flex; align-items: center; gap: 10px;
    margin: 12px 16px;
    color: var(--muted); font-size: 15px;
}

.spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Text fallback ────────────────────────────────────────────── */
.text-fallback {
    margin: 12px 16px;
    display: flex; flex-direction: column; gap: 8px;
}

.fallback-textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
    padding: 12px 14px;
    resize: none; outline: none;
    font-family: inherit;
    line-height: 1.5;
}
.fallback-textarea:focus { border-color: var(--primary); }

.fallback-submit {
    background: var(--primary);
    border: none; border-radius: var(--radius);
    color: #fff;
    font-size: 15px; font-weight: 600;
    padding: 11px;
    cursor: pointer;
}

/* ── Controls (fixed bottom) ──────────────────────────────────── */
.controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    padding: 16px 24px calc(16px + var(--safe-b));
    background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.controls-row {
    display: flex; align-items: center; justify-content: center; gap: 14px;
}

/* Record button — large circle */
.record-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px;
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 0 0 0 rgba(124,106,247,.4);
    transition: background .15s, transform .1s;
}
.record-btn:hover  { background: var(--primary-h); transform: scale(1.05); }
.record-btn:active { transform: scale(.96); }

.record-icon { font-size: 24px; line-height: 1; }
.record-label { font-size: 11px; font-weight: 600; letter-spacing: .4px; }

/* Stop button */
.stop-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px;
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--danger);
    border: none;
    color: #fff;
    cursor: pointer;
    transition: background .15s;
}
.stop-btn:hover { background: var(--danger-h); }
.stop-icon  { font-size: 20px; }
.stop-label { font-size: 11px; font-weight: 600; }

.pulsing {
    animation: pulse-ring 1.5s ease-out infinite;
}
@keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
    70%  { box-shadow: 0 0 0 18px rgba(239,68,68,0); }
    100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

.end-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--muted);
    font-size: 14px; font-weight: 500;
    padding: 8px 20px;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.end-btn:hover { color: var(--text); border-color: var(--muted); }

/* ── Entries List ─────────────────────────────────────────────── */
.entries-list, .entries-loading, .entries-empty {
    padding: 16px;
}

.entries-loading, .entries-empty {
    color: var(--muted); font-size: 15px;
    padding: 32px 16px; text-align: center;
}

.entry-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.entry-card:hover { background: var(--card-hover); border-color: var(--primary); }

.entry-date {
    font-size: 12px; font-weight: 700; letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

.entry-prompt {
    font-size: 14px; font-weight: 500; color: var(--text);
    margin-bottom: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.entry-preview {
    font-size: 13px; color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Entry Detail ─────────────────────────────────────────────── */
.back-btn {
    display: inline-flex; align-items: center; gap: 4px;
    background: none; border: none;
    color: var(--primary);
    font-size: 15px;
    padding: 14px 16px 4px;
    cursor: pointer;
}

.entry-detail { padding: 8px 16px 24px; }

.entry-detail-header {
    margin-bottom: 20px;
}

.entry-detail-date  { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.entry-detail-prompt { font-size: 18px; font-weight: 600; line-height: 1.4; }

/* ── Continue conversation button ────────────────────────────── */
.continue-row {
    padding: 16px 16px 32px;
    display: flex; justify-content: center;
}

.continue-btn {
    background: var(--primary);
    border: none; border-radius: var(--radius-lg);
    color: #fff;
    font-size: 15px; font-weight: 600;
    padding: 13px 32px;
    cursor: pointer;
    transition: background .15s, transform .1s;
    width: 100%;
}
.continue-btn:hover  { background: var(--primary-h); }
.continue-btn:active { transform: scale(.98); }

/* ── Tap-to-play button (iOS autoplay fallback) ───────────────── */
.tap-to-play-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    margin-top: 10px; width: 100%;
    background: rgba(124,106,247,.12);
    border: 1px solid rgba(124,106,247,.35);
    border-radius: 20px;
    color: var(--primary-h);
    font-size: 13px; font-weight: 600;
    padding: 7px 14px;
    cursor: pointer;
    transition: background .15s;
}
.tap-to-play-btn:hover  { background: rgba(124,106,247,.22); }
.tap-to-play-btn:active { opacity: .7; }

/* ── Dot pulse animation ──────────────────────────────────────── */
.dot-pulse {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--muted);
    animation: dot-pulse-anim .8s ease-in-out infinite;
}
@keyframes dot-pulse-anim {
    0%, 100% { opacity: .4; transform: scale(.8); }
    50%       { opacity: 1;  transform: scale(1); }
}
