:root {
  --bg: #07081a;
  --bg2: #0c0e24;
  --panel: #11142e;
  --panel2: #171b3b;
  --line: #242a52;
  --line2: #323a6b;
  --text: #eef0fa;
  --muted: #a3abcc;
  --dim: #7c84a8;
  --gold: #ffd98a;
  --gold2: #f4b740;
  --cyan: #7feaff;
  --violet: #8d7dff;
  --ok: #5fd39a;
  --warn: #ffb35c;
  --bad: #ff7a7a;
  --on-primary: #1a1405;
  --primary-a: #ffe2a3;
  --primary-b: #f4b740;
  --danger-line: #5a2a36;
  --danger-text: #ffb3b3;
  --code-bg: #0a0c1f;
  --err-bg: #24121a;
  --err-text: #ffc4c4;
  --warn-line: #5a4a24;
  --warn-bg: #221c10;
  --warn-text: #ffe0a8;
  --ok-line: #24563d;
  --ok-bg: #0f2219;
  --ok-text: #bff0d6;
  --approval-bg: #1d1a10;
  --hover: #ffffff05;
  --chart-b: #3a6bd8;
  --shadow: #0008;
  --overlay: #0009;
  --glow: #3a4bc855;
  --radius: 14px;
  --font: "Segoe UI", "Inter", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "Cascadia Code", Consolas, "JetBrains Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }
a { color: var(--cyan); }
button { font-family: inherit; font-size: inherit; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line2); border-radius: 10px; padding: 9px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); }
textarea { resize: vertical; line-height: 1.5; }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.dim { color: var(--dim); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line2); background: var(--panel2);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; white-space: nowrap; min-height: 38px; }
.btn:hover { border-color: var(--cyan); }
.btn.primary { background: linear-gradient(180deg, var(--primary-a), var(--primary-b)); color: var(--on-primary); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { border-color: var(--danger-line); color: var(--danger-text); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel2); border-color: var(--line2); }
a.btn { text-decoration: none; color: var(--text); }
a.btn.primary { color: var(--on-primary); }
.btn.small { padding: 5px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }

/* layout */
#app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }
#sidebar { background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
.brand img { width: 38px; height: 38px; border-radius: 50%; }
.brand b { font-size: 17px; letter-spacing: .18em; }
.side-actions { padding: 6px 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.side-actions .btn { justify-content: center; }
.nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 2px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--muted); text-decoration: none; font-size: 14px; }
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--panel2); color: var(--text); }
.nav .badge { margin-left: auto; background: var(--gold2); color: var(--on-primary); border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.chatlist { flex: 1; overflow-y: auto; padding: 8px; }
.chatlist h6 { margin: 12px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 600; }
.chatitem { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 9px; cursor: pointer; color: var(--muted); font-size: 14px; }
.chatitem:hover { background: var(--panel); color: var(--text); }
.chatitem.active { background: var(--panel2); color: var(--text); }
.chatitem span.t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatitem .src { font-size: 10px; color: var(--dim); border: 1px solid var(--line2); padding: 0 5px; border-radius: 6px; }
.chatitem .x { opacity: 0; background: none; border: 0; cursor: pointer; color: var(--dim); padding: 2px; }
.chatitem:hover .x { opacity: 1; }
.side-foot { padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--dim); display: flex; justify-content: space-between; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); min-height: 58px; }
.topbar .title { font-weight: 600; font-size: 16px; background: transparent; border: 1px solid transparent; padding: 6px 8px; border-radius: 8px; min-width: 120px; max-width: 520px; }
.topbar .title:hover, .topbar .title:focus { border-color: var(--line2); }
.menu-btn { display: none; }

/* chat */
#messages { flex: 1; overflow-y: auto; padding: 22px 0 10px; scroll-behavior: auto; }
.thread { max-width: 860px; margin: 0 auto; padding: 0 22px; }
.msg { margin: 0 0 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--panel2); border: 1px solid var(--line); border-radius: 18px 18px 4px 18px; padding: 11px 15px;
  max-width: 82%; white-space: pre-wrap; word-wrap: break-word; line-height: 1.55; }
.msg.user .tools { display: flex; gap: 4px; justify-content: flex-end; margin-top: 4px; opacity: 0; }
.msg.user:hover .tools { opacity: 1; }
.msg.user .col { display: flex; flex-direction: column; align-items: flex-end; max-width: 82%; }
.msg.user .col .bubble { max-width: 100%; }
.att-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-bottom: 6px; }
.att-row img { max-width: 220px; max-height: 180px; border-radius: 10px; border: 1px solid var(--line); }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line2); border-radius: 9px; padding: 5px 9px; font-size: 13px; color: var(--muted); }
.msg.ai { display: grid; grid-template-columns: 32px 1fr; gap: 12px; }
.msg.ai .av { width: 32px; height: 32px; border-radius: 50%; margin-top: 2px; }
.msg.ai .body { min-width: 0; }
.md { line-height: 1.65; word-wrap: break-word; }
.md > *:first-child { margin-top: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3 { margin: 18px 0 8px; line-height: 1.3; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16.5px; }
.md ul, .md ol { padding-left: 24px; margin: 0 0 12px; }
.md li { margin: 3px 0; }
.md blockquote { border-left: 3px solid var(--line2); margin: 0 0 12px; padding: 2px 14px; color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 14px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--line2); padding: 7px 11px; text-align: left; vertical-align: top; }
.md th { background: var(--panel2); }
.md code { font-family: var(--mono); font-size: 13px; background: var(--panel2); padding: 1px 6px; border-radius: 6px; }
.md pre code { background: none; padding: 0; }
.md img { max-width: 100%; border-radius: 10px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.code-block { border: 1px solid var(--line2); border-radius: 12px; margin: 0 0 14px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px 12px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.code-head .lang { flex: 1; font-family: var(--mono); }
.code-head button { background: none; border: 1px solid transparent; color: var(--muted); cursor: pointer; border-radius: 7px; padding: 3px 8px; font-size: 12px; }
.code-head button:hover { border-color: var(--line2); color: var(--text); }
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.5; }
.code-block pre code.hljs { background: transparent; padding: 0; }
.svg-preview, .mermaid-box { padding: 14px; background: #fff0; display: flex; justify-content: center; }
.svg-preview svg { max-width: 100%; height: auto; max-height: 420px; }
.mermaid-box svg { max-width: 100%; }
.thinking { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 10px; background: var(--bg2); }
.thinking summary { cursor: pointer; padding: 7px 12px; color: var(--muted); font-size: 13px; }
.thinking .tx { padding: 0 12px 10px; color: var(--dim); font-size: 13px; white-space: pre-wrap; max-height: 300px; overflow-y: auto; }
.meta { display: flex; gap: 10px; align-items: center; color: var(--dim); font-size: 12px; margin-top: 6px; flex-wrap: wrap; }
.meta button { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 3px; border-radius: 6px; display: inline-flex; }
.meta button:hover { color: var(--text); background: var(--panel); }
.cursor::after { content: "▍"; color: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cites { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.cites a { font-size: 12px; text-decoration: none; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 3px 8px; color: var(--cyan); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err { border: 1px solid var(--danger-line); background: var(--err-bg); color: var(--err-text); border-radius: 10px; padding: 10px 12px; margin: 6px 0; font-size: 14px; }
.warnbox { border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 8px 12px; margin: 6px 0; font-size: 13px; }

/* tool steps */
.step { border: 1px solid var(--line); background: var(--bg2); border-radius: 12px; margin: 8px 0; overflow: hidden; }
.step-head { display: flex; align-items: center; gap: 9px; padding: 8px 12px; cursor: pointer; font-size: 14px; color: var(--muted); }
.step-head .st { margin-left: auto; font-size: 12px; }
.step-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.step.running .dot { background: var(--gold); animation: pulse 1s infinite; }
.step.done .dot { background: var(--ok); }
.step.denied .dot, .step.error .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }
.step-body { padding: 0 12px 12px; display: none; }
.step.open .step-body { display: block; }
.step-body pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px; font-size: 12px; overflow-x: auto; max-height: 300px; white-space: pre-wrap; margin: 6px 0 0; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.filecard { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line2); background: var(--panel); border-radius: 12px; padding: 9px 12px; min-width: 240px; max-width: 360px; }
.filecard .ext { width: 38px; height: 38px; border-radius: 9px; background: var(--panel2); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--gold); flex: 0 0 auto; }
.filecard .nm { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filecard a { font-size: 12px; }
.imgs { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.imgs img { max-width: 420px; max-height: 420px; border-radius: 12px; border: 1px solid var(--line); cursor: zoom-in; }
.approval { border: 1px solid var(--gold2); background: var(--approval-bg); border-radius: 12px; padding: 12px 14px; margin: 8px 0; }
.approval h4 { margin: 0 0 8px; font-size: 14px; color: var(--gold); }
.kv { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 10px; }
.kv td { border-bottom: 1px solid var(--line); padding: 5px 6px; vertical-align: top; }
.kv td:first-child { color: var(--muted); width: 34%; white-space: nowrap; }
.kv pre { margin: 0; white-space: pre-wrap; font-family: var(--mono); font-size: 12px; }

/* composer */
.composer-wrap { padding: 8px 22px 16px; }
.composer { max-width: 860px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line2); border-radius: 18px; padding: 10px 12px 8px; }
.composer.drag { border-color: var(--gold); }
.composer textarea { width: 100%; border: 0; background: transparent; resize: none; max-height: 260px; min-height: 26px; padding: 4px 4px; font-size: 15px; }
.composer .pending { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.composer .pending .chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }
.composer .bar { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); border-radius: 20px; padding: 4px 10px; font-size: 13px; color: var(--muted); cursor: pointer; background: transparent; }
.toggle.on { border-color: var(--cyan); color: var(--cyan); }
.toggle select { background: transparent; border: 0; padding: 0; color: inherit; font-size: 13px; }
.sendbtn { margin-left: auto; width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: linear-gradient(180deg, var(--primary-a), var(--primary-b)); color: var(--on-primary); }
.sendbtn:disabled { opacity: .4; cursor: default; }
.sendbtn.stop { background: var(--panel2); color: var(--text); border: 1px solid var(--line2); }
.hint { text-align: center; color: var(--dim); font-size: 12px; margin-top: 6px; }
.modelbtn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); background: var(--panel); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-size: 13px; color: var(--muted); max-width: 300px; }
.modelbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* welcome */
.welcome { max-width: 760px; margin: 40px auto 0; padding: 0 22px; text-align: center; }
.welcome img { width: 120px; height: 120px; border-radius: 50%; box-shadow: 0 0 60px var(--glow); }
.welcome h1 { letter-spacing: .2em; margin: 18px 0 6px; font-weight: 700; }
.welcome .cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 26px; text-align: left; }
.welcome .card { border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 13px 15px; cursor: pointer; font-size: 14px; color: var(--muted); }
.welcome .card:hover { border-color: var(--cyan); color: var(--text); }
.welcome .card b { display: block; color: var(--text); margin-bottom: 3px; }
.setup { border: 1px solid var(--gold2); background: var(--approval-bg); border-radius: 14px; padding: 16px 18px; text-align: left; margin-top: 22px; }
.setup ol { margin: 8px 0 12px; padding-left: 20px; line-height: 1.7; }

/* pages */
.page { flex: 1; overflow-y: auto; padding: 22px 28px 60px; }
.page-inner { max-width: 1100px; margin: 0 auto; }
.page h2 { margin: 0 0 4px; font-size: 22px; }
.page .sub { color: var(--muted); margin: 0 0 20px; }
.panel { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.field { margin-bottom: 12px; }
.field input, .field select, .field textarea { width: 100%; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 13px; cursor: pointer; color: var(--muted); font-size: 14px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--gold); }
.tabs .badge { background: var(--gold2); color: var(--on-primary); border-radius: 10px; font-size: 11px; padding: 1px 6px; margin-left: 4px; font-weight: 700; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:hover td { background: var(--hover); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--gold); font-weight: 600; }
.zero { color: var(--ok); }
.neg { color: var(--cyan); }
.table-wrap { overflow-x: auto; }
.body > .table-wrap { margin: 6px 0 12px; }
.stat { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
.bar-bg { height: 8px; background: var(--bg2); border-radius: 6px; overflow: hidden; margin-top: 8px; }
.bar-fg { height: 100%; background: linear-gradient(90deg, var(--cyan), var(--violet)); }
.bar-fg.hot { background: linear-gradient(90deg, var(--gold2), var(--bad)); }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 10px; }
.chart div { flex: 1; background: linear-gradient(180deg, var(--cyan), var(--chart-b)); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.chart div:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); padding: 3px 7px; border-radius: 6px; font-size: 11px; white-space: nowrap; }
.pcard { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; }
.pcard:hover { border-color: var(--cyan); }
.pcard h4 { margin: 0 0 6px; }
.memtabs button { font-family: var(--mono); font-size: 13px; }
.report-card { border: 1px solid var(--line2); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--bg2); }
.tag { font-size: 11px; border: 1px solid var(--line2); border-radius: 6px; padding: 1px 6px; color: var(--muted); }
.tag.ok { color: var(--ok); border-color: var(--ok-line); }
.tag.bad { color: var(--bad); border-color: var(--danger-line); }
.tag.gold { color: var(--gold); border-color: var(--warn-line); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 16px; width: min(760px, 100%); max-height: 88vh; display: flex; flex-direction: column; }
.modal header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal header .x { margin-left: auto; }
.modal .mbody { padding: 16px 18px; overflow-y: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modellist { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.modelitem { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.modelitem:hover { background: var(--panel2); border-color: var(--line2); }
.modelitem.sel { border-color: var(--gold2); }
.modelitem .id { font-family: var(--mono); font-size: 12px; color: var(--dim); }
.modelitem .pr { margin-left: auto; text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; box-shadow: 0 10px 30px var(--shadow); }
.lightbox { position: fixed; inset: 0; background: #000d; z-index: 70; display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 10px; }
iframe.preview { width: 100%; height: 420px; border: 0; background: #fff; border-radius: 0 0 12px 12px; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; z-index: 40; width: 280px; height: 100vh; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .grid2, .grid3, .grid4, .welcome .cards { grid-template-columns: 1fr; }
  .thread { padding: 0 12px; }
  .composer-wrap { padding: 8px 10px 12px; }
  .msg.user .bubble, .msg.user .col { max-width: 92%; }
  .page { padding: 16px 14px 60px; }
}

/* v2 */
.composer { position: relative; }
.sc-menu { position: absolute; left: 10px; right: 10px; bottom: 100%; margin-bottom: 6px; background: var(--panel2); border: 1px solid var(--line2); border-radius: 12px; padding: 6px; z-index: 20; max-height: 260px; overflow-y: auto; box-shadow: 0 10px 30px var(--shadow); }
.sc-item { display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.sc-item:hover, .sc-item.sel { background: var(--panel); }
.sc-item b { color: var(--gold); font-family: var(--mono); font-size: 13px; }
.vid { max-width: 100%; max-height: 420px; border-radius: 12px; border: 1px solid var(--line); margin: 8px 0; background: #000; display: block; }
.sub { border-top: 1px solid var(--line); padding: 10px 0 4px; }
.on-voice { color: var(--cyan) !important; border-color: var(--cyan) !important; }
#micBtn.rec { color: var(--bad); border-color: var(--bad); animation: pulse 1s infinite; }
.task-card { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.task-card .row { align-items: flex-start; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text); }
.daypick { display: flex; gap: 4px; flex-wrap: wrap; }
.daypick label { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line2); border-radius: 8px; padding: 4px 8px; margin: 0; color: var(--text); cursor: pointer; }
.mono { font-family: var(--mono); font-size: 13px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

@media (max-width: 640px) {
  .composer .bar { flex-wrap: wrap; row-gap: 6px; }
  .toggle span { display: none; }
  .toggle select { max-width: 70px; }
  .hint { display: none; }
}


/* ---------------------------------------------------------------- v3: themes */
/* Tema Exitoso: claro, limpio y profesional (verde esmeralda + dorado) */
:root[data-theme="exitoso"] {
  --bg: #ffffff; --bg2: #f5f7f6; --panel: #ffffff; --panel2: #eef3f1; --line: #e1e7e4; --line2: #cfd8d4;
  --text: #13201b; --muted: #4c5c55; --dim: #6f7d77;
  --gold: #a46a0c; --gold2: #d9a033; --cyan: #0b7d57; --violet: #3c6fd1; --ok: #138a52; --warn: #b9690b; --bad: #c43a3a;
  --on-primary: #ffffff; --primary-a: #17a56f; --primary-b: #0b7d57;
  --danger-line: #f0c3c3; --danger-text: #b42f2f; --code-bg: #f6f8f7; --err-bg: #fdf0f0; --err-text: #9e2a2a;
  --warn-line: #ecd6a6; --warn-bg: #fdf7ea; --warn-text: #7a5208; --ok-line: #b9e2cc; --ok-bg: #eefaf3; --ok-text: #0f6b40;
  --approval-bg: #fdf8ec; --hover: #0b7d570a; --chart-b: #7fd3b0; --shadow: #13201b22; --overlay: #13201b55; --glow: #0b7d5733;
}
:root[data-theme="exitoso"] .msg.user .bubble { background: #e9f5ef; border-color: #d3e9dd; }
:root[data-theme="exitoso"] #sidebar { background: #f5f7f6; }
:root[data-theme="exitoso"] .composer { box-shadow: 0 4px 18px #13201b10; }
/* Alto contraste: negro, blanco y amarillo */
:root[data-theme="contraste"] {
  --bg: #000000; --bg2: #000000; --panel: #0b0b0b; --panel2: #1a1a1a; --line: #8a8a8a; --line2: #ffffff;
  --text: #ffffff; --muted: #f0f0f0; --dim: #d6d6d6;
  --gold: #ffe500; --gold2: #ffe500; --cyan: #66e0ff; --violet: #c9b8ff; --ok: #4dff9a; --warn: #ffb000; --bad: #ff6b6b;
  --on-primary: #000000; --primary-a: #ffe500; --primary-b: #ffe500;
  --danger-line: #ff6b6b; --danger-text: #ff9b9b; --code-bg: #000000; --err-bg: #2a0000; --err-text: #ffd0d0;
  --warn-line: #ffe500; --warn-bg: #1a1600; --warn-text: #fff3a0; --ok-line: #4dff9a; --ok-bg: #002a12; --ok-text: #c8ffdc;
  --approval-bg: #1a1600; --hover: #ffffff14; --chart-b: #ffe500; --shadow: #000; --overlay: #000c; --glow: #ffe50044;
}
:root[data-theme="contraste"] .md a, :root[data-theme="contraste"] .page p a, :root[data-theme="contraste"] .dim a { text-decoration: underline; }
:root[data-theme="contraste"] .btn:focus-visible, :root[data-theme="contraste"] a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------------------------------------------------------------- v3: account chip & member UI */
.side-user { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.side-user .av2 { width: 32px; height: 32px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line2); display: grid; place-items: center; font-weight: 700; color: var(--gold); flex: 0 0 auto; }
.side-user .who { flex: 1; min-width: 0; line-height: 1.2; }
.side-user .who b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who span { font-size: 11px; color: var(--dim); }
.rank { display: inline-block; font-size: 11px; border-radius: 6px; padding: 1px 7px; border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; }
.rank.owner { color: var(--gold); border-color: var(--gold2); }
.rank.admin_principal { color: var(--cyan); border-color: var(--cyan); }
.rank.admin_secundario { color: var(--violet); border-color: var(--violet); }
.rank.arbitro, .rank.club { color: var(--ok); border-color: var(--ok-line); }
.readonly-bar { max-width: 860px; margin: 0 auto; text-align: center; color: var(--muted); border: 1px dashed var(--line2); border-radius: 14px; padding: 12px; }
.flag { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; padding: 6px 10px; border-radius: 9px; margin: 4px 0; }
.flag.alto { background: var(--err-bg); color: var(--err-text); border: 1px solid var(--danger-line); }
.flag.medio { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-line); }
.okbox { border: 1px solid var(--ok-line); background: var(--ok-bg); color: var(--ok-text); border-radius: 10px; padding: 10px 12px; margin: 6px 0; font-size: 14px; }
.big-num { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.theme-pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.theme-pick button { border: 2px solid var(--line2); border-radius: 12px; padding: 0; overflow: hidden; cursor: pointer; background: none; text-align: left; }
.theme-pick button.on { border-color: var(--gold2); }
.theme-pick .sw { height: 54px; display: flex; }
.theme-pick .sw i { flex: 1; }
.theme-pick .nm { padding: 7px 10px; font-size: 13px; color: var(--text); background: var(--panel); }
.qr { background: #fff; padding: 10px; border-radius: 12px; width: 180px; height: 180px; }
.linkbox { display: flex; gap: 8px; align-items: center; }
.linkbox input { flex: 1; font-family: var(--mono); font-size: 13px; }

/* ---------------------------------------------------------------- v3: planillas (form builder + renderer) */
.fb { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.fb-field { border: 1px solid var(--line); background: var(--bg2); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.fb-field.sec { border-style: dashed; }
.fb-field .row { gap: 8px; }
.fb-field .tp { font-size: 11px; color: var(--dim); font-family: var(--mono); }
.fb-field .mini { padding: 5px 8px; font-size: 13px; }
.fb-add { display: flex; flex-wrap: wrap; gap: 6px; }
.fb-add button { font-size: 12px; }
.fb-preview { position: sticky; top: 0; }
.zf { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.zf .f { grid-column: span 2; }
.zf .f.half { grid-column: span 1; }
.zf .f label { color: var(--muted); font-size: 13px; margin-bottom: 5px; }
.zf .f label .req { color: var(--bad); }
.zf .f input, .zf .f select, .zf .f textarea { width: 100%; }
.zf .f .help { font-size: 12px; color: var(--dim); margin-top: 4px; }
.zf .sec-h { grid-column: span 2; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-weight: 700; font-size: 15px; }
.zf .money { display: flex; gap: 6px; }
.zf .money input { flex: 1; }
.zf .money select { width: 96px; flex: 0 0 auto; }
.zf .score { display: flex; gap: 6px; align-items: center; }
.zf .score input { width: 80px; text-align: center; }
.zf .checks { display: flex; flex-wrap: wrap; gap: 6px; }
.zf .checks label { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line2); border-radius: 9px; padding: 6px 10px; color: var(--text); margin: 0; cursor: pointer; }
.zf .photo-prev { max-width: 160px; max-height: 120px; border-radius: 8px; margin-top: 6px; display: block; }
.zf canvas.sig { width: 100%; height: 140px; background: #fff; border-radius: 10px; border: 1px solid var(--line2); touch-action: none; }
.zf .f.bad input, .zf .f.bad select, .zf .f.bad textarea { border-color: var(--bad); }
@media (max-width: 900px) {
  .fb { grid-template-columns: 1fr; }
  .fb-preview { position: static; }
  .theme-pick { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .zf .f.half { grid-column: span 2; }
}


/* ---------------------------------------------------------------- v4: canvas, diff, dashboard */
#canvas { position: fixed; top: 0; right: 0; bottom: 0; width: min(52vw, 900px); background: var(--bg2); border-left: 1px solid var(--line2); z-index: 40; display: flex; flex-direction: column; box-shadow: -12px 0 40px var(--shadow); }
#canvas header { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
#canvas header input.title { flex: 1; min-width: 0; font-weight: 700; background: none; border: 1px solid transparent; padding: 6px 8px; }
#canvas header input.title:focus { border-color: var(--line2); }
#canvas .cv-tabs { display: flex; gap: 4px; padding: 8px 12px 0; }
#canvas .cv-tabs button { background: none; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 8px 8px 0 0; cursor: pointer; font-size: 13px; }
#canvas .cv-tabs button.on { background: var(--panel); color: var(--text); }
#canvas .cv-body { flex: 1; min-height: 0; background: var(--panel); margin: 0 12px; border-radius: 0 10px 10px 10px; overflow: auto; }
#canvas .cv-body iframe { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 10px; }
#canvas .cv-body .md { padding: 18px 22px; }
#canvas .cv-body textarea { width: 100%; height: 100%; border: 0; background: var(--code-bg); color: var(--text); font-family: var(--mono); font-size: 13px; padding: 14px; resize: none; border-radius: 10px; }
#canvas footer { padding: 10px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#canvas footer .linkbox { flex: 1 1 100%; }
pre.diff { background: var(--code-bg); border-radius: 8px; padding: 10px; font-size: 12px; overflow: auto; max-height: 340px; line-height: 1.45; }
pre.diff .add { color: var(--ok); background: var(--ok-bg); display: inline-block; width: 100%; }
pre.diff .del { color: var(--bad); background: var(--err-bg); display: inline-block; width: 100%; }
pre.diff .hunk { color: var(--cyan); }
.tchart { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding-top: 8px; }
.tchart .tgrp { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.tchart .tbars { display: flex; align-items: flex-end; gap: 3px; height: 100%; width: 100%; justify-content: center; }
.tchart .tbars i { width: 38%; max-width: 26px; border-radius: 5px 5px 0 0; min-height: 2px; display: block; }
.tchart .lbl { font-size: 11px; color: var(--dim); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; padding: 4px 0; }
.hbar .tr { height: 8px; border-radius: 5px; background: var(--panel2); overflow: hidden; }
.hbar .tr i { display: block; height: 100%; background: var(--gold2); border-radius: 5px; }
@media (max-width: 900px) { #canvas { width: 100vw; } }

/* ---- v4.1 tesorero */
.chk { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: 13px; }
.chk li { display: flex; gap: 8px; align-items: baseline; color: var(--muted); }
.chk li i { font-style: normal; font-weight: 800; width: 14px; text-align: center; flex: none; }
.chk li.ok i { color: var(--ok); } .chk li.aviso i { color: var(--gold); } .chk li.grave i { color: var(--bad); }
.chk li.grave { color: var(--text); }
.stat .v.ok, td.ok { color: var(--ok); } .stat .v.warn { color: var(--gold); } .stat .v.bad, td.bad { color: var(--bad); }
.au-card .row > .grow { min-width: 0; }


/* ---------------------------------------------------------------- v4.4: ZENITH en el celular */
#sideScrim, #mobNav, .more-link, #swipeFlash, .modal .grab { display: none; }
@media (max-width: 760px) {
  #app { height: 100vh; height: 100dvh; }
  #sidebar { width: min(86vw, 320px); height: 100vh; height: 100dvh; box-shadow: 12px 0 40px var(--shadow); }
  #sideScrim { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 39; opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.side-open #sideScrim { opacity: 1; pointer-events: auto; }
  .nav a { min-height: 46px; font-size: 15px; }
  .menu-btn { min-width: 44px; min-height: 44px; justify-content: center; }

  /* barra de abajo */
  #mobNav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; background: var(--bg2); border-top: 1px solid var(--line2);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px var(--shadow); }
  #mobNav a, #mobNav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 56px; padding: 4px 2px;
    color: var(--muted); font: inherit; font-size: 11.5px; font-weight: 600; background: none; border: 0; border-radius: 12px; text-decoration: none; position: relative; cursor: pointer; }
  #mobNav a.on { color: var(--gold); background: var(--panel); }
  #mobNav svg { width: 24px; height: 24px; }
  #mobNav span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #mobNav .dot { position: absolute; top: 7px; left: calc(50% + 8px); width: 10px; height: 10px; border-radius: 50%; background: var(--bad); border: 2px solid var(--bg2); }
  #mobNav .dot.hidden { display: none; }
  #main { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  body.kb #mobNav, body.side-open #mobNav { display: none; }
  body.kb #main { padding-bottom: 0; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); text-align: center; }

  /* arriba: el título y los botones se acomodan en dos filas si no caben */
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 8px 12px; min-height: 56px; }
  .topbar > b.grow { flex: 1 1 120px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
  .topbar > .btn:not(.menu-btn) { flex: 1 1 auto; justify-content: center; }

  /* toques cómodos y sin zoom raro del iPhone al escribir */
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; padding: 8px 12px; font-size: 14px; }
  .btn.ghost.small.x, .modal header .x { min-width: 44px; min-height: 44px; justify-content: center; }
  input, select, textarea { font-size: 16px; }
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select { min-height: 44px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }

  /* página */
  .page { padding: 14px 12px 28px; }
  .page h2 { font-size: 21px; }
  .page .sub { margin-bottom: 12px; }
  .page .sub.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 2px; }
  .more-link { display: inline-block; background: none; border: 0; color: var(--cyan); font: inherit; font-size: 14px; font-weight: 600; padding: 6px 0 12px; cursor: pointer; }
  .panel { padding: 14px 12px; border-radius: 14px; }

  /* pestañas: una sola fila que se desliza con el dedo */
  .tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: none; gap: 2px; margin-left: -12px; margin-right: -12px; padding: 0 12px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; white-space: nowrap; min-height: 46px; padding: 10px 14px; font-size: 15px; scroll-snap-align: center; }
  .tabs.fade-r { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); }
  .tabs.fade-l { -webkit-mask-image: linear-gradient(to right, transparent, #000 36px); mask-image: linear-gradient(to right, transparent, #000 36px); }
  .tabs.fade-l.fade-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
  #swipeFlash { display: block; position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2); color: var(--text);
    padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; z-index: 45; opacity: 0; pointer-events: none; box-shadow: 0 8px 24px var(--shadow); }
  #swipeFlash.go { animation: swflash 1.1s ease forwards; }
  @keyframes swflash { 0% { opacity: 0; transform: translate(-50%, 6px); } 15% { opacity: 1; transform: translate(-50%, 0); } 75% { opacity: 1; } 100% { opacity: 0; } }

  /* filtros: Desde y Hasta lado a lado, botones abajo */
  .page .panel > .row:has(input[type=date]) { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
  .page .panel > .row:has(input[type=date]) > div { min-width: 0; }
  .page .panel > .row:has(input[type=date]) > div:has(> select), .page .panel > .row:has(input[type=date]) > div:has(> input:not([type=date])) { grid-column: 1 / -1; }
  .page .panel > .row:has(input[type=date]) > .grow { display: none; }
  .page .panel > .row:has(input[type=date]) > .row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; }
  .page .panel > .row:has(input[type=date]) > .row > .btn { flex: 1 1 auto; justify-content: center; }
  .page .panel > .row:has(input[type=date]) input, .page .panel > .row:has(input[type=date]) select { width: 100%; }

  /* tablas: cada fila es una tarjeta, con el nombre de cada dato a la izquierda (no se pierde ninguna columna) */
  .table-wrap { overflow: visible; }
  table.data.cards, table.data.cards tbody, table.data.cards tr, table.data.cards td { display: block; width: 100%; }
  table.data.cards thead { display: none; }
  table.data.cards tr { border: 1px solid var(--line2); border-radius: 14px; padding: 6px 12px; margin-bottom: 10px; background: var(--panel); }
  table.data.cards tr:hover td { background: none; }
  table.data.cards td { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); text-align: right; white-space: normal; }
  table.data.cards td:last-child { border-bottom: 0; }
  table.data.cards td::before { content: attr(data-label); flex: 0 0 auto; max-width: 42%; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; text-align: left; padding-top: 2px; }
  table.data.cards td[data-label=""]::before, table.data.cards td.full::before { content: none; }
  table.data.cards td[data-label=""] { justify-content: flex-end; }
  table.data.cards td.full { display: block; text-align: left; }
  table.data.cards td > .cv { min-width: 0; overflow-wrap: anywhere; }
  table.data.cards td > .cv .row { justify-content: flex-end; }
  table.data.cards td input, table.data.cards td select { max-width: 60vw; }
  table.data.cards tfoot { display: block; }

  /* ventanas: suben desde abajo, a lo ancho, y se cierran tocando la X o jalándolas hacia abajo */
  .modal-bg { place-items: end stretch; padding: 0; }
  .modal { width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 20px 20px 0 0; border-bottom: 0; transition: transform .2s; }
  .modal .grab { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line2); margin: 8px auto 0; flex: none; }
  .modal header { padding: 8px 14px 12px; font-size: 17px; touch-action: none; }
  .modal .mbody { padding: 14px; }
  .modal footer { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .modal footer .btn { flex: 1 1 40%; justify-content: center; min-height: 48px; font-size: 16px; }
}
