:root {
  --paper: #fbf6f4;
  --paper-warm: #f7f1ec;
  --ink: #1c1816;
  --muted: #766c66;
  --faint: #a89e96;
  --lotus: #7a462a;
  --lotus-soft: #a06c48;
  --connected: #348414;
  --selected: #f0e8e0;
  --bubble: #f2ece7;
  --code: #f4efe8;
  --code-h: #fcf9f6;
  --button: #2b2725;
  --stroke: #e0d8d2;
  --subtitle: #9e8a7a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --header: 78px;
  --sidebar: 292px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
}
body { padding: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#splash {
  position: fixed; inset: 0; z-index: 40;
  background: var(--paper);
  display: grid; place-items: center;
  overflow: hidden;
}
#splash img {
  width: 100%; height: 100%; object-fit: cover;
}
.splash-glow {
  position: absolute; width: 55vmin; height: 55vmin; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 220, 150, .28), transparent 70%);
  animation: pulse 2.2s ease-in-out infinite alternate;
  pointer-events: none;
}
.splash-mist {
  position: absolute; width: 80%; height: 30%; bottom: 18%;
  background: radial-gradient(ellipse, rgba(255,255,255,.22), transparent 70%);
  filter: blur(18px);
  animation: drift 3.4s ease-in-out infinite alternate;
  pointer-events: none;
}
.splash-bar-wrap {
  position: absolute; left: 50%; bottom: 16%; transform: translateX(-50%);
  width: min(320px, 30vw); text-align: center;
}
.splash-bar {
  height: 8px; border-radius: 99px;
  background: rgba(90, 70, 55, .45);
  overflow: hidden;
}
.splash-bar i {
  display: block; height: 100%; width: 4%;
  background: #f5eee4;
  border-radius: 99px;
  transition: width .2s linear;
}
.splash-bar-wrap p {
  margin: 10px 0 0;
  font-size: 13px;
  color: rgba(70, 52, 40, .9);
  font-family: system-ui, sans-serif;
}
@keyframes pulse { from { opacity: .45; transform: scale(.96); } to { opacity: 1; transform: scale(1.05); } }
@keyframes drift { from { transform: translateX(-4%); } to { transform: translateX(6%); } }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding-top: var(--safe-t);
}
#app[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--header);
  padding: 8px 14px 8px 12px;
  background: var(--paper) url("img/mountains.png") right center / 42% no-repeat;
  border-bottom: 1px solid color-mix(in srgb, var(--stroke) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lotus { width: 42px; height: 42px; flex: none; }
.brand h1 {
  margin: 0; font-size: 20px; font-weight: 500; letter-spacing: .28em;
}
.brand p {
  margin: 2px 0 0; font-size: 8px; letter-spacing: .16em;
  color: var(--subtitle); font-family: system-ui, sans-serif;
}
.pills { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(255,255,255,.72);
  border: 1px solid var(--stroke);
  font-family: system-ui, sans-serif; font-size: 12.5px;
}
.model-pill { padding-right: 8px; }
.model-pill select {
  border: 0; background: transparent; max-width: 180px; outline: none;
}
.balance-pill {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.balance-figure {
  margin: 8px 0 4px;
  font-size: 22px;
  font-weight: 650;
  font-family: system-ui, sans-serif;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: orange; }
.dot.on { background: var(--connected); }
.sep { color: var(--faint); }
.sun { color: var(--lotus); }
.icon-btn, .send, .new-dialog, .primary, .side-actions button, .diff-bar button, .row button {
  font-family: system-ui, sans-serif;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 12px;
  border: 1px solid var(--stroke); background: rgba(255,255,255,.72);
}
#install-btn { width: auto; padding: 0 12px; font-size: 12.5px; }
.menu-btn { display: none; }

.shell { display: flex; flex: 1 1 0; min-height: 0; overflow: hidden; }
aside {
  position: relative;
  width: var(--sidebar); flex: none;
  padding: 10px 12px 24px;
  border-right: 1px solid var(--stroke);
  overflow: auto;
  background: var(--paper);
}
.pine {
  position: absolute; left: 0; bottom: 0; width: 100%;
  pointer-events: none; opacity: .95;
}
.new-dialog {
  position: relative; z-index: 1;
  width: 100%; border: 0; border-radius: 999px;
  background: var(--button); color: #fff;
  padding: 10px 14px; font-size: 13.5px;
}
.side-actions { display: flex; gap: 8px; margin: 10px 0; position: relative; z-index: 1; }
.side-actions button, #session-search {
  flex: 1; border: 1px solid var(--stroke); background: rgba(255,255,255,.72);
  border-radius: 999px; padding: 6px 10px; font-size: 12px;
}
#session-search { width: 100%; margin-bottom: 8px; position: relative; z-index: 1; }
aside h2 {
  position: relative; z-index: 1;
  margin: 14px 8px 6px; font-size: 13.5px; font-weight: 600;
  font-family: system-ui, sans-serif;
}
.side-head {
  display: flex; align-items: center; gap: 8px;
  position: relative; z-index: 1;
}
.side-head h2 { flex: 1; margin: 14px 8px 6px; }
.mini-new {
  margin: 14px 8px 6px 0;
  border: 0; background: var(--button); color: #fff;
  border-radius: 999px; padding: 4px 10px; font-size: 11.5px; font-weight: 600;
  font-family: system-ui, sans-serif;
}
.chain-bar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  border: 1px solid var(--stroke); background: #fff;
  border-radius: 999px; padding: 5px 10px; margin: 0 0 8px;
  font-family: system-ui, sans-serif; font-size: 11.5px; color: var(--ink);
  width: fit-content; max-width: 100%;
}
.agent-step {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--connected); color: #fff;
  font-size: 11px; font-weight: 700; font-family: system-ui, sans-serif;
}
.model-badge {
  font-size: 11px; font-weight: 500; color: var(--muted);
  background: #fff; border: 1px solid var(--stroke);
  border-radius: 999px; padding: 2px 6px;
}
#agent-list { max-height: 180px; overflow: auto; margin: 8px 0 12px; font-family: system-ui, sans-serif; }
.agent-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; border-radius: 8px; cursor: pointer;
}
.agent-row.on { background: var(--selected); }
.agent-row small { display: block; color: var(--faint); font-size: 11px; }
#agent-model, #agent-content { width: 100%; margin-top: 4px; }
#agent-content { min-height: 120px; max-height: 220px; resize: vertical; }
.mode-switch {
  display: flex; gap: 0; margin: 0 0 8px;
  border: 1px solid var(--stroke); border-radius: 999px; overflow: hidden;
  width: fit-content; background: #fff;
  font-family: system-ui, sans-serif;
}
.mode-switch button {
  border: 0; background: transparent; padding: 6px 14px; font-size: 12.5px;
}
.mode-switch button.on { background: var(--button); color: #fff; }
.reason-btn {
  margin: 6px 0 0 30px; border: 0; background: transparent;
  color: var(--muted); font-size: 12px; font-family: system-ui, sans-serif;
  padding: 0;
}
.reason-body {
  margin: 6px 0 0 30px; padding: 8px; border-radius: 8px;
  background: var(--code); color: var(--muted); font-size: 12.5px;
  white-space: pre-wrap; font-family: system-ui, sans-serif;
}
.pending-banner { margin-top: 8px; }
.tab-actions { margin-left: auto; display: flex; gap: 6px; }
.files-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; min-height: 240px; }
#files-list { overflow: auto; border: 1px solid var(--stroke); border-radius: 10px; padding: 6px; }
#files-preview { margin: 0; max-height: 320px; }
.file-row { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 8px; font-size: 12.5px; font-family: ui-monospace, monospace; }
.file-row.active, .file-row:hover { background: var(--selected); }
@media (max-width: 720px) {
  .files-grid { grid-template-columns: 1fr; }
}
.row-item, .folder {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: 10px;
  font-family: system-ui, sans-serif; font-size: 13.5px;
  cursor: pointer;
}
.row-item.active, .row-item:hover { background: var(--selected); }
.row-item span.grow { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item .time { color: var(--faint); font-size: 11.5px; flex: none; }
.mini-icon-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--stroke) 80%, transparent);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  touch-action: manipulation;
}
.mini-icon-btn:active { background: var(--selected); }
.danger-icon-btn:active { color: #a33; border-color: #d8a0a0; }
.folder { padding-left: 28px; color: var(--ink); font-size: 13px; }
.lock { color: var(--muted); font-size: 11px; }

.banner {
  margin: 8px 16px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #f4e6d8;
  border: 1px solid var(--stroke);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  color: var(--lotus);
}
.banner[hidden] { display: none; }
.empty-server {
  margin: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
}

main {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
}
.tabs {
  display: flex; gap: 8px; padding: 8px 16px 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--stroke) 70%, transparent);
  min-height: 40px; overflow-x: auto;
  font-family: system-ui, sans-serif; font-size: 13px;
}
.tab {
  display: flex; gap: 6px; align-items: center;
  padding: 5px 10px; border-radius: 8px; cursor: default;
  min-width: 0;
}
.tab-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(46vw, 320px);
}
.tab.active { box-shadow: inset 0 -1px 0 rgba(28,24,22,.12); }
.messages-wrap {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 22px 12px;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: rgba(224, 216, 210, 0.65); }
.messages::-webkit-scrollbar-thumb {
  background: rgba(122, 70, 42, 0.58);
  border-radius: 8px;
}
.messages { scrollbar-width: thin; scrollbar-color: rgba(122, 70, 42, 0.58) rgba(224, 216, 210, 0.65); }
.msg, .msg-body, .bubble, .plain, .reason-body, .code-card, pre, code {
  user-select: text;
  -webkit-user-select: text;
}
.msg { margin-bottom: 20px; max-width: 820px; }
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: system-ui, sans-serif; font-size: 13.5px; font-weight: 600; }
.msg-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.copy-msg {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 4px;
}
.msg-actions .copy-msg { margin-left: 0; }
.msg-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--stroke) 80%, transparent);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1;
  touch-action: manipulation;
}
.msg-icon-btn:disabled, .mini-icon-btn:disabled { opacity: 0.45; pointer-events: none; }
#edit-msg-input {
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: #fff;
  min-height: 120px;
  max-height: 260px;
  resize: vertical;
}
.row button.danger-btn {
  background: #a63232;
  color: #fff;
  border-color: #a63232;
}
.jump-btns {
  position: absolute;
  right: 10px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 4;
}
.jump-btns[hidden] { display: none; }
.jump-btns button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,.94);
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(40, 20, 10, .12);
}
.program-bar {
  margin: 0 16px 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--connected);
  color: #fff;
  font-family: system-ui, sans-serif;
  font-size: 13.5px;
}
.program-bar[hidden] { display: none; }
.program-bar strong { display: block; margin-bottom: 8px; }
.program-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.program-bar button {
  border: 1px solid rgba(255,255,255,.45);
  background: transparent;
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
}
.program-bar .primary { background: #fff; color: var(--ink); border: 0; }
.who time { font-weight: 400; color: var(--faint); font-size: 12px; }
.avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: #726b66; color: #fff; display: grid; place-items: center; font-size: 11px;
}
.bubble {
  margin: 8px 0 0 30px; padding: 10px 14px; border-radius: 14px;
  background: var(--bubble); font-family: system-ui, sans-serif; font-size: 14.5px; line-height: 1.45;
  white-space: pre-wrap;
}
.plain {
  margin: 8px 0 0 30px; font-family: system-ui, sans-serif; font-size: 14.5px; line-height: 1.5;
  white-space: pre-wrap;
}
pre {
  margin: 8px 0 0 30px; padding: 10px; border-radius: 10px;
  background: var(--code); border: 1px solid var(--stroke);
  overflow: auto; font-size: 12.5px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0 30px; }
.chip {
  font-family: system-ui, sans-serif; font-size: 12px;
  padding: 4px 10px; border-radius: 999px;
  background: #fff; border: 1px solid var(--stroke);
}
.code-card {
  margin: 12px 0 0 44px; border: 1px solid var(--stroke); border-radius: 14px; overflow: hidden;
  background: var(--code);
}
.code-card header {
  display: flex; justify-content: space-between; padding: 10px 14px;
  background: var(--code-h); font-family: system-ui, sans-serif; font-size: 13px;
  border-bottom: 1px solid var(--stroke);
}
.code-card pre { margin: 0; border: 0; max-height: 320px; }

.diff-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 8px 22px 10px;
  font-family: system-ui, sans-serif; font-size: 13.5px;
}
.diff-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.diff-bar button, .row button, #check-btn, #download-btn, #close-settings {
  border: 1px solid var(--stroke); background: var(--paper);
  border-radius: 12px; padding: 9px 14px;
}
.primary, .send, .new-dialog {
  background: var(--button); color: #fff; border: 0;
}

.composer { padding: 4px 16px calc(12px + var(--safe-b)); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--stroke); border-radius: 18px;
  padding: 6px 8px; background: #fff;
}
textarea {
  flex: 1; border: 0; resize: none; min-height: 22px; max-height: 132px;
  font-family: system-ui, sans-serif; font-size: 14.5px; outline: none;
  background: transparent; line-height: 1.35;
}
.send { width: 36px; height: 36px; border-radius: 12px; }

#scrim { display: none; }
dialog {
  border: 1px solid var(--stroke); border-radius: 16px;
  background: var(--paper); padding: 20px; width: min(420px, 92vw);
  font-family: system-ui, sans-serif;
}
dialog h3 { font-family: serif; margin: 0 0 8px; }
dialog p { color: var(--muted); font-size: 13px; }
dialog label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0; }
dialog input, dialog select { width: 100%; margin-top: 4px; padding: 8px; border-radius: 8px; border: 1px solid var(--stroke); background: #fff; }
dialog label.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  margin: 10px 0;
}
dialog label.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
}
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { font-size: 12px; }
.error { color: #a33; }

@media (max-width: 860px) {
  .brand p, #status-pill span:first-of-type, #status-pill .sep { display: none; }
  .brand h1 { font-size: 15px; letter-spacing: .18em; }
  .lotus { width: 32px; height: 32px; }
  .menu-btn { display: grid; place-items: center; }
  .top { background-size: 70%; }
  aside {
    position: fixed; z-index: 20; top: calc(var(--header) + var(--safe-t)); bottom: 0; left: 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 8px 0 30px rgba(40, 20, 10, .12);
  }
  aside.open { transform: none; }
  #scrim {
    display: block; position: fixed; inset: 0; z-index: 15;
    background: rgba(28, 24, 22, .28);
  }
  #scrim[hidden] { display: none; }
  .messages { padding: 14px 14px 8px; }
  .program-bar { margin: 0 10px 8px; }
  .code-card { margin-left: 8px; }
  .diff-bar { padding: 8px 14px; }
  .diff-actions { margin-left: 0; width: 100%; }
  .diff-actions button { flex: 1; }
}

@media (display-mode: standalone) {
  .top, aside, .composer-row button, .jump-btns, .pills, .tabs {
    user-select: none;
    -webkit-user-select: none;
  }
  textarea, input, .msg, .msg *, .msg-body, .bubble, .plain, .reason-body, pre, code, .code-card {
    user-select: text;
    -webkit-user-select: text;
  }
}
