/* ============================================================
   DukaBook — styles.css
   Brand: deep green #1B7A43, white cards, subtle shadows.
   Mobile-first (~375px), desktop gets a centered container.
   ============================================================ */

:root {
  --green: #1B7A43;
  --green-dark: #145C32;
  --green-light: #E6F3EC;
  --green-mid: #2E9C5C;
  --gold: #C9932B;
  --gold-light: #FBF3E0;
  --red: #C0392B;
  --red-light: #FBEAE8;
  --amber: #B26A00;
  --amber-light: #FFF4E0;
  --ink: #1D2A22;
  --ink-soft: #5B6B61;
  --line: #E3EAE5;
  --bg: #F3F6F4;
  --card: #FFFFFF;
  --shadow: 0 1px 3px rgba(20, 40, 28, 0.08), 0 4px 14px rgba(20, 40, 28, 0.06);
  --radius: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
          'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

@media (min-width: 560px) {
  .app {
    box-shadow: 0 0 40px rgba(20, 40, 28, 0.10);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--green);
  color: #fff;
  box-shadow: 0 2px 8px rgba(20, 60, 36, 0.25);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px; background: #fff; }
.brand-text h1 { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: 0.2px; }
.brand-tag {
  display: block;
  font-size: 0.72rem;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover, .icon-btn:focus-visible { background: rgba(255, 255, 255, 0.26); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Main / views ---------- */
.app-main {
  padding: 16px 14px calc(84px + env(safe-area-inset-bottom, 0px));
}

.view { display: none; animation: fadeIn 0.18s ease; }
.view.active { display: block; }

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

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.card-head-row .card-title { margin: 0; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 12px; min-width: 0; }
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

input[type="text"], input[type="number"], input[type="tel"], select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #FAFCFB;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(27, 122, 67, 0.15);
}

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 0 0 auto; width: 92px; }
.field-row .field.grow { flex: 1 1 auto; width: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  font: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.985); }
.btn-block { width: 100%; }

.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

.btn-outline {
  background: #fff;
  color: var(--green);
  border: 1.5px solid var(--green);
}
.btn-outline:hover { background: var(--green-light); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger-outline {
  background: #fff;
  color: var(--red);
  border: 1.5px solid var(--red);
}
.btn-danger-outline:hover { background: var(--red-light); }

.btn-stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Sign-in front door (first-open) ---------- */
/* The hidden attribute must win over the display below (else it never hides). */
.auth-screen[hidden] { display: none !important; }
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: linear-gradient(160deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 22px calc(32px + env(safe-area-inset-bottom, 0px));
}
.auth-inner { width: 100%; max-width: 400px; }
.auth-logo { width: 64px; height: 64px; display: block; margin: 0 auto 18px; border-radius: 16px; }
.auth-title { margin: 0 0 8px; font-size: 1.55rem; font-weight: 800; text-align: center; }
.auth-sub { margin: 0 0 24px; font-size: 0.95rem; line-height: 1.45; opacity: 0.9; text-align: center; }
.auth-field { margin-bottom: 14px; }
.auth-field .field-label { color: rgba(255, 255, 255, 0.9); }
.auth-screen input[type="email"],
.auth-screen input[type="password"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid transparent;
  border-radius: 10px;
  outline: none;
}
.auth-screen input:focus { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.4); }
.auth-screen .btn-primary { background: #fff; color: var(--green-dark); margin-top: 4px; }
.auth-screen .btn-primary:hover { filter: brightness(0.96); }
.auth-screen .btn-outline { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.6); margin-top: 10px; }
.auth-screen .btn-outline:hover { background: rgba(255, 255, 255, 0.12); }
.auth-skip { color: rgba(255, 255, 255, 0.9); margin-top: 8px; }
.auth-skip:hover { background: rgba(255, 255, 255, 0.1); }
.auth-note { margin: 16px 0 0; font-size: 0.75rem; opacity: 0.75; text-align: center; }

/* While the front door is up, hide the app chrome behind it. */
.app.auth-open .app-header,
.app.auth-open .app-main,
.app.auth-open .bottom-nav { display: none; }

.btn-sm {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: 10px;
}

/* Segmented toggle */
.seg {
  display: flex;
  background: var(--bg);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 12px;
}
.seg-btn {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 9px;
  background: transparent;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn.active {
  background: var(--green);
  color: #fff;
  box-shadow: 0 1px 4px rgba(27, 122, 67, 0.35);
}

/* ---------- Pills & badges ---------- */
.pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--bg);
  color: var(--ink-soft);
  white-space: nowrap;
}
.pill-green { background: var(--green-light); color: var(--green-dark); }
.pill-red { background: var(--red-light); color: var(--red); }
.pill-gold { background: var(--gold-light); color: var(--gold); }
.pill-amber { background: var(--amber-light); color: var(--amber); }
.head-pills { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill.door { cursor: pointer; transition: filter 0.15s; }
.pill.door:hover, .pill.door:focus-visible { filter: brightness(0.95); }
.pill.door:active { filter: brightness(0.9); }
.pill.door .chev {
  position: static;
  transform: none;
  width: 12px;
  height: 12px;
  vertical-align: -1px;
  margin-left: 2px;
}

.badge-low {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--amber-light);
  color: var(--amber);
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--ink-soft);
}
.chip-mobile { background: #E8F0FB; color: #2B5FA6; }

/* ---------- Banner ---------- */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.banner-warn { background: linear-gradient(135deg, #B26A00, #D98E1B); color: #fff; }
.banner-label { display: block; font-size: 0.78rem; opacity: 0.9; }
.banner-value { display: block; font-size: 1.45rem; font-weight: 800; }
.banner-icon { width: 30px; height: 30px; opacity: 0.85; flex-shrink: 0; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: none; }

.li-main { flex: 1; min-width: 0; }
.li-title {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.li-sub { font-size: 0.78rem; color: var(--ink-soft); margin-top: 2px; }
.li-amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.li-amount.neg { color: var(--red); }

.li-del {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #A6B5AC;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.li-del:hover { background: var(--red-light); color: var(--red); }
.li-del svg { width: 18px; height: 18px; }

.empty {
  color: var(--ink-soft);
  font-size: 0.9rem;
  text-align: center;
  padding: 14px 6px;
  margin: 0;
}

/* Stock qty stepper */
.qty-stepper { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.qty-stepper button {
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--green);
  cursor: pointer;
}
.qty-stepper button:hover { background: var(--green-light); }
.qty-stepper .qty-val {
  min-width: 28px;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
}

/* ---------- Debt customer cards ---------- */
.debt-cust {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.debt-cust-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.debt-cust-name { font-weight: 700; font-size: 1rem; }
.debt-cust-phone { font-size: 0.78rem; color: var(--ink-soft); margin-top: 1px; }
.debt-cust-balance { font-weight: 800; font-size: 1.05rem; color: var(--red); white-space: nowrap; }
.debt-cust-date { font-size: 0.74rem; color: var(--ink-soft); margin-top: 2px; text-align: right; }

.debt-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.debt-actions .btn-sm { flex: 1 1 auto; }

.btn-pay { background: var(--green-light); color: var(--green-dark); border: none; }
.btn-pay:hover { background: #D3E9DC; }
.btn-sms { background: #E8F0FB; color: #2B5FA6; border: none; text-decoration: none; }
.btn-sms:hover { filter: brightness(0.96); }
.btn-wa { background: #E6F8EC; color: #128C4A; border: none; text-decoration: none; }
.btn-wa:hover { filter: brightness(0.96); }
.btn-hist { background: var(--bg); color: var(--ink-soft); border: none; }

.debt-history {
  margin-top: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}
.debt-history-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  padding: 4px 0;
  color: var(--ink-soft);
}
.debt-history-row .h-amount { font-weight: 700; }
.h-amount.pos { color: var(--red); }
.h-amount.neg { color: var(--green); }

.select-sm {
  width: auto;
  min-height: 40px;
  padding: 6px 10px;
  font-size: 0.85rem;
  border-radius: 10px;
}

/* ---------- Reports ---------- */
.report-card { margin-bottom: 14px; }
.report-period {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--green);
  margin: 0 0 10px;
}
.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.report-stat {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
}
.report-stat .rs-label { display: block; font-size: 0.72rem; color: var(--ink-soft); font-weight: 600; }
.report-stat .rs-value { display: block; font-size: 1.02rem; font-weight: 800; margin-top: 2px; }
.rs-value.pos { color: var(--green-dark); }
.rs-value.neg { color: var(--red); }

.report-profit {
  grid-column: 1 / -1;
  background: var(--green-light);
}

/* Bar chart */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 160px;
  padding-top: 18px;
}
.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}
.chart-bar {
  width: 100%;
  max-width: 34px;
  background: linear-gradient(180deg, var(--green-mid), var(--green));
  border-radius: 6px 6px 2px 2px;
  min-height: 3px;
  transition: height 0.3s ease;
}
.chart-bar.today { background: linear-gradient(180deg, #E0B54C, var(--gold)); }
.chart-val {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 3px;
  white-space: nowrap;
}
.chart-label {
  font-size: 0.68rem;
  color: var(--ink-soft);
  margin-top: 5px;
  font-weight: 600;
}

/* Month-over-month table */
.mom-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.mom-table th, .mom-table td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.mom-table th:first-child, .mom-table td:first-child { text-align: left; }
.mom-table th { font-size: 0.75rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.4px; }
.mom-table tr:last-child td { border-bottom: none; }
.mom-delta { font-size: 0.75rem; font-weight: 700; }
.mom-delta.up { color: var(--green-dark); }
.mom-delta.down { color: var(--red); }

.locked {
  text-align: center;
  padding: 18px 8px;
  color: var(--ink-soft);
}
.locked .lock-icon { font-size: 1.8rem; display: block; margin-bottom: 6px; }
.locked p { margin: 0 0 14px; font-size: 0.9rem; }

/* ---------- Upgrade view ---------- */
.upgrade-card {
  text-align: center;
  background: linear-gradient(160deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
}
.upgrade-star {
  width: 56px;
  height: 56px;
  margin: 4px auto 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  color: #FFD968;
}
.upgrade-title { margin: 0 0 4px; font-size: 1.3rem; }
.upgrade-price { margin: 0 0 10px; font-size: 1.15rem; opacity: 0.95; }
.upgrade-price strong { font-size: 1.5rem; }
.upgrade-lead { margin: 0 0 14px; font-size: 0.9rem; opacity: 0.9; }
.upgrade-benefits {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
}
.upgrade-benefits li {
  padding: 7px 0 7px 28px;
  position: relative;
  font-size: 0.9rem;
}
.upgrade-benefits li::before {
  content: "✓";
  position: absolute;
  left: 4px;
  color: #9FE0B8;
  font-weight: 800;
}

.pay-steps { margin: 0 0 16px; padding-left: 20px; }
.pay-steps li { margin-bottom: 10px; font-size: 0.92rem; line-height: 1.45; }

.lipa-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--green-light);
  border: 2px dashed var(--green);
  border-radius: 12px;
  padding: 12px;
  margin-top: 8px;
}
.lipa-box strong { font-size: 1.6rem; letter-spacing: 3px; color: var(--green-dark); }
.lipa-box span { font-size: 0.82rem; color: var(--ink-soft); font-weight: 600; }

/* ---------- Plan info (settings) ---------- */
.plan-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.plan-name { font-weight: 800; font-size: 1.05rem; }
.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin: 8px 0 6px;
}
.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width 0.3s ease;
}
.meter-fill.warn { background: var(--amber); }
.meter-fill.full { background: var(--red); }
.meter-note { font-size: 0.8rem; color: var(--ink-soft); margin: 0 0 12px; }

.version-note {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 18px 0 6px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(20, 40, 28, 0.08);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 30;
}
.nav-btn {
  flex: 1;
  min-height: 62px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: #8FA096;
  font-family: inherit;
  padding: 6px 2px;
  transition: color 0.15s;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn span { font-size: 0.66rem; font-weight: 700; }
.nav-btn.active { color: var(--green); }
.nav-btn.active svg { stroke-width: 2.4; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(10, 25, 15, 0.3);
  animation: fadeIn 0.15s ease;
}
.modal h3 { margin: 0 0 10px; font-size: 1.05rem; }
.modal p { margin: 0 0 14px; font-size: 0.92rem; color: var(--ink-soft); }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}
.repay-customer { font-weight: 700; color: var(--ink) !important; margin-bottom: 4px !important; }
.repay-balance strong { color: var(--red); }

/* ---------- Stat doors: tappable aggregates ---------- */
.report-stat { position: relative; }
.stat-door { cursor: pointer; padding-right: 26px; transition: background 0.15s; }
.stat-door:hover { background: #EAF0EC; }
.stat-door:active { background: var(--green-light); }
.stat-door.report-profit:hover, .stat-door.report-profit:active { background: #D3E9DC; }
.stat-door .chev {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: #A6B5AC;
}
.banner.door { cursor: pointer; transition: filter 0.15s; }
.banner.door:active { filter: brightness(1.08); }
.chart-col.door { cursor: pointer; border-radius: 8px; }
.chart-col.door:active .chart-bar { filter: brightness(1.18); }
.debt-cust-top[role="button"] { cursor: pointer; border-radius: 8px; }
.debt-cust-top[role="button"]:active { background: var(--bg); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(10, 25, 15, 0.3);
  z-index: 60;
  max-width: 90%;
  text-align: center;
  animation: toastIn 0.2s ease;
}
.toast[hidden] { display: none; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
