/* ---------------------------------------------------------------
   حسابداری خانواده — استایل اصلی (راست‌به‌چپ، با تم روشن و تیره)

   رنگ‌ها همگی به صورت متغیر تعریف شده‌اند:
     • حالت پیش‌فرض  = تم روشن
     • اگر سیستم کاربر تیره باشد و انتخاب دستی نکرده باشد = تیره
     • انتخاب دستی کاربر با data-theme روی <html> اعمال می‌شود

   هیچ رنگی نباید مستقیم در HTML یا JS نوشته شود؛ همیشه از متغیرها
   استفاده کنید تا هر دو تم درست بمانند.
   --------------------------------------------------------------- */

/* ----------------------------------------------------- فونت برنامه */

@font-face {
  font-family: 'B Nazanin';
  src: url('../fonts/B-Nazanin.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #eef2f8;
  --bg-accent: rgba(29, 111, 184, .07);
  --surface: #ffffff;
  --surface-2: #f5f8fc;
  --surface-3: #eef3f9;
  --input-bg: #ffffff;
  --border: #e3e9f2;
  --border-strong: #d2dbe8;
  --text: #16202f;
  --muted: #6a7a90;

  --primary: #1d6fb8;
  --primary-dark: #17588f;
  --primary-light: #e7f0f9;
  --primary-soft: rgba(29, 111, 184, .14);
  --ring: rgba(29, 111, 184, .22);

  --success: #12784a;
  --success-light: #e4f4ec;
  --danger: #c62828;
  --danger-light: #fdecec;
  --warning: #b45309;
  --warning-light: #fdf3e3;
  --info: #0e7490;
  --info-light: #e3f4f8;

  --row-active: rgba(18, 120, 74, .10);

  --sidebar-bg: linear-gradient(175deg, #102c48 0%, #0c2138 100%);
  --sidebar-text: #c7d3e3;
  --sidebar-title: #6d819b;
  --sidebar-hover: rgba(255, 255, 255, .07);
  --sidebar-active: rgba(77, 163, 214, .22);
  --sidebar-border: rgba(255, 255, 255, .09);
  --sidebar-accent: #62b4e8;

  --chart-income: #1aa35f;
  --chart-income-2: #12784a;
  --chart-expense: #d64545;
  --chart-expense-2: #c62828;
  --bar-fill: #3d90cd;
  --bar-fill-2: #1d6fb8;

  --auth-bg-1: #0c2138;
  --auth-bg-2: #1d6fb8;

  --shadow-xs: 0 1px 2px rgba(16, 32, 54, .05);
  --shadow: 0 1px 2px rgba(16, 32, 54, .05), 0 4px 12px rgba(16, 32, 54, .05);
  --shadow-md: 0 2px 6px rgba(16, 32, 54, .07), 0 10px 24px rgba(16, 32, 54, .07);
  --shadow-lg: 0 12px 34px rgba(16, 32, 54, .14);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  color-scheme: light;
}

/* تم تیره وقتی سیستم تیره است و کاربر «روشن» را دستی انتخاب نکرده */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #080e1a;
    --bg-accent: rgba(98, 180, 232, .06);
    --surface: #121b2b;
    --surface-2: #182334;
    --surface-3: #1e2b3f;
    --input-bg: #0d1626;
    --border: #26344a;
    --border-strong: #33445e;
    --text: #e8eef8;
    --muted: #93a3b8;

    --primary: #58aae0;
    --primary-dark: #7bc0ec;
    --primary-light: rgba(88, 170, 224, .16);
    --primary-soft: rgba(88, 170, 224, .24);
    --ring: rgba(88, 170, 224, .30);

    --success: #45dda0;
    --success-light: rgba(69, 221, 160, .14);
    --danger: #ff8585;
    --danger-light: rgba(255, 133, 133, .14);
    --warning: #fbbf24;
    --warning-light: rgba(251, 191, 36, .14);
    --info: #45dcea;
    --info-light: rgba(69, 220, 234, .13);

    --row-active: rgba(69, 221, 160, .13);

    --sidebar-bg: linear-gradient(175deg, #0c1524 0%, #070d18 100%);
    --sidebar-text: #b2c0d3;
    --sidebar-title: #5d6d85;
    --sidebar-hover: rgba(255, 255, 255, .05);
    --sidebar-active: rgba(88, 170, 224, .20);
    --sidebar-border: rgba(255, 255, 255, .07);
    --sidebar-accent: #58aae0;

    --chart-income: #45dda0;
    --chart-income-2: #2bb37b;
    --chart-expense: #ff8585;
    --chart-expense-2: #e05a5a;
    --bar-fill: #58aae0;
    --bar-fill-2: #2f7fae;

    --auth-bg-1: #050a13;
    --auth-bg-2: #113351;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 4px 14px rgba(0, 0, 0, .35);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .5), 0 12px 28px rgba(0, 0, 0, .4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

/* انتخاب دستی تم تیره */
:root[data-theme="dark"] {
  --bg: #080e1a;
  --bg-accent: rgba(98, 180, 232, .06);
  --surface: #121b2b;
  --surface-2: #182334;
  --surface-3: #1e2b3f;
  --input-bg: #0d1626;
  --border: #26344a;
  --border-strong: #33445e;
  --text: #e8eef8;
  --muted: #93a3b8;

  --primary: #58aae0;
  --primary-dark: #7bc0ec;
  --primary-light: rgba(88, 170, 224, .16);
  --primary-soft: rgba(88, 170, 224, .24);
  --ring: rgba(88, 170, 224, .30);

  --success: #45dda0;
  --success-light: rgba(69, 221, 160, .14);
  --danger: #ff8585;
  --danger-light: rgba(255, 133, 133, .14);
  --warning: #fbbf24;
  --warning-light: rgba(251, 191, 36, .14);
  --info: #45dcea;
  --info-light: rgba(69, 220, 234, .13);

  --row-active: rgba(69, 221, 160, .13);

  --sidebar-bg: linear-gradient(175deg, #0c1524 0%, #070d18 100%);
  --sidebar-text: #b2c0d3;
  --sidebar-title: #5d6d85;
  --sidebar-hover: rgba(255, 255, 255, .05);
  --sidebar-active: rgba(88, 170, 224, .20);
  --sidebar-border: rgba(255, 255, 255, .07);
  --sidebar-accent: #58aae0;

  --chart-income: #45dda0;
  --chart-income-2: #2bb37b;
  --chart-expense: #ff8585;
  --chart-expense-2: #e05a5a;
  --bar-fill: #58aae0;
  --bar-fill-2: #2f7fae;

  --auth-bg-1: #050a13;
  --auth-bg-2: #113351;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 4px 14px rgba(0, 0, 0, .35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .5), 0 12px 28px rgba(0, 0, 0, .4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'B Nazanin', Vazirmatn, 'IRANSans', Tahoma, 'Segoe UI', sans-serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.9;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ورودی‌ها و دکمه‌ها فونت را از بدنه به ارث می‌برند */
input, select, textarea, button { font-family: inherit; }

body {
  transition: background-color .2s ease, color .2s ease;
  background-image: radial-gradient(1100px 520px at 100% -10%, var(--bg-accent), transparent 70%);
  background-attachment: fixed;
}

a { color: var(--primary); text-decoration: none; transition: color .15s ease; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* اسکرول‌بار باریک و هم‌رنگ تم */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 20px;
  border: 3px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------ چیدمان */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 18px 0 0;
  position: sticky;
  top: 0;
  height: 100vh;
  border-inline-start: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  transition: width .18s ease;
}

/* فهرست پیمایش‌پذیر؛ «حساب من» همیشه پایین می‌ماند */
.sidebar .nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 10px;
  scrollbar-width: thin;
}
.sidebar .nav-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 8px 0 12px;
  background: rgba(0, 0, 0, .12);
}
.sidebar .nav-footer .nav-link { font-size: 15.5px; padding: 8px 12px; }
.sidebar .nav-logout:hover { background: rgba(214, 69, 69, .22); color: #fff; }

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 8px;
}
.sidebar .brand .logo {
  width: 42px; height: 42px;
  background: linear-gradient(140deg, var(--primary), var(--sidebar-accent));
  border-radius: 13px;
  display: grid; place-items: center;
  font-size: 21px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
}
.sidebar .brand b { color: #fff; font-size: 18px; display: block; line-height: 1.5; }
.sidebar .brand span { font-size: 13px; color: var(--sidebar-title); }

.nav-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: calc(100% - 20px);
  margin: 10px 10px 2px;
  padding: 6px 12px;
  background: none;
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  color: var(--sidebar-title);
  letter-spacing: .6px;
  cursor: pointer;
  text-align: start;
  transition: background .15s ease, color .15s ease;
}
.nav-group-title:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-chev { font-size: 15px; line-height: 1; transition: transform .18s ease; opacity: .8; }
.nav-group.collapsed .nav-chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-body { display: none; }

/* جست‌وجوی منو */
.nav-search {
  position: relative;
  margin: 4px 12px 8px;
  display: flex;
  align-items: center;
}
.nav-search input {
  width: 100%;
  padding: 8px 32px 8px 30px;
  border-radius: 11px;
  border: 1px solid var(--sidebar-border);
  background: rgba(255, 255, 255, .06);
  color: #fff;
  font: inherit;
  font-size: 14.5px;
}
.nav-search input::placeholder { color: var(--sidebar-title); }
.nav-search input:focus {
  outline: none;
  border-color: var(--sidebar-accent);
  background: rgba(255, 255, 255, .10);
}
.nav-search input::-webkit-search-cancel-button { filter: invert(.6); }
.nav-search-icon {
  position: absolute; inset-inline-start: 10px;
  font-size: 13px; opacity: .7; pointer-events: none;
}
.nav-search-key {
  position: absolute; inset-inline-end: 9px;
  font-size: 12px; color: var(--sidebar-title);
  border: 1px solid var(--sidebar-border);
  border-radius: 6px; padding: 0 5px; pointer-events: none;
}
.nav-empty {
  margin: 12px 16px;
  font-size: 14px;
  color: var(--sidebar-title);
  text-align: center;
}

/* نشانگر عدد کنار آیتم‌ها */
.nav-badge {
  margin-inline-start: auto;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}
.nav-badge.danger { background: var(--danger); }

/* کلید باز و بستهٔ منو */
.sidebar-rail-toggle {
  margin-inline-start: auto;
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid var(--sidebar-border);
  background: rgba(255, 255, 255, .06);
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: grid; place-items: center;
  transition: background .15s ease, transform .18s ease;
}
.sidebar-rail-toggle:hover { background: rgba(255, 255, 255, .14); color: #fff; }

/* حالت باریک: فقط آیکن‌ها */
:root.nav-rail .sidebar { width: 78px; }
:root.nav-rail .sidebar .brand { justify-content: center; padding-inline: 8px; }
:root.nav-rail .sidebar .brand-text,
:root.nav-rail .nav-search,
:root.nav-rail .nav-text,
:root.nav-rail .nav-badge,
:root.nav-rail .nav-group-title span:first-child,
:root.nav-rail .nav-chev { display: none; }
:root.nav-rail .sidebar-rail-toggle { transform: rotate(180deg); margin: 0; }
:root.nav-rail .nav-group-title {
  height: 1px; padding: 0; margin: 10px 16px;
  background: var(--sidebar-border); pointer-events: none;
}
:root.nav-rail .sidebar a.nav-link { justify-content: center; padding: 10px 0; margin: 3px 10px; }
:root.nav-rail .sidebar a.nav-link.active::before { inset-inline-end: -8px; }
:root.nav-rail .nav-group.collapsed .nav-group-body { display: block; }

/* پس‌زمینهٔ تیره پشت منو در موبایل */
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4, 10, 20, .55);
  backdrop-filter: blur(2px);
}

.sidebar a.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 2px 10px;
  padding: 9px 12px;
  border-radius: 12px;
  color: var(--sidebar-text);
  font-size: 16.5px;
  position: relative;
  transition: background .18s ease, color .18s ease, transform .12s ease;
}
.sidebar a.nav-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.sidebar a.nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 700;
}
.sidebar a.nav-link.active::before {
  content: "";
  position: absolute;
  inset-inline-end: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 22px;
  border-radius: 4px;
  background: var(--sidebar-accent);
}
.sidebar .nav-icon {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font-size: 15px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  flex-shrink: 0;
}
.sidebar a.nav-link.active .nav-icon { background: rgba(255, 255, 255, .14); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);                                  /* پشتیبان مرورگرهای قدیمی */
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 11px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .page-title { font-size: 21px; font-weight: 800; margin: 0; letter-spacing: -.2px; }
.topbar .meta { font-size: 14.5px; color: var(--muted); }
.topbar .user-box { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(140deg, var(--primary), var(--sidebar-accent));
  color: #fff;
  display: grid; place-items: center; font-weight: 800;
  box-shadow: var(--shadow-xs);
}

.content { padding: 22px; flex: 1; }
.menu-toggle {
  display: none; background: none; border: 0; font-size: 22px;
  cursor: pointer; color: var(--text); line-height: 1;
}

/* --------------------------------------------------- کلید تغییر تم */

.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: grid; place-items: center;
  transition: background .18s ease, transform .12s ease, border-color .18s ease;
  line-height: 1;
  padding: 0;
}
.theme-toggle:hover { background: var(--primary-light); border-color: var(--primary); }
.theme-toggle:active { transform: scale(.92); }

.theme-toggle-floating {
  position: fixed;
  top: 16px; left: 16px;
  z-index: 50;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .25);
  color: #fff;
  backdrop-filter: blur(6px);
}
.theme-toggle-floating:hover { background: rgba(255, 255, 255, .25); border-color: rgba(255, 255, 255, .4); }

/* ------------------------------------------------------------- کارت */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
  transition: box-shadow .2s ease, border-color .2s ease;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
}
.card-header h2, .card-header h3 { margin: 0; font-size: 18.5px; font-weight: 800; letter-spacing: -.2px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

/* ---------------------------------------------------------- آمار */

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 13px;
  align-items: flex-start;
  position: relative;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.stat::after {
  content: "";
  position: absolute; inset-block-start: 0; inset-inline: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--primary-soft), transparent);
  opacity: 0;
  transition: opacity .2s ease;
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat:hover::after { opacity: 1; }
.stat .icon {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center; font-size: 21px; flex-shrink: 0;
}
.stat .label { font-size: 15px; color: var(--muted); margin-bottom: 2px; font-weight: 700; }
.stat .value {
  font-size: 26px; font-weight: 800; letter-spacing: -.5px;
  font-variant-numeric: tabular-nums; line-height: 1.5;
}
.stat .value small { font-size: 14px; font-weight: 700; color: var(--muted); }
.stat .sub { font-size: 13.5px; color: var(--muted); }

.i-expense { background: var(--danger-light); color: var(--danger); }
.i-income  { background: var(--success-light); color: var(--success); }
.i-balance { background: var(--info-light); color: var(--info); }
.i-count   { background: var(--primary-light); color: var(--primary); }

/* --------------------------------------------------------- جدول */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; min-width: 360px; border-collapse: collapse; font-size: 17px; }
table.table th, table.table td {
  padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--border);
}
table.table thead th {
  background: var(--surface-2);
  font-size: 15.5px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  position: sticky; top: 0;
  border-bottom: 1px solid var(--border-strong);
  z-index: 1;
}
table.table tbody tr { transition: background .15s ease; }
table.table tbody tr:hover { background: var(--surface-3); }
table.table tbody tr:last-child td { border-bottom: 0; }
/* ردیفی که کاربر پرش کرده (ثبت درآمد روزانه، فاکتور و…) */
table.table tbody tr.row-active,
table.table tbody tr.row-active:hover { background: var(--row-active); }
table.table td.num, table.table th.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.table tfoot td { font-weight: 800; background: var(--surface-2); }
.table-empty { text-align: center; color: var(--muted); padding: 34px 10px; }

/* ---------------------------------------------------------- فرم */

.form-row { margin-bottom: 15px; }
.form-grid { display: grid; gap: 15px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label.form-label { display: block; font-size: 16px; font-weight: 700; margin-bottom: 6px; }
label.form-label .req { color: var(--danger); }

.form-control, select.form-control, textarea.form-control {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 17px;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.form-control:hover:not(:disabled):not([readonly]) { border-color: var(--primary); }
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}
.form-control[readonly] { background: var(--surface-2); color: var(--muted); }
.form-control::placeholder { color: var(--muted); opacity: .75; font-weight: 400; }
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: left 16px top 55%, left 11px top 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-start: 34px;
}
select.form-control option { background: var(--surface); color: var(--text); }
textarea.form-control { min-height: 76px; resize: vertical; }
.form-hint { font-size: 14px; color: var(--muted); margin-top: 5px; font-weight: 400; }
input[type="file"].form-control { padding: 8px 12px; }
input[type="color"].form-control { padding: 3px; cursor: pointer; height: 42px; }

.check-list { display: flex; flex-wrap: wrap; gap: 8px; }
.check-item {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border-strong); border-radius: 22px;
  padding: 7px 14px; font-size: 16px; cursor: pointer; background: var(--surface);
  user-select: none; color: var(--text);
  transition: border-color .15s ease, background .15s ease, color .15s ease, transform .1s ease;
}
.check-item:hover { border-color: var(--primary); transform: translateY(-1px); }
.check-item input { accent-color: var(--primary); }
.check-item.checked {
  background: var(--primary-light); border-color: var(--primary);
  color: var(--primary); font-weight: 700;
}

.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.perm-item {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 16px; background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.perm-item:hover { border-color: var(--primary); background: var(--surface-2); }

/* --------------------------------------------------------- دکمه */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit; font-size: 17px; font-weight: 700;
  cursor: pointer; background: var(--surface-2); color: var(--text);
  transition: background .16s ease, box-shadow .16s ease, transform .1s ease,
              border-color .16s ease, filter .16s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; box-shadow: var(--shadow); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn-primary { background: linear-gradient(160deg, var(--primary), var(--primary-dark)); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-success:hover, .btn-danger:hover, .btn-warning:hover { filter: brightness(1.08); }
.btn-light { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-light:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 12px; font-size: 15px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 9px; flex-wrap: wrap; }

:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .btn-success,
:root[data-theme="dark"] .btn-danger,
:root[data-theme="dark"] .btn-warning { color: #08111f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary,
  :root:not([data-theme="light"]) .btn-success,
  :root:not([data-theme="light"]) .btn-danger,
  :root:not([data-theme="light"]) .btn-warning { color: #08111f; }
}

/* --------------------------------------------------------- نشان */

.badge {
  display: inline-block; padding: 2px 11px; border-radius: 20px;
  font-size: 14px; font-weight: 700; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}
.badge-success { background: var(--success-light); color: var(--success); border-color: transparent; }
.badge-danger { background: var(--danger-light); color: var(--danger); border-color: transparent; }
.badge-warning { background: var(--warning-light); color: var(--warning); border-color: transparent; }
.badge-info { background: var(--info-light); color: var(--info); border-color: transparent; }
.badge-primary { background: var(--primary-light); color: var(--primary); border-color: transparent; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 6px; vertical-align: middle; }

/* --------------------------------------------------------- پیام */

.alert {
  padding: 12px 15px; border-radius: var(--radius-sm);
  margin-bottom: 13px; font-size: 17px; border: 1px solid transparent;
  border-inline-start: 4px solid currentColor;
  display: flex; gap: 9px; align-items: flex-start;
  box-shadow: var(--shadow-xs);
}
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-info { background: var(--info-light); color: var(--info); }

/* --------------------------------------------------------- نمودار */

.bar-row { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; font-size: 16px; }
.bar-row .bar-label {
  flex: 0 1 130px; min-width: 55px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-row .bar-track {
  flex: 1 1 50px; min-width: 40px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 20px; height: 20px; overflow: hidden;
}
.bar-row .bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--bar-fill), var(--bar-fill-2));
  border-radius: 20px; min-width: 3px;
  transition: width .4s ease;
}
.bar-row .bar-fill.income { background: linear-gradient(90deg, var(--chart-income), var(--chart-income-2)); }
.bar-row .bar-fill.expense { background: linear-gradient(90deg, var(--chart-expense), var(--chart-expense-2)); }
.bar-row .bar-value {
  flex: 0 0 auto; text-align: left; font-variant-numeric: tabular-nums;
  white-space: nowrap; font-size: 15px;
}

.chart-columns { display: flex; align-items: flex-end; gap: 12px; height: 180px; padding: 10px 0; overflow-x: auto; }
.chart-col { flex: 1; min-width: 46px; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart-bars { display: flex; gap: 4px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart-bar {
  width: 16px; border-radius: 6px 6px 3px 3px; min-height: 3px;
  transition: filter .15s ease, transform .15s ease;
}
.chart-bar:hover { filter: brightness(1.12); transform: scaleX(1.15); }
.chart-bar.income { background: linear-gradient(180deg, var(--chart-income), var(--chart-income-2)); }
.chart-bar.expense { background: linear-gradient(180deg, var(--chart-expense), var(--chart-expense-2)); }
.chart-label { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 14.5px; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 4px; }
.legend i.income { background: var(--chart-income); }
.legend i.expense { background: var(--chart-expense); }

/* -------------------------------------------- جست‌وجوی اقلام (کمبوباکس) */

.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 60; inset-inline: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto; display: none;
  padding: 5px;
}
.combo-list.open { display: block; animation: pop-in .14s ease; }
.combo-item {
  padding: 9px 12px; cursor: pointer; font-size: 16px;
  border-radius: 9px; display: flex;
  justify-content: space-between; gap: 8px; align-items: center;
}
.combo-item:hover, .combo-item.active { background: var(--primary-light); color: var(--primary); }
.combo-item .meta { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.combo-item mark { background: transparent; color: var(--primary); font-weight: 800; }
.combo-empty { padding: 12px; color: var(--muted); font-size: 15px; text-align: center; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------ تقویم شمسی */

.jdp {
  position: absolute;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
  width: 294px;
  display: none;
  color: var(--text);
}
.jdp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.jdp-head b { font-size: 16px; }
.jdp-nav {
  border: 0; background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 3px 10px; cursor: pointer; font-size: 14px; line-height: 1.6;
  transition: background .15s ease, color .15s ease;
}
.jdp-nav:hover { background: var(--primary-light); color: var(--primary); }
.jdp-week, .jdp-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.jdp-week { font-size: 13.5px; color: var(--muted); }
.jdp-days { margin-top: 5px; }
.jdp-day { cursor: pointer; padding: 7px 0; border-radius: 9px; font-size: 16px; transition: background .12s ease; }
.jdp-day:hover { background: var(--surface-2); }
.jdp-day.is-today { background: var(--primary-light); color: var(--primary); font-weight: 700; }
.jdp-day.is-selected { background: var(--primary); color: #fff; font-weight: 700; }
.jdp-actions { display: flex; gap: 7px; margin-top: 10px; }

/* فاکتور چندقلمی: در موبایل هر ردیف یک کارت با کادرهای تمام‌عرض */
.invoice-table td { vertical-align: top; }
.invoice-table .inv-remove-text { display: none; }
.invoice-table .inv-members { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 180px; }
.invoice-table .inv-select-all { padding: 3px 10px; font-size: 13px; }
.invoice-table .inv-check-list { gap: 5px; }
.invoice-table .inv-check-list .check-item { padding: 4px 10px; font-size: 14.5px; gap: 5px; }

@media (max-width: 768px) {
  .invoice-table, .invoice-table tbody, .invoice-table tr, .invoice-table td { display: block; }
  .invoice-table thead { display: none; }
  table.invoice-table { min-width: 0; width: 100%; }
  .invoice-table tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
  }
  .invoice-table td { padding: 0; border: 0; }
  .invoice-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
    color: var(--muted);
  }
  /* نام قلم، قیمت واحد و مبلغ تمام‌عرض؛ تعداد و واحد کنار هم */
  .invoice-table td:first-child,
  .invoice-table td[data-label="قیمت واحد"],
  .invoice-table td[data-label="مبلغ"],
  .invoice-table td[data-label="مصرف‌کنندگان"],
  .invoice-table .inv-remove-cell { grid-column: 1 / -1; }
  .invoice-table .inv-members { min-width: 0; width: 100%; }
  .invoice-table .inv-check-list .check-item { font-size: 16px; padding: 8px 12px; }
  .invoice-table td[data-label="واحد"] {
    align-self: end;
    padding-bottom: 10px;
    font-size: 16px;
  }
  .invoice-table .form-control { font-size: 17px; padding: 12px 13px; }
  .invoice-table .inv-remove { width: 100%; padding: 9px; }
  .invoice-table .inv-remove-text { display: inline; }
  /* جدول‌های دیگر هم در موبایل بی‌دلیل کشیده نشوند */
  .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* پنل شخصی‌سازی کارت‌های داشبورد */
.card-picker { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.card-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  cursor: default;
}
.card-picker-row .check-item { flex: 1; margin: 0; border: 0; background: none; padding: 0; }
.card-picker-row.is-off { opacity: .55; }
.card-picker-row.is-dragging { opacity: .4; border-style: dashed; }
.card-picker-row .drag-handle {
  cursor: grab; color: var(--muted); font-size: 17px; line-height: 1; user-select: none;
}
.card-picker-icon { margin-inline-end: 4px; }
.card-picker-actions { display: flex; gap: 4px; }

/* تقویم چندانتخابی داخل فرم (روزهای دلخواه) */
.multi-cal {
  max-width: 340px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.multi-cal .jdp-day { user-select: none; }
.multi-cal .jdp-day[data-iso]:hover { background: var(--primary-light); color: var(--primary); }
.jdp-btn {
  flex: 1; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 6px; cursor: pointer; font-family: inherit; font-size: 15px;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.jdp-btn:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }

/* --------------------------------------------------------- ورود */

.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, var(--auth-bg-1) 0%, var(--auth-bg-2) 100%);
  position: relative;
  overflow: hidden;
}
.auth-page::before,
.auth-page::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .35;
  pointer-events: none;
}
.auth-page::before { width: 380px; height: 380px; background: var(--primary); top: -110px; inset-inline-end: -90px; }
.auth-page::after { width: 320px; height: 320px; background: var(--sidebar-accent); bottom: -120px; inset-inline-start: -80px; }
.auth-card {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 410px; padding: 32px 28px;
  border: 1px solid var(--border);
  position: relative;
  z-index: 1;
}
.auth-card .auth-logo {
  width: 64px; height: 64px; border-radius: 20px;
  background: linear-gradient(140deg, var(--primary), var(--sidebar-accent));
  color: #fff; display: grid; place-items: center; font-size: 30px; margin: 0 auto 16px;
  box-shadow: var(--shadow-md);
}
.auth-card h1 { font-size: 23px; text-align: center; margin: 0 0 4px; }
.auth-card .subtitle { text-align: center; color: var(--muted); font-size: 16px; margin-bottom: 22px; }
.auth-footer { text-align: center; margin-top: 18px; font-size: 12px; color: rgba(255,255,255,.75); position: relative; z-index: 1; }

/* --------------------------------------------------------- کمکی */

.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-center { text-align: center; }
.text-left { text-align: left; }
.small { font-size: 15px; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; } .flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; } .gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.nowrap { white-space: nowrap; }
.w-100 { width: 100%; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
code {
  background: var(--surface-2); padding: 2px 7px; border-radius: 6px; font-size: 15px;
  border: 1px solid var(--border);
}

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 16px; font-size: 17px; color: var(--muted); border-bottom: 2px solid transparent;
  font-weight: 700; border-radius: 10px 10px 0 0;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--primary-light); }
.tabs a:hover { text-decoration: none; color: var(--primary); background: var(--surface-2); }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 6px 13px; border: 1px solid var(--border-strong); border-radius: 9px;
  font-size: 16px; background: var(--surface); color: var(--text);
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.pagination a:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

.money { font-variant-numeric: tabular-nums; font-weight: 700; }
.money.expense { color: var(--danger); }
.money.income { color: var(--success); }

details.help {
  background: var(--info-light); border-radius: var(--radius-sm); padding: 11px 15px;
  margin-bottom: 15px; font-size: 16px; border-inline-start: 4px solid var(--info);
}
details.help summary { cursor: pointer; font-weight: 700; color: var(--info); }
details.help ul { margin: 8px 0 0; padding-right: 18px; }

.qr-box { background: #fff; padding: 14px; border-radius: 14px; display: inline-block; box-shadow: var(--shadow); }

/* کد اتصال به ربات تلگرام */
.pair-code {
  font-family: Consolas, monospace;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 6px;
  text-align: center;
  padding: 16px 8px;
  border-radius: var(--radius);
  background: var(--primary-light);
  color: var(--primary);
  border: 2px dashed var(--primary);
  user-select: all;
}

/* ------------------------------------------------------- واکنش‌گرا */

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

@media (max-width: 992px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* کارت‌های دو ستونه با ستون ثابت (تعاریف) هم تک‌ستونه شوند */
  .grid[style*="320px"], .grid[style*="330px"] { grid-template-columns: 1fr !important; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed; right: 0; top: 0; z-index: 100; transform: translateX(100%);
    transition: transform .22s ease; box-shadow: var(--shadow-lg);
    width: min(84vw, 300px);
  }
  .sidebar.open { transform: translateX(0); }
  /* در موبایل همیشه حالت کامل (نه باریک) */
  :root.nav-rail .sidebar { width: min(84vw, 300px); }
  :root.nav-rail .sidebar .brand-text,
  :root.nav-rail .nav-search,
  :root.nav-rail .nav-text,
  :root.nav-rail .nav-badge,
  :root.nav-rail .nav-group-title span:first-child,
  :root.nav-rail .nav-chev { display: revert; }
  :root.nav-rail .nav-group-title {
    height: auto; padding: 6px 12px; margin: 10px 10px 2px;
    background: none; pointer-events: auto;
  }
  :root.nav-rail .sidebar a.nav-link { justify-content: flex-start; padding: 9px 12px; }
  .sidebar-rail-toggle { display: none; }
  body.nav-open { overflow: hidden; }
  .menu-toggle { display: block; }
  .grid-2, .grid-3, .grid-4, .form-grid, .form-grid.two, .perm-grid { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .card-body { padding: 14px; }
  .bar-row .bar-label { flex-basis: 90px; font-size: 12px; }
  .bar-row .bar-value { font-size: 11.5px; }
  .topbar .meta { display: none; }
  .topbar .user-box > div:first-child { display: none; }
  .stat .value { font-size: 23px; }
}

/* کاربرانی که انیمیشن کمتر می‌خواهند */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------------------------------------------------------- چاپ */

@media print {
  :root {
    --bg: #fff; --surface: #fff; --surface-2: #fff; --surface-3: #fff;
    --text: #000; --border: #ccc; --border-strong: #999; --row-active: transparent;
  }
  .sidebar, .topbar, .no-print, .btn, .pagination, .theme-toggle { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; background-image: none; }
  .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
  .card:hover { box-shadow: none; }
  .stat { box-shadow: none; }
  .content { padding: 0; }
}
