:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #1f1a14;
  --muted: #6f665b;
  --line: #e4ddd2;
  --brand: #7a4a12;
  --brand-ink: #ffffff;
  --brand-soft: #f3e8d8;
  --ok: #1f9d55;
  --warn: #e0a100;
  --sos: #d62d20;
  --off: #8a8f98;
  --fin: #2563eb;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--sos); min-height: 1.2em; }
.grow { flex: 1; }
h3 { margin: 18px 0 8px; font-size: 16px; }
.card h3 { margin-top: 0; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { text-align: left; }
.brand-mark { font-size: 40px; color: var(--brand); line-height: 1; }
.brand-mark.sm { font-size: 20px; }

/* Header */
#app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--brand); color: var(--brand-ink); }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .brand-mark { color: #f8d9a8; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: rgba(255,255,255,.18); white-space: nowrap; }
.pill.run { background: var(--ok); }
.pill.done { background: #444; }
.clock { font-variant-numeric: tabular-nums; font-size: 13px; opacity: .85; white-space: nowrap; }
.badge { background: var(--sos); color: #fff; border: 0; border-radius: 99px; min-width: 26px; height: 26px; font-weight: 700; cursor: pointer; }
.conn { color: #ff9b9b; font-size: 12px; }
.conn.on { color: #8dffb5; }
.tabs { display: flex; gap: 2px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 11px 14px; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }
.mini-badge { background: var(--sos); color: #fff; border-radius: 99px; padding: 0 6px; font-size: 11px; margin-left: 3px; }
main { flex: 1; min-height: 0; position: relative; }
.tab { display: none; height: 100%; overflow: auto; }
.tab.on { display: block; }
.pad { padding: 14px 16px 40px; }

/* SOS */
.sos-bar { background: var(--sos); color: #fff; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-weight: 700; animation: blink 1s steps(2) infinite; }
.sos-bar .btn { background: #fff; color: var(--sos); }
@keyframes blink { 50% { background: #a0170d; } }

/* Buttons & form */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--sos); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.top .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; min-width: 0; }
textarea { min-height: 70px; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 14px; }
label.inline input { width: auto; }
.form { display: grid; gap: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 120px; }
.row > .btn { flex: 0 0 auto; }
.radio-row { display: flex; gap: 14px; flex-wrap: wrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input { width: 200px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
.copy-row { display: flex; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
.tbl th { background: var(--brand-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--brand); position: sticky; top: 0; }
.tbl td.wrap { white-space: normal; min-width: 160px; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eee; }
.tag.putra { background: #dbeafe; color: #1e40af; }
.tag.putri { background: #fce7f3; color: #9d174d; }
.tag.ok { background: #dcfce7; color: #166534; }
.tag.no { background: #f1f1f1; color: #666; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.sos { background: var(--sos); color: #fff; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* Map */
.map-wrap { position: absolute; inset: 0; display: flex; }
#map { flex: 1; height: 100%; }
.side { width: 330px; height: 100%; display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
.side-head { padding: 10px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.side-list { overflow-y: auto; flex: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.sos { background: var(--sos); }
.dot.off { background: var(--off); } .dot.fin { background: var(--fin); } .dot.none { background: transparent; border: 2px dashed #bbb; }
.item { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; gap: 2px; }
.item:hover { background: var(--brand-soft); }
.item .t1 { font-weight: 700; display: flex; align-items: center; gap: 4px; }
.item .t2 { font-size: 12px; color: var(--muted); }
.item .t3 { font-size: 12px; }
.item.sos { background: #fde8e6; }
.side-toggle { display: none; }
.lbl { background: rgba(255,255,255,.92); border: 1px solid #ccc; border-radius: 4px; padding: 0 4px; font-size: 11px; font-weight: 700; box-shadow: none; }
.lbl::before { display: none; }
.pop h4 { margin: 0 0 2px; font-size: 15px; }
.pop .muted { font-size: 12px; }
.pop table { font-size: 13px; margin: 6px 0; border-collapse: collapse; }
.pop td { padding: 1px 8px 1px 0; }
.pop .acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* Pos */
.split { position: absolute; inset: 0; display: flex; }
.pos-map { flex: 1; height: 100%; }
.split-side { width: 420px; overflow-y: auto; border-left: 1px solid var(--line); background: var(--bg); }
.post { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.post .hd { display: flex; align-items: center; gap: 8px; }
.post .hd b { flex: 1; }
.post .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.post .who { margin-top: 8px; font-size: 13px; }

/* Alerts */
.alert-list { display: grid; gap: 8px; }
.alert { background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--warn); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.alert.sos { border-left-color: var(--sos); background: #fff5f4; }
.alert.done { opacity: .6; border-left-color: var(--line); }
.alert .body { flex: 1 1 240px; }
.alert .body b { display: block; }

/* Dialog & toasts */
dialog { border: 0; border-radius: 14px; padding: 20px; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 4px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 5000; max-width: calc(100vw - 32px); }
.toast { background: #222; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 380px; cursor: pointer; }
.toast.sos { background: var(--sos); }
.toast.warn { background: #92400e; }

@media (max-width: 760px) {
  .clock { display: none; }
  .side { position: absolute; right: 0; top: 0; bottom: 0; width: 88%; max-width: 360px; z-index: 1000; transform: translateX(100%); transition: transform .2s; box-shadow: -4px 0 16px rgba(0,0,0,.15); }
  .side.open { transform: none; }
  .side-toggle { display: block; position: absolute; right: 12px; bottom: 20px; z-index: 1001; background: var(--brand); color: #fff; border: 0; border-radius: 99px; padding: 12px 18px; font-weight: 700; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
  .split { position: static; flex-direction: column; }
  .pos-map { height: 45vh; flex: none; }
  .split-side { width: 100%; border-left: 0; }
  .toolbar input { width: 100%; }
  .cards { grid-template-columns: 1fr; }
}
