/* =========================================================================
   Time Keeper — tema "ink" (malam) sebagai default, "siang" untuk terik.
   Acara berlangsung 05:00–12:00 di luar ruangan, jadi keterbacaan di bawah
   matahari adalah syarat utama: tipografi besar, kontras tinggi, dan hanya
   warna status (hijau/kuning/merah) yang boleh jenuh.
   ========================================================================= */

:root {
  --bg: #0c0f14;
  --surface: #151a22;
  --surface-2: #1d242e;
  --line: #2a3340;
  --text: #edf2f8;
  --muted: #8593a6;

  --ok: #2ed47a;
  --warn: #ffc53d;
  --over: #ff4f5e;

  --on-primary: #0c0f14;
  --primary: #edf2f8;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;

  --tap: 48px;
  --pad: 16px;
  --tabbar-h: 62px;
  /* Ruang aman bawah yang dipakai tab bar dan elemen mengambang. */
  --pad-bawah: max(8px, calc(env(safe-area-inset-bottom, 0px) - 26px));

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

[data-theme="siang"] {
  --bg: #ffffff;
  --surface: #f0f3f7;
  --surface-2: #e3e8ef;
  --line: #c7d0db;
  --text: #0a0d12;
  --muted: #55627a;

  --ok: #0b8f55;
  --warn: #a36400;
  --over: #c8102e;

  --on-primary: #ffffff;
  --primary: #0a0d12;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------ struktur --- */

.view {
  position: fixed;
  inset: 0;
  bottom: calc(var(--tabbar-h) + var(--pad-bawah));
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.view--full { bottom: 0; z-index: 40; }

.view[hidden] { display: none; }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--pad) 24px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--pad) 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.topbar__clock { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.topbar__clock .eyebrow { width: 100%; margin-bottom: -2px; }
.topbar__clock strong { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.topbar__clock .tz { font-size: 11px; color: var(--muted); font-weight: 600; }

.topbar__title { flex: 1; min-width: 0; }
.topbar__title strong {
  display: block;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.iconbtn {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.iconbtn:active { background: var(--surface-2); }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}
.dot.is-off { background: var(--over); }

/* --------------------------------------------------------------- tabbar -- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  /* Sisakan ruang untuk home indicator, tapi tidak setinggi safe area penuh —
     8px sudah cukup agar label tidak tertimpa, sisanya jadi jarak berlebih. */
  height: calc(var(--tabbar-h) + var(--pad-bawah));
  padding-bottom: var(--pad-bawah);
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* Di mode layar penuh iOS, area di bawah viewport dicat dengan latar halaman —
   warnanya beda dari tab bar sehingga terlihat seperti pita kosong. Pelapis ini
   memanjangkan warna tab bar sampai ke tepi bawah layar. */
.tabbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 100vh;
  background: var(--surface);
  pointer-events: none;
}

.tab {
  border: 0;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.tab span { letter-spacing: 0.01em; }
.tab.is-active { color: var(--text); }

/* ---------------------------------------------------------------- watch -- */

.watch {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 14px;
  min-height: 100%;
}

.sesi-head { text-align: center; }
.sesi-head h1 {
  margin: 2px 0 0;
  font-size: clamp(22px, 6.5vw, 30px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.sesi-head .pic { color: var(--muted); font-size: 14px; font-weight: 600; margin-top: 4px; }

/*  Signature: kartu timer yang seluruh permukaannya ikut warna status,
    dengan meter yang menyusut. Terbaca dari sudut mata.  */
.timer {
  position: relative;
  border-radius: var(--r-lg);
  border: 2px solid var(--tone, var(--line));
  background: var(--surface);
  padding: 22px 16px 18px;
  text-align: center;
  overflow: hidden;
}
.timer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--tone, transparent);
  opacity: 0.1;
  pointer-events: none;
}
.timer.is-over { background: var(--over); border-color: var(--over); }
.timer.is-over::before { opacity: 0; }
.timer.is-over .timer__value,
.timer.is-over .timer__label { color: #fff; }
.timer.is-over .timer__meter { background: rgba(255, 255, 255, 0.25); }

.timer__label {
  position: relative;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.timer__value {
  position: relative;
  display: block;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(58px, 21vw, 104px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 6px 0 12px;
  color: var(--tone, var(--text));
}

.timer.is-over .timer__value { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.timer__meter {
  position: relative;
  height: 6px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.timer__meter i {
  display: block;
  height: 100%;
  background: var(--tone, var(--text));
  transition: width 0.4s linear;
}

.jadwal {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.jadwal div { text-align: center; }
.jadwal b { display: block; font-size: 15px; font-weight: 700; }
.jadwal b.late { color: var(--over); }
.jadwal b.early { color: var(--ok); }

.nextup {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 14px;
}
.nextup b { color: var(--text); font-weight: 700; }
.nextup .spacer { margin-left: auto; font-family: var(--mono); }

.empty {
  margin: 40px 0;
  text-align: center;
  color: var(--muted);
}
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ------------------------------------------------------------ actionbar -- */

.actionbar {
  display: flex;
  gap: 10px;
  padding: 10px var(--pad) 12px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.actionbar:empty { display: none; }

.btn {
  flex: 1;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
}
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.4; }

.btn--primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--over); border-color: var(--over); }
.btn--wide { flex: 2; }

/* -------------------------------------------------------------- rundown -- */

.list { list-style: none; margin: 14px 0 0; padding: 0; }

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--tone, var(--line));
  border-radius: var(--r-md);
  touch-action: pan-y;
}
.row.is-dragging {
  z-index: 5;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  opacity: 0.97;
}
.row.is-armed { border-color: var(--text); }

.row__body { flex: 1; min-width: 0; }
.row__name { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.row__meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row__meta .mono { font-weight: 600; }
.row__note { font-size: 13px; color: var(--muted); margin-top: 4px; font-style: italic; }

.badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 99px;
  border: 1px solid currentColor;
  flex: none;
}
.badge--run { color: var(--ok); }
.badge--pause { color: var(--warn); }
.badge--done { color: var(--muted); }
.badge--late { color: var(--over); }

.handle {
  width: 34px;
  align-self: stretch;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  flex: none;
}
.handle svg { width: 18px; height: 18px; }
.handle.is-locked { opacity: 0.25; cursor: default; }

.listfoot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}
.listfoot .btn { min-height: 48px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; text-align: center; }

/* --------------------------------------------------------------- sheet --- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
}
.sheet[hidden] { display: none; }

.sheet__panel {
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg);
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  border-top: 1px solid var(--line);
  padding: 8px var(--pad) calc(20px + env(safe-area-inset-bottom, 0px));
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0.6; } }

.sheet__head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sheet__head h2 { flex: 1; font-size: 18px; font-weight: 800; margin: 8px 0; }
.sheet__note { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.sheet__foot { display: flex; gap: 10px; margin-top: 16px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field > span em { font-style: normal; font-weight: 500; }
.field input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.field input:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.code {
  width: 100%;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

.msg {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  border: 1px solid var(--over);
  color: var(--over);
}
.msg.is-ok { border-color: var(--ok); color: var(--ok); }
.msg ul { margin: 4px 0 0; padding-left: 18px; }

/* -------------------------------------------------------------- report --- */

.rsection { margin-top: 22px; }
.rsection > h3 {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
}
.card span { display: block; font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.card b { display: block; font-size: 20px; font-weight: 800; margin-top: 4px; font-family: var(--mono); }
.card b.late { color: var(--over); }
.card b.early { color: var(--ok); }

.runrow {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.runrow__no {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding-top: 2px;
  flex: none;
}
.runrow__body { flex: 1; min-width: 0; }
.runrow__name { font-weight: 700; font-size: 15px; }
.runrow__line { font-size: 13px; color: var(--muted); margin-top: 3px; font-family: var(--mono); }
.runrow__delta { font-size: 13px; font-weight: 700; margin-top: 4px; }
.runrow__delta.late { color: var(--over); }
.runrow__delta.early { color: var(--ok); }
.tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--warn);
  border: 1px solid currentColor;
  border-radius: 99px;
  padding: 1px 6px;
  margin-left: 6px;
}

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { font-size: 13px; }
.bar__top { display: flex; justify-content: space-between; gap: 10px; }
.bar__top b { font-family: var(--mono); font-weight: 700; }
.bar__top b.late { color: var(--over); }
.bar__top b.early { color: var(--ok); }
.bar__track { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--over); }
.bar__fill.early { background: var(--ok); }

/* --------------------------------------------------------------- toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 18px + var(--pad-bawah));
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.toast[hidden] { display: none; }
.toast.is-bad { border-color: var(--over); color: var(--over); }

/* ------------------------------------------------------------ a11y/motion */

:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (min-width: 640px) {
  .view, .tabbar, .toast { max-width: 520px; margin-inline: auto; }
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); width: 100%; }
}
