:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #14212b; --muted: #5b6b78; --line: #e2e8ee;
  --brand: #0e7c86; --brand-ink: #ffffff; --brand-soft: #e3f4f5; --accent: #f2a541;
  --ok: #1f8a4c; --ok-soft: #e4f5ea; --warn: #b26a00; --warn-soft: #fff3df; --bad: #c0392b; --bad-soft: #fde8e6;
  --chip: #eef2f5; --shadow: 0 1px 2px rgba(16,32,48,.06), 0 4px 14px rgba(16,32,48,.06);
  --radius: 14px; --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f171d; --card: #17222a; --ink: #e6edf2; --muted: #93a4b1; --line: #26343f;
    --brand: #27a6b0; --brand-soft: #123238; --chip: #22303a; --ok-soft: #133524; --warn-soft: #3a2a10; --bad-soft: #3b1a17;
    --shadow: 0 1px 2px rgba(0,0,0,.3); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
body { min-height: 100vh; -webkit-text-size-adjust: 100%; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar .in { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: .2px; color: var(--ink); text-decoration: none; }
.logo img { width: 30px; height: 30px; border-radius: 8px; }
.logo small { font-weight: 600; font-size: 12px; color: var(--muted); margin-left: 2px; }
main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 90px; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--ink); min-height: 40px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.iconbtn { border: none; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.iconbtn:hover { background: var(--chip); color: var(--ink); }
label.f { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 42px; }
.input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea.input { min-height: 90px; resize: vertical; }
.seg { display: inline-flex; background: var(--chip); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { border: none; background: transparent; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 720px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.pad0 { padding: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 860px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { padding: 14px 16px; cursor: pointer; }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat.on { outline: 2px solid var(--brand); }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; background: var(--chip); font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.chip.brand { background: var(--brand-soft); color: var(--brand); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.badge { display: inline-flex; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: 12px; font-weight: 700; align-items: center; justify-content: center; }

/* case list */
.caselist { display: grid; gap: 10px; }
.caseitem { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; padding: 14px 16px; cursor: pointer; text-decoration: none; color: inherit; }
.caseitem:hover { border-color: var(--brand); }
.caseitem .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.progress { height: 6px; background: var(--chip); border-radius: 6px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty img { width: 64px; opacity: .9; margin-bottom: 8px; }

/* case page */
.casehead { margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 14px 0 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: none; background: none; padding: 10px 14px; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.section { margin-bottom: 18px; }
.section > .head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.item { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: start; }
.item:last-child { border-bottom: none; }
.item.drag { background: var(--brand-soft); }
.tick { width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; border: 2px solid var(--line); color: transparent; margin-top: 1px; }
.tick.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.files { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.file { display: flex; align-items: center; gap: 6px; font-size: 13px; background: var(--chip); border-radius: 8px; padding: 4px 6px 4px 10px; max-width: 520px; }
.file a { text-decoration: none; font-weight: 600; }
.addr { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.addr select { min-height: 34px; padding: 4px 8px; width: auto; max-width: 100%; }

/* chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 290px); min-height: 380px; }
.chat .msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); border-radius: var(--radius) var(--radius) 0 0; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); }
.msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; }
.msg .t { font-size: 11px; opacity: .75; margin-top: 3px; text-align: right; }
.msg a.doc { display: inline-block; margin-top: 6px; padding: 6px 10px; border-radius: 8px; background: rgba(0,0,0,.07); font-weight: 700; text-decoration: none; color: inherit; }
.msg.me a.doc { background: rgba(255,255,255,.18); }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: var(--card); border-radius: 0 0 var(--radius) var(--radius); align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; }
.daysep { align-self: center; font-size: 12px; color: var(--muted); background: var(--chip); padding: 2px 10px; border-radius: 999px; margin: 6px 0; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(10,20,30,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal .box { background: var(--card); border-radius: 16px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #14212b; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* login */
.authwrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.authbox { width: 100%; max-width: 380px; }
.authbox .logo { justify-content: center; font-size: 28px; margin-bottom: 4px; }
.authbox .logo img { width: 44px; height: 44px; border-radius: 12px; }
.pin { letter-spacing: 10px; font-size: 22px; text-align: center; }

/* client app */
.capp { max-width: 640px; margin: 0 auto; padding: 0 0 80px; }
.capp header { position: sticky; top: 0; z-index: 10; background: var(--brand); color: #fff; padding: 12px 16px; }
.capp header .logo { color: #fff; }
.capp header .biz { font-size: 13px; opacity: .9; }
.capp .page { padding: 14px; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
.bottomnav button { flex: 1; border: none; background: none; padding: 10px 4px 9px; font-weight: 700; font-size: 12px; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.bottomnav button svg { width: 22px; height: 22px; }
.bottomnav button.on { color: var(--brand); }
.bottomnav .badge { position: absolute; top: 4px; left: 54%; }
.capp .chat { height: 60vh; }
.capp .page { padding-bottom: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 10px 0; position: relative; }
.timeline li .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; background: var(--card); z-index: 1; }
.timeline li.done .dot { background: var(--ok); border-color: var(--ok); }
.timeline li.now .dot { background: var(--brand); border-color: var(--brand); box-shadow: 0 0 0 5px var(--brand-soft); }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 10px; top: 32px; bottom: -10px; width: 2px; background: var(--line); }
.timeline li.now b { color: var(--brand); }
.notice { border-radius: 12px; padding: 12px 14px; background: var(--brand-soft); margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); }
