:root {
  --bg: #edf1f3;
  --bg-accent: #e4ecea;
  --surface: #ffffff;
  --ink: #14262c;
  --muted: #5d6f79;
  --line: #d5dee3;
  --line-soft: #e8eef0;
  --accent: #0f6b5c;
  --accent-2: #0b5347;
  --accent-soft: rgba(15, 107, 92, 0.1);
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
  --sidebar: #0d2c29;
  --sidebar-2: #123330;
  --shadow: 0 12px 32px rgba(20, 38, 44, 0.06);
  --radius: 16px;
  --font: "Vazirmatn", "IRANSans", Tahoma, sans-serif;
  --sidebar-w: 272px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body, .app-body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(15, 107, 92, 0.08), transparent 55%),
    linear-gradient(180deg, #f7fafb 0%, var(--bg) 100%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

/* ===== App shell: fixed sidebar, scroll only main ===== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  height: 100vh;
  height: 100dvh;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), transparent 30%),
    linear-gradient(165deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
  color: #e7f3f0;
  overflow: hidden;
  position: relative;
  z-index: 5;
  border-left: 1px solid rgba(255,255,255,.06);
}

.sidebar-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1.25rem;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
}
.brand-text { display: grid; gap: .1rem; min-width: 0; }
.brand strong {
  font-size: .95rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text span,
.brand-text > span {
  color: rgba(231, 243, 240, .65);
  font-size: .75rem;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(145deg, #1aa58d, #0f6b5c);
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  flex-shrink: 0;
  box-shadow: 0 8px 20px rgba(0,0,0,.18);
}
.brand-light { color: #fff; }
.brand-center { justify-content: center; margin-bottom: 1rem; }

.nav {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.nav a {
  color: #c5ddd7;
  padding: .72rem .85rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: .55rem;
  transition: background .15s ease, color .15s ease;
}
.nav a:hover, .nav a.active {
  background: rgba(255,255,255,.09);
  color: #fff;
}
.nav a.active {
  background: rgba(26, 165, 141, .22);
  box-shadow: inset 0 0 0 1px rgba(26, 165, 141, .35);
}
.nav-ico {
  width: 1.1rem;
  text-align: center;
  opacity: .8;
  font-size: .75rem;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: .75rem;
  flex-shrink: 0;
  padding-top: .5rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-chip {
  background: rgba(255,255,255,.07);
  padding: .7rem .8rem;
  border-radius: 14px;
  display: grid;
  gap: .15rem;
}
.user-chip .user-role {
  font-size: .7rem;
  color: #8fd0c2;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.user-chip strong { font-size: .9rem; }
.user-chip small {
  color: rgba(231,243,240,.65);
  font-size: .78rem;
  direction: ltr;
  text-align: right;
}

.main {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.35rem 1.6rem 2.2rem;
  scroll-behavior: smooth;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.15rem;
}
.eyebrow {
  margin: 0 0 .2rem;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 500;
}
.topbar h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -.01em;
}
.date-pill {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .4rem .8rem;
  color: var(--muted);
  font-size: .88rem;
  box-shadow: var(--shadow);
}

.content { display: grid; gap: 1rem; }

.panel, .stat-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 1.15rem 1.25rem; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.panel-head h2 { margin: 0; font-size: 1.05rem; font-weight: 700; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.stat-card {
  padding: 1.15rem 1.25rem;
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  inset-inline-end: -20px;
  top: -20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: var(--accent-soft);
}
.stat-label { color: var(--muted); font-size: .88rem; position: relative; }
.stat-value {
  display: block;
  margin-top: .4rem;
  font-size: 1.85rem;
  font-weight: 700;
  position: relative;
}
.stat-value-sm { font-size: 1.2rem; }
.stat-sub {
  margin-top: .35rem;
  font-size: .8rem;
  position: relative;
}

.filters {
  display: grid;
  grid-template-columns: 2fr 1.2fr auto;
  gap: .75rem;
  align-items: end;
  margin-bottom: .85rem;
}
.filters.compact {
  grid-template-columns: 1fr auto;
  margin: 0;
}
.filter-actions { display: flex; gap: .5rem; }

label {
  display: grid;
  gap: .35rem;
  font-size: .88rem;
  color: var(--muted);
  font-weight: 500;
}
label.grow { min-width: 0; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .7rem .85rem;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #7eb9ae;
  box-shadow: 0 0 0 3px rgba(15, 107, 92, .12);
}
textarea { resize: vertical; }
.check {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--ink);
}
.check input { width: auto; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .9rem 1rem;
}
.span-2 { grid-column: span 2; }
.stack { display: grid; gap: .9rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: .58rem 1rem;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { border-color: #b7c6cd; transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(180deg, #128574, var(--accent));
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(15, 107, 92, .22);
}
.btn-primary:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.btn-danger { color: var(--danger); border-color: #f3c1bc; background: #fff5f4; }
.btn-ghost {
  background: transparent;
  border-color: rgba(255,255,255,.18);
  color: #e8f4f1;
}
.btn-ghost:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.28); }
.btn-block { width: 100%; }
.btn-sm { padding: .38rem .7rem; font-size: .84rem; border-radius: 10px; }
.btn-lg { padding: .8rem 1rem; font-size: 1rem; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.inline { display: inline; margin: 0; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
}
table, .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
  table-layout: fixed;
}
th, td {
  text-align: right;
  padding: .78rem .7rem;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-weight: 600;
  background: #f7fafb;
  font-size: .82rem;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f9fcfb; }
.empty { text-align: center; color: var(--muted); padding: 1.4rem !important; }
.num,
.col-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  direction: ltr;
  text-align: left !important;
  unicode-bidi: isolate;
  white-space: nowrap;
}
.col-text {
  text-align: right !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-action {
  text-align: center !important;
  white-space: nowrap;
}
.col-num-strong {
  font-weight: 700;
}
.portal-table .col-period { width: 22%; }
.portal-table .col-month { width: 16%; }
.portal-table .col-money { width: 16%; }
.portal-table .col-action { width: 14%; }

.badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  margin-inline-start: .35rem;
  font-weight: 600;
}
.badge-draft { background: #fff7ed; color: var(--warn); }
.badge-final { background: #ecfdf3; color: var(--ok); }

.alert {
  padding: .9rem 1rem;
  border-radius: 14px;
  margin-bottom: 1rem;
  border: 1px solid;
  font-weight: 500;
}
.alert-success { background: #ecfdf3; border-color: #abefc6; color: var(--ok); }
.alert-error { background: #fef3f2; border-color: #fecdca; color: var(--danger); }

.muted { color: var(--muted); }
.callout {
  background: linear-gradient(180deg, #f4faf8, #eef7f4);
  border: 1px solid #cfe7e1;
  border-radius: 14px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.callout p { margin: .35rem 0; }

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: 1rem;
}
.pagination a {
  min-width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}
.pagination a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.log-list { margin: 0; padding-inline-start: 1.1rem; color: var(--muted); }
.log-list li { margin-bottom: .4rem; }

/* ===== Auth / Login ===== */
.auth-page {
  min-height: 100vh;
  margin: 0;
  background: #0d2c29;
  display: flex;
  flex-direction: column;
}
.auth-shell {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
}
.auth-hero {
  padding: 2.5rem;
  background:
    radial-gradient(700px 400px at 20% 10%, rgba(26,165,141,.35), transparent 60%),
    linear-gradient(160deg, #0d2c29, #145c52 55%, #0f3d38);
  color: #eaf6f3;
  display: grid;
  align-items: center;
}
.auth-hero-inner { max-width: 460px; }
.auth-hero h2 {
  margin: 1.4rem 0 .7rem;
  font-size: clamp(1.5rem, 2.4vw, 2.1rem);
  line-height: 1.35;
}
.auth-hero p {
  margin: 0;
  color: rgba(234,246,243,.78);
  line-height: 1.8;
  font-size: .98rem;
}
.auth-footer {
  flex-shrink: 0;
  text-align: center;
  padding: .85rem 1rem;
  font-size: .82rem;
  color: rgba(234, 246, 243, .72);
  background: rgba(0, 0, 0, .18);
  border-top: 1px solid rgba(255,255,255,.06);
}
.auth-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-card-wide {
  margin: auto;
  width: min(440px, calc(100% - 2.5rem));
  padding: 1.6rem 1.5rem 1.7rem;
  border-radius: 20px;
}
.auth-card h1 {
  margin: .9rem 0 .35rem;
  font-size: 1.35rem;
  text-align: right;
}
.auth-hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: .88rem;
}
.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .35rem;
  background: #f1f5f6;
  padding: .3rem;
  border-radius: 14px;
}
.login-tab {
  text-align: center;
  padding: .65rem .5rem;
  border-radius: 11px;
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
}
.login-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(20,38,44,.08);
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  .sidebar {
    height: auto;
    position: sticky;
    top: 0;
    overflow: hidden;
  }
  .sidebar-inner {
    height: auto;
    gap: .85rem;
    padding: .9rem;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    overflow: visible;
  }
  .sidebar-foot {
    border-top: none;
    padding-top: 0;
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  .main {
    height: auto;
    overflow: visible;
    padding: 1rem;
  }
  .stats-grid,
  .filters,
  .form-grid,
  .auth-shell { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .auth-hero { display: none; }
  .auth-page { background: var(--bg); }
  .auth-footer {
    color: var(--muted);
    background: transparent;
    border-top: 1px solid var(--line-soft);
  }
  .auth-card-wide { width: min(440px, calc(100% - 1.5rem)); }
}

/* ===== Payslip settings ===== */
.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .85rem;
}
.settings-tabs a {
  padding: .55rem .9rem;
  border-radius: 999px;
  background: #f1f5f6;
  color: var(--muted);
  font-weight: 600;
  font-size: .88rem;
}
.settings-tabs a.active {
  background: var(--accent);
  color: #fff;
}
.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.template-card {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  padding: 1rem;
  background: #fff;
  display: grid;
  gap: .85rem;
}
.template-card.is-active {
  border-color: #7eb9ae;
  box-shadow: 0 0 0 3px rgba(15, 107, 92, .12);
}
.template-card-top { display: flex; gap: .85rem; }
.template-card h3 { margin: 0 0 .25rem; font-size: 1rem; }
.template-card p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.6; }
.template-swatch {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.tpl-swatch-classic { background: linear-gradient(145deg, #0f3d38, #1aa58d); }
.tpl-swatch-compact { background: linear-gradient(145deg, #334155, #94a3b8); }
.tpl-swatch-formal { background: linear-gradient(145deg, #111827, #6b7280); }
.tpl-swatch-modern { background: linear-gradient(125deg, #0d2c29, #1a7a6a 55%, #34d399); }
.template-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  font-size: .82rem;
}
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: 1rem;
}
.item-group { margin-bottom: 1.25rem; }
.item-group-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: .5rem;
}
.item-group-head h3 { margin: 0; font-size: 1rem; }
.settings-items-table .center { text-align: center; }
.settings-items-table code {
  font-size: .78rem;
  background: #f1f5f6;
  padding: .15rem .35rem;
  border-radius: 6px;
  direction: ltr;
  display: inline-block;
}
.preview-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .85rem;
}
.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.profile-card {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  padding: 1.1rem 1.15rem;
  background: #fbfcfd;
}
.profile-card h3 {
  margin: 0 0 .85rem;
  font-size: 1rem;
}
.profile-card.span-2 { grid-column: span 2; }
.profile-dl {
  margin: 0;
  display: grid;
  gap: .65rem;
}
.profile-dl div {
  display: grid;
  gap: .15rem;
}
.profile-dl dt {
  color: var(--muted);
  font-size: .8rem;
}
.profile-dl dd {
  margin: 0;
  font-weight: 600;
}
a.user-chip-link {
  color: inherit;
  text-decoration: none;
}
a.user-chip-link:hover {
  background: rgba(255,255,255,.12);
}
@media (max-width: 960px) {
  .template-grid,
  .preview-summary,
  .profile-grid { grid-template-columns: 1fr; }
  .profile-card.span-2 { grid-column: auto; }
}
