/* UnionSPACE Case Tracker. Orange + navy on warm paper. Works on phones (BST updates from anywhere). */
:root {
  --bg: #FBF7F3; --surface: #FFFFFF; --sunk: #F4EEE8; --ink: #14131A; --body: #33313A; --muted: #6E6862;
  --line: #ECE4DC; --navy: #01004C; --orange: #FF581A; --orange-d: #B83A0A; --orange-soft: #FFE9DF;
  --ok: #1E7A46; --ok-soft: #E3F4EA; --warn: #9A5800; --warn-soft: #FDF0DA; --bad: #C2341B; --bad-soft: #FBE5E0; --navy-soft: #E8E8F6;
  --r: 14px; --font: "Poppins", "Noto Sans Thai", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --shadow: 0 1px 2px rgba(20,19,26,.04), 0 4px 14px rgba(20,19,26,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121118; --surface: #1B1A22; --sunk: #24232C; --ink: #F4EFEA; --body: #DAD4CE; --muted: #A29B94;
    --line: #2F2D38; --navy: #C9C7FA; --orange: #FF6A30; --orange-d: #FF8A5C; --orange-soft: #3A2218;
    --ok: #5CC98A; --ok-soft: #17301F; --warn: #E3A54A; --warn-soft: #33270F; --bad: #FF7A62; --bad-soft: #3A1C17; --navy-soft: #24234A;
    --shadow: none; color-scheme: dark;
  }
  :root:not([data-theme="light"]) .logo img { background: #fff; border-radius: 8px; padding: 3px 7px; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--body); font: 14.5px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--navy); text-underline-offset: 2px; }
a:hover { color: var(--orange-d); }
h1, h2, h3 { color: var(--ink); margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .92em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* top bar */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 600; white-space: nowrap; }
.logo img { height: 26px; width: auto; display: block; }
.logo span { font-size: 13px; color: var(--muted); font-weight: 500; border-left: 1px solid var(--line); padding-left: 10px; }
.topnav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topnav a { padding: 7px 11px; border-radius: 9px; text-decoration: none; color: var(--body); white-space: nowrap; font-weight: 500; font-size: 13.5px; }
.topnav a:hover { background: var(--sunk); color: var(--ink); }
.topnav a.on { background: var(--orange-soft); color: var(--orange-d); }
.me { display: flex; align-items: center; gap: 12px; font-size: 13px; white-space: nowrap; }
.bell { position: relative; text-decoration: none; font-size: 17px; }
.bell b { position: absolute; top: -6px; right: -9px; background: var(--orange); color: #fff; font-size: 10.5px; border-radius: 99px; padding: 0 5px; line-height: 16px; }
@media (max-width: 860px) {
  .top-in { flex-wrap: wrap; gap: 8px 12px; }
  .topnav { order: 3; flex-basis: 100%; }
  .me { margin-left: auto; }
  .logo span { display: none; }
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 16px 60px; }
.wrap.narrow { max-width: 760px; }
.stack > * + * { margin-top: 16px; }
.stack-s > * + * { margin-top: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.side.side-cl { grid-template-columns: minmax(0, 1fr) 280px; }
@media (max-width: 960px) { .side, .side.side-cl { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card h2 + * { margin-top: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 10px; }
.section-title:first-child { margin-top: 0; }
.count { background: var(--sunk); color: var(--muted); border-radius: 99px; padding: 0 8px; font-size: 12px; font-weight: 600; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 22px; }
@media (max-width: 960px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-decoration: none; color: inherit; display: block; }
.kpi b { display: block; font-size: 24px; color: var(--ink); font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.bad b { color: var(--bad); } .kpi.warn b { color: var(--warn); }
a.kpi:hover { border-color: var(--orange); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.link-row { cursor: pointer; }
.tbl tr.link-row:hover td { background: var(--sunk); }
.tbl .t-main { color: var(--ink); font-weight: 500; text-decoration: none; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }

/* pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--sunk); color: var(--body); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.navy { background: var(--navy-soft); color: var(--navy); }
.pill.orange { background: var(--orange-soft); color: var(--orange-d); }
.pill.muted { color: var(--muted); }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 500 13.5px var(--font); padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 38px; }
.btn:hover { border-color: var(--muted); color: var(--ink); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:hover { background: var(--orange-d); border-color: var(--orange-d); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.navy { background: var(--navy); border-color: var(--navy); color: var(--surface); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--sunk); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; min-height: 30px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.copied { background: var(--ok); border-color: var(--ok); color: #fff; }
label { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink); margin-bottom: 5px; }
.field + .field { margin-top: 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=tel], select, textarea {
  width: 100%; font: 14px var(--font); padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); min-height: 38px; }
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange-soft); border-color: var(--orange); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 13.5px; color: var(--body); }
.check input { margin-top: 3px; accent-color: var(--orange); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 360px; }

.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13.5px; background: var(--ok-soft); color: var(--ok); border: 1px solid transparent; }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }

/* progress */
.bar { height: 8px; background: var(--sunk); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--orange); border-radius: 99px; }
.bar.ok > i { background: var(--ok); }
.mini-bar { width: 80px; display: inline-block; vertical-align: middle; height: 6px; }

/* case header facts */
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.facts > div { background: var(--surface); padding: 11px 14px; }
.facts dt { font-size: 11.5px; color: var(--muted); }
.facts dd { margin: 2px 0 0; color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* milestone list (staff) */
.ms { list-style: none; margin: 0; padding: 0; }
.ms > li { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); align-items: start; }
.ms > li:last-child { border-bottom: 0; }
.ms .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; background: var(--sunk); color: var(--muted); }
.ms .done .dot { background: var(--ok); color: #fff; }
.ms .current .dot { background: var(--orange); color: #fff; box-shadow: 0 0 0 4px var(--orange-soft); }
.ms .skipped { opacity: .55; }
.ms .skipped .t { text-decoration: line-through; }
.ms .t { color: var(--ink); font-weight: 500; }
.ms .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ms .note { font-size: 12.5px; margin-top: 6px; padding: 6px 10px; background: var(--sunk); border-radius: 8px; }
.ms .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.ms .current { background: linear-gradient(90deg, var(--orange-soft), transparent 60%); }
details.inline > summary { list-style: none; cursor: pointer; }
details.inline > summary::-webkit-details-marker { display: none; }
.done-form { grid-column: 2 / -1; background: var(--sunk); border-radius: 10px; padding: 12px; margin-top: 4px; }
.done-form .grid2 { gap: 10px; }
@media (max-width: 640px) { .ms > li { grid-template-columns: 26px minmax(0, 1fr); } .ms .acts { grid-column: 2; justify-content: flex-start; } }

/* message draft */
.draft { white-space: pre-wrap; background: var(--sunk); border-radius: 10px; padding: 12px; font-size: 13.5px; color: var(--ink); border: 1px dashed var(--line); }
.update-card { border-left: 4px solid var(--orange); }
.update-card.late { border-left-color: var(--bad); }

/* activity */
.log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.log li { padding: 7px 0; border-bottom: 1px dashed var(--line); }
.log li:last-child { border-bottom: 0; }
.log b { color: var(--ink); font-weight: 500; }

/* template editor */
.ed th, .ed td { padding: 6px 6px; }
.ed input[type=text] { min-width: 150px; }
.ed input[type=number] { width: 80px; }

/* auth & client portal */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 420px; padding: 28px; }
.auth .logo { justify-content: center; margin-bottom: 18px; }
.auth .logo img { height: 34px; }

.cl-top { background: var(--surface); border-bottom: 1px solid var(--line); }
.cl-top .top-in { max-width: 880px; }
.langs { display: flex; gap: 2px; margin-left: auto; }
.langs a { padding: 4px 9px; border-radius: 8px; text-decoration: none; font-size: 13px; color: var(--muted); }
.langs a.on { background: var(--orange-soft); color: var(--orange-d); font-weight: 600; }
.cl-wrap { max-width: 880px; margin: 0 auto; padding: 26px 16px 60px; }
.hero { background: var(--navy); color: #fff; border-radius: 18px; padding: 24px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { background: #1F1E52; } }
.hero h1 { color: #fff; font-size: 22px; }
.hero .muted { color: rgba(255,255,255,.72); }
.hero .bar { background: rgba(255,255,255,.18); height: 10px; margin-top: 16px; }
.hero-facts { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 16px; }
.hero-facts dt { font-size: 12px; color: rgba(255,255,255,.7); }
.hero-facts dd { margin: 2px 0 0; font-weight: 600; font-size: 15px; }
.wait { background: var(--warn-soft); color: var(--warn); border-radius: 14px; padding: 16px 18px; }
.wait b { display: block; margin-bottom: 2px; }
.tl { list-style: none; margin: 0; padding: 0; position: relative; }
.tl li { position: relative; padding: 0 0 22px 40px; }
.tl li::before { content: ""; position: absolute; left: 13px; top: 28px; bottom: -2px; width: 2px; background: var(--line); }
.tl li:last-child::before { display: none; }
.tl li.done::before { background: var(--ok); }
.tl .dot { position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--sunk); border: 2px solid var(--line); display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.tl .done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.tl .current .dot { background: var(--orange); border-color: var(--orange); color: #fff; box-shadow: 0 0 0 5px var(--orange-soft); }
.tl .t { color: var(--ink); font-weight: 500; padding-top: 3px; }
.tl .upcoming .t { color: var(--body); font-weight: 400; }
.tl .meta { font-size: 13px; color: var(--muted); }
.tl .note { margin-top: 6px; font-size: 13px; background: var(--sunk); border-radius: 10px; padding: 8px 12px; }
.person { display: flex; gap: 12px; align-items: center; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--orange-soft); color: var(--orange-d); display: grid; place-items: center; font-weight: 600; flex: none; }
