/* ---------- Themes ---------- */
:root, [data-theme="midnight"] {
  --bg:#0F1115; --panel:#14171D; --panel2:#1A1E26; --border:#2A2F3B;
  --text:#E8EAF0; --muted:#9AA1B2; --accent:#8B7BFF; --accent-ink:#0F1115; --user:#232838;
}
[data-theme="daylight"] {
  --bg:#F6F7FB; --panel:#FFFFFF; --panel2:#EEF0F6; --border:#D9DCE6;
  --text:#171A21; --muted:#5B6272; --accent:#5B45E6; --accent-ink:#FFFFFF; --user:#E6E8F7;
}
[data-theme="ocean"] {
  --bg:#0B1620; --panel:#0F1D2A; --panel2:#142638; --border:#22384D;
  --text:#E4EEF7; --muted:#93A9BC; --accent:#38BDF8; --accent-ink:#0B1620; --user:#17324A;
}
[data-theme="sunset"] {
  --bg:#1A1210; --panel:#211715; --panel2:#2A1D1A; --border:#3C2B26;
  --text:#F5E9E4; --muted:#BCA59C; --accent:#FF8A5B; --accent-ink:#1A1210; --user:#3A2621;
}
[data-theme="forest"] {
  --bg:#0E1512; --panel:#121C17; --panel2:#172420; --border:#263A31;
  --text:#E6F0EA; --muted:#9BB3A6; --accent:#3DDC97; --accent-ink:#0E1512; --user:#1D3329;
}

/* ---------- Base ---------- */
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{
  background:var(--bg); color:var(--text);
  font-family:'Hind Siliguri','Inter',system-ui,sans-serif;
  font-size:16px; line-height:1.55;
}
button,textarea{font:inherit;color:inherit}
button{cursor:pointer}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.app{display:flex;height:100dvh}

/* ---------- Sidebar ---------- */
.sidebar{
  flex:0 0 290px;width:290px;background:var(--panel);border-right:1px solid var(--border);
  display:flex;flex-direction:column;gap:20px;padding:18px 14px;overflow-y:auto;z-index:30;
}
.brand{display:flex;align-items:center;gap:10px;padding:0 4px}
.logo{width:34px;height:34px;border-radius:10px;background:var(--accent);color:var(--accent-ink);display:flex;align-items:center;justify-content:center}
.brand-name{font-size:20px;font-weight:700;letter-spacing:-.01em}
.btn-new,.btn-side{
  display:flex;align-items:center;gap:10px;min-height:44px;padding:0 14px;border-radius:12px;
  border:1px solid var(--border);background:var(--panel2);font-weight:500;
}
.btn-side{border-color:transparent;background:transparent;color:var(--muted)}
.btn-new:hover,.btn-side:hover{border-color:var(--accent)}
.label{font-size:13px;font-weight:600;color:var(--muted);padding:0 8px 6px}
.toollist{display:flex;flex-direction:column;gap:4px}
.tool{
  display:flex;align-items:center;gap:12px;min-height:44px;padding:0 12px;border-radius:10px;
  border:0;background:transparent;text-align:start;color:var(--muted);width:100%;
}
.tool:hover{background:var(--panel2)}
.tool.active{background:var(--panel2);color:var(--text);font-weight:600;box-shadow:inset 3px 0 0 var(--accent)}
.history-wrap{flex:1;min-height:0}
.history{display:flex;flex-direction:column;gap:2px}
.hist-row{display:flex;align-items:center;border-radius:10px}
.hist-row:hover,.hist-row.active{background:var(--panel2)}
.hist-item{flex:1;min-width:0;min-height:44px;padding:8px 12px;border:0;background:transparent;text-align:start;color:var(--muted);font-size:15px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hist-row.active .hist-item{color:var(--text)}
.hist-del{flex:0 0 44px;height:44px;border:0;background:transparent;color:var(--muted);border-radius:10px}
.hist-del:hover{color:var(--text)}
.empty-hist{padding:8px 12px;color:var(--muted);font-size:14px}

/* ---------- Main ---------- */
.main{flex:1;min-width:0;display:flex;flex-direction:column}
.topbar{display:flex;align-items:center;gap:8px;padding:12px 24px;border-bottom:1px solid var(--border)}
.title-block{flex:1;min-width:0}
.title-block h1{margin:0;font-size:20px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.sub{font-size:14px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.top-actions{display:flex;align-items:center;gap:8px}
.icon-btn{width:44px;height:44px;border-radius:12px;border:0;background:transparent;display:flex;align-items:center;justify-content:center;color:var(--text)}
.icon-btn:hover{background:var(--panel2)}
.menu-btn,.toolchips,.backdrop{display:none}
.seg{display:inline-flex;border:1px solid var(--border);border-radius:12px;background:var(--panel);padding:3px}
.seg button{min-height:38px;padding:0 14px;border:0;border-radius:9px;background:transparent;color:var(--muted);font-weight:500}
.seg button[aria-pressed="true"]{background:var(--accent);color:var(--accent-ink);font-weight:600}
.seg-lg button{min-height:44px;padding:0 22px}

.toolchips{gap:8px;padding:10px 24px;overflow-x:auto;border-bottom:1px solid var(--border)}
.chip{flex:0 0 auto;min-height:44px;padding:0 16px;border-radius:999px;border:1px solid var(--border);background:var(--panel2);color:var(--text);font-size:14px;white-space:nowrap}
.chip.active{background:var(--accent);color:var(--accent-ink);border-color:var(--accent);font-weight:600}

.messages{flex:1;overflow-y:auto;padding:28px 24px}
.messages-inner{max-width:780px;margin:0 auto;display:flex;flex-direction:column;gap:26px}

.empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:10px;padding:40px 0 10px}
.empty .logo{width:52px;height:52px;border-radius:16px}
.empty h2{margin:6px 0 0;font-size:26px}
.empty p{margin:0;color:var(--muted);max-width:480px}
.examples{display:flex;flex-direction:column;gap:10px;margin-top:18px;width:100%;max-width:560px}
.example{min-height:44px;padding:10px 16px;border-radius:14px;border:1px solid var(--border);background:var(--panel);text-align:start}
.example:hover{border-color:var(--accent)}

.msg{display:flex;gap:14px;align-items:flex-start}
.msg.user{justify-content:flex-end}
.bubble{max-width:82%;background:var(--user);border-radius:18px 18px 4px 18px;padding:12px 16px;white-space:pre-wrap;overflow-wrap:anywhere}
html[dir] .bubble{}
.avatar{flex:0 0 34px;width:34px;height:34px;border-radius:10px;background:var(--accent);color:var(--accent-ink);display:flex;align-items:center;justify-content:center}
.answer{flex:1;min-width:0}
.answer p{margin:0 0 10px}
.answer h4{margin:14px 0 6px;font-size:17px}
.answer ul{margin:0 0 10px;padding-inline-start:22px}
.answer li{margin-bottom:4px}
.actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px}
.act{min-height:44px;padding:0 14px;border-radius:10px;border:1px solid var(--border);background:transparent;color:var(--muted);font-size:14px}
.act:hover{color:var(--text);border-color:var(--accent)}
.error{color:#FF8A8A}
[data-theme="daylight"] .error{color:#B3261E}
.typing{display:flex;gap:5px;padding:12px 0}
.typing span{width:8px;height:8px;border-radius:50%;background:var(--muted);animation:blink 1.2s infinite}
.typing span:nth-child(2){animation-delay:.2s}.typing span:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,80%,100%{opacity:.25}40%{opacity:1}}

.composer-wrap{padding:0 24px 18px}
.composer{max-width:780px;margin:0 auto;background:var(--panel);border:1px solid var(--border);border-radius:20px;padding:12px 12px 10px 18px}
.composer:focus-within{border-color:var(--accent)}
.composer textarea{width:100%;resize:none;border:0;outline:0;background:transparent;font-size:16px;line-height:1.55;padding:4px 0;max-height:180px}
.composer-row{display:flex;align-items:center;justify-content:space-between;gap:8px}
.hint{font-size:13px;color:var(--muted)}
.send{width:44px;height:44px;border-radius:12px;border:0;background:var(--accent);color:var(--accent-ink);display:flex;align-items:center;justify-content:center}
.send:disabled{opacity:.5;cursor:not-allowed}
.footnote{max-width:780px;margin:8px auto 0;font-size:13px;color:var(--muted);text-align:center}

/* ---------- Layout: focus & topbar (drawer sidebar + chips) ---------- */
body[data-layout="focus"] .sidebar,
body[data-layout="topbar"] .sidebar{
  position:fixed;inset-block:0;inset-inline-start:0;transform:translateX(-102%);transition:transform .2s;
  box-shadow:0 0 40px rgba(0,0,0,.35);
}
body[data-layout="focus"] .menu-btn,
body[data-layout="topbar"] .menu-btn{display:flex}
body[data-layout="focus"] .toolchips,
body[data-layout="topbar"] .toolchips{display:flex}
body.drawer-open .sidebar{transform:none}
body.drawer-open .backdrop{display:block;position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:20}

body[data-layout="focus"] .messages-inner,
body[data-layout="focus"] .composer,
body[data-layout="focus"] .footnote{max-width:660px}
body[data-layout="focus"] .messages{font-size:17px}
body[data-layout="focus"] .avatar{display:none}
body[data-layout="focus"] .toolchips{justify-content:center;border-bottom:0}
body[data-layout="focus"] .topbar{border-bottom:0}

body[data-layout="topbar"] .messages-inner,
body[data-layout="topbar"] .composer,
body[data-layout="topbar"] .footnote{max-width:980px}
body[data-layout="topbar"] .toolchips{padding:0 24px;gap:0}
body[data-layout="topbar"] .chip{border:0;border-bottom:3px solid transparent;border-radius:0;background:transparent;color:var(--muted)}
body[data-layout="topbar"] .chip.active{background:transparent;color:var(--text);border-bottom-color:var(--accent)}

/* ---------- Mobile: sidebar always a drawer ---------- */
@media (max-width: 899px){
  .sidebar{position:fixed;inset-block:0;inset-inline-start:0;transform:translateX(-102%);transition:transform .2s;box-shadow:0 0 40px rgba(0,0,0,.35)}
  .menu-btn,.toolchips{display:flex}
  .topbar{padding:10px 12px}
  .messages{padding:20px 14px}
  .composer-wrap{padding:0 12px 14px}
  .toolchips{padding:10px 12px}
  .hint{display:none}
  .bubble{max-width:90%}
}

/* ---------- Settings dialog ---------- */
dialog{width:min(560px,calc(100vw - 24px));max-height:calc(100dvh - 24px);padding:0;border:1px solid var(--border);border-radius:20px;background:var(--panel);color:var(--text)}
dialog::backdrop{background:rgba(0,0,0,.6)}
.dlg-head{display:flex;align-items:center;justify-content:space-between;padding:14px 16px 14px 22px;border-bottom:1px solid var(--border)}
.dlg-head h2{margin:0;font-size:19px}
.dlg-body{padding:18px 22px 22px;display:flex;flex-direction:column;gap:22px;overflow-y:auto;max-height:calc(100dvh - 110px)}
.dlg-body h3{margin:0 0 10px;font-size:14px;font-weight:600;color:var(--muted)}
.theme-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px}
.theme-card{min-height:44px;padding:10px;border-radius:14px;border:2px solid var(--border);background:var(--panel2);text-align:start;display:flex;flex-direction:column;gap:8px}
.theme-card[aria-pressed="true"]{border-color:var(--accent)}
.theme-prev{display:flex;height:34px;border-radius:8px;overflow:hidden;border:1px solid rgba(128,128,128,.35)}
.theme-prev i{flex:1}
.theme-name{font-size:14px;font-weight:500}
.swatches{display:flex;flex-wrap:wrap;gap:10px}
.swatch{width:44px;height:44px;border-radius:50%;border:3px solid transparent;outline:2px solid var(--border)}
.swatch[aria-pressed="true"]{outline-color:var(--text)}
.swatch.auto{background:conic-gradient(#8B7BFF,#3DDC97,#FF8A5B,#38BDF8,#8B7BFF)}
.layout-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px}
.layout-card{padding:10px;border-radius:14px;border:2px solid var(--border);background:var(--panel2);text-align:start;display:flex;flex-direction:column;gap:8px;min-height:44px}
.layout-card[aria-pressed="true"]{border-color:var(--accent)}
.layout-prev{height:52px;border-radius:8px;border:1px solid var(--border);background:var(--bg);display:flex;overflow:hidden;gap:3px;padding:3px}
.layout-prev i{background:var(--border);border-radius:3px}
.layout-prev .a{flex:0 0 26%}
.layout-prev .b{flex:1;background:var(--panel)}
.layout-prev.focusp{justify-content:center}.layout-prev.focusp .b{flex:0 0 56%}
.layout-prev.topp{flex-direction:column}.layout-prev.topp .a{flex:0 0 22%}
.layout-name{font-size:14px;font-weight:600}
.layout-desc{font-size:13px;color:var(--muted)}
.btn-reset{align-self:flex-start;min-height:44px;padding:0 16px;border-radius:12px;border:1px solid var(--border);background:transparent;color:var(--muted)}
.btn-reset:hover{color:var(--text)}

/* ---------- Account + auth ---------- */
.account{display:flex;flex-direction:column;gap:8px}
.acct-mail{display:flex;flex-direction:column;padding:0 8px;min-width:0}
.acct-label{font-size:12px;color:var(--muted)}
.acct-email{font-size:14px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.acct-note{font-size:13px;color:var(--muted);padding:0 8px}
.field{display:flex;flex-direction:column;gap:6px;font-size:14px;color:var(--muted)}
.field input{min-height:44px;padding:0 14px;border-radius:12px;border:1px solid var(--border);background:var(--panel2);color:var(--text);font:inherit;font-size:16px}
.field input:focus{outline:2px solid var(--accent);outline-offset:1px}
.auth-msg{min-height:22px;font-size:14px;color:var(--muted)}
.send-wide{min-height:46px;border-radius:12px;border:0;background:var(--accent);color:var(--accent-ink);font-weight:600;font-size:16px}
.send-wide:disabled{opacity:.6;cursor:not-allowed}
.link-btn{min-height:44px;border:0;background:transparent;color:var(--accent);font-size:14px}
