/* =========================================================
   Global tokens + base layout + shell primitives
   (from home_style.css)
   ========================================================= */

:root{
  --bg:#f9fafb;
  --fg:#020617;
  --card-bg:#fff;
  --muted:#6b7280;
  --muted-strong:#111827;
  --accent:#2563eb;
  --accent-soft:#60a5fa;
  --border-subtle:#e5e7eb;
  --result-border:#e5e7eb;
  --code-bg:#e5e7eb;
  --url:#15803d;
  color-scheme:light;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,sans-serif;
}

body.theme-dark{
  --bg:#020617;
  --fg:#e2e8f0;
  --card-bg:#020617;
  --muted:#64748b;
  --muted-strong:#94a3b8;
  --accent:#3b82f6;
  --accent-soft:#60a5fa;
  --border-subtle:#111827;
  --result-border:#0f172a;
  --code-bg:#020617;
  --url:#16a34a;
  color-scheme:dark;
}

*{ box-sizing:border-box; }

body{
  margin:0;
  min-height:100vh;
  background:var(--bg);
  color:var(--fg);
  display:flex;
  justify-content:center;
  overflow-x:hidden;
}

/* Keep app from shrinking to content width (prevents view-dependent width jumps) */
#app{
  width:100%;
}

main{
  width:min(720px, 100vw);
  max-width:720px;
  margin:0 auto;
  padding:3rem 1.5rem 4rem;
  display:flex;
  flex-direction:column;
  align-items:center;
}

/* Ensure view mounts don't shrink to content width inside the centered main */
#viewMount{
  width:100%;
  align-self:stretch;
}

/* =========================================================
   Top bar / header cluster
   ========================================================= */

.top-bar{
  position:fixed;
  top:1rem;
  right:1.5rem;
  display:flex;
  align-items:center;
  gap:.6rem;
  z-index:10;
}

/* Group pills like modern header clusters */
.top-group{
  display:flex;
  align-items:center;
  gap:.2rem;
  padding:.25rem;
  border:1px solid var(--border-subtle);
  background: var(--card-bg);
  border-radius:999px;
  box-shadow:0 6px 18px rgba(15,23,42,.06);
}

/* Icon buttons (inline SVG) */
.icon-btn{
  width:38px;
  height:38px;
  padding:0;
  border-radius:12px;
  border:1px solid transparent;
  background:transparent;
  color:var(--muted-strong);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}

.icon-btn svg{
  width:20px;
  height:20px;
  display:block;
  fill:none;
  stroke:currentColor;
  stroke-width:1.8;
  stroke-linecap:round;
  stroke-linejoin:round;
}

.icon-btn svg *{
  fill:none;
  stroke:currentColor;
  stroke-width:1.8;
  stroke-linecap:round;
  stroke-linejoin:round;
}

.icon-btn:hover{
  background:rgba(2,6,23,.06);
  border-color:var(--border-subtle);
  color:var(--fg);
  transform: translateY(-1px);
}

body.theme-dark .icon-btn:hover{
  background:rgba(226,232,240,.08);
}

.icon-btn:active{ transform: translateY(0px); }

.icon-btn:focus-visible,
.avatar-btn:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:2px;
}

/* Avatar button */
.avatar-btn{
  width:40px;
  height:40px;
  padding:0;
  border-radius:999px;
  border:1px solid var(--border-subtle);
  background:var(--card-bg);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  box-shadow:0 1px 2px rgba(15,23,42,.08);
}

.avatar{
  width:28px;
  height:28px;
  border-radius:999px;
  overflow:hidden;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  background:rgba(2,6,23,.06);
  color:var(--muted-strong);
}

body.theme-dark .avatar{ background:rgba(226,232,240,.10); }

.avatar img{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
}

.avatar svg{
  width:18px;
  height:18px;
  fill:none;
  stroke:currentColor;
  stroke-width:1.8;
  stroke-linecap:round;
  stroke-linejoin:round;
}

/* =========================================================
   Settings overlay (ChatGPT-ish)
   ========================================================= */

.settings-overlay{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  z-index:60;
}

.settings-modal{
  width:min(880px, calc(100vw - 2rem));
  height:min(560px, calc(100vh - 2rem));
  background:var(--card-bg);
  border:1px solid var(--border-subtle);
  border-radius:18px;
  box-shadow:0 30px 80px rgba(0,0,0,.28);
  overflow:hidden;
  display:flex;
}

.settings-side{
  width:220px;
  padding:14px;
  border-right:1px solid var(--border-subtle);
  background:rgba(2,6,23,.02);
}

body.theme-dark .settings-side{
  background:rgba(226,232,240,.03);
}

.settings-side-title{
  font-weight:800;
  margin:6px 8px 10px;
  color:var(--fg);
}

.settings-nav-item{
  width:100%;
  padding:10px 12px;
  border:none;
  background:transparent;
  color:var(--muted);
  border-radius:12px;
  text-align:left;
  font-weight:700;
  cursor:pointer;
}

.settings-nav-item.active{
  background:rgba(2,6,23,.06);
  color:var(--fg);
}

body.theme-dark .settings-nav-item.active{
  background:rgba(226,232,240,.08);
}

.settings-main{
  flex:1;
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:14px;
}

.settings-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

.settings-title{ margin:0; font-size:1.1rem; }

.settings-close{
  width:36px;
  height:36px;
}

.settings-section{ display:flex; flex-direction:column; gap:12px; }

.settings-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 14px;
  border:1px solid var(--border-subtle);
  border-radius:16px;
  background:var(--bg);
}

.settings-row-title{ font-weight:800; }
.settings-row-sub{ margin-top:2px; color:var(--muted); font-size:.9rem; }

/* Toggle switch */
.switch{
  position:relative;
  display:inline-block;
  width:46px;
  height:26px;
}

.switch input{
  opacity:0;
  width:0;
  height:0;
}

.slider{
  position:absolute;
  inset:0;
  cursor:pointer;
  background:rgba(2,6,23,.22);
  border-radius:999px;
  transition:.2s;
}

body.theme-dark .slider{ background:rgba(226,232,240,.22); }

.slider:before{
  content:"";
  position:absolute;
  height:20px;
  width:20px;
  left:3px;
  top:3px;
  background:white;
  border-radius:50%;
  transition:.2s;
  box-shadow:0 6px 16px rgba(0,0,0,.2);
}

.switch input:checked + .slider{
  background: var(--accent);
}

.switch input:checked + .slider:before{
  transform: translateX(20px);
}

/* =========================================================
   Shared primitives
   ========================================================= */

.chip{
  padding:.35rem .7rem;
  border-radius:999px;
  border:1px solid var(--border-subtle);
  background:var(--card-bg);
  color:var(--fg);
  display:inline-flex;
  align-items:center;
  gap:.35rem;
  cursor:pointer;
  font-size:.8rem;
  box-shadow:0 1px 2px rgba(15,23,42,.08);
}

.chip[disabled]{opacity:.5;cursor:not-allowed}
.chip:hover{border-color:var(--accent-soft)}

/*
  Primary button styling.
  IMPORTANT: exclude icon/avatar buttons so header controls don't turn
  into solid blue circles/pills when their SVG isn't visible.
  Primary buttons are now opt-in 
*/

.btn-primary{
  padding:.9rem 1.4rem;
  border-radius:999px;
  border:none;
  background:var(--accent);
  color:#f9fafb;
  font-weight:600;
  cursor:pointer;
  font-size:.95rem;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}

.btn-primary:hover{
  background:#1d4ed8;
}


.sr-only{
  position:absolute;
  width:1px;
  height:1px;
  padding:0;
  margin:-1px;
  overflow:hidden;
  clip:rect(0,0,0,0);
  border:0;
}

.spinner{
  display:inline-block;
  width:14px;
  height:14px;
  border:2px solid var(--muted);
  border-right-color:transparent;
  border-radius:50%;
  animation:spin .7s linear infinite;
  margin-right:.4rem;
}

@keyframes spin{ to{transform:rotate(360deg)} }

/* =========================================================
   API status dot (Step 13)
   ========================================================= */

.api-status-dot{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 14px;
  opacity: .85;
  user-select:none;
  cursor: default;
}

.api-status-dot.is-offline{ color: #ef4444; }
.api-status-dot.is-online{ color: #22c55e; }
.api-status-dot.is-degraded{ color: #f59e0b; }
