/* ROV Tutor — dark-mode (OLED) technical UI. Vanilla, lightweight.
   Inter when available, instant system fallback (offline-safe). */
:root{
  --bg:#0a0e14; --surface:#0f1520; --surface-2:#151d2b; --raised:#1a2433;
  --border:#212c3d; --border-strong:#30405a;
  --text:#e7eef7; --text-dim:#9db0c6; --text-faint:#677890;
  --primary:#2f74ff; --primary-press:#1f5fe0; --navy:#1e3a5f;
  --accent:#10b981; --accent-dim:#0e7c5a;
  --warn:#f0b03a; --danger:#f0616d;
  --user:#15314e; --user-border:#27517f;
  --radius:14px; --radius-sm:9px; --radius-pill:999px;
  --shadow:0 10px 30px rgba(0,0,0,.40);
  --font:"Inter",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,system-ui,sans-serif;
  --mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,monospace;
  --sidebar:268px; --maxw:1180px;
}
*{box-sizing:border-box}
[hidden]{display:none !important}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:var(--font); font-size:16px; line-height:1.6;
  -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility;
  display:flex; flex-direction:column; min-height:100dvh;
  overflow-x:hidden;                 /* hard stop on any horizontal scroll */
}
button{font-family:inherit}
::selection{background:rgba(47,116,255,.32)}

/* ---------- Header ---------- */
.topbar{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between; gap:14px;
  padding:12px clamp(14px,4vw,28px);
  padding-top:calc(12px + env(safe-area-inset-top));   /* clear the iPhone status bar / notch in standalone */
  background:rgba(10,14,20,.82); backdrop-filter:blur(10px);
  border-bottom:1px solid var(--border);
}
.brand{display:flex; align-items:center; gap:10px; font-weight:600; letter-spacing:-.01em}
.brand .mark{width:26px; height:26px; color:var(--primary); flex:0 0 auto}
.brand .sub{color:var(--text-faint); font-weight:400; font-size:13px}
.status{display:flex; align-items:center; gap:8px; flex-wrap:wrap; justify-content:flex-end}
.pill{
  display:inline-flex; align-items:center; gap:6px;
  padding:5px 10px; border:1px solid var(--border); border-radius:var(--radius-pill);
  background:var(--surface); color:var(--text-dim); font-size:12.5px;
}
.pill .k{font-family:var(--mono); color:var(--text)}
.led{width:8px; height:8px; border-radius:50%; background:var(--text-faint); flex:0 0 auto}
.led.ok{background:var(--accent); box-shadow:0 0 8px rgba(16,185,129,.7)}
.led.warn{background:var(--warn); box-shadow:0 0 8px rgba(240,176,58,.6)}
.pill.off{color:var(--warn); border-color:rgba(240,176,58,.35); background:rgba(240,176,58,.08)}

/* ---------- Layout ---------- */
main{
  flex:1; width:100%; max-width:var(--maxw); margin:0 auto;
  display:grid; grid-template-columns:var(--sidebar) 1fr; gap:18px;
  padding:18px clamp(14px,4vw,28px); min-height:0;
}
.controls{
  display:flex; flex-direction:column; gap:16px; min-width:0;
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:16px; align-self:start; position:sticky; top:74px;
}
.field{display:flex; flex-direction:column; gap:7px}
.field > .lab{font-size:12px; text-transform:uppercase; letter-spacing:.06em; color:var(--text-faint)}

/* Segmented control */
.seg{display:flex; flex-wrap:wrap; background:var(--surface-2); border:1px solid var(--border); border-radius:var(--radius-sm); padding:3px; gap:3px}
.seg button{
  flex:1 1 auto; min-width:62px; white-space:nowrap; border:0; background:transparent; color:var(--text-dim);
  padding:8px 8px; border-radius:7px; font-size:12.5px; font-weight:500; cursor:pointer;
  transition:background .18s ease, color .18s ease;
}
.seg button:hover{color:var(--text)}
.seg button[aria-pressed="true"]{background:var(--primary); color:#fff}
body[data-mode="troubleshooter"] .seg.modes button[aria-pressed="true"]{background:var(--accent); color:#04150f}

select{
  appearance:none; width:100%; cursor:pointer;
  background:var(--surface-2) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%239db0c6' stroke-width='2' stroke-linecap='round'><path d='M3 5l4 4 4-4'/></svg>") no-repeat right 12px center;
  color:var(--text); border:1px solid var(--border); border-radius:var(--radius-sm);
  padding:10px 32px 10px 12px; font-size:14px;
}
select:focus-visible, .seg button:focus-visible, textarea:focus-visible, .btn:focus-visible, .chip:focus-visible, .ex:focus-visible{
  outline:2px solid var(--primary); outline-offset:2px;
}
.ghost{
  background:transparent; border:1px solid var(--border); color:var(--text-dim);
  padding:9px 12px; border-radius:var(--radius-sm); font-size:13.5px; cursor:pointer;
  transition:border-color .18s, color .18s;
}
.ghost:hover{border-color:var(--border-strong); color:var(--text)}
.muted2{color:var(--text-faint); font-weight:400}
.manual-checks{display:flex; flex-direction:column; gap:2px; max-height:210px; overflow-y:auto}
.mcheck{display:flex; align-items:flex-start; gap:8px; min-width:0; padding:7px 9px; border-radius:var(--radius-sm); cursor:pointer; font-size:13px; color:var(--text-dim); border:1px solid transparent; transition:background .15s, color .15s, border-color .15s}
.mcheck:hover{background:var(--surface-2); color:var(--text)}
.mcheck.on{background:rgba(47,116,255,.10); color:var(--text); border-color:rgba(47,116,255,.28)}
.mcheck input{accent-color:var(--primary); width:15px; height:15px; flex:0 0 auto; margin-top:2px; cursor:pointer}
.mcheck span{min-width:0; white-space:normal; overflow-wrap:anywhere; line-height:1.35}
.photo-list{display:flex; flex-wrap:wrap; gap:6px}
.photo-thumb{width:48px; height:48px; padding:0; border:1px solid var(--border); border-radius:8px;
  overflow:hidden; cursor:pointer; background:none}
.photo-thumb:hover{border-color:var(--accent)}
.photo-thumb img{width:100%; height:100%; object-fit:cover; display:block}
.note{font-size:12px; color:var(--text-faint); line-height:1.55; border-top:1px solid var(--border); padding-top:12px; margin:0}
.note strong{color:var(--text-dim); font-weight:500}

/* ---------- Chat ---------- */
.chat{display:flex; flex-direction:column; min-height:0; min-width:0;
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); overflow:hidden}
.messages{flex:1; overflow-y:auto; padding:clamp(14px,3vw,26px); display:flex; flex-direction:column; gap:18px; scroll-behavior:smooth}
.row{display:flex; gap:12px; max-width:100%}
.row.user{flex-direction:row-reverse}
.avatar{width:30px; height:30px; border-radius:8px; flex:0 0 auto; display:grid; place-items:center;
  background:var(--surface-2); border:1px solid var(--border); color:var(--text-dim)}
.row.user .avatar{background:var(--user); border-color:var(--user-border); color:#bcd6f5}
.bubble{
  padding:13px 15px; border-radius:var(--radius); max-width:min(760px,82%);
  border:1px solid var(--border); background:var(--surface-2);
  animation:rise .26s ease both;
}
.row.user .bubble{background:var(--user); border-color:var(--user-border)}
@keyframes rise{from{opacity:0; transform:translateY(6px)} to{opacity:1; transform:none}}

/* markdown-lite */
.bubble p{margin:0 0 10px} .bubble p:last-child{margin-bottom:0}
.bubble h4{margin:4px 0 8px; font-size:15px; font-weight:600; color:var(--text)}
.bubble ul,.bubble ol{margin:6px 0 10px; padding-left:20px} .bubble li{margin:3px 0}
.bubble code{font-family:var(--mono); font-size:13px; background:rgba(255,255,255,.06); padding:1px 6px; border-radius:5px}
.bubble strong{color:#fff; font-weight:600}
.bubble .mermaid{margin:11px 0; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-sm); padding:12px; overflow-x:auto; text-align:center}
.bubble pre.code{background:rgba(255,255,255,.04); border:1px solid var(--border); border-radius:var(--radius-sm); padding:10px 12px; overflow-x:auto; font-family:var(--mono); font-size:12.5px; margin:8px 0}
.cite{font-family:var(--mono); font-size:12px; color:var(--accent);
  background:rgba(16,185,129,.10); border:1px solid rgba(16,185,129,.25); border-radius:6px; padding:0 5px; white-space:nowrap}

.sources{display:flex; flex-wrap:wrap; gap:6px; margin-top:11px; padding-top:11px; border-top:1px dashed var(--border)}
.chip{
  font-family:var(--mono); font-size:11.5px; color:var(--text-dim);
  background:var(--raised); border:1px solid var(--border); border-radius:var(--radius-pill);
  padding:4px 9px; display:inline-flex; gap:6px; align-items:center; cursor:default;
}
.chip b{color:var(--text); font-weight:500}

/* typing dots */
.typing{display:inline-flex; gap:4px; padding:4px 2px}
.typing span{width:7px; height:7px; border-radius:50%; background:var(--text-faint); animation:blink 1.2s infinite ease-in-out}
.typing span:nth-child(2){animation-delay:.18s} .typing span:nth-child(3){animation-delay:.36s}
@keyframes blink{0%,80%,100%{opacity:.25; transform:translateY(0)} 40%{opacity:1; transform:translateY(-3px)}}

/* empty state */
.empty{margin:auto; text-align:center; max-width:560px; padding:24px 8px}
.empty h2{font-size:20px; font-weight:600; margin:0 0 8px; letter-spacing:-.01em}
.empty p{color:var(--text-dim); margin:0 0 20px}
.examples{display:grid; gap:10px; grid-template-columns:1fr 1fr}
.ex{
  text-align:left; background:var(--surface-2); border:1px solid var(--border); color:var(--text);
  border-radius:var(--radius-sm); padding:12px 14px; font-size:13.5px; cursor:pointer; line-height:1.45;
  transition:border-color .18s, transform .18s, background .18s;
}
.ex:hover{border-color:var(--border-strong); transform:translateY(-2px); background:var(--raised)}
.ex .tagline{display:block; font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:var(--text-faint); margin-bottom:4px}

/* ---------- Composer ---------- */
.composer{display:flex; flex-direction:column; gap:10px; padding:12px; padding-bottom:max(12px,env(safe-area-inset-bottom)); border-top:1px solid var(--border); background:var(--surface)}
.composer-row{display:flex; gap:8px; align-items:flex-end}
.icon-btn{
  flex:0 0 auto; width:44px; height:46px; display:grid; place-items:center;
  background:var(--surface-2); color:var(--text-dim); border:1px solid var(--border);
  border-radius:var(--radius-sm); cursor:pointer; transition:border-color .18s, color .18s, background .18s;
}
.icon-btn:hover{color:var(--text); border-color:var(--border-strong)}
.icon-btn.cam:hover{color:var(--accent); border-color:var(--accent-dim)}
.icon-btn.web.on{color:var(--primary); border-color:var(--primary); background:rgba(47,116,255,.12)}
.chip.link{color:var(--primary); text-decoration:none; cursor:pointer}
.chip.link:hover{border-color:var(--primary)}
.web-label{display:flex; align-items:center; gap:5px; font-size:11px; color:var(--text-faint); margin-top:11px}
.web-label + .sources.web{margin-top:5px; border-top:none; padding-top:0}
.choice-btns{display:flex; gap:8px; flex-wrap:wrap; margin-top:6px}
.cbtn{display:inline-flex; align-items:center; gap:6px; background:var(--surface-2); color:var(--text); border:1px solid var(--border); border-radius:var(--radius-sm); padding:8px 12px; font-size:13px; cursor:pointer; transition:border-color .18s, color .18s}
.cbtn:hover{border-color:var(--border-strong)}
.cbtn.web:hover{border-color:var(--primary); color:var(--primary)}
.history-list{display:flex; flex-direction:column; gap:3px; max-height:240px; overflow-y:auto}
.hist-day{font-size:10px; text-transform:uppercase; letter-spacing:.06em; color:var(--text-faint); margin:8px 0 2px}
.hist-item{text-align:left; background:transparent; border:1px solid transparent; border-radius:var(--radius-sm); padding:7px 9px; font-size:12.5px; color:var(--text-dim); cursor:pointer; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; transition:background .15s, color .15s}
.hist-item:hover{background:var(--surface-2); color:var(--text)}
.hist-item.cur{background:rgba(47,116,255,.10); color:var(--text); border-color:rgba(47,116,255,.3)}
.staged{display:flex; flex-wrap:wrap; gap:8px}
.thumb{position:relative; width:54px; height:54px; border-radius:9px; overflow:hidden; border:1px solid var(--border)}
.thumb img{width:100%; height:100%; object-fit:cover; display:block}
.thumb .rm{position:absolute; top:2px; right:2px; width:18px; height:18px; border:0; border-radius:50%;
  background:rgba(0,0,0,.65); color:#fff; font-size:11px; line-height:1; cursor:pointer; display:grid; place-items:center}
.msg-atts{display:flex; flex-wrap:wrap; gap:8px; margin-bottom:8px}
.msg-atts img{max-width:200px; max-height:200px; border-radius:10px; border:1px solid var(--user-border); display:block}
.sysmsg{align-self:center; max-width:90%; text-align:center; font-size:12.5px; color:var(--text-faint);
  background:var(--surface-2); border:1px solid var(--border); border-radius:var(--radius-pill); padding:6px 14px}

/* rule badge + help */
.rule{font-size:10px; font-weight:600; color:var(--accent); background:rgba(16,185,129,.12);
  border:1px solid rgba(16,185,129,.3); border-radius:5px; padding:1px 5px; margin-left:6px; text-transform:none; letter-spacing:0}
.help{font-size:11.5px; color:var(--text-faint); line-height:1.4}
textarea#input{
  flex:1; resize:none; max-height:180px; min-height:24px;
  background:var(--surface-2); color:var(--text); border:1px solid var(--border);
  border-radius:var(--radius-sm); padding:12px 14px; font-size:15px; line-height:1.5;
}
textarea#input::placeholder{color:var(--text-faint)}
.btn{
  flex:0 0 auto; display:inline-flex; align-items:center; gap:8px;
  background:var(--primary); color:#fff; border:0; border-radius:var(--radius-sm);
  padding:0 16px; height:46px; font-size:14.5px; font-weight:600; cursor:pointer;
  transition:background .18s, transform .1s;
}
.btn:hover{background:var(--primary-press)}
.btn:active{transform:scale(.98)}
.btn[disabled]{opacity:.5; cursor:not-allowed}
body[data-mode="troubleshooter"] .btn{background:var(--accent); color:#04150f}
body[data-mode="troubleshooter"] .btn:hover{background:var(--accent-dim); color:#fff}
.btn .spin{width:16px; height:16px; border:2px solid rgba(255,255,255,.4); border-top-color:#fff; border-radius:50%; animation:rot .7s linear infinite}
@keyframes rot{to{transform:rotate(360deg)}}

/* ---------- Responsive ---------- */
/* ---------- Auth page ---------- */
.auth-body{justify-content:center; align-items:center; padding:24px}
.auth-card{width:100%; max-width:384px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:28px}
.auth-card .brand{margin-bottom:18px}
.auth-card h1{font-size:20px; font-weight:600; margin:0 0 6px}
.auth-sub{color:var(--text-dim); font-size:13.5px; margin:0 0 18px; line-height:1.5}
.auth-card form{display:flex; flex-direction:column; gap:12px}
.auth-card label{display:flex; flex-direction:column; gap:6px; font-size:12px; text-transform:uppercase; letter-spacing:.05em; color:var(--text-faint)}
.auth-card input{background:var(--surface-2); color:var(--text); border:1px solid var(--border); border-radius:var(--radius-sm); padding:12px 13px; font-size:15px}
.auth-card .btn{justify-content:center; height:48px; margin-top:4px}
.auth-err{color:var(--danger); font-size:13px; margin:0; background:rgba(240,97,109,.1); border:1px solid rgba(240,97,109,.3); border-radius:var(--radius-sm); padding:9px 12px}
.auth-card .note{margin-top:16px}

/* ---------- Mobile drawer (controls hidden behind the ☰ button) ---------- */
.menu-btn{display:none; flex:0 0 auto; width:40px; height:40px; align-items:center; justify-content:center;
  background:var(--surface-2); color:var(--text); border:1px solid var(--border); border-radius:var(--radius-sm); cursor:pointer}
.menu-btn:hover{border-color:var(--border-strong)}
.drawer-head{display:none}
.icon-x{background:transparent; border:0; color:var(--text-dim); font-size:18px; line-height:1; cursor:pointer; width:34px; height:34px; border-radius:8px}
.icon-x:hover{background:var(--surface-2); color:var(--text)}
.scrim{position:fixed; inset:0; background:rgba(0,0,0,.55); z-index:40; border:0; display:none}

@media (max-width:860px){
  .menu-btn{display:inline-flex}
  main{grid-template-columns:1fr; gap:0; padding:12px clamp(12px,4vw,20px)}
  .controls{
    position:fixed; top:0; left:0; z-index:50;
    height:100dvh; width:min(86vw,330px);
    border-radius:0; border-top:0; border-bottom:0; border-left:0;
    transform:translateX(-100%); transition:transform .26s ease;
    overflow-y:auto; box-shadow:var(--shadow);
    padding-top:calc(16px + env(safe-area-inset-top));   /* drawer ✕ clears the status bar */
  }
  body.drawer-open .controls{transform:translateX(0)}
  body.drawer-open .scrim{display:block}
  body.drawer-open{overflow:hidden}
  .drawer-head{display:flex; align-items:center; justify-content:space-between;
    font-size:13px; font-weight:600; color:var(--text-dim); padding-bottom:8px; border-bottom:1px solid var(--border)}
  .chat{min-height:calc(100dvh - 132px)}
  .examples{grid-template-columns:1fr}
  .bubble{max-width:92%}
}
@media (max-width:480px){
  .brand .sub{display:none}
  .pill.model{display:none}
  .bubble{max-width:94%}
  .topbar{padding:10px 12px; padding-top:calc(10px + env(safe-area-inset-top)); gap:10px}
}
@media (min-width:861px){
  .scrim{display:none !important}
  .menu-btn{display:none !important}
}
@media (prefers-reduced-motion:reduce){
  *{animation:none !important; transition:none !important; scroll-behavior:auto !important}
}

/* recovery code + auth links */
.auth-alt{text-align:center; margin:10px 0 0; font-size:13px}
.auth-alt a{color:var(--primary); text-decoration:none; opacity:.85}
.auth-alt a:hover{opacity:1; text-decoration:underline}
.reccode{display:block; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:16px;
  letter-spacing:1px; text-align:center; background:var(--surface-2); border:1px dashed var(--border);
  border-radius:var(--radius-sm); padding:10px; margin:6px 0; cursor:pointer; user-select:all; color:var(--text)}
.reccode.copied{border-color:var(--primary); color:var(--primary)}

/* compact send + expand-to-fullscreen composer */
.send-btn{width:46px; height:46px; padding:0; justify-content:center; flex:0 0 auto}
.send-btn #sendLabel{display:inline-flex; align-items:center; justify-content:center}
.input-wrap{flex:1; position:relative; display:flex; min-width:0}
.input-wrap textarea{flex:1; padding-right:34px}
.expand-btn{position:absolute; top:7px; right:7px; width:26px; height:26px; padding:0; border:0;
  background:transparent; color:var(--text-faint); cursor:pointer; border-radius:6px; display:grid; place-items:center}
.expand-btn:hover{color:var(--text); background:var(--surface-2)}
.compose-sheet{position:fixed; top:0; left:0; right:0; bottom:0; z-index:60; background:var(--bg);
  display:flex; flex-direction:column; gap:12px; padding:14px;
  padding-top:calc(14px + env(safe-area-inset-top)); padding-bottom:max(14px,env(safe-area-inset-bottom))}
.compose-head{display:flex; align-items:center; justify-content:space-between; color:var(--text-dim); font-size:14px; font-weight:600}
#bigInput{flex:1; width:100%; resize:none; background:var(--surface-2); color:var(--text);
  border:1px solid var(--border); border-radius:var(--radius-sm); padding:14px; font-size:16px; line-height:1.55}
#bigInput::placeholder{color:var(--text-faint)}
.compose-actions{display:flex; justify-content:flex-end}
