/* ============= ReconV — mobile-first stylesheet ============= */
:root {
  --bg:        #f5f7fb;
  --surface:   #ffffff;
  --text:      #1a2233;
  --muted:     #6b7686;
  --border:    #e3e7ee;
  --primary:   #0d6efd;
  --primary-d: #0954c8;
  --debit:     #d6336c;   /* outstanding / credit given */
  --credit:    #2f9e44;   /* payments received */
  --danger:    #d6336c;
  --shadow:    0 1px 2px rgba(20,30,60,.06), 0 6px 18px rgba(20,30,60,.06);
  --radius:    14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.muted  { color: var(--muted); }
.small  { font-size: 13px; }
.center { text-align: center; }

a { color: var(--primary); text-decoration: none; }

/* ----- Header ----- */
header#app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--primary); color: #fff;
  padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
  font-weight: 600; box-shadow: var(--shadow);
}
header#app-header .title { display: flex; align-items: center; gap: 10px; font-size: 18px; }
header#app-header #back-btn { font-size: 28px; line-height: 1; cursor: pointer; padding: 0 4px; }
.icon-btn { background: transparent; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 4px 8px; }

/* ----- Main / views ----- */
main { padding: 16px 16px 96px; max-width: 720px; margin: 0 auto; }
.view { animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ----- Auth screens ----- */
.auth-view {
  min-height: 100vh; padding: 24px 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px; max-width: 460px; margin: 0 auto;
}
.brand { text-align: center; }
.brand .logo {
  width: 64px; height: 64px; margin: 0 auto 8px;
  border-radius: 16px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700;
}
.brand h1 { margin: 4px 0; font-size: 26px; }
.tagline { color: var(--muted); margin: 0; font-size: 14px; }

/* ----- Forms / cards ----- */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); width: 100%;
}
.card h2 { margin: 0 0 14px; font-size: 18px; }
label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px;
  font-size: 16px; font-family: inherit; color: var(--text);
  padding: 10px 12px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; }

button, .primary, .ghost, .danger {
  font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 11px 16px; border-radius: 10px; cursor: pointer; border: 0;
  transition: background .15s, transform .05s;
}
button:active { transform: scale(.98); }
.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-d); }
.ghost   { background: transparent; color: var(--text); border: 1px solid var(--border); }
.danger  { background: #fff; color: var(--danger); border: 1px solid var(--danger); }
.block   { width: 100%; margin-top: 12px; }

/* ----- Summary cards ----- */
.summary-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 16px;
}
.summary-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.summary-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.summary-card .value { font-size: 22px; font-weight: 700; }
.summary-card.outstanding .value { color: var(--debit); }
.summary-card.collected   .value { color: var(--credit); }

/* ----- List rows ----- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  background: var(--surface); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  cursor: pointer;
}
.list li .meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.list li .meta .name { font-weight: 600; }
.list li .meta .sub  { font-size: 13px; color: var(--muted); }

.balance-pill {
  font-weight: 700; font-size: 15px; padding: 6px 10px;
  border-radius: 999px; white-space: nowrap;
}
.balance-pill.owed   { background: #fde7ef; color: var(--debit); }
.balance-pill.clear  { background: #e7f5ec; color: var(--credit); }
.balance-pill.advance{ background: #e7f0ff; color: var(--primary); }

/* ----- Customer detail ----- */
.customer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.customer-head h2 { margin: 0; }
.row-actions { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.row-actions input { flex: 1; margin-top: 0; }
.section-h { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 4px 8px; }

.entry-row { gap: 8px; }
.entry-row .meta .name { display: flex; align-items: center; gap: 6px; }
.entry-row .amount { font-weight: 700; }
.entry-row .amount.debit  { color: var(--debit); }
.entry-row .amount.credit { color: var(--credit); }
.tag {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: #eef2f7; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
}

/* ----- Bottom nav ----- */
nav#bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 8px max(6px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(20,30,60,.05);
}
nav#bottom-nav button {
  background: transparent; border: 0; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 12px; font-size: 11px; min-width: 64px;
}
nav#bottom-nav button.active { color: var(--primary); }
nav#bottom-nav button.fab {
  background: var(--primary); color: #fff;
  width: 56px; height: 56px; border-radius: 50%;
  font-size: 28px; padding: 0; margin-top: -16px;
  box-shadow: 0 4px 14px rgba(13,110,253,.4);
}

/* ----- Modal sheet ----- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15,20,40,.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 520px;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px max(20px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(0,0,0,.18);
  max-height: 92vh; overflow-y: auto;
  animation: slideup .2s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 14px; font-size: 18px; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.sheet .actions .primary { flex: 1; }

/* Segmented toggle for entry_type */
.seg { border: 0; padding: 0; margin: 0 0 12px; display: flex; gap: 8px; }
.seg-opt {
  flex: 1; margin: 0; cursor: pointer;
  background: #f0f3f8; border-radius: 10px; padding: 10px;
  text-align: center; transition: background .15s, color .15s, box-shadow .15s;
}
.seg-opt input { display: none; }
.seg-opt span { display: block; font-weight: 600; font-size: 14px; color: var(--text); }
.seg-opt span small { display: block; font-weight: 400; color: var(--muted); margin-top: 2px; font-size: 11px; }
.seg-opt:has(input:checked) {
  background: #fff; box-shadow: 0 0 0 2px var(--primary) inset; color: var(--primary);
}

/* WhatsApp sheet */
.sheet.wa { text-align: center; }
.wa-icon { font-size: 38px; margin-bottom: 8px; }
.wa-preview {
  text-align: left; white-space: pre-wrap; word-break: break-word;
  background: #f0f3f8; padding: 12px; border-radius: 10px;
  font-family: inherit; font-size: 14px; margin: 12px 0;
}
a.primary { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* Toast */
.toast {
  position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: #1a2233; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 200; box-shadow: var(--shadow);
  animation: fade .15s ease-out;
}

/* Tablet / wider */
@media (min-width: 600px) {
  main { padding: 24px; }
  .summary-grid { grid-template-columns: repeat(4, 1fr); }
}
