/* =============================================
   SARI-SARI LEDGER — Main Stylesheet
   ============================================= */

:root {
  --red:     #E63946;
  --amber:   #F4A261;
  --cream:   #FFF8F0;
  --white:   #FFFFFF;
  --dark:    #2D2D2D;
  --gray:    #6B7280;
  --light:   #F3F4F6;
  --green:   #22C55E;
  --yellow:  #EAB308;
  --shadow:  0 2px 12px rgba(0,0,0,0.10);
  --radius:  14px;
  --nav-h:   64px;
  --header-h:60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--cream);
  color: var(--dark);
  overflow: hidden;
}

/* ── App Shell ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── Header ── */
#header {
  background: var(--red);
  color: var(--white);
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 10;
}
#header h1 {
  font-size: 20px;
  font-weight: 700;
  flex: 1;
}
#header .kita-bar {
  font-size: 15px;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
  padding: 4px 10px;
  border-radius: 20px;
}
#btn-summary {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Screen Container ── */
#screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

/* ── Bottom Nav ── */
#nav {
  display: flex;
  background: var(--white);
  border-top: 1px solid #E5E7EB;
  height: var(--nav-h);
  flex-shrink: 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.07);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--gray);
  font-size: 11px;
  font-weight: 600;
  transition: color 0.15s;
  padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn .icon { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--red); }
.nav-btn.active .icon { transform: scale(1.1); }

/* ── SELL SCREEN ── */
.screen-sell { padding: 12px; }

.sell-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.product-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 100px;
  cursor: pointer;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.15s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
}
.product-card:active { transform: scale(0.95); border-color: var(--red); }
.product-card.low-stock { border-color: var(--yellow); }
.product-card.out-stock { border-color: #EF4444; opacity: 0.6; }

.product-card .p-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}
.product-card .p-price {
  font-size: 18px;
  font-weight: 800;
  color: var(--red);
}
.product-card .p-stock {
  font-size: 11px;
  color: var(--gray);
  background: var(--light);
  padding: 2px 8px;
  border-radius: 20px;
}
.product-card .p-stock.warn { color: #B45309; background: #FEF3C7; }
.product-card .p-stock.danger { color: #991B1B; background: #FEE2E2; }

.edit-hint {
  position: absolute;
  top: 4px; right: 6px;
  font-size: 10px;
  color: #D1D5DB;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  border: none;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(230,57,70,0.4);
  z-index: 50;
  transition: transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: scale(0.92); }

/* ── CREDIT SCREEN ── */
.screen-credit { padding: 12px; }

.credit-header {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.credit-header .label { font-size: 13px; color: var(--gray); }
.credit-header .total { font-size: 32px; font-weight: 800; color: var(--red); }

.customer-list { display: flex; flex-direction: column; gap: 10px; }

.customer-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  -webkit-tap-highlight-color: transparent;
}
.customer-card:active { transform: scale(0.98); }
.customer-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.customer-info { flex: 1; min-width: 0; }
.customer-info .c-name {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.customer-info .c-note {
  font-size: 12px;
  color: var(--gray);
  margin-top: 2px;
}
.c-badge {
  font-size: 16px;
  font-weight: 800;
  color: var(--red);
  white-space: nowrap;
}
.overdue-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  margin-left: 4px;
}
.overdue-badge.yellow { background: #FEF3C7; color: #92400E; }
.overdue-badge.red    { background: #FEE2E2; color: #991B1B; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray);
}
.empty-state .e-icon { font-size: 56px; margin-bottom: 12px; }
.empty-state .e-text { font-size: 15px; line-height: 1.6; }

/* ── RESTOCK SCREEN ── */
.screen-restock { padding: 12px; }

.tab-bar {
  display: flex;
  background: var(--white);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active {
  background: var(--red);
  color: white;
}

.restock-list { display: flex; flex-direction: column; gap: 10px; }

.restock-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}
.restock-info { flex: 1; }
.restock-info .r-name { font-size: 15px; font-weight: 700; }
.restock-info .r-stock { font-size: 13px; color: var(--gray); margin-top: 2px; }
.restock-info .r-stock span { font-weight: 700; color: #EF4444; }
.btn-restock {
  padding: 10px 16px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-restock:active { transform: scale(0.95); }

/* ── MODAL / BOTTOM SHEET ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.15s ease;
}
.overlay.hidden { display: none; }

.sheet {
  background: var(--white);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 0 0 32px;
  animation: slideUp 0.2s ease;
}

.sheet-handle {
  width: 36px; height: 4px;
  background: #D1D5DB;
  border-radius: 2px;
  margin: 12px auto 4px;
}
.sheet-title {
  font-size: 18px;
  font-weight: 800;
  padding: 12px 20px 16px;
  border-bottom: 1px solid var(--light);
}
.sheet-body { padding: 16px 20px; }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(60px) } to { transform: translateY(0) } }

/* ── FORM ELEMENTS ── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 5px;
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid #E5E7EB;
  border-radius: 10px;
  font-size: 16px;
  background: var(--white);
  color: var(--dark);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--red); }

/* ── BUTTONS ── */
.btn-primary {
  width: 100%;
  padding: 16px;
  background: var(--red);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { opacity: 0.85; }

.btn-secondary {
  width: 100%;
  padding: 14px;
  background: var(--light);
  color: var(--dark);
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}

.btn-danger {
  width: 100%;
  padding: 14px;
  background: #FEE2E2;
  color: #991B1B;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--dark);
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 999;
  white-space: nowrap;
  pointer-events: none;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── SUMMARY SCREEN ── */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.summary-card {
  background: var(--light);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}
.summary-card .s-label { font-size: 11px; color: var(--gray); font-weight: 600; text-transform: uppercase; }
.summary-card .s-value { font-size: 26px; font-weight: 800; color: var(--dark); margin-top: 4px; }
.summary-card .s-value.red { color: var(--red); }
.summary-card .s-value.green { color: var(--green); }

/* ── CREDIT DETAIL ── */
.txn-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.txn-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--light);
  font-size: 14px;
}
.txn-item .txn-type-utang { color: var(--red); font-weight: 700; }
.txn-item .txn-type-bayad { color: var(--green); font-weight: 700; }

/* ── UTILS ── */
.mt-8 { margin-top: 8px; }
.text-center { text-align: center; }
.text-gray { color: var(--gray); font-size: 13px; }
.bold { font-weight: 700; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 2px; }

/* ── QUANTITY STEPPER (sell sheet) ── */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 8px 0 12px;
}
.stepper button {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--light);
  color: var(--dark);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.stepper button:active { background: #E5E7EB; transform: scale(0.94); }
.stepper span {
  min-width: 56px;
  text-align: center;
  font-size: 40px;
  font-weight: 800;
}

/* ── DASHBOARD (Home) ── */
.screen-home { padding: 12px; }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.dash-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dash-card:active { transform: scale(0.97); }
.dash-card .s-label { font-size: 11px; color: var(--gray); font-weight: 600; text-transform: uppercase; }
.dash-value { font-size: 26px; font-weight: 800; margin: 4px 0 2px; color: var(--dark); }
.dash-value.red { color: var(--red); }
.dash-value.green { color: var(--green); }
.dash-value.warn { color: #D97706; }

.dash-actions { margin-bottom: 14px; }
.dash-actions .btn-primary { margin-top: 0; }

.dash-section {
  background: var(--white);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.dash-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 6px;
}
.dash-title a { font-size: 13px; font-weight: 700; color: var(--red); cursor: pointer; }
.dash-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--light);
  font-size: 14px;
}
.dash-row:last-child { border-bottom: none; }
.dash-row[data-action="customer"] { cursor: pointer; }
.dash-row-main { flex: 1; min-width: 0; }
.dash-empty { padding: 10px 0; }
.customer-avatar.sm { width: 34px; height: 34px; font-size: 15px; }
