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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* Sentuhan: hilangkan jeda 300ms & zoom dua-ketuk pada kontrol, tanpa mematikan scroll.
   Pinch-zoom tetap dikendalikan lewat meta viewport (dan pengaturan aksesibilitas OS). */
a,
button,
label,
input,
select,
textarea,
summary,
[role='button'] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

ul {
  margin: 0;
  padding-left: 1.15em;
}

a {
  color: var(--primary);
}

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

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) 0;
  text-decoration: none;
}

.skip-link:focus {
  left: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
  text-align: center;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
  filter: brightness(0.96);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn--accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn--ghost {
  background: var(--surface);
  border-color: var(--border-strong);
}

.btn--sm {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 13px;
}

.btn--icon {
  min-height: 44px;
  width: 44px;
  padding: 0;
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn--danger-text {
  color: var(--danger);
}

/* Hover hanya untuk penunjuk presisi — di layar sentuh :hover bisa tertinggal setelah diketuk. */
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) {
    background: var(--border);
  }

  .btn--primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
  }

  .btn--accent:hover:not(:disabled) {
    filter: brightness(1.08);
    background: var(--accent);
  }

  .btn--ghost:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--primary);
  }

  .btn--danger:hover:not(:disabled) {
    filter: brightness(1.06);
    background: var(--danger);
  }

  .btn--danger-text:hover:not(:disabled) {
    border-color: var(--danger);
    background: var(--danger-soft);
  }
}

/* ---------- inputs ---------- */
.input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* 16px minimum untuk layar sentuh: di bawah itu Safari iOS otomatis men-zoom halaman
   saat input difokus. Perangkat desktop (pointer halus, layar lebar) tidak membutuhkannya. */
@media (pointer: coarse), (max-width: 1023.98px) {
  .input {
    font-size: 16px;
  }
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.input:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input[aria-invalid='true'] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}

textarea.input {
  resize: vertical;
  min-height: 62px;
}

select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

@media (hover: hover) and (pointer: fine) {
  .input:hover:not(:disabled) {
    border-color: var(--primary);
  }
}

.input--unit {
  width: 84px;
  min-width: 84px;
  text-align: center;
}

.input--qty {
  width: 64px;
  min-width: 64px;
  text-align: center;
}

input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  opacity: 0.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.field-hint {
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.45;
}

.field-hint--warn {
  color: var(--warning);
  background: var(--warning-soft);
  border-radius: 6px;
  padding: 6px 8px;
}

.field-error {
  font-size: 12.5px;
  color: var(--danger);
  font-weight: 600;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.field-pair--power {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.field-triple {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.unit-slot {
  display: flex;
  align-items: flex-end;
}

.form-status {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.form-status--error {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.form-actions--inline {
  margin-top: 10px;
}

/* ---------- radio / switch ---------- */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.radio-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.radio {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  /* ukuran kontrol diatur width/height; font-size tetap 16px agar iOS tidak men-zoom saat fokus */
  font-size: 16px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13.5px;
}

.switch {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  flex: none;
  font-size: 16px;
}

/* ---------- chips / segmented ---------- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip--active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-3);
  border-radius: 999px;
}

.segmented-btn {
  min-height: 38px;
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.segmented-btn--active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

@media (hover: hover) and (pointer: fine) {
  .radio-label:hover {
    border-color: var(--primary);
  }

  .chip:hover {
    border-color: var(--primary);
    color: var(--primary);
  }
}

/* ---------- toast ---------- */
.toast-stack {
  position: fixed;
  z-index: 90;
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(520px, 100%);
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  pointer-events: auto;
  animation: toast-in 0.18s ease;
}

.toast--success {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
  color: var(--accent);
}

.toast--error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.toast-msg {
  flex: 1;
  min-width: 0;
  font-weight: 550;
}

.toast-action {
  flex: none;
}

.toast-close {
  flex: none;
  width: 40px;
  height: 40px;
  margin: -8px -6px -8px 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.toast--leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- modal ---------- */
.modal {
  width: min(560px, calc(100% - 24px));
  max-height: min(86vh, 780px);
  max-height: min(82dvh, 780px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  overscroll-behavior: contain;
}

.modal--wide {
  width: min(880px, calc(100% - 24px));
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.modal-body {
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 780px);
  max-height: min(82dvh, 780px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 17px;
}

.modal-close {
  flex: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-content {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

@media (hover: hover) and (pointer: fine) {
  .modal-close:hover {
    border-color: var(--danger);
    color: var(--danger);
  }

  .toast-close:hover {
    background: color-mix(in srgb, currentColor 12%, transparent);
  }
}

.modal-close:active:not(:disabled),
.toast-close:active:not(:disabled) {
  background: color-mix(in srgb, currentColor 14%, transparent);
}

/* ---------- misc ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.empty-hint {
  padding: 12px 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: center;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text);
}

.info-bar {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  background: var(--primary-soft);
  color: var(--text);
  font-size: 13.5px;
}

.info-bar svg {
  flex: none;
  color: var(--primary);
  margin-top: 1px;
}

/* ---------- target sentuh pada perangkat layar sentuh / layar sempit ---------- */
@media (pointer: coarse), (max-width: 1023.98px) {
  .btn--sm,
  .segmented-btn {
    min-height: 44px;
  }
}

/* ---------- kunci scroll saat dialog modal terbuka ----------
   Body dibuat position:fixed dengan offset scroll posisi sebelumnya; `overflow: hidden`
   saja masih bisa digeser dengan sentuhan pada Safari iOS. */
html.modal-open {
  overflow: hidden;
  overscroll-behavior: none;
}

html.modal-open body {
  position: fixed;
  left: 0;
  top: var(--modal-lock-offset, 0px);
  width: 100%;
  padding-right: var(--modal-lock-gutter, 0px);
  overflow: hidden;
  overscroll-behavior: none;
}
