:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --line: #d8e1eb;
  --soft-line: #e8eef5;
  --surface: #ffffff;
  --band: #f6f8fb;
  --brand: #1f4e79;
  --brand-2: #0f766e;
  --warn: #b45309;
  --bad: #b91c1c;
  --good: #047857;
  --focus: #2f7dd1;
  font-family: Tahoma, "Segoe UI", Arial, ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef3f8;
  color: var(--ink);
  direction: rtl;
}

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

button,
.file-button,
.button-link {
  min-height: 38px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 7px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

button:hover,
.file-button:hover,
.button-link:hover {
  filter: brightness(0.96);
}

button.ghost,
.button-link.ghost {
  background: #fff;
  color: var(--brand);
}

button.danger {
  background: var(--bad);
  border-color: var(--bad);
}

button.full {
  width: 100%;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 16px;
}

.brand p,
.section-title p,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-badge {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.sidebar {
  border-left: 1px solid var(--line);
  background: #f8fafc;
  padding: 18px;
}

.month-control {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.month-create {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 8px;
}

.month-create button {
  grid-column: 1 / -1;
}

label {
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  direction: rtl;
}

input {
  min-height: 38px;
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.8;
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 7px 8px;
  color: var(--ink);
  background: #fff;
}

input[type="number"],
input[type="date"],
input[type="time"] {
  direction: ltr;
  text-align: right;
}

input[readonly] {
  color: #475569;
  background: #edf2f7;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(47, 125, 209, 0.24);
  border-color: var(--focus);
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.day-grid button {
  min-height: 42px;
  border-color: var(--line);
  background: #fff;
  color: #334155;
  padding: 0;
}

.day-grid button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.workspace {
  min-width: 0;
  padding: 22px 24px 36px;
}

.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 18px;
}

.report-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions {
  white-space: nowrap;
}

.button-link.compact,
button.compact {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

html[dir="rtl"] .tabs {
  direction: rtl;
}

.tab {
  border: 0;
  background: transparent;
  color: #475569;
  min-height: 36px;
}

.tab.active {
  background: var(--brand);
  color: #fff;
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  margin-inline-start: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1e3a5f;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.tab-badge[hidden] {
  display: none;
}

.tab.active .tab-badge {
  background: #fff;
  color: var(--brand);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 10px;
  width: min(420px, 100%);
}

.date-selects {
  display: grid;
  grid-template-columns: 1fr 1.2fr 0.8fr auto;
  gap: 6px;
  margin-top: 6px;
}

.date-selects button {
  min-height: 38px;
  padding: 0 10px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.section-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 18px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
}

.table-wrap.wide {
  max-height: 68vh;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

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

th:first-child,
td:first-child {
  text-align: right;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #e9f1f8;
  color: #1e3a5f;
  font-weight: 700;
}

tfoot th,
tfoot td {
  background: #f2f7fb;
  font-weight: 700;
}

.fuel-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #e0f2f1;
  color: #0f766e;
  font-size: 12px;
  font-weight: 700;
}

.fuel-pill.regular {
  background: #eaf2ff;
  color: #1f4e79;
}

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

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

.report-builder-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
}

.report-builder-filters label {
  display: grid;
  gap: 6px;
}

.report-month-output {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  color: #1e3a5f;
  font-weight: 700;
}

.report-toggle {
  min-height: 42px;
  display: flex !important;
  grid-column: span 2;
  align-items: center;
  gap: 8px !important;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #f8fafc;
}

.report-toggle input,
.report-field-options input {
  width: 18px;
  height: 18px;
  min-height: 0;
  accent-color: var(--brand);
}

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

.report-fields-help {
  margin-top: 5px !important;
  color: #365b78 !important;
  font-size: 12px;
  font-weight: 700;
}

.report-field-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.report-field-group:hover,
.report-field-group:focus-within {
  border-color: #8fb6d8;
  box-shadow: 0 3px 12px rgba(30, 58, 95, 0.08);
}

.report-field-group[open] {
  border-color: #74a4cc;
}

.report-field-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  padding: 11px 12px;
  color: #1e3a5f;
  font-weight: 800;
  background: #f8fafc;
  list-style: none;
  user-select: none;
}

.report-field-group summary::-webkit-details-marker {
  display: none;
}

.report-group-title {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.report-group-title > span:last-child {
  display: grid;
  gap: 2px;
}

.report-group-title strong {
  font-size: 14px;
}

.report-group-chevron {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
  font-size: 11px;
  transition: transform 160ms ease;
}

.report-field-group[open] .report-group-chevron {
  transform: rotate(-90deg);
}

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

.report-group-hint::after {
  content: "برای مشاهده و انتخاب ستون‌ها کلیک کنید";
}

.report-field-group[open] .report-group-hint::after {
  content: "ستون‌های قابل انتخاب نمایش داده شده‌اند";
}

.report-group-count {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  color: #365b78;
  background: #e8f1f8;
  font-size: 12px;
  font-weight: 700;
}

.report-field-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  max-height: 320px;
  overflow: auto;
  border-top: 1px solid var(--soft-line);
}

.report-field-options label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px;
  border-radius: 6px;
  color: #334155;
  font-size: 13px;
}

.report-field-options label:hover {
  background: #f2f7fb;
}

.report-csv-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.report-preview-wrap {
  max-height: 62vh;
}

.report-preview-wrap td {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-grid label,
.settings-grid label {
  display: grid;
  gap: 6px;
}

.inventory-grid {
  display: grid;
  grid-template-columns: 130px repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
}

.inventory-grid strong {
  color: #1e3a5f;
  text-align: center;
}

.computed-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--soft-line);
}

.computed-list dt {
  color: var(--muted);
}

.computed-list dd {
  margin: 0;
  font-weight: 700;
  text-align: left;
}

.check-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.check {
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.check.good {
  color: var(--good);
  border-color: #a7f3d0;
  background: #ecfdf5;
}

.check.warn {
  color: var(--warn);
  border-color: #fed7aa;
  background: #fff7ed;
}

.expense-list,
.incoming-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.expense-row,
.incoming-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px 38px;
  gap: 8px;
}

.incoming-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

.incoming-title {
  color: #1e3a5f;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

.incoming-row {
  grid-template-columns: 110px minmax(140px, 1fr) 110px minmax(130px, 1fr) 130px 38px;
}

.expense-row button,
.incoming-row button {
  padding: 0;
  background: #fff;
  color: var(--bad);
  border-color: #fecaca;
}

.danger-zone {
  border-color: #fecaca;
}

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

.upload-form label,
.user-form label {
  display: grid;
  gap: 6px;
}

.upload-context {
  min-height: 38px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
}

.inline-status {
  min-height: 22px;
  margin-top: 12px;
  color: var(--brand-2);
  font-size: 13px;
  font-weight: 700;
}

.user-table-wrap {
  margin-top: 14px;
}

.operational-scroll {
  width: 100%;
  overflow: auto;
  border: 1px solid #111;
  background: #fff;
}

.operational-sheet {
  min-width: 1680px;
  direction: rtl;
  background: #fff;
  color: #000;
  font-family: "B Nazanin", Tahoma, Arial, sans-serif;
}

.op-title,
.op-period {
  background: #000;
  color: #fff;
  font-family: "B Titr", Tahoma, Arial, sans-serif;
  font-weight: 700;
  text-align: center;
}

.op-title {
  padding: 16px;
  font-size: 22px;
}

.op-period {
  min-height: 48px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 90px;
  padding: 8px 52px;
  font-size: 17px;
}

.operational-sheet .op-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  direction: rtl;
}

.operational-sheet .op-table th,
.operational-sheet .op-table td {
  position: static;
  border: 1px dashed #333;
  border-bottom: 1px solid #333;
  background: #fff;
  color: #000;
  padding: 8px 6px;
  text-align: center;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
  direction: rtl;
}

.operational-sheet .op-table thead th {
  height: 72px;
  border-top: 3px solid #000;
  font-size: 15px;
}

.operational-sheet .op-table tr > :first-child {
  width: 125px;
  border-right: 3px solid #000;
}

.operational-sheet .op-table tr > :last-child {
  border-left: 3px solid #000;
}

.operational-sheet .op-summary-table tbody tr:last-child > * {
  border-bottom: 3px solid #000;
}

.operational-sheet .op-pink {
  background: #f3dddd !important;
}

.operational-sheet .op-blue,
.operational-sheet .op-blue-row td {
  background: #d9e8f2 !important;
}

.operational-sheet .op-super {
  background: #dce9bf !important;
}

.op-divider {
  height: 20px;
  border-top: 3px solid #000;
  border-bottom: 3px solid #000;
}

.op-empty-band {
  height: 34px;
  border: 3px solid #000;
}

.op-signatures {
  direction: rtl;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 40px;
  min-height: 100px;
  align-items: center;
  padding: 20px 42px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.op-note {
  direction: rtl;
  margin: 0;
  padding: 8px 14px;
  color: #475569;
  text-align: right;
  font-size: 11px;
}

.password-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.password-toggle {
  min-width: 72px;
  min-height: 38px;
  padding: 0 10px;
  background: #fff;
  color: var(--brand);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .day-grid {
    grid-template-columns: repeat(8, 1fr);
  }

  .two-column,
  .metric-strip,
  .settings-grid,
  .incoming-layout,
  .upload-form,
  .user-form {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  body.print-operational {
    background: #fff;
  }

  body.print-operational .app-header,
  body.print-operational .sidebar,
  body.print-operational .tabs,
  body.print-operational .view-heading,
  body.print-operational .view:not(#operationalView) {
    display: none !important;
  }

  body.print-operational .app-shell,
  body.print-operational .workspace,
  body.print-operational #operationalView,
  body.print-operational .operational-scroll {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    overflow: visible !important;
  }

  body.print-operational .operational-sheet {
    min-width: 0;
    width: 100%;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body.print-operational .operational-sheet .op-table th,
  body.print-operational .operational-sheet .op-table td {
    padding: 4px 2px;
    font-size: 8px;
  }

  body.print-operational .op-title {
    padding: 8px;
    font-size: 13px;
  }

  body.print-operational .op-period,
  body.print-operational .op-signatures {
    min-height: 0;
    font-size: 9px;
  }
}

@media (max-width: 680px) {
  .app-header,
  .view-heading,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header {
    position: static;
  }

  .header-actions,
  .inline-fields,
  .form-grid,
  .date-selects,
  .report-builder-filters,
  .report-field-groups,
  .report-field-options {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .report-toggle {
    grid-column: auto;
  }

  .report-field-group summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .report-group-count {
    margin-right: 33px;
  }

  .header-actions {
    display: grid;
  }

  .workspace {
    padding: 16px;
  }

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

  .tabs {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .inventory-grid {
    grid-template-columns: 1fr;
  }

  .expense-row,
  .incoming-row {
    grid-template-columns: 1fr;
  }
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
}

.login-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 12px;
}

.login-panel h1 {
  font-size: 24px;
}

.login-panel p {
  color: var(--muted);
  margin-top: 6px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form label {
  display: grid;
  gap: 6px;
}

.login-error {
  margin-top: 16px;
  border: 1px solid #fecaca;
  border-radius: 7px;
  background: #fef2f2;
  color: var(--bad);
  padding: 10px 12px;
  font-size: 13px;
}

.login-success {
  margin-top: 16px;
  border: 1px solid #a7f3d0;
  border-radius: 7px;
  background: #ecfdf5;
  color: var(--good);
  padding: 10px 12px;
  font-size: 13px;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 420px) {
  .panel-actions {
    grid-template-columns: 1fr;
  }
}
