:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6b7686;
  --line: #e2e7ef;
  --brand: #1f5fbf;
  --brand-dark: #174a96;
  --profit: #0f7a4d;
  --loss: #c0392b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(24, 39, 75, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Tahoma, "Segoe UI", "Noto Naskh Arabic", sans-serif;
  font-size: 14px;
  line-height: 1.7;
}

.shell {
  width: 100%;
  margin: 0;
}

body.no-scroll { overflow: hidden; }

h1, h2 { margin: 0; line-height: 1.4; }
h1 { font-size: 26px; }
h2 { font-size: 17px; margin-bottom: 14px; }
h3 { font-size: 15px; margin: 18px 0 10px; }

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

button:hover { background: var(--brand-dark); }
button:active { transform: translateY(1px); }

button.quiet {
  background: #eaf0fb;
  color: var(--brand);
}

button.quiet:hover { background: #dbe6fa; }

button.delete {
  background: #fdeceb;
  color: var(--loss);
  padding: 6px 12px;
  font-size: 12px;
}

button.delete:hover { background: #fadbd8; }

textarea { resize: vertical; min-height: 42px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.12);
}

input[readonly] {
  background: #f5f7fb;
  color: var(--muted);
}

.date-input {
  cursor: pointer;
  background: #fff;
  color: var(--ink);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.login-card {
  width: min(380px, calc(100% - 32px));
  margin: 10vh auto 0;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.login-card h1 { margin-bottom: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.summary article {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary span { font-size: 12px; color: var(--muted); }
.summary strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.summary article.balance {
  background: linear-gradient(135deg, #1f5fbf, #2f7de1);
  color: #fff;
}

.summary article.balance span { color: rgba(255, 255, 255, 0.82); }

.sale-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  align-items: end;
  margin-bottom: 8px;
}

.sale-form .wide { grid-column: 1 / -1; }

.sale-form button { height: 40px; }

.statement-items { display: grid; gap: 10px; }

.items-head,
.item-row {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) 90px 130px 130px 44px;
  gap: 8px;
  align-items: center;
}

.items-head { font-size: 12px; color: var(--muted); }

.item-row select,
.item-row input { padding: 8px 10px; }

.item-total { font-size: 13px; text-align: left; }

.item-remove {
  height: 36px;
  padding: 0;
  background: #fdeceb;
  color: var(--loss);
  font-size: 18px;
  line-height: 1;
}

.item-remove:hover { background: #fadbd8; }

.items-total { margin-top: 6px; text-align: left; font-size: 14px; }
.items-total strong { color: var(--brand); }

.statement-payment {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  align-items: end;
}

.statement-items[hidden],
.statement-payment[hidden] { display: none; }

.account-balance {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 20px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1f5fbf, #2f7de1);
  color: #fff;
}

.account-balance span { font-size: 13px; color: rgba(255, 255, 255, 0.85); }
.account-balance strong { font-size: 18px; font-variant-numeric: tabular-nums; }

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.detail-meta > div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafd;
  padding: 10px 12px;
}

.detail-meta span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-meta strong { font-size: 14px; }

.detail-payment {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.detail-payment[hidden] { display: none; }

.detail-payment > div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafd;
  padding: 10px 12px;
}

.detail-payment span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-payment strong { font-size: 14px; }

.detail-notes {
  margin: 0 0 16px;
  border-radius: 10px;
  background: #f8fafd;
  padding: 12px;
  color: var(--text);
}

.detail-actions button.delete { padding: 10px 18px; font-size: 14px; }

.detail-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 12px 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.detail-totals strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

#statement-detail-returns-wrap { margin: 8px 0 16px; }
#statement-detail-returns-wrap h3,
#statement-return-form-wrap h3 { margin: 18px 0 10px; font-size: 15px; }
#statement-detail-returns-wrap table { min-width: 780px; }
#statement-return-form-wrap {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
#statement-return-form-wrap table { min-width: 720px; }
#statement-return-items input { width: 100px; }

.return-badge {
  display: inline-block;
  margin-right: 6px;
  border-radius: 999px;
  background: #fff4e5;
  color: #b45309;
  padding: 2px 8px;
  font-size: 11px;
  vertical-align: middle;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

.success { margin: 4px 0 0; color: #157347; font-size: 13px; min-height: 1em; }

@media (max-width: 700px) {
  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .item-product { grid-column: 1 / -1; }
  .item-row .item-remove { grid-column: 1 / -1; }
}

.error {
  margin: 4px 0 0;
  color: var(--loss);
  font-size: 13px;
  min-height: 1em;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  font-variant-numeric: tabular-nums;
}

th, td {
  text-align: right;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: #f8fafd;
  position: sticky;
  top: 0;
}

tbody tr:hover { background: #f9fbff; }
tbody tr.clickable-row { cursor: pointer; }
tbody tr:last-child td { border-bottom: 0; }

td.profit { color: var(--profit); font-weight: 600; }
td.loss { color: var(--loss); font-weight: 600; }

.empty {
  margin: 18px 0 4px;
  color: var(--muted);
  text-align: center;
}

input[type="file"] { padding: 7px; }

.hint { color: var(--muted); font-size: 11px; }

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
}

.image-preview[hidden] { display: none; }

.image-preview img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4f6fa;
}

.image-preview span { color: var(--muted); font-size: 12px; }

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.product-card {
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.product-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  background: #f4f6fa;
  color: var(--muted);
  font-size: 12px;
}

.product-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-body { padding: 10px 12px 12px; }
.product-body strong { display: block; font-size: 14px; }
.product-body span { display: block; color: var(--muted); font-size: 12px; }

.name-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.name-list li {
  padding: 6px 14px;
  border-radius: 999px;
  background: #eef3fb;
  color: var(--brand);
  font-size: 13px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

button.edit {
  background: #eaf0fb;
  color: var(--brand);
  padding: 6px 12px;
  font-size: 12px;
}

button.edit:hover { background: #dbe6fa; }

/* چیدمان داشبورد و سایدبار */
.app-shell {
  --sidebar-width: 272px;
  min-height: 100vh;
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin-right: var(--sidebar-width);
  transition: margin-right 0.25s ease;
}

.main-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 26px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.main-header h1 { font-size: 18px; font-weight: 600; }

.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  background: #eaf0fb;
  color: var(--brand);
  font-size: 18px;
}

.menu-toggle:hover { background: #dbe6fa; }

.content {
  flex: 1;
  min-width: 0;
  padding: 24px 26px 48px;
}

.view[hidden] { display: none; }

.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, #0f172a 0%, #111c33 100%);
  color: #cbd5e1;
  box-shadow: -12px 0 30px rgba(15, 23, 42, 0.12);
  transition: width 0.25s ease, transform 0.28s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.brand-text strong { display: block; color: #fff; font-size: 16px; line-height: 1.4; }
.brand-text small { display: block; color: #94a3b8; font-size: 11px; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
}

.nav-label {
  margin: 0 10px 10px;
  font-size: 10px;
  letter-spacing: 1px;
  color: #64748b;
}

.acc-group { margin-bottom: 4px; }

.acc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  background: transparent;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 500;
  text-align: right;
}

.acc-header:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.acc-header.active { background: var(--brand); color: #fff; }
.acc-header.active:hover { background: var(--brand); }

.acc-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 20px;
  height: 20px;
}

.acc-icon svg { width: 18px; height: 18px; }

.acc-text { flex: 1; }

.acc-chevron {
  flex: none;
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.acc-group.open .acc-chevron { transform: rotate(-135deg); }

.acc-panel {
  max-height: 0;
  overflow: hidden;
  visibility: hidden;
  transition: max-height 0.25s ease, visibility 0.25s;
}

.acc-group.open .acc-panel {
  max-height: 260px;
  visibility: visible;
}

.acc-link {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 8px 44px 8px 12px;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 400;
  text-align: right;
}

.acc-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.acc-link.active { background: rgba(31, 95, 191, 0.35); color: #fff; }

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

.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  font-size: 13px;
}

.sidebar-logout:hover { background: rgba(239, 68, 68, 0.85); color: #fff; }
.sidebar-logout svg { width: 16px; height: 16px; }

.sidebar-backdrop { display: none; }

@media (min-width: 901px) {
  .app-shell.rail-collapsed { --sidebar-width: 76px; }

  .rail-collapsed .brand-text,
  .rail-collapsed .nav-label,
  .rail-collapsed .acc-text,
  .rail-collapsed .acc-chevron,
  .rail-collapsed .acc-panel,
  .rail-collapsed .sidebar-logout span { display: none; }

  .rail-collapsed .sidebar-brand { justify-content: center; padding: 20px 0; }
  .rail-collapsed .sidebar-nav { padding: 16px 10px; }
  .rail-collapsed .acc-header { justify-content: center; padding: 12px 0; }
  .rail-collapsed .acc-icon { width: 22px; height: 22px; }
  .rail-collapsed .sidebar-footer { padding: 14px 10px; }
  .rail-collapsed .sidebar-logout { padding: 11px 0; }
}

/* تقویم شمسی */
.datepicker {
  position: fixed;
  z-index: 1000;
  width: 300px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 45px rgba(24, 39, 75, 0.18);
  direction: rtl;
  user-select: none;
}

.dp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 10px;
}

.dp-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}

button.dp-nav {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  background: #eef3fb;
  color: var(--brand);
  font-size: 16px;
  line-height: 1;
}

button.dp-nav:hover { background: #dbe6fa; }

.dp-week,
.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.dp-week {
  margin-bottom: 6px;
}

.dp-week span {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 0;
}

.dp-empty { display: block; }

button.dp-day {
  height: 34px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

button.dp-day:hover { background: #eef3fb; }

button.dp-day.today {
  box-shadow: inset 0 0 0 1px var(--brand);
}

button.dp-day.selected {
  background: var(--brand);
  color: #fff;
}

button.dp-day.selected:hover { background: var(--brand-dark); }

.dp-foot {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

button.dp-today {
  background: #eaf0fb;
  color: var(--brand);
  padding: 6px 14px;
  font-size: 12px;
}

button.dp-today:hover { background: #dbe6fa; }

@media (max-width: 900px) {
  .main { margin-right: 0; }
  .menu-toggle { display: inline-flex; }
  .sidebar {
    transform: translateX(100%);
    transition: transform 0.28s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(15, 23, 42, 0.45);
  }
  .sidebar-backdrop.show { display: block; }
  .content { padding: 18px 14px 40px; }
  .main-header { padding: 12px 14px; }
}

@media (max-width: 640px) {
  .panel { padding: 16px; }
  .main-header h1 { font-size: 16px; }
  .datepicker { width: min(300px, calc(100vw - 16px)); }
}
