@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
  --bg: #0D0D0D;
  --bg-card: #161616;
  --bg-card-2: #1E1E1E;
  --border: #2A2A2A;
  --border-light: #333;

  --gold: #FFD700;
  --gold-dim: rgba(255, 215, 0, 0.12);
  --green: #00C853;
  --green-dim: rgba(0, 200, 83, 0.1);
  --red: #FF3D00;
  --red-dim: rgba(255, 61, 0, 0.1);
  --blue: #2979FF;
  --blue-dim: rgba(41, 121, 255, 0.1);
  --purple: #AA00FF;
  --purple-dim: rgba(170, 0, 255, 0.1);

  --text: #FFFFFF;
  --text-2: #AAAAAA;
  --text-3: #666666;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;

  --tab-h: 64px;
  --header-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  min-height: 100vh;
  overscroll-behavior: none;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 0; }

/* ── LAYOUT ── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: rgba(13,13,13,0.92);
  backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.header-title { font-size: 17px; font-weight: 700; }
.header-logo { color: var(--gold); font-size: 20px; }

.content {
  flex: 1;
  padding: 16px 16px calc(var(--tab-h) + 16px);
  overflow-y: auto;
}

/* ── TAB BAR ── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--tab-h);
  background: rgba(22,22,22,0.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--text-3);
  font-family: inherit;
  font-size: 10px; font-weight: 500;
  transition: color 0.2s;
}
.tab-btn.active { color: var(--gold); }
.tab-btn .icon { font-size: 22px; line-height: 1; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── CARDS ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-sm { padding: 12px; }

.card-2col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-bottom: 12px;
}

/* ── METRIC CARD ── */
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.metric-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.metric-card.green::before { background: var(--green); }
.metric-card.red::before { background: var(--red); }
.metric-card.blue::before { background: var(--blue); }
.metric-card.gold::before { background: var(--gold); }

.metric-label {
  font-size: 11px; font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.metric-value {
  font-size: 22px; font-weight: 800;
  line-height: 1.1;
}
.metric-value.green { color: var(--green); }
.metric-value.red { color: var(--red); }
.metric-value.blue { color: var(--blue); }
.metric-value.gold { color: var(--gold); }
.metric-sub {
  font-size: 12px; color: var(--text-3);
  margin-top: 4px;
}

/* ── HERO CARD ── */
.hero-card {
  background: linear-gradient(135deg, #1A1A0A 0%, #1A1500 100%);
  border: 1px solid rgba(255,215,0,0.2);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.hero-left {}
.hero-label { font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.hero-value { font-size: 32px; font-weight: 900; color: var(--gold); line-height: 1; }
.hero-sub { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* ── GAUGE ── */
.gauge-wrap { position: relative; width: 80px; height: 80px; flex-shrink: 0; }
.gauge-wrap svg { width: 80px; height: 80px; transform: rotate(-90deg); }
.gauge-bg { fill: none; stroke: var(--border); stroke-width: 8; }
.gauge-fill { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 1s ease; }
.gauge-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; color: var(--gold);
  line-height: 1;
}
.gauge-sub { font-size: 9px; color: var(--text-3); margin-top: 2px; }

/* ── SECTION TITLE ── */
.section-title {
  font-size: 13px; font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin: 20px 0 10px;
}

/* ── CHART CONTAINER ── */
.chart-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.chart-wrap canvas { max-height: 200px; }

/* ── PROGRESS BAR ── */
.progress-item { margin-bottom: 12px; }
.progress-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.progress-label { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.progress-value { font-size: 13px; font-weight: 700; }
.progress-track {
  height: 6px;
  background: var(--bg-card-2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.8s ease;
}

/* ── PARTNER PAYOUT ROW ── */
.payout-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.payout-row:last-child { border-bottom: none; }
.payout-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.payout-amount { font-size: 15px; font-weight: 700; color: var(--gold); }

/* ── ALERT ── */
.alert {
  background: rgba(255, 61, 0, 0.08);
  border: 1px solid rgba(255, 61, 0, 0.25);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.alert-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--red);
  margin-bottom: 10px;
}
.alert-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,61,0,0.1);
}
.alert-item:last-child { border-bottom: none; }
.alert-name { color: var(--text); font-weight: 500; }
.alert-days { color: var(--red); font-weight: 700; font-size: 12px; }

/* ── MONTH NAV ── */
.month-nav {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-bottom: 16px;
}
.month-nav-btn {
  width: 36px; height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}
.month-nav-btn:hover { background: var(--bg-card-2); border-color: var(--gold); }
.month-nav-title { font-size: 17px; font-weight: 700; min-width: 160px; text-align: center; }

/* ── CLIENT CARD ── */
.client-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.client-card:hover { border-color: var(--gold); }
.client-card.expiring-soon { border-color: rgba(255,61,0,0.4); }
.client-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.client-name { font-size: 15px; font-weight: 700; }
.client-badge {
  font-size: 10px; font-weight: 700;
  padding: 3px 8px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.badge-td { background: rgba(170,0,255,0.15); color: #CC44FF; }
.badge-club { background: rgba(41,121,255,0.15); color: var(--blue); }
.badge-op { background: rgba(255,215,0,0.15); color: var(--gold); }
.badge-other { background: var(--bg-card-2); color: var(--text-2); }
.client-meta { font-size: 12px; color: var(--text-2); display: flex; gap: 12px; margin-bottom: 10px; }
.client-access { font-size: 12px; margin-bottom: 6px; display: flex; justify-content: space-between; }
.client-access-label { color: var(--text-3); }
.client-access-date { font-weight: 600; }
.access-bar-track { height: 4px; background: var(--bg-card-2); border-radius: 99px; overflow: hidden; }
.access-bar-fill { height: 100%; border-radius: 99px; transition: width 0.6s ease; }
.client-amount { font-size: 13px; color: var(--text-2); margin-top: 8px; }
.client-amount strong { color: var(--green); }

/* ── FILTER TABS ── */
.filter-tabs {
  display: flex; gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.filter-tab {
  flex-shrink: 0;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-2);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}
.filter-tab.active {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--gold);
}

/* ── SEARCH ── */
.search-wrap { position: relative; margin-bottom: 14px; }
.search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px 11px 38px;
  color: var(--text);
  font-family: inherit; font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--gold); }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-size: 16px;
}

/* ── ACTION BUTTONS ── */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.action-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 20px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  color: var(--text);
}
.action-btn:hover { border-color: var(--gold); background: var(--gold-dim); }
.action-btn:active { transform: scale(0.97); }
.action-btn .btn-icon { font-size: 28px; line-height: 1; }
.action-btn .btn-label { font-size: 13px; font-weight: 600; }
.action-btn.green { border-color: rgba(0,200,83,0.3); }
.action-btn.green:hover { border-color: var(--green); background: var(--green-dim); }
.action-btn.red { border-color: rgba(255,61,0,0.3); }
.action-btn.red:hover { border-color: var(--red); background: var(--red-dim); }
.action-btn.gold { border-color: rgba(255,215,0,0.3); }
.action-btn.gold:hover { border-color: var(--gold); background: var(--gold-dim); }
.action-btn.blue { border-color: rgba(41,121,255,0.3); }
.action-btn.blue:hover { border-color: var(--blue); background: var(--blue-dim); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-handle {
  width: 36px; height: 4px;
  background: var(--border-light);
  border-radius: 99px;
  margin: 0 auto 20px;
}
.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 20px; }

/* ── FORM ── */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; display: block; }
.form-input, .form-select {
  width: 100%;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-family: inherit; font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  appearance: none;
}
.form-input:focus, .form-select:focus { border-color: var(--gold); }
.form-input::placeholder { color: var(--text-3); }
.form-select option { background: var(--bg-card); }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 14px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.2s;
}
.chip.selected { background: var(--gold-dim); border-color: var(--gold); color: var(--gold); }

.submit-btn {
  width: 100%;
  padding: 15px;
  background: var(--gold);
  border: none; border-radius: var(--radius-sm);
  color: #000;
  font-family: inherit; font-size: 15px; font-weight: 800;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s, transform 0.1s;
}
.submit-btn:hover { opacity: 0.9; }
.submit-btn:active { transform: scale(0.98); }

/* ── YEAR TABLE ── */
.year-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.year-table th {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.4px;
  padding: 8px 6px; text-align: right;
}
.year-table th:first-child { text-align: left; }
.year-table td { padding: 9px 6px; border-top: 1px solid var(--border); text-align: right; }
.year-table td:first-child { text-align: left; font-weight: 600; }
.year-table .positive { color: var(--green); font-weight: 700; }
.year-table .negative { color: var(--red); }
.year-table tr:last-child td { color: var(--gold); font-weight: 700; border-top: 2px solid var(--gold); }

/* ── LOADING ── */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  color: var(--text-3); font-size: 14px; gap: 10px;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--text-3);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: calc(var(--tab-h) + 16px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1E1E1E; border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 14px; font-weight: 500;
  white-space: nowrap; z-index: 300;
  opacity: 0; transition: all 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ── ANIMATIONS ── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s ease forwards; }

/* ── PERIOD SELECTOR ── */
.period-selector { padding: 10px 16px 0; }
.period-mode-tabs {
  display: flex; gap: 4px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 3px;
  margin-bottom: 10px;
}
.period-mode-btn {
  flex: 1; padding: 6px; background: none; border: none;
  border-radius: 8px; color: var(--text-3);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.period-mode-btn.active { background: var(--gold); color: #000; }

.range-nav {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.range-input { flex: 1; padding: 8px 10px; font-size: 13px; }
.range-apply-btn {
  width: 36px; height: 36px; background: var(--gold); border: none;
  border-radius: var(--radius-xs); color: #000; font-size: 14px;
  cursor: pointer; flex-shrink: 0;
}

/* ── HISTORY ── */
.history-item {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-left { display: flex; gap: 10px; flex: 1; min-width: 0; }
.history-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.history-info { flex: 1; min-width: 0; }
.history-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.history-comment { font-size: 11px; color: var(--text-3); margin-top: 2px; font-style: italic; }
.history-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; margin-left: 8px; }
.history-amount { font-size: 14px; font-weight: 700; white-space: nowrap; }
.history-actions { display: flex; gap: 4px; }

/* ── ICON BUTTONS ── */
.icon-btn {
  width: 30px; height: 30px; background: var(--bg-card-2); border: 1px solid var(--border);
  border-radius: var(--radius-xs); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--gold); }
.icon-btn.danger:hover { border-color: var(--red); }

/* ── SMALL BUTTON ── */
.small-btn {
  padding: 5px 12px; background: var(--gold-dim); border: 1px solid var(--gold);
  border-radius: var(--radius-xs); color: var(--gold);
  font-family: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.small-btn.secondary { background: var(--bg-card-2); border-color: var(--border); color: var(--text-3); }

/* ── RECURRING ── */
.recurring-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.recurring-item:last-child { border-bottom: none; }
.recurring-item.inactive { opacity: 0.4; }
.recurring-info { flex: 1; min-width: 0; }
.recurring-name { font-size: 14px; font-weight: 600; }
.recurring-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.recurring-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; margin-left: 8px; }
