@font-face {
  font-family: "Plex Arabic";
  src: url("../fonts/IBMPlexSansArabic-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../fonts/IBMPlexSansArabic-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../fonts/IBMPlexSansArabic-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("../fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("../fonts/IBMPlexMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #17232b;
  --muted: #6d655a;
  --paper: #e4ddd0;
  --sheet: #fffaf3;
  --field: #ffffff;
  --line: #ddd4c6;
  --inkwell: #0f3d44;
  --inkwell-2: #16545c;
  --copper: #b15d32;
  --danger: #9a2f2f;
  --ok: #2f6a4a;
  --focus: #0f3d44;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 1px 0 rgba(23, 35, 43, 0.04), 0 18px 40px rgba(23, 35, 43, 0.07);
  --shadow-dd: 0 12px 32px rgba(23, 35, 43, 0.16);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(23, 35, 43, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 35, 43, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: "Plex Arabic", "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible {
  outline: 2px solid var(--inkwell);
  outline-offset: 2px;
}

.app {
  width: min(1120px, calc(100% - 28px));
  margin: 28px auto 64px;
}

.mast {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 4px 18px;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--inkwell);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.mast h1 {
  margin: 0 0 8px;
  max-width: 34ch;
  font-size: clamp(1.35rem, 2.6vw, 1.85rem);
  font-weight: 600;
  line-height: 1.35;
  text-wrap: balance;
}
.lede { margin: 0; color: var(--muted); font-size: 14.5px; max-width: 52ch; }
.mast-meta {
  flex: 0 0 auto;
  min-width: 148px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--inkwell);
  color: #f4efe6;
  text-align: center;
}
.mast-meta .k { font-size: 11px; opacity: 0.72; }
.mast-meta .v {
  margin-top: 4px;
  font-family: "Plex Mono", ui-monospace, monospace;
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.mast-meta .s { margin-top: 6px; font-size: 12px; color: #e7c4a6; }

.progress {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 0 0 18px;
}
.progress i {
  display: block;
  height: 4px;
  border-radius: 99px;
  background: #cfc6b6;
}
.progress i.is-on { background: var(--inkwell); }
.progress i.is-now { background: var(--copper); }

.layout {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.dossier {
  position: sticky;
  top: 16px;
  padding: 8px;
  border-radius: var(--radius-lg);
  background: rgba(255, 250, 243, 0.72);
  box-shadow: var(--shadow);
}
.dossier button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: right;
  color: var(--muted);
}
.dossier button:hover { background: rgba(15, 61, 68, 0.06); color: var(--ink); }
.dossier button[aria-current="step"] {
  background: var(--inkwell);
  color: #f6f1e8;
}
.dossier-n {
  font-family: "Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.sheet {
  overflow: visible;
  min-height: 520px;
  padding: 28px 28px 22px;
  border-radius: var(--radius-lg);
  background: var(--sheet);
  box-shadow: var(--shadow);
}
.sheet h2 {
  margin: 0 0 6px;
  font-size: 1.28rem;
  text-wrap: balance;
}
.sheet-lead { margin: 0 0 22px; color: var(--muted); font-size: 14.5px; }
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 16px;
  overflow: visible;
}
.grid.full { grid-template-columns: 1fr; }
.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; overflow: visible; }
.field label, .field > span:first-child {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}
.req::after { content: " *"; color: var(--copper); }
.control {
  min-height: 46px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  padding: 10px 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition-property: border-color, box-shadow;
  transition-duration: 160ms;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
.control:hover { border-color: #c9bfb0; }
.control:focus {
  border-color: var(--inkwell);
  box-shadow: 0 0 0 3px rgba(15, 61, 68, 0.12);
}
.field-error { margin: 0; color: var(--danger); font-size: 13px; }
.field.is-invalid .control,
.field.is-invalid .dd-trigger { border-color: var(--danger); }

.dd { position: relative; }
.dd-trigger {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  text-align: right;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition-property: border-color, box-shadow;
  transition-duration: 160ms;
}
.dd-trigger:hover { border-color: #c9bfb0; }
.dd.is-open .dd-trigger,
.dd-trigger:focus {
  border-color: var(--inkwell);
  box-shadow: 0 0 0 3px rgba(15, 61, 68, 0.12);
}
.dd-trigger .dd-value { flex: 1; color: var(--ink); }
.dd-trigger.is-empty .dd-value { color: #9a9186; }
.dd-caret {
  width: 10px;
  height: 10px;
  border-inline-end: 1.6px solid var(--inkwell);
  border-bottom: 1.6px solid var(--inkwell);
  transform: rotate(45deg) translateY(-2px);
  opacity: 0.7;
}
.dd.is-open .dd-caret { transform: rotate(225deg) translateY(1px); }

.dd-panel {
  display: none;
  position: fixed;
  z-index: 80;
  flex-direction: column;
  max-height: min(280px, 50vh);
  padding: 8px;
  border-radius: 14px;
  background: #fffaf3;
  box-shadow: var(--shadow-dd);
}
.dd.is-open .dd-panel { display: flex; }
.dd-search {
  width: 100%;
  min-height: 40px;
  margin-bottom: 6px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.dd-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
}
.dd-list li { margin: 0; }
.dd-list button {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: right;
}
.dd-list button:hover,
.dd-list button.is-active,
.dd-list button[aria-selected="true"] { background: rgba(15, 61, 68, 0.08); }
.dd-empty { padding: 10px; color: var(--muted); font-size: 13px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 46px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
}
.chip[aria-pressed="true"] {
  border-color: var(--inkwell);
  background: var(--inkwell);
  color: #f4efe6;
}

.block { margin-top: 28px; }
.block h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--inkwell);
}
.rows { display: flex; flex-direction: column; gap: 12px; }
.card {
  overflow: visible;
  padding: 16px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-family: "Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  color: var(--muted);
}

.linkish, .ghost, .primary, .danger {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  transition-property: transform, background-color, border-color, color;
  transition-duration: 140ms;
}
.primary {
  border-color: var(--inkwell);
  background: var(--inkwell);
  color: #f6f1e8;
}
.primary:hover { background: var(--inkwell-2); }
.danger {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}
.ghost { background: transparent; }
.ghost:hover, .danger:hover { background: rgba(23, 35, 43, 0.05); }
.primary:active, .ghost:active, .danger:active { transform: scale(0.96); }

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.save-state { font-size: 13px; color: var(--ok); min-height: 1.4em; }
.sig-wrap {
  overflow: hidden;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.sig-wrap canvas { display: block; width: 100%; height: 140px; touch-action: none; }
.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 14px;
  border-radius: 14px;
  background: #f4efe4;
}
.check input { width: 20px; height: 20px; margin-top: 3px; accent-color: var(--inkwell); }
.review { display: grid; gap: 10px; }
.review section {
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.review h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.review p { margin: 0; font-size: 14.5px; }
.banner {
  margin-top: 8px;
  padding: 18px 18px;
  border-radius: 14px;
  background: #e7f3ea;
  color: var(--ok);
}
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 168px;
  padding: 24px 18px;
  border: 1.5px dashed #c4b8a6;
  border-radius: 16px;
  background: #fff;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition-property: border-color, background-color, box-shadow;
  transition-duration: 160ms;
}
.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--inkwell);
  background: #f7f3ea;
}
.dropzone.is-over {
  border-color: var(--inkwell);
  background: #eaf3f2;
  box-shadow: 0 0 0 3px rgba(15, 61, 68, 0.1);
}
.dropzone strong { color: var(--ink); font-weight: 600; }
.dropzone small { font-size: 12.5px; }
.dropzone input { display: none; }
.file-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.file-thumb {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  overflow: hidden;
  border-radius: 8px;
  background: #efe8db;
  outline: 1px solid rgba(0, 0, 0, 0.08);
  outline-offset: -1px;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-meta { flex: 1; min-width: 0; }
.file-meta b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { color: var(--muted); font-size: 12.5px; }

.titleblock {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 4px 8px;
}
.titleblock-main { flex: 1; }
.titleblock h1 {
  margin: 0 0 8px;
  font-size: clamp(1.25rem, 2.4vw, 1.7rem);
  font-weight: 600;
  text-wrap: balance;
}
.plate {
  min-width: 148px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--inkwell);
  color: #f4efe6;
  text-align: center;
}
.plate-k { font-size: 11px; opacity: 0.72; }
.plate-v {
  margin-top: 4px;
  font-family: "Plex Mono", ui-monospace, monospace;
  font-size: 14px;
}
.plate-step { margin-top: 6px; font-size: 12px; color: #e7c4a6; }

.admin-login {
  width: min(400px, calc(100% - 24px));
  margin: 14vh auto;
  padding: 28px;
  border-radius: var(--radius-lg);
  background: var(--sheet);
  box-shadow: var(--shadow);
}
.table-wrap {
  overflow: auto;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
table.data { width: 100%; border-collapse: collapse; min-width: 720px; }
table.data th, table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}
table.data th { background: var(--inkwell); color: #f6f1e8; font-weight: 500; }
table.data tr:hover td { background: #f7f3ea; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}
.detail { margin-top: 18px; }
.attach-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

@media (max-width: 860px) {
  .app { width: min(100% - 16px, 1120px); margin-top: 16px; }
  .mast { flex-direction: column; align-items: stretch; }
  .mast-meta { width: 100%; }
  .layout { grid-template-columns: 1fr; }
  .dossier {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
  .sheet { padding: 20px 16px 16px; }
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .actions { flex-direction: column-reverse; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
