/* =====================================================================
   Mobile & portrait-tablet layout  —  loaded only when (max-width: 899px)
   One screen at a time, switched by a bottom tab bar (thumb zone):
   Ringkasan · Kalender · Agenda. Natural vertical scrolling replaces the
   desktop's fit-to-viewport paging. Touch targets ≥ 44px.
   ===================================================================== */

html, body { height: auto; }
body {
  min-width: 0; min-height: 100dvh; display: block; overflow-x: hidden;
  font-size: var(--fs-md);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- top bar: compact, sticky ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
}
.brand { gap: 10px; }
.brand-mark { width: 36px; height: 36px; }
.brand h1 { font-size: 1.0625rem; }
.today-pill { display: none; }
.theme-btn { width: 44px; height: 44px; }

/* ---------- page + tab switching ---------- */
.layout {
  display: block; padding: 12px max(12px, env(safe-area-inset-right)) 16px max(12px, env(safe-area-inset-left));
}
body[data-mtab="ringkasan"] .main { display: none; }
body:not([data-mtab="ringkasan"]) .side { display: none; }

/* ---------- Ringkasan ---------- */
.side { overflow: visible; gap: 12px; }
.hero { padding: 16px; column-gap: 16px; }
.hero-num { font-size: 2.5rem; min-width: 72px; }
.hero-title { -webkit-line-clamp: 3; }
.side .panel { flex: none; padding: 14px 12px; }
.side .ev-list { overflow: visible; gap: 2px; }
.pager { display: none; }
.side-row { height: auto; min-height: 56px; padding: 8px 6px; align-items: center; }
.sr-title {
  white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  font-size: var(--fs-md); line-height: 1.35;
}
.sr-meta { margin-top: 2px; }

/* ---------- toolbar (Kalender / Agenda) ---------- */
.main { padding: 12px; overflow: visible; }
.toolbar { flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.month-nav { width: 100%; gap: 6px; }
.month-nav h2 { flex: 1; min-width: 0; font-size: 1.125rem; text-align: center; }
.icon-btn { width: 44px; height: 44px; font-size: 22px; }
#go-today { min-height: 44px; order: 4; }
body[data-mtab="agenda"] .month-nav { display: none; }
.tool-right { width: 100%; }
.seg { display: none; }                          /* the tab bar replaces it */
.filter-wrap { flex: 1; }
.filter-btn { width: 100%; min-height: 44px; justify-content: flex-start; }
.fb-count { margin-left: auto; }

/* filter = bottom sheet */
.filter-pop {
  position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 60;
  width: auto; max-height: 78dvh; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 18px 18px 0 0; border-bottom: 0;
  padding: 22px 16px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 0 0 100vmax var(--backdrop), var(--shadow-pop);
}
.filter-pop::before {
  content: ""; display: block; width: 40px; height: 4px; border-radius: 4px;
  background: var(--line); margin: -8px auto 16px;
}
.filter-pop .eyebrow .muted { display: none; }   /* Ctrl+klik hint is meaningless on touch */
.chip { min-height: 40px; padding: 8px 14px; font-size: var(--fs-md); }
.legend { gap: 10px 18px; }

/* ---------- month grid: day number + category dots ---------- */
#view-calendar { display: block; }
.cal-head { padding-bottom: 8px; }
.cal-head span { padding: 0; text-align: center; }
.cal-body { grid-template-rows: none !important; grid-auto-rows: 58px; border-radius: 12px; }
.cell { padding: 6px 2px; gap: 5px; align-items: center; cursor: pointer; }
.cell.has-ev:hover { background: var(--surface); }
.cell.weekend:hover { background: color-mix(in oklch, var(--surface-2) 60%, var(--surface)); }
.cell-top { justify-content: center; min-height: 28px; }
.num { width: 28px; height: 28px; font-size: var(--fs-sm); }
.cell.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.cell.sel:not(.today) .num { color: var(--accent); }
.hol-tag, .hol-full, .cell-top .more { display: none; }
.cell.holiday .num { color: var(--hol-text); }

.cell-evs {
  flex: none; flex-direction: row; flex-wrap: wrap; justify-content: center;
  gap: 3px; max-width: 34px; max-height: 17px; overflow: hidden;
}
.ev {
  width: 7px; height: 7px; padding: 0; border: 0; border-radius: 50%;
  font-size: 0; pointer-events: none; background: var(--c);
}
.ev-ajuan, .ev-lain { background: var(--c); }
.ev-sp2d, .ev-mulai { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.ev.past { background: var(--text-faint); box-shadow: none; opacity: .5; }

/* tapped day's agenda, under the grid */
.day-panel { display: block; margin-top: 16px; scroll-margin-top: 80px; }
.dp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.dp-head h3 { font-size: var(--fs-lg); }
.dp-hol {
  margin: 0 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--hol-bg);
  color: var(--hol-text); font-weight: var(--fw-label); line-height: 1.4;
}
.dp-hol small { display: block; font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em; font-weight: var(--fw-strong); opacity: .85; }
.day-panel .empty { padding: 14px 4px; }

/* ---------- agenda: stacked rows, full titles ---------- */
.agenda { display: block; }
.agenda-bar { flex-wrap: wrap; row-gap: 6px; }
.agenda-bar label { min-height: 44px; }
.ag-rows { overflow: visible; gap: 8px; }
.ag-row { padding: 14px 16px; align-items: flex-start; }
.ag-row.with-date { display: flex; flex-direction: column; align-items: stretch; height: auto; gap: 8px; }
.ag-date {
  flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  height: auto; padding: 0 0 8px; border-right: 0; border-bottom: 1px solid var(--line-soft);
}
.ag-rows li.cont .ag-date { display: none; }
.ag-title { white-space: normal; line-height: 1.35; }
.ag-meta { white-space: normal; }

/* ---------- details = bottom sheet ---------- */
.dlg {
  width: 100%; max-width: 100%; margin: auto 0 0; max-height: 88dvh;
  border-radius: 20px 20px 0 0; border-bottom: 0;
  padding: 26px 18px calc(22px + env(safe-area-inset-bottom));
}
.dlg::before {
  content: ""; position: absolute; top: 9px; left: 50%; translate: -50% 0;
  width: 40px; height: 4px; border-radius: 4px; background: var(--line);
}
.dlg-close button { width: 40px; height: 40px; }
.dlg h2 { font-size: 1.125rem; }
.det-grid { grid-template-columns: 1fr; }
@media (prefers-reduced-motion: no-preference) {
  .dlg[open] { animation: sheet-up .28s cubic-bezier(.22, 1, .36, 1); }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---------- footer + tab bar ---------- */
.foot {
  flex-direction: column; gap: 4px;
  padding: 4px max(16px, env(safe-area-inset-left)) calc(84px + env(safe-area-inset-bottom));
}
.foot span:last-child { text-align: left; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: var(--surface); border-top: 1px solid var(--line-soft);
}
.tabbar button {
  min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; border-radius: 12px; color: var(--text-faint);
  font-size: var(--fs-cap); font-weight: var(--fw-label);
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar button[aria-selected="true"] { color: var(--accent); }
.tabbar button[aria-selected="true"] svg { background: var(--accent-bg); border-radius: 10px; padding: 2px 10px; width: 46px; height: 26px; box-sizing: border-box; }
.tabbar button:active { background: var(--surface-2); }

/* ---------- holiday editor ---------- */
.editor .topbar { flex-wrap: wrap; row-gap: 10px; }
.editor .top-actions { width: 100%; justify-content: flex-end; }
.editor .save-state { margin-right: auto; }
.editor .top-actions .btn { min-height: 44px; }
.editor .ed-main {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px max(12px, env(safe-area-inset-right)) 16px max(12px, env(safe-area-inset-left));
}
.ed-card { padding: 12px; }
.ed-toolbar { flex-wrap: wrap; }
.ed-toolbar .seg-btn { min-height: 40px; }
.ed-toolbar .seg { display: inline-flex; }
#btn-add { min-height: 44px; }
.ed-head { display: none; }
.ed-rows { overflow: visible; gap: 10px; }
.ed-row {
  height: auto; padding: 12px; gap: 8px 10px;
  grid-template-columns: minmax(0, 1fr) auto 44px;
  grid-template-areas: "date day del" "name name name" "type type type" "err err err";
}
.ed-row input[type=date] { grid-area: date; min-height: 44px; }
.ed-row .ed-day { grid-area: day; text-align: right; }
.ed-row .del { grid-area: del; width: 44px; height: 44px; }
.ed-row input[data-f=name] { grid-area: name; min-height: 44px; }
.ed-row select { grid-area: type; min-height: 44px; }
.ed-err { grid-area: err; position: static; }
.ed-row input, .ed-row select, .fld input, .fld textarea { font-size: 16px; }   /* no iOS zoom-on-focus */
.ed-side .toast { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 50; }
.editor .foot { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

/* legend mirrors the mobile dots: filled = pengajuan/lainnya, ring = SP2D/mulai */
.legend .k { width: 10px; height: 10px; border-radius: 50%; border: 0; background: none; }
.legend .k-ajuan, .legend .k-lain { background: var(--text-soft); }
.legend .k-sp2d { box-shadow: inset 0 0 0 1.5px var(--text-soft); }
.legend .k-mulai { box-shadow: inset 0 0 0 1.5px var(--text-faint); }
.legend .k-hol { width: 14px; border-radius: 4px; background: var(--hol-bg); box-shadow: inset 0 0 0 1px var(--hol-text); }

body:not([data-mtab="calendar"]) .day-panel { display: none; }
.ag-row.with-date .ag-date { justify-content: flex-start; }

/* long subtitles wrap instead of widening the page */
.brand { min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.sub { white-space: normal; }
.editor .top-actions { flex-wrap: wrap; row-gap: 8px; }
.editor .top-actions .btn { white-space: nowrap; }
.editor .save-state { order: -1; flex-basis: 100%; margin: 0; padding-left: 0; background: none; }

/* portrait tablets: same pattern, more room */
@media (min-width: 600px) {
  .cal-body { grid-auto-rows: 76px; }
  .cell-evs { max-width: 60px; max-height: 26px; gap: 4px; }
  .ev { width: 8px; height: 8px; }
  .layout { padding-left: 20px; padding-right: 20px; }
}

/* phones in landscape: give the height back to content */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { position: static; }
  .tabbar { padding-top: 2px; padding-bottom: calc(2px + env(safe-area-inset-bottom)); }
  .tabbar button { flex-direction: row; gap: 8px; min-height: 44px; }
  .tabbar button[aria-selected="true"] svg { padding: 1px 8px; width: 40px; height: 24px; }
  .foot { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* search: full-width row under the title */
.topbar { flex-wrap: wrap; row-gap: 10px; }
.search { order: 3; flex: 1 1 100%; height: 44px; }
.search input { font-size: 16px; }          /* no iOS zoom-on-focus */
.search kbd { display: none; }
