/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
    --p: #6C63FF;
    --pd: #4F46E5;
    --pl: #EDE9FE;
    --pg: rgba(108,99,255,0.12);
    --acc: #4ECDC4;
    --ok: #10B981;
    --err: #EF4444;
    --warn: #F59E0B;
    --bg: #F0F4FF;
    --text: #1E1B4B;
    --muted: #6B7280;
    --light: #9CA3AF;
    --border: rgba(108,99,255,0.14);
    --sh: 0 4px 20px rgba(108,99,255,0.10);
    --r: 18px;
    --rsm: 12px;
    --tr: 0.25s ease;
}

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

/* ── SCREENS ── */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ══════════════ AUTH ══════════════ */
#auth {
    background: linear-gradient(155deg, #7C3AED 0%, #6C63FF 45%, #4F46E5 100%);
    overflow-y: auto; -webkit-overflow-scrolling: touch; align-items: center;
}

.hero { padding: 52px 24px 24px; text-align: center; color: #fff; }
.logo-box {
    width: 84px; height: 84px; margin: 0 auto 18px;
    background: rgba(255,255,255,0.18); backdrop-filter: blur(10px);
    border-radius: 24px; display: flex; align-items: center; justify-content: center;
    font-size: 42px; box-shadow: 0 8px 28px rgba(0,0,0,0.22);
    border: 1px solid rgba(255,255,255,0.25);
}
.hero h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.4px; margin-bottom: 8px; }
.hero p  { font-size: 16px; opacity: 0.82; }

.auth-card {
    border-radius: 26px 26px 0 0 !important;
    width: 100%; max-width: 480px; min-height: 420px;
}

.card {
    background: #fff; border-radius: var(--r);
    padding: 22px; box-shadow: var(--sh);
}

.tabs { display: flex; background: var(--bg); border-radius: var(--rsm); padding: 4px; margin-bottom: 24px; }
.tab {
    flex: 1; padding: 10px; border: none; background: transparent;
    border-radius: 10px; font-size: 15px; font-weight: 600;
    color: var(--muted); cursor: pointer; transition: var(--tr); font-family: inherit;
}
.tab.active { background: #fff; color: var(--p); box-shadow: var(--sh); }

.aform { display: none; flex-direction: column; gap: 14px; }
.aform.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.field input {
    padding: 13px 15px; border: 2px solid var(--border); border-radius: var(--rsm);
    font-size: 15px; color: var(--text); background: var(--bg); outline: none;
    transition: var(--tr); font-family: inherit;
}
.field input:focus { border-color: var(--p); background: #fff; box-shadow: 0 0 0 3px var(--pg); }

.btn-primary {
    padding: 14px; background: linear-gradient(135deg, var(--p), var(--pd));
    color: #fff; border: none; border-radius: var(--rsm); font-size: 16px;
    font-weight: 700; cursor: pointer; transition: var(--tr); font-family: inherit;
    box-shadow: 0 4px 14px rgba(108,99,255,0.38);
}
.btn-primary:active { transform: scale(0.98); }

.btn-ghost {
    padding: 12px; background: var(--pl); color: var(--p); border: none;
    border-radius: var(--rsm); font-size: 15px; font-weight: 600;
    cursor: pointer; transition: var(--tr); font-family: inherit;
}

.disclaimer {
    margin-top: 18px; padding: 11px 13px; background: #FFFBEB;
    border-radius: 10px; border-left: 3px solid var(--warn);
    font-size: 12px; color: #92400E; line-height: 1.55;
}

/* ══════════════ APP LAYOUT ══════════════ */
#app { background: var(--bg); }

.app-header {
    height: 58px; padding: 0 16px; display: flex; align-items: center;
    justify-content: space-between; background: #fff;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.brand {
    font-size: 20px; font-weight: 800; letter-spacing: -0.3px;
    background: linear-gradient(135deg, var(--p), var(--pd));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.page-title { font-size: 16px; font-weight: 700; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--p), var(--acc));
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: #fff; cursor: pointer; flex-shrink: 0;
}
.avatar.big { width: 52px; height: 52px; font-size: 20px; flex-shrink: 0; }

.views { flex: 1; overflow: hidden; position: relative; }

.view {
    position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    display: none; flex-direction: column; gap: 14px; padding: 16px;
    background: var(--bg);
}
.view.active { display: flex; }

.bottom-nav {
    height: 66px; background: #fff; border-top: 1px solid var(--border);
    display: flex; align-items: stretch; flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; border: none; background: transparent;
    cursor: pointer; color: var(--light); font-size: 10px; font-weight: 600;
    transition: var(--tr); position: relative; font-family: inherit;
}
.nav-btn span { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--p); }
.nav-btn.active::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 26px; height: 3px; background: var(--p); border-radius: 0 0 3px 3px;
}

/* ══════════════ MOOD ══════════════ */
.mood-card h2  { font-size: 18px; font-weight: 700; margin-bottom: 5px; }
.mood-card .sub { font-size: 14px; color: var(--muted); margin-bottom: 20px; }

.emojis { display: flex; justify-content: space-between; margin-bottom: 16px; }
.em-btn {
    width: 54px; height: 54px; border-radius: 50%; border: 3px solid transparent;
    background: var(--bg); cursor: pointer; transition: var(--tr);
    display: flex; align-items: center; justify-content: center;
    flex-direction: column; font-size: 0; /* hide default button text */
}
.em-btn span  { font-size: 26px; display: block; }
.em-btn small { font-size: 8px; font-weight: 700; color: var(--muted); display: block; margin-top: 1px; }
.em-btn.sel {
    border-color: var(--p); background: var(--pl);
    transform: scale(1.18); box-shadow: 0 4px 14px rgba(108,99,255,0.28);
}

.mood-chosen { font-size: 14px; font-weight: 600; color: var(--p); min-height: 20px; margin-bottom: 12px; }

.note-area {
    width: 100%; padding: 10px 13px; border: 2px solid var(--border); border-radius: var(--rsm);
    font-size: 14px; font-family: inherit; resize: none; outline: none;
    background: var(--bg); color: var(--text); transition: var(--tr); margin-bottom: 12px;
}
.note-area:focus { border-color: var(--p); background: #fff; }

.section-title { font-size: 15px; font-weight: 700; }

.mood-row {
    background: #fff; border-radius: var(--rsm); padding: 13px 15px;
    box-shadow: var(--sh); display: flex; align-items: flex-start; gap: 13px;
}
.mr-emoji { font-size: 28px; flex-shrink: 0; }
.mr-date  { font-size: 12px; color: var(--muted); font-weight: 500; }
.mr-lbl   { font-size: 15px; font-weight: 600; }
.mr-note  { font-size: 13px; color: var(--muted); margin-top: 2px; }

.empty-state { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty-state span { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-state h3 { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 6px; }

/* ══════════════ CHAT ══════════════ */
#v-chat { padding: 0; gap: 0; }

.chat-topics {
    padding: 12px 14px; background: #fff; border-bottom: 1px solid var(--border);
    display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
}
.chat-topics::-webkit-scrollbar { display: none; }
.chip {
    padding: 6px 13px; border-radius: 20px; border: 2px solid var(--border);
    background: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
    white-space: nowrap; color: var(--muted); transition: var(--tr); font-family: inherit; flex-shrink: 0;
}
.chip.on { border-color: var(--p); background: var(--p); color: #fff; }

.chat-messages {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 14px 13px 8px; display: flex; flex-direction: column; gap: 10px;
}

.msg { max-width: 82%; animation: msgIn 0.22s ease; }
@keyframes msgIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.msg.u { align-self: flex-end; }
.msg.a { align-self: flex-start; }
.bubble { padding: 11px 14px; border-radius: 18px; font-size: 15px; line-height: 1.55; }
.msg.u .bubble { background: linear-gradient(135deg, var(--p), var(--pd)); color: #fff; border-bottom-right-radius: 4px; }
.msg.a .bubble { background: #fff; color: var(--text); border-bottom-left-radius: 4px; box-shadow: var(--sh); }
.msg-time { font-size: 11px; color: var(--light); margin-top: 3px; padding: 0 3px; }
.msg.u .msg-time { text-align: right; }

.typing-wrap { display: flex; gap: 5px; padding: 12px 14px; background: #fff; border-radius: 18px; border-bottom-left-radius: 4px; box-shadow: var(--sh); align-self: flex-start; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--light); animation: dotPop 1.4s infinite; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPop { 0%,80%,100%{transform:scale(0.7);opacity:0.4;} 40%{transform:scale(1);opacity:1;} }

.chat-disc {
    background: #FFFBEB; border-top: 1px solid #FDE68A; padding: 7px 14px;
    font-size: 11px; color: #92400E; text-align: center; flex-shrink: 0;
}
.chat-bar {
    padding: 10px 12px; background: #fff; border-top: 1px solid var(--border);
    flex-shrink: 0; display: flex; gap: 9px; align-items: flex-end;
}
.chat-input {
    flex: 1; padding: 10px 14px; border: 2px solid var(--border); border-radius: 22px;
    font-size: 15px; font-family: inherit; outline: none; resize: none;
    max-height: 100px; background: var(--bg); color: var(--text); transition: var(--tr); line-height: 1.4;
}
.chat-input:focus { border-color: var(--p); background: #fff; }
.send-btn {
    width: 40px; height: 40px; border-radius: 50%; border: none; flex-shrink: 0;
    background: linear-gradient(135deg, var(--p), var(--pd)); color: #fff; font-size: 16px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: var(--tr); box-shadow: 0 4px 12px rgba(108,99,255,0.38);
}
.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ══════════════ SETTINGS ══════════════ */
.profile-row { display: flex; align-items: center; gap: 14px; }
.profile-name  { font-size: 17px; font-weight: 700; }
.profile-email { font-size: 13px; color: var(--muted); margin-top: 2px; }

.api-section h3 { font-size: 16px; font-weight: 700; margin-bottom: 5px; }
.api-section p  { font-size: 13px; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }
.api-row { display: flex; gap: 8px; margin-bottom: 8px; }
.api-row input {
    flex: 1; padding: 11px 13px; border: 2px solid var(--border); border-radius: var(--rsm);
    font-size: 14px; font-family: monospace; outline: none; background: var(--bg); color: var(--text);
}
.api-row input:focus { border-color: var(--p); }
.api-section small { font-size: 12px; color: var(--muted); }

.row-btn {
    width: 100%; padding: 13px 16px; border: none; border-radius: var(--rsm);
    background: var(--bg); color: var(--text); font-size: 15px; font-weight: 600;
    cursor: pointer; text-align: left; transition: var(--tr); font-family: inherit;
    display: block; margin-bottom: 6px;
}
.row-btn:last-child { margin-bottom: 0; }
.row-btn:active { background: var(--pl); }
.row-btn.danger { color: var(--err); }

/* ══════════════ TOASTS ══════════════ */
#toasts {
    position: fixed; top: 68px; left: 50%; transform: translateX(-50%);
    z-index: 9999; display: flex; flex-direction: column; gap: 7px; pointer-events: none;
}
.toast {
    padding: 10px 18px; border-radius: 22px; font-size: 14px; font-weight: 600;
    color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,0.18); white-space: nowrap;
    animation: tIn 0.28s ease;
}
@keyframes tIn { from{opacity:0;transform:translateY(-12px) scale(0.92);} to{opacity:1;transform:translateY(0) scale(1);} }
.toast.ok   { background: var(--ok); }
.toast.err  { background: var(--err); }
.toast.info { background: var(--p); }

/* ══════════════ SCROLLBAR ══════════════ */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
