:root {
  color-scheme: light;
  --bg: #f7fbff;
  --panel: #ffffff;
  --panel-soft: #edf6ff;
  --ink: #1f2937;
  --muted: #65758b;
  --line: #d7e4f2;
  --line-strong: #a9bfda;
  --brand: #0ea5e9;
  --brand-dark: #153e75;
  --brand-soft: #e0f2fe;
  --gold: #facc15;
  --blue: #2563eb;
  --red: #f43f5e;
  --orange: #f97316;
  --green: #10b981;
  --purple: #8b5cf6;
  --pink: #ec4899;
  --shadow: 0 10px 28px rgba(37, 99, 235, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(14, 165, 233, 0.08), rgba(250, 204, 21, 0.04) 42%, transparent),
    var(--bg);
  color: var(--ink);
  font-family: "B Nazanin", "BNazanin", Nazanin, Tahoma, Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

body.auth-locked {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.sprite {
  display: none;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  flex: 0 0 auto;
}

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

body.auth-locked .app-shell {
  display: none;
}

.login-screen {
  display: none;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

body.auth-locked .login-screen {
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 20px;
  color: var(--ink);
}

.login-brand span {
  color: var(--muted);
}

.login-error {
  min-height: 24px;
  margin: 8px 0 12px;
  color: var(--red);
  font-size: 0.9rem;
}

.login-submit {
  width: 100%;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  width: 264px;
  height: 100vh;
  padding: 20px 16px;
  background: #123e74;
  color: #f8fbfa;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--gold);
  color: #1e293b;
  font-weight: 800;
}

.brand strong,
.brand span,
.storage-card span,
.storage-card strong,
.storage-card small {
  display: block;
}

.brand strong {
  font-size: 1.02rem;
}

.brand span {
  margin-top: 4px;
  color: #cad9d5;
  font-size: 0.83rem;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #e9f1ee;
  text-align: right;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(250, 204, 21, 0.42);
}

.nav-item.active {
  box-shadow: inset -3px 0 0 var(--gold);
}

.storage-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(14, 165, 233, 0.18);
}

.storage-card span,
.storage-card small {
  color: #c7d5d1;
  font-size: 0.82rem;
}

.storage-card strong {
  margin-top: 6px;
  margin-bottom: 6px;
  font-size: 1.1rem;
}

.main {
  min-width: 0;
  flex: 1;
  padding: 22px;
}

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

.view-heading h1 {
  margin: 0;
  font-size: 1.42rem;
  line-height: 1.45;
}

.view-heading p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions,
.quick-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-actions {
  margin-bottom: 12px;
}

.report-controls {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) repeat(4, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 270px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.search-field input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.icon-button.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.icon-button.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 0.86rem;
}

.icon-button:hover {
  border-color: var(--line-strong);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card,
.surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 118px;
  padding: 16px;
  border-top: 4px solid var(--brand);
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.86rem;
}

.metric-card strong {
  display: block;
  margin-top: 12px;
  font-size: 1.24rem;
  line-height: 1.35;
}

.metric-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.metric-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
}

.metric-card.blue .metric-icon {
  background: #dbeafe;
  color: var(--blue);
}

.metric-card.red .metric-icon {
  background: #ffe4e6;
  color: var(--red);
}

.metric-card.orange .metric-icon {
  background: #ffedd5;
  color: var(--orange);
}

.metric-card.blue {
  border-top-color: var(--blue);
}

.metric-card.red {
  border-top-color: var(--red);
}

.metric-card.orange {
  border-top-color: var(--orange);
}

.dashboard-grid,
.definition-grid,
.balance-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 1fr);
  gap: 14px;
}

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

.surface {
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(14, 165, 233, 0.1), rgba(250, 204, 21, 0.08));
}

.section-head h2 {
  margin: 0;
  font-size: 0.96rem;
}

.section-head span {
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
  max-height: 600px;
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.data-table.compact {
  min-width: 520px;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e0f2fe;
  color: #164e63;
  font-weight: 700;
}

.data-table td {
  line-height: 1.55;
}

.data-table th,
.data-table td:not(.detail) {
  white-space: nowrap;
}

.number {
  direction: ltr;
  text-align: left !important;
  white-space: nowrap;
}

.detail {
  min-width: 220px;
  max-width: 360px;
  white-space: normal;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7faf9;
  color: #39423f;
  white-space: nowrap;
}

.badge.good {
  border-color: #86efac;
  background: #dcfce7;
  color: #166534;
}

.badge.warn {
  border-color: #fde68a;
  background: #fef9c3;
  color: #854d0e;
}

.badge.bad {
  border-color: #fda4af;
  background: #ffe4e6;
  color: #9f1239;
}

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

.action-cell {
  width: 92px;
  white-space: nowrap;
}

.row-action {
  display: inline-grid;
  place-items: center;
  width: 31px;
  height: 31px;
  margin-left: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.row-action.delete {
  border-color: #fda4af;
  background: #fff1f2;
  color: var(--red);
}

.mini-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.mini-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line);
}

.mini-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.mini-row strong {
  direction: ltr;
  text-align: left;
}

.mini-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.report-summary div {
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef6ff;
}

.report-summary span,
.report-summary strong {
  display: block;
}

.report-summary span {
  color: var(--muted);
  font-size: 0.84rem;
}

.report-summary strong {
  margin-top: 8px;
  direction: ltr;
  text-align: left;
}

.report-wrap {
  max-height: 430px;
}

#reportSummary:empty {
  display: none;
}

dialog {
  width: min(800px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 22px 80px rgba(30, 45, 40, 0.22);
}

dialog::backdrop {
  background: rgba(16, 25, 23, 0.45);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.02rem;
}

.dialog-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.close-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 1.2rem;
}

.record-type-field,
.form-grid,
.dialog-actions {
  margin: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.86rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.field textarea {
  min-height: 78px;
  resize: vertical;
}

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

.field.wide {
  grid-column: 1 / -1;
}

.dialog-actions {
  justify-content: flex-end;
  padding-bottom: 16px;
}

@media (max-width: 1120px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .dashboard-grid,
  .definition-grid,
  .balance-grid,
  .report-summary,
  .report-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
    min-height: 42px;
    padding: 0 8px;
    font-size: 0.84rem;
  }

  .storage-card {
    display: none;
  }

  .main {
    padding: 16px;
  }

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

  .search-field {
    min-width: 0;
    flex: 1 1 220px;
  }
}

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

  .top-actions,
  .quick-actions {
    align-items: stretch;
  }

  .top-actions > *,
  .quick-actions > * {
    flex: 1 1 100%;
  }

  .kpi-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding-top: 12px;
    padding-bottom: 12px;
  }
}
