:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.navbar-inner { display: flex; align-items: center; justify-content: space-between; }
.navbar-brand { font-weight: 700; font-size: 18px; color: var(--text); }
.navbar-links { display: flex; gap: 16px; align-items: center; }
.navbar-links a { color: var(--muted); font-weight: 500; }
.navbar-links a:hover { color: var(--primary); text-decoration: none; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-title { font-size: 16px; font-weight: 700; margin: 0 0 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: white; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { background: var(--red); color: white; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 6px; font-size: 11px; font-weight: 500; }

.btn-pink {
  background: #fce7f3;
  color: #be185d;
  border: 1px solid #fbcfe8;
}
.btn-pink:hover {
  background: #fbcfe8;
  color: #9d174d;
}

.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }
.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  background: white;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; background: white; }
.table th {
  background: #f9fafb;
  padding: 10px 12px;
  text-align: center;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover { background: #f9fafb; }
.table .num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

.row-normal { background: var(--green-bg) !important; }
.row-normal:hover { background: #bbf7d0 !important; }
.row-below, .row-above { background: var(--red-bg) !important; }
.row-below:hover, .row-above:hover { background: #fecaca !important; }
.row-unknown { background: var(--amber-bg) !important; }
.row-ignored {
  background: #e5e7eb !important;
  color: #6b7280;
}
.row-ignored:hover { background: #d1d5db !important; }
.row-review {
  background: #fef3c7 !important;
  border-right: 4px solid #f59e0b;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: #f3f4f6; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  border: 1px solid;
}
.alert-error { background: var(--red-bg); color: var(--red); border-color: #fecaca; }
.alert-success { background: var(--green-bg); color: var(--green); border-color: #bbf7d0; }
.alert-info { background: var(--blue-bg); color: var(--blue); border-color: #bfdbfe; }
.alert-warn { background: var(--amber-bg); color: var(--amber); border-color: #fde68a; }

.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
}
.login-card { width: 100%; max-width: 400px; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.member-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-top: 8px;
  background: white;
}
.member-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.member-item:last-child { border-bottom: none; }
.member-item:hover { background: #f9fafb; }
.member-item.selected { background: #dbeafe; border-right: 3px solid #2563eb; }
.member-name { font-weight: 500; }
.member-meta { font-size: 11px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }

.hidden { display: none; }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* پیجینیشن استاندارد */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.pagination-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
}
.page-btn:hover:not(.disabled):not(.current) {
  background: #f3f4f6;
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}
.page-btn.current {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 700;
  cursor: default;
}
.page-btn.disabled {
  background: #f9fafb;
  color: #d1d5db;
  cursor: not-allowed;
  pointer-events: none;
}
.page-ellipsis {
  padding: 0 4px;
  color: var(--muted);
  user-select: none;
}

/* ستون‌های کوتاه وسط‌چین */
.table td.num,
.table td:has(+ td) { text-align: right; }

/* ساده‌تر: سلول‌های عددی وسط‌چین */
.table td.num { text-align: center; }


/* ========== Toolbar بالای جدول ========== */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.table-toolbar .toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.table-toolbar .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* جستجو */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box .search-input {
  width: 280px;
  padding: 7px 36px 7px 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  background: white;
  transition: border-color .15s, box-shadow .15s;
}
.search-box .search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.search-box .search-icon {
  position: absolute;
  right: 12px;
  color: var(--muted);
  pointer-events: none;
  font-size: 14px;
}
.search-box .search-clear {
  position: absolute;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  padding: 0;
  font-family: inherit;
}
.search-box .search-clear:hover {
  background: #f3f4f6;
  color: var(--text);
}
.search-box.has-value .search-clear { display: inline-flex; }

/* سورت ستون‌ها */
.table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.table th.sortable:hover {
  background: #eef2ff;
}
.table th .sort-icon {
  display: inline-block;
  margin-right: 4px;
  color: #d1d5db;
  font-size: 11px;
}
.table th.sorted-asc .sort-icon,
.table th.sorted-desc .sort-icon {
  color: var(--primary);
}

/* پیجینیشن فشرده بالای جدول */
.pagination-top {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.pagination-top .page-info {
  font-size: 12px;
  color: var(--muted);
  margin-right: 8px;
}

/* فرمت منفی حسابداری */
.amount-negative {
  color: var(--red);
  font-weight: 500;
}


/* ========== مودال جدید ========== */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.modal-close:hover { background: #f3f4f6; color: var(--text); }
.modal-body { padding-bottom: 8px; }
.modal-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.info-box {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  gap: 12px;
}
.info-label { color: var(--muted); font-weight: 500; }
.info-value { font-weight: 600; }

/* ========== Toast ========== */
#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 20px;
  border-radius: 999px;
  background: #1f2937;
  color: white;
  font-weight: 500;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }

/* ============================================================
   Layout جدید: Topbar + Sidebar راست + محتوا
   ============================================================ */

:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

body {
  transition: padding-right .2s ease;
}
body.has-shell {
  padding-top: var(--topbar-height);
  padding-right: var(--sidebar-width);
}

/* ===== Topbar ===== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  z-index: 100;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px;
}
.topbar-brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}
.user-name {
  font-weight: 600;
  font-size: 13px;
}
.user-role {
  font-size: 11px;
  color: var(--muted);
}
.topbar-hamburger {
  display: none;
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--text);
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  right: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  z-index: 90;
  transition: transform .2s ease;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.sidebar-link:hover {
  background: #f3f4f6;
  color: var(--primary);
  text-decoration: none;
}
.sidebar-link.active {
  background: var(--blue-bg);
  color: var(--primary);
  font-weight: 600;
}
.sidebar-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* ===== Overlay (موبایل) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 80;
}

/* ===== Main content ===== */
.main-content {
  padding: 24px 24px 40px;
  max-width: 1400px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  body { padding-right: 0; }
  .sidebar {
    transform: translateX(100%);
    box-shadow: -2px 0 8px rgba(0,0,0,.1);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .topbar-hamburger { display: inline-block; }
  .main-content { padding: 16px; }
}

/* صفحه لاگین: وسط‌چین افقی و عمودی */
.login-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* login-wrap نیازی به min-height دیگه نداره چون main داره */
.login-main .login-wrap {
  min-height: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
}
/* دکمه تمام‌عرض با متن وسط‌چین */
.btn-block {
  width: 100%;
  justify-content: center;
  text-align: center;
}