:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #102033;
  --muted: #6b7a90;
  --line: #e2e8f0;
  --navy: #0a1d33;
  --navy-2: #102b49;
  --blue: #1268f3;
  --blue-soft: #eaf2ff;
  --gold: #d9a62e;
  --gold-soft: #fff7df;
  --green: #138a62;
  --danger: #d83a52;
  --shadow: 0 16px 40px rgba(10, 29, 51, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 29, 51, .96);
  color: #fff;
  box-shadow: 0 8px 26px rgba(10, 29, 51, .16);
  backdrop-filter: blur(14px);
}
.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  min-height: 72px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: max-content;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: -.04em;
  color: var(--navy);
  background: linear-gradient(145deg, #fff, #f0c85f);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.55), 0 8px 22px rgba(0,0,0,.16);
}
.brand-text strong { display: block; font-size: 15px; letter-spacing: .01em; }
.brand-text span { display: block; margin-top: 1px; font-size: 11px; color: #9fb2c7; }

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 13px;
  border-radius: 11px;
  text-decoration: none;
  color: #c9d5e2;
  font-size: 13px;
  font-weight: 700;
  transition: .2s ease;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: rgba(255,255,255,.12); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
.nav a.logout { margin-left: 6px; color: #ffe9ec; background: rgba(216,58,82,.14); }
.nav a.logout:hover { background: rgba(216,58,82,.24); }
.nav-icon { width: 16px; height: 16px; display: inline-grid; place-items: center; }
.mobile-menu-btn { display: none; margin-left: auto; }

.page-wrap { max-width: 1500px; margin: 0 auto; padding: 32px 24px 48px; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #8a6411;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.page-head h1 { margin: 0; font-size: clamp(28px, 3vw, 42px); line-height: 1.08; letter-spacing: -.035em; }
.page-head p { margin: 9px 0 0; color: var(--muted); max-width: 760px; font-size: 14px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--blue); box-shadow: 0 8px 18px rgba(18,104,243,.22); }
.btn-primary:hover { background: #0f5fdf; }
.btn-dark { color: #fff; background: var(--navy); }
.btn-light { color: var(--ink); background: #fff; border: 1px solid var(--line); }
.btn-soft { color: var(--blue); background: var(--blue-soft); }
.btn-danger-soft { color: var(--danger); background: #fff0f2; }
.btn-sm { min-height: 36px; padding: 0 11px; border-radius: 10px; font-size: 12px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 8px 26px rgba(10,29,51,.04);
}
.stat-card small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.stat-card strong { display: block; margin-top: 4px; font-size: 24px; letter-spacing: -.03em; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 18px; }
.card-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: linear-gradient(180deg, #fff, #fbfdff);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 16px; letter-spacing: -.015em; }
.card-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.card-body { padding: 22px; }

.section-kicker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.section-no {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}
.section-kicker h3 { margin: 0; font-size: 15px; }
.section-kicker p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.form-section { padding: 22px; border-bottom: 1px solid var(--line); }
.form-section:last-child { border-bottom: 0; }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.field { grid-column: span 3; min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field.span-4 { grid-column: span 4; }
.field.span-6 { grid-column: span 6; }
.field.span-8 { grid-column: span 8; }
.field.span-12 { grid-column: span 12; }
.field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 800;
  color: #334155;
}
.field label .hint { color: #9aa7b8; font-size: 10px; font-weight: 600; }
.field input, .field select, .field textarea,
.table-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d7dfeb;
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.field textarea { resize: vertical; min-height: 96px; }
.field input:focus, .field select:focus, .field textarea:focus, .table-input:focus {
  border-color: #7eabf8;
  box-shadow: 0 0 0 4px rgba(18,104,243,.09);
}
.field input[readonly] { background: var(--surface-2); color: #576579; }
.field select { cursor: pointer; }
.field.required label::after { content: "Required"; color: var(--blue); font-size: 9px; text-transform: uppercase; letter-spacing: .05em; }
.field-status { margin-top: 7px; font-size: 11px; color: var(--muted); min-height: 16px; }
.field-status.success { color: var(--green); }
.field-status.error { color: var(--danger); }

.charges-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
.charges-table { width: 100%; min-width: 1050px; border-collapse: separate; border-spacing: 0; }
.charges-table th {
  background: #f5f8fc;
  color: #536277;
  padding: 10px;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.charges-table td { padding: 8px; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
.charges-table tr:last-child td { border-bottom: 0; }
.charges-table .table-input { min-height: 39px; padding: 7px 9px; border-radius: 9px; font-size: 12px; }
.charges-table .charge-name { min-width: 210px; }
.charges-table .money { min-width: 105px; }
.charges-table .currency { min-width: 80px; }
.charges-table .remove-cell { width: 46px; }
.icon-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  background: #fff0f2;
  color: var(--danger);
  font-weight: 900;
}
.charges-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.live-total { padding: 10px 14px; border-radius: 12px; background: var(--navy); color: #fff; display: flex; align-items: baseline; gap: 10px; }
.live-total span { color: #aebfd1; font-size: 11px; }
.live-total strong { font-size: 18px; }

.form-footer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(10px);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.search-box { position: relative; flex: 1 1 300px; max-width: 480px; }
.search-box input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px 0 40px;
  background: #fff;
  outline: none;
}
.search-box input:focus { border-color: #8bb4f7; box-shadow: 0 0 0 4px rgba(18,104,243,.08); }
.search-box::before { content: "⌕"; position: absolute; left: 14px; top: 9px; font-size: 20px; color: #7f8da1; }
.record-count { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 700; }

.table-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.data-table th {
  padding: 13px 16px;
  text-align: left;
  background: #f7f9fc;
  border-bottom: 1px solid var(--line);
  color: #607085;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  white-space: nowrap;
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid #edf1f6; font-size: 13px; vertical-align: middle; }
.data-table tbody tr:hover > td { background: #fbfdff; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.primary-cell { font-weight: 800; color: #17283c; }
.secondary { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 500; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; background: var(--blue-soft); color: var(--blue); font-size: 10px; font-weight: 800; white-space: nowrap; }
.badge.gold { background: var(--gold-soft); color: #87630e; }
.table-actions { display: flex; gap: 7px; justify-content: flex-end; white-space: nowrap; }
.action-link { min-height: 34px; padding: 0 10px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: #fff; color: #314257; text-decoration: none; font-size: 11px; font-weight: 800; cursor: pointer; }
.action-link.primary { color: var(--blue); background: var(--blue-soft); border-color: transparent; }
.action-link:hover { border-color: #bcc8d8; }

.details-row { display: none; }
.details-row.open { display: table-row; }
.details-row > td { padding: 0 !important; background: #f9fbfd !important; }
.details-panel { padding: 18px; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.detail-item { padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; min-width: 0; }
.detail-item small { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.detail-item span { display: block; margin-top: 5px; font-size: 12px; font-weight: 700; overflow-wrap: anywhere; }
.detail-item.wide { grid-column: span 2; }

.empty-state { padding: 54px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 5px; }

.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 12px; border: 1px solid #b9e9d9; background: #effbf7; color: #0c7251; font-size: 13px; font-weight: 700; }

.customer-cards { display: none; gap: 12px; }
.customer-card { background: #fff; border: 1px solid var(--line); border-radius: 15px; padding: 16px; }
.customer-card h3 { margin: 0; font-size: 15px; }
.customer-card p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.customer-meta { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin-top: 14px; }
.customer-meta div { padding: 9px 10px; border-radius: 10px; background: #f7f9fc; font-size: 11px; overflow-wrap: anywhere; }
.customer-meta strong { display: block; color: #536277; font-size: 9px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.customer-links { display: flex; gap: 8px; margin-top: 13px; }
.customer-links a { flex: 1; text-align: center; text-decoration: none; background: var(--blue-soft); color: var(--blue); padding: 9px; border-radius: 9px; font-size: 11px; font-weight: 800; }

@media (max-width: 1080px) {
  .topbar-inner { flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
  .mobile-menu-btn { display: inline-flex; width: 42px; height: 42px; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.16); border-radius: 10px; color: #fff; background: rgba(255,255,255,.07); cursor: pointer; }
  .nav { width: 100%; display: none; flex-wrap: wrap; padding-top: 4px; }
  .nav.open { display: flex; }
  .nav a { flex: 1 1 150px; justify-content: center; }
  .nav a.logout { margin-left: 0; }
  .field { grid-column: span 4; }
  .field.span-2 { grid-column: span 4; }
  .field.span-4 { grid-column: span 4; }
  .field.span-6, .field.span-8 { grid-column: span 6; }
  .details-panel { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 720px) {
  .page-wrap { padding: 22px 14px 36px; }
  .topbar-inner { padding-left: 14px; padding-right: 14px; }
  .brand-text span { display: none; }
  .page-head { flex-direction: column; }
  .page-head h1 { font-size: 29px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .card-body, .form-section { padding: 17px; }
  .field, .field.span-2, .field.span-4, .field.span-6, .field.span-8, .field.span-12 { grid-column: span 12; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { padding: 14px; }
  .details-panel { grid-template-columns: 1fr; }
  .detail-item.wide { grid-column: span 1; }
  .record-count { width: 100%; margin-left: 0; }
  .form-footer { justify-content: stretch; }
  .form-footer .btn { flex: 1; }
  .data-table.customer-table { display: none; }
  .customer-cards { display: grid; }
}
