:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --panel: #ffffff;
  --brand: #7c3aed;
  --brand-deep: #5b21b6;
  --brand-soft: #ede9fe;
  --green: #16a34a;
  --green-deep: #15803d;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(124, 58, 237, 0.1), transparent 32%),
    var(--bg);
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--brand-deep); }

.app-shell { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: rgba(255,255,255,0.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 0.65rem; font-weight: 750; letter-spacing: -0.02em; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(145deg, var(--brand), var(--brand-deep));
  color: white; display: grid; place-items: center; font-size: 0.75rem; font-weight: 800;
}
.brand small { display: block; color: var(--muted); font-weight: 500; font-size: 0.75rem; }
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.main {
  width: min(1100px, calc(100% - 2rem));
  margin: 1.25rem auto 2.5rem;
  flex: 1;
}

.view { display: none !important; }
.view.active { display: block !important; animation: fade 0.16s ease; }
@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.35rem;
}
.panel + .panel { margin-top: 1rem; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.panel-head h2, .panel-head h3 { margin: 0; letter-spacing: -0.02em; }
.panel-head p { margin: 0.35rem 0 0; color: var(--muted); }

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.05rem;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: 0.12s ease;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-deep)); color: white; }
.btn-green { background: linear-gradient(135deg, #22c55e, var(--green-deep)); color: white; }
.btn-secondary { background: white; border: 1px solid var(--line); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-danger { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.88rem; }
.btn-lg { padding: 0.85rem 1.3rem; font-size: 1rem; }
.btn:hover:not(:disabled) { filter: brightness(1.03); transform: translateY(-1px); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.86rem; font-weight: 650; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  background: #fff;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}
.field textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--muted); font-size: 0.8rem; }
.error-text { color: var(--red); font-size: 0.85rem; }

.hero-lite {
  background: linear-gradient(135deg, #5b21b6, #4c1d95 50%, #0f172a);
  color: white;
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.hero-lite h1 { margin: 0 0 0.35rem; font-size: clamp(1.45rem, 2.5vw, 1.9rem); letter-spacing: -0.03em; }
.hero-lite p { margin: 0; opacity: 0.92; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.stat {
  background: linear-gradient(180deg, #fff, #f8fafc);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem;
}
.stat .label { color: var(--muted); font-size: 0.8rem; }
.stat .value { font-size: 1.25rem; font-weight: 750; letter-spacing: -0.03em; margin-top: 0.2rem; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.75rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th {
  color: var(--muted);
  font-weight: 650;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.data tr:hover td { background: #faf5ff; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
}
.badge.draft { background: #e2e8f0; }
.badge.enrolling { background: #dbeafe; color: #1d4ed8; }
.badge.active { background: #dcfce7; color: #15803d; }
.badge.completed { background: #ede9fe; color: #6d28d9; }
.badge.paid { background: #dcfce7; color: #15803d; }
.badge.due { background: #fef3c7; color: #b45309; }
.badge.missed { background: #fee2e2; color: #b91c1c; }
.badge.payout { background: #ccfbf1; color: #0f766e; }

.auth-wrap {
  min-height: calc(100vh - 70px);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.auth-card { width: min(560px, 100%); }
.center { text-align: center; }
.muted { color: var(--muted); }
.money { font-variant-numeric: tabular-nums; font-weight: 650; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88rem; }

.alert {
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}
.alert.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert.info { background: #f5f3ff; border: 1px solid #ddd6fe; color: #5b21b6; }
.alert.ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }

.strength {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.strength > i { display: block; height: 100%; width: 0%; background: #ef4444; transition: 0.15s ease; }
.strength.ok > i { background: #f59e0b; }
.strength.good > i { background: #22c55e; }
.strength.strong > i { background: #7c3aed; }

.steps { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.step-pill {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}
.step-pill.on { background: var(--brand-soft); color: var(--brand-deep); }
.step-pill.done { background: #dcfce7; color: #15803d; }

.wizard-step { display: none; }
.wizard-step.active { display: block; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.round-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  background: #fff;
}
.round-card.current {
  border-color: rgba(124, 58, 237, 0.45);
  box-shadow: 0 10px 24px rgba(124, 58, 237, 0.12);
}
.round-card.done { background: #f8fafc; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(560px, 100%);
  background: white;
  border-radius: 18px;
  padding: 1.4rem;
  box-shadow: 0 30px 80px rgba(15,23,42,0.28);
  max-height: 90vh;
  overflow: auto;
}
.modal.wide { width: min(860px, 100%); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.1rem; }
.success-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: #dcfce7; color: #15803d;
  display: grid; place-items: center; font-size: 1.6rem; margin: 0 auto 0.8rem;
}

.split-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.order-list { list-style: none; padding: 0; margin: 0; }
.order-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 0.5rem;
  background: #fff;
}
.order-list .pos {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-deep);
  display: grid; place-items: center; font-weight: 800; font-size: 0.85rem;
}
.order-list .pos.admin { background: #0f172a; color: #fff; }

.report {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.5rem;
}
.report h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.report .meta { color: var(--muted); margin-bottom: 1rem; font-size: 0.9rem; }
.report h2 {
  font-size: 1.05rem;
  margin: 1.1rem 0 0.45rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.35rem;
}

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.callout {
  background: #f8fafc;
  border-left: 4px solid var(--brand);
  padding: 0.85rem 1rem;
  border-radius: 0 12px 12px 0;
  margin: 0.75rem 0;
}

@media print {
  .topbar, .loan-flow-nav, .btn, #toast { display: none !important; }
  .panel { box-shadow: none; border: none; }
  body { background: white; }
}

@media (max-width: 900px) {
  .grid-2, .grid-3, .stat-cards { grid-template-columns: 1fr; }
}
