/* ระบบติดตามสำนวนค้างส่งศาลอุทธรณ์ — themes are sets of tokens on [data-theme]. */

:root,
[data-theme="court"] {
  --bg: #f3f5fa; --surface: #ffffff; --surface-2: #f7f8fc; --ink: #172036; --muted: #5f6b85; --line: #e1e6f0;
  --primary: #1f3a8a; --primary-2: #2f56c4; --primary-ink: #ffffff; --primary-soft: #e8eefc; --accent: #c49a3a;
  --head-1: #18306f; --head-2: #2b4fb3;
  --danger: #c62828; --danger-soft: #fdecec; --warn: #c25e00; --warn-soft: #fff1e0; --soon: #a16207; --soon-soft: #fef7d7;
  --ok: #18794e; --ok-soft: #e3f5ea; --info-soft: #eef2f8;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 6px 20px rgba(20, 30, 60, .06);
  --shadow-lg: 0 20px 60px rgba(15, 25, 50, .25);
  color-scheme: light;
}
[data-theme="emerald"] { --primary: #047857; --primary-2: #10a37f; --primary-soft: #e3f6ef; --accent: #d4a017; --head-1: #035e45; --head-2: #0b8f6c; --bg: #f2f7f5; --line: #dde9e4; --info-soft: #edf5f2; }
[data-theme="royal"] { --primary: #5b21b6; --primary-2: #7c3aed; --primary-soft: #f0e9fe; --accent: #e0a526; --head-1: #4c1d95; --head-2: #7c3aed; --bg: #f6f3fc; --line: #e7e0f5; --info-soft: #f2eefa; }
[data-theme="rose"] { --primary: #be185d; --primary-2: #e2367f; --primary-soft: #fde8f1; --accent: #7c3aed; --head-1: #9d174d; --head-2: #db2777; --bg: #fcf4f7; --line: #f2dfe7; --info-soft: #faeef3; }
[data-theme="amber"] { --primary: #b45309; --primary-2: #ea7a12; --primary-soft: #fff1df; --accent: #0f766e; --head-1: #92400e; --head-2: #d97706; --bg: #fbf7f1; --line: #efe4d4; --info-soft: #f8f1e6; }
[data-theme="ocean"] { --primary: #0e7490; --primary-2: #0891b2; --primary-soft: #e0f4f8; --accent: #f59e0b; --head-1: #155e75; --head-2: #0891b2; --bg: #f1f7f9; --line: #d9e9ee; --info-soft: #ebf4f7; }
[data-theme="night"], [data-theme="nightgold"] {
  --bg: #0d1424; --surface: #151e33; --surface-2: #1b2640; --ink: #e6ebf5; --muted: #98a3bb; --line: #26324d;
  --primary: #6d9bff; --primary-2: #8fb3ff; --primary-ink: #0b1220; --primary-soft: #1d2c4f; --accent: #f2c14e;
  --head-1: #111b33; --head-2: #1d2d55;
  --danger: #ff6b6b; --danger-soft: #3a1c24; --warn: #ffa94d; --warn-soft: #3a2a1a; --soon: #f5d061; --soon-soft: #33301a;
  --ok: #4ade80; --ok-soft: #173a2a; --info-soft: #1a2440;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
[data-theme="nightgold"] { --primary: #e3b341; --primary-2: #f2c96a; --primary-soft: #33290f; --accent: #6d9bff; --head-1: #17140c; --head-2: #2c2410; --bg: #0f0e0b; --surface: #1a1813; --surface-2: #211e17; --line: #332e22; --info-soft: #221f17; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 15.5px/1.55 "Sarabun", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
}
h1, h2, h3, .display { font-family: "Prompt", "Sarabun", sans-serif; font-weight: 600; line-height: 1.3; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.svg { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.18em; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); border-radius: 11px; padding: .5em .95em; cursor: pointer;
  font-weight: 600; font-size: .95em; text-decoration: none; transition: transform .08s, background .15s, border-color .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: .32em .65em; font-size: .86em; border-radius: 9px; }
.btn.icon { padding: .5em; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: grid; gap: 4px; align-content: start; }
.field > span { font-size: .85em; color: var(--muted); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: .55em .75em;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
textarea.input { resize: vertical; min-height: 70px; }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 10% -10%, color-mix(in srgb, var(--primary) 28%, transparent), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%), var(--bg);
}
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 30px 26px; display: grid; gap: 14px; }
.login-card .logo { width: 84px; height: 84px; margin: 0 auto; }
.login-card h1 { text-align: center; font-size: 1.3em; }
.login-card p { text-align: center; margin: -6px 0 6px; color: var(--muted); }
.login-card .error { color: var(--danger); text-align: center; min-height: 1.4em; font-weight: 600; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; color: #fff;
  background: linear-gradient(120deg, var(--head-1), var(--head-2));
  box-shadow: 0 2px 16px rgba(0, 0, 0, .15);
}
.topbar-inner { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 14px; padding: 10px 20px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .92); padding: 2px; flex: none; }
.brand .t1 { font-family: "Prompt", sans-serif; font-weight: 600; font-size: 1.08em; line-height: 1.2; }
.brand .t2 { font-size: .84em; opacity: .85; }
.topbar .spacer { flex: 1; }
.topbar .chip { display: inline-flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .2); padding: 6px 11px; border-radius: 999px; font-size: .88em; white-space: nowrap; }
.topbar .tb-btn { background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22); color: #fff; border-radius: 11px; padding: 7px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.topbar .tb-btn:hover { background: rgba(255, 255, 255, .24); }
.topbar .tb-btn.alert { background: #fff; color: var(--danger); animation: pulse-bg 1.4s infinite; }
.nav { max-width: 1320px; margin: 0 auto; display: flex; gap: 4px; padding: 0 14px; overflow-x: auto; scrollbar-width: none; }
.nav a {
  display: inline-flex; align-items: center; gap: 7px; color: rgba(255, 255, 255, .8); text-decoration: none; padding: 9px 14px 11px;
  border-bottom: 3px solid transparent; font-weight: 600; white-space: nowrap; position: relative;
}
.nav a:hover { color: #fff; }
.nav a.active { color: #fff; border-bottom-color: var(--accent); }
.nav .count { background: var(--danger); color: #fff; border-radius: 999px; font-size: .74em; padding: 0 7px; line-height: 1.6; }

/* ---------- alarm banner ---------- */
.alarm-bar { max-width: 1320px; margin: 14px auto 0; padding: 0 20px; }
.alarm-inner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; border-radius: 16px; padding: 12px 16px;
  background: linear-gradient(110deg, var(--danger), color-mix(in srgb, var(--danger) 70%, #ff8a00)); color: #fff;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--danger) 35%, transparent);
}
.alarm-inner.quiet { background: var(--danger-soft); color: var(--danger); box-shadow: none; border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.alarm-inner .big { font-family: "Prompt", sans-serif; font-weight: 600; font-size: 1.08em; }
.alarm-inner .grow { flex: 1; min-width: 220px; }
.alarm-inner .btn { background: rgba(255, 255, 255, .95); color: var(--danger); border: 0; }
.alarm-inner.quiet .btn { background: var(--surface); border: 1px solid var(--line); }
.ring-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .2); flex: none; }
.alarm-inner:not(.quiet) .ring-icon .svg { animation: ring 1.2s infinite; transform-origin: 50% 10%; }

/* ---------- layout ---------- */
main { max-width: 1320px; margin: 0 auto; padding: 18px 20px 110px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 6px 0 16px; }
.page-head h2 { font-size: 1.45em; }
.page-head .sub { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card h3 { font-size: 1.05em; display: flex; align-items: center; gap: 8px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat {
  position: relative; overflow: hidden; border-radius: 18px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); cursor: pointer; text-align: left; transition: transform .12s, box-shadow .12s;
}
.stat:hover { transform: translateY(-2px); }
.stat .label { color: var(--muted); font-weight: 600; font-size: .92em; display: flex; align-items: center; gap: 7px; }
.stat .num { font-family: "Prompt", sans-serif; font-size: 2.3em; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.stat .foot { font-size: .84em; color: var(--muted); }
.stat::after { content: ""; position: absolute; right: -24px; top: -24px; width: 96px; height: 96px; border-radius: 50%; background: var(--tone-soft); }
.stat .ico { position: absolute; right: 14px; top: 14px; z-index: 1; color: var(--tone); }
.stat .ico .svg { width: 26px; height: 26px; }
.stat .num { color: var(--tone); }
.tone-danger { --tone: var(--danger); --tone-soft: var(--danger-soft); }
.tone-warn { --tone: var(--warn); --tone-soft: var(--warn-soft); }
.tone-soon { --tone: var(--soon); --tone-soft: var(--soon-soft); }
.tone-primary { --tone: var(--primary); --tone-soft: var(--primary-soft); }
.tone-ok { --tone: var(--ok); --tone-soft: var(--ok-soft); }
.stat.hot { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); animation: glow 2s infinite; }

/* ---------- pipeline ---------- */
.pipeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.pipe {
  position: relative; border-radius: 14px; padding: 12px 12px 10px; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; text-align: left;
  transition: border-color .15s, transform .12s;
}
.pipe:hover { border-color: var(--primary); transform: translateY(-1px); }
.pipe .n { font-family: "Prompt", sans-serif; font-size: 1.7em; font-weight: 600; color: var(--primary); line-height: 1.1; }
.pipe .step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); font-weight: 700; font-size: .8em; }
.pipe .name { font-weight: 600; margin-top: 6px; font-size: .93em; }
.pipe .bar { height: 5px; border-radius: 9px; background: var(--line); margin-top: 8px; overflow: hidden; }
.pipe .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 9px; }
.pipe .alerts { position: absolute; top: 10px; right: 10px; background: var(--danger); color: #fff; border-radius: 999px; font-size: .74em; padding: 0 7px; font-weight: 700; }
.pipe.done .n { color: var(--ok); }
.pipe.done .step { background: var(--ok); }

/* ---------- urgency badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 10px; font-size: .84em; font-weight: 700; white-space: nowrap; }
.u-overdue { background: var(--danger); color: #fff; }
.u-due { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.u-soon { background: var(--soon-soft); color: var(--soon); }
.u-waiting { background: var(--info-soft); color: var(--muted); }
.u-none { background: var(--info-soft); color: var(--muted); font-weight: 600; }
.u-done { background: var(--ok-soft); color: var(--ok); }
.stage-pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 9px; padding: 3px 9px; font-size: .86em; font-weight: 700; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.stage-pill b { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 6px; background: var(--primary); color: var(--primary-ink); font-size: .8em; }
.stage-pill.done { background: var(--ok-soft); color: var(--ok); }
.stage-pill.done b { background: var(--ok); }
.mini-steps { display: inline-flex; gap: 3px; margin-top: 4px; }
.mini-steps i { width: 16px; height: 5px; border-radius: 4px; background: var(--line); }
.mini-steps i.on { background: var(--primary); }

/* ---------- urgent list ---------- */
.urgent-list { display: grid; gap: 10px; }
.urgent {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 12px 14px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-left: 5px solid var(--tone, var(--line)); cursor: pointer;
}
.urgent:hover { border-color: color-mix(in srgb, var(--tone) 50%, var(--line)); }
.urgent .nos { font-weight: 700; }
.urgent .who { color: var(--muted); font-size: .9em; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.urgent .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.ringdays { width: 56px; height: 56px; position: relative; display: grid; place-items: center; }
.ringdays svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ringdays .v { font-family: "Prompt", sans-serif; font-weight: 600; font-size: 1.15em; line-height: 1; text-align: center; color: var(--tone); }
.ringdays .v small { display: block; font-size: .5em; font-family: "Sarabun", sans-serif; color: var(--muted); font-weight: 600; margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.empty .svg { width: 40px; height: 40px; color: var(--ok); display: block; margin: 0 auto 8px; }

.upcoming { display: grid; gap: 8px; }
.day-group { display: grid; grid-template-columns: 62px 1fr; gap: 10px; align-items: start; }
.day-box { border-radius: 12px; text-align: center; padding: 6px 4px; background: var(--primary-soft); color: var(--primary); }
.day-box .d { font-family: "Prompt", sans-serif; font-size: 1.35em; font-weight: 600; line-height: 1.1; }
.day-box .m { font-size: .76em; font-weight: 700; }
.day-box.today { background: var(--warn); color: #fff; }
.day-items { display: grid; gap: 6px; }
.day-item { padding: 7px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; font-size: .93em; }
.day-item:hover { border-color: var(--primary); }

/* ---------- toolbar & table ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 260px; }
.search .svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chipf { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-weight: 600; font-size: .9em; display: inline-flex; gap: 6px; align-items: center; }
.chipf .c { background: var(--surface-2); border-radius: 999px; padding: 0 7px; font-size: .85em; color: var(--muted); }
.chipf.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chipf.on .c { background: rgba(255, 255, 255, .25); color: inherit; }
.table-wrap { overflow: hidden; }
table.cases { width: 100%; border-collapse: separate; border-spacing: 0; }
table.cases th { text-align: left; font-size: .84em; color: var(--muted); font-weight: 700; padding: 11px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
table.cases td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.cases tr { cursor: pointer; }
table.cases tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
table.cases tbody tr:last-child td { border-bottom: 0; }
table.cases td:first-child { border-left: 4px solid var(--tone, transparent); }
.parties { font-size: .9em; max-width: 360px; }
.parties div { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.caseno { font-weight: 700; white-space: nowrap; }
.caseno small { display: block; font-weight: 600; color: var(--muted); }
.row-acts { display: flex; gap: 6px; justify-content: flex-end; }
.result-count { color: var(--muted); font-size: .9em; margin: 0 2px 8px; }

/* ---------- board ---------- */
.board { display: grid; grid-template-columns: repeat(6, minmax(230px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; padding: 10px; min-height: 200px; transition: background .15s, border-color .15s; }
.col.drop { background: var(--primary-soft); border-color: var(--primary); border-style: dashed; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 10px; font-weight: 700; }
.col-head .step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); font-size: .8em; }
.col.done-col .col-head .step { background: var(--ok); }
.col-head .n { margin-left: auto; color: var(--muted); font-size: .9em; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--tone, var(--line)); border-radius: 12px; padding: 9px 10px; margin-bottom: 8px; cursor: grab; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .45; }
.kcard .nos { font-weight: 700; font-size: .95em; }
.kcard .who { font-size: .84em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin: 2px 0 6px; }
.kcard .row { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.kcard .moves { margin-left: auto; }
.kcard .moves { display: flex; gap: 4px; }

/* ---------- modal ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 20px; width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.modal.small { width: min(520px, calc(100vw - 24px)); }
dialog.modal.wide { width: min(1100px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 16, 32, .5); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h3 { font-size: 1.2em; }
.modal-head .grow { flex: 1; min-width: 0; }
.modal-body { padding: 16px 20px; display: grid; gap: 16px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 20px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
.modal-foot .left { margin-right: auto; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: 1 / -1; }
.deadline-box { border-radius: 14px; padding: 12px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* stepper */
.stepper { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0; counter-reset: st; }
.stepper button { position: relative; background: none; border: 0; padding: 0 4px; cursor: pointer; text-align: center; display: grid; justify-items: center; gap: 6px; font-size: .84em; font-weight: 600; color: var(--muted); }
.stepper button::before { content: ""; position: absolute; top: 17px; left: -50%; right: 50%; height: 3px; background: var(--line); z-index: 0; }
.stepper button:first-child::before { display: none; }
.stepper .dot { position: relative; z-index: 1; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--line); font-weight: 700; color: var(--muted); transition: all .15s; }
.stepper button.past .dot { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.stepper button.past::before, .stepper button.cur::before { background: var(--primary); }
.stepper button.cur .dot { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 20%, transparent); }
.stepper button.cur { color: var(--ink); }
.stepper button.final .dot { border-color: var(--ok); color: var(--ok); }
.stepper button.final.cur .dot { background: var(--ok); color: #fff; box-shadow: 0 0 0 5px color-mix(in srgb, var(--ok) 20%, transparent); }
.stepper button:hover .dot { border-color: var(--primary); }

.timeline { display: grid; gap: 0; }
.tl { display: grid; grid-template-columns: 18px 1fr; gap: 10px; font-size: .9em; }
.tl .d { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); margin: 6px auto 0; box-shadow: 0 0 0 3px var(--primary-soft); }
.tl .body { padding-bottom: 10px; border-left: 0; }

/* alert modal */
dialog.alarm-modal .modal-head { background: linear-gradient(110deg, var(--danger), color-mix(in srgb, var(--danger) 70%, #ff8a00)); color: #fff; border-radius: 20px 20px 0 0; border-bottom: 0; }
.alarm-modal .bigicon { width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 255, 255, .2); display: grid; place-items: center; flex: none; }
.alarm-modal .bigicon .svg { width: 30px; height: 30px; animation: ring 1.1s infinite; transform-origin: 50% 10%; }

/* settings */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .t { font-weight: 600; }
.setting-row .d { font-size: .86em; color: var(--muted); }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); }
.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.theme-swatch { border: 2px solid var(--line); border-radius: 14px; padding: 8px; cursor: pointer; background: var(--surface); display: grid; gap: 6px; text-align: center; font-size: .85em; font-weight: 600; }
.theme-swatch.on { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.theme-swatch .sw { height: 38px; border-radius: 9px; display: flex; overflow: hidden; }
.theme-swatch .sw i { flex: 1; }
.hol-list { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.hol-list div { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: .92em; }
.hol-list div:last-child { border-bottom: 0; }
.hol-list .past { opacity: .5; }
.log-list { max-height: 340px; overflow: auto; font-size: .88em; }
.log-list div { padding: 6px 0; border-bottom: 1px dashed var(--line); }

/* popover */
.popover { position: absolute; right: 16px; top: 62px; z-index: 50; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 14px; width: 330px; }

/* FAB + bottom nav (mobile) */
.fab { position: fixed; right: 22px; bottom: 24px; z-index: 25; border-radius: 18px; padding: 14px 18px; box-shadow: 0 10px 30px color-mix(in srgb, var(--primary) 45%, transparent); font-size: 1em; }
.bottom-nav { display: none; }

/* toast */
.toasts { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
.toasts[popover] { inset: auto auto 26px 50%; margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; color: inherit; width: max-content; max-width: calc(100vw - 32px); }
.toasts[popover]:not(:popover-open) { display: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 600; animation: toast-in .25s; }
.toast.err { background: var(--danger); color: #fff; }

/* sound unlock chip */
.unlock { position: fixed; left: 16px; bottom: 20px; z-index: 40; }

/* import preview */
.preview-table { width: 100%; border-collapse: collapse; font-size: .88em; }
.preview-table th, .preview-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.preview-table th { white-space: nowrap; position: sticky; top: 0; background: var(--surface-2); }
.preview-table tr.exists td { color: var(--muted); }
.preview-table tr.warn td { background: var(--warn-soft); }

/* ---------- animation ---------- */
@keyframes ring { 0%, 50%, 100% { transform: rotate(0); } 10% { transform: rotate(16deg); } 20% { transform: rotate(-14deg); } 30% { transform: rotate(10deg); } 40% { transform: rotate(-6deg); } }
@keyframes pulse-bg { 50% { box-shadow: 0 0 0 6px rgba(255, 255, 255, .25); } }
@keyframes glow { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 18%, transparent), var(--shadow); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 0, 0); } 20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-8px, 0, 0); } 40%, 60% { transform: translate3d(8px, 0, 0); }
}
body.shake #app { animation: shake .7s cubic-bezier(.36, .07, .19, .97) 2; }
body.flash::after { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 200; box-shadow: inset 0 0 0 10px var(--danger); animation: flash .5s 4 alternate; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { body.shake #app { animation: none; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .pipeline { grid-template-columns: repeat(3, 1fr); }
  .settings { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .topbar-inner { padding: 8px 14px; gap: 8px; }
  .brand img { width: 36px; height: 36px; }
  .brand .t1 { font-size: .98em; }
  .brand .t2, .topbar .chip.date, .topbar .user-name { display: none; }
  .nav { display: none; }
  main { padding: 14px 14px 120px; }
  .alarm-bar { padding: 0 14px; margin-top: 12px; }
  .alarm-inner { padding: 10px 12px; gap: 8px 10px; border-radius: 14px; }
  .alarm-inner .big { font-size: .95em; }
  .alarm-inner .grow { min-width: 0; flex: 1 1 calc(100% - 50px); font-size: .9em; }
  .alarm-inner .btn { padding: .35em .8em; font-size: .88em; }
  .ring-icon { width: 34px; height: 34px; }
  .stat .label { padding-right: 30px; font-size: .86em; }
  .stat::after { width: 64px; height: 64px; right: -18px; top: -18px; }
  .stat .ico .svg { width: 20px; height: 20px; }
  .toolbar select.input { flex: 1 1 40%; width: auto !important; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .chipf { flex: none; }
  [data-act="print"] { display: none !important; }
  .stats { gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat .num { font-size: 1.9em; }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
  .urgent { grid-template-columns: auto 1fr; }
  .urgent .acts { grid-column: 1 / -1; justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .stepper { grid-template-columns: repeat(3, 1fr); row-gap: 14px; }
  .stepper button:nth-child(4)::before { display: none; }
  .themes { grid-template-columns: repeat(2, 1fr); }
  .popover { left: 14px; right: 14px; width: auto; }
  table.cases thead { display: none; }
  table.cases, table.cases tbody, table.cases tr, table.cases td { display: block; }
  table.cases tr { border: 1px solid var(--line); border-left: 5px solid var(--tone, var(--line)); border-radius: 14px; margin: 0 0 10px; padding: 8px 12px; background: var(--surface); }
  table.cases td { border: 0 !important; padding: 3px 0; }
  table.cases tr { display: flex; flex-direction: column; }
  table.cases td.caseno { order: -1; font-size: 1.05em; }
  table.cases td.caseno small { display: inline; margin-left: 6px; }
  table.cases td[data-l]::before { content: attr(data-l) " "; display: inline; font-size: .8em; color: var(--muted); font-weight: 700; margin-right: 4px; }
  table.cases td[data-l] br { display: none; }
  table.cases .mini-steps { display: none; }
  table.cases td.hide-m { display: none; }
  .table-wrap.card { background: transparent; border: 0; box-shadow: none; }
  .row-acts { justify-content: flex-start; padding-top: 6px !important; }
  .board { grid-template-columns: repeat(6, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .fab { bottom: 84px; right: 16px; padding: 14px; }
  .fab .lbl { display: none; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a { display: grid; justify-items: center; gap: 2px; font-size: .72em; font-weight: 600; color: var(--muted); text-decoration: none; padding: 4px 0; position: relative; }
  .bottom-nav a .svg { width: 22px; height: 22px; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav .count { position: absolute; top: 0; left: 55%; background: var(--danger); color: #fff; border-radius: 99px; font-size: .9em; padding: 0 6px; }
  .unlock { bottom: 84px; }
  .toasts { bottom: 90px; }
}

/* ---------- print ---------- */
@media print {
  .topbar, .alarm-bar, .toolbar, .fab, .bottom-nav, .row-acts, .unlock, .no-print { display: none !important; }
  body { background: #fff; font-size: 12px; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  table.cases th { position: static; }
  table.cases td { padding: 5px 6px; }
  .print-title { display: block !important; text-align: center; margin-bottom: 8px; }
}
.print-title { display: none; }

/* demo package tag */
.topbar .chip.demo { background: var(--accent); border-color: transparent; color: #1b1406; font-weight: 700; }

/* sound picker */
.sound-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 6px; }
.sound-opt { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); font-size: .92em; }
.sound-opt:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.sound-opt.on { border-color: var(--primary); background: var(--primary-soft); }
.sound-opt .muted { font-size: .86em; }
.sound-opt .play { flex: none; width: 34px; height: 34px; border-radius: 50%; font-size: .8em; }
.sound-off { opacity: .55; }
.modal-foot .sound-hint-btn { order: -1; }
@media (max-width: 760px) { .sound-grid { grid-template-columns: 1fr; } }
