/* TERNAQU — Smart Livestock Monitoring • Developed by DG © 2026 */
:root {
  --bg: #FFFFFF; --cream: #FFF8EA; --cream-2: #FBF1DC; --mint: #EEF7E9; --mint-2: #DDEFD4;
  --green: #2F7D3A; --green-2: #5DAE5B; --leaf: #8CC66B;
  --text: #1F2A21; --muted: #6B7B6E; --line: #E4EADF;
  --warn: #B7791F; --warn-bg: #FFF3CD; --bad: #C2392F; --bad-bg: #FDE2E0; --ok-bg: #E3F3DD; --idle-bg: #F1F3EF;
  --r: 14px; --r-sm: 10px; --shadow: 0 1px 2px rgba(31,42,33,.06), 0 4px 14px rgba(31,42,33,.05);
  --nav-h: 64px; --top-h: 58px;
  --font: "Plus Jakarta Sans", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; min-height: 100vh; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.08rem; } h3 { font-size: .98rem; }
.muted { color: var(--muted); } .small { font-size: .84rem; } .num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* Splash */
.splash { position: fixed; inset: 0; z-index: 100; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; transition: opacity .3s; }
.splash strong { font-size: 1.8rem; color: var(--green); letter-spacing: .04em; margin-top: 10px; }
.splash span { color: var(--muted); } .splash small { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); color: var(--muted); }
.splash.gone { opacity: 0; pointer-events: none; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(255,255,255,.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; min-width: 0; }
.brand span { display: flex; flex-direction: column; min-width: 0; }
.brand b { color: var(--green); letter-spacing: .05em; font-size: 1.05rem; }
.brand small { color: var(--muted); font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.sync-chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: .8rem; cursor: pointer; white-space: nowrap; }
.sync-chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-chip em { font-style: normal; background: var(--warn-bg); color: var(--warn); border-radius: 999px; padding: 0 7px; font-weight: 700; }
.sync-chip[data-state="ok"] i { background: var(--green-2); }
.sync-chip[data-state="syncing"] i { background: var(--green-2); animation: pulse 1s infinite; }
.sync-chip[data-state="offline"] i { background: var(--warn); }
.sync-chip[data-state="error"] i { background: var(--bad); }
.sync-chip[data-state="checking"] i { background: #9BA79D; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* Layout */
.view { padding: 16px max(16px, env(safe-area-inset-right)) calc(var(--nav-h) + 56px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); width: 100%; outline: none; }
.credit { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); text-align: center; font-size: .7rem; color: var(--muted); padding: 3px; background: rgba(255,255,255,.9); pointer-events: none; }
.nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(6, 1fr); background: #fff; border-top: 1px solid var(--line); }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: .66rem; font-weight: 600; min-width: 0; }
.nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.nav svg { width: 22px; height: 22px; fill: currentColor; }
.nav a.active { color: var(--green); }
.nav a.active svg { background: var(--mint); border-radius: 10px; padding: 2px; width: 30px; height: 26px; }
@media (min-width: 900px) {
  :root { --nav-h: 0px; }
  .nav { top: calc(var(--top-h) + env(safe-area-inset-top)); bottom: 0; right: auto; width: 220px; height: auto; display: flex; flex-direction: column; padding: 14px 10px; gap: 4px; border-top: 0; border-right: 1px solid var(--line); }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: .92rem; padding: 10px 12px; border-radius: 10px; }
  .nav a.active { background: var(--mint); }
  .nav a.active svg { background: none; padding: 0; width: 22px; height: 22px; }
  .view { padding-left: 244px; padding-bottom: 48px; }
  .credit { left: 220px; bottom: 0; }
}
@media (max-height: 480px) and (orientation: landscape) { :root { --nav-h: 50px; --top-h: 48px; } .nav a span { font-size: .6rem; } .credit { display: none; } }

/* Components */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card.cream { background: var(--cream); border-color: var(--cream-2); }
.card.mint { background: var(--mint); border-color: var(--mint-2); }
.kpi .lbl { color: var(--muted); font-size: .8rem; font-weight: 600; }
.kpi .val { font-size: clamp(1.05rem, 4.4vw, 1.45rem); font-weight: 800; color: var(--green); margin-top: 4px; font-variant-numeric: tabular-nums; word-break: break-word; }
.kpi .val.neg { color: var(--bad); }
.kpi .sub { font-size: .76rem; color: var(--muted); margin-top: 2px; }
.section { margin: 22px 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--idle-bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--green); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--cream); color: #8B6B43; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--green); background: var(--green); color: #fff; border-radius: 12px; padding: 10px 16px; font-weight: 700; cursor: pointer; min-height: 44px; text-decoration: none; }
.btn.ghost { background: #fff; color: var(--green); }
.btn.soft { background: var(--mint); color: var(--green); border-color: var(--mint-2); }
.btn.danger { background: #fff; color: var(--bad); border-color: #F0B7B2; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .84rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.fab { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(var(--nav-h) + 30px + env(safe-area-inset-bottom)); z-index: 15; border-radius: 999px; box-shadow: 0 6px 18px rgba(47,125,58,.35); padding: 12px 20px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; cursor: pointer; text-align: left; width: 100%; }
.item:hover { border-color: var(--green-2); }
.item .t { font-weight: 700; } .item .s { color: var(--muted); font-size: .82rem; }
.item .r { text-align: right; flex: none; }
.item.deleted { opacity: .55; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--r); background: #FCFDFB; }
.empty img { width: 64px; opacity: .8; }
.alert { border-radius: var(--r-sm); padding: 10px 12px; font-size: .86rem; border: 1px solid; }
.alert.warn { background: var(--warn-bg); border-color: #F5DE9B; color: #7A5410; }
.alert.bad { background: var(--bad-bg); border-color: #F3B9B4; color: #8A2620; }
.alert.ok { background: var(--ok-bg); border-color: var(--mint-2); color: #245F2D; }
.alert.info { background: var(--cream); border-color: var(--cream-2); color: #6A5532; }
.ind { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 104px), 1fr)); gap: 8px; margin-top: 10px; }
.ind div { background: var(--mint); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.ind b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.ind span { font-size: .72rem; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 10px; fill: var(--muted); font-family: var(--font); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: .84rem; cursor: pointer; }
.tabs button.on { background: var(--green); color: #fff; border-color: var(--green); }
.filters { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); margin-bottom: 12px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .84rem; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 700; font-size: .76rem; }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

/* Forms */
.form { display: grid; gap: 12px; }
.form .two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; }
/* Label sebagai blok biasa: teks label + keterangan kecil tetap satu baris */
label.f { display: block; font-size: .82rem; font-weight: 700; color: #3A483C; min-width: 0; line-height: 1.3; }
label.f small { font-weight: 500; color: var(--muted); }
label.f > .in, label.f > select, label.f > textarea, label.f > input { display: block; margin-top: 6px; }
label.f > .with-add { margin-top: 6px; }
/* Tombol tambah pilihan: kecil, seperti tautan, tidak memenuhi lebar */
[data-addopt] { display: inline-flex !important; background: none !important; border: 0 !important; color: var(--green) !important; padding: 6px 0 0 !important; min-height: 0 !important; font-size: .78rem !important; font-weight: 700; box-shadow: none !important; width: auto !important; }
/* Safari iPhone: input tanggal jangan melebar keluar kolom */
input[type="date"].in { -webkit-appearance: none; appearance: none; display: block; width: 100%; min-width: 0; max-width: 100%; text-align: left; line-height: 1.2; }
input[type="date"].in::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"].in::-webkit-datetime-edit { padding: 0; }
.form .two > * { min-width: 0; }
.in, select.in, textarea.in { width: 100%; border: 1px solid #D5DECF; background: #fff; border-radius: 10px; padding: 10px 12px; min-height: 44px; font-size: 16px; font-weight: 500; }
textarea.in { min-height: 70px; resize: vertical; }
.in:focus { outline: 2px solid var(--leaf); outline-offset: 1px; border-color: var(--green-2); }
.with-add { display: flex; gap: 6px; }
.with-add select { flex: 1; min-width: 0; }
.with-add .btn { flex: none; padding: 0 12px; }
details.opt { border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; background: #FCFDFB; }
details.opt summary { cursor: pointer; font-weight: 700; color: var(--green); font-size: .86rem; }
details.opt[open] summary { margin-bottom: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid #D5DECF; border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 10px; font-weight: 700; cursor: pointer; }
.seg button.on.in-c { background: var(--ok-bg); color: var(--green); }
.seg button.on.out-c { background: var(--bad-bg); color: var(--bad); }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.check input { width: 20px; height: 20px; flex: none; accent-color: var(--green); margin-top: 1px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(31,42,33,.35); display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: #fff; width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px max(16px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); -webkit-overflow-scrolling: touch; }
@media (min-width: 700px) { .modal { align-items: center; } .modal .sheet { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.x { border: 0; background: var(--idle-bg); width: 36px; height: 36px; border-radius: 50%; font-size: 1.1rem; cursor: pointer; flex: none; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--top-h) + 10px + env(safe-area-inset-top)); z-index: 60; background: #1F2A21; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .88rem; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); }
.toast { pointer-events: none; } .toast button { pointer-events: auto; }

/* Wizard & login */
.center-wrap { min-height: calc(100vh - 200px); display: flex; align-items: center; justify-content: center; }
.hero { max-width: 480px; width: 100%; text-align: center; }
.hero img.logo { width: 96px; height: 96px; }
.steps { display: flex; gap: 6px; justify-content: center; margin: 10px 0 18px; }
.steps i { width: 34px; height: 6px; border-radius: 6px; background: var(--line); }
.steps i.on { background: var(--green-2); }
.wizard { text-align: left; }
.pill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); gap: 8px; }
.pill-grid button { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px; font-weight: 700; cursor: pointer; text-align: left; }
.pill-grid button.on { border-color: var(--green); background: var(--mint); color: var(--green); }
#gbtn { display: flex; justify-content: center; min-height: 44px; }

@media print { .nav, .topbar, .fab, .credit { display: none; } .view { padding: 0; } }
