/* ============================================================
   Sunovative Accounts - Mobile-first stylesheet
   Brand: Teal (#0f766e)
   ============================================================ */

:root {
  --c-bg:        #f4f6f8;
  --c-card:      #ffffff;
  --c-text:      #0f172a;
  --c-text-2:    #475569;
  --c-muted:     #64748b;
  --c-border:    #e2e8f0;
  --c-border-2:  #cbd5e1;
  --c-primary:   #0f766e;
  --c-primary-d: #115e59;
  --c-primary-l: #ccfbf1;
  --c-success:   #16a34a;
  --c-warn:      #d97706;
  --c-danger:    #dc2626;
  --c-info:      #2563eb;
  --c-amber:     #b45309;
  --c-amber-bg:  #fef3c7;
  --c-blue-bg:   #dbeafe;
  --c-green-bg:  #dcfce7;
  --c-wa:        #25d366;
  --r-sm:        6px;
  --r-md:        10px;
  --r-lg:        14px;
  --shadow-sm:   0 1px 2px rgba(15,23,42,.06);
  --shadow-md:   0 4px 14px rgba(15,23,42,.08);
  --topbar-h:    56px;
  --side-w:      240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
small { font-size: 12px; }
.muted { color: var(--c-muted); }
.strong { font-weight: 600; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.block { display: block; }
.inline { display: inline; }
.danger { color: var(--c-danger); }

/* ---------- Auth screens ---------- */
.auth-body { min-height: 100vh; background: linear-gradient(135deg, #0f766e 0%, #115e59 100%); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-shell { width: 100%; max-width: 420px; }
.auth-card {
  background: var(--c-card);
  border-radius: var(--r-lg);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-md);
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand h1 { margin: .5rem 0 .25rem; font-size: 1.5rem; }
.auth-brand .muted { font-size: 13px; }
.auth-form h2 { margin-top: 0; font-size: 1.1rem; color: var(--c-text-2); }
.auth-form label { display: block; margin-bottom: .9rem; }
.auth-form label > span { display: block; font-size: 13px; color: var(--c-text-2); margin-bottom: .35rem; font-weight: 500; }
.auth-alt { text-align: center; font-size: 13px; margin-top: 1rem; color: var(--c-text-2); }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--c-primary); color: #fff;
  border-radius: 8px; font-weight: 700; font-size: 16px;
}
.brand-mark.big { width: 56px; height: 56px; font-size: 26px; border-radius: 14px; }

/* ---------- App shell ---------- */
.app-body { padding-top: var(--topbar-h); }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: #fff; border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; padding: 0 1rem; gap: .75rem;
  z-index: 30; box-shadow: var(--shadow-sm);
}
.menu-toggle {
  background: transparent; border: 0; padding: .5rem; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
}
.menu-toggle span { display: block; width: 20px; height: 2px; background: var(--c-text); border-radius: 2px; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.brand-name { font-size: 15px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.who { font-size: 13px; color: var(--c-text-2); }
.badge {
  display: inline-block; padding: 2px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  margin-left: .35rem;
}
.badge-admin { background: #fee2e2; color: #b91c1c; }
.badge-accounts { background: #dbeafe; color: #1d4ed8; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0;
  width: var(--side-w); background: #fff; border-right: 1px solid var(--c-border);
  transform: translateX(-100%); transition: transform .2s ease;
  z-index: 25; padding: 1rem 0; display: flex; flex-direction: column;
}
.sidebar.is-open { transform: translateX(0); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 .5rem; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .75rem; border-radius: var(--r-md);
  color: var(--c-text-2); font-weight: 500; font-size: 14px;
}
.nav-link:hover { background: var(--c-bg); text-decoration: none; }
.nav-link.is-active { background: var(--c-primary-l); color: var(--c-primary-d); }
.nav-icon { width: 20px; text-align: center; opacity: .7; }
.sidebar-foot { padding: 0 1rem; color: var(--c-muted); font-size: 11px; }
.sidebar-backdrop {
  position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(15,23,42,.4);
  z-index: 24; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }

.app-main { padding: 1rem; max-width: 1400px; margin: 0 auto; }

/* ---------- Page head ---------- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem; margin-bottom: 1.25rem;
}
.page-head h1 { margin: 0 0 .25rem; font-size: 1.35rem; }
.page-head p { margin: 0; font-size: 13px; }
.page-head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem .95rem; border-radius: var(--r-md);
  font-weight: 500; font-size: 14px; cursor: pointer;
  border: 1px solid transparent; background: transparent;
  text-decoration: none; transition: all .15s; line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: .35rem .65rem; font-size: 13px; }
.btn-lg { padding: .75rem 1.25rem; font-size: 15px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-d); }
.btn-secondary { background: #fff; color: var(--c-text); border-color: var(--c-border-2); }
.btn-secondary:hover { background: var(--c-bg); }
.btn-ghost { color: var(--c-text-2); }
.btn-ghost:hover { background: var(--c-bg); }
.btn-wa { background: var(--c-wa); color: #fff; font-weight: 600; }
.btn-wa:hover { background: #1ebe5b; color: #fff; }
.btn-ghost.danger:hover { color: var(--c-danger); background: #fee2e2; }

/* ---------- Forms ---------- */
input[type="text"], input[type="number"], input[type="date"],
input[type="email"], input[type="password"], input[type="tel"],
input[type="search"], select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--c-border-2);
  border-radius: var(--r-md);
  background: #fff;
  font: inherit; color: var(--c-text);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-l); }
input[readonly] { background: var(--c-bg); color: var(--c-text-2); }
textarea { resize: vertical; min-height: 70px; }
em { color: var(--c-danger); font-style: normal; }

.form-card { padding: 1rem; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
.form-grid label { display: block; }
.form-grid label > span { display: block; font-size: 13px; color: var(--c-text-2); margin-bottom: .3rem; font-weight: 500; }
.form-grid label.span-2 { grid-column: 1 / -1; }
.form-foot { margin-top: 1.25rem; display: flex; gap: .5rem; flex-wrap: wrap; }

.inline-form { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.search-bar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.search-bar input[type="search"] { flex: 1; min-width: 200px; }

/* ---------- Cards ---------- */
.card {
  background: var(--c-card); border-radius: var(--r-lg);
  border: 1px solid var(--c-border);
  margin-bottom: 1.25rem; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem; border-bottom: 1px solid var(--c-border);
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem; margin-bottom: 1.25rem;
}
.stat-grid-sub { grid-template-columns: 1fr 1fr; }
.stat {
  background: #fff; border: 1px solid var(--c-border);
  border-radius: var(--r-lg); padding: 1rem;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.stat-value-sm { font-size: 16px; font-weight: 600; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.stat-foot { font-size: 11px; color: var(--c-muted); margin-top: .25rem; }
.stat-blue { border-left: 4px solid var(--c-info); }
.stat-amber { border-left: 4px solid var(--c-amber); }
.stat-green { border-left: 4px solid var(--c-success); }
.stat-mini { padding: .65rem .85rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
  min-width: 600px;
}
.data-table thead th {
  text-align: left; padding: .65rem .75rem;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--c-muted); background: var(--c-bg); border-bottom: 1px solid var(--c-border);
}
.data-table tbody td { padding: .7rem .75rem; border-bottom: 1px solid var(--c-border); vertical-align: top; }
.data-table tbody tr:hover { background: #fafbfc; }
.data-table tfoot th { padding: .7rem .75rem; background: var(--c-bg); font-size: 13px; }
.table-compact td, .table-compact th { padding: .5rem .65rem !important; }
.table-ledger { min-width: 760px; }

.row-due { background: #fffbeb; }
.row-due:hover { background: #fef3c7 !important; }
.row-paid td:nth-child(5) { color: var(--c-muted); }

/* ---------- Pills / Badges ---------- */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  background: var(--c-bg); color: var(--c-text-2);
}
.pill-bill { background: #dbeafe; color: #1d4ed8; }
.pill-payment { background: #dcfce7; color: #166534; }
.pill-credit { background: #fee2e2; color: #b91c1c; }
.pill-ok { background: var(--c-green-bg); color: var(--c-success); }
.pill-muted { background: var(--c-bg); color: var(--c-muted); }
.pill-pending, .pill-failed { background: #fee2e2; color: var(--c-danger); }
.pill-done { background: var(--c-green-bg); color: var(--c-success); }
.pill-flat { background: #e0e7ff; color: #3730a3; }
/* note: pill-credit reused — in plan-context we override */
.pill-plan.pill-credit { background: #fef3c7; color: var(--c-amber); }

.amount { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Flash ---------- */
.flash {
  padding: .7rem 1rem; border-radius: var(--r-md);
  margin: 0 0 1rem; border: 1px solid; font-size: 14px;
}
.flash-success { background: var(--c-green-bg); color: var(--c-success); border-color: #86efac; }
.flash-error   { background: #fee2e2; color: var(--c-danger); border-color: #fca5a5; }

/* ---------- Activity list ---------- */
.activity-list { list-style: none; padding: 0; margin: 0; }
.activity-list li {
  padding: .7rem 1rem; border-bottom: 1px solid var(--c-border); display: flex;
  align-items: center; flex-wrap: wrap; gap: .5rem;
}
.activity-list li:last-child { border-bottom: 0; }
.activity-list .amount { margin-left: auto; }

/* ---------- Upload ---------- */
.upload-zone {
  border: 2px dashed var(--c-border-2); border-radius: var(--r-lg);
  padding: 1.5rem 1rem; text-align: center; transition: border-color .15s;
}
.upload-zone:hover { border-color: var(--c-primary); }
.upload-zone input[type="file"] { display: block; margin: 0 auto; }
.upload-zone label { display: block; margin-top: .5rem; }
.upload-zone label strong { display: block; }
.help-box { padding: 1rem; }
.help-box ul { margin: .5rem 0; padding-left: 1.25rem; }
.help-box li { margin-bottom: .25rem; }
.small { font-size: 12px; }
.result-summary { display: flex; gap: 1rem; padding: 1rem; flex-wrap: wrap; }
.rs-item { background: var(--c-bg); padding: .75rem 1rem; border-radius: var(--r-md); flex: 1; min-width: 100px; }
.rs-label { font-size: 11px; color: var(--c-muted); text-transform: uppercase; }
.rs-value { font-size: 22px; font-weight: 700; }
.rs-ok { background: var(--c-green-bg); }
.rs-warn { background: #fef3c7; }

/* ---------- WA preview ---------- */
.wa-preview {
  background: #f0fdf4; border: 1px solid #86efac;
  border-radius: var(--r-md); padding: 1rem; margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
  font-size: 14px; white-space: pre-wrap;
}

/* ---------- CTA row ---------- */
.cta-row { margin-bottom: 1.25rem; }

/* ---------- Dealer screens ---------- */
.dealer-body { background: var(--c-bg); padding-top: var(--topbar-h); }
.dealer-topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: #fff; border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; padding: 0 1rem; gap: .75rem; z-index: 30;
}
.dealer-main { padding: 1rem; max-width: 900px; margin: 0 auto; }
.dealer-hero { padding: 1rem 0 .5rem; }
.dealer-hero h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.dealer-hero p { margin: 0; font-size: 13px; }

/* ---------- Errors ---------- */
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 4rem; color: var(--c-primary); margin-bottom: 0; }

/* ---------- Responsive ---------- */
.d-none-mobile { display: none; }

@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .stat-grid-sub { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
  .grid-2 .card { margin-bottom: 0; }
  .d-none-mobile { display: inline; }
}

@media (min-width: 1024px) {
  .app-main { padding-left: calc(var(--side-w) + 1.5rem); padding-right: 1.5rem; padding-top: 1.25rem; }
  .sidebar { transform: translateX(0); }
  .sidebar-backdrop { display: none; }
  .menu-toggle { display: none; }
  .stat-value { font-size: 26px; }
}

/* ---------- PWA install button ---------- */
.pwa-install-btn {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.35);
  -webkit-tap-highlight-color: transparent;
}
.pwa-install-btn:hover { filter: brightness(1.05); }
.pwa-install-btn:active { transform: scale(0.97); }
@media (display-mode: standalone) {
  /* hide once installed */
  .pwa-install-btn { display: none !important; }
}

/* ---------- Upload form fieldset ---------- */
.form-fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 16px 0;
}
.form-fieldset legend {
  padding: 0 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.checkbox {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; margin-bottom: 10px;
}
.checkbox input { width: 16px; height: 16px; }
.field-inline {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; margin-top: 6px;
}
.field-inline select {
  padding: 6px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px;
  background: white;
}
.pill-info {
  background: #e0f2fe; color: #075985;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
}

/* ---------- Reconcile box on upload result ---------- */
.reconcile-box {
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.6;
}
.reconcile-ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.reconcile-warn {
  background: #fef3c7;
  color: #78350f;
  border: 1px solid #fcd34d;
}
.reconcile-box code {
  background: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.rs-info {
  background: #eff6ff;
  color: #1e40af;
}

/* ---------- Ledger optic (Option C + chargeable, single table everywhere) ---------- */
.cell-interest .interest-amt {
  font-weight: 500;
  line-height: 1.2;
}
.cell-interest .interest-formula {
  font-size: 11px;
  color: var(--muted, #6b7280);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.4;
  margin-top: 2px;
  word-break: break-word;
}
.cell-interest .interest-formula.muted {
  color: var(--muted, #9ca3af);
}

.pill-grace {
  display: inline-block;
  background: #d1fae5;
  color: #065f46;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
}

.ledger-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.ledger-scroll .table-ledger {
  min-width: 720px;
}
.ledger-scroll .table-ledger .interest-formula {
  max-width: 240px;
}

@media (max-width: 720px) {
  .ledger-scroll .table-ledger {
    font-size: 11.5px;
  }
  .ledger-scroll .table-ledger th,
  .ledger-scroll .table-ledger td {
    padding: 6px 8px;
  }
  .ledger-scroll .table-ledger .interest-formula {
    font-size: 10px;
    max-width: 180px;
  }
}

/* ---------- Statement page additions ---------- */
.banner {
  padding: 10px 14px;
  border-radius: var(--border-radius-md);
  font-size: 13px;
  line-height: 1.5;
}
.banner-info {
  background: #eff6ff;
  border-left: 3px solid #2563eb;
  color: #1e3a8a;
}
.banner-info code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.btn-link {
  font-size: 12px;
  color: var(--muted, #2563eb);
  text-decoration: none;
}
.btn-link:hover {
  text-decoration: underline;
}

/* ---------- Dashboard hero (Interest as headline metric) ---------- */
.stat-grid-hero {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.stat-hero .stat-value {
  font-size: 28px;
  font-weight: 600;
}
.stat-hero .stat-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
@media (max-width: 640px) {
  .stat-grid-hero {
    grid-template-columns: 1fr;
  }
  .stat-hero .stat-value {
    font-size: 24px;
  }
}

.pill-interest {
  display: inline-block;
  background: #fce7f3;
  color: #831843;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 999px;
  margin-top: 2px;
}
