:root {
  --color-primary: #0f766e;
  --color-primary-dark: #0b5a54;
  --color-primary-light: #ccfbf1;
  --color-bg: #f4f6f7;
  --color-surface: #ffffff;
  --color-text: #1b2528;
  --color-text-muted: #6b7680;
  --color-border: #e2e6e8;
  --color-warn: #b45309;
  --color-warn-bg: #fef3c7;
  --color-danger: #b91c1c;
  --color-danger-bg: #fee2e2;
  --color-ok: #15803d;
  --color-ok-bg: #dcfce7;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.18);
  --radius: 12px;
  --topbar-h: 56px;
  --bottomnav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-primary: #2dd4bf;
    --color-primary-dark: #14b8a6;
    --color-primary-light: #134e4a;
    --color-bg: #14181a;
    --color-surface: #1f2426;
    --color-text: #eef2f3;
    --color-text-muted: #9aa5ac;
    --color-border: #313a3d;
    --color-warn: #fbbf24;
    --color-warn-bg: #3a2e0e;
    --color-danger: #f87171;
    --color-danger-bg: #3a1414;
    --color-ok: #4ade80;
    --color-ok-bg: #123321;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  --color-primary: #2dd4bf;
  --color-primary-dark: #14b8a6;
  --color-primary-light: #134e4a;
  --color-bg: #14181a;
  --color-surface: #1f2426;
  --color-text: #eef2f3;
  --color-text-muted: #9aa5ac;
  --color-border: #313a3d;
  --color-warn: #fbbf24;
  --color-warn-bg: #3a2e0e;
  --color-danger: #f87171;
  --color-danger-bg: #3a1414;
  --color-ok: #4ade80;
  --color-ok-bg: #123321;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* Utilitas umum - !important supaya selalu menang atas display rule spesifik-elemen
   manapun (mis. .field { display:flex }), sesuai maksud kelas "hidden": selalu sembunyi. */
.hidden { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font-family: inherit; font-size: 16px; color: inherit; }
button { cursor: pointer; }
h3 { margin: 0; font-size: 15px; font-weight: 700; }

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  padding-top: env(safe-area-inset-top);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 8px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.net-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  white-space: nowrap;
}
.net-badge.online { background: rgba(255,255,255,0.25); }
.net-badge.online::before { content: "● "; color: #86efac; }
.net-badge.offline::before { content: "● "; color: #fca5a5; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.auth-badge {
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
}
.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: rgba(0,0,0,0.08); }

/* Sync banner */
.sync-banner {
  background: var(--color-warn-bg);
  color: var(--color-warn);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sync-banner.hidden { display: none; }
.sync-banner button {
  background: var(--color-warn);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 12px;
}

/* Main / views */
main#views { flex: 1; overflow-y: auto; padding-bottom: calc(var(--bottomnav-h) + 16px); }
.view { display: none; padding: 12px 14px 24px; }
.view.active { display: block; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  z-index: 20;
}
.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
}
.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--color-primary); }

/* Form fields */
.entry-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--color-text-muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type="text"], input[type="date"], input[type="number"], input[type="url"], select, textarea {
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 46px;
  width: 100%;
}
textarea { min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); }

.picker-btn {
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  width: 100%;
}
.picker-btn .placeholder { color: var(--color-text-muted); }
.picker-btn .chev { color: var(--color-text-muted); font-size: 12px; }
.picker-btn.filled span:first-child { font-weight: 600; }

.readonly-field .readonly-value {
  padding: 11px 12px;
  min-height: 46px;
  display: flex;
  align-items: center;
  background: var(--color-bg);
  border-radius: 10px;
  font-weight: 700;
  color: var(--color-primary);
}

/* Usage banner */
.usage-banner { background: var(--color-surface); border: 1.5px solid var(--color-border); border-radius: 10px; padding: 10px 12px; }
.usage-banner.hidden { display: none; }
.usage-row { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.usage-row span:first-child { color: var(--color-text-muted); }
.usage-bar { height: 8px; border-radius: 999px; background: var(--color-bg); overflow: hidden; }
.usage-bar-fill { height: 100%; background: var(--color-ok); border-radius: 999px; transition: width .2s; }
.usage-banner.warn .usage-bar-fill { background: var(--color-warn); }
.usage-banner.over .usage-bar-fill { background: var(--color-danger); }
.usage-banner.warn .usage-row span:first-child { color: var(--color-warn); }
.usage-banner.over .usage-row span:first-child { color: var(--color-danger); }

/* Materials */
.materials-section { border: 1.5px solid var(--color-border); border-radius: 10px; padding: 10px 12px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.link-btn { background: transparent; border: none; color: var(--color-primary); font-weight: 700; font-size: 13px; padding: 4px; }
.material-row { display: grid; grid-template-columns: 1fr 72px 60px 30px; gap: 6px; align-items: center; margin-bottom: 8px; }
.material-row .picker-btn { min-height: 42px; padding: 8px 10px; font-size: 14px; }
.material-row input { min-height: 42px; padding: 8px; text-align: center; }
.material-qtyha { font-size: 11px; color: var(--color-text-muted); text-align: center; }
.material-remove { background: var(--color-danger-bg); color: var(--color-danger); border: none; border-radius: 8px; height: 42px; font-weight: 700; }
.materials-empty { color: var(--color-text-muted); font-size: 13px; padding: 6px 2px; }

/* Buttons */
.btn-block { width: 100%; }
.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-weight: 700;
  font-size: 15px;
  min-height: 48px;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:active { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn-danger { background: var(--color-danger); color: #fff; }
.monitoring-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }

/* Today / history list */
.today-list-section, .monitoring-summary, .usage-table { margin-top: 18px; }
.entry-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.entry-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 10px 12px;
}
.entry-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.entry-card-title { font-weight: 700; font-size: 14px; }
.entry-card-sub { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }
.entry-card-meta { font-size: 12px; color: var(--color-text-muted); margin-top: 6px; }
.entry-card-actions { display: flex; gap: 8px; margin-top: 8px; }
.entry-card-actions button {
  flex: 1;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  padding: 7px;
  font-size: 12.5px;
  font-weight: 600;
}
.entry-card-actions .del-btn { color: var(--color-danger); }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--color-primary-light); color: var(--color-primary-dark); font-size: 11px; font-weight: 700; }
.status-pill { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.status-pill.synced { background: var(--color-ok-bg); color: var(--color-ok); }
.status-pill.pending { background: var(--color-warn-bg); color: var(--color-warn); }
.status-pill.error { background: var(--color-danger-bg); color: var(--color-danger); }
.status-pill.pending-delete { background: var(--color-danger-bg); color: var(--color-danger); }

/* Monitoring stat cards */
.monitoring-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 10px; padding: 12px 6px; text-align: center; }
.stat-card .stat-value { font-size: 22px; font-weight: 800; }
.stat-card .stat-label { font-size: 11px; color: var(--color-text-muted); font-weight: 600; margin-top: 2px; }
.stat-card.warn .stat-value { color: var(--color-warn); }
.stat-card.danger .stat-value { color: var(--color-danger); }

.muted-text { font-size: 12.5px; color: var(--color-text-muted); margin-top: 6px; }
.filter-date { max-width: 160px; min-height: 36px; padding: 6px 8px; }

.usage-table { display: flex; flex-direction: column; gap: 8px; }
.usage-item { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 10px; padding: 10px 12px; }
.usage-item-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; }
.usage-item-sub { font-size: 11.5px; color: var(--color-text-muted); margin-bottom: 6px; }
.empty-state { text-align: center; color: var(--color-text-muted); font-size: 13px; padding: 24px 8px; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; z-index: 100;
}
.overlay.hidden { display: none; }
.picker-sheet, .sheet {
  background: var(--color-surface);
  width: 100%;
  max-height: 86vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.small { max-height: unset; }
.picker-header, .sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px;
}
.picker-title, .sheet-header h3 { font-weight: 700; font-size: 16px; }
.picker-search {
  margin: 8px 16px; width: calc(100% - 32px);
}
.picker-list { overflow-y: auto; padding: 4px 8px 16px; }
.picker-row {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--color-border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.picker-row:active { background: var(--color-bg); }
.picker-row-title { font-weight: 600; font-size: 14.5px; }
.picker-row-sub { font-size: 12px; color: var(--color-text-muted); }
.picker-empty { text-align: center; padding: 32px 16px; color: var(--color-text-muted); }

.sheet-body { padding: 8px 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sheet-body hr { border: none; border-top: 1px solid var(--color-border); margin: 4px 0; }
.app-version { text-align: center; margin-top: 8px; }

.confirm-icon { font-size: 36px; text-align: center; margin-top: 6px; }
.confirm-message { text-align: center; font-size: 14.5px; padding: 4px 8px 14px; white-space: pre-line; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.auth-body { align-items: center; text-align: center; padding-bottom: 24px; }
.auth-title { margin: 4px 0 2px; }
.auth-desc { margin: 0 0 10px; }
.auth-password-input { text-align: center; letter-spacing: 2px; }
.auth-error { color: var(--color-danger); min-height: 16px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1b2528;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
.toast.hidden { display: none; }
.toast.error { background: var(--color-danger); }
.toast.success { background: var(--color-ok); }

@media (min-width: 640px) {
  main#views { max-width: 560px; margin: 0 auto; width: 100%; }
  .bottom-nav { max-width: 560px; margin: 0 auto; }
  .picker-sheet, .sheet { max-width: 560px; margin: 0 auto; border-radius: 16px; margin-bottom: 24px; }
  .overlay { align-items: center; }
}
