:root, html[data-theme="light"] {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --bg-card: #ffffff;
  --bg-page: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-on-dark: #f8fafc;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --primary-soft: #eef2ff;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #ea580c;
  --warning-soft: #ffedd5;
  --info: #0284c7;
  --info-soft: #e0f2fe;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow: 0 4px 16px rgba(15,23,42,.08);
  --shadow-lg: 0 12px 40px rgba(15,23,42,.12);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 260px;
}

html[data-theme="dark"] {
  --bg-card: #1e293b;
  --bg-page: #0f172a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary-soft: #312e81;
  --success-soft: #14532d;
  --danger-soft: #7f1d1d;
  --warning-soft: #7c2d12;
  --info-soft: #0c4a6e;
  --border: #334155;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}
html[data-theme="dark"] body { background: var(--bg-page); color: var(--text); }
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .topbar-search input {
  background: #1e293b; color: var(--text); border-color: var(--border);
}
html[data-theme="dark"] .form-control::placeholder { color: var(--text-muted); }
html[data-theme="dark"] .topbar { background: var(--bg-page); }
html[data-theme="dark"] .notif-panel,
html[data-theme="dark"] .search-results,
html[data-theme="dark"] .modal-content { background: var(--bg-card); color: var(--text); }
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer { border-color: var(--border); }
html[data-theme="dark"] .btn-icon { background: var(--bg-card); border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .lang-switch { background: var(--bg-card); border-color: var(--border); }
html[data-theme="dark"] .tbl thead th { background: var(--bg-page); color: var(--text-muted); }
html[data-theme="dark"] .tbl tbody tr:hover { background: rgba(255,255,255,.04); }
html[data-theme="dark"] code { background: #1a2233; color: #fcd34d; padding: 1px 6px; border-radius: 4px; }

html[data-lang="fa"] body { font-family: "Vazirmatn", "Segoe UI", system-ui, sans-serif; }
html[data-lang="de"] body { font-family: "Inter", "Segoe UI", system-ui, sans-serif; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  inset-inline-start: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  box-shadow: 0 0 30px rgba(0,0,0,.2);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(99,102,241,.4);
}
.brand-title { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; opacity: .7; }

.nav-menu { list-style: none; padding: 12px 10px; margin: 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: rgba(248,250,252,.7);
  font-size: 14px;
  transition: all .15s ease;
  margin-bottom: 2px;
}
.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: var(--text-on-dark);
}
.nav-item.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  box-shadow: 0 4px 12px rgba(99,102,241,.35);
}
.nav-item i { font-size: 18px; }

/* ===== Main ===== */
.main {
  margin-inline-start: var(--sidebar-w);
  min-height: 100vh;
  padding: 0 24px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg-page);
  z-index: 50;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: white;
  border: 1px solid var(--border);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.topbar-search {
  position: relative;
  flex: 1;
  max-width: 520px;
}
.topbar-search i {
  position: absolute;
  inset-inline-start: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.topbar-search input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding-inline-start: 42px;
  padding-inline-end: 16px;
  background: white;
  font-size: 14px;
  outline: none;
  transition: all .15s;
}
.topbar-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.search-results {
  position: absolute;
  top: 48px;
  inset-inline-start: 0;
  width: 100%;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 500px;
  overflow-y: auto;
  z-index: 60;
  display: none;
}
.search-results.show { display: block; }
.search-group-title {
  padding: 8px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  background: var(--bg-page);
}
.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.search-item:hover { background: var(--bg-page); }

.topbar-actions { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; }
.notif-wrap { position: relative; }
.notif-btn { display: flex; position: relative; }
.notif-badge {
  position: absolute; top: -4px; inset-inline-end: -4px;
  background: var(--danger); color: white;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
}
.notif-panel {
  position: absolute; top: 48px; inset-inline-end: 0;
  width: 380px; max-width: calc(100vw - 24px);
  background: white; border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg);
  max-height: 70vh; overflow: hidden; display: none;
  z-index: 60; flex-direction: column;
}
.notif-panel.show { display: flex; }
.notif-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700;
}
.notif-list { overflow-y: auto; flex: 1; }
.notif-item {
  display: grid; grid-template-columns: 36px 1fr auto;
  gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border);
  align-items: center;
}
.notif-item:hover { background: var(--bg-page); }
.notif-item:last-child { border-bottom: none; }
.notif-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.notif-icon.danger { background: var(--danger-soft); color: var(--danger); }
.notif-icon.warning { background: var(--warning-soft); color: var(--warning); }
.notif-icon.info { background: var(--info-soft); color: var(--info); }
.notif-icon.success { background: var(--success-soft); color: var(--success); }
.notif-title { font-weight: 600; font-size: 13px; }
.notif-sub { font-size: 11.5px; color: var(--text-muted); }
.notif-amount { font-weight: 700; font-size: 13px; }
.notif-actions { padding: 8px 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

.lang-switch {
  display: flex;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.lang-btn {
  border: none;
  background: transparent;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.lang-btn.active { background: var(--primary); color: white; }

/* ===== Cards / Layout ===== */
.page-title {
  font-size: 22px;
  font-weight: 700;
  margin: 6px 0 18px;
}
.card-x {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* ===== KPI ===== */
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.5px;
}
.kpi-trend { margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }
.kpi-icon {
  position: absolute;
  inset-inline-end: 14px;
  top: 14px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: var(--primary-soft);
  color: var(--primary);
}
.kpi.kpi-success .kpi-icon { background: var(--success-soft); color: var(--success); }
.kpi.kpi-danger .kpi-icon { background: var(--danger-soft); color: var(--danger); }
.kpi.kpi-warning .kpi-icon { background: var(--warning-soft); color: var(--warning); }

/* ===== Member chips ===== */
.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

/* ===== Tables ===== */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
.tbl thead th {
  text-align: start;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-page);
}
.tbl tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
.tbl tbody tr:hover { background: var(--bg-page); }
.tbl tbody tr:last-child td { border-bottom: none; }
.amount-in { color: var(--success); font-weight: 700; }
.amount-out { color: var(--danger); font-weight: 700; }

/* ===== Alerts ===== */
.alert-x {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13.5px;
}
.alert-x.info { background: var(--info-soft); color: var(--info); }
.alert-x.danger { background: var(--danger-soft); color: var(--danger); }
.alert-x.warning { background: var(--warning-soft); color: var(--warning); }
.alert-x.success { background: var(--success-soft); color: var(--success); }

/* ===== Buttons ===== */
.btn-soft {
  background: var(--primary-soft);
  color: var(--primary);
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  font-weight: 600;
}
.btn-soft:hover { background: var(--primary); color: white; }
.btn-soft.danger { background: var(--danger-soft); color: var(--danger); }
.btn-soft.danger:hover { background: var(--danger); color: white; }
.btn-soft.success { background: var(--success-soft); color: var(--success); }
.btn-soft.success:hover { background: var(--success); color: white; }

.row-actions { display: flex; gap: 6px; }

/* ===== Forms ===== */
.form-label { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.form-control, .form-select { font-size: 14px; }

/* ===== Calendar ===== */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 0;
}
.cal-day {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  min-height: 90px;
  font-size: 12px;
  position: relative;
  cursor: pointer;
}
.cal-day:hover { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.cal-day.has-items { background: linear-gradient(180deg, #fff 60%, #f8fafc 100%); }

/* ===== Bank letter avatar ===== */
.bank-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  color: white; font-weight: 700;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  letter-spacing: -0.5px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  flex-shrink: 0;
}
.bank-avatar.sm { width: 28px; height: 28px; font-size: 10px; }
.bank-avatar.md { font-size: 13px; }
.bank-avatar.lg { width: 48px; height: 48px; font-size: 16px; }
.bank-avatar.emoji { font-size: 22px; background: white !important; color: inherit; border: 1px solid var(--border); }
html[data-theme="dark"] .bank-avatar.emoji { background: #0f172a !important; }

/* ===== Sidebar section headers ===== */
.nav-section {
  list-style: none;
  padding: 14px 16px 4px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
  color: rgba(248,250,252,.4);
  margin-top: 6px;
}

/* ===== Member select in topbar ===== */
.member-select { font-size: 12px; height: 34px; }

/* ===== PIN overlay ===== */
.pin-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(135deg, #0f172a 0%, #312e81 100%);
  display: flex; align-items: center; justify-content: center;
}
.pin-box {
  background: white; padding: 32px; border-radius: 20px;
  box-shadow: 0 30px 60px rgba(0,0,0,.5);
  width: 320px; max-width: 90%; text-align: center;
}
.pin-logo { font-size: 56px; margin-bottom: 8px; }
.pin-error { color: var(--danger); font-size: 13px; margin-top: 8px; }
html[data-theme="dark"] .pin-box { background: #1e293b; color: white; }

/* ===== Goal progress ===== */
.goal-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
  position: relative; overflow: hidden;
}
.goal-header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.goal-icon { width: 44px; height: 44px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 22px; }
.goal-title { font-weight: 700; font-size: 16px; flex: 1; }
.goal-progress-track {
  height: 10px; background: var(--bg-page); border-radius: 6px; overflow: hidden;
}
.goal-progress-fill { height: 100%; border-radius: 6px; transition: width .4s; }
.goal-meta { display: flex; justify-content: space-between; font-size: 12px;
  color: var(--text-muted); margin-top: 6px; }

/* ===== Budget progress ===== */
.budget-row {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 10px;
}
.budget-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.budget-bar-track {
  height: 12px; background: var(--bg-page); border-radius: 6px; overflow: hidden;
}
.budget-bar-fill { height: 100%; border-radius: 6px; transition: width .4s; }
.budget-meta { display: flex; justify-content: space-between; font-size: 12px;
  color: var(--text-muted); margin-top: 6px; }
.budget-row.over .budget-bar-fill { background: var(--danger) !important; }

/* ===== Vehicle card ===== */
.vehicle-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 14px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center;
}
.vehicle-icon { width: 60px; height: 60px; border-radius: 14px; display: flex;
  align-items: center; justify-content: center; font-size: 32px; color: white; }
.vehicle-plate {
  background: white; color: #000; padding: 4px 10px; border: 2px solid #000;
  border-radius: 4px; font-family: "Courier New", monospace; font-weight: 700;
  font-size: 14px; display: inline-block; letter-spacing: 1px;
}

/* ===== Warranty card ===== */
.warranty-row {
  background: var(--bg-card); border: 1px solid var(--border);
  border-inline-start: 4px solid var(--success);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
  display: grid; grid-template-columns: 36px 1fr auto auto; gap: 12px; align-items: center;
}
.warranty-row.warn { border-inline-start-color: var(--warning); }
.warranty-row.expired { border-inline-start-color: var(--danger); opacity: .7; }
.warranty-days { font-size: 11px; color: var(--text-muted); }
.warranty-days.warn { color: var(--warning); font-weight: 700; }
.warranty-days.danger { color: var(--danger); font-weight: 700; }

/* ===== Net worth ===== */
.networth-hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  color: white; border-radius: var(--radius); padding: 28px; margin-bottom: 18px;
  text-align: center;
}
.networth-hero .label { font-size: 14px; opacity: .85; }
.networth-hero .value { font-size: 40px; font-weight: 800; letter-spacing: -1px; margin: 6px 0; }

/* ===== Receipt scan modal area ===== */
.ocr-box {
  background: var(--bg-page); border: 2px dashed var(--border);
  padding: 18px; border-radius: 12px; text-align: center;
}
.ocr-result { background: var(--bg-card); padding: 10px; border-radius: 8px;
  margin-top: 10px; font-size: 11px; max-height: 120px; overflow-y: auto;
  text-align: start; white-space: pre-wrap; font-family: monospace; }

/* ===== Member card grid ===== */
.member-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; text-align: center;
  cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.member-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }
.member-card-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; margin: 0 auto;
  box-shadow: 0 6px 14px rgba(0,0,0,.15);
}

/* ===== Profile header ===== */
.profile-header {
  display: flex; align-items: center; gap: 18px;
  padding: 22px; border-radius: var(--radius);
  color: white; margin: 14px 0 18px;
  box-shadow: var(--shadow);
}
.profile-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: rgba(255,255,255,.2); display: flex;
  align-items: center; justify-content: center;
  font-size: 36px; flex-shrink: 0;
}
.profile-info { flex: 1; }

/* ===== Profile tabs ===== */
.profile-tabs {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.profile-tab {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.profile-tab:hover { border-color: var(--primary); color: var(--primary); }
.profile-tab.active {
  background: var(--primary); color: white; border-color: var(--primary);
}
.tab-count {
  background: rgba(255,255,255,.25);
  padding: 1px 7px; border-radius: 10px; font-size: 11px;
}
.profile-tab:not(.active) .tab-count {
  background: var(--bg-page); color: var(--text-muted);
}

/* ===== Profile info grid ===== */
.profile-section { padding-bottom: 14px; }
.profile-section h5 {
  font-size: 14px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin: 0 0 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.info-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (max-width: 700px) { .info-grid { grid-template-columns: 1fr; } }
.info-item {}
.info-label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: 2px;
}
.info-value { font-size: 14px; font-weight: 500; }
.info-value code { background: var(--bg-page); padding: 2px 8px; border-radius: 4px; font-size: 13px; }

/* ===== Reference hub cards ===== */
.ref-card {
  position: relative;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 30px;
  display: grid; grid-template-columns: 64px 1fr auto; gap: 16px; align-items: center;
  cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s;
  overflow: hidden;
}
.ref-card::before {
  content: ""; position: absolute; top: 0; inset-inline-start: 0; inset-inline-end: 0;
  height: 3px; background: var(--ref-accent, var(--primary));
  opacity: 0; transition: opacity .15s;
}
.ref-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,.08));
  border-color: var(--ref-accent, var(--primary));
}
.ref-card:hover::before { opacity: 1; }
.ref-icon {
  width: 56px; height: 56px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.ref-body { min-width: 0; }
.ref-body h4 { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.ref-body p { margin: 0; font-size: 12px; line-height: 1.4; }
.ref-count-pill {
  align-self: start; padding: 4px 10px; border-radius: 999px;
  font-weight: 700; font-size: 12px; white-space: nowrap;
}
.ref-edit-hint {
  position: absolute; bottom: 8px; inset-inline-end: 14px;
  font-size: 11px; color: var(--text-muted); opacity: 0;
  transition: opacity .15s, transform .15s;
  transform: translateX(0);
}
.ref-card:hover .ref-edit-hint { opacity: 1; color: var(--ref-accent, var(--primary)); }

/* ===== Reference hub sections ===== */
.ref-hub-search {
  position: relative; margin-bottom: 22px; max-width: 520px;
}
.ref-hub-search i {
  position: absolute; inset-inline-start: 14px; top: 50%;
  transform: translateY(-50%); color: var(--text-muted);
}
.ref-hub-search input {
  width: 100%; height: 42px;
  border: 1px solid var(--border); border-radius: 12px;
  padding-inline-start: 42px; padding-inline-end: 16px;
  background: white; font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.ref-hub-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
html[data-theme="dark"] .ref-hub-search input { background: #1e293b; color: var(--text); }
.ref-hub-section { margin-bottom: 28px; }
.ref-hub-section-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 2px solid var(--section-accent, var(--border));
}
.ref-hub-section-emoji { font-size: 22px; line-height: 1; }
.ref-hub-section-title {
  margin: 0; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; gap: 8px; flex: 1;
}
.ref-hub-section-title .rhs-fa { order: 2; }
.ref-hub-section-title .rhs-sep { order: 1; color: var(--text-muted); font-weight: 400; }
.ref-hub-section-title .rhs-de { order: 0; color: var(--text-muted); font-weight: 500; font-size: 14px; }
html[dir="rtl"] .ref-hub-section-title .rhs-fa { order: 0; }
html[dir="rtl"] .ref-hub-section-title .rhs-de { order: 2; }
.ref-hub-section-count {
  font-size: 12px; color: var(--text-muted);
  padding: 4px 10px; border-radius: 999px;
  background: var(--bg-page); white-space: nowrap;
}

/* ===== Tom Select tweaks ===== */
.ts-wrapper { font-family: inherit; }
.ts-control { border-color: var(--border) !important; background: white !important; min-height: 38px !important; border-radius: 8px !important; }
.ts-dropdown { z-index: 9999 !important; border-color: var(--border) !important; box-shadow: var(--shadow-lg) !important; }
html[data-theme="dark"] .ts-control { background: #1e293b !important; color: var(--text) !important; }
html[data-theme="dark"] .ts-control input,
html[data-theme="dark"] .ts-control .item { color: var(--text) !important; }
html[data-theme="dark"] .ts-dropdown { background: #1e293b !important; color: var(--text) !important; }
html[data-theme="dark"] .ts-dropdown .option { color: var(--text) !important; }
html[data-theme="dark"] .ts-dropdown .option.active,
html[data-theme="dark"] .ts-dropdown .active { background: var(--primary) !important; color: white !important; }
.ts-wrapper.single .ts-control .item { padding-inline-end: 0 !important; }

/* ===== Tom Select: caret never overlaps the selected item ===== */
.ts-wrapper .ts-control {
  min-height: 38px;
  padding-inline-end: 36px !important;
  padding-inline-start: 12px !important;
  position: relative;
}
.ts-wrapper.single .ts-control::after {
  /* default caret position fix */
  inset-inline-end: 12px !important;
  inset-inline-start: auto !important;
  border-color: var(--text-muted) transparent transparent transparent !important;
}
.ts-dropdown {
  margin-top: 6px !important;     /* clear visual gap from the input */
  border-radius: 10px !important;
  overflow: hidden;
}
.ts-dropdown .option {
  padding: 8px 12px !important;
  min-height: 36px;
}

/* ===== Bootstrap form-select arrow: never overlap the value text ===== */
.form-select {
  padding-inline-end: 2.5rem !important;
}
html[dir="rtl"] .form-select {
  background-position: left 0.75rem center !important;
}

/* ===== Equal-height form fields across columns ===== */
#crud-body .form-label,
#txModal .form-label {
  min-height: 22px;
  line-height: 1.4;
  margin-bottom: 6px !important;
}
#crud-body .col-md-1,
#crud-body .col-md-2,
#crud-body .col-md-3,
#crud-body .col-md-4,
#crud-body .col-md-5,
#crud-body .col-md-6,
#crud-body .col-md-7,
#crud-body .col-md-8,
#crud-body .col-md-9,
#crud-body .col-md-12,
#txModal .col-md-3,
#txModal .col-md-4,
#txModal .col-md-6,
#txModal .col-12 {
  display: flex;
  flex-direction: column;
}
/* Push the input to the bottom of the column so all inputs align */
#crud-body .col-md-1 > :last-child,
#crud-body .col-md-2 > :last-child,
#crud-body .col-md-3 > :last-child,
#crud-body .col-md-4 > :last-child,
#crud-body .col-md-5 > :last-child,
#crud-body .col-md-6 > :last-child,
#crud-body .col-md-7 > :last-child,
#crud-body .col-md-8 > :last-child,
#crud-body .col-md-9 > :last-child,
#crud-body .col-md-12 > :last-child:not(textarea):not(label) {
  margin-top: auto;
}
/* Uniform height for all inputs / selects (textarea exempt) */
#crud-body .form-control:not(textarea),
#crud-body .form-select,
#crud-body .input-group,
#crud-body .ts-wrapper .ts-control {
  min-height: 38px;
  height: 38px;
  display: flex;
  align-items: center;
}
#crud-body .input-group { padding: 0; }
#crud-body .input-group .form-control { border: 0; height: 100%; }
#crud-body textarea.form-control { min-height: 64px; height: auto; }
#crud-body input[type="color"] { height: 38px !important; padding: 4px 6px !important; }
#crud-body input[type="file"] { height: 38px !important; padding: 6px 12px !important; }

/* Dropdown direction strategy:
   - DEFAULT on RTL pages: rtl + right-align (good for Persian content like
     categories, member names, insurance kinds, account types).
   - For fields whose content is predominantly Latin (bank/vendor/airline/
     lender/brand names, IBAN/BIC), JS adds class "dir-ltr" on the select
     element AND on the surrounding ts-wrapper to flip to ltr + left-align.
   - On LTR pages everything inherits ltr naturally; the "dir-rtl" opt-in
     is available for the rare Persian field in German mode. */

/* Default (Persian page) */
html[dir="rtl"] .ts-dropdown,
html[dir="rtl"] .ts-dropdown .ts-dropdown-content,
html[dir="rtl"] .ts-dropdown .option,
html[dir="rtl"] .ts-dropdown .optgroup-header {
  direction: rtl !important;
  text-align: right !important;
}
html[dir="rtl"] .ts-wrapper .ts-control,
html[dir="rtl"] .ts-wrapper .ts-control .item,
html[dir="rtl"] .ts-wrapper .ts-control input {
  direction: rtl !important;
  text-align: right !important;
}

/* Opt-in: force LTR (Latin-content fields like bank names) */
.dir-ltr,
.dir-ltr .ts-control,
.dir-ltr .ts-control .item,
.dir-ltr .ts-control input,
.ts-wrapper.dir-ltr .ts-control,
.ts-wrapper.dir-ltr .ts-control .item,
.ts-wrapper.dir-ltr .ts-control input,
.ts-wrapper.dir-ltr + .ts-dropdown,
.ts-wrapper.dir-ltr + .ts-dropdown .option,
.ts-wrapper.dir-ltr + .ts-dropdown .optgroup-header,
.ts-dropdown.dir-ltr,
.ts-dropdown.dir-ltr .option,
.ts-dropdown.dir-ltr .optgroup-header {
  direction: ltr !important;
  text-align: left !important;
}

/* Opt-in: force RTL on LTR pages (rare — Persian field in German mode) */
.dir-rtl,
.dir-rtl .ts-control,
.dir-rtl .ts-control .item,
.dir-rtl .ts-control input,
.ts-wrapper.dir-rtl .ts-control,
.ts-wrapper.dir-rtl .ts-control .item,
.ts-wrapper.dir-rtl .ts-control input,
.ts-wrapper.dir-rtl + .ts-dropdown,
.ts-wrapper.dir-rtl + .ts-dropdown .option,
.ts-dropdown.dir-rtl,
.ts-dropdown.dir-rtl .option {
  direction: rtl !important;
  text-align: right !important;
}

/* Native form-select alignment also follows opt-in classes */
select.form-select.dir-ltr { direction: ltr !important; text-align: left !important; }
select.form-select.dir-rtl { direction: rtl !important; text-align: right !important; }

/* Backwards-compat: .force-ltr still works (used by IBAN/BIC inputs) */
.force-ltr,
.force-ltr input,
.force-ltr .ts-control,
.force-ltr .ts-control .item,
.force-ltr .ts-control input {
  direction: ltr !important;
  text-align: left !important;
}

/* ===== Bilingual labels: Persian on right, German on left ===== */
.form-label {
  display: flex !important;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.label-de {
  /* In RTL flex, margin-right:auto pushes the item to the far LEFT (end of flex flow).
     We don't use margin-inline-start because direction:ltr on this span flips its meaning. */
  margin-right: auto;
  margin-inline-start: 0;
  order: 99;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0;
  direction: ltr;
  text-align: left;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}
/* In LTR mode (German UI) hide the .label-de since the main label already IS German */
html[dir="ltr"] .label-de { display: none; }
.label-de::before {
  content: "·";
  color: var(--border);
  margin-right: 6px;
}

/* ===== Flatpickr (smart date picker) ===== */
.date-input {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.5px;
  text-align: start;
  direction: ltr;  /* dates always LTR for consistency */
}
html[dir="rtl"] .date-input { text-align: right; }
.flatpickr-calendar {
  font-family: inherit !important;
  font-size: 13px !important;
  box-shadow: 0 12px 40px rgba(15,23,42,.18) !important;
}
html[data-theme="dark"] .flatpickr-calendar,
.flatpickr-calendar.fp-dark {
  background: #1e293b !important;
  color: #f1f5f9 !important;
  border-color: #334155 !important;
}
html[data-theme="dark"] .flatpickr-calendar .flatpickr-day,
.flatpickr-calendar.fp-dark .flatpickr-day {
  color: #cbd5e1 !important;
}
html[data-theme="dark"] .flatpickr-calendar .flatpickr-day:hover,
.flatpickr-calendar.fp-dark .flatpickr-day:hover { background: #334155 !important; }
html[data-theme="dark"] .flatpickr-calendar .flatpickr-day.selected,
.flatpickr-calendar.fp-dark .flatpickr-day.selected { background: var(--primary) !important; color: white !important; }
html[data-theme="dark"] .flatpickr-calendar .flatpickr-day.today,
.flatpickr-calendar.fp-dark .flatpickr-day.today { border-color: var(--primary) !important; color: var(--primary) !important; }
html[data-theme="dark"] .flatpickr-months,
.flatpickr-calendar.fp-dark .flatpickr-months { background: transparent !important; color: #f1f5f9 !important; }
html[data-theme="dark"] .flatpickr-monthDropdown-months,
.flatpickr-calendar.fp-dark .flatpickr-monthDropdown-months { background: transparent !important; color: #f1f5f9 !important; }
html[data-theme="dark"] .flatpickr-current-month input.cur-year,
.flatpickr-calendar.fp-dark .flatpickr-current-month input.cur-year { color: #f1f5f9 !important; }
html[data-theme="dark"] .flatpickr-weekdays,
.flatpickr-calendar.fp-dark .flatpickr-weekdays { background: transparent !important; }
html[data-theme="dark"] .flatpickr-weekday,
.flatpickr-calendar.fp-dark .flatpickr-weekday { color: #94a3b8 !important; }
html[data-theme="dark"] .flatpickr-prev-month svg,
html[data-theme="dark"] .flatpickr-next-month svg,
.flatpickr-calendar.fp-dark .flatpickr-prev-month svg,
.flatpickr-calendar.fp-dark .flatpickr-next-month svg { fill: #cbd5e1 !important; }

/* ===== Icon Picker ===== */
.icon-picker-input { font-size: 18px; text-align: center; cursor: pointer; }
.icon-picker-modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 10000; padding: 16px;
}
.icon-picker-card {
  background: var(--card-bg, #fff); color: var(--text); width: 100%; max-width: 720px;
  max-height: 88vh; display: flex; flex-direction: column; border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4); overflow: hidden;
}
.icon-picker-header { display:flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.icon-picker-header h3 { margin: 0; font-size: 16px; }
.icon-picker-toolbar { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.icon-picker-search { width: 100%; }
.icon-picker-tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px;
  border-bottom: 1px solid var(--border); flex-wrap: nowrap; scrollbar-width: thin;
}
.icon-tab {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: 12px; white-space: nowrap; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-tab:hover { background: var(--bg-subtle, #f1f5f9); }
.icon-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.icon-picker-grid {
  flex: 1; overflow-y: auto; padding: 14px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px;
  align-content: start;
}
.icon-cell {
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  font-size: 22px; line-height: 1; padding: 8px 0; cursor: pointer; transition: all .15s;
  display: flex; align-items: center; justify-content: center;
}
.icon-cell:hover { background: var(--bg-subtle, #f1f5f9); border-color: var(--border); }
.icon-cell.selected { background: var(--primary); color: #fff; border-color: var(--primary); transform: scale(1.05); }
.icon-custom-add {
  grid-column: 1 / -1; display: flex; gap: 8px; padding: 0 0 10px 0;
  border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.icon-custom-add input { flex: 1; }
.icon-picker-empty {
  grid-column: 1 / -1; text-align: center; padding: 30px 16px;
  color: var(--text-muted); font-size: 13px;
}
.icon-picker-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-top: 1px solid var(--border); gap: 10px;
}
.icon-picker-current { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.icon-picker-current-val { font-size: 22px; }
.icon-picker-current .muted { color: var(--text-muted); font-size: 12px; }
html[data-theme="dark"] .icon-picker-card { background: #1e293b; }
html[data-theme="dark"] .icon-tab:hover { background: #334155; }
html[data-theme="dark"] .icon-cell:hover { background: #334155; }

/* ===== Help-icon tooltip ===== */
.help-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-muted); color: white;
  font-size: 10px; font-weight: 700;
  margin-inline-start: 6px;
  cursor: help;
  position: relative;
  vertical-align: middle;
  flex-shrink: 0;
  transition: background .15s;
}
.help-icon:hover { background: var(--primary); }
.help-icon::after {
  content: attr(data-help);
  position: absolute;
  bottom: calc(100% + 6px);
  inset-inline-end: -4px;
  background: #0f172a;
  color: #f8fafc;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  width: max-content;
  max-width: 280px;
  white-space: normal;
  text-align: start;
  z-index: 10001;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s, visibility .15s;
}
.help-icon::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 1px);
  inset-inline-end: 4px;
  border: 5px solid transparent;
  border-top-color: #0f172a;
  z-index: 10002;
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s, visibility .15s;
}
.help-icon:hover::after, .help-icon:hover::before {
  opacity: 1;
  visibility: visible;
}

/* ===== Field validation feedback ===== */
.form-control.is-invalid-custom {
  border-color: var(--danger) !important;
  background: linear-gradient(0deg, rgba(220,38,38,.05), rgba(220,38,38,.05));
}
.form-control.is-valid-custom {
  border-color: var(--success) !important;
}
.field-error {
  color: var(--danger);
  font-size: 11.5px;
  margin-top: 4px;
  display: flex; align-items: center; gap: 4px;
}
.field-error::before { content: "⚠️"; }
.field-success {
  color: var(--success);
  font-size: 11.5px;
  margin-top: 4px;
}

/* ===== Product Category tree ===== */
.pc-tree { font-size: 14px; }
.pc-node { margin-bottom: 4px; }
.pc-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-card);
}
.pc-node:hover > .pc-row { border-color: var(--primary); }
.cal-day.today { background: linear-gradient(180deg, var(--primary-soft) 0%, white 100%); border-color: var(--primary); }
.cal-day.muted { opacity: .35; }
.cal-num { font-weight: 700; margin-bottom: 4px; }
.cal-item {
  font-size: 10.5px;
  padding: 2px 4px;
  border-radius: 4px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-item.expense { background: var(--danger-soft); color: var(--danger); }
.cal-item.income { background: var(--success-soft); color: var(--success); }
.cal-item.bill { background: var(--warning-soft); color: var(--warning); }
.cal-item.event { background: #ede9fe; color: #7c3aed; }

.cal-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.cal-title { font-size: 17px; font-weight: 700; }

/* ===== Toasts ===== */
.toast-stack {
  position: fixed;
  bottom: 20px;
  inset-inline-end: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-x {
  background: white;
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  animation: slideIn .25s ease;
}
.toast-x.success { border-inline-start-color: var(--success); }
.toast-x.danger { border-inline-start-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
html[dir="ltr"] .toast-x { animation: slideInLtr .25s ease; }
@keyframes slideInLtr { from { transform: translateX(-20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== Empty state ===== */
.empty {
  text-align: center;
  padding: 36px 18px;
  color: var(--text-muted);
}
.empty i { font-size: 36px; opacity: .4; display: block; margin-bottom: 8px; }

/* ===== Pills / badges ===== */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-page);
  color: var(--text-muted);
}
.pill.health { background: #dcfce7; color: #166534; }
.pill.car { background: #dbeafe; color: #1e40af; }
.pill.life { background: #fae8ff; color: #86198f; }
.pill.legal { background: #fef3c7; color: #92400e; }
.pill.pension { background: #cffafe; color: #155e75; }
.pill.liability { background: #ffe4e6; color: #9f1239; }
.pill.household { background: #f3e8ff; color: #6b21a8; }
.pill.other { background: #e2e8f0; color: #475569; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar .form-select, .toolbar .form-control { max-width: 200px; }

/* ===== LTR adjustments for German ===== */
html[dir="ltr"] .sidebar { box-shadow: 5px 0 30px rgba(0,0,0,.15); }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; }
  .brand-title { font-size: 15px; }
  .nav-item { padding: 9px 12px; font-size: 13px; }
}
@media (max-width: 820px) {
  html[dir="ltr"] .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  html[dir="rtl"] .sidebar { transform: translateX(100%); transition: transform .25s ease; }
  html[dir="ltr"] .sidebar.open,
  html[dir="rtl"] .sidebar.open { transform: translateX(0); }
  .main { margin-inline-start: 0; padding: 0 12px 24px; }
  .btn-icon { display: flex; }
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 90;
}
.sidebar.open ~ .sidebar-backdrop { display: block; }

/* dashboard chart container */
.chart-wrap { position: relative; height: 280px; }
.chart-wrap-sm { position: relative; height: 220px; }

/* category bar */
.cat-bar { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; }
.cat-bar-track { background: var(--bg-page); border-radius: 8px; height: 8px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 8px; }

/* member pill row */
.member-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-page);
  margin-bottom: 6px;
}
.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
  font-weight: 700;
}

/* forecast list */
.forecast-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-page);
  margin-bottom: 6px;
  border-inline-start: 3px solid var(--primary);
}
.forecast-row.warn { border-inline-start-color: var(--danger); background: #fff5f5; }
.forecast-row.good { border-inline-start-color: var(--success); }
.forecast-month { font-weight: 700; }
.forecast-net { font-weight: 700; font-size: 16px; }
.forecast-net.pos { color: var(--success); }
.forecast-net.neg { color: var(--danger); }
.forecast-bal { font-size: 12px; color: var(--text-muted); }

/* upcoming list */
.upcoming-row {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}
.upcoming-row:last-child { border-bottom: none; }
.upcoming-date {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  line-height: 1.1;
}
.upcoming-date span:first-child { font-size: 14px; }

/* ===== Universal field border (BLACK, visible everywhere) =====
   The user explicitly asked for a black strip around every form field
   regardless of type/context — money, text, select, date, textarea, ts-control,
   input-group, and inputs that live inside an input-group. */
:root { --field-border: #64748b; }      /* slate-500 — visible but softer than near-black */
html[data-theme="dark"] { --field-border: #94a3b8; } /* slate-400 on dark */

/* Native form controls */
.form-control,
.form-select,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="file"],
input[type="color"],
textarea,
select {
  border: 1.5px solid var(--field-border) !important;
}

/* Focus state — slightly thicker + accent color, but still black-ish */
.form-control:focus,
.form-select:focus,
input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary, #0d6efd) !important;
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.18) !important;
}

/* Input-group wrapper (used for money fields with the € prefix).
   Make the WHOLE group look like one bordered box. */
.input-group {
  border: 1.5px solid var(--field-border) !important;
  border-radius: 8px;
  overflow: hidden;
}
/* Inputs/addons inside an input-group should drop their individual borders */
.input-group > .form-control,
.input-group > .form-select,
.input-group > input,
.input-group > .input-group-text {
  border: none !important;
  box-shadow: none !important;
}
.input-group > .input-group-text {
  border-inline-end: 1.5px solid var(--field-border) !important;
}
html[dir="rtl"] .input-group > .input-group-text {
  border-inline-end: none !important;
  border-inline-start: 1.5px solid var(--field-border) !important;
}

/* Tom Select control */
.ts-wrapper .ts-control {
  border: 1.5px solid var(--field-border) !important;
}
.ts-wrapper.focus .ts-control,
.ts-wrapper .ts-control:focus-within {
  border-color: var(--primary, #0d6efd) !important;
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.18) !important;
}
.ts-dropdown { border: 1.5px solid var(--field-border) !important; }

/* Flatpickr alt-input also gets the border */
input.flatpickr-input,
input.flatpickr-alt-input {
  border: 1.5px solid var(--field-border) !important;
}

/* Validation feedback should not lose the border, only swap the color */
.form-control.is-invalid-custom,
.form-control.is-invalid { border-color: #dc2626 !important; }
.form-control.is-valid-custom,
.form-control.is-valid { border-color: #16a34a !important; }

/* ===== Universal Drag-and-Drop (sidebar, ref-cards, all forms) =====
   Handles are hidden by default. They become visible when the global
   edit mode is on (body.dnd-global-edit). */
.dnd-uni-item {
  position: relative;
  transition: outline .15s, background .15s, transform .15s;
}
.dnd-uni-handle {
  position: absolute;
  top: 4px;
  inset-inline-start: 4px;
  width: 22px;
  height: 22px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--primary, #0d6efd);
  color: white;
  font-size: 13px;
  cursor: grab;
  z-index: 20;
  user-select: none;
  pointer-events: none; /* visual only; container handles drag */
  box-shadow: 0 2px 6px rgba(13,110,253,.25);
}
body.dnd-global-edit .dnd-uni-handle {
  display: flex;
  animation: dndUniPulse 1.4s ease-in-out infinite;
}
body.dnd-global-edit .dnd-uni-item {
  outline: 1.5px dashed rgba(13,110,253,0.35);
  outline-offset: 3px;
  border-radius: 8px;
  cursor: grab;
}
body.dnd-global-edit .dnd-uni-item:hover {
  outline-color: rgba(13,110,253,0.7);
  background: rgba(13,110,253,0.04);
}
/* Disable interactive children while in edit mode so the column itself
   receives the drag (input/select/link won't steal mousedown). */
body.dnd-global-edit .dnd-uni-item > *:not(.dnd-uni-handle) {
  pointer-events: none !important;
}
body.dnd-global-edit .dnd-uni-item .dnd-uni-handle {
  pointer-events: auto !important;
}
.dnd-uni-dragging {
  opacity: 0.4;
  transform: scale(0.97);
}
.dnd-uni-target {
  background: rgba(13, 110, 253, 0.10) !important;
  box-shadow: 0 0 0 2.5px rgba(13, 110, 253, 0.55) inset !important;
  border-radius: 8px;
}
@keyframes dndUniDropFlash {
  0%   { background: rgba(34, 197, 94, 0.25); }
  100% { background: transparent; }
}
.dnd-uni-flash {
  animation: dndUniDropFlash 0.6s ease-out;
  border-radius: 8px;
}
@keyframes dndUniPulse {
  0%, 100% { box-shadow: 0 2px 6px rgba(13,110,253,.25); }
  50%      { box-shadow: 0 2px 12px rgba(13,110,253,.55); }
}

/* Sidebar: while edit mode, give the whole li an outline */
.sidebar nav ul li.dnd-uni-item { padding-inline-start: 0; }
body.dnd-global-edit .sidebar .nav-item { pointer-events: none; }
body.dnd-global-edit .sidebar nav ul li { cursor: grab; }

/* Topbar toggle button — turns solid blue when active */
#global-dnd-toggle {
  border-color: var(--primary, #0d6efd) !important;
  color: var(--primary, #0d6efd) !important;
}
#global-dnd-toggle.active {
  background: var(--primary, #0d6efd) !important;
  color: #fff !important;
  box-shadow: 0 0 0 3px rgba(13,110,253,.20);
}

/* ===== Form field drag-and-drop reordering =====
   Handle is HIDDEN unless the parent form has .dnd-edit-mode (opt-in via
   the toggle button in the modal footer). This prevents the grip from
   distracting users while filling out the form. */
.dnd-draggable {
  position: relative;
  transition: outline .15s, background .15s, transform .15s;
}
.dnd-handle {
  position: absolute;
  top: 4px;
  inset-inline-start: 4px;
  width: 24px;
  height: 24px;
  display: none; /* hidden by default */
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--primary, #0d6efd);
  color: white;
  font-size: 14px;
  cursor: grab;
  z-index: 10;
  user-select: none;
  box-shadow: 0 2px 6px rgba(13,110,253,.25);
}
.dnd-handle:hover { background: #0b5ed7; transform: scale(1.08); }
.dnd-handle:active { cursor: grabbing; }

/* When form is in edit mode: show handles + outline columns */
form.dnd-edit-mode .dnd-handle {
  display: flex;
  animation: dndPulse 1.4s ease-in-out infinite;
}
form.dnd-edit-mode > .dnd-draggable {
  outline: 1.5px dashed rgba(13,110,253,0.35);
  outline-offset: 4px;
  border-radius: 8px;
  cursor: grab;
}
form.dnd-edit-mode > .dnd-draggable:hover {
  outline-color: rgba(13,110,253,0.7);
  background: rgba(13,110,253,0.04);
}
/* CRITICAL: while in edit mode, prevent input/select/dropdown children
   from swallowing the mousedown — drag must start from the column itself.
   The handle is exempted so its hover/grab cursor still works. */
form.dnd-edit-mode > .dnd-draggable > *:not(.dnd-handle) {
  pointer-events: none !important;
  user-select: none !important;
}
form.dnd-edit-mode > .dnd-draggable .dnd-handle {
  pointer-events: auto !important;
}
@keyframes dndPulse {
  0%, 100% { box-shadow: 0 2px 6px rgba(13,110,253,.25); }
  50%      { box-shadow: 0 2px 12px rgba(13,110,253,.55); }
}

.dnd-dragging {
  opacity: 0.4;
  transform: scale(0.98);
}
.dnd-drop-target {
  background: rgba(13, 110, 253, 0.08) !important;
  border-radius: 8px;
  box-shadow: 0 0 0 2.5px rgba(13, 110, 253, 0.55) inset !important;
}
@keyframes dndDropFlash {
  0%   { background: rgba(34, 197, 94, 0.22); }
  100% { background: transparent; }
}
.dnd-just-dropped {
  animation: dndDropFlash 0.6s ease-out;
  border-radius: 8px;
}

/* "Edit layout" toggle button (in modal footer). Becomes solid when active. */
#crud-edit-layout {
  position: relative;
}
#crud-edit-layout.active {
  background: var(--primary, #0d6efd) !important;
  color: #fff !important;
  border-color: var(--primary, #0d6efd) !important;
  box-shadow: 0 0 0 3px rgba(13,110,253,.18);
}

/* ===== Premium look for forced-LTR dropdowns =====
   Lender, vendor, brand, insurance company, currency etc. — these hold
   canonical Latin names (Sparkasse, REWE, Lufthansa, EUR, …) and look
   best with a clean LTR typeface and tight letter-spacing. */
.dir-ltr.ts-wrapper .ts-control,
.ts-wrapper.dir-ltr .ts-control,
.dir-ltr.form-select,
select.dir-ltr {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif !important;
  letter-spacing: 0 !important;
  font-feature-settings: "tnum" 1, "kern" 1;
}
.ts-wrapper.dir-ltr .ts-control .item,
.dir-ltr.form-select option,
.ts-dropdown.dir-ltr .option {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif !important;
  letter-spacing: 0 !important;
}
/* Caret position on LTR-forced dropdowns: on the right (LTR convention) */
.ts-wrapper.dir-ltr.single .ts-control::after {
  inset-inline-end: 12px !important;
  inset-inline-start: auto !important;
}
/* Native form-select arrow: also on right for forced-LTR */
html[dir="rtl"] select.form-select.dir-ltr {
  background-position: right 0.75rem center !important;
  padding-inline-end: 2.5rem !important;
  padding-inline-start: 0.75rem !important;
}
/* Dropdown options: subtle hover + selected indicator */
.ts-dropdown.dir-ltr .option {
  padding: 8px 12px !important;
  border-bottom: 1px solid transparent;
  transition: background .12s;
}
.ts-dropdown.dir-ltr .option:hover { background: #f1f5f9; }
.ts-dropdown.dir-ltr .option.active { background: #e0e7ff !important; color: #1e293b !important; font-weight: 500; }
html[data-theme="dark"] .ts-dropdown.dir-ltr .option:hover { background: #334155; }
html[data-theme="dark"] .ts-dropdown.dir-ltr .option.active { background: #475569 !important; color: #f1f5f9 !important; }

/* ===== Bilingual option (Persian right + German left in a single row) =====
   For dropdowns whose options render via `bi-option-row` template
   (e.g. income source types, contract types). */
.bi-option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 14px;
}
.bi-option-row .bi-fa {
  font-family: "Vazirmatn", system-ui, sans-serif;
  text-align: right;
  direction: rtl;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bi-option-row .bi-de {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  text-align: left;
  direction: ltr;
  color: var(--text-muted);
  font-size: 0.86em;
  font-weight: 400;
  flex: 0 0 auto;
  letter-spacing: 0;
}
/* In Tom Select rendered items (the selected one), keep both sides visible */
.ts-wrapper .ts-control .item .bi-option-row { width: auto; }
.ts-wrapper .ts-control .item .bi-option-row .bi-de {
  padding-inline-start: 10px;
  border-inline-start: 1px solid var(--border);
  margin-inline-start: 4px;
}

/* ===== Brand cell (logo + bilingual name) =====
   Used in reference-data tables: vendors, banks, airlines, vehicle brands,
   insurance companies, lenders. RTL: Persian on the RIGHT (default position
   in flex-row with row-reverse), Latin (logo-style) on the LEFT. */
.brand-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
.brand-logo-wrap {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-subtle, #f8fafc);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.brand-logo {
  width: 100%; height: 100%;
  object-fit: contain;
  background: white;
}
.brand-emoji-fallback {
  font-size: 22px;
  line-height: 1;
}
.brand-text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;     /* Persian (top) aligned to RIGHT in RTL */
  gap: 1px;
  min-width: 0;
  text-align: right;
}
html[dir="ltr"] .brand-text {
  align-items: flex-start;
  text-align: left;
}
.brand-fa {
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.brand-latin {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text-muted);
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
html[data-theme="dark"] .brand-logo-wrap {
  background: #1e293b;
}
html[data-theme="dark"] .brand-logo {
  background: #f8fafc;  /* logos are designed for light backgrounds */
}

/* ===== Sidebar accordion groups ===== */
.nav-group { list-style: none; }
.nav-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  text-align: start;
  border-radius: 8px;
  transition: background .15s, color .15s;
}
.nav-group-header:hover { background: rgba(13,110,253,0.06); color: var(--primary, #0d6efd); }
.nav-group-header > i:first-child {
  font-size: 16px;
  width: 18px;
  color: var(--primary, #0d6efd);
}
.nav-group-header > span { flex: 1; }
.nav-chevron {
  font-size: 12px;
  transition: transform .25s ease;
  color: var(--text-muted);
}
.nav-group.open .nav-chevron { transform: rotate(180deg); }

.nav-group-items {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height .35s ease;
}
.nav-group.open .nav-group-items {
  max-height: 1000px; /* large enough to fit any group */
}
.nav-group-items > li > .nav-item {
  padding-inline-start: 38px; /* indent group items */
  font-size: 13.5px;
}
.nav-group-items > li > .nav-item.active {
  background: rgba(13,110,253,0.10);
  font-weight: 600;
}
html[data-theme="dark"] .nav-group-header:hover {
  background: rgba(96,165,250,0.10);
}

/* ===== Spending heatmap (GitHub-style calendar) ===== */
.hm-wrap { overflow-x: auto; padding: 4px 2px 2px; }
.hm-grid { display: flex; gap: 3px; min-width: max-content; }
.hm-col { display: flex; flex-direction: column; gap: 3px; }
.hm-cell {
  width: 13px; height: 13px; border-radius: 3px;
  background: var(--success-soft); cursor: default;
}
.hm-cell.hm-empty { background: transparent; cursor: default; }
.hm-l0 { background: rgba(127,127,127,0.12); }
.hm-l1 { background: #fde68a; }
.hm-l2 { background: #fb923c; }
.hm-l3 { background: #ef4444; }
.hm-l4 { background: #b91c1c; }
.hm-months { display: flex; gap: 3px; min-width: max-content; margin-bottom: 4px;
  font-size: 11px; color: var(--text-muted); }
.hm-month { width: 16px; white-space: nowrap; }
.hm-legend { display: flex; align-items: center; gap: 6px; margin-top: 10px;
  font-size: 12px; color: var(--text-muted); justify-content: flex-end; }
.hm-legend .hm-cell { cursor: default; }
html[data-theme="dark"] .hm-l1 { background: #92710f; }
html[data-theme="dark"] .hm-l2 { background: #b45309; }

/* ===== Cashflow calendar ===== */
.cf-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cf-head { margin-bottom: 6px; }
.cf-wd { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 4px 0; }
.cf-cell { min-height: 78px; border: 1px solid var(--border, #e5e7eb); border-radius: 8px; padding: 5px 6px;
  display: flex; flex-direction: column; gap: 2px; background: var(--card-bg, #fff); overflow: hidden; }
.cf-cell.cf-out { background: transparent; border-color: transparent; }
.cf-cell.cf-today { border-color: var(--primary, #2563eb); box-shadow: 0 0 0 1px var(--primary, #2563eb) inset; }
.cf-day { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.cf-amt { font-size: 12px; font-weight: 700; }
.cf-up { font-size: 11px; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cf-in { color: var(--success); }
.cf-out { color: var(--danger); }
html[data-theme="dark"] .cf-cell { border-color: rgba(255,255,255,0.08); }

/* ===== Multi-user: viewer (read-only) role hides write actions ===== */
.role-viewer .row-actions,
.role-viewer [id^="add-"],
.role-viewer #quick-add-btn,
.role-viewer #scan-l,
.role-viewer #scan-w,
.role-viewer #rep-save,
.role-viewer #refresh-prices,
.role-viewer .btn-soft.danger,
.role-viewer [onclick*="openTxModal"],
.role-viewer [onclick*="openSplitModal"],
.role-viewer [onclick*="Crud("] { display: none !important; }
.role-viewer .ro-badge { display: inline-flex !important; }

/* ===== Google Places address autocomplete dropdown =====
   The crud form opens inside a Bootstrap modal (z-index ~1055). Google's
   .pac-container defaults to z-index 1000, so without this it renders BEHIND
   the modal and the address suggestions are invisible. Lift it above. */
.pac-container {
  z-index: 100000 !important;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-family: inherit;
  background: var(--card, #fff);
  margin-top: 2px;
}
.pac-item {
  padding: 7px 12px;
  cursor: pointer;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.pac-item:hover, .pac-item-selected { background: var(--hover, #f1f5f9); }
.pac-item-query { font-size: 13px; }

/* ===== Language dropdown + User menu (topbar) ===== */
.lang-dd, .user-dd { position: relative; }
.lang-dd-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card, #fff); color: var(--text, #0f172a);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.lang-dd-btn:hover { background: var(--hover, #f1f5f9); }
.lang-dd-btn .bi-chevron-down { font-size: 11px; opacity: .6; }
.lang-dd-menu, .user-dd-menu {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0;
  min-width: 170px; background: var(--card, #fff);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 1200;
  display: none; flex-direction: column; gap: 2px;
}
.lang-dd.open .lang-dd-menu, .user-dd.open .user-dd-menu { display: flex; }
.lang-dd-menu .lang-btn, .user-dd-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: transparent; border: 0; border-radius: 8px;
  padding: 9px 12px; font-size: 14px; color: var(--text, #0f172a);
  cursor: pointer; text-align: start;
}
.lang-dd-menu .lang-btn:hover, .user-dd-item:hover { background: var(--hover, #f1f5f9); }
.lang-dd-menu .lang-btn.active { background: var(--primary, #4f46e5); color: #fff; }
.lang-dd-menu .lang-btn .fl { font-size: 17px; }

.user-dd-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--card, #fff); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 8px 4px 5px; cursor: pointer;
}
.user-dd-btn:hover { background: var(--hover, #f1f5f9); }
.user-dd-btn .bi-chevron-down { font-size: 11px; opacity: .6; }
.user-dd-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary, #4f46e5); color: #fff; font-size: 16px;
}
.user-dd-head {
  padding: 8px 12px 10px; border-bottom: 1px solid var(--border);
  margin-bottom: 4px; display: flex; flex-direction: column; gap: 2px;
}
.user-dd-name { font-weight: 700; font-size: 14px; }
.user-dd-role { color: var(--muted, #64748b); font-size: 12px; }
.user-dd-item#user-dd-logout { color: #dc2626; }
