@font-face {
  font-family: 'YekanBakhFaNum';
  src: url('fonts/YekanBakhFaNum-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'YekanBakhFaNum';
  src: url('fonts/YekanBakhFaNum-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'YekanBakhFaNum';
  src: url('fonts/YekanBakhFaNum-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

html,
body,
button,
input,
select,
textarea,
table {
  font-family: 'YekanBakhFaNum', Tahoma, Arial, sans-serif !important;
}

:root {
  --bg: #f4f7fb;
  --bg-2: #eef3fb;
  --card: rgba(255, 255, 255, 0.92);
  --card-solid: #ffffff;
  --text: #111827;
  --text-soft: #334155;
  --muted: #718096;
  --muted-2: #94a3b8;
  --line: #e6eaf2;
  --line-strong: #d7deea;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eaf1ff;
  --primary-ring: rgba(37, 99, 235, 0.16);
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --info: #0ea5e9;
  --info-soft: #e0f2fe;
  --shadow-sm: 0 8px 22px rgba(15, 23, 42, 0.055);
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.075);
  --shadow-lg: 0 24px 70px rgba(15, 23, 42, 0.12);
  --radius-sm: 14px;
  --radius: 22px;
  --radius-lg: 28px;
  --sidebar: 278px;
}

* { box-sizing: border-box; }

html {
  direction: rtl;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% 8%, rgba(37, 99, 235, 0.12), transparent 28%),
    radial-gradient(circle at 88% 14%, rgba(14, 165, 233, 0.10), transparent 26%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  font-size: 14px;
  line-height: 1.85;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.45) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.45) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.65), transparent 70%);
  z-index: -1;
}

a { color: inherit; }

::selection {
  background: rgba(37, 99, 235, 0.18);
  color: var(--primary-hover);
}

/* Layout */
.sidebar {
  position: fixed;
  inset: 18px 18px 18px auto;
  width: var(--sidebar);
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(226, 232, 240, .86);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 8px 10px;
  color: #0f172a;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: -0.02em;
}

.brand::before {
  content: "";
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #22c55e);
  box-shadow: 0 12px 26px rgba(37, 99, 235, .25);
}

nav {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

nav a {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 11px 14px;
  border-radius: 16px;
  color: #475569;
  text-decoration: none;
  font-weight: 600;
  transition: transform .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease;
}

nav a:hover {
  transform: translateX(-2px);
  background: rgba(37, 99, 235, .08);
  color: var(--primary);
}

nav a.active {
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: #fff;
  box-shadow: 0 12px 28px rgba(37, 99, 235, .25);
}

.userbox {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(226, 232, 240, .75);
  border-radius: 18px;
  background: rgba(248, 250, 252, .9);
  color: var(--muted);
  font-size: 13px;
}

.userbox a {
  float: left;
  color: var(--danger);
  text-decoration: none;
  font-weight: 600;
}

.main {
  margin-right: calc(var(--sidebar) + 36px);
  padding: 28px 28px 40px;
  min-height: 100vh;
}

.auth-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* Cards and headings */
.login-card,
.card,
.narrow {
  background: var(--card);
  border: 1px solid rgba(226, 232, 240, .88);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.card {
  padding: 22px;
  margin-bottom: 18px;
}

.login-card {
  width: min(450px, 100%);
  padding: 34px;
}

.login-card h1,
.topbar h1 {
  margin: 0;
  color: #0f172a;
  letter-spacing: -0.03em;
}

.login-card h1 { font-size: 24px; }
.login-card p { color: var(--muted); margin: 8px 0 24px; }

.login-card .login-submit {
  margin-top: 20px;
}


.narrow {
  max-width: 720px;
  margin: 54px auto;
  padding: 30px;
}

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

.topbar h1 {
  font-size: clamp(22px, 2.5vw, 32px);
  font-weight: 800;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

h2 {
  margin: 0 0 18px;
  color: #0f172a;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h3 { color: #0f172a; }

.muted,
small.muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

small.muted { display: block; margin-top: 3px; }

/* Grids */
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.stat {
  position: relative;
  overflow: hidden;
  min-height: 138px;
}

.stat::after {
  content: "";
  position: absolute;
  left: -42px;
  top: -42px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(37,99,235,.13), transparent 68%);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.stat b {
  display: block;
  margin: 12px 0 3px;
  color: #0f172a;
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.stat small { color: var(--muted); }

/* Forms */
.filters,
.search-inline,
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: end;
}

.form-grid .wide { grid-column: span 2; }

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 45px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .9);
  border-radius: 15px;
  padding: 11px 13px;
  color: #111827;
  font-size: 14px;
  line-height: 1.8;
  outline: none;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

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

input::placeholder,
textarea::placeholder {
  color: #a8b1c3;
  font-size: 14px;
}


select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%2318273a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 20px center;
  padding-inline-start: 16px;
  padding-inline-end: 16px;
  padding-left: 46px;
}

select option { font-size: 14px; }

input:focus,
select:focus,
textarea:focus {
  border-color: #93c5fd;
  background: #fff;
  box-shadow: 0 0 0 5px var(--primary-ring);
}

.check {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  min-height: 45px;
  padding: 12px 14px;
  border: 1px solid rgba(226, 232, 240, .75);
  border-radius: 15px;
  background: rgba(248, 250, 252, .9);
}

.check input {
  width: 18px;
  min-height: auto;
  height: 18px;
  accent-color: var(--primary);
}

.btn,
button.btn,
a.btn {
  min-height: 43px;
  border: 0;
  border-radius: 15px;
  padding: 10px 16px;
  background: #eef2f7;
  color: #0f172a;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: none;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease, color .16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: #e2e8f0;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: #fff;
  box-shadow: 0 12px 24px rgba(37, 99, 235, .23);
}

.btn.primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), var(--primary));
}

.btn.danger {
  background: var(--danger-soft);
  color: #b91c1c;
}

.btn.danger:hover { background: #fecaca; }

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 11px;
  font-size: 12px;
}

.btn.full { width: 100%; }

/* Tables */
.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.table-head h2 { margin: 0 0 4px; }

.search-inline { min-width: min(560px, 100%); }
.search-inline input { min-width: 280px; }

.table-wrap,
.card:has(table) {
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

th,
td {
  text-align: right;
  border-bottom: 1px solid var(--line);
  padding: 14px 11px;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #64748b;
  background: rgba(248, 250, 252, .96);
  font-size: 12px;
  font-weight: 700;
}

tbody tr {
  transition: background .15s ease;
}

tr:hover td { background: rgba(248, 250, 252, .72); }

td:first-child,
th:first-child { border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
td:last-child,
th:last-child { border-top-left-radius: 12px; border-bottom-left-radius: 12px; }

.actions {
  white-space: nowrap;
  flex-wrap: nowrap;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 34px 16px;
}

.alert {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 9999;
  min-width: 280px;
  max-width: 420px;
  box-shadow: 0 12px 30px rgba(15,23,42,.18);
  transform: translateX(-120%);
  opacity: 0;
  transition: transform .45s ease, opacity .45s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  margin-bottom: 18px;
  border: 1px solid #bbf7d0;
  border-radius: 18px;
  background: linear-gradient(135deg, #ecfdf5, #f0fdf4);
  color: #166534;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok { background: var(--ok-soft); color: #166534; }
.badge.danger { background: var(--danger-soft); color: #b91c1c; }
.badge.info { background: var(--info-soft); color: #0369a1; }

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* Charts / bars */
.bars { display: flex; flex-direction: column; gap: 14px; }

.barrow {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 160px;
  gap: 12px;
  align-items: center;
}

.barrow label {
  display: block;
  color: var(--text-soft);
  font-size: 12px;
}

.barrow strong {
  color: #475569;
  font-size: 12px;
  text-align: left;
}

.bar {
  height: 13px;
  background: #eaf0f7;
  border-radius: 999px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, var(--primary));
  box-shadow: 0 6px 16px rgba(37, 99, 235, .25);
}

.tips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tips p {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(248, 250, 252, .82);
  line-height: 1.95;
}

.petty-help {
  display: block;
  grid-template-columns: none;
  gap: 0;
  margin-top: 12px;
}

.petty-help p {
  margin: 4px 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.85;
}

.petty-help p b {
  color: var(--text);
  font-weight: 600;
}

.version-badge {
  margin: 22px 0 0;
  color: var(--muted-2);
  font-size: 12px;
  text-align: center;
}

/* Persian datepicker */
.jdp,
.jalali-picker {
  position: absolute;
  z-index: 9999;
  width: min(310px, calc(100vw - 24px));
  background: rgba(255,255,255,.98);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
  direction: rtl;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.jdp.hidden,
.jalali-picker[style*="display: none"] { display: none !important; }

.jdp-head,
.jp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.jdp-head button,
.jdp-foot button,
.jdp-days button,
.jp-head button,
.jp-days button {
  border: 0;
  background: #f1f5f9;
  border-radius: 12px;
  cursor: pointer;
  color: #0f172a;
}

.jdp-head button,
.jp-head button {
  width: 38px;
  height: 38px;
  font-size: 22px;
}

.jdp-head button svg {
  width: 18px;
  height: 18px;
  display: block;
  margin: auto;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.jdp-head div { display: flex; gap: 6px; flex: 1; }
.jdp-head select,
.jdp-head input { height: 38px; min-height: 38px; padding: 6px 8px; border-radius: 12px; }
.jdp-head input { max-width: 82px; text-align: center; }

.jdp-week,
.jdp-days,
.jp-week,
.jp-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.jdp-week span,
.jp-week span {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 0;
}

.jdp-days button,
.jdp-days span,
.jp-days button,
.jp-days span {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.jdp-days button:hover,
.jp-days button:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.jdp-days button.is-today {
  position: relative;
  color: var(--primary);
  background: rgba(14, 165, 233, .11);
  box-shadow: inset 0 0 0 1px rgba(14, 165, 233, .2);
}

.jdp-days button.is-today::after {
  content: '';
  position: absolute;
  bottom: 5px;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: var(--primary);
}

.jdp-days button.is-selected {
  background: var(--primary);
  color: #fff;
  box-shadow: none;
}

.jdp-days button.is-selected::after {
  background: #fff;
}

.jdp-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.jdp-foot button { padding: 9px 12px; color: #475569; }

/* AJAX item search */
.ajax-search-wrap {
  position: relative;
  width: 100%;
}

.ajax-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  z-index: 9998;
  max-height: 280px;
  overflow: auto;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.98);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.ajax-results.hidden { display: none; }

.ajax-result-item {
  width: 100%;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--text);
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 12px;
  cursor: pointer;
}

.ajax-result-item:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.ajax-result-item strong { font-size: 13px; font-weight: 700; }
.ajax-result-item small { color: var(--muted); font-size: 11px; }
.ajax-loading,
.ajax-empty { padding: 12px; color: var(--muted); font-size: 12px; text-align: center; }

/* Large tablets */
@media (max-width: 1180px) {
  :root { --sidebar: 240px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
  .tips { grid-template-columns: 1fr; }
}

/* Tablets and mobile */
@media (max-width: 860px) {
  body { font-size: 13px; }

  .sidebar {
    position: sticky;
    top: 0;
    inset-inline: auto;
    width: 100%;
    border-radius: 0 0 24px 24px;
    border-top: 0;
    border-right: 0;
    border-left: 0;
    padding: 12px;
    gap: 10px;
  }

  .brand {
    min-height: 42px;
    padding: 4px 8px;
    font-size: 15px;
  }

  .brand::before {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    border-radius: 13px;
  }

  nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  nav::-webkit-scrollbar { display: none; }

  nav a {
    min-width: max-content;
    min-height: 40px;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 12px;
  }

  nav a:hover { transform: none; }

  .userbox {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 0;
    padding: 10px 12px;
  }

  .userbox a { float: none; }

  .main {
    margin-right: 0;
    padding: 18px 14px 30px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .filters {
    width: 100%;
    flex-wrap: wrap;
  }

  .filters > * { flex: 1 1 160px; }

  .cards,
  .form-grid,
  .two,
  .tips {
    grid-template-columns: 1fr;
  }

  .form-grid .wide { grid-column: auto; }

  .card { padding: 16px; border-radius: 20px; }

  .table-head {
    flex-direction: column;
    align-items: stretch;
  }

  .search-inline {
    min-width: 0;
    width: 100%;
    flex-wrap: wrap;
  }

  .search-inline input {
    min-width: 0;
    flex: 1 1 100%;
  }

  .search-inline .btn { flex: 1 1 auto; }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    min-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  thead,
  tbody,
  tr { min-width: 760px; }

  th,
  td { padding: 12px 10px; }

  .barrow {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .barrow strong { text-align: right; }

  .actions { gap: 6px; }
}

/* Small mobile */
@media (max-width: 520px) {
  body { line-height: 1.75; }

  .main { padding: 14px 10px 26px; }

  .sidebar { padding: 10px; }

  .brand { font-size: 14px; }

  .topbar h1 { font-size: 22px; }

  .topbar p { font-size: 12px; }

  .login-card,
  .narrow {
    padding: 22px;
    border-radius: 22px;
  }

  .card {
    padding: 14px;
    margin-bottom: 14px;
  }

  .stat {
    min-height: 118px;
  }

  .stat b { font-size: 21px; }

  input,
  select,
  textarea,
  .btn {
    min-height: 46px;
    border-radius: 14px;
  }

  .btn:not(.small) { width: 100%; }

  .actions .btn,
  .btn.small {
    width: auto;
    min-height: 34px;
  }

  .pagination .btn {
    width: auto;
  }

  .jdp,
  .jalali-picker {
    position: fixed !important;
    right: 10px !important;
    left: 10px !important;
    top: auto !important;
    bottom: 12px !important;
    width: auto;
    max-height: calc(100vh - 24px);
    overflow: auto;
    border-radius: 24px;
  }

  .ajax-results {
    position: fixed;
    right: 10px;
    left: 10px;
    top: auto;
    bottom: 12px;
    max-height: min(420px, 70vh);
    border-radius: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

/* v14 security patch: inline POST forms for delete/logout */
.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.userbox .inline-form {
  display: inline-flex;
  margin-inline-start: 8px;
}

.linklike {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 0;
}

.linklike:hover {
  color: var(--primary);
}

/* v16 - purchase invoice multi-line rows */
.invoice-head {
  margin-bottom: 22px;
}

.invoice-lines-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 10px 0 16px;
}

.invoice-lines-head h2 {
  margin: 0 0 4px;
}

.purchase-lines {
  display: grid;
  gap: 12px;
}

.purchase-line {
  display: grid;
  grid-template-columns: 44px minmax(260px, 1.5fr) minmax(140px, .7fr) minmax(160px, .8fr) auto;
  align-items: end;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(248, 250, 252, .8);
}

.purchase-line label {
  margin: 0;
}

.line-no {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(37, 99, 235, .1);
  color: var(--primary);
  font-weight: 700;
  align-self: center;
}

.purchase-submit {
  margin-top: 18px;
  min-width: 260px;
}

@media (max-width: 900px) {
  .invoice-lines-head {
    flex-direction: column;
    align-items: stretch;
  }
  .purchase-line {
    grid-template-columns: 42px 1fr;
  }
  .purchase-line label,
  .purchase-line .remove-purchase-line {
    grid-column: 1 / -1;
  }
  .line-no {
    grid-column: 1 / 2;
  }
}


/* Numeric typography for Rial amounts */
.money-input {
  direction: ltr;
  text-align: left !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
td, th, .stat-value, .metric-value {
  font-variant-numeric: tabular-nums;
}


/* v21 - invoice calculation preview */
.line-total-wrap input.line-total {
  background: rgba(15, 23, 42, 0.035);
  color: #0f172a;
  font-weight: 700;
  direction: ltr;
  text-align: left;
}
.invoice-total-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0;
  padding: 14px 18px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(14, 165, 233, 0.06));
  border: 1px solid rgba(37, 99, 235, 0.12);
}
.invoice-total-preview span {
  color: #64748b;
  font-size: 13px;
  font-weight: 600;
}
.invoice-total-preview strong {
  color: #0f172a;
  font-size: 18px;
  font-weight: 700;
  direction: ltr;
}

/* v22 - compact invoice line layout: keep delete button on the same row */
.purchase-line {
  grid-template-columns: 42px minmax(300px, 1.8fr) minmax(90px, .45fr) minmax(145px, .65fr) minmax(145px, .65fr) 74px;
  align-items: end;
  gap: 10px;
  padding: 12px;
}

.purchase-line label,
.purchase-line .line-total-wrap {
  min-width: 0;
}

.purchase-line input,
.purchase-line select {
  min-height: 48px;
}

.purchase-line .line-total-wrap input.line-total {
  min-height: 48px;
}

.purchase-line .remove-purchase-line,
.purchase-line .btn.danger,
.purchase-line button[name="remove"],
.purchase-line button[type="button"] {
  align-self: end;
  min-height: 48px;
  height: 48px;
  padding: 0 12px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.purchase-line .line-no {
  align-self: end;
  margin-bottom: 5px;
}

@media (max-width: 1280px) {
  .purchase-line {
    grid-template-columns: 40px minmax(240px, 1.6fr) minmax(88px, .45fr) minmax(130px, .65fr) minmax(130px, .65fr) 70px;
    gap: 8px;
    padding: 10px;
  }
}

@media (max-width: 980px) {
  .purchase-line {
    grid-template-columns: 40px 1fr 1fr;
  }

  .purchase-line label,
  .purchase-line .line-total-wrap {
    grid-column: auto;
  }

  .purchase-line label:first-of-type {
    grid-column: 2 / -1;
  }

  .purchase-line .remove-purchase-line,
  .purchase-line .btn.danger,
  .purchase-line button[name="remove"],
  .purchase-line button[type="button"] {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .purchase-line {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .purchase-line .line-no,
  .purchase-line label,
  .purchase-line .line-total-wrap,
  .purchase-line .remove-purchase-line,
  .purchase-line .btn.danger,
  .purchase-line button[name="remove"],
  .purchase-line button[type="button"] {
    grid-column: 1 / -1;
    width: 100%;
  }
}


/* v23: رنگ‌بندی تازه سایدبار و گزارش‌های حرفه‌ای */
.sidebar {
  background: linear-gradient(180deg, #111827 0%, #172554 52%, #0f766e 100%);
  border-color: rgba(255,255,255,.14);
  box-shadow: 0 28px 80px rgba(15, 23, 42, .28);
}
.brand { color: #fff; }
.brand::before {
  background: linear-gradient(135deg, #facc15, #22c55e 45%, #38bdf8);
  box-shadow: 0 14px 32px rgba(34, 197, 94, .28);
}
nav a {
  color: rgba(255,255,255,.72);
  background: transparent;
}
nav a:hover {
  background: rgba(255,255,255,.10);
  color: #fff;
}
nav a.active {
  background: linear-gradient(135deg, #22c55e, #06b6d4);
  color: #052e2b;
  box-shadow: 0 16px 34px rgba(6, 182, 212, .22);
}
.userbox {
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.14);
  color: rgba(255,255,255,.82);
}
.userbox .linklike { color: #fecaca; }
body {
  background:
    radial-gradient(circle at 10% 8%, rgba(34, 197, 94, .13), transparent 30%),
    radial-gradient(circle at 88% 12%, rgba(14, 165, 233, .13), transparent 28%),
    linear-gradient(180deg, #f6f8fc 0%, #eef6f7 100%);
}
.report-filter { border-color: rgba(34, 197, 94, .22); }
.report-cards .stat:nth-child(1) { background: linear-gradient(135deg, rgba(34,197,94,.13), rgba(255,255,255,.92)); }
.report-cards .stat:nth-child(2) { background: linear-gradient(135deg, rgba(14,165,233,.13), rgba(255,255,255,.92)); }
.report-cards .stat:nth-child(3) { background: linear-gradient(135deg, rgba(245,158,11,.13), rgba(255,255,255,.92)); }
.report-cards .stat:nth-child(4) { background: linear-gradient(135deg, rgba(139,92,246,.12), rgba(255,255,255,.92)); }
.clean-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
}
.clean-list p {
  margin: 0;
  padding: 0;
  font-size: 13px;
  color: var(--text-soft);
}
.barrow label small {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}
@media (max-width: 900px) {
  .sidebar {
    background: linear-gradient(135deg, #111827, #0f766e);
  }
}


.alert.show { transform: translateX(0); opacity: 1; }
.alert.hide { transform: translateX(-120%); opacity: 0; }

/* Petty cash v1.2 */
.petty-kpis .stat:nth-child(1)::after,
.petty-kpis .stat:nth-child(4)::after { background: radial-gradient(circle, rgba(22,163,74,.14), transparent 68%); }
.petty-kpis .stat:nth-child(2)::after { background: radial-gradient(circle, rgba(239,68,68,.13), transparent 68%); }
.petty-kpis .stat:nth-child(3)::after { background: radial-gradient(circle, rgba(14,165,233,.13), transparent 68%); }

.petty-person-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2fr;
  gap: 18px;
  align-items: stretch;
  background: linear-gradient(135deg, rgba(37,99,235,.08), rgba(255,255,255,.94));
}

.petty-person-card > div:first-child span {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.petty-person-card h2 { margin-bottom: 8px; }
.petty-person-card p { margin: 0; color: var(--muted); line-height: 1.9; }

.petty-person-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.petty-person-grid > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.76);
}

.petty-person-grid small {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 700;
}

.petty-person-grid b {
  display: block;
  margin-bottom: 8px;
  font-size: 18px;
  color: var(--text);
}

@media (max-width: 900px) {
  .petty-person-card,
  .petty-person-grid { grid-template-columns: 1fr; }
}

.badge.warn { background: var(--warning-soft); color: #92400e; }
.receipt-current {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: var(--bg-2);
  color: var(--text-soft);
  font-size: 13px;
}
.form-grid.compact {
  align-items: end;
}

/* v1.3.1 - purchase form layout + responsive hardening */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.card,
.form-grid,
.purchase-form,
.purchase-lines,
.purchase-line,
.table-wrap,
.filters,
.search-inline,
.actions {
  max-width: 100%;
}

.form-grid > *,
.purchase-form > *,
.purchase-line > * {
  min-width: 0;
}

.purchase-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.purchase-form .wide,
.purchase-form .purchase-lines,
.purchase-form .invoice-total-preview,
.purchase-form .receipt-current {
  grid-column: 1 / -1 !important;
}

.purchase-form > .btn.primary,
.purchase-form > a.btn {
  grid-column: 1 / -1;
  justify-self: end;
  min-width: 260px;
}

.purchase-form input[type="file"] {
  padding-top: 10px;
  overflow: hidden;
}

.purchase-form .purchase-lines {
  width: 100%;
}

.purchase-form .purchase-line {
  width: 100%;
  grid-template-columns: 42px minmax(220px, 2fr) minmax(96px, .6fr) minmax(135px, .75fr) minmax(135px, .75fr) 74px;
}

.card:has(table),
.table-wrap {
  overflow-x: auto !important;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.card:has(table) table,
.table-wrap table {
  min-width: 760px;
}

@media (max-width: 1180px) {
  .purchase-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .purchase-form .wide,
  .purchase-form .purchase-lines,
  .purchase-form .invoice-total-preview,
  .purchase-form .receipt-current {
    grid-column: 1 / -1 !important;
  }

  .purchase-form .purchase-line {
    grid-template-columns: 40px minmax(220px, 1.6fr) minmax(90px, .55fr) minmax(125px, .75fr) minmax(125px, .75fr) 70px;
  }
}

@media (max-width: 980px) {
  .purchase-form .purchase-line {
    grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1fr);
  }

  .purchase-form .purchase-line label:first-of-type {
    grid-column: 2 / -1;
  }
}

@media (max-width: 720px) {
  .form-grid,
  .purchase-form {
    grid-template-columns: 1fr !important;
  }

  .form-grid .wide,
  .purchase-form .wide,
  .purchase-form .purchase-lines,
  .purchase-form .invoice-total-preview,
  .purchase-form .receipt-current,
  .purchase-form > .btn.primary,
  .purchase-form > a.btn {
    grid-column: 1 / -1 !important;
  }

  .purchase-form > .btn.primary,
  .purchase-form > a.btn {
    width: 100%;
    min-width: 0;
    justify-self: stretch;
  }

  .purchase-form .purchase-line {
    grid-template-columns: 1fr !important;
  }

  .purchase-form .purchase-line .line-no,
  .purchase-form .purchase-line label,
  .purchase-form .purchase-line .line-total-wrap,
  .purchase-form .purchase-line .remove-purchase-line,
  .purchase-form .purchase-line .btn.danger,
  .purchase-form .purchase-line button[name="remove"],
  .purchase-form .purchase-line button[type="button"] {
    grid-column: 1 / -1 !important;
    width: 100%;
  }

  .purchase-form .purchase-line .line-no {
    justify-self: start;
    width: 42px;
  }

  .topbar,
  .filters,
  .search-inline,
  .actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 520px) {
  .card:has(table) table,
  .table-wrap table {
    min-width: 680px;
  }

  .receipt-current {
    flex-direction: column;
    align-items: stretch;
  }
}


/* v1.4 tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 18px;
}
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(15,23,42,.08);
  color: #475569;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15,23,42,.05);
}
.tab:hover { transform: translateY(-1px); }
.tab.active {
  background: #111827;
  color: #fff;
  border-color: #111827;
}
.userbox small {
  display: block;
  margin-top: 3px;
  color: rgba(255,255,255,.68);
  font-size: 12px;
}
@media (max-width: 720px) {
  .tabs { gap: 6px; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .tab { white-space: nowrap; min-height: 34px; padding: 7px 11px; font-size: 13px; }
}

/* v1.4.2 - compact purchase rows + responsive polish */
.userbox span {
  display: block;
  color: rgba(255,255,255,.92);
  font-weight: 700;
  line-height: 1.8;
}
.userbox small:empty { display: none; }

.purchase-form {
  gap: 14px;
}
.purchase-form > label {
  gap: 6px;
}
.purchase-form input,
.purchase-form select,
.purchase-form textarea {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 13px;
  line-height: 1.55;
}
.purchase-form input[type="file"] {
  min-height: 40px;
  padding: 7px 10px;
  line-height: 1.4;
}
.purchase-form .purchase-lines {
  gap: 9px;
}
.purchase-form .purchase-line {
  grid-template-columns: 36px minmax(260px, 2.2fr) minmax(76px, .46fr) minmax(118px, .66fr) minmax(118px, .66fr) 64px;
  gap: 8px;
  padding: 9px;
  border-radius: 18px;
  align-items: end;
}
.purchase-form .purchase-line label {
  gap: 5px;
  font-size: 11.5px;
}
.purchase-form .purchase-line input,
.purchase-form .purchase-line select,
.purchase-form .purchase-line .line-total-wrap input.line-total {
  min-height: 38px;
  padding: 7px 10px;
  border-radius: 12px;
  line-height: 1.45;
}
.purchase-form .purchase-line .line-no {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  margin-bottom: 2px;
  font-size: 12px;
}
.purchase-form .purchase-line .remove-purchase-line,
.purchase-form .purchase-line .btn.danger,
.purchase-form .purchase-line button[name="remove"],
.purchase-form .purchase-line button[type="button"] {
  min-height: 38px;
  height: 38px;
  padding: 0 9px;
  border-radius: 12px;
  font-size: 11.5px;
}
.purchase-form > .btn.primary,
.purchase-form > a.btn {
  min-height: 40px;
  padding: 9px 16px;
}

@media (max-width: 1280px) {
  .purchase-form .purchase-line {
    grid-template-columns: 34px minmax(220px, 1.9fr) minmax(72px, .46fr) minmax(108px, .66fr) minmax(108px, .66fr) 60px;
    gap: 7px;
    padding: 8px;
  }
}

@media (max-width: 980px) {
  .purchase-form .purchase-line {
    grid-template-columns: 34px minmax(0, 1.4fr) minmax(0, .8fr);
  }
  .purchase-form .purchase-line label:first-of-type {
    grid-column: 2 / -1;
  }
}

@media (max-width: 720px) {
  .purchase-form input,
  .purchase-form select,
  .purchase-form textarea,
  .purchase-form .purchase-line input,
  .purchase-form .purchase-line select,
  .purchase-form .purchase-line .line-total-wrap input.line-total {
    min-height: 42px;
    font-size: 14px;
  }
  .purchase-form .purchase-line {
    padding: 10px;
    gap: 9px;
  }
  .purchase-form .purchase-line .line-no {
    width: 38px;
    height: 38px;
  }
}


/* v1.4.3 - invoice total live preview */
.invoice-total-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px solid rgba(148, 163, 184, .28);
  margin-top: 2px;
}
.invoice-total-preview span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.invoice-total-preview b {
  font-size: 18px;
  color: var(--primary);
}
@media (max-width: 720px) {
  .invoice-total-preview {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* v1.4.3 UI polish - vendor form, sidebar userbox, compact report tables */
.userbox {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
}
.userbox span {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
}
.userbox small {
  grid-column: 1;
  grid-row: 2;
}
.userbox .inline-form {
  grid-column: 2;
  grid-row: 1 / span 2;
  justify-self: end;
  align-self: center;
  margin: 0;
}
.userbox .linklike {
  white-space: nowrap;
}

.vendor-form {
  grid-template-columns: minmax(240px, 1fr) minmax(320px, 1fr);
  gap: 12px 16px;
  align-items: stretch;
  margin-bottom: 24px;
}
.vendor-form label:nth-of-type(1) {
  grid-column: 1;
  grid-row: 1;
}
.vendor-form label:nth-of-type(2) {
  grid-column: 1;
  grid-row: 2;
}
.vendor-form label.wide {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.vendor-form label.wide textarea {
  min-height: 132px;
  height: 132px;
}
.vendor-form .btn {
  margin-top: 4px;
}
.vendor-form + table {
  margin-top: 22px;
}

.grid.two {
  gap: 14px;
}
.grid.two > .card {
  padding: 18px;
}
.grid.two > .card h2 {
  margin-bottom: 14px;
}
.grid.two > .card:has(table) {
  overflow-x: auto !important;
}
.grid.two > .card table {
  min-width: 0 !important;
  width: 100%;
  table-layout: auto;
  font-size: 12.5px;
}
.grid.two > .card th,
.grid.two > .card td {
  padding: 10px 8px;
  white-space: nowrap;
}
.grid.two > .card th:first-child,
.grid.two > .card td:first-child {
  white-space: normal;
}

@media (max-width: 860px) {
  .userbox {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .vendor-form {
    grid-template-columns: 1fr;
  }
  .vendor-form label:nth-of-type(1),
  .vendor-form label:nth-of-type(2),
  .vendor-form label.wide {
    grid-column: 1 / -1;
    grid-row: auto;
  }
  .vendor-form label.wide textarea {
    height: auto;
    min-height: 110px;
  }
}

/* v1.4.5 - final cleanup and sidebar polish */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}
.page-current,
.page-gap {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}
.page-current {
  color: #fff;
  background: #0f766e;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.22);
}
.page-gap { color: #64748b; }
.report-filter.compact,
.form-grid.compact { align-items: end; }
.compact-report { overflow-x: auto; }
.compact-report table { min-width: 0; }
.compact-report th,
.compact-report td { padding: 13px 14px; }
@media (max-width: 768px) {
  .pagination { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .page-current, .page-gap { flex: 0 0 auto; }
}

/* v1.4.5 final polish - completed cleanup pass */
.settings-audit-head {
  margin-top: 0;
}
.settings-audit-head p {
  margin-bottom: 0;
}

.userbox {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
}
.userbox span,
.userbox small {
  grid-column: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.userbox span { grid-row: 1; }
.userbox small { grid-row: 2; margin-top: 0; }
.userbox .inline-form {
  grid-column: 2;
  grid-row: 1 / span 2;
  justify-self: end;
  align-self: center;
  margin: 0;
}
.userbox .linklike {
  white-space: nowrap;
}

.form-grid.compact {
  gap: 12px;
}
.form-grid.compact .btn {
  min-height: 42px;
}

.petty-form,
.purchase-form {
  row-gap: 14px;
}
.purchase-form .invoice-total-preview {
  margin-top: 2px;
}

@media (max-width: 720px) {
  .topbar {
    gap: 12px;
  }
  .topbar .btn,
  .topbar a.btn {
    width: 100%;
    justify-content: center;
  }
  .form-grid.compact {
    grid-template-columns: 1fr !important;
  }
  .form-grid.compact .btn,
  .form-grid.compact a.btn {
    width: 100%;
    justify-content: center;
  }
  .settings-audit-head {
    padding: 18px;
  }
}

/* v1.6 theme selector and modern theme */
.appearance-form {
  grid-template-columns: repeat(2, minmax(220px, 1fr)) auto;
  align-items: stretch;
}
.theme-option {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 92px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(248, 250, 252, .8);
  cursor: pointer;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease, background .18s ease;
}
.theme-option:hover {
  transform: translateY(-1px);
  border-color: rgba(37,99,235,.30);
  box-shadow: var(--shadow-sm);
}
.theme-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.theme-option b,
.theme-option small {
  display: block;
}
.theme-option b {
  color: var(--text);
  font-size: 15px;
}
.theme-option small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.8;
}
.theme-preview-card { overflow: hidden; }
.theme-preview {
  direction: rtl;
  min-height: 260px;
  border: 1px solid #e5eaf3;
  border-radius: 22px;
  background: #f5f7fb;
  padding: 18px;
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 18px;
}
.theme-preview aside,
.theme-preview main,
.theme-preview .preview-kpis b,
.theme-preview .preview-table {
  background: #fff;
  border: 1px solid #e8edf5;
  border-radius: 18px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .06);
}
.theme-preview aside {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.theme-preview aside strong { margin-bottom: 8px; color: #0f172a; }
.theme-preview aside span {
  padding: 10px 12px;
  border-radius: 12px;
  color: #64748b;
  font-weight: 600;
}
.theme-preview aside .active { background: #123f7a; color: #fff; }
.theme-preview main { padding: 18px; }
.preview-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.preview-kpis b { padding: 28px 16px; color: #0f172a; }
.preview-table { padding: 16px; }
.preview-table i {
  display: block;
  height: 26px;
  border-bottom: 1px solid #eef2f7;
}

body.theme-modern {
  --bg: #f5f7fb;
  --bg-2: #eef3f8;
  --card: #ffffff;
  --card-solid: #ffffff;
  --text: #111827;
  --text-soft: #334155;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e6ebf2;
  --line-strong: #d9e1ec;
  --primary: #123f7a;
  --primary-hover: #0b2f61;
  --primary-soft: #eaf1fb;
  --primary-ring: rgba(18, 63, 122, .16);
  --shadow-sm: 0 10px 28px rgba(15, 23, 42, .055);
  --shadow: 0 18px 50px rgba(15, 23, 42, .07);
  --shadow-lg: 0 26px 80px rgba(15, 23, 42, .11);
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 22px;
  --sidebar: 250px;
  background: linear-gradient(180deg, #f7f9fc 0%, #eef3f8 100%);
  font-size: 13.5px;
  line-height: 1.78;
}
body.theme-modern::before {
  background-image: none;
}
body.theme-modern .sidebar {
  inset: 18px 18px 18px auto;
  background: rgba(255,255,255,.96);
  border-color: #e8edf5;
  border-radius: 22px;
  box-shadow: 0 18px 46px rgba(15, 23, 42, .07);
  padding: 16px 14px;
  gap: 14px;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body.theme-modern .brand {
  min-height: 58px;
  padding: 10px 12px;
  font-size: 17px;
  color: #0f172a;
}
body.theme-modern .brand::before {
  width: 38px;
  height: 38px;
  flex-basis: 38px;
  border-radius: 14px;
  background: linear-gradient(135deg, #123f7a, #2563eb);
  box-shadow: 0 10px 24px rgba(18, 63, 122, .22);
}
body.theme-modern nav { gap: 5px; }
body.theme-modern nav a {
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 13px;
  color: #475569;
  font-size: 13px;
  font-weight: 600;
}
body.theme-modern nav a:hover {
  transform: none;
  background: #f1f5fb;
  color: #123f7a;
}
body.theme-modern nav a.active {
  background: #123f7a;
  color: #fff;
  box-shadow: 0 10px 22px rgba(18, 63, 122, .22);
}
body.theme-modern .userbox {
  border-color: #edf1f7;
  background: #f8fafc;
  border-radius: 16px;
  padding: 12px;
}
body.theme-modern .main {
  margin-right: calc(var(--sidebar) + 34px);
  padding: 22px 24px 34px;
}
body.theme-modern .topbar {
  margin-bottom: 18px;
}
body.theme-modern .topbar h1 {
  font-size: 25px;
  letter-spacing: -.03em;
}
body.theme-modern .topbar p { color: #64748b; }
body.theme-modern .login-card,
body.theme-modern .card,
body.theme-modern .narrow {
  background: #fff;
  border-color: #e8edf5;
  border-radius: 20px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, .055);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body.theme-modern .card { padding: 22px; }
body.theme-modern h2 { font-size: 17px; }
body.theme-modern input,
body.theme-modern select,
body.theme-modern textarea {
  min-height: 42px;
  border-color: #dfe7f1;
  border-radius: 13px;
  background: #fff;
  box-shadow: none;
}
body.theme-modern select {
  padding-inline-start: 22px;
  padding-inline-end: 20px;
  background-position: left 16px center;
}
body.theme-modern input:focus,
body.theme-modern select:focus,
body.theme-modern textarea:focus {
  border-color: #123f7a;
  box-shadow: 0 0 0 4px rgba(18, 63, 122, .10);
}
body.theme-modern .btn {
  min-height: 42px;
  border-radius: 13px;
  box-shadow: none;
}
body.theme-modern .btn.primary {
  background: #123f7a;
  box-shadow: 0 10px 22px rgba(18, 63, 122, .18);
}
body.theme-modern .btn.primary:hover { background: #0b2f61; }
body.theme-modern .tabs {
  background: transparent;
  border: 0;
  padding: 0;
  gap: 8px;
}
body.theme-modern .tabs a {
  min-height: 38px;
  border: 1px solid #e6ebf2;
  background: #fff;
  border-radius: 12px;
  color: #64748b;
}
body.theme-modern .tabs a.active {
  background: #123f7a;
  border-color: #123f7a;
  color: #fff;
  box-shadow: 0 9px 20px rgba(18, 63, 122, .18);
}
body.theme-modern table {
  border-collapse: separate;
  border-spacing: 0;
}
body.theme-modern th {
  background: #f7f9fc;
  color: #64748b;
  font-size: 12px;
  padding: 12px 14px;
}
body.theme-modern td {
  padding: 13px 14px;
  border-bottom-color: #edf2f7;
}
body.theme-modern tr:hover td { background: #fafcff; }
body.theme-modern .stat b { font-size: 25px; }
body.theme-modern .alert {
  border-radius: 16px;
  box-shadow: 0 14px 36px rgba(15, 23, 42, .08);
}
body.theme-modern .app-footer {
  color: #64748b;
}

@media (max-width: 920px) {
  .appearance-form { grid-template-columns: 1fr; }
  .theme-preview { grid-template-columns: 1fr; }
  .preview-kpis { grid-template-columns: 1fr; }
}

/* v1.6.2 — theme isolation fixes: classic keeps its previous markup, modern owns its own sidebar */
body.theme-classic .sidebar .brand-mark { display: none; }
body.theme-classic .sidebar .brand-text { display: contents; }
body.theme-classic .sidebar .brand small { display: none; }
body.theme-classic .sidebar .avatar,
body.theme-classic .sidebar .nav-icon,
body.theme-classic .sidebar .theme-state,
body.theme-classic .sidebar .mobile-logout { display: none; }

body.theme-modern {
  --bg: #f3f6fa;
  --bg-2: #eef3f8;
  --card: #ffffff;
  --card-solid: #ffffff;
  --text: #111827;
  --text-soft: #334155;
  --muted: #64748b;
  --muted-2: #9aa7b8;
  --line: #e8edf4;
  --line-strong: #dbe3ee;
  --primary: #0f3b78;
  --primary-hover: #0a2f61;
  --primary-soft: #eef5ff;
  --primary-ring: rgba(15, 59, 120, .14);
  --gold: #d6b353;
  --shadow-sm: 0 8px 22px rgba(15, 23, 42, .045);
  --shadow: 0 16px 42px rgba(15, 23, 42, .065);
  --shadow-lg: 0 24px 70px rgba(15, 23, 42, .09);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --sidebar: 252px;
  background: #f3f6fa;
  color: var(--text);
  font-size: 13px;
  line-height: 1.75;
}
body.theme-modern::before {
  display: none;
}
body.theme-modern .sidebar {
  inset: 18px 18px 18px auto;
  width: var(--sidebar);
  padding: 14px 12px;
  gap: 10px;
  background: #fff;
  border: 1px solid #e9eef5;
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .065);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body.theme-modern .brand {
  min-height: auto;
  padding: 12px 10px 14px;
  border-bottom: 1px solid #eef2f7;
  gap: 10px;
  font-size: 15px;
  color: #111827;
  align-items: center;
}
body.theme-modern .brand::before { display: none; }
body.theme-modern .brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, #0f3b78 0%, #1d5fbf 100%);
  box-shadow: 0 10px 22px rgba(15, 59, 120, .22);
}
body.theme-modern .brand-mark::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background:
    linear-gradient(90deg, transparent 0 20%, #fff 20% 32%, transparent 32% 44%, #fff 44% 56%, transparent 56% 68%, #fff 68% 80%, transparent 80% 100%);
  opacity: .95;
}
body.theme-modern .brand-text {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}
body.theme-modern .brand strong {
  font-size: 15px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -.02em;
}
body.theme-modern .brand small {
  display: block;
  color: #8a97a8;
  font-size: 11px;
  font-weight: 500;
  margin-top: -2px;
}
body.theme-modern .userbox.user-profile {
  margin: 2px 0 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border: 1px solid #eef2f7;
  border-radius: 15px;
  background: #fafcff;
  color: #64748b;
  font-size: 12px;
}
body.theme-modern .avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 14px;
  background: #edf2f8;
  color: #0f3b78;
  font-weight: 700;
  border: 1px solid #e6edf5;
}
body.theme-modern .user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
body.theme-modern .userbox.user-profile > .user-meta {
  grid-column: 1;
  min-width: 0;
}
body.theme-modern .userbox.user-profile > .logout-form {
  grid-column: 2;
  justify-self: end;
  align-self: center;
  margin: 0;
}
body.theme-modern .userbox.user-profile .user-meta span,
body.theme-modern .userbox.user-profile .user-meta small {
  grid-column: auto;
  grid-row: auto;
}

body.theme-modern .user-meta span {
  color: #111827;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.theme-modern .user-meta small {
  color: #8b98aa;
  font-size: 11px;
}
body.theme-modern .logout-form .linklike {
  color: #ef4444;
  background: #fff1f2;
  border: 1px solid #ffe1e6;
  border-radius: 10px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 700;
}
body.theme-modern .main-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 0;
}
body.theme-modern .main-nav a {
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 12px;
  color: #475569;
  font-size: 13px;
  font-weight: 600;
  gap: 10px;
}
body.theme-modern .main-nav a:hover {
  transform: none;
  background: #f4f7fb;
  color: #0f3b78;
}
body.theme-modern .main-nav a.active {
  background: #0f3b78;
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 59, 120, .22);
}
body.theme-modern .nav-icon {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  border-radius: 9px;
  background: #f1f5f9;
  color: #64748b;
  font-size: 13px;
  line-height: 1;
}
body.theme-modern .main-nav a.active .nav-icon {
  background: rgba(255,255,255,.16);
  color: #fff;
}
body.theme-modern .nav-label { flex: 1; }
body.theme-modern .sidebar-bottom {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid #eef2f7;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
body.theme-modern .theme-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid #eef2f7;
  border-radius: 13px;
  background: #fafcff;
  color: #7b8798;
  font-size: 12px;
}
body.theme-modern .theme-state b {
  color: #0f3b78;
  font-weight: 700;
}
body.theme-modern .mobile-logout { display: none; }
body.theme-modern .main {
  margin-right: calc(var(--sidebar) + 36px);
  padding: 18px 20px 30px;
  min-height: 100vh;
}
body.theme-modern .topbar {
  min-height: 74px;
  margin: 0 0 18px;
  padding: 18px 22px;
  background: #fff;
  border: 1px solid #e9eef5;
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .045);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
body.theme-modern .topbar h1 {
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -.04em;
  color: #111827;
  margin: 0;
}
body.theme-modern .topbar h2 {
  font-size: 16px;
  margin: 0;
}
body.theme-modern .topbar p {
  margin: 3px 0 0;
  color: #7b8798;
  font-size: 12.5px;
}
body.theme-modern .login-card,
body.theme-modern .card,
body.theme-modern .narrow {
  background: #fff;
  border: 1px solid #e9eef5;
  border-radius: 18px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, .045);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
body.theme-modern .card { padding: 18px; }
body.theme-modern .stat {
  position: relative;
  min-height: 112px;
  overflow: hidden;
}
body.theme-modern .stat::after {
  content: "";
  position: absolute;
  left: 18px;
  top: 18px;
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: #edf4ff;
  box-shadow: inset 0 0 0 1px #e1ebf8;
}
body.theme-modern .stat:nth-child(2n)::after { background: #f4edff; }
body.theme-modern .stat:nth-child(3n)::after { background: #fff7e8; }
body.theme-modern .stat:nth-child(4n)::after { background: #eaf8ee; }
body.theme-modern .stat span {
  color: #7b8798;
  font-weight: 700;
  font-size: 12px;
}
body.theme-modern .stat b {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -.03em;
  color: #111827;
}
body.theme-modern .stat small { color: #8b98aa; }
body.theme-modern h2 {
  font-size: 16px;
  font-weight: 800;
  color: #111827;
  letter-spacing: -.02em;
}
body.theme-modern input,
body.theme-modern select,
body.theme-modern textarea {
  min-height: 40px;
  border: 1px solid #dfe7f1;
  border-radius: 12px;
  background-color: #fff;
  color: #111827;
  box-shadow: none;
  font-size: 13px;
}
body.theme-modern textarea { min-height: 90px; }
body.theme-modern select {
  padding-inline-start: 24px;
  padding-inline-end: 18px;
  background-position: left 18px center;
}
body.theme-modern input:focus,
body.theme-modern select:focus,
body.theme-modern textarea:focus {
  border-color: #0f3b78;
  box-shadow: 0 0 0 4px rgba(15, 59, 120, .10);
}
body.theme-modern .btn {
  min-height: 40px;
  border-radius: 12px;
  border-color: #e2e8f0;
  background: #f7f9fc;
  color: #334155;
  box-shadow: none;
  font-weight: 700;
}
body.theme-modern .btn:hover { background: #eef3f8; }
body.theme-modern .btn.primary {
  background: #0f3b78;
  border-color: #0f3b78;
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 59, 120, .18);
}
body.theme-modern .btn.primary:hover { background: #0a2f61; }
body.theme-modern .btn.danger,
body.theme-modern .danger,
body.theme-modern button.danger {
  background: #fff1f2;
  border-color: #ffe1e6;
  color: #e11d48;
}
body.theme-modern .tabs {
  background: transparent;
  border: 0;
  padding: 0;
  gap: 7px;
  margin-bottom: 14px;
}
body.theme-modern .tabs a {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid #e6ebf2;
  background: #fff;
  border-radius: 12px;
  color: #64748b;
  font-size: 12.5px;
  font-weight: 700;
}
body.theme-modern .tabs a.active {
  background: #0f3b78;
  border-color: #0f3b78;
  color: #fff;
  box-shadow: 0 9px 20px rgba(15, 59, 120, .16);
}
body.theme-modern .table-wrap,
body.theme-modern .card:has(table) {
  overflow: hidden;
}
body.theme-modern table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.7px;
}
body.theme-modern th {
  background: #f8fafc;
  color: #7b8798;
  font-size: 11.5px;
  font-weight: 800;
  padding: 11px 13px;
  border-bottom: 1px solid #e9eef5;
}
body.theme-modern td {
  padding: 12px 13px;
  border-bottom: 1px solid #eef2f7;
  color: #1f2937;
}
body.theme-modern tr:hover td { background: #fbfdff; }
body.theme-modern .badge,
body.theme-modern .pill {
  border-radius: 999px;
  font-size: 11.5px;
  padding: 4px 9px;
}
body.theme-modern .alert {
  border-radius: 15px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .06);
  border: 1px solid #e9eef5;
}
body.theme-modern .form-grid {
  gap: 14px 16px;
}
body.theme-modern label {
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}
body.theme-modern .app-footer {
  margin-top: 18px;
  color: #8492a6;
  font-size: 12px;
}
body.theme-modern .pagination a,
body.theme-modern .pagination span {
  min-width: 34px;
  height: 34px;
  border-radius: 11px;
}

@media (max-width: 1100px) {
  body.theme-modern { --sidebar: 232px; }
  body.theme-modern .sidebar { inset: 12px 12px 12px auto; }
  body.theme-modern .main { margin-right: calc(var(--sidebar) + 24px); padding: 14px; }
}
@media (max-width: 820px) {
  body.theme-modern { --sidebar: 0px; }
  body.theme-modern .sidebar {
    position: static;
    width: auto;
    margin: 10px;
    border-radius: 18px;
  }
  body.theme-modern .brand,
  body.theme-modern .userbox.user-profile,
  body.theme-modern .sidebar-bottom { display: none; }
  body.theme-modern .main-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }
  body.theme-modern .main-nav a {
    justify-content: center;
    min-height: 38px;
    padding: 8px;
  }
  body.theme-modern .nav-icon { display: none; }
  body.theme-modern .main {
    margin-right: 0;
    padding: 10px;
  }
  body.theme-modern .topbar {
    padding: 15px;
    align-items: flex-start;
    flex-direction: column;
  }
  body.theme-modern .topbar h1 { font-size: 20px; }
  body.theme-modern .card { padding: 15px; }
}
@media (max-width: 520px) {
  body.theme-modern .main-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.theme-modern .tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  body.theme-modern .tabs a { white-space: nowrap; }
}

/* v1.6.4 — accurate modern theme redraw based on user's reference: white slim sidebar, line icons, navy active pill, orange accent. Classic theme is untouched. */
body.theme-modern {
  --modern-bg: #f3f6fa;
  --modern-card: #ffffff;
  --modern-text: #151f32;
  --modern-muted: #7c889a;
  --modern-line: #e9eef5;
  --modern-line-2: #f0f3f8;
  --modern-navy: #073b78;
  --modern-navy-2: #0b4a92;
  --modern-orange: #f5a623;
  --modern-orange-soft: #fff4dd;
  --modern-green: #21bf73;
  --sidebar: 222px;
  background: var(--modern-bg);
  color: var(--modern-text);
  font-size: 13px;
  line-height: 1.72;
}

body.theme-modern .sidebar.modern-sidebar {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: var(--sidebar);
  padding: 13px 11px;
  background: #fff;
  border: 1px solid var(--modern-line);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(18, 31, 55, .07);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

body.theme-modern .brand.modern-brand {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 8px;
  align-items: center;
  gap: 9px;
  padding: 9px 8px 13px;
  border-bottom: 1px solid var(--modern-line-2);
  min-height: 54px;
  color: var(--modern-text);
}
body.theme-modern .brand.modern-brand::before { display: none; }
body.theme-modern .brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 13px;
  background: #f4f7fb;
  border: 1px solid #e7edf5;
  display: grid;
  place-items: center;
  box-shadow: none;
}
body.theme-modern .brand-bars {
  width: 18px;
  height: 18px;
  display: block;
  background:
    linear-gradient(to top, var(--modern-navy) 0 64%, transparent 64%) 2px 3px / 3px 14px no-repeat,
    linear-gradient(to top, var(--modern-navy-2) 0 92%, transparent 92%) 8px 0 / 3px 17px no-repeat,
    linear-gradient(to top, var(--modern-orange) 0 48%, transparent 48%) 14px 6px / 3px 11px no-repeat;
  border-radius: 3px;
}
body.theme-modern .brand-text strong {
  font-size: 14px;
  line-height: 1.35;
  font-weight: 800;
  color: var(--modern-text);
  letter-spacing: -.02em;
}
body.theme-modern .brand-text small {
  font-size: 10.5px;
  color: var(--modern-muted);
  font-weight: 500;
  margin-top: 0;
}
body.theme-modern .brand-accent {
  width: 8px;
  height: 8px;
  align-self: start;
  margin-top: 8px;
  border-radius: 99px;
  background: var(--modern-orange);
  box-shadow: 0 0 0 4px rgba(245, 166, 35, .14);
}

body.theme-modern .userbox.user-profile {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 9px;
  border: 1px solid var(--modern-line);
  border-radius: 15px;
  background: #fbfcfe;
  min-height: 52px;
}
body.theme-modern .userbox.user-profile .avatar {
  grid-column: 1;
  width: 34px;
  height: 34px;
  border-radius: 13px;
  background: #eef3f9;
  border: 1px solid #e5ebf4;
  color: var(--modern-navy);
  font-size: 13px;
  font-weight: 800;
}
body.theme-modern .userbox.user-profile .user-meta {
  grid-column: 2;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
body.theme-modern .userbox.user-profile .user-meta span {
  color: var(--modern-text);
  font-weight: 800;
  font-size: 12.5px;
  line-height: 1.35;
}
body.theme-modern .userbox.user-profile .user-meta small {
  color: var(--modern-muted);
  font-size: 10.5px;
  line-height: 1.35;
}
body.theme-modern .userbox.user-profile .logout-form {
  grid-column: 3;
  margin: 0;
  justify-self: end;
}
body.theme-modern .logout-form .linklike {
  color: #ef4444;
  background: #fff3f4;
  border: 1px solid #ffe1e6;
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1;
}

body.theme-modern .main-nav {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 2px 0;
  margin-top: 24px;
}
body.theme-modern .main-nav a {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 38px;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 12px;
  color: #445064;
  font-size: 12.7px;
  font-weight: 700;
  text-decoration: none;
  background: transparent;
  border: 0;
  box-shadow: none;
}
body.theme-modern .main-nav a:hover {
  background: #f5f8fc;
  color: var(--modern-navy);
}
body.theme-modern .main-nav a.active {
  background: var(--modern-navy);
  color: #fff;
  box-shadow: 0 11px 22px rgba(7, 59, 120, .22);
}
body.theme-modern .nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border-radius: 9px;
  background: transparent;
  color: currentColor;
  font-size: 0;
}
body.theme-modern .nav-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
body.theme-modern .nav-label {
  flex: 1;
  min-width: 0;
}
body.theme-modern .nav-badge {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--modern-orange);
  box-shadow: 0 0 0 4px rgba(245, 166, 35, .16);
  flex: 0 0 7px;
}
body.theme-modern .main-nav a.active .nav-badge {
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255,255,255,.16);
}

body.theme-modern .sidebar-bottom {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--modern-line-2);
  gap: 7px;
}
body.theme-modern .theme-state,
body.theme-modern .version-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 12px;
  background: #fbfcfe;
  border: 1px solid var(--modern-line);
  color: var(--modern-muted);
  font-size: 11.5px;
}
body.theme-modern .theme-state b,
body.theme-modern .version-chip b {
  color: var(--modern-navy);
  font-size: 11.5px;
}
body.theme-modern .version-chip b {
  color: var(--modern-orange);
}

body.theme-modern .main {
  margin-right: calc(var(--sidebar) + 38px);
  padding: 18px 20px 32px;
}
body.theme-modern .topbar {
  min-height: 66px;
  margin-bottom: 16px;
  padding: 15px 18px;
  background: #fff;
  border: 1px solid var(--modern-line);
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(18, 31, 55, .045);
}
body.theme-modern .topbar h1 {
  font-size: 22px;
  color: var(--modern-text);
}
body.theme-modern .topbar p {
  color: var(--modern-muted);
  font-size: 12px;
}
body.theme-modern .card,
body.theme-modern .narrow,
body.theme-modern .login-card {
  border: 1px solid var(--modern-line);
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(18, 31, 55, .045);
}
body.theme-modern .card { padding: 17px; }
body.theme-modern h2 { font-size: 15.5px; }
body.theme-modern .stat {
  min-height: 104px;
  padding-inline-start: 72px;
}
body.theme-modern .stat::after {
  left: 18px;
  top: 18px;
  width: 42px;
  height: 42px;
  border-radius: 15px;
  background: #eef5ff;
  box-shadow: inset 0 0 0 1px #dfeafe;
}
body.theme-modern .stat:nth-child(3n)::after {
  background: var(--modern-orange-soft);
  box-shadow: inset 0 0 0 1px #ffe5b3;
}
body.theme-modern .stat b { font-size: 23px; }
body.theme-modern .stat span,
body.theme-modern label,
body.theme-modern th { font-weight: 800; }
body.theme-modern input,
body.theme-modern select,
body.theme-modern textarea {
  min-height: 39px;
  border-radius: 11px;
}
body.theme-modern select {
  background-position: left 18px center;
  padding-inline-start: 24px;
  padding-inline-end: 18px;
}
body.theme-modern .btn {
  min-height: 39px;
  border-radius: 11px;
}
body.theme-modern .btn.primary,
body.theme-modern .tabs a.active {
  background: var(--modern-navy);
  border-color: var(--modern-navy);
}
body.theme-modern .tabs a {
  min-height: 35px;
  border-radius: 11px;
}
body.theme-modern .badge.warning,
body.theme-modern .badge.orange,
body.theme-modern .pill.warning,
body.theme-modern .pill.orange {
  background: var(--modern-orange-soft);
  color: #9a6300;
  border-color: #ffe1a3;
}
body.theme-modern table { font-size: 12.5px; }
body.theme-modern th { background: #f8fafc; }
body.theme-modern td { padding: 11px 13px; }

@media (max-width: 1100px) {
  body.theme-modern { --sidebar: 210px; }
  body.theme-modern .sidebar.modern-sidebar { right: 12px; top: 12px; bottom: 12px; }
  body.theme-modern .main { margin-right: calc(var(--sidebar) + 26px); padding: 14px; }
}
@media (max-width: 820px) {
  body.theme-modern { --sidebar: 0px; }
  body.theme-modern .sidebar.modern-sidebar {
    position: static;
    width: auto;
    margin: 10px;
    padding: 10px;
    border-radius: 18px;
  }
  body.theme-modern .brand.modern-brand,
  body.theme-modern .userbox.user-profile,
  body.theme-modern .sidebar-bottom { display: none; }
  body.theme-modern .main-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }
  body.theme-modern .main-nav a {
    justify-content: center;
    min-height: 38px;
    padding: 8px;
  }
  body.theme-modern .nav-icon,
  body.theme-modern .nav-badge { display: none; }
  body.theme-modern .main { margin-right: 0; padding: 10px; }
}
@media (max-width: 520px) {
  body.theme-modern .main-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* v1.6.4 — dashboard KPI icons for both themes */
.stat {
  padding-left: 82px;
}
.stat::after {
  display: none;
}
.stat .stat-icon {
  position: absolute;
  left: 22px;
  top: 22px;
  z-index: 1;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  color: #2563eb;
  background: rgba(37, 99, 235, .10);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .13);
}
.stat .stat-icon svg {
  width: 23px;
  height: 23px;
}
.stat .stat-title {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.stat--wallet .stat-icon,
.stat--cash .stat-icon { color: #16a34a; background: rgba(22, 163, 74, .10); box-shadow: inset 0 0 0 1px rgba(22, 163, 74, .14); }
.stat--copy .stat-icon,
.stat--target .stat-icon,
.stat--undo .stat-icon { color: #d97706; background: rgba(245, 158, 11, .12); box-shadow: inset 0 0 0 1px rgba(245, 158, 11, .20); }
.stat--calculator .stat-icon,
.stat--receipt .stat-icon,
.stat--chart .stat-icon { color: #2563eb; background: rgba(37, 99, 235, .10); box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .14); }
.stat--calendar .stat-icon,
.stat--list .stat-icon { color: #7c3aed; background: rgba(124, 58, 237, .09); box-shadow: inset 0 0 0 1px rgba(124, 58, 237, .13); }
.stat--users .stat-icon { color: #0891b2; background: rgba(8, 145, 178, .10); box-shadow: inset 0 0 0 1px rgba(8, 145, 178, .14); }
.stat--coffee .stat-icon { color: #b45309; background: rgba(180, 83, 9, .11); box-shadow: inset 0 0 0 1px rgba(180, 83, 9, .16); }
.stat--status .stat-icon,
.stat--check .stat-icon { color: #059669; background: rgba(5, 150, 105, .10); box-shadow: inset 0 0 0 1px rgba(5, 150, 105, .14); }
.stat--trend_down .stat-icon { color: #dc2626; background: rgba(220, 38, 38, .09); box-shadow: inset 0 0 0 1px rgba(220, 38, 38, .13); }
.stat--trend_up .stat-icon { color: #0ea5e9; background: rgba(14, 165, 233, .10); box-shadow: inset 0 0 0 1px rgba(14, 165, 233, .14); }

body.theme-classic .stat .stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 18px;
  opacity: .95;
}
body.theme-classic .stat b {
  margin-top: 11px;
}

body.theme-modern .stat {
  padding-inline-start: 17px;
  padding-left: 72px;
  min-height: 104px;
}
body.theme-modern .stat .stat-icon {
  left: 18px;
  top: 18px;
  width: 42px;
  height: 42px;
  border-radius: 15px;
  background: #eef5ff;
  color: #0b3a75;
  box-shadow: inset 0 0 0 1px #dfeafe;
}
body.theme-modern .stat .stat-icon svg {
  width: 21px;
  height: 21px;
}
body.theme-modern .stat--copy .stat-icon,
body.theme-modern .stat--target .stat-icon,
body.theme-modern .stat--undo .stat-icon,
body.theme-modern .stat--coffee .stat-icon {
  color: var(--modern-orange);
  background: var(--modern-orange-soft);
  box-shadow: inset 0 0 0 1px #ffe3ab;
}
body.theme-modern .stat--wallet .stat-icon,
body.theme-modern .stat--cash .stat-icon,
body.theme-modern .stat--status .stat-icon,
body.theme-modern .stat--check .stat-icon {
  color: #16a34a;
  background: #eaf8ee;
  box-shadow: inset 0 0 0 1px #d3f1dc;
}
body.theme-modern .stat--calendar .stat-icon,
body.theme-modern .stat--list .stat-icon {
  color: #7c3aed;
  background: #f4edff;
  box-shadow: inset 0 0 0 1px #eadcff;
}
body.theme-modern .stat--users .stat-icon,
body.theme-modern .stat--trend_up .stat-icon {
  color: #0284c7;
  background: #edf8ff;
  box-shadow: inset 0 0 0 1px #d7efff;
}
body.theme-modern .stat--trend_down .stat-icon {
  color: #dc2626;
  background: #fff1f1;
  box-shadow: inset 0 0 0 1px #ffdada;
}

@media (max-width: 700px) {
  .stat {
    padding-left: 66px;
  }
  .stat .stat-icon {
    left: 16px;
    top: 18px;
    width: 40px;
    height: 40px;
    border-radius: 14px;
  }
  .stat .stat-icon svg {
    width: 20px;
    height: 20px;
  }
  body.theme-modern .stat {
    padding-left: 64px;
  }
}

/* v1.6.4 hotfix — modern theme flat progress bars */
body.theme-modern .bars {
  gap: 12px;
}

body.theme-modern .barrow {
  grid-template-columns: 128px minmax(0, 1fr) 132px;
  gap: 14px;
}

body.theme-modern .barrow label,
body.theme-modern .barrow strong {
  color: #64748b;
  font-size: 11.5px;
  font-weight: 600;
}

body.theme-modern .bar {
  height: 8px;
  background: #edf2f7;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .02);
}

body.theme-modern .bar i {
  height: 100%;
  border-radius: inherit;
  background: #0f3b78;
  box-shadow: none;
}

body.theme-modern .barrow:nth-child(3n + 2) .bar i {
  background: #d6b353;
}

body.theme-modern .barrow:nth-child(3n) .bar i {
  background: #2f80c9;
}

@media (max-width: 700px) {
  body.theme-modern .barrow {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  body.theme-modern .barrow strong {
    text-align: right;
  }
}


/* v1.6.5: safer, clearer datepicker controls */
body.theme-modern .jdp {
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, .12);
}
body.theme-modern .jdp-head button,
body.theme-modern .jdp-foot button,
body.theme-modern .jdp-days button {
  background: #f3f6fa;
}
body.theme-modern .jdp-head button:hover,
body.theme-modern .jdp-foot button:hover {
  background: rgba(245, 158, 11, .14);
  color: #b7791f;
}
body.theme-modern .jdp-days button.is-today {
  color: #0f3b73;
  background: rgba(15, 59, 115, .10);
  box-shadow: inset 0 0 0 1px rgba(15, 59, 115, .18);
}
body.theme-modern .jdp-days button.is-today::after {
  background: #f59e0b;
}
body.theme-modern .jdp-days button.is-selected {
  background: #0f3b73;
  color: #fff;
}
body.theme-modern .jdp-days button.is-selected::after {
  background: #f59e0b;
}


/* v1.6.7 - invoice attachment list */
.receipt-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.receipt-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 14px;
  background: rgba(248, 250, 252, .82);
}
.receipt-links {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.theme-modern .receipt-item {
  border-color: #e8edf4;
  background: #f8fafc;
  border-radius: 12px;
  padding: 8px 10px;
}
@media (max-width: 640px) {
  .receipt-item { align-items: stretch; }
  .receipt-item .inline-form { width: 100%; }
  .receipt-item .inline-form .btn { width: 100%; }
}

/* v1.6.8 - receipt upload polish */
.receipt-upload-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 16px;
  background: rgba(248, 250, 252, .72);
}
.receipt-upload-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.receipt-upload-head strong {
  font-size: 13px;
  color: var(--text, #1f2937);
}
.receipt-upload-inputs {
  display: grid;
  gap: 8px;
}
.receipt-upload-row {
  display: grid;
  grid-template-columns: minmax(70px, auto) 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px dashed rgba(148, 163, 184, .45);
  border-radius: 14px;
  background: #fff;
}
.receipt-upload-row span,
.receipt-item-meta {
  font-size: 12px;
  color: var(--muted, #64748b);
  white-space: nowrap;
}
.receipt-upload-row input[type="file"] {
  width: 100%;
  min-height: 38px;
  padding: 6px;
  border-radius: 10px;
}
.receipt-upload-row.has-file {
  border-style: solid;
  border-color: rgba(16, 185, 129, .34);
  background: rgba(240, 253, 244, .48);
}
.receipt-current {
  margin-top: 6px;
}
.receipt-list {
  gap: 10px;
  margin-top: 10px;
}
.receipt-item {
  gap: 10px;
  padding: 10px;
}
.receipt-item-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}
.receipt-links {
  gap: 6px;
}
.purchase-form-actions {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(148, 163, 184, .18);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.hidden-delete-form {
  display: none !important;
}
body.theme-modern .receipt-upload-box {
  background: #fff;
  border-color: rgba(15, 23, 42, .08);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .04);
}
body.theme-modern .receipt-upload-row {
  border-color: rgba(15, 23, 42, .10);
  background: #f8fafc;
}
body.theme-modern .receipt-upload-row.has-file {
  border-color: rgba(234, 136, 46, .35);
  background: rgba(255, 247, 237, .56);
}
@media (max-width: 720px) {
  .receipt-upload-head,
  .receipt-item,
  .purchase-form-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .receipt-upload-head .btn,
  .purchase-form-actions .btn,
  .receipt-item .btn {
    width: 100%;
  }
  .receipt-upload-row {
    grid-template-columns: 1fr;
  }
}

.muted-field { opacity: .65; }
.debt-report-card .stat { margin: 10px 0 14px; }

/* v1.7.3 - final requested layout fixes */
/* Select arrow spacing in RTL: keep arrow away from field edge */
select {
  background-position: left 26px center;
  padding-left: 58px;
}
body.theme-modern select {
  background-position: left 26px center;
  padding-left: 56px;
}

/* Datepicker: today should be clearly highlighted with orange accent and white text */
.jdp-days button.is-today,
body.theme-modern .jdp-days button.is-today {
  background: #f59e0b !important;
  color: #fff !important;
  box-shadow: 0 10px 20px rgba(245, 158, 11, .24) !important;
}
.jdp-days button.is-today::after,
body.theme-modern .jdp-days button.is-today::after {
  background: #fff !important;
}
.jdp-days button.is-selected,
body.theme-modern .jdp-days button.is-selected {
  color: #fff;
}

/* Pagination: stats on the right, page buttons on the left */
.pagination {
  display: flex !important;
  align-items: center;
  justify-content: space-between !important;
  gap: 14px;
  flex-wrap: wrap;
}
.pagination-stats-wrap {
  order: 1;
  margin-inline-end: auto;
}
.pagination-buttons {
  order: 2;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  margin-inline-start: auto;
}
.pagination-stats {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
@media (max-width: 768px) {
  .pagination {
    align-items: stretch;
    overflow-x: visible;
    flex-wrap: wrap;
  }
  .pagination-stats-wrap,
  .pagination-buttons {
    width: 100%;
    margin-inline: 0;
  }
  .pagination-stats-wrap { order: 1; }
  .pagination-buttons {
    order: 2;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }
}

/* Modern sidebar: user/logout box sits near the bottom, above appearance/version controls */
body.theme-modern .sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
body.theme-modern .sidebar-bottom .userbox.user-profile {
  margin-bottom: 4px;
}
body.theme-modern .sidebar-bottom .theme-state {
  margin-top: 8px;
}

/* v1.7.4 — Modern sidebar menu spacing: move navigation lower and spread items slightly to reduce unused vertical gap. */
@media (max-height: 760px) and (min-width: 861px) {
  body.theme-modern .main-nav {
    margin-top: 14px;
    gap: 6px;
  }
  body.theme-modern .main-nav a { min-height: 36px; }
}

/* v1.7.6 — Modern sidebar quick links sit after menu, not pinned to bottom */
body.theme-modern .sidebar-quick-group {
  margin-top: 36px;
  padding-top: 0;
  border-top: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
body.theme-modern .sidebar-quick-title {
  color: var(--modern-navy);
  font-size: 13px;
  font-weight: 900;
  padding: 0 4px 6px;
  line-height: 1.7;
}
body.theme-modern .sidebar-quick-action {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 4px;
  border-radius: 12px;
  background: transparent;
  border: 0;
  color: var(--modern-navy);
  text-decoration: none;
  font-size: 11.8px;
  font-weight: 800;
}
body.theme-modern .sidebar-quick-action:hover {
  background: rgba(245, 158, 11, .08);
}
body.theme-modern .sidebar-quick-action .quick-icon {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--modern-orange);
  color: #fff;
  flex: 0 0 23px;
}
body.theme-modern .sidebar-quick-action .quick-icon svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
body.theme-modern .sidebar-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--modern-line-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
body.theme-modern .sidebar-bottom .userbox.user-profile {
  margin: 0;
}
body.theme-modern .sidebar-bottom .theme-state {
  margin-top: 0;
}
body.theme-modern .main-nav {
  margin-bottom: 0;
}
@media (max-height: 820px) and (min-width: 861px) {
  body.theme-modern .sidebar-quick-group {
    margin-top: 22px;
    padding-top: 0;
    gap: 6px;
  }
  body.theme-modern .sidebar-quick-title {
    font-size: 12px;
    padding-bottom: 4px;
  }
  body.theme-modern .sidebar-quick-action {
    min-height: 32px;
    padding-block: 5px;
    font-size: 11.3px;
  }
  body.theme-modern .sidebar-bottom {
    gap: 7px;
    padding-top: 8px;
  }
}
@media (max-width: 860px) {
  body.theme-modern .sidebar-quick-group { display: none; }
}


/* Viewer access notice modal */
.viewer-access-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .34);
  backdrop-filter: blur(5px);
  animation: viewerModalFadeIn .18s ease-out both;
}
.viewer-access-modal.is-hiding {
  animation: viewerModalFadeOut .18s ease-in both;
}
.viewer-access-card {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid rgba(226, 232, 240, .95);
  border-radius: 22px;
  box-shadow: 0 26px 80px rgba(15, 23, 42, .22);
  padding: 24px;
  text-align: center;
  display: grid;
  gap: 14px;
}
.viewer-access-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 2px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(245, 158, 11, .14);
  color: #f59e0b;
}
.viewer-access-icon svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.viewer-access-content h2 {
  margin: 0 0 8px;
  color: #0f172a;
  font-size: 18px;
  font-weight: 900;
}
.viewer-access-content p {
  margin: 0;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
  line-height: 2;
}
.viewer-access-close {
  border: 0;
  border-radius: 14px;
  min-height: 44px;
  padding: 0 18px;
  background: #0b3f7f;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.viewer-access-close:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(11, 63, 127, .22);
  background: #08366d;
}
body.theme-classic .viewer-access-icon {
  background: rgba(20, 184, 166, .12);
  color: #0f766e;
}
body.theme-classic .viewer-access-close {
  background: #0f766e;
}
body.theme-classic .viewer-access-close:hover {
  background: #0d665f;
}
@keyframes viewerModalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes viewerModalFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
@media (max-width: 520px) {
  .viewer-access-card { padding: 20px; border-radius: 20px; }
  .viewer-access-content h2 { font-size: 16px; }
  .viewer-access-content p { font-size: 12.5px; }
}
