/* SmartMed — design system */
:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --blue: #2F7DF6;
  --blue-l: #EAF2FF;
  --ink: #171A1F;
  --muted: #747A84;
  --line: #E8EBEF;
  --ok: #22C55E;
  --ok-l: #E8F8EE;
  --warn: #F59E0B;
  --warn-l: #FEF3E0;
  --bad: #EF4444;
  --bad-l: #FDECEC;
  --soft: #EEF0F3;
  --shadow: 0 1px 2px rgba(23, 26, 31, .03), 0 10px 30px -18px rgba(23, 26, 31, .12);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 'Manrope', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg.lucide { width: 20px; height: 20px; stroke-width: 2; flex: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 32px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: 16px 0 10px;
  background: linear-gradient(var(--bg) 75%, rgba(244, 246, 248, 0));
}
.topbar-inner {
  display: flex; align-items: center; gap: 24px;
  height: 72px; padding: 0 12px 0 14px;
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.logo { width: 44px; height: 44px; border-radius: 50%; background: var(--blue); display: grid; place-items: center; flex: none; }
.logo::before {
  content: ""; width: 21px; height: 9px; border-radius: 9px; transform: rotate(-45deg);
  background: linear-gradient(90deg, #fff 50%, rgba(255, 255, 255, .5) 50%);
}
.logo-inv { background: #fff; }
.logo-inv::before { background: linear-gradient(90deg, var(--blue) 50%, rgba(47, 125, 246, .4) 50%); }

.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 20px;
  border-radius: 999px; font-weight: 600; color: var(--muted);
  transition: background .2s, color .2s;
}
.nav a:hover { color: var(--ink); background: var(--bg); }
.nav a[aria-current="page"] { background: var(--ink); color: #fff; }
.nav svg.lucide { width: 18px; height: 18px; }

.top-actions { display: flex; align-items: center; gap: 10px; padding-left: 16px; border-left: 1px solid var(--line); }
.icon-btn {
  position: relative; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--bg); display: grid; place-items: center; transition: background .2s;
}
.icon-btn:hover { background: #E9EDF1; }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
.badge-dot { position: absolute; top: 11px; right: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 2px var(--bg); }

.pop { position: relative; }
.pop > summary { list-style: none; cursor: pointer; }
.pop > summary::-webkit-details-marker { display: none; }
.pop-panel {
  position: absolute; right: 0; top: calc(100% + 10px); width: 340px; padding: 8px;
  background: #fff; border-radius: 20px; z-index: 40;
  box-shadow: 0 18px 50px -16px rgba(23, 26, 31, .22), 0 0 0 1px var(--line);
  animation: pop .18s var(--ease);
}
.pop-sm { width: 240px; }
.pop-title { padding: 10px 12px 6px; font-weight: 800; font-size: 15px; }
.pop-item { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 12px; align-items: start; padding: 10px 12px; border-radius: 14px; }
.pop-item time { font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; line-height: 1.35; }
.pop-item .pill { margin-top: 6px; height: 24px; font-size: 12px; }
.pop-item:hover { background: var(--bg); }
.pop-item p { font-weight: 700; font-size: 14px; line-height: 1.35; }
.pop-item small, .pop-user small { color: var(--muted); font-size: 13px; }
.pop-user { display: flex; align-items: center; gap: 12px; padding: 10px 12px 14px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.pop-user p { font-weight: 700; }
button.pop-link { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; }
.pop-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; font-weight: 600; color: #DC2626; }
.pop-link:hover { background: var(--bad-l); }
.pop-link svg.lucide { width: 18px; height: 18px; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 14px 4px 4px; border-radius: 999px; background: var(--bg); transition: background .2s; }
.user-chip:hover { background: #E9EDF1; }
.user-meta { line-height: 1.2; }
.user-meta b { display: block; font-size: 14px; }
.user-meta small { color: var(--muted); font-size: 12px; font-weight: 500; }
.user-chip svg.lucide { width: 16px; height: 16px; color: var(--muted); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #DCE8FF; color: var(--blue); font-weight: 800; display: grid; place-items: center; flex: none; }

.bottom-nav {
  display: none; position: fixed; z-index: 30;
  left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom));
  padding: 8px; gap: 4px; border-radius: 24px;
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(14px);
  box-shadow: 0 12px 34px -12px rgba(23, 26, 31, .25), 0 0 0 1px var(--line);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 0; min-height: 48px; padding: 9px 0 7px; border-radius: 18px; text-align: center;
  font-size: 12px; font-weight: 700; color: var(--muted);
  transition: background .2s, color .2s;
}
.bottom-nav a[aria-current="page"] { background: var(--ink); color: #fff; }

/* ---------- Page ---------- */
.page { padding-top: 28px; padding-bottom: 72px; animation: rise .25s var(--ease); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.page-head h1 { font-size: clamp(30px, 4.2vw, 48px); font-weight: 800; letter-spacing: -.035em; line-height: 1.08; }
.lead { margin-top: 10px; color: var(--muted); font-size: 17px; font-weight: 500; }
.date-chip {
  display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.date-chip svg.lucide { width: 16px; height: 16px; }

.section { margin-top: 44px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-head h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }

.card { background: var(--surface); border-radius: 24px; padding: 24px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.card-head h2 { font-size: 18px; font-weight: 800; letter-spacing: -.015em; }
.card-head > :last-child { margin-left: auto; }
.link { display: inline-flex; align-items: center; gap: 4px; color: var(--blue); font-weight: 700; font-size: 14px; }
.link svg.lucide { width: 16px; height: 16px; transition: transform .2s var(--ease); }
.link:hover svg.lucide { transform: translate(2px, -2px); }


.eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

/* ---------- Pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px;
  border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-l); color: #15803D; }
.pill-warn { background: var(--warn-l); color: #B45309; }
.pill-bad { background: var(--bad-l); color: #DC2626; }
.pill-wait { background: var(--soft); color: #5B626C; }
.pill-info { background: var(--blue-l); color: var(--blue); }
.dot.pulse { animation: pulse 1.8s ease-out infinite; }

/* ---------- Buttons ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 22px; border: 0; border-radius: 14px;
  font-weight: 700; font-size: 15px; white-space: nowrap;
  transition: background .2s, box-shadow .2s, transform .15s, opacity .2s;
  --spin: #fff;
}
.btn:active { transform: scale(.98); }
.btn svg.lucide { width: 18px; height: 18px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #2470E8; }
.btn-soft { background: var(--bg); color: var(--ink); --spin: var(--ink); }
.btn-soft:hover { background: #EAEDF1; }
.btn-ghost { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); --spin: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { height: 40px; padding: 0 16px; font-size: 14px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--spin); border-right-color: transparent; animation: spin .7s linear infinite;
}
.tag { padding: 2px 7px; border-radius: 6px; background: var(--blue-l); color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- Dashboard: summary ---------- */
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; gap: 18px; min-height: 200px; }
.stat-head { font-weight: 700; font-size: 16px; }
.stat-num {
  display: flex; align-items: baseline; gap: 10px; margin-top: auto;
  font-size: 60px; font-weight: 800; letter-spacing: -.045em; line-height: 1; font-variant-numeric: tabular-nums;
}
.stat-num small { font-size: 15px; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.stat-num .of { font-size: 34px; letter-spacing: -.03em; }
.stat-word { font-size: 42px; align-items: center; gap: 14px; }
.live { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 5px var(--ok-l); flex: none; }
.live.off { background: #A8AFB8; box-shadow: 0 0 0 5px var(--soft); }
.stat-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--bg); color: #5B626C; font-variant-numeric: tabular-nums; }
.chip-opened { background: var(--ok-l); color: #15803D; }
.chip-overdue { background: var(--bad-l); color: #DC2626; }
.stat-foot { display: flex; align-items: center; justify-content: space-between; font-weight: 700; color: var(--muted); font-size: 14px; }

.stat-blue { background: var(--blue); color: #fff; box-shadow: 0 18px 40px -22px rgba(47, 125, 246, .7); }
.stat-blue .of { color: rgba(255, 255, 255, .6); }
.segments { display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: 6px; }
.segments span { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .24); transition: background .25s; }
.segments span.on { background: #fff; }
.stat-note { font-size: 14px; font-weight: 600; color: rgba(255, 255, 255, .82); margin-top: -6px; }

.signal { display: inline-flex; align-items: flex-end; gap: 3px; height: 18px; }
.signal span { width: 5px; border-radius: 2px; background: #D9DEE4; }
.signal span:nth-child(1) { height: 25%; } .signal span:nth-child(2) { height: 50%; }
.signal span:nth-child(3) { height: 75%; } .signal span:nth-child(4) { height: 100%; }
.signal span.on { background: var(--blue); }
.signal-lg { height: 40px; gap: 5px; }
.signal-lg span { width: 9px; border-radius: 3px; }

/* ---------- Alert ---------- */
.alerts { display: grid; gap: 12px; }
.alert {
  display: flex; align-items: center; gap: 16px; padding: 18px 20px 18px 18px;
  background: #fff; border-radius: 22px;
  box-shadow: var(--shadow), inset 0 0 0 1.5px rgba(239, 68, 68, .22);
  animation: rise .25s var(--ease);
}
.alert-icon { width: 24px; height: 24px; color: var(--bad); align-self: flex-start; margin-top: 2px; }
.alert-body { min-width: 0; }
.alert-title { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.alert-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; margin-top: 2px; color: var(--muted); font-weight: 600; font-size: 14px; }
.alert-meta b { color: #DC2626; font-weight: 700; }
.sep { width: 4px; height: 4px; border-radius: 50%; background: #C3CAD2; }
.alert .btn { margin-left: auto; }
.alert.leaving { animation: fall .2s var(--ease) forwards; }

/* ---------- Dose cards ---------- */
.doses { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.dose { display: flex; flex-direction: column; transition: box-shadow .2s; }
.dose-top { display: flex; align-items: flex-start; gap: 14px; }
.dose-top .pill { margin-left: auto; }
.dose-comp { font-weight: 700; font-size: 15px; margin-top: 1px; }
.dose-time { margin-top: 28px; font-size: 56px; font-weight: 800; letter-spacing: -.045em; line-height: 1; font-variant-numeric: tabular-nums; }
.dose-note { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-weight: 700; font-size: 14px; color: var(--muted); }
.dose-note svg.lucide { width: 16px; height: 16px; }
.dose-opened .dose-note { color: #16A34A; }
.dose-overdue { box-shadow: var(--shadow), inset 0 0 0 1.5px rgba(239, 68, 68, .35); }
.dose-overdue .dose-note { color: #DC2626; }
.dose-alarm { box-shadow: var(--shadow), inset 0 0 0 1.5px rgba(47, 125, 246, .35); }
.dose-alarm .dose-note { color: var(--blue); }

.track { display: flex; align-items: center; gap: 16px; margin-top: 22px; padding: 14px 16px; background: var(--bg); border-radius: 16px; }
.track small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.track b { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.track .end { text-align: right; }
.track-line { --c: #C3CAD2; position: relative; flex: 1; height: 2px; background: repeating-linear-gradient(90deg, var(--c) 0 6px, transparent 6px 11px); }
.track-line::before, .track-line::after {
  content: ""; position: absolute; top: 50%; width: 8px; height: 8px; border-radius: 50%;
  background: var(--c); transform: translateY(-50%);
}
.track-line::before { left: -2px; }
.track-line::after { right: -2px; }
.track-opened .track-line { --c: var(--ok); background: var(--ok); }
.track-overdue .track-line { --c: var(--bad); }
.track-overdue .track-line::after { animation: pulse-bad 1.8s ease-out infinite; }
.track-alarm .track-line { --c: var(--blue); }
.track-alarm .track-line::after { animation: pulse-blue 1.8s ease-out infinite; }
.track-waiting .track-line::after { background: var(--bg); box-shadow: inset 0 0 0 2px var(--c); }

/* ---------- Stock ---------- */
.stocks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.stock-form { display: grid; gap: 18px; }
.stock-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.box-state { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.box-state .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.box-state-open { color: #DC2626; background: var(--bad-l); }
.box-state-closed { color: #15803D; background: var(--ok-l); }
.box-state-stale { color: var(--muted); background: var(--soft); }
.stock-form label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.stock-value { display: flex; align-items: baseline; gap: 8px; margin-top: 8px; font-size: 52px; font-weight: 800; line-height: 1; letter-spacing: -.04em; }
.stock-value small { color: var(--muted); font-size: 14px; font-weight: 700; letter-spacing: 0; }

/* ---------- Dashboard bottom ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 20px; margin-top: 44px; align-items: start; }
.stack { display: grid; gap: 16px; }

.acts { list-style: none; margin: 0; padding: 0; }
.act { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 16px; align-items: baseline; padding: 14px 0; border-top: 1px solid var(--line); }
.act:first-child { border-top: 0; }
.act.is-new { animation: rise .25s var(--ease); }
.act-body { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.act-body p { font-weight: 700; }
.act time { display: flex; flex-direction: column; font-weight: 800; font-size: 15px; line-height: 1.3; font-variant-numeric: tabular-nums; }
.act time .day { font-size: 12px; font-weight: 600; color: var(--muted); }
.act-empty { display: block; color: var(--muted); font-weight: 500; }

.device-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 14px 0 20px; }
.device-id { font-size: 26px; font-weight: 800; letter-spacing: -.03em; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv div { background: var(--bg); border-radius: 14px; padding: 12px 14px; }
.kv dt { font-size: 12px; font-weight: 600; color: var(--muted); }
.kv dd { margin-top: 2px; font-weight: 800; font-size: 14px; }
.sensor-list { display: grid; gap: 8px; margin-top: 16px; }
.sensor-list div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; border-radius: 12px; background: var(--bg); font-size: 13px; font-weight: 700; }
.sensor-open { color: #DC2626; }
.sensor-closed { color: #15803D; }
.sensor-stale { color: var(--muted); }

.note { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; border-radius: 18px; background: var(--blue-l); color: #2E4F84; font-size: 13.5px; font-weight: 500; line-height: 1.55; }
.note svg.lucide { width: 18px; height: 18px; color: var(--blue); margin-top: 1px; }

/* ---------- Jadwal ---------- */
.sync-chip { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 999px; background: #fff; box-shadow: var(--shadow); font-size: 14px; font-weight: 700; white-space: nowrap; }
.sync-chip svg.lucide { width: 16px; height: 16px; color: #16A34A; }
.scheds { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.sched { display: flex; flex-direction: column; }
.sched-top { display: flex; align-items: center; justify-content: space-between; }
.comp-badge { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; color: var(--muted); }
.comp-badge b { width: 28px; height: 28px; border-radius: 9px; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 13px; transition: background .2s; }
.sched-mid { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 28px; transition: opacity .2s; }
.sched-name { font-size: 20px; font-weight: 800; letter-spacing: -.015em; }
.sched-time { margin: 22px 0 26px; font-size: 64px; font-weight: 800; letter-spacing: -.05em; line-height: 1; font-variant-numeric: tabular-nums; transition: opacity .2s; }
.sched.is-off .sched-time, .sched.is-off .sched-mid { opacity: .4; }
.sched.is-off .comp-badge b { background: #C3CAD2; }
.sched .btn { margin-top: auto; }

.switch { position: relative; display: inline-flex; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: relative; width: 48px; height: 28px; border-radius: 999px; background: #D5DAE0; transition: background .2s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(23, 26, 31, .18); transition: transform .2s var(--ease);
}
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 8px; }
.field > label, .field-label { font-size: 14px; font-weight: 700; }
.control { position: relative; display: flex; align-items: center; }
.control > svg.lucide:first-child { position: absolute; left: 16px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.input {
  width: 100%; height: 52px; padding: 0 16px; border: 1.5px solid var(--line); border-radius: 14px;
  background: #fff; font-weight: 600; appearance: none;
  transition: border-color .2s, box-shadow .2s;
}
.input::placeholder { color: #A3A9B1; font-weight: 500; }
.control > svg.lucide:first-child ~ .input { padding-left: 46px; }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px var(--blue-l); }
select.input {
  padding-right: 42px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%23747A84' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 7 4 4 4-4'/%3E%3C/svg%3E") no-repeat right 14px center;
}
.field.has-error .input { border-color: var(--bad); }
.field.has-error .input:focus { box-shadow: 0 0 0 4px var(--bad-l); }
.field-error { color: #DC2626; font-size: 13px; font-weight: 600; }
.input-btn { position: absolute; right: 6px; width: 40px; height: 40px; border: 0; border-radius: 10px; background: none; color: var(--muted); display: grid; place-items: center; }
.input-btn:hover { background: var(--bg); color: var(--ink); }
.input-btn svg.lucide { width: 18px; height: 18px; }

.seg { display: inline-flex; gap: 4px; padding: 4px; background: var(--bg); border-radius: 14px; }
.seg button, .seg label span {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border: 0; border-radius: 10px; background: none;
  font-weight: 700; font-size: 14px; color: var(--muted); white-space: nowrap; cursor: pointer;
  transition: background .2s, color .2s, box-shadow .2s;
}
.seg button:hover, .seg label:hover span { color: var(--ink); }
.seg button[aria-pressed="true"], .seg input:checked + span { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(23, 26, 31, .08); }
.seg label { position: relative; flex: 1; display: flex; }
.seg label span { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; }

/* ---------- Modal ---------- */
.modal {
  width: min(480px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - env(safe-area-inset-top));
  overflow-y: auto; overscroll-behavior: contain; padding: 0; border: 0; border-radius: 28px;
  color: var(--ink); background: #fff; box-shadow: 0 30px 80px -24px rgba(23, 26, 31, .4);
}
.modal::backdrop { background: rgba(23, 26, 31, .34); backdrop-filter: blur(3px); }
.modal[open] { animation: modal-in .22s var(--ease); }
.modal[open]::backdrop { animation: fade .22s ease; }
.modal.closing { animation: modal-out .16s ease forwards; }
.modal.closing::backdrop { animation: fade-out .16s ease forwards; }
.modal form { padding: 28px; display: grid; gap: 20px; }
.modal-head { display: flex; align-items: flex-start; gap: 14px; }
.modal-head h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.modal-head p { color: var(--muted); font-weight: 600; font-size: 14px; margin-top: 2px; }
.modal-head .icon-btn { margin-left: auto; width: 44px; height: 44px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }
.form-alert { display: flex; gap: 8px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--bad-l); color: #B91C1C; font-weight: 600; font-size: 14px; }
.form-alert svg.lucide { width: 18px; height: 18px; }

/* ---------- Riwayat ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px; margin-bottom: 16px; border-radius: 20px; }
.filters .control { width: 210px; }
.filters .input { height: 48px; }
.filters .count { margin-left: auto; padding-right: 8px; color: var(--muted); font-weight: 700; font-size: 14px; }
.reset { display: inline-flex; align-items: center; min-height: 44px; border: 0; background: none; color: var(--blue); font-weight: 700; font-size: 14px; padding: 8px; }

.table-card { padding: 8px 8px 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; min-width: 680px; border-collapse: collapse; }
.table th { text-align: left; padding: 14px 20px; font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); }
.table td { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 600; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: #FAFBFC; }
.c-sched, .c-open { font-variant-numeric: tabular-nums; }
.c-open.none { color: #A3A9B1; }
.slot { font-weight: 800; }
.c-date small { display: block; color: var(--muted); font-size: 13px; font-weight: 500; }

.skel { height: 14px; border-radius: 8px; background: linear-gradient(90deg, var(--soft) 25%, #F7F8FA 50%, var(--soft) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skel-row td { padding: 22px 20px; }
.empty { text-align: center; padding: 56px 16px; }
.empty-icon { width: 28px; height: 28px; color: #A3A9B1; margin: 0 auto 12px; display: block; }
.empty p { font-weight: 800; font-size: 16px; }
.card.empty { padding: 40px 16px; }
.empty small { color: var(--muted); font-weight: 500; font-size: 14px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 24px; bottom: 24px; z-index: 100; display: grid; gap: 10px; justify-items: end; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 14px 18px 14px 14px; border-radius: 16px;
  background: var(--ink); color: #fff; font-weight: 600; font-size: 14px;
  box-shadow: 0 14px 34px -12px rgba(23, 26, 31, .45); animation: toast-in .22s var(--ease);
}
.toast svg.lucide { color: var(--ok); }
.toast.is-error svg.lucide { color: var(--bad); }
.toast.leaving { animation: toast-out .2s ease forwards; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.login-brand {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; gap: 48px;
  padding: 40px 48px 48px; border-radius: 32px; background: var(--blue); color: #fff;
}
.login-brand::after {
  content: ""; position: absolute; right: -180px; top: -180px; width: 520px; height: 520px; border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .12); box-shadow: 0 0 0 80px rgba(255, 255, 255, .03), 0 0 0 160px rgba(255, 255, 255, .025);
  pointer-events: none;
}
.login-brand .brand { font-size: 20px; }
.login-brand h1 { font-size: clamp(34px, 3.6vw, 54px); font-weight: 800; letter-spacing: -.04em; line-height: 1.05; max-width: 560px; }
.login-brand .sub { margin-top: 18px; max-width: 420px; color: rgba(255, 255, 255, .8); font-size: 18px; font-weight: 500; }
.preview { position: relative; z-index: 1; display: grid; gap: 12px; max-width: 440px; }
.pv-card { background: #fff; color: var(--ink); border-radius: 22px; padding: 18px 20px; box-shadow: 0 24px 50px -24px rgba(10, 30, 80, .5); }
.pv-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.pv-head b { font-size: 15px; }
.pv-head small { color: var(--muted); font-weight: 600; font-size: 13px; }
.pv-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.pv-row:nth-child(2) { border-top: 0; }
.pv-time { width: 44px; font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.pv-row p { font-weight: 800; font-size: 14px; line-height: 1.2; }
.pv-row p small { display: block; color: var(--muted); font-weight: 600; font-size: 12px; }
.pv-row .pill { margin-left: auto; }
.pv-chip { justify-self: start; display: inline-flex; align-items: center; gap: 10px; padding: 10px 16px 10px 12px; border-radius: 999px; background: rgba(255, 255, 255, .14); backdrop-filter: blur(8px); font-weight: 700; font-size: 14px; }
.pv-chip .live { width: 9px; height: 9px; box-shadow: 0 0 0 4px rgba(34, 197, 94, .25); }

.login-main { display: grid; place-items: center; padding: 32px 16px; }
.login-main > div { width: min(100%, 440px); }
.login-card { width: 100%; max-width: 440px; padding: 40px; display: grid; gap: 22px; }
.login-card h2 { font-size: 28px; font-weight: 800; letter-spacing: -.03em; }
.login-card .lead { margin-top: 6px; font-size: 15px; }
.hint { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; justify-content: center; }
.hint svg.lucide { width: 16px; height: 16px; }
.login-foot { text-align: center; color: var(--muted); font-size: 13px; font-weight: 500; margin-top: 20px; }

.section-head .link, .card-head .link { min-height: 44px; }
.switch { min-height: 44px; align-items: center; }
.dose-top > div, .sched-mid > :first-child, .kv div, .table tr > *, .track > div { min-width: 0; }
.eyebrow, .dose-comp, .sched-name, .kv dd, .slot, .c-sched, .c-open { overflow-wrap: anywhere; }
.sched-top { gap: 12px; }
.comp-badge { min-width: 0; overflow-wrap: anywhere; }
.sched-mid, .sensor-list div { flex-wrap: wrap; }
.sensor-list div > span { min-width: 0; overflow-wrap: anywhere; }
.sensor-list div > b { margin-left: auto; }
.track b { overflow-wrap: anywhere; }
.stat-num { min-width: 0; flex-wrap: wrap; }
.stat-foot span { overflow-wrap: anywhere; }

/* ---------- Motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes fall { to { opacity: 0; transform: translateY(-4px) scale(.99); } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .45); } 100% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); } }
@keyframes pulse-bad { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .45); } 100% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); } }
@keyframes pulse-blue { 0% { box-shadow: 0 0 0 0 rgba(47, 125, 246, .45); } 100% { box-shadow: 0 0 0 8px rgba(47, 125, 246, 0); } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- Tablet ---------- */
@media (max-width: 1080px) {
  .wrap { padding: 0 24px; }
  .topbar-inner { gap: 12px; }
  .nav a { padding: 0 14px; }
  .user-meta, .user-chip > svg.lucide { display: none; }
  .user-chip { padding: 4px; }
  .split { grid-template-columns: 1fr; }
  .stack { grid-template-columns: 1fr 1fr; align-items: start; }
  .stat-num { font-size: 50px; }
  .stat-word { font-size: 34px; }
  .dose-time { font-size: 46px; }
  .sched-time { font-size: 52px; }
  .login-brand { padding: 32px; }
}
@media (max-width: 900px) {
  .doses, .scheds, .stocks { grid-template-columns: 1fr 1fr; }
  .login { grid-template-columns: 1fr; }
  .preview { display: none; }
  .login-brand { gap: 28px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  body { font-size: 14.5px; }
  .wrap { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .topbar { padding-top: 12px; }
  .topbar-inner { height: 64px; padding: 0 10px; border-radius: 22px; }
  .brand { font-size: 17px; }
  .logo { width: 40px; height: 40px; }
  .nav { display: none; }
  .top-actions { margin-left: auto; padding: 0; border: 0; }
  .icon-btn { width: 44px; height: 44px; }
  .badge-dot { top: 9px; right: 10px; }
  .pop-panel {
    position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); top: 84px; width: auto;
    max-height: calc(100dvh - 100px - env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain;
  }
  .bottom-nav { display: flex; }
  .page { padding-top: 16px; padding-bottom: 128px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
  .page-head > .btn { width: 100%; height: auto; min-height: 48px; padding-block: 12px; white-space: normal; }
  .lead { font-size: 15px; }
  .section, .split { margin-top: 32px; }
  .card { padding: 20px; border-radius: 22px; }

  .summary { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-blue { grid-column: 1 / -1; order: -1; }
  .stat { min-height: 0; gap: 14px; }
  .stat:not(.stat-blue) .stat-head { font-size: 14px; }
  .stat-num { font-size: 44px; }
  .stat-word { font-size: 26px; gap: 10px; }
  .stat-num small { font-size: 13px; }
  .stat-foot { flex-direction: column; align-items: flex-start; gap: 2px; }
  .stat:not(.stat-blue) .stat-chips { display: none; }

  .doses, .scheds, .stocks, .stack { grid-template-columns: 1fr; gap: 12px; }
  .dose-time { font-size: 44px; margin-top: 20px; }
  .section-head .btn-label { display: none; }
  .alert { flex-wrap: wrap; }
  .alert-body { flex: 1; }
  .alert-meta { flex-direction: column; align-items: flex-start; }
  .alert-meta .sep { display: none; }
  .alert .btn { width: 100%; }
  .kv { grid-template-columns: 1fr 1fr; }

  .filters { padding: 12px; }
  .filters .control { width: 100%; }
  .filters .seg { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .seg button { min-width: 0; min-height: 44px; height: auto; padding: 8px; white-space: normal; line-height: 1.2; }
  .filters .count { margin-left: 0; padding-left: 4px; }
  .table-card { background: none; box-shadow: none; padding: 0; overflow: visible; }
  .table { min-width: 0; }
  .table, .table tbody { display: block; }
  .table thead { display: none; }
  .table tbody { display: grid; gap: 12px; }
  .table tr {
    display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "slot status" "date date" "sched open";
    gap: 4px 10px; padding: 16px; border-radius: 20px; background: #fff; box-shadow: var(--shadow);
  }
  .table tbody tr:hover { background: #fff; }
  .table td { padding: 0; border: 0 !important; }
  .table tr.skel-row, .table tr.empty-row { display: block; }
  .skel-row td { display: block; padding: 6px 0; }
  .c-slot { grid-area: slot; }
  .c-status { grid-area: status; justify-self: end; }
  .c-date { grid-area: date; color: var(--muted); font-size: 13px; }
  .c-date small { display: inline; }
  .c-date small::before { content: " · "; }
  .c-sched, .c-open { margin-top: 10px; padding: 10px 12px !important; border-radius: 12px; background: var(--bg); font-weight: 800; }
  .c-sched { grid-area: sched; } .c-open { grid-area: open; }
  .c-sched::before, .c-open::before { content: attr(data-label); display: block; font-size: 12px; font-weight: 600; color: var(--muted); }

  .toasts { left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); bottom: calc(96px + env(safe-area-inset-bottom)); justify-items: stretch; }

  .modal { width: 100%; max-height: calc(100dvh - max(16px, env(safe-area-inset-top))); margin: auto 0 0; border-radius: 28px 28px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .modal[open] { animation: sheet-in .25s var(--ease); }
  .modal.closing { animation: sheet-out .18s ease forwards; }
  .modal form { padding: 24px 20px; }
  .modal-foot .btn { flex: 1; }

  .login { padding: 12px; gap: 12px; }
  .login-brand { padding: 24px; border-radius: 26px; gap: 22px; }
  .login-brand::after { width: 320px; height: 320px; right: -140px; top: -140px; }
  .login-brand h1 { font-size: 30px; }
  .login-brand .sub { font-size: 15px; margin-top: 10px; }
  .login-main { padding: 8px 0 24px; place-items: start center; }
  .login-card { padding: 24px 20px; }
}

@media (max-width: 380px) {
  .summary, .kv, .field-row { grid-template-columns: 1fr; }
  .stat-blue { grid-column: auto; }
  .track { gap: 10px; padding-inline: 12px; }
  .track-line { min-width: 16px; }
  .login-brand { padding: 20px; }
  .login-brand h1 { font-size: 26px; }
  .login-card { padding: 20px 16px; gap: 18px; }
}
