:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #fbfbfa;
  --border: #eaeaea;
  --text: #2f3437;
  --strong: #111111;
  --muted: #787774;
  --accent: #111111;
  --accent-text: #ffffff;
  --red-bg: #fdebec; --red: #9f2f2d;
  --blue-bg: #e1f3fe; --blue: #1f6c9f;
  --green-bg: #edf3ec; --green: #346538;
  --yellow-bg: #fbf3db; --yellow: #956400;
  --code-bg: #f1f0ec;
  --sans: "SF Pro Display", "Geist Sans", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: "Geist Mono", "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --surface: #1b1b1b; --surface-2: #202020; --border: #2c2c2c;
    --text: #d9d8d4; --strong: #f3f2ee; --muted: #9a9893; --accent: #f3f2ee; --accent-text: #141414;
    --red-bg: #3a1f1f; --red: #f0a3a1; --blue-bg: #17303f; --blue: #8cc8ef;
    --green-bg: #1d2e1f; --green: #9fd0a3; --yellow-bg: #362c12; --yellow: #e8c46b; --code-bg: #262626;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141414; --surface: #1b1b1b; --surface-2: #202020; --border: #2c2c2c;
  --text: #d9d8d4; --strong: #f3f2ee; --muted: #9a9893; --accent: #f3f2ee; --accent-text: #141414;
  --red-bg: #3a1f1f; --red: #f0a3a1; --blue-bg: #17303f; --blue: #8cc8ef;
  --green-bg: #1d2e1f; --green: #9fd0a3; --yellow-bg: #362c12; --yellow: #e8c46b; --code-bg: #262626;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--strong); margin: 0; }
h1 { font: 500 30px/1.15 var(--serif); letter-spacing: -0.02em; }
h2 { font: 500 22px/1.2 var(--serif); letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 600; }
code, pre, kbd { font-family: var(--mono); font-size: 13px; }
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--code-bg); padding: 12px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
pre code { background: none; padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }

button, .btn {
  font: 500 14px/1 var(--sans); border-radius: 6px; padding: 10px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--strong);
  transition: transform .12s, background .15s, opacity .15s; min-height: 40px;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { opacity: .88; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--strong); background: var(--surface-2); }
button.danger { color: var(--red); }
button:disabled { opacity: .45; cursor: not-allowed; }
input, textarea, select {
  font: 15px/1.4 var(--sans); color: var(--strong); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

.tag {
  display: inline-block; border-radius: 9999px; padding: 2px 9px; font-size: 11px; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase; background: var(--code-bg); color: var(--muted); white-space: nowrap;
}
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.blue { background: var(--blue-bg); color: var(--blue); }
.tag.yellow { background: var(--yellow-bg); color: var(--yellow); }
.tag.red { background: var(--red-bg); color: var(--red); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.error { background: var(--red-bg); color: var(--red); border-radius: 6px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }
.notice { background: var(--yellow-bg); color: var(--yellow); border-radius: 6px; padding: 10px 12px; font-size: 14px; }
.ok { background: var(--green-bg); color: var(--green); border-radius: 6px; padding: 10px 12px; font-size: 14px; }

/* ---------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 400px; }
.login .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login .brand .mark { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font: 600 15px var(--serif); }
.login .actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.login .sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 18px 0 4px; }
.login .sep::before, .login .sep::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.qr { background: #fff; border-radius: 8px; padding: 8px; width: 220px; max-width: 100%; display: block; margin: 12px auto; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-family: var(--mono); font-size: 14px; background: var(--code-bg); padding: 14px; border-radius: 8px; margin: 12px 0; }
.linklike { background: none; border: none; color: var(--muted); padding: 4px 0; min-height: 0; font-size: 13px; text-decoration: underline; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--border); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; background: var(--surface-2); }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.side .brand .mark { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font: 600 13px var(--serif); }
.side .brand b { color: var(--strong); font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text); font-size: 14px; }
.nav a:hover { background: var(--surface); text-decoration: none; }
.nav a.active { background: var(--surface); color: var(--strong); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }
.nav a .count { margin-left: auto; font-size: 11px; color: var(--muted); }
.nav svg { width: 17px; height: 17px; flex: none; }
.side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: 1px; }
.dot.on { background: #3f9a4a; }
.dot.off { background: #c94a46; }
.main { padding: 32px 40px 80px; max-width: 1100px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.mobilebar { display: none; }

/* projects */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.proj h3 { font: 500 19px/1.25 var(--serif); color: var(--strong); }
.proj .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.proj .rel { font-size: 13px; color: var(--muted); margin: 8px 0 12px; }
.proj .sum { font-size: 14px; margin: 8px 0 0; }
.points { list-style: none; padding: 0; margin: 10px 0 0; }
.points li { display: flex; gap: 9px; align-items: flex-start; padding: 6px 0; border-top: 1px solid var(--border); font-size: 14px; }
.points li.done span { text-decoration: line-through; color: var(--muted); }
.points input[type=checkbox] { width: 16px; height: 16px; margin: 3px 0 0; flex: none; accent-color: var(--strong); }
.links { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 12px; font-size: 13px; }
.addpoint { display: flex; gap: 6px; margin-top: 10px; }
.addpoint input { padding: 7px 10px; font-size: 14px; }
.addpoint button { min-height: 34px; padding: 7px 10px; }

/* decisions */
.dec { display: flex; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.dec:first-child { padding-top: 0; }
.dec .body { flex: 1; min-width: 0; }
.dec .title { color: var(--strong); font-weight: 600; }
.dec.answered .title { color: var(--muted); text-decoration: line-through; }
.dec .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.dec textarea { margin-top: 8px; min-height: 60px; font-size: 14px; }
.toggle { position: relative; width: 40px; height: 24px; flex: none; margin-top: 2px; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle span { position: absolute; inset: 0; border-radius: 12px; background: var(--border); transition: background .15s; cursor: pointer; }
.toggle span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: var(--surface); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.toggle input:checked + span { background: #3f9a4a; }
.toggle input:checked + span::after { transform: translateX(16px); }

/* comms */
.comms { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 16px; align-items: start; }
.clist { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.clist .item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.clist .item:last-child { border-bottom: none; }
.clist .item:hover { background: var(--surface-2); }
.clist .item.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--strong); }
.clist .item .s { color: var(--strong); font-size: 14px; font-weight: 500; }
.clist .item .d { font-size: 12px; color: var(--muted); }
.viewer { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; position: sticky; top: 16px; }
.viewer .vh { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.viewer iframe { width: 100%; height: 70vh; border: 0; background: #fff; display: block; }
.search { max-width: 320px; }

/* chat */
.chat { display: grid; grid-template-columns: 260px 1fr; gap: 0; height: calc(100vh - 0px); }
.convs { border-right: 1px solid var(--border); padding: 20px 12px; overflow-y: auto; }
.convs .c { padding: 9px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text); }
.convs .c:hover { background: var(--surface); }
.convs .c.active { background: var(--surface); box-shadow: 0 0 0 1px var(--border); color: var(--strong); }
.convs .c .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convs .c .d { font-size: 11px; color: var(--muted); }
.thread { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.prod-banner { background: var(--red-bg); color: var(--red); padding: 9px 20px; font-size: 13px; display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--border); }
.prod-banner svg { width: 16px; height: 16px; flex: none; }
.msgs { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 820px; width: 100%; }
.msg.user { align-self: flex-end; max-width: 640px; width: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; white-space: pre-wrap; word-break: break-word; }
.msg.ai .md { word-break: break-word; }
.msg.ai .md p { margin: 0 0 10px; }
.msg.ai .md ul, .msg.ai .md ol { margin: 0 0 10px; padding-left: 22px; }
.msg.ai .md h1, .msg.ai .md h2, .msg.ai .md h3 { font: 600 16px/1.3 var(--sans); margin: 14px 0 6px; }
.msg.ai .md table { border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; margin-bottom: 10px; }
.msg.ai .md td, .msg.ai .md th { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.tools { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; }
.tool { font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 5px 9px; }
.tool summary { cursor: pointer; list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary b { color: var(--strong); font-weight: 600; }
.tool pre { margin: 6px 0 2px; font-size: 11.5px; max-height: 260px; overflow: auto; }
.tool.err b { color: var(--red); }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { border-top: 1px solid var(--border); padding: 14px 20px 18px; background: var(--bg); }
.composer form { display: flex; gap: 10px; align-items: flex-end; max-width: 860px; }
.composer textarea { resize: none; min-height: 46px; max-height: 220px; }
.composer .hint { font-size: 11px; color: var(--muted); margin-top: 6px; }
.empty { color: var(--muted); text-align: center; margin: auto; max-width: 420px; padding: 40px 16px; }

/* security */
.sec { display: grid; gap: 16px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.row:first-of-type { border-top: none; }
table.audit { width: 100%; border-collapse: collapse; font-size: 13px; }
table.audit td, table.audit th { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.audit th { color: var(--muted); font-weight: 500; font-size: 12px; }
.audit-wrap { overflow-x: auto; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; padding: 24px; width: 100%; max-width: 440px; border: 1px solid var(--border); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.fade { animation: fadein .45s cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .fade, .typing i { animation: none; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; max-width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; height: 100vh; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .mobilebar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; z-index: 30; }
  .mobilebar b { color: var(--strong); }
  .main { padding: 20px 16px 60px; }
  .comms { grid-template-columns: 1fr; }
  .viewer { position: static; }
  .viewer iframe { height: 60vh; }
  .chat { grid-template-columns: 1fr; height: auto; }
  .convs { border-right: none; border-bottom: 1px solid var(--border); padding: 12px 16px; max-height: 30vh; }
  .convs.collapsed .c:not(.active) { display: none; }
  .thread { height: calc(100vh - 53px); height: calc(100dvh - 53px); }
  .msgs { padding: 16px; }
  .composer { padding: 10px 12px 12px; }
  .prod-banner { padding: 8px 16px; }
  .grid { grid-template-columns: 1fr; }
  h1 { font-size: 26px; }
}
body.page-chat .main { padding: 0; max-width: none; }
body.page-chat .convs { padding-top: 24px; }
.footbtns { display: flex; gap: 6px; flex-wrap: wrap; }
.login .actions.tight { margin-top: 8px; }
.center { text-align: center; }
.breakall { word-break: break-all; }
