@font-face {
  font-family: Vazirmatn;
  src: url("/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: Vazirmatn;
  src: url("/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #17325c;
  --muted: #3d5278;
  --paper: #e7edf4;
  --line: #c5d0e0;
  --desk: #d5dce6;
  --danger: #9d1c2b;
  --gold: #f6e3a4;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: Vazirmatn, Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  overflow-x: clip;
}

body.preview-open { overflow: hidden; }

.ribbon {
  height: 6px;
  background: linear-gradient(90deg, #239f46 0 33.33%, #ffffff 33.33% 66.66%, #da1e28 66.66% 100%);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  padding: 22px 28px 8px;
}

.top h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.35;
  font-weight: 700;
}

.top p {
  margin: 4px 0 0;
  color: var(--muted);
  max-width: 42em;
}

nav { display: flex; gap: 8px; }

button, .file-btn {
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--ink);
  background: white;
}

button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.primary { background: var(--ink); color: white; }
.primary:hover { background: #10243f; }
.ghost { background: white; border-color: var(--line); }
button:disabled { opacity: 0.6; cursor: progress; }

#boot { padding: 24px 28px; color: var(--muted); }

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 640px) minmax(280px, 1fr);
  gap: 28px;
  align-items: start;
  padding: 12px 28px 48px;
}

.step-label {
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 700;
}

.block { margin: 0 0 28px; }

.block h2 {
  display: inline-block;
  margin: 0 0 14px;
  padding: 5px 14px;
  background: var(--gold);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
  border-radius: 8px 8px 2px 8px;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  margin-bottom: 12px;
}

.field { margin: 0 0 12px; min-width: 0; }
.row .field { margin: 0; }

fieldset.field {
  border: 0;
  padding: 0;
  margin: 0 0 12px;
}

.row fieldset.field { margin: 0; }

.field-label,
legend {
  display: block;
  margin: 0 0 6px;
  padding: 0;
  font-size: 14px;
  font-weight: 700;
}

.req { color: var(--danger); }

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

input[type="text"],
input[type="tel"],
input[type="url"],
input[type="password"],
input[type="email"],
textarea {
  width: 100%;
  max-width: 100%;
  font: inherit;
  color: inherit;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  min-height: 44px;
}

input[type="file"] { max-width: 100%; font: inherit; }

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.8;
}

.field[data-invalid="true"] input,
.field[data-invalid="true"] textarea {
  border-color: var(--danger);
}

.digits { text-align: center; }

.err {
  margin: 4px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.err:empty { display: none; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }

.choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 44px;
  cursor: pointer;
}

.choice:has(input:checked) {
  background: #e5edf8;
  border-color: var(--ink);
}

.date {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.date label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.date input { width: 76px; }
.date .year input { width: 92px; }

.today {
  height: 42px;
  padding: 8px 12px;
  font-size: 13px;
}

.pad {
  width: 100%;
  height: 150px;
  background: white;
  border: 1px dashed #8ea0b8;
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

.pad-actions, .photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.pad-actions button, .photo-actions button { padding: 8px 12px; font-size: 13px; }

.thumb {
  width: 92px;
  height: 112px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
}

.file-btn input { font: inherit; max-width: 100%; }

.form-col { min-width: 0; }

.actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid #d3ddec;
  z-index: 2;
}

.actions button { min-height: 48px; }

.preview-toggle,
.preview-close { display: none; }

.desk {
  position: sticky;
  top: 16px;
  background: var(--desk);
  border-radius: 16px;
  padding: 14px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}

.tabs button {
  background: transparent;
  border-radius: 999px;
  padding: 6px 14px;
}

.tabs button[aria-selected="true"] {
  background: var(--ink);
  color: white;
}

.sheet {
  width: min(100%, calc((100vh - 150px) * 1055 / 1491));
  aspect-ratio: 1055 / 1491;
  margin-inline: auto;
  background: white;
  box-shadow: 0 10px 28px rgba(16, 36, 63, 0.18);
  overflow: hidden;
}

.sheet.landscape {
  aspect-ratio: 1200 / 896;
  width: min(100%, calc((100vh - 170px) * 1200 / 896));
}

.sheet canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#preview-note {
  margin: 10px 4px 0;
  color: var(--danger);
  font-size: 13px;
}

#preview-note:empty { display: none; }

#status:empty { display: none; }

#status.ok,
#status.bad {
  padding: 10px 12px;
  border-radius: 10px;
  margin: 0 0 14px;
}

#status.ok { background: #e7f3ea; border: 1px solid #b7d7c0; }
#status.bad { background: #fdecee; border: 1px solid #f0c2c6; }

#status a { color: var(--ink); font-weight: 700; }

.done[hidden] { display: none !important; }

.done {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
}

.done p {
  margin: 0;
  max-width: 12em;
  font-size: 28px;
  font-weight: 700;
  text-align: center;
}

.admin {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 28px 48px;
}

.login {
  max-width: 420px;
  margin: 48px auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}

.login h2, .admin h2 { margin: 0 0 14px; font-size: 22px; }

.login label, .admin-tools { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-weight: 700; }

.admin-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 16px;
}

.admin-tools { flex-direction: row; flex-wrap: wrap; margin: 0; font-weight: 400; }

#admin-note { color: var(--muted); min-height: 1.4em; }

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th, td {
  text-align: right;
  padding: 10px 12px;
  border-bottom: 1px solid #d3ddec;
  vertical-align: top;
}

th {
  font-size: 13px;
  color: var(--muted);
}

td a { color: var(--ink); font-weight: 700; }

@media (max-width: 960px) {
  .top {
    padding: max(16px, env(safe-area-inset-top)) 16px 8px;
  }

  .top h1 { font-size: 22px; }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .preview-toggle { display: inline-flex; flex: 1 1 140px; justify-content: center; }

  .desk {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 30;
    border-radius: 0;
    overflow: auto;
    padding: max(12px, env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  }

  .desk.is-open {
    display: flex;
    flex-direction: column;
  }

  .preview-close {
    display: inline-flex;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    margin-bottom: 10px;
  }

  .sheet {
    width: min(100%, calc((100dvh - 150px) * 1055 / 1491));
  }

  .sheet.landscape {
    width: min(100%, calc((100dvh - 170px) * 1200 / 896));
  }

  .pad { height: 200px; }

  .actions button { flex: 1 1 140px; justify-content: center; }

  .login {
    margin: 20px 16px 32px;
    max-width: none;
  }

  .login button { width: 100%; min-height: 48px; }

  .admin { padding: 8px 16px 32px; }

  .admin-bar { align-items: stretch; }

  .admin-tools {
    flex-direction: column;
    width: 100%;
  }

  .admin-tools button { width: 100%; min-height: 48px; }

  #admin-table { overflow-x: auto; }

  table, thead, tbody, tr, th, td { display: block; }

  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

  tr {
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 10px 12px;
  }

  td {
    border: 0;
    padding: 6px 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  td a { display: inline-block; min-height: 44px; line-height: 44px; }
}

@media (max-width: 700px) {
  .row { grid-template-columns: minmax(0, 1fr); }

  .date label { flex: 1 1 72px; min-width: 0; }
  .date input,
  .date .year input { width: 100%; }

  input[type="text"],
  input[type="tel"],
  input[type="url"],
  input[type="password"],
  input[type="email"],
  textarea { font-size: 16px; }

  .done p { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
