/* FinPilot — Main Stylesheet */
/* Font: Onest | Theme: Deep teal & warm neutrals */

:root {
  --primary:       #0ea5a0;
  --primary-dark:  #0b8a86;
  --primary-light: #e0f7f6;
  --accent:        #f59e0b;
  --success:       #22c55e;
  --danger:        #ef4444;
  --warning:       #f97316;
  --bg:            #f4f6f9;
  --surface:       #ffffff;
  --surface2:      #f8fafc;
  --border:        #e5e9f0;
  --text:          #1a2332;
  --text-muted:    #7a8898;
  --text-light:    #b0bac8;
  --sidebar-bg:    #0f1e2e;
  --sidebar-text:  #c8d8e8;
  --sidebar-hover: rgba(255,255,255,0.07);
  --sidebar-active:#0ea5a0;
  --sidebar-w:     240px;
  --topbar-h:      56px;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow-sm:     0 1px 4px rgba(0,0,0,0.06);
  --shadow:        0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg:     0 8px 32px rgba(0,0,0,0.12);
  --transition:    0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Onest', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* =========================================
   SIDEBAR
   ========================================= */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(0);
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  margin: 8px 8px 4px;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 14px;
  flex-shrink: 0;
}

.user-name { font-size: 0.85rem; font-weight: 600; color: #fff; }
.user-phone { font-size: 0.72rem; color: var(--sidebar-text); }

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: none; background: transparent; width: 100%; text-align: left;
}

.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: rgba(14,165,160,0.2);
  color: #fff;
  border-left: 3px solid var(--primary);
  padding-left: 9px;
}

.nav-icon { font-size: 1.1rem; flex-shrink: 0; }

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.nav-logout { color: #f87171; }
.nav-logout:hover { background: rgba(239,68,68,0.1); color: #ef4444; }

/* =========================================
   MAIN WRAPPER
   ========================================= */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin var(--transition);
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.burger-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.burger-btn span {
  display: block;
  width: 22px; height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: var(--transition);
}

.page-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

.tg-badge {
  display: flex; align-items: center;
  padding: 6px;
  border-radius: 8px;
  background: #e8f4fd;
  text-decoration: none;
  transition: var(--transition);
}
.tg-badge:hover { background: #d0eaf9; }

.page-content {
  flex: 1;
  padding: 20px;
  max-width: 1200px;
  width: 100%;
}

/* =========================================
   CARDS
   ========================================= */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.card-body { padding: 20px; }

/* =========================================
   STAT CARDS
   ========================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card.income { border-top: 3px solid var(--success); }
.stat-card.expense { border-top: 3px solid var(--danger); }
.stat-card.balance { border-top: 3px solid var(--primary); }

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.stat-amount {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-amount.income { color: var(--success); }
.stat-amount.expense { color: var(--danger); }
.stat-icon { font-size: 1.4rem; margin-bottom: 4px; }

/* =========================================
   BUTTONS
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}

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

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.9); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }

.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-icon { padding: 7px; }

/* =========================================
   FORMS
   ========================================= */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition);
  -webkit-appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,165,160,0.12);
}

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 70px; }

/* Radio type selector */
.type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.type-radio { display: none; }
.type-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  transition: all var(--transition);
  text-align: center;
}

.type-radio[value="income"]:checked + .type-label {
  border-color: var(--success);
  background: rgba(34,197,94,0.08);
  color: var(--success);
}

.type-radio[value="expense"]:checked + .type-label {
  border-color: var(--danger);
  background: rgba(239,68,68,0.08);
  color: var(--danger);
}

/* =========================================
   TABLE
   ========================================= */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--surface2);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

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

tbody td {
  padding: 10px 14px;
  color: var(--text);
  vertical-align: middle;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-income { background: rgba(34,197,94,0.12); color: var(--success); }
.badge-expense { background: rgba(239,68,68,0.12); color: var(--danger); }

.amount-income { color: var(--success); font-weight: 600; }
.amount-expense { color: var(--danger); font-weight: 600; }

.actions-cell {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}

/* =========================================
   MODAL
   ========================================= */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  display: none;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius); max-height: 88vh; }
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-title { flex: 1; font-size: 1rem; font-weight: 700; }

.modal-close {
  background: var(--bg);
  border: none;
  border-radius: 8px;
  width: 30px; height: 30px;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.modal-close:hover { background: var(--border); }

.modal-body { padding: 20px; }

/* =========================================
   BUDGET PROGRESS
   ========================================= */
.category-budget-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.budget-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.budget-icon { font-size: 1.2rem; }

.budget-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.budget-amounts {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}

.budget-amounts strong { color: var(--text); }

.progress-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
  min-width: 3px;
}

.progress-bar.green { background: var(--success); }
.progress-bar.orange { background: var(--warning); }
.progress-bar.red { background: var(--danger); }
.progress-bar.gradient-danger {
  background: linear-gradient(to right, var(--warning), var(--danger));
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pct-label { font-weight: 700; }
.pct-label.over { color: var(--danger); }
.pct-label.warn { color: var(--warning); }
.pct-label.ok   { color: var(--success); }

/* Inline budget input */
.inline-budget-input {
  width: 90px;
  padding: 2px 6px;
  border: 1.5px dashed var(--border);
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  background: transparent;
  text-align: right;
  cursor: text;
  transition: border-color var(--transition), background var(--transition);
}
.inline-budget-input:hover { border-color: var(--primary); background: var(--primary-light); }
.inline-budget-input:focus { outline: none; border-color: var(--primary); border-style: solid; background: var(--surface); }
.inline-budget-input::placeholder { color: var(--text-light); font-weight: 400; font-style: italic; }

/* Remove number input arrows */
.inline-budget-input::-webkit-outer-spin-button,
.inline-budget-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.inline-budget-input[type=number] { -moz-appearance: textfield; }

/* =========================================
   MONTH PICKER
   ========================================= */
.month-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  margin-bottom: 18px;
}

.month-picker select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.month-picker select:focus { outline: none; }

/* =========================================
   EMPTY STATE
   ========================================= */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: 10px; opacity: 0.5; }
.empty-state p { font-size: 0.9rem; }

/* =========================================
   FILTER ROW
   ========================================= */
.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filter-row .form-control {
  flex: 1;
  min-width: 120px;
}

/* =========================================
   OVERLAY
   ========================================= */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}

/* =========================================
   LOGIN PAGE
   ========================================= */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1e2e 0%, #1a3a4e 50%, #0ea5a0 100%);
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo-icon {
  width: 60px; height: 60px;
  background: var(--primary);
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; color: #fff;
  margin: 0 auto 12px;
}

.login-logo h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
}

.login-logo p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.phone-input-wrap {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--transition);
}

.phone-input-wrap:focus-within { border-color: var(--primary); }

.phone-prefix {
  padding: 10px 12px;
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.phone-input-wrap .form-control {
  border: none;
  border-radius: 0;
}
.phone-input-wrap .form-control:focus { box-shadow: none; }

/* OTP inputs */
.otp-wrap {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.otp-input {
  width: 46px; height: 52px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  transition: border-color var(--transition);
}

.otp-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,165,160,0.12);
}

.resend-timer { text-align: center; font-size: 0.82rem; color: var(--text-muted); margin-top: 10px; }
.resend-link { color: var(--primary); cursor: pointer; font-weight: 600; }

/* =========================================
   RESPONSIVE - MOBILE
   ========================================= */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-overlay.open { display: block; }

  .main-wrapper { margin-left: 0; }

  .burger-btn { display: flex; }

  .page-content { padding: 12px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid .stat-card:last-child { grid-column: 1 / -1; }

  .stat-amount { font-size: 1.1rem; }

  thead th:nth-child(4),
  tbody td:nth-child(4) { display: none; } /* hide comment on mobile */

  .actions-cell { gap: 2px; }
  .btn-sm { padding: 4px 7px; font-size: 0.72rem; }

  .filter-row { gap: 6px; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stats-grid .stat-card:last-child { grid-column: auto; }
}

/* =========================================
   ALERTS / TOASTS
   ========================================= */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 300px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: #1a2332;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); color: #fff; }

@keyframes toastIn {
  from { transform: translateX(30px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* Telegram WebApp adaptations */
.tg-webapp .topbar { display: none; }
.tg-webapp .sidebar { display: none; }
.tg-webapp .main-wrapper { margin-left: 0; }
.tg-webapp .page-content { padding: 10px; }

/* Loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.btn.loading .spinner { display: inline-block; }
.btn.loading span:not(.spinner) { display: none; }
