/* ============================================================
   VPS Assistant — monochrome terminal theme
   grayscale only · monospace · square corners · inverted accents
   ============================================================ */

:root {
  --bg: #0b0b0b;
  --panel: #101010;
  --panel2: #151515;
  --border: #2a2a2a;
  --border-bright: #454545;
  --fg: #e8e8e8;
  --dim: #9a9a9a;
  --faint: #5f5f5f;
  --inv-bg: #e8e8e8;
  --inv-fg: #0b0b0b;
  /* the one deliberate exception to monochrome: errors/warnings */
  --red: #f05555;
  --danger: #f05555; /* legacy alias used by inline styles */
  --blue: #79b8ff;   /* user prompt accent */
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo,
               Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.55;
}

::selection { background: var(--fg); color: var(--bg); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

.hidden { display: none !important; }
code, pre {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo,
               Consolas, "Liberation Mono", monospace;
}

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 26px 24px;
}
.auth-card h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: .5px;
}
.auth-card h1::before { content: "# "; color: var(--faint); }
.auth-card p { color: var(--dim); margin: 6px 0 18px; font-size: 13px; }
.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;   /* prevents iOS zoom */
  font-family: inherit;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--fg);
}
.auth-card button {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--fg);
  background: var(--inv-bg);
  color: var(--inv-fg);
  font-weight: 700;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.auth-card button:hover { background: #fff; }
.err { color: var(--red); font-weight: 700; min-height: 18px; margin-top: 10px !important; font-size: 13px; }
.err:not(:empty)::before { content: "!! "; }

/* ---------- app shell ---------- */
.app {
  display: flex;
  height: 100dvh;
}
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- sidebar ---------- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.side-title { font-weight: 700; letter-spacing: .5px; }
.side-title::before { content: "# "; color: var(--faint); }
.chat-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 8px 12px;
  cursor: pointer;
  color: var(--dim);
  border-left: 2px solid transparent;
  font-size: 13px;
}
.chat-item::before { content: "> "; color: var(--faint); flex-shrink: 0; }
.chat-item:hover { color: var(--fg); background: var(--panel2); }
.chat-item.active {
  color: var(--fg);
  border-left-color: var(--fg);
  background: var(--panel2);
}
.ci-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ci-dots {
  background: transparent;
  border: none;
  color: var(--faint);
  font-size: 15px;
  line-height: 1;
  padding: 2px 5px;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}
.ci-dots:hover { color: var(--fg); }
.ctx-menu {
  position: fixed;
  z-index: 90;
  background: var(--panel);
  border: 1px solid var(--border-bright);
  min-width: 150px;
  padding: 4px;
}
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: inherit;
  font-size: 12.5px;
  padding: 7px 10px;
  cursor: pointer;
}
.ctx-menu button:hover { background: var(--panel2); }
.ctx-menu button.danger { color: var(--red); }
.run-mark { color: var(--red); animation: blink 1.1s steps(1) infinite; }
.side-foot {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.side-btn {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--dim);
  font-family: inherit;
  font-size: 12.5px;
  padding: 7px 8px;
  cursor: pointer;
}
.side-btn:hover { color: var(--fg); background: var(--panel2); }
.backdrop { display: none; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand {
  font-weight: 700;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand::before { content: "■"; color: var(--fg); font-size: 10px; }
@keyframes blink { 50% { opacity: 0; } }
.top-actions { display: flex; align-items: center; gap: 6px; }
.badge {
  font-size: 11px;
  color: var(--dim);
  border: 1px solid var(--border);
  padding: 3px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}
.badge::before { content: "["; color: var(--faint); }
.badge::after  { content: "]"; color: var(--faint); }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }

/* ---------- chat ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 26px;
}
.chat-inner { max-width: 820px; margin: 0 auto; }

.msg { margin-bottom: 16px; }
.bubble {
  position: relative;
  max-width: 100%;
  padding: 1px 0 1px 7ch;
  overflow-wrap: break-word;
}
.msg.user .bubble::before {
  content: "you >";
  position: absolute;
  left: 0;
  top: 1px;
  color: var(--blue);
}
.msg.assistant .bubble::before {
  content: "vpsa>";
  position: absolute;
  left: 0;
  top: 1px;
  color: var(--fg);
  font-weight: 700;
}
.msg.user .bubble { color: var(--dim); }
.msg.user .bubble strong, .msg.assistant .bubble strong { color: var(--fg); }
.bubble p { margin: .25em 0; }
.bubble pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-bright);
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 12.5px;
  margin: .5em 0;
}
.bubble :not(pre) > code {
  background: var(--panel2);
  border: 1px solid var(--border);
  padding: 0 5px;
  font-size: .92em;
}
.bubble ul, .bubble ol { margin: .35em 0; padding-left: 20px; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1em; margin: .6em 0 .3em; text-decoration: underline; }
.bubble a { color: var(--fg); text-decoration: underline; }
.bubble em { color: var(--dim); }
.alert {
  color: var(--red);
  font-weight: 700;
  border: 1px solid var(--red);
  padding: 2px 8px;
  display: inline-block;
  background: rgba(240, 85, 85, .07);
}

/* tool chips */
.tool-chip {
  margin: 0 0 10px 7ch;
  max-width: calc(100% - 7ch);
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 12.5px;
}
.tool-chip summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  user-select: none;
}
.tool-chip summary::-webkit-details-marker { display: none; }
.t-ico { color: var(--faint); flex-shrink: 0; }
.tool-chip.done .t-ico { color: var(--fg); }
.t-name { color: var(--fg); font-weight: 700; }
.t-name::before { content: "["; color: var(--faint); font-weight: 400; }
.t-name::after  { content: "]"; color: var(--faint); font-weight: 400; }
.t-brief {
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}
.tool-chip pre {
  margin: 0;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  max-height: 260px;
  overflow: auto;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.tool-chip.failed { border-style: dashed; border-color: var(--border-bright); }
.tool-chip.failed .t-name::before { content: "[!"; }
.tool-chip.failed .t-name::after  { content: "]"; }

.cursor::after {
  content: "█";
  animation: blink 1s steps(1) infinite;
  color: var(--fg);
}

.status-line {
  color: var(--faint);
  font-size: 12.5px;
  margin: 4px 0 12px 7ch;
}
.status-line::before { content: "·· "; }

.empty-hero {
  margin-top: 10vh;
  color: var(--dim);
}
.hero-title {
  color: var(--fg);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
  margin: 0 0 4px;
}
.hero-tag { color: var(--faint); font-size: 13px; }
.hero-tag::before { content: "-- "; }
.hero-tag::after  { content: " --"; }
.suggestions {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 480px;
}
.suggestions button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-left: 2px solid var(--border);
  color: var(--dim);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}
.suggestions button::before { content: "> "; color: var(--faint); }
.suggestions button:hover {
  color: var(--fg);
  border-left-color: var(--fg);
  background: var(--panel2);
}

/* ---------- composer ---------- */
.composer-wrap {
  flex-shrink: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.composer {
  display: flex;
  align-items: stretch;
  gap: 0;
  max-width: 820px;
  margin: 0 auto;
  border: 1px solid var(--border);
  background: var(--panel);
}
.composer:focus-within { border-color: var(--border-bright); }
.prompt-char {
  display: flex;
  align-items: center;
  padding: 0 4px 0 12px;
  color: var(--dim);
  font-weight: 700;
  user-select: none;
}
#input {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--fg);
  font-size: 16px;   /* prevents iOS zoom */
  font-family: inherit;
  max-height: 160px;
  line-height: 1.45;
  padding: 11px 10px;
}
#input:focus { outline: none; }
.composer button {
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font-size: 12px;
  font-family: inherit;
  padding: 0 14px;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 46px;
}
.composer button:hover { background: var(--inv-bg); color: var(--inv-fg); }
#btn-send:disabled { opacity: .35; cursor: default; }
#btn-send:disabled:hover { background: transparent; color: var(--fg); }
#btn-send.stopping {
  background: var(--red);
  color: #fff;
  font-weight: 700;
}
#btn-send.stopping:hover { background: #d94343; }

#btn-mic.recording {
  background: var(--inv-bg);
  color: var(--inv-fg);
  animation: invpulse 1.2s steps(2) infinite;
}
@keyframes invpulse { 50% { background: var(--panel2); color: var(--fg); } }
@media (prefers-reduced-motion: reduce) {
  #btn-mic.recording, .brand::after, .cursor::after { animation: none; }
}

.hint {
  text-align: center;
  color: var(--faint);
  font-size: 9.5px;
  margin: 4px 0 0;
}

/* ---------- settings modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 80;   /* above sidebar drawer (60) and its backdrop (55) */
}
.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border-bright);
  padding: 0 18px 18px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 -18px 0;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}
.modal-head h2 { margin: 0; font-size: 13px; letter-spacing: .5px; }
.modal-head h2::before { content: "# "; color: var(--faint); }
.fld-label {
  display: block;
  color: var(--faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 16px 0 6px;
}
.key-row { display: flex; align-items: center; gap: 8px; }
.key-status {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 12.5px;
  overflow-x: auto;
  white-space: nowrap;
  color: var(--dim);
}
#key-input {
  width: 100%;
  margin-top: 8px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
  font-family: inherit;
}
#key-input:focus { outline: none; border-color: var(--fg); }
.mini-btn {
  padding: 7px 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.mini-btn:hover { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); }
.mini-btn.primary { background: var(--inv-bg); color: var(--inv-fg); border-color: var(--inv-bg); font-weight: 700; }
.mini-btn.danger { border-color: var(--border-bright); }
hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 16px 0;
}

/* reasoning segmented control */
.seg {
  display: flex;
  border: 1px solid var(--border);
}
.seg button {
  flex: 1;
  padding: 8px 0;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--dim);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.seg button:last-child { border-right: none; }
.seg button:hover { color: var(--fg); background: var(--panel2); }
.seg button.active {
  background: var(--inv-bg);
  color: var(--inv-fg);
  font-weight: 700;
}
.fld-note {
  color: var(--faint);
  font-size: 10px;
  margin: 6px 0 0;
  line-height: 1.4;
}

#btn-menu { display: none; }

@media (max-width: 900px) {
  #btn-menu { display: inline-block; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 60;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .18s ease-out;
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 55;
  }
}

@media (min-width: 640px) {
  .chat { padding: 22px; }
  .t-brief { max-width: 380px; }
}
