:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --panel: #ffffff;
  --ink: #1e2a2f;
  --muted: #67757b;
  --line: #d9ded8;
  --teal: #16756f;
  --teal-dark: #0f5e59;
  --rust: #a54632;
  --gold: #d0a24a;
  --soft: #eef4f2;
  --shadow: 0 4px 18px rgba(22, 38, 43, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scrollbar-gutter: stable;
}

body {
  direction: rtl;
  text-align: right;
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Vazirmatn", "Noto Sans Arabic", Tahoma, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  width: 100%;
  min-height: 100vh;
}

.sidebar {
  background: #203239;
  color: #f8fbfb;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

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

.brand h1 {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.5;
}

.brand p {
  margin: 0;
  color: #c4d0d2;
  font-size: 12px;
}

.step-list {
  display: grid;
  gap: 8px;
}

.step-item {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border-radius: 8px;
  color: #eaf0ef;
  background: rgba(255, 255, 255, 0.06);
  text-align: right;
}

.step-item.active {
  background: #f4fbf9;
  color: #163035;
}

.step-item.done .step-index {
  background: var(--teal);
  color: #fff;
}

.step-index {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  font-size: 12px;
  font-weight: 700;
}

.step-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.workspace {
  padding: clamp(12px, 2vw, 28px);
  display: grid;
  gap: 16px;
  align-content: start;
}

.workspace,
.workspace > *,
.sidebar,
.brand > div,
.toolbar > div,
.result-header > div,
.field,
.field > div,
.table-field-group,
.help-body,
.help-section,
.transfer-copy,
.import-preview {
  min-width: 0;
  max-width: 100%;
}

.toolbar,
.footer-actions,
.result-header,
.transfer-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.toolbar {
  min-height: 96px;
  padding: 18px 20px;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar h2,
.result-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.45;
}

.draft-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.kicker {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.toolbar-actions,
.footer-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.transfer-panel {
  padding: 18px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 20px;
  align-items: center;
}

.transfer-copy h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.transfer-copy p,
.transfer-status,
.import-note,
.table-scroll-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.9;
}

.transfer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.transfer-status,
.import-preview {
  grid-column: 1 / -1;
}

.transfer-status:empty {
  display: none;
}

.transfer-status:not(:empty) {
  color: var(--teal-dark);
}

.transfer-status.is-error {
  color: var(--rust);
}

.import-preview {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 10px;
}

.import-preview p {
  margin: 0;
}

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

.panel {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(12px, 1.5vw, 20px);
  display: grid;
  gap: 10px;
  background: #fff;
}

.field-header {
  display: grid;
  gap: 6px;
}

.field-title-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.field-label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 800;
  min-width: 0;
  font-size: 15px;
  flex: 1 1 150px;
}

.required {
  color: var(--rust);
}

.question {
  margin: 0;
  color: var(--muted);
  line-height: 1.9;
  font-size: 14px;
}

.help-trigger,
.icon-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: var(--soft);
  color: var(--teal-dark);
  font-size: 18px;
  font-weight: 900;
}

.help-trigger:hover,
.icon-btn:hover {
  background: #dfecea;
}

input,
textarea,
select {
  width: 100%;
  direction: rtl;
  text-align: right;
  border: 1px solid #cbd4d0;
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  min-width: 0;
  min-height: 46px;
}

textarea {
  min-height: 112px;
  resize: vertical;
  line-height: 1.75;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(22, 117, 111, 0.14);
}

button:focus-visible,
a:focus-visible,
.table-field:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 3px;
}

.primary,
.secondary,
.ghost,
.download-link {
  min-height: 42px;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary {
  background: var(--teal);
  color: #fff;
}

.primary:hover {
  background: var(--teal-dark);
}

.secondary {
  background: var(--soft);
  color: #17353a;
}

.ghost {
  background: transparent;
  color: var(--rust);
}

.danger {
  background: var(--rust);
}

.download-link {
  background: var(--teal);
  color: #fff;
}

.footer-actions {
  padding: 14px 16px;
  justify-content: space-between;
}

.progress-wrap {
  min-width: min(180px, 100%);
  flex: 1;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  height: 8px;
  background: #e7ebe7;
  border-radius: 999px;
  overflow: hidden;
}

#progressBar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.table-field {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  overscroll-behavior-inline: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.table-scroll-hint {
  margin-bottom: 8px;
}

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

.data-table th {
  background: #edf3f0;
  font-size: 12px;
  text-align: right;
}

.data-table input {
  min-width: 120px;
  border-radius: 6px;
}

.row-actions {
  width: 54px;
  text-align: center;
}

.mini-btn {
  min-width: 34px;
  height: 34px;
  border-radius: 6px;
  background: #f8e8e4;
  color: var(--rust);
  font-weight: 800;
}

.add-row {
  width: fit-content;
  margin-top: 8px;
}

.result-panel {
  padding: 0;
  overflow: hidden;
}

.result-header {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

#preview {
  direction: rtl;
  text-align: right;
  unicode-bidi: isolate;
  margin: 0;
  padding: 18px;
  max-height: 560px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.85;
  font-family: inherit;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  background: #fcfdfb;
}

.status-ok {
  color: #a4e7c0 !important;
}

.status-warn {
  color: #ffd88b !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(14, 27, 31, 0.52);
}

.modal-backdrop[hidden] {
  display: none;
}

.help-modal {
  width: min(820px, 100%);
  max-height: min(780px, calc(100vh - 36px));
  overflow: auto;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(10, 24, 28, 0.28);
  border: 1px solid var(--line);
  min-width: 0;
}

.help-modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  background: #fbfcfb;
  border-bottom: 1px solid var(--line);
}

.help-modal-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.5;
}

.help-question {
  margin: 0;
  padding: 16px 18px;
  color: var(--muted);
  line-height: 1.8;
  border-bottom: 1px solid var(--line);
}

.help-body {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.help-section {
  display: grid;
  gap: 8px;
}

.help-section h3 {
  margin: 0;
  font-size: 15px;
  color: #17353a;
}

.help-section p,
.help-section li {
  line-height: 1.85;
}

.help-section p {
  margin: 0;
}

.help-section ul {
  margin: 0;
  padding: 0 20px 0 0;
}

.help-example {
  direction: rtl;
  text-align: right;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf7;
  white-space: pre-wrap;
  line-height: 1.85;
  font-family: inherit;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.help-example-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  overflow: hidden;
  border-radius: 8px;
  table-layout: fixed;
}

.help-example-table th,
.help-example-table td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: right;
  vertical-align: top;
  line-height: 1.7;
}

.help-example-table th {
  background: #edf3f0;
}

.sample-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
  align-items: center;
  gap: 12px 20px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sample-panel > div,
.department-label,
.field-actions,
.sample-card,
.select-with-custom,
.jalali-control {
  min-width: 0;
  max-width: 100%;
}

.sample-panel h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.sample-panel p,
.sample-disclaimer,
.sample-status {
  margin: 0;
  font-size: 13px;
  line-height: 1.9;
  color: var(--muted);
}

.sample-status {
  grid-column: 1 / -1;
  color: var(--teal-dark);
}

.sample-status:empty {
  display: none;
}

.department-label {
  display: grid;
  gap: 5px;
  font-size: 13px;
  font-weight: 700;
}

.field-actions,
.department-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.sample-trigger {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
}

.department-tab {
  flex: 1 1 130px;
}

.department-tab[aria-pressed="true"] {
  background: var(--teal-dark);
  color: white;
}

.sample-card {
  display: grid;
  gap: 12px;
  padding-block: 14px;
  border-top: 1px solid var(--line);
}

.sample-card h3 {
  margin: 0;
  font-size: 15px;
}

.sample-card .help-example-table {
  min-width: 760px;
}

.apply-sample {
  justify-self: start;
}

.select-with-custom,
.jalali-control {
  display: grid;
  gap: 8px;
}

.jalali-selectors {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 6px;
  min-width: 0;
}

.jalali-selectors label {
  display: grid;
  gap: 3px;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}

.jalali-selectors select {
  padding-inline: 6px;
}

.data-table .jalali-control {
  min-width: 240px;
}

.data-table select {
  min-width: 140px;
}

.data-table .jalali-selectors select {
  min-width: 0;
}

.date-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

.date-hint.is-error {
  color: var(--rust);
}

.date-untested {
  justify-self: start;
  font-size: 12px;
  padding: 4px 0;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .step-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .transfer-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .sample-panel {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 680px) {
  .workspace {
    padding: 12px;
  }

  .toolbar,
  .footer-actions,
  .result-header {
    align-items: stretch;
    flex-direction: column;
  }

  .step-list {
    display: flex;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    padding-bottom: 6px;
    scrollbar-width: thin;
  }

  .step-item {
    flex: 0 0 180px;
  }

  .brand {
    margin-bottom: 16px;
  }

  .progress-wrap {
    min-width: 0;
    width: 100%;
  }

  .transfer-panel {
    padding: 14px;
  }

  .transfer-actions > button {
    flex: 1 1 130px;
  }

  .toolbar-actions > button {
    flex: 1;
  }

  .help-modal-header {
    align-items: center;
  }
}
