/* Saffron (deep yellow) theme: default */
:root{
  --bg:#fff8e6;
  --panel:#ffffff;
  --ink:#1b1914;
  --muted:#6b5f3a;
  --brand:#b7791f;      /* golden brown */
  --brand-2:#f6ad55;    /* deep yellow accent */
  --ok:#15803d;
  --bad:#b91c1c;
  --chip:#fff2cc;
  --shadow: 0 6px 24px rgba(0,0,0,.10);
  --radius: 14px;
  --ring: rgba(247, 177, 66, .25);
  --border: rgba(0,0,0,.08);
  /* --chat-max: 900px; */
}

/* Dark theme variables */
[data-theme="dark"]{
  --bg:#0b0f19;
  --panel:#121829;
  --ink:#eaeefb;
  --muted:#9aa3b2;
  --brand:#6ee7b7;
  --brand-2:#f59e0b;
  --ok:#34d399;
  --bad:#ef4444;
  --chip:#1b2338;
  --shadow: 0 12px 40px rgba(0,0,0,.45);
  --ring: rgba(110,231,183,.3);
  --border:#1f2a44;
}

*{ box-sizing:border-box; -webkit-tap-highlight-color: rgba(0,0,0,0.1); }

body{
  margin:0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
html,body{ height:100%; overflow:hidden;}
/* app shell */
.layout{
  height:100dvh;
  overflow:hidden;
  display:grid; grid-template-columns: 310px 1fr;
  min-height: 100dvh;
  gap:12px; padding:12px;
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.scrollable{ overflow:auto; }

/* toasts */
#toasts{
  position: fixed; top: 12px; right: 12px; z-index: 9999;
  display:flex; flex-direction:column; gap:8px;
}
.toast{
  background:#111; color:#fff; padding:10px 14px; border-radius:12px;
  box-shadow:var(--shadow); font-size:14px;
}

/* sidebar */
.sidebar{
  background: var(--panel);
  border:1px solid var(--border); border-radius:16px; box-shadow:var(--shadow);
  padding:12px; display:flex; flex-direction:column; gap:12px; min-height:0;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
}
[data-theme="dark"] .sidebar{
  background: linear-gradient(160deg, #0f172a, #0c1222);
}
.side-header{ display:flex; align-items:center; justify-content:space-between; position:sticky; top:0; background:transparent; padding-bottom:4px; }
.brand-mini{ display:flex; align-items:center; gap:10px; font-weight:700; }
.brand-mini img{ width:28px; height:28px; }
.icon-btn{ background:var(--panel); color:var(--ink); border:1px solid var(--border); border-radius:10px; padding:8px 10px; cursor:pointer; }
.only-mobile{ display:none; }

.primary{ background:var(--brand); color:#fff; border:none; }
.ghost{ background:transparent; color:var(--ink); border:1px dashed var(--border); }
.full{ width:100%; }
.side-actions{ display:flex; flex-direction:column; gap:8px; }

.section-title{ font-size:12px; letter-spacing:.06em; color:var(--muted); text-transform:uppercase; margin-top:4px; }
.list{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:6px; min-height:0; }
.list li{ display:flex; align-items:center; justify-content:space-between; gap:6px; background: var(--panel); border:1px solid var(--border); border-radius:12px; padding:8px; }
.list li .left{ display:flex; align-items:center; gap:8px; min-width:0; }
.folder-dot{ width:8px; height:8px; border-radius:50%; background:var(--brand); }
.list .title{ white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.row-btns{ display:flex; gap:6px; }
.small{ font-size:12px; color:var(--muted); }

/* off-canvas behavior */
.offcanvas{ position:relative; }
.scrim{
  display:none; position:fixed; inset:0; background:rgba(0,0,0,.45);
  z-index: 20; pointer-events:none;
}

/* panel & header/footer */
.panel{ display:flex; flex-direction:column; gap:12px; min-width:0; min-height:0; align-items:center; }
.header{
  display:flex; align-items:center; justify-content:space-between; padding:12px 14px;
  border:1px solid var(--border); background: var(--panel); border-radius:16px; box-shadow:var(--shadow);
}
[data-theme="dark"] .header{
  background: linear-gradient(160deg, #0f172a, #0b1120);
}
.sticky-top{ position: sticky; top: calc(12px + env(safe-area-inset-top)); z-index: 10; }
.sticky-bottom{ position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 10; }

.brand{ display:flex; align-items:center; gap:12px; }
.vera-icon{ width:44px; height:44px; }
.titles h1{ margin:0; font-size:20px; }
.subtitle{ font-size:12px; color:var(--brand); opacity:.85; }

/* header controls cluster */
.header-controls{ display:flex; align-items:center; gap:12px; }
.header-controls .field{ display:flex; align-items:center; gap:8px; }
.header-controls .field select{
  background:var(--panel); color:var(--ink); border:1px solid var(--border);
  border-radius:10px; padding:8px;
}

.field{ display:flex; align-items:center; gap:8px; }
.field select{
  background:var(--panel); color:var(--ink); border:1px solid var(--border);
  border-radius:10px; padding:8px;
}
.user-pill{ background:var(--panel); border:1px solid var(--border); padding:6px 8px; border-radius:999px; font-size:12px; color:var(--brand); }

/* switches */
.switch{ position:relative; display:inline-block; width:48px; height:28px; }
.switch input{ display:none; }
.slider{ position:absolute; inset:0; background:#e5e7eb; border-radius:999px; transition:.2s; }
.slider:before{ content:''; position:absolute; width:22px; height:22px; left:3px; top:3px; background:#fff; border-radius:50%; transition:.2s; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.switch input:checked + .slider{ background:var(--brand); }
.switch input:checked + .slider:before{ transform: translateX(20px); }

/* chat area */
.chat{
  padding: 10px; display:flex; flex-direction:column; gap:12px;
  border:1px solid var(--border); background: var(--panel);
  border-radius:16px; box-shadow:var(--shadow);
  min-height:0; flex:1;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
}
[data-theme="dark"] .chat{
  background: radial-gradient(1000px 400px at 70% -10%, #121a2e 0%, #0c1222 60%);
}
.user, .bot{
  max-width: min(900px, 100%);
  border-radius: 14px; padding: 12px 14px; line-height:1.6; border:1px solid var(--border);
  width: fit-content;
}
.user{ align-self:flex-end; background: rgba(21,128,61,.07); }
.bot{ align-self:flex-start; background: rgba(0,0,0,.03); }
[data-theme="dark"] .bot{ background:#0c162b; }
.bot h1,h2,h3{ margin:.3em 0; }
.bot pre code{ display:block; padding:12px; background:rgba(0,0,0,.06); border:1px solid var(--border); border-radius:12px; overflow:auto; }
.code-actions{ display:flex; justify-content:flex-end; margin-top:6px; }
.copy-btn{ border:1px solid var(--border); background:var(--panel); color:var(--ink); padding:4px 8px; border-radius:8px; cursor:pointer; }

.welcome{ background: rgba(246,173,85,.12); border-left:3px solid var(--brand-2); }
.bot-icon{ width:56px; height:56px; display:block; margin-bottom:6px; }
.chips{ display:flex; gap:8px; flex-wrap:wrap; }
.chip{ background: var(--chip); color:#111; border:1px solid var(--border); border-radius:999px; padding:8px 10px; cursor:pointer; font-size:13px; }
[data-theme="dark"] .chip{ color:#a7f3d0; background:#132035; }

/* footer / input row */
.footer{
  display:flex; align-items:center; gap:10px; padding:10px; border:1px solid var(--border);
  background: var(--panel); border-radius:16px; box-shadow:var(--shadow);
}
[data-theme="dark"] .footer{
  background: linear-gradient(160deg, #0f172a, #0b1120);
}
.left-tools{ display:flex; gap:6px; }
.mini{ border:1px solid var(--border); background:var(--panel); color:var(--ink); border-radius:8px; padding:6px 8px; cursor:pointer; }

.input{
  flex:1;
  display:grid;
  grid-template-columns: 1fr auto auto auto; /* text | send | mic */
  gap:8px;
  align-items:stretch; /* equal heights */
}

.attach{
  border:1px solid var(--border);
  background:var(--panel); color:var(--ink);
  border-radius:12px; padding:10px 12px; min-height:42px; cursor:pointer;
}

#userInput{
  min-height:42px; max-height:160px; resize:none; overflow:auto;
  border:1px solid var(--border); outline:none; background:var(--panel); color:var(--ink);
  border-radius:12px; padding:10px; line-height:1.35;
}

.send, .mic{
  display:inline-flex; align-items:center; justify-content:center;
  min-height:42px;
  border:none; color:#fff; border-radius:12px; padding:10px 12px; cursor:pointer;
}

.send{ background:var(--brand); }
.mic{ background:#475569; }
/* .mic{ background:#475569; } /* slightly brighter for saffron */ */

/* loading / misc */
.loading{ display:flex; align-items:center; gap:10px; color:#374151; }
.spinner{ width:18px; height:18px; border:3px solid var(--border); border-top-color:var(--brand); border-radius:50%; animation: spin 1s linear infinite; }
@keyframes spin{ to{ transform: rotate(360deg);} }

.pill{ display:inline-block; padding:4px 8px; border-radius:999px; font-size:12px; background:var(--chip); color:var(--ink); border:1px solid var(--border); margin-bottom:6px; }

/* Modal */
.modal{ border:none; border-radius:16px; padding:0; box-shadow:var(--shadow); width:min(560px, 92vw); max-height:90dvh; overflow:auto; }
.modal::backdrop{ background: rgba(0,0,0,.45); }
.modal-content{ padding:18px; background:var(--panel); color:var(--ink); border:1px solid var(--border); border-radius:16px; }
.modal h3{ margin:4px 0 12px; }
.close{ float:right; border:none; background:transparent; font-size:24px; color:var(--ink); cursor:pointer; }
.setting-field{ display:flex; align-items:center; gap:10px; margin:10px 0; }
.setting-field label{ min-width:130px; font-weight:600; }
.setting-field .hint{ color:var(--muted); font-size:12px; }

/* Drawer (mobile header controls) */
.drawer{
  position: fixed; top:0; left:0; bottom:0; width: 84vw; max-width: 360px;
  background: var(--panel); box-shadow:var(--shadow);
  transform: translateX(-105%); transition: transform .25s ease; z-index: 30; padding: 12px; border-right:1px solid var(--border);
}
.drawer.open{ transform: translateX(0); }
.drawer-scrim{ position:fixed; inset:0; background: rgba(0,0,0,.45); display:none; z-index:29; }
.drawer-scrim.show{ display:block; }
.drawer-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:8px; }
.drawer-body{ display:flex; flex-direction:column; gap:10px; }

/* States & a11y */
:focus-visible{ outline: 2px solid var(--brand-2); outline-offset: 2px; }

.icon-btn, .mini, .copy-btn, .send, .mic{
  transition: transform .08s ease, box-shadow .12s ease, opacity .12s ease;
}
.icon-btn:hover, .mini:hover, .copy-btn:hover{
  transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--ring);
}
.send:disabled, .mic:disabled, .icon-btn:disabled{
  opacity:.5; cursor:not-allowed; transform:none; box-shadow:none;
}

/* Scrollbars (optional) */
*{ scrollbar-width: thin; scrollbar-color: var(--brand) transparent; }
*::-webkit-scrollbar{ width:10px; height:10px; }
*::-webkit-scrollbar-thumb{ background:var(--brand); border-radius:10px; }
*::-webkit-scrollbar-track{ background:transparent; }

.chat,
.footer{
  width: 100%;
  max-width: var(--chat-max);
  margin: 0 auto;
}

/* Mobile */
@media (max-width: 960px){
  .layout{ grid-template-columns: 1fr; }
  .only-mobile{ display:inline-flex; }
  .hide-sm{ display:none; }

  /* Sidebar off-canvas */
  .sidebar.offcanvas{
    position: fixed; top: 0; bottom: 0; left: 0; width: 86vw; max-width: 360px;
    transform: translateX(-105%); transition: transform .25s ease; z-index: 21;
  }
  .sidebar.offcanvas.open{ transform: translateX(0%); }
  .scrim.show{ display:block; pointer-events:auto; }

  /* Keep the gear visible on mobile; hide only the Category field */
  .header-controls{ display:flex; align-items:center; gap:12px; }
  .header-controls .field{ display:none; }      /* hides Category on mobile */
  #openSettings{ display:inline-flex; }         /* ensure gear is visible */

  .footer{
    flex-direction:column;
    align-items:stretch;
    gap:10px;
  }
  .input{ order:1; }
  .left-tools{
    order:2;
    display:grid;
    grid-template-columns: repeat(4, 1fr);
    gap:8px;
    width:100%;
  }
  .mini{ width:100%; padding:10px 0; } /* touch-friendly */
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce){
  *{ animation-duration:0.001ms !important; animation-iteration-count:1 !important; transition:none !important; scroll-behavior:auto !important; }
}
