:root {
  --bg: #0E1116;
  --surface: #161C24;
  --chip: #141A22;
  --line: #26303C;
  --accent: #8AB4FF;
  --text: #E8EAF0;
  --muted: #7A8494;
  --green: #59C37A;
  --orange: #E5A25A;
  --red: #E56B5A;
  --user-bubble: #1D3A66;
  --ai-bubble: #1A2029;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overscroll-behavior: none;
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body { display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  position: relative;
  z-index: 50;
}
#title { font-size: 18px; font-weight: 700; }
#btn-settings {
  background: none; border: 0; color: var(--muted); font-size: 22px;
  padding: 6px 10px; cursor: pointer;
}

#tabsrow {
  background: var(--bg); padding: 0 0 8px;
}
#tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 0 12px;
  background: var(--bg); scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 5px 13px; border-radius: 999px; font-size: 12.5px;
  color: var(--muted); background: var(--chip); border: 1px solid var(--line);
  cursor: pointer; white-space: nowrap;
}
.tab.active {
  color: #0A1830; background: var(--accent); border-color: var(--accent);
  font-weight: 600;
}
.tab.special { border-color: #4A5E80; color: var(--accent); }
.tab.special.active { border-color: var(--accent); }
.tab .dot { color: var(--green); }
.tab .tk {
  margin-left: 6px; padding-left: 6px; border-left: 1px solid var(--line);
  color: var(--accent); font-size: 10.5px; font-variant-numeric: tabular-nums;
}
.tab.active .dot { color: #0A1830; }
.tab.active .tk { color: #0A1830; border-left-color: rgba(0,0,0,.25); }

/* tab color picker */
.colorgrid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px;
  justify-items: center; margin: 6px 0 2px;
}
.swatch {
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-shadow: inset 0 0 0 2px rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--muted); background: var(--chip);
}
.swatch.sel { border-color: #fff; }
.swatch.none { border: 2px dashed var(--line); }

#pager-viewport { flex: 1; overflow: hidden; position: relative; touch-action: pan-y; }
#pager {
  position: relative; width: 100%; height: 100%;
  transition: transform .22s ease;
  will-change: transform;
}
#pager.dragging { transition: none; }
.page {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex; flex-direction: column; overflow: hidden;
  padding: 0 12px;
  transition: transform .22s ease;
  will-change: transform;
}
#pager.dragging .page { transition: none; }

.linkrow {
  flex: none; display: flex; gap: 6px; margin: 0 0 4px;
}
.linkbar {
  flex: 1; display: block; text-align: center;
  padding: 9px; border-radius: 10px; text-decoration: none;
  background: #10261C; border: 1px solid #2C5A41; color: #7CE0A8;
  font-size: 13.5px; font-weight: 600;
}
.linkrefresh {
  flex: none; width: 40px; border-radius: 10px; cursor: pointer;
  background: #10261C; border: 1px solid #2C5A41; color: #7CE0A8;
  font-size: 17px; line-height: 1;
}
.linkrefresh:active { background: #16402C; }
.linkrefresh.busy { animation: linkspin 1.1s linear infinite; opacity: .8; }
@keyframes linkspin { to { transform: rotate(360deg); } }
.status {
  flex: none; font-size: 11px; color: var(--muted);
  padding: 2px 4px 6px; display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
.status > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.status.online { color: var(--green); }
.status.offline { color: var(--orange); }
.mbtn {
  flex: none; color: var(--accent); background: var(--chip); border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 8px; cursor: pointer; font-size: 11px;
}
.sbtn { flex: none; color: var(--muted); cursor: pointer; padding: 2px 4px; }
.tbtn {
  flex: none; color: var(--muted); background: var(--chip); border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 8px; font-size: 11px; font-variant-numeric: tabular-nums;
  cursor: default; user-select: none; -webkit-user-select: none;
}
.del { flex: none; color: var(--muted); cursor: pointer; padding: 2px 4px; }
.del:active { color: var(--red); }
.archrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.archrow:last-of-type { border-bottom: 0; }
#btn-menu {
  flex: none;
  background: none; border: 0; color: var(--muted); font-size: 26px;
  padding: 2px 10px; cursor: pointer; font-weight: 700; line-height: 1;
  margin: -4px -6px 0 0;
}

/* top-level menu (drops from the header) */
.topmenu {
  position: absolute; top: 100%; right: 12px; z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  min-width: 200px; padding: 4px;
}
.trow { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.trow:active { background: var(--chip); }
.ticon { width: 24px; text-align: center; font-size: 17px; }

.msgs { flex: 1; overflow-y: auto; padding: 6px 2px 10px; scroll-behavior: smooth; }

.row { display: flex; margin: 3px 0; }
.row.user { justify-content: flex-end; }
.bubble {
  max-width: 86%; padding: 9px 13px; border-radius: 16px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
  font-size: 15px;
}
.row.user .bubble { background: var(--user-bubble); border-bottom-right-radius: 5px; }
.row.ai { justify-content: flex-start; }
.row.ai .bubble { background: var(--ai-bubble); border-bottom-left-radius: 5px; }
.bubble .cursor { color: var(--accent); animation: blink 1s step-start infinite; }
@keyframes blink { 50% { opacity: 0; } }

.thinking {
  color: #5F6B7C; font-size: 12px; font-style: italic; cursor: pointer;
  margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thinking.open { white-space: pre-wrap; }
.thinking.live {
  max-height: 4.5em; overflow-y: hidden; white-space: pre-wrap;
  font-style: italic; color: #5F6B7C; margin-bottom: 4px;
}

.tools { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.tool {
  font-size: 12px; color: var(--muted); background: var(--chip);
  border: 1px solid var(--line); border-radius: 9px; padding: 4px 9px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool.ok { color: var(--green); }
.tool.err { color: var(--red); }
.tool.run { color: var(--accent); }

.row.bash { justify-content: flex-start; }
.row.bash .bubble {
  background: var(--chip); border: 1px solid var(--line); border-radius: 10px;
  font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; color: #8B96A5;
}

.inputbar {
  flex: none; display: flex; gap: 8px; align-items: flex-end;
}
.bottom {
  flex: none; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border-radius: 14px 14px 0 0;
  margin: 0 -12px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
}
.mic {
  width: 100%; padding: 13px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--chip); color: var(--text); font: inherit; font-size: 14.5px; cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
.mic.rec {
  background: #3A1620; border-color: var(--red); color: #ffd9d9;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .7; } }
.inputbar textarea {
  flex: 1; resize: none; background: var(--chip); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px;
  font: inherit; max-height: 120px; outline: none;
}
.inputbar button {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--accent); color: #0A1830; font-size: 19px; cursor: pointer;
}
.inputbar button.stop { background: var(--orange); color: #1a1208; }

/* new-window page */
.newpage { justify-content: center; padding: 0 8px; }
.newpage .card { display: flex; flex-direction: column; gap: 10px; }
.newpage h2 { margin: 0 0 4px; font-size: 21px; }
.newpage p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.newpage label { font-size: 12px; color: var(--muted); }
.newpage input, .newpage textarea {
  background: var(--chip); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font: inherit; outline: none;
}
.newpage textarea { min-height: 90px; resize: vertical; }
.newpage button {
  margin-top: 8px; padding: 12px; border: 0; border-radius: 10px;
  background: var(--accent); color: #0A1830; font: inherit; font-weight: 600; cursor: pointer;
}

/* assets gallery */
/* window dropdown menu */
.status { position: relative; }
.mbtn.menubtn {
  font-size: 19px; line-height: 1; padding: 4px 14px; font-weight: 700;
}
.pagemenu {
  position: absolute; top: 100%; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  min-width: 190px; padding: 4px; margin-top: 4px;
}
.pmrow {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.pmrow:active { background: var(--chip); }
.pmrow.pmdanger { color: var(--red); }
.pmicon { width: 20px; text-align: center; font-size: 15px; }
.mbtn.assetsbtn {
  font-size: 17px; line-height: 1.1; padding: 2px 10px;
  position: relative;
}
.mbtn.assetsbtn.empty { opacity: .45; }
.mbtn.assetsbtn sup {
  font-size: 9px; line-height: 1; position: absolute; top: -2px; right: 0;
  color: var(--orange); font-weight: 700;
}
.assetgrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px; max-height: 55vh; overflow-y: auto;
}
.assetcell { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.assetimg {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--line); display: block;
}
.assetcap {
  font-size: 9px; color: var(--muted); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}

/* dialog */
dialog {
  border: 0; border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 18px; width: min(92vw, 380px);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h3 { margin: 0 0 8px; font-size: 16px; }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
dialog .btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
dialog button {
  padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--chip); color: var(--text); font: inherit; cursor: pointer;
}
dialog button.primary { background: var(--accent); color: #0A1830; border: 0; font-weight: 600; }
dialog input, dialog textarea {
  width: 100%; background: var(--chip); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 10px; font: inherit; outline: none;
}
dialog label { font-size: 12px; color: var(--muted); display: block; margin: 8px 0 3px; }

/* VPS resources panel */
.res { display: flex; flex-direction: column; gap: 10px; }
.res .sub { color: var(--muted); font-size: 12px; margin-top: -6px; }
.res .gauge { display: flex; flex-direction: column; gap: 3px; }
.res .glabel { display: flex; justify-content: space-between; font-size: 12.5px; }
.res .glabel b { font-variant-numeric: tabular-nums; font-weight: 600; }
.res .bar { height: 9px; border-radius: 5px; background: var(--chip); border: 1px solid var(--line); overflow: hidden; }
.res .bar > i { display: block; height: 100%; width: 0; background: var(--green); border-radius: 4px; transition: width .5s ease, background .5s ease; }
.res .bar > i.warn { background: var(--orange); }
.res .bar > i.crit { background: var(--red); }
.res canvas { width: 100%; height: 52px; display: block; }
.res .ptable { width: 100%; border-collapse: collapse; font-size: 12px; }
.res .ptable td { padding: 3px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.res .ptable tr:last-child td { border-bottom: 0; }
.res .ptable .pname { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.res .ptable .num { text-align: right; font-variant-numeric: tabular-nums; }
.res .phead td { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.res .meta { font-size: 11.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }

/* tab reorder dialog */
.reorder { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; margin: 4px 0 2px; }
.revrow {
  display: flex; align-items: center; gap: 8px;
  background: var(--chip); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px;
}
.revname { flex: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.revbtn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--chip); color: var(--text); font-size: 15px; cursor: pointer;
}
.revbtn:disabled { opacity: .3; }

/* site snapshot overlay (overscroll-up at chat bottom) */
.snapov {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5,8,12,.92); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 14px;
}
.snapbox {
  max-width: 94vw; max-height: 88vh; display: flex; flex-direction: column; gap: 8px;
}
.snapbox img {
  max-width: 94vw; max-height: 80vh; border-radius: 12px;
  border: 1px solid var(--line); background: #0b0e13; display: block;
}
.snapcap { color: var(--muted); font-size: 12px; text-align: center; }
