/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #f0f1f3;
  --border: #e8eaed;
  --text: #111827;
  --text2: #6b7280;
  --text3: #9ca3af;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-dark: #1d4ed8;
  --green: #059669;
  --green-light: #d1fae5;
  --red: #dc2626;
  --red-light: #fee2e2;
  --orange: #d97706;
  --orange-light: #fef3c7;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --nav-h: 68px;
  --font: 'DM Sans', sans-serif;
  --mono: 'DM Mono', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { overflow: hidden; }

#app {
  height: calc(100dvh - var(--nav-h));
  overflow: hidden;
  position: relative;
}

/* ── Views ── */
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px calc(12px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}
.view.active {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

/* Sub-views (client detail, etc.) */
.sub-view {
  position: fixed;
  inset: 0 0 var(--nav-h);
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 16px;
  z-index: 100;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.sub-view.open { transform: none; }

/* ── Bottom Nav ── */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text3);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s;
  padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn.active { color: var(--accent); }
.nav-btn svg { transition: transform .15s; }
.nav-btn.active svg { transform: scale(1.1); }

/* ── Typography ── */
.page-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 4px;
}
.page-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.5px;
  margin-bottom: 20px;
}
.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

/* ── Stat Grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}
.stat-card.full { grid-column: 1/-1; }
.stat-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.5px;
  font-family: var(--mono);
}
.stat-value.accent { color: var(--accent); }
.stat-value.red { color: var(--red); }
.stat-value.green { color: var(--green); }
.stat-sub {
  font-size: 12px;
  color: var(--text3);
  margin-top: 2px;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-blue { background: var(--accent-light); color: var(--accent); }
.badge-gray { background: var(--surface2); color: var(--text2); }

/* ── List Items ── */
.list-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
  position: relative;
}
.list-item:active { background: var(--surface2); }
.list-item-accent {
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 4px;
  border-radius: 0 4px 4px 0;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-sub {
  font-size: 13px;
  color: var(--text2);
  margin-top: 2px;
}
.list-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.list-item-amount {
  font-size: 15px;
  font-weight: 700;
  font-family: var(--mono);
}
.chevron {
  color: var(--text3);
  flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { opacity: .85; transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-success { background: var(--green-light); color: var(--green); }
.btn-sm {
  height: 38px;
  padding: 0 14px;
  font-size: 14px;
  border-radius: var(--radius-sm);
}
.btn-full { width: 100%; }
.btn-icon {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37,99,235,.4);
  cursor: pointer;
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(.93); box-shadow: 0 2px 8px rgba(37,99,235,.3); }

/* ── Forms ── */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text2);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, background .15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-textarea {
  height: auto;
  min-height: 80px;
  padding: 12px 14px;
  resize: vertical;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 42px;
}
.form-error {
  font-size: 12px;
  color: var(--red);
  margin-top: 4px;
}
.toggle-group {
  display: flex;
  gap: 8px;
}
.toggle-btn {
  flex: 1;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.toggle-btn.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  animation: fadeIn .2s ease;
}
.modal-overlay.center { align-items: center; padding: 16px; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-sheet {
  width: 100%;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px 32px;
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp .25s cubic-bezier(.4,0,.2,1);
}
.modal-sheet.center-modal {
  border-radius: 20px;
  padding: 24px 20px;
  max-height: 90dvh;
  animation: scaleIn .2s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes scaleIn { from { opacity:0; transform: scale(.95); } to { opacity:1; transform: none; } }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

/* ── Sub-view header ── */
.sub-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 0;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  padding-bottom: 4px;
}
.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.sub-header-title {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub-content {
  padding: 12px 16px 80px;
}

/* ── Dashboard specific ── */
.revenue-hero {
  background: var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  color: #fff;
}
.revenue-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .75;
  margin-bottom: 4px;
}
.revenue-amount {
  font-size: 38px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: -1px;
}
.revenue-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,.2);
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
}

.big-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 20px;
  transition: background .1s;
}
.big-btn:active { background: var(--surface2); }
.big-btn-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}
.big-btn-text { text-align: left; flex: 1; }
.big-btn-title { font-size: 15px; font-weight: 600; color: var(--text); }
.big-btn-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ── Attention items ── */
.attention-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  border-left: 4px solid var(--red);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.attention-item:active { background: var(--surface2); }
.attention-body { flex: 1; }
.attention-name { font-size: 15px; font-weight: 600; }
.attention-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }
.attention-amount { font-size: 16px; font-weight: 700; color: var(--red); font-family: var(--mono); }

/* ── Session items ── */
.session-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
  position: relative;
}
.session-item:active { background: var(--surface2); }
.session-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.session-body { flex: 1; min-width: 0; }
.session-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.session-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.session-amount { font-size: 15px; font-weight: 700; font-family: var(--mono); }

/* ── Package bar ── */
.pkg-bar-wrap {
  background: var(--surface2);
  border-radius: 100px;
  height: 6px;
  margin-top: 8px;
  overflow: hidden;
}
.pkg-bar-fill {
  height: 100%;
  border-radius: 100px;
  background: var(--accent);
  transition: width .4s ease;
}
.pkg-bar-fill.depleted { background: var(--red); }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  margin-bottom: 16px;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  height: 34px;
  padding: 0 14px;
  border-radius: 100px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all .15s;
}
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── Search ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: 48px;
  margin-bottom: 16px;
}
.search-bar svg { color: var(--text3); flex-shrink: 0; }
.search-bar input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  outline: none;
}
.search-bar input::placeholder { color: var(--text3); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text3);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-title { font-size: 18px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.empty-state-sub { font-size: 14px; }

/* ── Confirm dialog ── */
.confirm-dialog {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px 20px;
  width: 100%;
  max-width: 360px;
  animation: scaleIn .2s ease;
}
.confirm-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.confirm-msg { font-size: 15px; color: var(--text2); margin-bottom: 24px; line-height: 1.5; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }

/* ── Client detail ── */
.client-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.client-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.client-stat-label { font-size: 10px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--text3); margin-bottom: 4px; }
.client-stat-val { font-size: 22px; font-weight: 700; font-family: var(--mono); }

.quick-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.quick-actions .btn { flex: 1; font-size: 13px; }

/* ── Package card ── */
.pkg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.pkg-card:active { background: var(--surface2); }
.pkg-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.pkg-card-name { font-size: 16px; font-weight: 600; }
.pkg-card-meta { font-size: 13px; color: var(--text2); margin-top: 2px; }
.pkg-sessions { font-size: 13px; font-weight: 500; color: var(--text2); margin-top: 8px; }

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  animation: toastIn .25s ease, toastOut .25s ease 2.5s forwards;
  box-shadow: var(--shadow);
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes toastIn { from { opacity:0; transform: translateY(-12px); } to { opacity:1; transform: none; } }
@keyframes toastOut { to { opacity:0; transform: translateY(-8px); } }

/* ── Misc ── */
.mt-4 { margin-top: 16px; }
.mt-2 { margin-top: 8px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text2); font-size: 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.view-all-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.view-all-btn { font-size: 13px; font-weight: 600; color: var(--accent); background: none; border: none; cursor: pointer; padding: 4px 0; }

/* scrollbar */
.view::-webkit-scrollbar { width: 0; }
.sub-view::-webkit-scrollbar { width: 0; }
.modal-sheet::-webkit-scrollbar { width: 0; }
