:root {
  --ink: #17202a;
  --muted: #617080;
  --line: #d9e1e8;
  --panel: #f6f8fa;
  --paper: #ffffff;
  --accent: #0076b6;
  --accent-strong: #005b91;
  --warm: #f5b942;
  --soft: #e8f4fb;
  --danger: #9f2d2d;
  --danger-soft: #fff1f1;
  --shadow: 0 18px 50px rgba(22, 32, 42, 0.14);
  font-family: Arial, Helvetica, sans-serif;
}

@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("data/fonts/noto-naskh-arabic-regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "Noto Naskh Arabic";
  src: url("data/fonts/noto-naskh-arabic-bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: "Vazir";
  src: url("data/fonts/vazir/16.1.0/Vazir.woff2") format("woff2"),
       url("data/fonts/vazir/16.1.0/Vazir.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: #edf1f4;
}

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

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

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

.brand img {
  width: 118px;
  height: auto;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.print-button {
  min-height: 42px;
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.print-button:hover {
  background: var(--accent-strong);
}

.print-button:disabled {
  background: #9aa8b3;
  cursor: not-allowed;
}

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

.control-panel {
  height: calc(100vh - 72px);
  overflow: auto;
  padding: 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.control-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.capacity-alert {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0 0 14px;
  padding: 11px 12px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #ecc4c4;
  border-left: 5px solid var(--danger);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(159, 45, 45, 0.12);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.capacity-alert.is-flashing {
  animation: capacityPulse 420ms ease;
}

@keyframes capacityPulse {
  0% {
    transform: translateY(-2px);
  }

  100% {
    transform: translateY(0);
  }
}

.control-section:first-child {
  padding-top: 0;
}

.control-section h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.language-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.gender-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.date-shortcuts,
.date-stepper {
  display: grid;
  gap: 8px;
  margin: -4px 0 12px;
}

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

.date-stepper {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.date-shortcuts button,
.date-stepper button {
  min-height: 34px;
  color: var(--accent-strong);
  background: #fff;
  border: 1px solid #cbd6df;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
}

.date-shortcuts button:hover,
.date-stepper button:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 118, 182, 0.1);
}

.date-stepper button:disabled {
  color: #9aa8b3;
  background: #edf1f4;
  border-color: #d9e1e8;
  box-shadow: none;
  cursor: not-allowed;
}

.language-option {
  display: inline-grid;
  place-items: center;
  min-width: 88px;
  height: 34px;
  padding: 0 10px;
  margin: 0;
  background: #fff;
  border: 1px solid #cbd6df;
  border-radius: 7px;
  cursor: pointer;
}

.gender-option {
  display: inline-grid;
  place-items: center;
  height: 36px;
  padding: 0 10px;
  margin: 0;
  color: #263746;
  background: #fff;
  border: 1px solid #cbd6df;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.language-name {
  color: #263746;
  font-size: 12px;
  font-weight: 700;
}

.language-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.gender-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.language-option:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 118, 182, 0.14);
}

.gender-option:has(input:checked) {
  color: var(--accent-strong);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 118, 182, 0.14);
}

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

label {
  display: grid;
  gap: 7px;
  margin: 0 0 12px;
  color: #314253;
  font-size: 13px;
  font-weight: 700;
}

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

textarea {
  resize: vertical;
}

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

.option-card,
.check-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
  margin: 0;
  padding: 10px;
  background: #fff;
  border: 1px solid #d5dee6;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 400;
}

.option-card input,
.check-row input,
.switch-row input {
  width: auto;
  min-height: auto;
  margin-top: 2px;
}

.option-card strong,
.check-row strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 13px;
}

.option-card span,
.check-row span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.compact {
  gap: 6px;
}

.grouped {
  gap: 12px;
}

.option-group {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 10px;
  background: #fff;
  border: 1px solid #d5dee6;
  border-radius: 8px;
}

.option-group legend {
  padding: 0 5px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.option-group .check-row {
  padding: 8px;
  border-color: #edf1f4;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.editable-options {
  display: grid;
  gap: 10px;
}

.editable-option {
  padding: 10px;
  background: #fff;
  border: 1px solid #d5dee6;
  border-radius: 8px;
}

.editable-option textarea {
  min-height: 96px;
  margin-top: 6px;
  font-size: 12px;
}

.preview-zone {
  min-width: 0;
  height: calc(100vh - 72px);
  padding: 18px;
  overflow: auto;
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.preview-toolbar strong {
  color: var(--ink);
  font-size: 15px;
}

.paper-stack {
  display: grid;
  gap: 18px;
  align-content: start;
  justify-items: stretch;
}

.page-frame {
  width: 100%;
  overflow: hidden;
}

.a4-page {
  position: relative;
  width: 297mm;
  height: 210mm;
  padding: 7mm;
  overflow: hidden;
  background: var(--paper);
  box-shadow: var(--shadow);
  transform-origin: top left;
}

.fold-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  height: 100%;
}

.fold-column {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3.2mm;
  min-width: 0;
  padding: 0 4.5mm;
  border-left: 0;
  overflow: hidden;
}

.fold-column + .fold-column::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-left: 1px dashed #c7d2dc;
  content: "";
}

.box-slot {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 3.2mm;
}

.fold-column:first-child {
  padding-left: 0;
}

.location-column {
  padding: 0 4.5mm;
}

.location-column .pinned-location-box {
  flex: 0 0 auto;
}

.cover-stack {
  display: flex;
  flex: 0 0 auto;
  min-height: 0;
  flex-direction: column;
  gap: 3.2mm;
}

.box-pool {
  display: none;
}

.fold-column:last-child {
  padding-right: 0;
}

.brand-cover {
  display: grid;
  justify-items: start;
  gap: 1.8mm;
  padding: 4.4mm;
  background: linear-gradient(180deg, #ffffff 0%, #f3f9fd 100%);
  color: var(--accent-strong);
  border: 1px solid #cfe4f1;
  border-top: 5px solid var(--accent);
  border-radius: 8px;
}

.brand-cover img {
  width: 39mm;
  height: auto;
}

.brand-cover strong {
  font-size: 17pt;
  line-height: 1;
}

.brand-cover span {
  color: #45697f;
  font-size: 9.4pt;
  font-weight: 700;
}

.cover-panel {
  padding: 4.2mm;
  background: var(--soft);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
}

.cover-panel h1 {
  margin: 0 0 2.4mm;
  font-size: 18.5pt;
  line-height: 1.08;
}

.cover-panel p {
  margin: 0;
  color: #405262;
  font-size: 9.5pt;
  line-height: 1.45;
}

.patient-fields {
  display: grid;
  gap: 2mm;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 8pt;
  font-weight: 700;
  text-transform: uppercase;
}

.field-value {
  display: block;
  margin-top: 1mm;
  font-size: 10.5pt;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.brochure-box {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-height: 16mm;
  padding: 2.6mm;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: clip;
  overflow-wrap: anywhere;
}

.brochure-box.grow {
  flex: 0 0 auto;
}

.brochure-box.is-column-filler {
  flex: 1 0 auto;
}

.box-logo {
  margin-top: auto;
  padding-top: 1.5mm;
  text-align: center;
}

.box-logo img {
  display: block;
  width: 14mm;
  height: auto;
  margin: 0 auto;
  opacity: 0.88;
}

.brochure-box h2 {
  margin: 0 0 1.6mm;
  color: var(--accent-strong);
  font-size: 10pt;
}

.brochure-box h3 {
  margin: 0 0 1mm;
  color: #263746;
  font-size: 8.5pt;
}

.brochure-box p,
.brochure-box li {
  color: #334657;
  font-size: 8pt;
  line-height: 1.24;
}

.brochure-box p {
  margin: 0 0 1.5mm;
}

.brochure-box ul {
  margin: 0;
  padding-left: 5mm;
}

.map-placeholder {
  display: grid;
  min-height: 38mm;
  margin: 1.8mm 0;
  padding: 4mm;
  place-items: center;
  color: #45697f;
  background: #eef7fc;
  border: 1px dashed #84b8d5;
  border-radius: 6px;
  font-size: 8pt;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.location-section + .location-section {
  margin-top: 2.2mm;
  padding-top: 2.2mm;
  border-top: 1px solid var(--line);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2mm;
  margin-top: 2mm;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  color: #06466d;
  background: #d7ecf8;
  border-radius: 999px;
  font-size: 8pt;
  font-weight: 700;
}

.alert-box {
  padding: 3mm;
  color: var(--danger);
  background: #fff2f2;
  border: 1px solid #f0c4c4;
  border-radius: 8px;
  font-size: 8.8pt;
  line-height: 1.35;
}

.supplemental-note-box {
  background: #fff8df;
  border-color: #e8c35c;
  border-left: 5px solid var(--warm);
}

.supplemental-note-box h2 {
  color: #7a5600;
}

.review-box {
  display: block;
  text-align: center;
  background: #f7fafb;
}

.review-box h2,
.review-box p {
  text-align: inherit;
}

.review-qr {
  display: block;
  width: 35mm;
  height: 35mm;
  margin: 2mm auto 0;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  padding: 2mm;
  object-fit: contain;
}

.number-token {
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
}

.shaving-guide {
  display: grid;
  grid-template-columns: 1fr 28mm;
  gap: 3mm;
  align-items: center;
  margin-top: 2mm;
  padding: 2.4mm;
  background: #eef7fc;
  border: 1px solid #cfe4f1;
  border-radius: 8px;
}

.shaving-guide strong,
.shaving-guide span {
  display: block;
}

.shaving-guide strong {
  color: var(--accent-strong);
  font-size: 9pt;
}

.shaving-guide span {
  color: #334657;
  font-size: 8.5pt;
  line-height: 1.3;
}

.shaving-guide img {
  width: 28mm;
  height: auto;
}

.a4-page[dir="rtl"] {
  font-family: "Noto Naskh Arabic", Arial, Helvetica, sans-serif;
  text-align: right;
}

article.a4-page[lang="fa"] {
  font-family: "Vazir", "Noto Naskh Arabic", Arial, Helvetica, sans-serif;
}

.a4-page[dir="rtl"] .brochure-box ul {
  padding-right: 5mm;
  padding-left: 0;
}

.a4-page[dir="rtl"] .cover-panel {
  border-right: 5px solid var(--accent);
  border-left: 0;
}

.loading,
.error {
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.error {
  color: var(--danger);
}

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

  .control-panel {
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #brochureForm {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 0 18px;
  }

  .preview-zone {
    height: auto;
  }
}

@media (max-width: 520px) {
  .app-header,
  .preview-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  #brochureForm {
    grid-template-columns: 1fr;
  }

  .preview-zone {
    padding: 12px;
  }
}

@page {
  size: A4 landscape;
  margin: 0;
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .control-panel,
  .preview-toolbar {
    display: none;
  }

  .app-shell,
  .preview-zone,
  .paper-stack,
  .page-frame {
    display: block;
    width: auto;
    height: auto !important;
    padding: 0;
    margin: 0;
    overflow: visible;
  }

  .a4-page {
    width: 297mm;
    height: 210mm;
    transform: none !important;
    margin: 0;
    box-shadow: none;
    page-break-after: always;
    break-after: page;
  }
}
