/* ============================================================
   TOKENS — light (bare :root), then dark via media + [data-theme]
   ============================================================ */
:root {
  --floor: #E7EBEC;          /* the grey worktable the sheets sit on */
  --floor-line: #D3D9DB;
  --sheet: #FFFFFF;          /* paper itself — always white, like real paper */
  --sheet-line: #DEE2E3;
  --ink: #17212B;            /* proof-ink blue-black, not pure black */
  --ink-soft: #4A5560;
  --muted: #77828C;
  --accent: #C9432F;         /* registration-mark red */
  --accent-ink: #FFFFFF;
  --accent-2: #2F7B6B;       /* proof-cyan/teal, used sparingly */
  --danger: #C9432F;
  --rail-bg: #17212B;
  --rail-ink: #C7D0D6;
  --rail-ink-dim: #6E7A84;
  --shadow-sheet: 0 1px 2px rgba(23,33,43,0.06), 0 12px 28px rgba(23,33,43,0.10);
  --shadow-soft: 0 4px 12px rgba(23,33,43,0.08);
  --font-display: 'Barlow Semi Condensed', system-ui, sans-serif;
  --font-body: 'Karla', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius-sm: 4px;
  --radius-md: 7px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --floor: #0E1318;
    --floor-line: #1C242B;
    --sheet: #1B232B;
    --sheet-line: #2B353E;
    --ink: #E7ECEE;
    --ink-soft: #B7C1C8;
    --muted: #7C8790;
    --accent: #E2604A;
    --accent-ink: #17212B;
    --accent-2: #4FA695;
    --danger: #E2604A;
    --rail-bg: #0A0D11;
    --rail-ink: #B7C1C8;
    --rail-ink-dim: #4F5960;
    --shadow-sheet: 0 1px 2px rgba(0,0,0,0.4), 0 14px 32px rgba(0,0,0,0.5);
    --shadow-soft: 0 4px 14px rgba(0,0,0,0.4);
  }
}
:root[data-theme="dark"] {
  --floor: #0E1318;
  --floor-line: #1C242B;
  --sheet: #1B232B;
  --sheet-line: #2B353E;
  --ink: #E7ECEE;
  --ink-soft: #B7C1C8;
  --muted: #7C8790;
  --accent: #E2604A;
  --accent-ink: #17212B;
  --accent-2: #4FA695;
  --danger: #E2604A;
  --rail-bg: #0A0D11;
  --rail-ink: #B7C1C8;
  --rail-ink-dim: #4F5960;
  --shadow-sheet: 0 1px 2px rgba(0,0,0,0.4), 0 14px 32px rgba(0,0,0,0.5);
  --shadow-soft: 0 4px 14px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* `hidden` atributi doim g'olib chiqsin — pastda .panel, .sig-modal va
   boshqa ko'p joyda `display: flex/grid` qoidasi bor, ular attributdan
   ko'ra kuchliroq bo'lib, elementni "hidden" bo'lsa ham ko'rsatib
   qo'yishi mumkin edi. */
[hidden] { display: none !important; }
body {
  background: var(--floor);
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.005em; text-wrap: balance; margin: 0; }
::selection { background: var(--accent); color: var(--accent-ink); }

.workshop {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- Rail (tool pegboard) ---------- */
.rail {
  background: var(--rail-bg);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 20px;
  color: #fff;
}
.rail-brand-mark {
  font-size: 1.5rem;
  color: var(--accent);
  transform: scaleX(-1) rotate(180deg);
  line-height: 1;
}
.rail-brand-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.15;
  letter-spacing: 0.01em;
}
.rail-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border: none;
  background: transparent;
  color: var(--rail-ink-dim);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.86rem;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.rail-btn svg { width: 19px; height: 19px; flex: none; }
.rail-btn:hover { color: var(--rail-ink); background: rgba(255,255,255,0.05); }
.rail-btn.is-active { color: #fff; background: rgba(201,67,47,0.18); }
.rail-btn.is-active svg { color: var(--accent); }

/* ---------- Floor / panels ---------- */
.floor { padding: clamp(20px, 4vw, 48px); }
.panel { max-width: 880px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.panel-head { display: flex; flex-direction: column; gap: 8px; padding-bottom: 4px; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}
.panel-head h1 { font-size: clamp(1.5rem, 3vw, 1.95rem); }
.panel-sub { margin: 0; color: var(--muted); max-width: 62ch; line-height: 1.5; }

/* Muhim cheklovni tushuntiruvchi eslatma — accent chiziq bilan ajratilgan,
   ogohlantirish rangisiz (bu xato emas, PDF formatining o'zi shunday) */
.callout {
  border-left: 3px solid var(--accent);
  background: var(--sheet);
  border-top: 1px solid var(--sheet-line); border-right: 1px solid var(--sheet-line); border-bottom: 1px solid var(--sheet-line);
  padding: 12px 16px;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 68ch;
}
.callout strong { color: var(--ink); }

/* ---------- Dropzone (a sheet with crop-mark corners) ---------- */
.dropzone {
  position: relative;
  background: var(--sheet);
  border: 1px solid var(--sheet-line);
  box-shadow: var(--shadow-sheet);
  padding: 8px;
}
.dropzone.is-dragover { outline: 2px solid var(--accent); outline-offset: -2px; }
.dropzone-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 40px 20px;
  cursor: pointer;
  color: var(--ink-soft);
}
.dropzone-body svg { width: 30px; height: 30px; color: var(--accent); }
.dropzone-body strong { color: var(--ink); font-weight: 700; }
.dropzone-body small { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }

/* crop / registration marks — a real print-proof motif, not decoration:
   they mark the corners of the "sheet" the way a printer's proof does */
.crop-tick { position: absolute; width: 14px; height: 14px; pointer-events: none; }
.crop-tick::before, .crop-tick::after { content: ""; position: absolute; background: var(--sheet-line); }
.crop-tick::before { width: 100%; height: 1px; }
.crop-tick::after { width: 1px; height: 100%; }
.crop-tick.tl { top: -1px; left: -1px; }
.crop-tick.tr { top: -1px; right: -1px; }
.crop-tick.bl { bottom: -1px; left: -1px; }
.crop-tick.br { bottom: -1px; right: -1px; }
.crop-tick.tl::before, .crop-tick.tl::after { top: 0; left: 0; }
.crop-tick.tr::before { top: 0; right: 0; } .crop-tick.tr::after { top: 0; right: 0; }
.crop-tick.bl::before { bottom: 0; left: 0; } .crop-tick.bl::after { bottom: 0; left: 0; }
.crop-tick.br::before { bottom: 0; right: 0; } .crop-tick.br::after { bottom: 0; right: 0; }

/* ---------- File list (merge / create-images order) ---------- */
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.file-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--sheet); border: 1px solid var(--sheet-line);
  padding: 10px 12px; box-shadow: var(--shadow-soft);
  cursor: grab;
}
.file-row.dragging { opacity: 0.4; }
.file-row-index { font-family: var(--font-mono); font-size: 0.76rem; color: var(--muted); width: 20px; flex: none; }
.file-row-thumb { width: 34px; height: 44px; object-fit: cover; border: 1px solid var(--sheet-line); flex: none; background: var(--floor); }
.file-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.88rem; }
.file-row-size { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.file-row-remove {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: 2px 4px; flex: none;
}
.file-row-remove:hover { color: var(--danger); }

/* ---------- Thumb grid (split / to-image page previews) ---------- */
.split-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip-btn {
  font-family: var(--font-body); font-weight: 600; font-size: 0.8rem;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--sheet-line); background: var(--sheet); color: var(--ink-soft);
  cursor: pointer;
}
.chip-btn:hover { color: var(--ink); border-color: var(--accent); }
.field-inline { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); }
.field-inline select {
  font-family: var(--font-body); font-size: 0.84rem; padding: 6px 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--sheet-line); background: var(--sheet); color: var(--ink);
}
.hint-text { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; }
.thumb-card {
  background: var(--sheet); border: 1px solid var(--sheet-line); box-shadow: var(--shadow-soft);
  padding: 6px 6px 8px; cursor: pointer; user-select: none;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  transition: box-shadow 0.15s ease;
}
.thumb-card canvas, .thumb-card img { width: 100%; height: auto; display: block; border: 1px solid var(--sheet-line); }
.thumb-card.is-selected { box-shadow: 0 0 0 2px var(--accent), var(--shadow-soft); }
.thumb-card-label { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.thumb-check {
  width: 14px; height: 14px; border-radius: 3px; border: 1.4px solid var(--sheet-line);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.thumb-card.is-selected .thumb-check { background: var(--accent); border-color: var(--accent); color: #fff; }
.thumb-card.is-selected .thumb-check::after { content: "✓"; font-size: 10px; }

/* ---------- Subtabs (create / word modes) ---------- */
.subtabs { display: flex; gap: 6px; border-bottom: 1px solid var(--floor-line); padding-bottom: 0; }
.subtab-btn {
  font-family: var(--font-display); font-weight: 600; font-size: 0.92rem;
  padding: 9px 4px; margin-bottom: -1px;
  border: none; border-bottom: 2px solid transparent; background: none; color: var(--muted);
  cursor: pointer;
}
.subtab-btn + .subtab-btn { margin-left: 14px; }
.subtab-btn.is-active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Form fields (create-from-text) ---------- */
.field-block { display: flex; flex-direction: column; gap: 6px; font-size: 0.84rem; color: var(--muted); font-weight: 600; }
.field-block input[type="text"], .field-block textarea {
  font-family: var(--font-body); font-size: 0.95rem; color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--sheet-line); background: var(--sheet);
  border-radius: var(--radius-sm); resize: vertical;
}
.field-block input[type="text"]:focus, .field-block textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fine-print { font-size: 0.78rem; color: var(--muted); margin: 0; }

/* ---------- Actions / buttons ---------- */
.panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding-top: 4px; }
.btn-primary {
  font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.01em;
  padding: 11px 22px; border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { background: var(--sheet-line); color: var(--muted); cursor: not-allowed; }

/* ---------- Annotate workspace ---------- */
.annotate-workspace { display: flex; flex-direction: column; gap: 12px; }
.annotate-toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  background: var(--sheet); border: 1px solid var(--sheet-line); padding: 8px 10px; box-shadow: var(--shadow-soft);
}
.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-btn, .icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid var(--sheet-line); background: var(--sheet); color: var(--ink-soft);
  border-radius: var(--radius-sm); cursor: pointer;
}
.tool-btn svg { width: 16px; height: 16px; }
.tool-btn.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.icon-btn { font-family: var(--font-display); font-size: 1rem; }
.icon-btn:hover, .tool-btn:hover:not(.is-active) { border-color: var(--accent); color: var(--ink); }
.page-indicator { font-family: var(--font-mono); font-size: 0.82rem; color: var(--muted); padding: 0 4px; font-variant-numeric: tabular-nums; }

.annotate-stage-wrap { background: var(--floor); border: 1px solid var(--floor-line); padding: 20px; display: flex; justify-content: center; overflow: auto; }
.annotate-stage { position: relative; box-shadow: var(--shadow-sheet); background: #fff; }
.annotate-stage canvas { display: block; }
.annotate-runs { position: absolute; inset: 0; z-index: 1; }
.annotate-overlay { position: absolute; inset: 0; z-index: 2; }

/* PDF ichidan avtomatik aniqlangan matn qatorlari — sichqoncha
   olib borilganda ko'rinadi, bosilganda tahrirlashga o'tadi */
.text-run {
  position: absolute;
  cursor: text;
  border-radius: 2px;
  border: 1px dashed transparent;
}
.text-run:hover { border-color: var(--accent-2); background: rgba(47,123,107,0.08); }
.text-run.is-edited { border-style: solid; border-color: var(--accent); background: #fff; }
.text-run-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: none; padding: 0; margin: 0; background: #fff; color: #17212B;
  font-family: 'Karla', sans-serif; line-height: 1;
}
.ann-item {
  position: absolute; cursor: move; user-select: none;
  border: 1px dashed transparent;
}
.ann-item:hover, .ann-item.is-active { border-color: var(--accent); }
.ann-item.text-item {
  font-family: 'Karla', sans-serif; color: #17212B; min-width: 24px; min-height: 1.2em;
  padding: 1px 3px; outline: none; white-space: pre-wrap;
}
.ann-item.cover-item { background: #fff; }
.ann-item img { display: block; width: 100%; height: 100%; pointer-events: none; }
.ann-item-del {
  position: absolute; top: -10px; right: -10px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--danger); color: #fff; border: none;
  font-size: 11px; line-height: 1; cursor: pointer; display: none; place-items: center;
}
.ann-item:hover .ann-item-del, .ann-item.is-active .ann-item-del { display: grid; }
.ann-item .resize-handle {
  position: absolute; right: -5px; bottom: -5px; width: 11px; height: 11px;
  background: var(--accent); border: 1.5px solid #fff; border-radius: 50%; cursor: nwse-resize; display: none;
}
.ann-item:hover .resize-handle, .ann-item.is-active .resize-handle { display: block; }

/* ---------- Signature modal ---------- */
.sig-modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(23,33,43,0.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.sig-card { background: var(--sheet); box-shadow: var(--shadow-sheet); padding: 22px; max-width: 520px; width: 100%; }
.sig-card h3 { font-size: 1.1rem; margin-bottom: 14px; }
.sig-card canvas { width: 100%; height: auto; border: 1px dashed var(--sheet-line); background: #fff; touch-action: none; cursor: crosshair; }
.sig-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 10px; flex-wrap: wrap; }
.sig-actions-right { display: flex; gap: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 70; transform: translate(-50%, 16px);
  background: var(--ink); color: var(--floor); padding: 10px 18px; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 0.86rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(90vw, 420px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .workshop { grid-template-columns: 1fr; }
  .rail {
    position: sticky; top: 0; height: auto; width: 100%;
    /* min-width:0 shart — grid katakchasi standart bo'yicha o'z
       tarkibi kengligidan kichrayolmaydi, shuning uchun overflow-x:auto
       ishlamay, butun sahifani yon tomonga cho'zib yuborardi. */
    min-width: 0;
    flex-direction: row; align-items: center; overflow-x: auto; overflow-y: visible;
    padding: 10px 12px; gap: 2px; z-index: 20;
  }
  .rail-brand { display: none; }
  .rail-btn { flex-direction: column; gap: 4px; padding: 8px 10px; font-size: 0.68rem; white-space: nowrap; }
}
@media (max-width: 480px) {
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}
