/* HK Duet: dark, calm, gold accent. System fonts only. */
:root {
  --bg: #0d0d0f;
  --text: #f2efe9;
  --muted: #8d8a84;
  --gold: #d8b56a;
  --gold-soft: rgba(216, 181, 106, .14);
  --card: #17171b;
  --card2: #1e1e23;
  --line: rgba(255, 255, 255, .08);
  --green: #7fc58f;
  --red: #e07a6f;
  --r: 16px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--gold); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; display: block; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.col { width: 100%; max-width: 780px; margin: 0 auto; padding-left: calc(16px + var(--sal)); padding-right: calc(16px + var(--sar)); min-width: 0; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(24px + var(--sat)) 20px calc(24px + var(--sab)); overflow-y: auto; }
.login-card { width: 100%; max-width: 380px; text-align: center; margin: auto; }
.login .mark { border-radius: 18px; box-shadow: 0 0 0 1px var(--line), 0 10px 40px rgba(216, 181, 106, .12); }
.login h1 { margin: 18px 0 2px; font-size: 28px; font-weight: 650; letter-spacing: .2px; }
.login .sub { margin: 0 0 28px; color: var(--muted); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--card); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.seg button { padding: 12px 8px; border-radius: 11px; color: var(--muted); min-height: 44px; }
.seg button.on { background: var(--card2); color: var(--text); box-shadow: 0 0 0 1px var(--gold-soft) inset; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px; border-radius: 14px; font-weight: 600; }
.btn.primary { background: var(--gold); color: #1a1408; width: 100%; }
.btn.primary:active { filter: brightness(.92); }
.btn.ghost { color: var(--muted); }
.btn.line { background: var(--card2); box-shadow: 0 0 0 1px var(--line) inset; }
.btn.danger { color: var(--red); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.hint { color: var(--muted); font-size: 14px; margin: 22px 0 14px; }
.codes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.codes input { width: 100%; min-width: 0; height: 56px; text-align: center; font-size: 24px; font-weight: 600; background: var(--card); border: 1px solid var(--line); border-radius: 12px; caret-color: var(--gold); }
.codes input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.err { color: var(--red); min-height: 22px; font-size: 14px; margin: 10px 0 0; }

/* ---------- app shell ---------- */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.top { flex: none; padding-top: var(--sat); background: rgba(13, 13, 15, .92); border-bottom: 1px solid var(--line); z-index: 5; }
.top-in { display: flex; align-items: center; justify-content: space-between; max-width: 780px; margin: 0 auto; height: 56px; padding: 0 calc(10px + var(--sar)) 0 calc(16px + var(--sal)); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; }
.brand img { border-radius: 8px; }
.top-actions { display: flex; gap: 2px; }
.ibtn { position: relative; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; color: #cfcbc3; flex: none; }
.ibtn:hover { background: var(--card); }
.ibtn:active { background: var(--card2); }
.ibtn[aria-pressed="true"], .ibtn.on { color: var(--gold); background: var(--gold-soft); }
.badge { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--gold); color: #1a1408; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }

.apwrap { flex: none; position: relative; z-index: 4; }
.apbar { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 42px; background: var(--gold); color: #1a1408; font-weight: 600; font-size: 14px; padding: 0 16px; }
.appanel { max-height: 55vh; overflow-y: auto; background: var(--bg); border-bottom: 1px solid var(--line); padding: 12px calc(16px + var(--sar)) 12px calc(16px + var(--sal)); }
.appanel .approval { max-width: 780px; margin: 0 auto 10px; }

.thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; outline: none; }
.older { text-align: center; color: var(--muted); font-size: 13px; padding: 10px 0; }
.msgs { padding: 18px 0 24px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 18vh 0 0; }
.empty img { border-radius: 14px; opacity: .85; }
.jump { position: absolute; right: calc(18px + var(--sar)); bottom: calc(140px + var(--sab)); width: 44px; height: 44px; border-radius: 22px; background: var(--card2); box-shadow: 0 0 0 1px var(--line), 0 6px 20px rgba(0, 0, 0, .5); display: flex; align-items: center; justify-content: center; color: var(--gold); z-index: 3; }

/* ---------- messages ---------- */
.msg { min-width: 0; max-width: 100%; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { max-width: min(86%, 560px); background: var(--card2); border-radius: 18px 18px 6px 18px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.userfiles { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.userfiles span { font-size: 12px; color: var(--muted); background: var(--card); border-radius: 8px; padding: 2px 8px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.ai { min-width: 0; }
.ai-body { min-width: 0; overflow-wrap: anywhere; }
.ai-foot { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted); font-size: 12px; }
.ai-foot .ibtn { width: 36px; height: 36px; }
.ai-foot .ibtn svg.i { width: 18px; height: 18px; }
.ai-foot .ibtn.on { color: var(--gold); }
.errnote { color: var(--red); background: rgba(224, 122, 111, .08); border: 1px solid rgba(224, 122, 111, .25); border-radius: 12px; padding: 8px 12px; margin: 6px 0; font-size: 14px; }
.dots { display: inline-flex; gap: 5px; padding: 8px 2px; align-items: center; color: var(--muted); font-size: 13px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); opacity: .35; animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
.dots em { font-style: normal; margin-left: 6px; }
@keyframes dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* markdown */
.md { overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h2, .md h3, .md h4, .md h5 { margin: 16px 0 6px; line-height: 1.3; font-weight: 650; }
.md h2 { font-size: 20px; } .md h3 { font-size: 18px; } .md h4, .md h5 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li > ul, .md li > ol { margin: 3px 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--card2); border-radius: 6px; padding: 1px 6px; }
.md pre { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; overflow-x: auto; margin: 0 0 10px; max-width: 100%; }
.md pre code { background: none; padding: 0; font-size: 13px; white-space: pre; }
.md blockquote { margin: 0 0 10px; padding: 2px 0 2px 14px; border-left: 3px solid var(--gold-soft); color: #cfcbc3; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md .tablewrap { overflow-x: auto; max-width: 100%; margin: 0 0 10px; border: 1px solid var(--line); border-radius: 12px; }
.md table { border-collapse: collapse; min-width: 100%; font-size: 14px; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { color: var(--gold); font-weight: 600; background: var(--card); white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }

/* tool steps */
.steps { margin: 6px 0; }
.step { margin: 2px 0; }
.step-h { display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 2px 4px; border-radius: 8px; color: var(--muted); font-size: 13px; max-width: 100%; text-align: left; }
.step-h:hover { background: var(--card); }
.step-h .nm { font-family: var(--mono); color: #b8b3a8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.step-h svg.i { width: 15px; height: 15px; }
.step-h .ok { color: var(--green); } .step-h .bad { color: var(--red); }
.step-d { margin: 2px 0 6px 20px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-family: var(--mono); font-size: 12px; color: #b8b3a8; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow: auto; }
.step-d b { color: var(--gold); font-weight: 600; font-family: var(--font); }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--gold-soft); border-top-color: var(--gold); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* approval cards */
.approval { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin: 10px 0; min-width: 0; }
.approval.pending { border-color: rgba(216, 181, 106, .45); box-shadow: 0 0 0 3px var(--gold-soft); }
.ap-h { display: flex; align-items: center; gap: 10px; }
.ap-ic { width: 34px; height: 34px; border-radius: 10px; background: var(--gold-soft); color: var(--gold); display: flex; align-items: center; justify-content: center; flex: none; }
.ap-t { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.ap-job { font-size: 12px; color: var(--muted); }
.ap-kv { margin: 10px 0 0; padding: 10px 12px; background: var(--bg); border-radius: 10px; font-size: 13px; color: #cfcbc3; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 12px; }
.ap-kv .k { color: var(--muted); }
.ap-kv .v { overflow-wrap: anywhere; white-space: pre-wrap; max-height: 120px; overflow: auto; }
.ap-act { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.ap-act .btn { min-height: 50px; width: 100%; }
.ap-act .yes { background: var(--gold); color: #1a1408; }
.ap-act .no { background: var(--card2); color: var(--text); box-shadow: 0 0 0 1px var(--line) inset; }
.ap-done { margin-top: 10px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ap-done.y { color: var(--green); } .ap-done.n { color: var(--muted); }
.ap-done svg.i { width: 18px; height: 18px; }

/* event cards */
.evcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; min-width: 0; }
.ev-h { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.ev-ic { width: 32px; height: 32px; border-radius: 10px; background: var(--gold-soft); color: var(--gold); display: flex; align-items: center; justify-content: center; flex: none; }
.ev-ic svg.i { width: 18px; height: 18px; }
.evcard.failed .ev-ic { color: var(--red); background: rgba(224, 122, 111, .12); }
.evcard.done .ev-ic { color: var(--green); background: rgba(127, 197, 143, .12); }
.ev-k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.ev-t { font-weight: 600; overflow-wrap: anywhere; }
.ev-time { margin-left: auto; font-size: 12px; color: var(--muted); flex: none; }
.ev-job { color: var(--gold); font-size: 13px; margin-top: 8px; text-align: left; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; min-height: 40px; padding: 6px 12px; border-radius: 12px; background: var(--card2); box-shadow: 0 0 0 1px var(--line) inset; color: var(--text); text-decoration: none; font-size: 14px; }
.file svg.i { width: 18px; height: 18px; color: var(--gold); }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file small { color: var(--muted); font-size: 12px; flex: none; }
.chips { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; align-items: flex-start; }
.chip { display: inline-block; max-width: 100%; text-align: left; padding: 9px 14px; border-radius: 14px; background: var(--gold-soft); color: var(--gold); border: 1px solid rgba(216, 181, 106, .3); font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; }
.chip:active { background: rgba(216, 181, 106, .25); }
.chip::before { content: "\2192\00a0"; }

/* ---------- composer ---------- */
.composer { flex: none; padding: 8px 0 calc(10px + var(--sab)); background: linear-gradient(to top, var(--bg) 78%, rgba(13, 13, 15, 0)); }
.cbox { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 8px 8px 6px 14px; transition: border-color .15s, box-shadow .15s; }
.cbox:focus-within { border-color: rgba(216, 181, 106, .5); box-shadow: 0 0 0 3px var(--gold-soft); }
.cbox textarea { display: block; width: 100%; resize: none; border: 0; background: none; outline: none; font-size: 16px; line-height: 1.45; padding: 6px 4px 4px 0; max-height: 200px; min-height: 28px; caret-color: var(--gold); }
.cbox textarea::placeholder { color: var(--muted); }
.crow { display: flex; align-items: center; gap: 2px; margin-left: -6px; }
.crow .grow { flex: 1 1 auto; }
.pill { height: 34px; padding: 0 14px; margin-left: 4px; border-radius: 17px; background: var(--card2); color: #cfcbc3; font-size: 13px; font-weight: 600; box-shadow: 0 0 0 1px var(--line) inset; flex: none; }
.pill.fast { color: var(--gold); }
.send { width: 44px; height: 44px; border-radius: 22px; background: var(--gold); color: #1a1408; display: flex; align-items: center; justify-content: center; flex: none; margin-left: 4px; }
.send[disabled] { background: var(--card2); color: var(--muted); }
.send.stop { background: var(--card2); color: var(--gold); box-shadow: 0 0 0 1px rgba(216, 181, 106, .5) inset; }
.ibtn.rec { color: #fff; background: #c4493d; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.bgnote { font-size: 12px; color: var(--gold); padding: 2px 0 4px; }
.attached { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 6px; }
.att { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; background: var(--card2); border-radius: 10px; padding: 2px 4px 2px 10px; font-size: 13px; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.att button { width: 28px; height: 28px; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.att svg.i { width: 14px; height: 14px; }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20; }
.sheet { position: fixed; z-index: 21; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: var(--bg); border-left: 1px solid var(--line); display: flex; flex-direction: column; padding-top: var(--sat); box-shadow: -20px 0 60px rgba(0, 0, 0, .5); animation: slidein .22s ease-out; }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { flex: none; display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 calc(8px + var(--sar)) 0 8px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0 0 0 8px; font-size: 18px; font-weight: 650; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 16px calc(16px + var(--sar)) calc(24px + var(--sab)) 16px; -webkit-overflow-scrolling: touch; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1 1 auto; min-width: 0; }
.row .lbl { font-weight: 500; }
.row .sm { font-size: 13px; color: var(--muted); }
.group { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 16px; margin-bottom: 16px; }
.group h3 { margin: 12px 0 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; font-weight: 600; }
.group .btnrow { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 14px; }
.group .btnrow .btn { min-height: 44px; padding: 0 16px; font-size: 15px; }
.note { font-size: 13px; color: var(--gold); background: var(--gold-soft); border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.timeinput { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 40px; color-scheme: dark; }
select.timeinput { max-width: 100%; }
.times { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0 12px; align-items: center; }
.times .tm { display: inline-flex; align-items: center; gap: 2px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--card2); box-shadow: 0 0 0 1px var(--line) inset; transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #cfcbc3; transition: transform .15s, background .15s; }
.switch input:checked + span { background: var(--gold-soft); box-shadow: 0 0 0 1px rgba(216, 181, 106, .5) inset; }
.switch input:checked + span::after { transform: translateX(20px); background: var(--gold); }
.switch input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

/* jobs */
.job { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); margin-bottom: 8px; min-width: 0; }
.job:active { background: var(--card2); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.running, .dot.queued { background: var(--gold); animation: pulse 1.4s infinite; }
.dot.waiting { background: #e5a04a; animation: pulse 1.4s infinite; }
.dot.done { background: var(--green); }
.dot.failed { background: var(--red); }
.job .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .s { font-size: 12px; color: var(--muted); }
.job .grow { flex: 1 1 auto; min-width: 0; }
.formcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.formcard input, .formcard textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 16px; resize: vertical; min-height: 44px; }
.formcard input:focus, .formcard textarea:focus { outline: none; border-color: var(--gold); }
.jhead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.jsum { color: #cfcbc3; margin: 6px 0 12px; }
.sect { font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin: 18px 0 8px; }
.emptyl { color: var(--muted); text-align: center; padding: 30px 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(110px + var(--sab)); max-width: min(90vw, 420px); background: var(--card2); border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0, 0, 0, .6); padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 40; text-align: center; overflow-wrap: anywhere; }

@media (max-width: 700px) {
  .sheet { width: 100vw; border-left: 0; }
}
@media (min-width: 1000px) {
  .msgs { gap: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; transition: none !important; }
}
