/* Artifact platform tokens — auto-resolved */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; }

html, body, #root {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
}

input:focus-visible, button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------------- Layout ---------------- */

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.loading-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text);
}
.loading-screen .brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}
.loading-screen .loading-text { color: var(--text-muted); font-size: 0.9rem; }

/* ---------------- Login ---------------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--primary-tint), var(--bg) 60%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.login-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  font-weight: 800;
}
.login-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 24px;
  line-height: 1.5;
}
.login-btn {
  width: 100%;
  padding: 12px 16px;
  font-size: 0.95rem;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.logout-btn {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.plan-btn {
  padding: 6px 12px;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.plan-btn-paid {
  background: var(--primary-tint);
  color: var(--primary);
  border-color: var(--primary-tint);
}
.plan-badge {
  color: var(--primary);
  font-size: 0.9rem;
  line-height: 1;
}

/* ---------------- Topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--neutral);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-tint);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text {
  flex: 1;
  min-width: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.back-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-tint);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

/* ---------------- Main ---------------- */

.main {
  flex: 1;
  padding: 16px;
  padding-bottom: 40px;
}

/* ---------------- Free plan banner ---------------- */

.free-limit-banner {
  background: var(--primary-tint);
  color: var(--primary);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  margin-bottom: 12px;
  border: 1px solid var(--primary-tint);
}
.free-limit-banner.at-limit {
  background: var(--primary-tint);
  color: var(--primary);
  border-color: var(--primary);
}

/* ---------------- Dashboard ---------------- */

.summary-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
}

.summary-label {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-bottom: 6px;
}
.summary-amount {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.summary-foot {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  opacity: 0.95;
}
.summary-foot strong { font-weight: 700; }

.advance-chip {
  background: var(--scrim);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}
.list-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.fab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, transform 0.05s;
}
.fab:hover { background: var(--primary-dark); }
.fab:active { transform: scale(0.97); }
.fab:disabled {
  background: var(--neutral);
  color: var(--text-muted);
  cursor: not-allowed;
}

.search-wrap {
  position: relative;
  margin-bottom: 12px;
}
.search-wrap input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--neutral);
  background: var(--surface);
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.cust-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cust-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-md);
  transition: background 0.15s, border-color 0.15s;
}
.cust-row:hover {
  background: var(--surface-2);
  border-color: var(--primary-tint);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-tint);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.cust-meta {
  flex: 1;
  min-width: 0;
}
.cust-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cust-phone {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.cust-balance {
  text-align: right;
  flex-shrink: 0;
}
.bal-amount {
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.bal-label {
  font-size: 0.7rem;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
.cust-balance.due .bal-amount { color: var(--danger); }
.cust-balance.advance .bal-amount { color: var(--success); }
.cust-balance.settled .bal-amount { color: var(--text-muted); }

/* ---------------- Empty ---------------- */

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--neutral);
}
.empty.small { padding: 20px; }
.empty-illus {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--primary);
  opacity: 0.7;
}
.empty h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 1rem;
}
.empty p { margin: 0; font-size: 0.9rem; }

/* ---------------- Detail ---------------- */

.detail { display: flex; flex-direction: column; gap: 16px; }

.balance-card {
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--neutral);
}
.balance-card.due { border-left: 4px solid var(--danger); }
.balance-card.advance { border-left: 4px solid var(--success); }
.balance-card.settled { border-left: 4px solid var(--text-muted); }

.balance-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.balance-amount {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.balance-card.due .balance-amount { color: var(--danger); }
.balance-card.advance .balance-amount { color: var(--success); }

.balance-breakdown {
  display: flex;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--neutral);
  gap: 12px;
}
.balance-breakdown > div:not(.bd-divider) { flex: 1; }
.bd-divider {
  width: 1px;
  height: 32px;
  background: var(--neutral);
}
.bd-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.bd-value {
  display: block;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.bd-value.udhaar { color: var(--danger); }
.bd-value.paid { color: var(--success); }

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn.big { padding: 12px 14px; }
.btn.primary {
  background: var(--primary);
  color: white;
}
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--neutral);
}
.btn.ghost:hover { color: var(--text); }
.btn.danger-btn {
  background: var(--danger);
  color: white;
}
.btn.danger-btn:hover { filter: brightness(0.94); }
.btn.success-btn {
  background: var(--success);
  color: white;
}
.btn.success-btn:hover { filter: brightness(0.94); }

.whatsapp-btn {
  background: var(--primary);
  color: white;
  width: 100%;
}
.whatsapp-btn:hover { background: var(--primary); color: white; filter: brightness(0.94); }
.whatsapp-btn:visited { color: white; }

.history h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 700;
}

.txn-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.txn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-md);
}

.txn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.txn.udhaar .txn-icon {
  background: var(--primary-tint);
  color: var(--danger);
}
.txn.paid .txn-icon {
  background: var(--primary-tint);
  color: var(--success);
}

.txn-meta { flex: 1; min-width: 0; }
.txn-title {
  font-weight: 600;
  font-size: 0.9rem;
}
.txn-sub {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.txn.udhaar .txn-amt { color: var(--danger); }
.txn.paid .txn-amt { color: var(--success); }

.del-btn {
  width: 32px;
  height: 32px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.del-btn:hover {
  background: var(--primary-tint);
  color: var(--danger);
}

/* ---------------- Dialog / Sheet ---------------- */

dialog.sheet {
  border: none;
  border-radius: var(--radius-lg);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  width: min(440px, calc(100% - 32px));
  max-width: 440px;
}
dialog.sheet::backdrop {
  background: var(--scrim);
}

dialog.sheet h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
}
.sheet-sub {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.field {
  display: block;
  margin-bottom: 12px;
}
.field > span {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--neutral);
  background: var(--bg);
}
.field input:focus {
  border-color: var(--primary);
}

.sheet-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 0;
  margin: 16px 0 0;
}
.sheet-actions .btn { flex: 1; }

@media (min-width: 480px) {
  .sheet-actions .btn { flex: 0 0 auto; min-width: 120px; }
}

/* ---------------- Plans ---------------- */

dialog.plans-sheet {
  width: min(500px, calc(100% - 32px));
  max-width: 500px;
}

.plan-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plan-card {
  border: 1px solid var(--neutral);
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--surface);
}
.plan-card.plan-highlight {
  border-color: var(--primary);
  background: linear-gradient(180deg, var(--primary-tint) 0%, var(--surface) 60%);
}
.plan-card.plan-current {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.plan-name {
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.plan-tag {
  background: var(--primary);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.plan-price {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.plan-price strong {
  font-size: 1rem;
  color: var(--text);
  font-weight: 800;
}
.plan-period { font-size: 0.8rem; }

.plan-head .btn {
  padding: 6px 12px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.plan-features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.plan-features li {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.tick {
  color: var(--success);
  font-weight: 700;
  flex-shrink: 0;
}

/* ---------------- Reports ---------------- */

dialog.reports-sheet {
  width: min(520px, calc(100% - 32px));
  max-width: 520px;
}

.report-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.report-stat {
  background: var(--surface);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}
.rs-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}
.rs-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
}
.rs-value.due { color: var(--danger); }
.rs-value.paid { color: var(--success); }

.report-section {
  margin-bottom: 16px;
}
.report-section h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}
.report-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.report-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.rl-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rl-amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rl-amt.due { color: var(--danger); }
.rl-split {
  display: inline-flex;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.rl-split .due { color: var(--danger); }
.rl-split .paid { color: var(--success); }
.rl-split .sep { color: var(--text-muted); }

.report-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0;
  padding: 8px 0;
}

/* ---------------- Admin Panel ---------------- */

.admin-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--neutral);
  border-radius: var(--radius-md);
}

.admin-row-main {
  flex: 1;
  min-width: 140px;
}
.admin-row-sub {
  margin-top: 2px;
  font-size: 0.8rem;
}

.admin-row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn.admin-mini {
  padding: 5px 10px;
  font-size: 0.75rem;
}

.btn.danger-text {
  color: var(--danger);
  border-color: var(--neutral);
}
.btn.danger-text:hover {
  color: var(--danger);
  background: var(--primary-tint);
}

.danger-zone {
  border: 1px dashed var(--danger);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}
.danger-zone-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}
