:root {
  --brand: #d97706;
  --brand-dark: #b45309;
  --brand-light: #fef3c7;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f9fafb;
  --card: #ffffff;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --whatsapp: #25d366;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 84px;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand);
  color: white;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.header .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.15rem;
}

.header .brand small {
  display: block;
  font-weight: 400;
  font-size: 0.72rem;
  opacity: 0.85;
}

.header button.icon-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.card.link {
  display: block;
}

.card-title {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 2px;
}

.card-sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.totals-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  flex: 1;
  min-width: 90px;
  text-align: center;
}

.pill.in { background: var(--green-bg); color: var(--green); }
.pill.out { background: var(--red-bg); color: var(--red); }
.pill.balance { background: var(--brand-light); color: var(--brand-dark); }

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 18px 0 8px;
  font-weight: 700;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  font-size: 0.95rem;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: 84px;
  background: var(--brand);
  color: white;
  border: none;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  font-size: 1.8rem;
  box-shadow: 0 4px 14px rgba(217,119,6,0.45);
  z-index: 25;
  line-height: 0;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 25;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 8px;
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.bottom-nav a.active { color: var(--brand-dark); font-weight: 700; }
.bottom-nav a .ic { font-size: 1.25rem; }

/* Buttons & forms */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn.primary { background: var(--brand); color: white; }
.btn.secondary { background: var(--line); color: var(--ink); }
.btn.whatsapp { background: var(--whatsapp); color: white; }
.btn.ghost { background: transparent; color: var(--brand-dark); border: 1px solid var(--brand); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn.small { width: auto; padding: 8px 12px; font-size: 0.82rem; }

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  background: white;
  font-family: inherit;
}

.toggle-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.toggle-row button {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: white;
  font-weight: 700;
  font-size: 0.9rem;
}

.toggle-row button.active.in { border-color: var(--green); background: var(--green-bg); color: var(--green); }
.toggle-row button.active.out { border-color: var(--red); background: var(--red-bg); color: var(--red); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  display: flex;
  align-items: flex-end;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: white;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px;
}

.modal h2 { margin-top: 0; font-size: 1.15rem; }

.tx-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  gap: 10px;
}

.tx-row:last-child { border-bottom: none; }

.tx-left { flex: 1; }
.tx-desc { font-weight: 600; font-size: 0.92rem; }
.tx-meta { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.tx-amount { font-weight: 700; font-size: 0.98rem; white-space: nowrap; }
.tx-amount.in { color: var(--green); }
.tx-amount.out { color: var(--red); }

.trade-group { margin-bottom: 6px; }
.trade-group-title {
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--brand-dark);
  background: var(--brand-light);
  padding: 6px 10px;
  border-radius: 8px;
  margin: 14px 0 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.trade-group:first-child .trade-group-title { margin-top: 0; }
.trade-count {
  background: white;
  color: var(--brand-dark);
  border-radius: 999px;
  font-size: 0.68rem;
  padding: 1px 7px;
  font-weight: 700;
}

.supplier-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.supplier-row:last-child { border-bottom: none; }

.supplier-name { font-weight: 700; }
.supplier-meta { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.badge {
  display: inline-block;
  background: var(--brand-light);
  color: var(--brand-dark);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 4px;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 18px;
  padding: 32px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

.login-card .logo {
  font-size: 2.4rem;
  margin-bottom: 6px;
}

.login-card h1 { font-size: 1.3rem; margin: 4px 0 2px; }
.login-card p.tag { color: var(--muted); font-size: 0.85rem; margin-bottom: 22px; }
.error-msg { color: var(--red); font-size: 0.85rem; margin-top: 8px; min-height: 18px; }

.top-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.icon-inline-btn {
  background: none;
  border: none;
  color: var(--brand-dark);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
}

.search-box input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-bottom: 14px;
  font-size: 0.95rem;
}

.back-link {
  color: white;
  opacity: 0.9;
  font-size: 1.3rem;
  margin-right: 4px;
}

/* ---------- Reports dashboard ---------- */
.report-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.period-tabs {
  display: flex;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  flex: 1;
  min-width: 220px;
}

.period-tabs button {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: white;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}

.period-tabs button.active {
  background: var(--brand);
  color: white;
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  width: 100%;
}

.period-nav button {
  background: var(--brand-light);
  color: var(--brand-dark);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.period-label {
  font-weight: 700;
  flex: 1;
  text-align: center;
  font-size: 0.88rem;
}

.select-inline {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: white;
  font-size: 0.88rem;
  flex: 1;
  min-width: 140px;
}

.custom-range-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.custom-range-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.88rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.stat-card .stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 700;
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 1.25rem;
  font-weight: 800;
}

.stat-card.in .stat-value { color: var(--green); }
.stat-card.out .stat-value { color: var(--red); }
.stat-card.balance .stat-value { color: var(--brand-dark); }
.stat-card.count .stat-value { color: var(--ink); }

.chart-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}

.chart-card h3 {
  margin: 0 0 12px;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-wrap {
  position: relative;
  height: 230px;
}

.chart-wrap.donut { height: 200px; }

.legend-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name { flex: 1; }
.legend-amt { font-weight: 700; }
.legend-pct { color: var(--muted); font-size: 0.76rem; min-width: 36px; text-align: right; }

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
  padding: 6px 8px;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}

.data-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table tr:last-child td { border-bottom: none; }

.export-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.export-row .btn { width: auto; padding: 10px 16px; font-size: 0.85rem; }
