/* codeR - agentic coding console. Dark theme matching Gptopen, mobile-first. */
/* Same theme variables as the main app (assets/styles-1.css), so codeR
   always matches the app's theme, including the light mode. */
:root{
  --accent:#ffffff; --accent-ink:#0b0b0c;
  --bg:#000000; --surface:#1c1c1e; --surface2:#2c2c2e; --text:#ffffff; --text2:#e5e5ea;
  --muted:#98989d; --border:rgba(255,255,255,.08); --border2:rgba(255,255,255,.14);
  --input:rgba(255,255,255,.06); --hover:rgba(255,255,255,.07); --rowbg:rgba(255,255,255,.055);
  --overlay:rgba(0,0,0,.55); --glass:rgba(28,28,30,.72);
  --green:#30d158; --orange:#ff9f0a; --red:#ff453a; --blue:#0a84ff; --purple:#bf5af2;
  --radius:14px;
  --font:-apple-system,BlinkMacSystemFont,"SF Pro Text",Inter,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --mono:ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
}
html[data-theme="white"]{
  --bg:#ffffff; --surface:#f2f2f7; --surface2:#e5e5ea; --text:#111111; --text2:#333333;
  --muted:#6b6b70; --border:rgba(0,0,0,.09); --border2:rgba(0,0,0,.16);
  --input:rgba(0,0,0,.045); --hover:rgba(0,0,0,.05); --rowbg:rgba(0,0,0,.04);
  --overlay:rgba(0,0,0,.35); --glass:rgba(255,255,255,.78);
}
/* light-mode variants of codeR's hardcoded dark surfaces */
html[data-theme="white"] .cr-head{background:rgba(255,255,255,.86);}
html[data-theme="white"] .cr-bar{background:rgba(255,255,255,.72);}
html[data-theme="white"] .cr-nav{background:rgba(255,255,255,.6); border-color:rgba(0,0,0,.1);
  box-shadow:0 8px 32px rgba(0,0,0,.16), inset 0 1px 0 rgba(255,255,255,.7);}
html[data-theme="white"] .cr-nav a.on{background:rgba(0,0,0,.08); color:#111111;}
html[data-theme="white"] .cr-compose .cr-row{background:rgba(255,255,255,.6); border-color:rgba(0,0,0,.1);
  box-shadow:0 10px 34px rgba(0,0,0,.12);}
*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{height:100%;}
body{margin:0; background:var(--bg); color:var(--text); font-family:var(--font); font-size:15px; -webkit-font-smoothing:antialiased; overflow:hidden;}
button{font-family:var(--font);}

/* ---------- header ---------- */
.cr-head{position:fixed; top:0; left:0; right:0; z-index:20; display:flex; align-items:center; gap:10px;
  padding:calc(10px + env(safe-area-inset-top)) 12px 10px; background:rgba(0,0,0,.86);
  backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); border-bottom:1px solid var(--border);}
.cr-title{font-size:20px; font-weight:800; letter-spacing:-.02em; flex:1;}
.cr-title .r{color:var(--purple);}
/* minimalistic header buttons: no boxes, just quiet text and icons */
.cr-model-btn{max-width:38vw; border:none; background:none; color:var(--muted);
  border-radius:10px; padding:8px 6px; font-size:12.5px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.cr-model-btn:active{color:var(--text); background:var(--hover);}
.cr-gear{width:36px; height:36px; border:none; background:none;
  color:var(--muted); display:grid; place-items:center; flex:none; border-radius:10px;}
.cr-gear:active{color:var(--text); background:var(--hover);}
.cr-gear svg{width:19px; height:19px;}

/* ---------- mode + tool bar ---------- */
.cr-bar{position:fixed; z-index:19; left:0; right:0; top:calc(59px + env(safe-area-inset-top));
  display:flex; gap:8px; align-items:center; padding:8px 12px; background:rgba(0,0,0,.7);
  border-bottom:1px solid var(--border); overflow-x:auto; scrollbar-width:none;}
.cr-bar::-webkit-scrollbar{display:none;}
.chip{flex:none; border:1px solid transparent; background:none; color:var(--muted);
  border-radius:999px; padding:6px 10px; font-size:13px; font-weight:700;}
.chip:active{background:var(--hover);}
.chip.on{color:var(--text); background:var(--rowbg); border-color:var(--border);}
.chip.plan.on{background:var(--blue); border-color:var(--blue); color:#fff;}
.chip.auto.on{background:var(--orange); border-color:var(--orange); color:#000;}
.cr-bar .sp{flex:1; min-width:4px;}
.tbtn{flex:none; border:none; background:none; color:var(--muted);
  border-radius:10px; padding:7px 8px; font-size:13px; font-weight:600;}
.tbtn:active{color:var(--text); background:var(--hover);}

/* ---------- messages ---------- */
#msgs{position:fixed; inset:0; padding:calc(116px + env(safe-area-inset-top)) 12px calc(150px + env(safe-area-inset-bottom));
  overflow-y:auto; -webkit-overflow-scrolling:touch; display:flex; flex-direction:column; gap:10px;}
.msg{max-width:100%; border-radius:var(--radius); padding:10px 13px; line-height:1.5; word-wrap:break-word; font-size:14.5px;}
.msg.user{align-self:flex-end; background:var(--blue); color:#fff; border-bottom-right-radius:6px; max-width:88%;}
.msg.agent{align-self:flex-start; background:var(--surface); color:var(--text2); border:1px solid var(--border); border-bottom-left-radius:6px; max-width:94%;}
.msg.agent pre{background:#000; border:1px solid var(--border); border-radius:10px; padding:10px; overflow-x:auto; font-family:var(--mono); font-size:12.5px; color:var(--text2);}
.msg.agent code{font-family:var(--mono); font-size:13px; background:rgba(255,255,255,.08); padding:1px 5px; border-radius:6px;}
.msg.agent pre code{background:none; padding:0;}
.msg.sys{align-self:center; background:none; border:1px dashed var(--border2); color:var(--muted); font-size:12.5px; text-align:center;}

/* ---------- tool cards ---------- */
.tool{border:1px solid var(--border2); border-radius:var(--radius); background:var(--surface); overflow:hidden; max-width:100%;}
.tool-head{display:flex; align-items:center; gap:9px; padding:9px 12px; font-size:13.5px; font-weight:700;}
.tool-ic{width:26px; height:26px; border-radius:8px; display:grid; place-items:center; flex:none; font-size:14px;}
.tool-ic.think{background:rgba(152,152,157,.18);}
.tool-ic.plan{background:rgba(10,132,255,.2);}
.tool-ic.list,.tool-ic.read,.tool-ic.search{background:rgba(10,132,255,.2);}
.tool-ic.write,.tool-ic.edit{background:rgba(255,159,10,.2);}
.tool-ic.run{background:rgba(191,90,242,.2);}
.tool-ic.done{background:rgba(48,209,88,.2);}
.tool-ic.bad{background:rgba(255,69,58,.2);}
.tool-path{font-family:var(--mono); font-size:12.5px; color:var(--text2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1;}
.tool-status{font-size:11.5px; font-weight:700; color:var(--muted); flex:none;}
.tool-status.ok{color:var(--green);} .tool-status.wait{color:var(--orange);} .tool-status.no{color:var(--red);}
.tool-body{border-top:1px solid var(--border); padding:10px 12px; font-size:13px; color:var(--text2);}
.tool-body pre{background:#000; border:1px solid var(--border); border-radius:10px; padding:9px; overflow-x:auto;
  font-family:var(--mono); font-size:12px; line-height:1.5; max-height:260px; overflow-y:auto; white-space:pre-wrap; word-break:break-word;}
.tool-body .lbl{font-size:11px; font-weight:800; letter-spacing:.06em; text-transform:uppercase; color:var(--muted); margin:8px 0 4px;}
.tool-body .lbl:first-child{margin-top:0;}
.tool-actions{display:flex; gap:8px; padding:10px 12px; border-top:1px solid var(--border);}
.btn{flex:1; border:none; border-radius:12px; padding:11px; font-size:14px; font-weight:700;}
.btn.approve{background:var(--green); color:#000;}
.btn.reject{background:var(--surface3); color:var(--text);}
.btn:disabled{opacity:.45;}

/* ---------- composer: same search box + send button as the main app ---------- */
.cr-compose{position:fixed; left:0; right:0; bottom:calc(76px + env(safe-area-inset-bottom)); z-index:20; padding:0 12px;}
.cr-row{display:flex; align-items:flex-end; gap:8px; background:rgba(18,18,20,.55);
  -webkit-backdrop-filter:blur(22px) saturate(1.5); backdrop-filter:blur(22px) saturate(1.5);
  border:1px solid rgba(255,255,255,.12);
  border-radius:28px; padding:6px; box-shadow:0 10px 34px rgba(0,0,0,.28);}
#prompt{flex:1; border:none; outline:none; background:none; resize:none; color:var(--text);
  font-family:var(--font); font-size:16px; line-height:1.4; padding:9px 2px; max-height:130px; min-width:0;
  scrollbar-width:none; -ms-overflow-style:none;}
#prompt::-webkit-scrollbar{width:0 !important; height:0 !important; display:none;}
#prompt::placeholder{color:var(--muted);}
#send{width:40px; height:40px; border-radius:50%; border:none; background:var(--accent); color:var(--accent-ink);
  display:grid; place-items:center; flex:none;}
#send:disabled{background:var(--surface2); color:var(--muted);}
#send:active{filter:brightness(1.12);}
#send svg{width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round;}
.typing{display:inline-flex; gap:4px; padding:4px 0;}
.typing i{width:7px; height:7px; border-radius:50%; background:var(--muted); animation:tp 1s infinite;}
.typing i:nth-child(2){animation-delay:.15s;} .typing i:nth-child(3){animation-delay:.3s;}
@keyframes tp{0%,100%{opacity:.3}50%{opacity:1}}

/* ---------- drawers ---------- */
.drawer{position:fixed; inset:0; z-index:40; display:none;}
.drawer.open{display:block;}
.scrim{position:absolute; inset:0; background:rgba(0,0,0,.6);}
.sheet{position:absolute; left:0; right:0; bottom:0; top:8%; background:var(--bg); border-top:1px solid var(--border2);
  border-radius:20px 20px 0 0; display:flex; flex-direction:column; overflow:hidden;}
.sheet-head{display:flex; align-items:center; gap:10px; padding:14px 14px 10px; border-bottom:1px solid var(--border);}
.sheet-head h2{margin:0; font-size:17px; font-weight:800; flex:1;}
.x{width:34px; height:34px; border-radius:50%; border:1px solid var(--border); background:var(--surface); color:var(--text); font-size:16px;}
.tabs{display:flex; gap:8px; padding:10px 14px 0;}
.tab{border:1px solid var(--border); background:var(--surface); color:var(--muted); border-radius:999px; padding:7px 14px; font-size:13px; font-weight:700;}
.tab.on{background:#fff; color:#000; border-color:#fff;}
.sheet-body{flex:1; overflow-y:auto; padding:12px 14px calc(20px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling:touch;}

/* workspace */
.ws-actions{display:flex; gap:8px; margin-bottom:12px;}
.ws-actions .tbtn{flex:1; text-align:center;}
.ftree{display:flex; flex-direction:column; gap:2px;}
.frow{display:flex; align-items:center; gap:10px; padding:9px 10px; border-radius:10px; border:1px solid transparent; width:100%;
  background:none; color:var(--text2); font-size:14px; text-align:left;}
.frow:active{background:var(--surface);}
.frow.sel{background:var(--surface); border-color:var(--border2);}
.frow .fn{font-family:var(--mono); font-size:13px; flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.frow .fdel{color:var(--muted); font-size:15px; padding:2px 6px;}
.fdir{font-size:11.5px; font-weight:800; letter-spacing:.07em; text-transform:uppercase; color:var(--muted); margin:10px 2px 4px;}
#editor{width:100%; min-height:46vh; background:#000; color:var(--text2); border:1px solid var(--border2); border-radius:12px;
  font-family:var(--mono); font-size:13px; line-height:1.55; padding:12px; resize:vertical;}
.ed-bar{display:flex; gap:8px; margin:10px 0;}
.ed-bar .tbtn{flex:1; text-align:center; padding:10px;}
#previewFrame{width:100%; height:62vh; border:1px solid var(--border2); border-radius:12px; background:#fff;}
.ws-empty{color:var(--muted); text-align:center; padding:34px 20px; font-size:14px; line-height:1.6;}

/* sessions */
.srow{width:100%; text-align:left; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:12px 13px; margin-bottom:9px; color:var(--text);}
.srow .st{font-weight:700; font-size:14.5px; margin-bottom:4px;}
.srow .sm{font-size:12.5px; color:var(--muted);}
.snap{font-size:12.5px; color:var(--muted); background:var(--surface); border:1px dashed var(--border2);
  border-radius:10px; padding:9px 11px; margin:8px 0; line-height:1.5;}

/* settings modal */
.modal{position:fixed; inset:0; z-index:50; display:none;}
.modal.open{display:block;}
.modal-card{position:absolute; left:14px; right:14px; top:12%; max-height:76%; overflow-y:auto; background:var(--surface);
  border:1px solid var(--border2); border-radius:18px; padding:16px;}
.modal-card h3{margin:0 0 4px; font-size:16px;}
.fld{margin:12px 0;}
.fld label{display:block; font-size:12.5px; font-weight:700; color:var(--muted); margin-bottom:6px;}
.fld input,.fld select{width:100%; background:#000; border:1px solid var(--border2); border-radius:10px; color:var(--text);
  padding:10px 11px; font-size:14px; font-family:var(--font);}
.fld input[type=password]{font-family:var(--mono);}
.presets{display:flex; flex-wrap:wrap; gap:7px; margin-top:8px;}
.presets .tbtn{font-size:12px; padding:6px 10px;}
.mrow{display:flex; gap:8px; margin-top:14px;}
.note{font-size:12px; color:var(--muted); line-height:1.55; margin-top:10px;}

@media (min-width:760px){
  #msgs{max-width:760px; margin:0 auto; left:0; right:0;}
  .cr-compose{max-width:760px; margin:0 auto;}
  .modal-card{max-width:520px; margin:0 auto;}
}

/* ---------- floating liquid-glass bottom nav, icons only ---------- */
.cr-nav{position:fixed; left:50%; transform:translateX(-50%); bottom:calc(10px + env(safe-area-inset-bottom));
  z-index:30; display:flex; align-items:center; gap:2px; padding:6px;
  width:min(400px, calc(100vw - 32px));
  background:rgba(18,18,20,.55); -webkit-backdrop-filter:blur(22px) saturate(1.5); backdrop-filter:blur(22px) saturate(1.5);
  border:1px solid rgba(255,255,255,.12); border-radius:28px;
  box-shadow:0 8px 32px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.08);}
.cr-nav a{flex:1 1 0; min-width:0; height:46px; display:flex; align-items:center; justify-content:center;
  border-radius:20px; color:var(--muted); text-decoration:none; -webkit-tap-highlight-color:transparent;}
.cr-nav a svg{width:22px; height:22px;}
.cr-nav a.on{background:rgba(255,255,255,.16); color:#ffffff;}
.cr-nav a:active{transform:scale(.97);}
/* lift the composer above the floating pill, and clear the message list */
#msgs{padding-bottom:calc(140px + env(safe-area-inset-bottom));}
