:root {
  --sd-bg: #f8fafc;
  --sd-surface: #ffffff;
  --sd-text: #0f172a;
  --sd-muted: #64748b;
  --sd-border: #e2e8f0;
  --sd-teal: #0d9488;
  --sd-teal-dark: #0f766e;
  --sd-warn: #b45309;
  --sd-danger: #b91c1c;
  --sd-ok: #15803d;
  --sd-radius: 14px;
  --sd-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--sd-bg);
  color: var(--sd-text);
  min-height: 100dvh;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

.sd-phone-app {
  max-width: 520px;
  margin: 0 auto;
}

.sd-header {
  background: var(--sd-surface);
  border-bottom: 1px solid var(--sd-border);
  padding: calc(10px + env(safe-area-inset-top, 0)) 16px 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.sd-header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sd-header__title {
  margin: 0;
  flex: 1;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sd-header__identity {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--sd-muted);
  line-height: 1.4;
}

.sd-module {
  padding: 10px 16px 12px;
  background: var(--sd-surface);
  border-bottom: 1px solid var(--sd-border);
  position: sticky;
  top: 64px;
  z-index: 9;
}

.sd-module__row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.sd-module__field {
  flex: 1 1 0;
  min-width: 0;
}

.sd-module__label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sd-muted);
  margin: 0 0 6px;
}

.sd-module__select {
  width: 100%;
  min-height: 40px;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--sd-border);
  border-radius: 12px;
  padding: 8px 36px 8px 10px;
  font-size: 14px;
  font-weight: 650;
  color: var(--sd-text);
  background-color: var(--sd-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%230f766e' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
}

.sd-module-lead {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--sd-muted);
}

.sd-main {
  padding: 12px 16px 88px;
  max-width: 720px;
  margin: 0 auto;
}

.sd-panel[hidden] { display: none !important; }

.sd-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sd-muted {
  color: var(--sd-muted);
  font-size: 13px;
  margin-top: 4px;
}

.sd-card__meta {
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--sd-muted);
  word-break: break-word;
}

.sd-card {
  background: var(--sd-surface);
  border: 1px solid var(--sd-border);
  border-radius: var(--sd-radius);
  box-shadow: var(--sd-shadow);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}

.sd-card:active { transform: scale(0.995); }

.sd-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.sd-card__name {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.sd-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.sd-badge--normal { background: #dcfce7; color: var(--sd-ok); }
.sd-badge--low { background: #fef3c7; color: var(--sd-warn); }
.sd-badge--over { background: #fee2e2; color: var(--sd-danger); }
.sd-badge--due { background: #ffe4e6; color: #be123c; }

.sd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-size: 13px;
}

.sd-grid dt { color: var(--sd-muted); margin: 0; font-weight: 500; }
.sd-grid dd { margin: 2px 0 0; font-weight: 600; }

.sd-banner {
  padding: 12px 14px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 14px;
  margin-bottom: 12px;
}

.sd-banner--deny {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.sd-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--sd-muted);
  font-size: 15px;
  line-height: 1.5;
}

.sd-search-wrap { margin-bottom: 12px; }

.sd-module .sd-search-wrap {
  margin: 10px 0 0;
}

.sd-inv-customer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.sd-search {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--sd-border);
  font-size: 16px;
  background: var(--sd-surface);
}

.sd-btn {
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--sd-border);
  background: var(--sd-surface);
  color: var(--sd-text);
  padding: 8px 14px;
}

.sd-btn--sm { padding: 6px 10px; font-size: 13px; }
.sd-btn--ghost { background: transparent; }
.sd-btn--primary {
  background: linear-gradient(135deg, var(--sd-teal), var(--sd-teal-dark));
  border-color: transparent;
  color: #fff;
}

.sd-detail {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 50;
  display: flex;
  align-items: flex-end;
}

.sd-detail[hidden] { display: none !important; }

.sd-detail__sheet {
  background: var(--sd-surface);
  width: 100%;
  max-height: 92dvh;
  border-radius: 18px 18px 0 0;
  overflow: auto;
  padding: 12px 16px 96px;
}

.sd-detail__title {
  margin: 8px 0 0;
  font-size: 1.1rem;
}

.sd-detail__sub {
  margin: 16px 0 8px;
  font-size: 14px;
  color: var(--sd-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sd-outlet-selected {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--sd-muted);
}

.sd-card--selected {
  border-color: var(--sd-teal);
}

.sd-outlet-slug {
  margin: 0;
  font-size: 13px;
  color: var(--sd-muted);
}

.sd-count-row {
  border: 1px solid var(--sd-border);
  border-radius: var(--sd-radius);
  padding: 12px;
  margin-bottom: 8px;
  background: var(--sd-surface);
}

.sd-count-row label {
  display: block;
  font-size: 12px;
  color: var(--sd-muted);
  margin: 8px 0 4px;
}

.sd-count-row input[type='number'] {
  width: 100%;
  border: 1px solid var(--sd-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
}

.sd-count-meta {
  margin: 0;
  font-size: 13px;
  color: var(--sd-muted);
}

.sd-count-result {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--sd-text);
}

.sd-topup {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--sd-border);
}

.sd-topup[hidden] {
  display: none !important;
}

.sd-topup .sd-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
}

.sd-topup-status {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--sd-ok);
  font-weight: 600;
}


.sd-count-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 8px;
}

.sd-count-actions[hidden] {
  display: none !important;
}

#sd-detail-topup-actions {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0));
  z-index: 30;
  width: min(calc(100% - 32px), 488px);
  transform: translateX(-50%);
  padding: 10px;
  margin: 0;
  background: var(--sd-surface);
  border: 1px solid var(--sd-border);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

#sd-detail-topup-actions .sd-btn {
  width: 100%;
  min-height: 48px;
}

body:has(#sd-detail-topup-actions:not([hidden])) .sd-main {
  padding-bottom: calc(104px + env(safe-area-inset-bottom, 0));
}

body:has(#sd-pwa-bar:not([hidden])) #sd-detail-topup-actions {
  bottom: calc(108px + env(safe-area-inset-bottom, 0));
}

body:has(#sd-pwa-bar:not([hidden])):has(#sd-detail-topup-actions:not([hidden])) .sd-main {
  padding-bottom: calc(200px + env(safe-area-inset-bottom, 0));
}

.sd-count-row__fields--bare {
  margin-top: 8px;
}

.sd-count-help[hidden] {
  display: none !important;
}

.sd-ar-row {
  border: 1px solid var(--sd-border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  font-size: 14px;
}

.sd-ar-row strong { display: block; margin-bottom: 4px; }

.sd-pwa-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0));
  background: var(--sd-surface);
  border: 1px solid var(--sd-border);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  z-index: 40;
}

.sd-phone-app.sd-standalone .sd-pwa-bar {
  display: none !important;
}

.sd-pwa-bar[hidden] { display: none !important; }

.sd-pwa-bar span { flex: 1 1 180px; }

/* FIRST WORKING LAYER V1 — existing customer status only */
.sd-fwl {
  margin: 0 0 12px;
  padding: 12px 14px 14px;
  background: var(--sd-surface);
  border: 1px solid var(--sd-border);
  border-radius: var(--sd-radius);
  box-shadow: var(--sd-shadow);
}
.sd-fwl__title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--sd-text);
  letter-spacing: 0.02em;
}
.sd-fwl__empty {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f1f5f9;
  color: var(--sd-muted);
  font-size: 13px;
}
.sd-fwl .sd-cards {
  margin: 0;
}
.sd-fwl[hidden] {
  display: none !important;
}
.sd-fwl__why {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--sd-text);
  text-align: left;
}
.sd-fwl__next {
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--sd-teal-dark);
  text-align: left;
}
.sd-fwl__card {
  cursor: default;
  text-align: left;
}
.sd-fwl__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.sd-fa-followup__done {
  margin: 6px 0 0;
  font-weight: 700;
  color: var(--sd-teal-dark, #0f766e);
}
.sd-prod-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  background: #e2e8f0;
  flex-shrink: 0;
}
.sd-prod-img--empty {
  background: #f1f5f9;
  border: 1px dashed var(--sd-border);
}
.sd-card--product .sd-card__head {
  align-items: flex-start;
  gap: 10px;
}
.sd-fa-followup__now,
.sd-fa-followup__note {
  margin: 8px 0 0;
}
.sd-fa-followup__note {
  color: var(--sd-muted);
  font-size: 12px;
}
.sd-fa-followup__actions {
  margin-top: 10px;
}

@media (min-width: 768px) {
  .sd-detail { align-items: center; justify-content: center; }
  .sd-detail__sheet {
    max-width: 520px;
    border-radius: 18px;
    max-height: 85vh;
  }
}

.sd-fa-followup {
  margin: 0 16px 12px;
  padding: 12px 14px;
  border: 1px solid #fcd34d;
  border-radius: 12px;
  background: #fffbeb;
  font-size: 13px;
  line-height: 1.45;
  color: #78350f;
}
.sd-fa-followup[hidden] {
  display: none !important;
}
.sd-fa-followup__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #b45309;
  margin-bottom: 6px;
}
