:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #faf8f5;
  --line: #e2ddd4;
  --text: #1f1d1a;
  --muted: #6f6a61;
  --accent: #0f6e5c;
  --accent-soft: #dcefe9;
  --danger: #b3372b;
  --warn: #9a6a00;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151614;
    --panel: #1d1f1c;
    --panel-2: #232622;
    --line: #33372f;
    --text: #ecebe6;
    --muted: #9c9a90;
    --accent: #4fc3a8;
    --accent-soft: #1f3a33;
    --danger: #ef7b6e;
    --warn: #e0b04a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary { color: #0c1a16; } }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }

/* entrada */
.gate { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.gate form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: grid; gap: 12px; }
.gate h1 { margin: 0; font-size: 22px; }
.error { color: var(--danger); min-height: 1.4em; font-size: 14px; }

/* estrutura */
.shell { display: grid; grid-template-columns: 200px 1fr; height: 100%; }
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 17px; padding: 4px 10px 12px; letter-spacing: .2px; }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--panel-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .spacer { flex: 1; }
.runner { font-size: 13px; padding: 8px 10px; display: flex; gap: 8px; align-items: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: #2fb37a; }
.dot.busy { background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.view { min-width: 0; min-height: 0; overflow: auto; }

/* início */
.home { max-width: 860px; margin: 0 auto; padding: 32px 20px; display: grid; gap: 22px; }
.home h1 { margin: 0; font-size: 26px; }
.composer { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 8px; }
.composer textarea { border: 0; resize: none; min-height: 70px; padding: 4px; background: transparent; }
.composer textarea:focus { outline: none; }
.composer .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.composer select { width: auto; max-width: 60%; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.card h2 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.list { display: grid; }
.item { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 8px; cursor: pointer; min-width: 0; }
.item:hover { background: var(--panel-2); }
.item .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.item .when { color: var(--muted); font-size: 12px; flex: none; }

/* mesa */
.desk { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.side { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 10px; }
.seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.side .tools { display: flex; gap: 6px; padding: 0 10px 8px; }
.side .tools input { flex: 1; min-width: 0; }
.side .scroll { overflow: auto; flex: 1; padding: 0 6px 12px; }
.tree-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-row:hover { background: var(--panel-2); }
.tree-row .ico { width: 16px; text-align: center; color: var(--muted); flex: none; }
.group { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 10px 8px 4px; }
.chat-row { padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.chat-row:hover { background: var(--panel-2); }
.chat-row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.panes { display: flex; min-width: 0; min-height: 0; position: relative; }
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.pane + .pane { border-left: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; background: var(--panel-2); border-bottom: 1px solid var(--line); padding: 6px 6px 0; overflow-x: auto; min-height: 39px; }
.tab { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; cursor: pointer; white-space: nowrap; max-width: 220px; }
.tab span.n { overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--panel); border-color: var(--line); }
.tab .x { border: 0; background: transparent; padding: 0 2px; color: var(--muted); }
.body { flex: 1; min-height: 0; background: var(--panel); display: flex; flex-direction: column; }
.empty { margin: auto; color: var(--muted); text-align: center; padding: 24px; }
.dropzone { position: absolute; top: 0; right: 0; bottom: 0; width: 34%; background: var(--accent-soft); border: 2px dashed var(--accent); display: none; place-items: center; color: var(--accent); font-weight: 600; z-index: 5; }
.dragging .dropzone { display: grid; }

/* arquivo */
.bar { display: flex; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bar .path { font-family: var(--mono); font-size: 13px; color: var(--muted); margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor { flex: 1; border: 0; border-radius: 0; resize: none; font: 13.5px/1.55 var(--mono); padding: 14px; background: var(--panel); min-height: 0; }
.editor:focus { outline: none; }
.preview { flex: 1; overflow: auto; padding: 18px 22px; min-height: 0; }
.preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview.frame { padding: 0; }
.preview img { max-width: 100%; }
.md h1, .md h2, .md h3 { line-height: 1.25; margin: 1em 0 .4em; }
.md pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; font: 13px/1.5 var(--mono); }
.md code { font-family: var(--mono); font-size: .92em; background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md a { color: var(--accent); }
.history { border-left: 1px solid var(--line); width: 320px; overflow: auto; flex: none; padding: 10px; }
.split { display: flex; flex: 1; min-height: 0; }
.ver { padding: 8px; border-radius: 8px; cursor: pointer; }
.ver:hover, .ver.on { background: var(--panel-2); }
.diff { font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 6px 0; }
.diff .add { background: rgba(47,179,122,.18); display: block; }
.diff .del { background: rgba(214,80,66,.18); display: block; }

/* conversa */
.msgs { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.msg { max-width: 780px; width: 100%; margin: 0 auto; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg.user .bubble { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; }
.msg.assistant .bubble { word-break: break-word; }
.status { max-width: 780px; width: 100%; margin: 0 auto; color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.send { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.send textarea { resize: none; max-height: 180px; min-height: 42px; }
.notice { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.token { font-family: var(--mono); word-break: break-all; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; user-select: all; }
.settings { max-width: 720px; margin: 0 auto; padding: 32px 20px; display: grid; gap: 16px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .nav { order: 2; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); overflow-x: auto; }
  .brand, .nav .spacer { display: none; }
  .desk { grid-template-columns: 1fr; }
  .desk.has-tab .side { display: none; }
  .desk:not(.has-tab) .panes { display: none; }
  .pane + .pane, .history { display: none; }
}
