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

:root {
  --bg:            #0a0a0f;
  --bg-secondary:  #111118;
  --surface:       #16161f;
  --surface-hover: #1e1e2a;
  --border:        #ffffff12;
  --border-strong: #ffffff20;
  --accent:        #7c6df5;
  --accent-hover:  #9083f7;
  --text-primary:  #f0f0f5;
  --text-secondary:#8888a0;
  --text-muted:    #55556a;
  --success:       #22c55e;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --radius:        8px;
  --radius-lg:     12px;
  --sidebar-w:     220px;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(124,109,245,0.12) 0%, transparent 70%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 48px 40px 40px;
}

.login-brand {
  text-align: center;
  margin-bottom: 36px;
}

.login-brand-name {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.login-brand-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-error {
  font-size: 13px;
  color: var(--danger);
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  display: none;
}

/* ─── App Layout ───────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  user-select: none;
  position: relative;
  transition: background 0.12s, color 0.12s;
  margin-bottom: 1px;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(124,109,245,0.12);
  color: var(--accent);
}

.nav-item .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  flex-shrink: 0;
}

.nav-item .badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 20px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-username {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.12s, background 0.12s;
  flex-shrink: 0;
}

.logout-btn:hover {
  color: var(--danger);
  background: rgba(239,68,68,0.08);
}

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.page {
  display: none;
  padding: 32px 36px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  flex-direction: column;
}

.page.active {
  display: flex;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.page-header p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ─── Hero Debt Counter ────────────────────────────────────────────────────── */
.debt-hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.debt-hero-left { flex: 1; min-width: 200px; }

.debt-hero-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: 10px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

.debt-hero-counter {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  font-size: 36px;
  font-weight: 600;
  color: var(--success);
  letter-spacing: -0.02em;
  text-shadow: 0 0 32px rgba(34,197,94,0.25);
  line-height: 1.1;
}

.debt-hero-rate {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.debt-hero-right { flex-shrink: 0; }

.debt-progress-wrap { min-width: 200px; }

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.progress-bar {
  height: 6px;
  background: var(--border-strong);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* ─── Stats Grid ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.stat-card-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  color: var(--text-muted);
  opacity: 0.5;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 8px;
  color: var(--text-primary);
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-card.stat-danger .stat-value  { color: var(--danger); }
.stat-card.stat-success .stat-value { color: var(--success); }
.stat-card.stat-accent .stat-value  { color: var(--accent); }
.stat-card.stat-warning .stat-value { color: var(--warning); }

/* ─── Section Title ────────────────────────────────────────────────────────── */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

/* ─── Table ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-hover); }

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-active  { background: rgba(34,197,94,0.1);   color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.badge-paused  { background: rgba(245,158,11,0.1);  color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }
.badge-paid    { background: rgba(124,109,245,0.1); color: var(--accent);  border: 1px solid rgba(124,109,245,0.2); }
.badge-overdue { background: rgba(239,68,68,0.1);   color: var(--danger);  border: 1px solid rgba(239,68,68,0.2); }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  height: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  padding: 0 14px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

textarea {
  height: auto;
  min-height: 80px;
  padding: 10px 14px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,109,245,0.12);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

select option {
  background: var(--surface);
  color: var(--text-primary);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  height: 36px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: background 0.12s, opacity 0.12s, transform 0.08s;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn:hover   { opacity: 0.88; }
.btn:active  { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); opacity: 1; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text-primary); opacity: 1; }

.btn-danger  { background: var(--danger); color: #fff; }

.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; }

.btn-full { width: 100%; justify-content: center; height: 40px; font-size: 14px; }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.12s, background 0.12s;
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
}

.modal-body   { padding: 22px 24px; }

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ─── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13.5px;
  min-width: 240px;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: toast-in 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: all;
}

.toast.success { border-color: rgba(34,197,94,0.3); }
.toast.error   { border-color: rgba(239,68,68,0.3); }

@keyframes toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ─── Notifications ────────────────────────────────────────────────────────── */
.notif-item {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  background: var(--surface);
  transition: background 0.12s;
}

.notif-item.unread {
  border-color: rgba(124,109,245,0.2);
  background: rgba(124,109,245,0.04);
}

.notif-icon {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  padding-top: 2px;
}

.notif-body   { flex: 1; }
.notif-msg    { font-size: 13.5px; color: var(--text-primary); }
.notif-time   { font-size: 12px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.notif-unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 6px;
}

/* ─── Repayment Plan ───────────────────────────────────────────────────────── */
.plan-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
}

.plan-order {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.plan-info { flex: 1; }
.plan-name { font-weight: 500; font-size: 14px; color: var(--text-primary); }
.plan-detail { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.plan-months { text-align: right; flex-shrink: 0; }
.plan-months-label { font-size: 11px; color: var(--text-muted); }
.plan-months-value { font-size: 14px; font-weight: 600; color: var(--success); margin-top: 2px; }

/* ─── Method Selector ──────────────────────────────────────────────────────── */
.method-select {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.method-btn {
  flex: 1;
  text-align: center;
  padding: 14px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  transition: all 0.12s;
  font-weight: 500;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text-muted);
}

.method-btn:hover:not(.active) {
  border-color: var(--border-strong);
  color: var(--text-secondary);
  background: var(--surface-hover);
}

.method-btn.active {
  border-color: rgba(124,109,245,0.4);
  color: var(--accent);
  background: rgba(124,109,245,0.08);
}

.method-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

/* ─── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-icon-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
  opacity: 0.35;
}

.empty-state p {
  font-size: 14px;
}

/* ─── Settings Cards ───────────────────────────────────────────────────────── */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ─── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Mobile Bottom Tab Bar ────────────────────────────────────────────────── */
.bottom-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px 6px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  gap: 3px;
  transition: color 0.12s;
  position: relative;
  user-select: none;
}

.tab-item.active { color: var(--accent); }

.tab-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.tab-notif-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  width: 6px;
  height: 6px;
  background: var(--danger);
  border-radius: 50%;
  border: 1px solid var(--bg-secondary);
  display: none;
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Utilities ────────────────────────────────────────────────────────────── */
.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-success   { color: var(--success); }
.text-danger    { color: var(--danger); }
.text-accent    { color: var(--accent); }
.fw-medium      { font-weight: 500; }
.fw-semibold    { font-weight: 600; }
.fw-bold        { font-weight: 700; }
.mt-4           { margin-top: 16px; }
.mb-4           { margin-bottom: 16px; }
.gap-2          { display: flex; gap: 8px; }
.flex-end       { justify-content: flex-end; }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { display: none; }

  .bottom-tabs { display: flex; }

  .main-content { padding-bottom: 64px; }

  .page { padding: 20px 16px; }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .debt-hero-card { padding: 20px; }
  .debt-hero-counter { font-size: 26px; }

  .form-row { grid-template-columns: 1fr; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
  }

  .method-select { flex-direction: column; }

  .plan-item { flex-wrap: wrap; }

  .modal { max-width: 100%; }
  .toast-container { bottom: 76px; right: 12px; left: 12px; }
  .toast { min-width: 0; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ─── Settings ──────────────────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
  max-width: 800px;
}
.settings-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.form-msg {
  display: none;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, currentColor 10%, transparent);
  margin-bottom: 12px;
}
