/* Claude Remote Console — styled after claude.ai/code (dark, "claude" theme).
 * Palette/metrics lifted from the official design tokens:
 * surfaces #151515/#1a1a19/#20201f, text #f0efec/#c3c2b7/#898781,
 * body 13px/19px, content column 768px, item gap 12px,
 * user bubble = accent tint at ~7% alpha, radius 10px, left-aligned. */

:root {
  --surface-1: #151515;      /* page */
  --surface-2: #1a1a19;      /* panels / pre */
  --surface-3: #20201f;      /* cards / code */
  --surface-4: #2c2c2a;      /* hover */
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .14);
  --text-1: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #898781;
  --brand: #d97757;          /* coral */
  --brand-strong: #c96442;
  --accent-blue: #2a78d6;    /* user-bubble tint base */
  --link: #7ab3e8;
  --success: #5a9e37;
  --warning: #da9c25;
  --danger: #de5454;
  --git-added: #1e9e3c;
  --git-removed: #cd2054;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans TC", Arial, sans-serif;
  --serif: "Iowan Old Style", Georgia, "Times New Roman", "Noto Serif TC", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --col: 768px;
  --gap: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 13px/1.462 var(--sans);
  background: var(--surface-1);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
::selection { background: rgba(42, 120, 214, .35); }

* { scrollbar-width: thin; scrollbar-color: var(--surface-4) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

button {
  font: inherit; color: var(--text-2); background: none;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 10px; cursor: pointer;
}
button:hover { color: var(--text-1); background: var(--surface-3); }
.err { color: var(--danger); min-height: 1.2em; }

/* ---- login ---- */
#login { display: flex; align-items: center; justify-content: center; height: 100vh; }
#loginForm { display: flex; flex-direction: column; gap: 12px; width: 280px; text-align: center; }
#loginForm h1 { font-size: 18px; font-weight: 500; margin: 0 0 8px; font-family: var(--serif); }
#loginForm input {
  font: inherit; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-1);
}
#loginForm input:focus { outline: none; border-color: var(--brand); }
#loginForm button { background: var(--brand); border-color: var(--brand); color: #fff; padding: 7px; border-radius: 8px; }
#loginForm button:hover { background: var(--brand-strong); }

/* ---- layout ---- */
#app { display: flex; height: 100vh; height: 100dvh; }
#sidebar {
  width: 264px; min-width: 220px; flex-shrink: 0;
  border-right: 1px solid var(--border); background: var(--surface-2);
  display: flex; flex-direction: column;
}
#sidebar header {
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 500; font-size: 13px; color: var(--text-1); letter-spacing: .01em; }
#notifBtn { padding: 2px 6px; border: none; opacity: .5; font-size: 13px; }
#notifBtn:hover { background: none; }
#notifBtn.on { opacity: 1; }
#sessions { flex: 1; overflow-y: auto; padding: 4px 8px; }
#connState { padding: 8px 14px; color: var(--text-3); font-size: 11px; border-top: 1px solid var(--border); }
#connState.ok { color: var(--text-3); }

.sessionItem {
  padding: 8px 10px; cursor: pointer; border-radius: 8px; margin-bottom: 2px;
}
.sessionItem:hover { background: var(--surface-3); }
.sessionItem.active { background: var(--surface-3); }
.sessionItem .t { display: flex; align-items: center; gap: 7px; }
.sessionItem .name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500; color: var(--text-1);
}
.sessionItem .meta {
  color: var(--text-3); font-size: 11px; margin-top: 2px; padding-left: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--text-3); }
.dot.working { background: var(--brand); animation: pulse 1.4s ease-in-out infinite; }
.dot.idle { background: var(--success); }
.dot.offline, .dot.ended { background: var(--surface-4); }
.badge {
  background: var(--brand); color: #fff; font-size: 10px; border-radius: 8px;
  padding: 0 6px; line-height: 16px; font-weight: 600;
}
@keyframes pulse { 50% { opacity: .3; } }

/* ---- main ---- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface-1); }
#placeholder { margin: auto; color: var(--text-3); }
#view { display: flex; flex-direction: column; height: 100%; min-height: 0; }

#topbar { padding: 10px 20px 9px; border-bottom: 1px solid var(--border); }
.titleRow { display: flex; align-items: center; gap: 10px; min-width: 0; }
#topbar { min-width: 0; }
#sTitle {
  font-weight: 500; font-size: 13px; color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.metaRow {
  color: var(--text-3); font-size: 11px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip {
  font-size: 11px; padding: 1px 8px; border-radius: 10px; line-height: 16px;
  border: 1px solid var(--border); color: var(--text-2); flex-shrink: 0;
}
.chip.working { color: var(--brand); border-color: rgba(217, 119, 87, .4); }
.chip.idle { color: var(--text-2); }
.chip.offline, .chip.ended, .chip.dim { color: var(--text-3); }

/* ---- permissions ---- */
#perms:not(:empty) { padding: 12px 20px 0; max-width: calc(var(--col) + 40px); margin: 0 auto; width: 100%; }
.permCard {
  border: 1px solid rgba(218, 156, 37, .35); border-radius: 10px; background: var(--surface-2);
  padding: 10px 14px; margin-bottom: 8px;
}
.permCard .head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.permCard .tool { font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--warning); }
.permCard pre {
  margin: 8px 0 0; max-height: 160px; overflow: auto; font-size: 11.5px;
  font-family: var(--mono); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; white-space: pre-wrap; word-break: break-all;
  color: var(--text-2);
}
.permCard .btns { margin-top: 10px; display: flex; gap: 8px; }
.permCard .allow { color: var(--text-1); background: var(--brand); border-color: var(--brand); }
.permCard .allow:hover { background: var(--brand-strong); }
.permCard .deny:hover { color: var(--danger); border-color: var(--danger); background: none; }
.permCard.resolved { opacity: .5; border-color: var(--border); }

/* ---- feed ---- */
#feedWrap { flex: 1; overflow-y: auto; min-height: 0; }
#feed { max-width: calc(var(--col) + 40px); margin: 0 auto; padding: 20px 20px 12px; }
#loadEarlier {
  display: block; margin: 0 auto 16px; font-size: 11px; color: var(--text-3);
  border: none; padding: 4px 10px;
}

.msg { margin-bottom: var(--gap); }
.msg .who { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }

/* user turns — left-aligned tinted bubbles, like claude.ai/code */
.msg.user { display: flex; flex-direction: column; align-items: flex-start; margin: 20px 0; }
.bubble {
  border-radius: 10px; padding: 8px 12px; max-width: 75%;
  white-space: pre-wrap; word-break: break-word; width: fit-content;
  background: rgba(42, 120, 214, .08); color: var(--text-1);
}
.msg.user.web .bubble { background: rgba(217, 119, 87, .1); }
.msg.user .pending { opacity: .55; }
.msg.user .stat { font-size: 11px; color: var(--text-3); margin-top: 3px; }

/* assistant — plain text on the page, no bubble */
.assistant .md { max-width: none; }
.md { color: var(--text-1); }
.md p { margin: 6px 0; }
.md pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; font-family: var(--mono); font-size: 12px;
  line-height: 1.5;
}
.md code {
  font-family: var(--mono); font-size: .92em; background: var(--surface-3);
  border: 1px solid var(--border); padding: 0 4px; border-radius: 4px;
}
.md pre code { background: none; border: none; padding: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 16px 0 6px; line-height: 1.35; font-weight: 600; }
.md h1 { font-size: 15px; } .md h2 { font-size: 14px; } .md h3, .md h4 { font-size: 13px; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md blockquote { margin: 6px 0; padding: 2px 12px; border-left: 3px solid var(--surface-4); color: var(--text-2); }
.md a { color: var(--link); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; font-size: 12.5px; }
.md th, .md td { border: 1px solid var(--border-strong); padding: 4px 10px; }
.md th { background: var(--surface-2); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* thinking — quiet collapsible row, serif italic body */
details.thinking { margin: var(--gap) 0; }
details.thinking summary {
  cursor: pointer; font-size: 13px; color: var(--text-3); user-select: none;
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
details.thinking summary::-webkit-details-marker { display: none; }
details.thinking summary::before { content: '▸'; font-size: 10px; transition: transform .12s; }
details[open].thinking summary::before { transform: rotate(90deg); }
details.thinking summary:hover { color: var(--text-2); }
details.thinking .body {
  white-space: pre-wrap; word-break: break-word;
  font-family: var(--serif); font-style: italic; font-size: 13px; line-height: 1.55;
  color: var(--text-2); margin: 6px 0 2px 4px; padding-left: 12px;
  border-left: 2px solid var(--surface-4);
}

/* tool rows — quiet one-liners, hover to reveal, like the official transcript */
.toolCard { margin: 0; font-size: 13px; }
.toolCard summary {
  cursor: pointer; user-select: none; list-style: none;
  display: flex; align-items: baseline; gap: 8px;
  padding: 3px 8px; margin-left: -8px; border-radius: 6px;
  color: var(--text-2); max-width: 100%;
}
.toolCard summary::-webkit-details-marker { display: none; }
.toolCard summary::before {
  content: '▸'; font-size: 9px; color: var(--text-3); flex-shrink: 0;
  transition: transform .12s;
}
.toolCard[open] > summary::before { transform: rotate(90deg); }
.toolCard summary:hover { color: var(--text-1); background: var(--surface-2); }
.toolCard .tverb { font-weight: 500; flex-shrink: 0; color: var(--text-1); }
.toolCard .targ {
  color: var(--text-3); font-family: var(--mono); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0;
}
.toolCard summary:hover .targ { color: var(--text-2); }
.toolCard .tstat { flex-shrink: 0; font-size: 11px; color: var(--text-3); align-self: center; }
.toolCard .tstat.err { color: var(--danger); }
.toolCard .tstat.ok { color: var(--success); }
.toolCard .inner {
  margin: 4px 0 10px 6px; padding: 0 0 0 12px;
  border-left: 2px solid var(--border-strong);
}
.toolCard pre {
  margin: 0; font-family: var(--mono); font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto;
  padding: 8px 10px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text-2);
}
.toolCard pre.cmd { color: var(--text-1); background: var(--surface-3); }
.toolCard pre.err { color: var(--danger); border-color: rgba(222,84,84,.3); }
.toolCard .rlabel {
  color: var(--text-3); font-size: 10px; text-transform: uppercase;
  letter-spacing: .06em; margin: 8px 0 3px;
}
.toolCard .rlabel:first-child { margin-top: 0; }
.toolCard .rnote { color: var(--text-3); font-size: 11.5px; margin: 4px 0 0; }
.toolCard img { max-width: 100%; border-radius: 6px; margin-top: 6px; }
.msg.assistant + .toolCard, .md + .toolCard { margin-top: 8px; }
.toolCard + .msg.assistant, .toolCard + .sysline, .toolCard + .divider { margin-top: 10px; }

.sysline { color: var(--text-3); font-size: 11.5px; margin: 10px 0; }
.divider {
  text-align: center; color: var(--text-3); font-size: 11px; margin: 18px 0;
  border-top: 1px solid var(--border); padding-top: 8px;
}
.fileCard {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  padding: 7px 12px; margin: 6px 0; font-size: 12.5px;
}
.fileCard a { color: var(--link); text-decoration: none; }
.fileCard a:hover { text-decoration: underline; }
.imgAttach { max-width: 320px; max-height: 240px; border-radius: 8px; display: block; margin-top: 4px; }

#typing .bubble { background: none; color: var(--text-3); font-style: italic; padding-left: 0; }

/* ---- status strip ---- */
#statusStrip {
  display: flex; align-items: center; gap: 8px;
  max-width: calc(var(--col) + 40px); margin: 0 auto; width: 100%;
  padding: 4px 20px 6px; font-size: 12px; color: var(--text-3);
  font-family: var(--mono);
}
.pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--brand);
  animation: pulse 1.4s infinite; flex-shrink: 0;
}

/* ---- composer — rounded floating box like claude.ai/code ---- */
#composer {
  max-width: calc(var(--col) + 40px); margin: 0 auto; width: 100%;
  padding: 4px 20px 16px;
}
#composer .box {
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: 14px; padding: 10px 12px 8px;
}
#composer .box:focus-within { border-color: rgba(217, 119, 87, .55); }
#composer textarea {
  display: block; width: 100%; resize: none; font: inherit; color: var(--text-1);
  background: none; border: none; padding: 0 2px; max-height: 40vh;
}
#composer textarea:focus { outline: none; }
#composer textarea::placeholder { color: var(--text-3); }
#composer .row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
#composer .spacer { flex: 1; }
#attachBtn { border: none; padding: 3px 6px; font-size: 14px; opacity: .7; }
#attachBtn:hover { opacity: 1; background: var(--surface-4); }
#fileChip { color: var(--text-3); font-size: 11.5px; }
#sendBtn {
  background: var(--brand); border: none; color: #fff;
  width: 28px; height: 28px; border-radius: 50%; padding: 0;
  font-size: 15px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
#sendBtn:hover { background: var(--brand-strong); color: #fff; }
#sendBtn:disabled { opacity: .4; cursor: default; }

/* ---- toasts ---- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 10px 14px; max-width: 340px; font-size: 12.5px;
  color: var(--text-1); box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

/* ---- mobile ---- */
#menuBtn { display: none; }
@media (max-width: 720px) {
  #sidebar {
    position: fixed; inset: 0 25% 0 0; z-index: 20; width: auto;
    transform: translateX(-102%); transition: transform .18s;
    box-shadow: 8px 0 32px rgba(0, 0, 0, .5);
  }
  #sidebar.open { transform: none; }
  #topbar { padding-left: 52px; }
  #menuBtn {
    display: block; position: fixed; top: 8px; left: 10px; z-index: 30;
    padding: 4px 10px; background: var(--surface-3); border-radius: 8px;
  }
  .bubble { max-width: 95%; }
}

/* ---- topbar meters: model / context / quota ---- */
.chip.meter {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 10.5px; white-space: nowrap;
}
.chip.meter:empty { display: none; }
.chip.meter .bar {
  width: 34px; height: 4px; border-radius: 2px;
  background: var(--surface-4); overflow: hidden; flex-shrink: 0;
}
.chip.meter .bar i { display: block; height: 100%; background: var(--text-3); border-radius: 2px; }
.chip.meter.ok  .bar i { background: var(--success); }
.chip.meter.mid .bar i { background: var(--warning); }
.chip.meter.hi  .bar i { background: var(--danger); }
.chip.meter.hi { color: var(--danger); border-color: rgba(222,84,84,.35); }
.chip.meter .lbl { color: var(--text-3); }
@media (max-width: 720px) { .chip.meter .lbl { display: none; } }
