:root {
  --bg: #f6f5f1; --panel: #ffffff; --ink: #1c2530; --muted: #6a7480; --line: #e2e0d8;
  --accent: #0f5c63; --accent-ink: #ffffff; --soft: #e6f0f0; --danger: #a8322a; --warn: #fff6e0; --warn-line: #e6c56a;
  --radius: 10px; --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181c; --panel: #1d2329; --ink: #e8ebee; --muted: #98a2ad; --line: #2e363e;
    --accent: #5fb8bf; --accent-ink: #0d1114; --soft: #1f3134; --danger: #e07b72; --warn: #33290f; --warn-line: #7a6320; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0; flex: 1; }
h2 { font-size: 15px; margin: 22px 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .error { color: var(--danger); min-height: 1.2em; margin: 4px 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 8px 14px; background: none; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost, a.ghost { border: 1px solid var(--line); background: var(--panel); text-decoration: none; color: inherit; padding: 7px 12px; border-radius: 8px; font-size: 14px; }
button.link { padding: 0; color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--line); }
input, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
label input, label textarea { margin-top: 4px; color: var(--ink); font-size: 15px; }

.screen { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; }
.card button.primary { width: 100%; margin-top: 8px; }
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; }
.brand small { display: block; color: var(--muted); font-size: 12px; }

#app { display: grid; grid-template-columns: 232px 1fr; height: 100%; }
aside { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav button { text-align: left; padding: 9px 12px; color: var(--ink); }
nav button:hover { background: var(--bg); }
nav button.active { background: var(--soft); color: var(--accent); font-weight: 600; }
.who { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; padding: 0 6px; }
main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.tab { flex: 1; overflow-y: auto; padding: 22px 28px; max-width: 980px; width: 100%; margin: 0 auto; }
.tab header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

#tab-chat { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 12px; }
#messages { flex: 1; overflow-y: auto; padding: 8px 2px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--soft); white-space: pre-wrap; }
.msg.chief { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.note { align-self: center; color: var(--muted); font-size: 13px; padding: 0; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; }
.msg ul, .msg ol { margin: 4px 0 8px; padding-left: 22px; }
.msg code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.msg table { border-collapse: collapse; margin: 6px 0; font-size: 14px; display: block; overflow-x: auto; }
.msg th, .msg td { border: 1px solid var(--line); padding: 4px 9px; text-align: left; }
.msg td.num { text-align: right; font-variant-numeric: tabular-nums; }
.msg a { color: var(--accent); }
.ran { font-size: 12px; color: var(--muted); margin-top: 6px; }
.confirm { align-self: stretch; background: var(--warn); border: 1px solid var(--warn-line); border-radius: var(--radius); padding: 12px 14px; }
.confirm b { display: block; margin-bottom: 6px; }
.confirm li { margin: 3px 0; }
.confirm .actions { margin-top: 10px; display: flex; gap: 8px; }
.typing { align-self: flex-start; color: var(--muted); font-size: 14px; }
.typing::after { content: "…"; animation: dots 1.2s steps(4, end) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0 } to { width: 1.2em } }
@media (prefers-reduced-motion: reduce) { .typing::after { animation: none; width: 1.2em; } }

#composer { border-top: 1px solid var(--line); padding-top: 10px; }
#composer .row { display: flex; gap: 8px; align-items: flex-end; }
#composer textarea { resize: none; max-height: 200px; }
.attach { width: 40px; height: 40px; margin: 0; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; font-size: 20px; color: var(--ink); flex: none; }
#chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { background: var(--soft); border-radius: 999px; padding: 3px 10px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { padding: 0 2px; color: var(--muted); }
#composer .small { margin: 6px 0 0; }

.list { display: grid; gap: 10px; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.item .top { display: flex; gap: 8px; align-items: center; }
.item .top b { flex: 1; }
.item .body { color: var(--muted); font-size: 14px; white-space: pre-wrap; margin-top: 6px; max-height: 7.5em; overflow: hidden; }
.item .body.open { max-height: none; }
.item .meta { font-size: 13px; margin-top: 6px; color: var(--muted); }
.empty { color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); padding: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px 14px; margin-top: 14px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; } .inline input { flex: 1; min-width: 180px; }
.urow { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.urow span { flex: 1; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(640px, 94vw); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h2 { margin-top: 0; }
.actions { display: flex; gap: 8px; align-items: center; } .spacer { flex: 1; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  aside { flex-direction: row; align-items: center; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; gap: 8px; }
  aside .brand { margin: 0; } aside .brand div { display: none; }
  nav { flex-direction: row; } nav button { white-space: nowrap; }
  .who span { display: none; }
  .tab { padding: 14px; } .msg { max-width: 96%; }
}
