:root {
  --bg: #0b0f14;
  --surface: #141a22;
  --surface-elevated: #1c2430;
  --outline: #2a3441;
  --accent: #0d6efd;
  --accent2: #00c6ff;
  --profit: #17c964;
  --loss: #f31260;
  --amber: #f5a623;
  --text: #f5f7fa;
  --text-secondary: #9aa6b2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  direction: rtl;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

#content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.page-pad { padding: 16px; max-width: 640px; margin: 0 auto; }

/* ---------- Top Bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11,15,20,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--outline);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 8px;
}
.topbar-title { font-weight: 700; font-size: 17px; flex: 1; text-align: center; }
.topbar-side { min-width: 48px; display: flex; align-items: center; }
.topbar-actions { justify-content: flex-end; gap: 4px; }
.icon-btn {
  background: none; border: none; color: var(--text); font-size: 20px;
  padding: 8px; cursor: pointer; border-radius: 8px;
}
.icon-btn:active { background: var(--surface-elevated); }

/* ---------- Bottom Nav ---------- */
#bottomnav {
  display: none;
  position: sticky; bottom: 0; z-index: 20;
  background: rgba(11,15,20,0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--outline);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 8px 0 6px; text-decoration: none; color: var(--text-secondary);
  font-size: 11px;
}
.nav-item.active { color: var(--accent2); }
.nav-icon { font-size: 20px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 32px;
  background: radial-gradient(circle at 50% 20%, rgba(13,110,253,0.18), transparent 60%);
}
.login-logo {
  width: 84px; height: 84px; border-radius: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center; font-size: 40px;
  margin-bottom: 20px;
}
.login-screen h1 { margin: 0 0 8px; font-size: 24px; }
.login-status { margin-top: 16px; min-height: 20px; }

/* ---------- Cards / Stats ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface-elevated); border-radius: 16px; padding: 16px; }
.stat-label { color: var(--text-secondary); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-weight: 700; font-size: 17px; }
.stat-value.accent { color: var(--accent2); }
.stat-value.profit { color: var(--profit); }
.stat-value.loss { color: var(--loss); }

.section-title { font-weight: 700; font-size: 16px; margin: 20px 0 10px; }

.card {
  background: var(--surface-elevated); border-radius: 16px; padding: 16px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.card hr, hr { border: none; border-top: 1px solid var(--outline); margin: 10px 0; opacity: 0.5; }

/* ---------- Car Card ---------- */
.car-list { display: flex; flex-direction: column; gap: 10px; }
.car-card, .partner-card {
  background: var(--surface-elevated); border-radius: 16px; padding: 16px; cursor: pointer;
}
.car-card:active, .partner-card:active { opacity: 0.85; }
.car-card-top { display: flex; align-items: flex-start; justify-content: space-between; }
.car-title { font-weight: 700; font-size: 15px; }
.car-sub { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.car-card-bottom { display: flex; justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.06); }
.mini-label { color: var(--text-secondary); font-size: 11px; }

.badge { font-size: 11px; padding: 4px 10px; border-radius: 8px; white-space: nowrap; }
.badge-green { background: rgba(23,201,100,0.15); color: var(--profit); }
.badge-amber { background: rgba(245,166,35,0.15); color: var(--amber); }

.profit { color: var(--profit); }
.loss { color: var(--loss); }
.amber { color: var(--amber); }
.muted { color: var(--text-secondary); }

.empty-msg { color: var(--text-secondary); text-align: center; padding: 24px; font-size: 14px; }

/* ---------- Forms ---------- */
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--outline);
  color: var(--text); border-radius: 10px; padding: 12px 14px; font-size: 15px;
  font-family: inherit; direction: rtl;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  padding: 14px 20px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary:disabled { opacity: 0.6; }
.btn-outline {
  background: transparent; color: var(--text); border: 1px solid var(--outline);
  border-radius: 12px; padding: 14px 20px; font-size: 15px; cursor: pointer;
}
.full-width { width: 100%; display: block; }
.flex1 { flex: 1; }
.action-row { display: flex; gap: 10px; margin-bottom: 20px; }
.mb8 { margin-bottom: 8px; }

.fab {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; border: none; border-radius: 28px;
  padding: 14px 24px; font-weight: 700; font-size: 15px; box-shadow: 0 8px 24px rgba(13,110,253,0.4);
  cursor: pointer; z-index: 15;
}

/* ---------- Add Car Wizard ---------- */
.step-indicator { display: flex; gap: 4px; margin-bottom: 20px; }
.step-bar { flex: 1; height: 4px; border-radius: 2px; background: var(--outline); }
.step-bar.active { background: var(--accent); }

.partner-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.partner-name { flex: 1; font-size: 14px; }
.partner-name-input { flex: 1; }
.partner-pct-input { width: 80px; text-align: center; flex-shrink: 0; }

.pct-sum-box {
  border-radius: 12px; padding: 14px; margin-top: 16px; font-weight: 700; text-align: center;
  background: rgba(243,18,96,0.12); color: var(--loss);
}
.pct-sum-box.valid { background: rgba(23,201,100,0.12); color: var(--profit); }

.confirm-card { background: var(--surface); border-radius: 12px; padding: 14px; }
.confirm-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }

/* ---------- Partner / Expense tables ---------- */
.partner-table-header, .partner-table-row {
  display: grid; grid-template-columns: 2fr 1fr 1.2fr; font-size: 13px; padding: 6px 0;
}
.partner-table-header { color: var(--text-secondary); font-size: 11px; border-bottom: 1px solid var(--outline); padding-bottom: 8px; margin-bottom: 4px; }
.expense-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 14px; }
.expense-row:last-child { border-bottom: none; }

/* ---------- Documents ---------- */
.doc-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 14px;
}
.doc-row:last-child { border-bottom: none; }
.doc-actions { display: flex; gap: 6px; }
.doc-actions button {
  background: var(--surface); border: 1px solid var(--outline); color: var(--text);
  border-radius: 8px; width: 36px; height: 36px; font-size: 15px; cursor: pointer;
}

/* ---------- Category rows ---------- */
.add-category-row { display: flex; gap: 8px; margin-bottom: 12px; }
.add-category-row input { flex: 1; }
.btn-icon-add {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  width: 46px; font-size: 20px; cursor: pointer;
}
.category-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.category-delete-btn { background: none; border: none; color: var(--loss); font-size: 16px; cursor: pointer; }

/* ---------- Reports ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; }
.chip {
  flex-shrink: 0; background: var(--surface-elevated); color: var(--text); border: 1px solid var(--outline);
  border-radius: 20px; padding: 8px 16px; font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.totals-grid { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.total-item { text-align: right; }
.total-value { font-weight: 700; font-size: 15px; margin-top: 2px; }

/* ---------- Search ---------- */
.search-input { font-size: 16px; }

/* ---------- Misc ---------- */
.error-box {
  background: rgba(243,18,96,0.12); color: var(--loss); border-radius: 10px;
  padding: 12px 14px; font-size: 14px; margin-bottom: 12px;
}
.success-box {
  background: rgba(23,201,100,0.12); color: var(--profit); border-radius: 10px;
  padding: 12px 14px; font-size: 14px; margin-bottom: 12px;
}
.info-box {
  background: rgba(23,201,100,0.08); border-radius: 10px; padding: 12px 14px;
  font-size: 14px; margin-bottom: 16px;
}
.mini-note { color: var(--text-secondary); font-size: 12px; margin: 8px 0; }

.center-loading { display: flex; justify-content: center; padding: 60px 0; }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--outline); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.spinner.small { width: 20px; height: 20px; border-width: 2px; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: -80px; left: 50%; transform: translateX(-50%);
  background: var(--surface-elevated); color: var(--text); padding: 12px 20px;
  border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transition: bottom 0.3s ease; z-index: 100; max-width: 90vw;
}
.toast.show { bottom: 90px; }
.toast.error { background: var(--loss); color: #fff; }

/* ---------- Print (PDF export via browser print) ---------- */
@media print {
  #topbar, #bottomnav, .action-row, .fab, #print-btn, .toast { display: none !important; }
  body, #app { background: #fff; color: #000; }
  .card, .car-card { background: #fff; border: 1px solid #ccc; break-inside: avoid; }
}
