/* Avalon Offer Sign — спільні стилі.
   Ідея: «папір і чорнило». Інтерфейс тихий і сірий, колір мають лише
   чорнила сторін: синє для компанії, зелене для працівника. */

/* Палітра з оргструктури Авалону: графіт логотипу, темно-синій,
   сіро-блакитний блоків і фіолетовий пунктир відділів. */
:root {
  color-scheme: light;
  --brand: #3A4449;
  --on-brand: #FFFFFF;
  --on-brand-muted: #C3CBD2;
  --paper: #EDF0F4;
  --sheet: #FFFFFF;
  --ink: #2B333D;
  --heading: #333F50;
  --muted: #5F6670;
  --line: #D9DFE7;
  --line-strong: #B9C4D2;
  --steel: #8497B0;
  --on-steel: #FFFFFF;
  --primary: #333F50;
  --on-primary: #FFFFFF;
  --company: #333F50;
  --company-wash: #E3E8EF;
  --employee: #603790;
  --employee-wash: #EFE8F6;
  --ok: #00873E;
  --ok-dot: #00B050;
  --ok-wash: #E1F4E8;
  --info: #2F5AA8;
  --info-wash: #E5ECF8;
  --danger: #C81F1F;
  --danger-wash: #FBE9E9;
  --focus: #4472C4;
  --radius: 4px;
  --topbar-h: 54px;
  --tap: 44px;
  --shadow: 0 1px 2px rgba(51, 63, 80, 0.08), 0 8px 24px rgba(51, 63, 80, 0.10);
  --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --hand: "Caveat", "Segoe Script", cursive;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --brand: #2F373B;
    --on-brand-muted: #A9B3BC;
    --paper: #22282C;
    --sheet: #2C3338;
    --ink: #E6EAEF;
    --heading: #F0F3F6;
    --muted: #A3ACB6;
    --line: #3E474D;
    --line-strong: #56616A;
    --steel: #4B5A6E;
    --primary: #A9B9D0;
    --on-primary: #1B2228;
    --company: #A9B9D0;
    --company-wash: #34404E;
    --employee: #C1A6E4;
    --employee-wash: #3B2D4E;
    --ok: #5FD394;
    --ok-dot: #3CC97D;
    --ok-wash: #1A3A29;
    --info: #9DB8EC;
    --info-wash: #243352;
    --danger: #FF8E8E;
    --danger-wash: #3F2020;
    --focus: #9DB8EC;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, canvas { max-width: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}
@media (max-width: 600px) { body { font-size: 16px; } }

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; color: var(--heading); }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--info); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.topbar :focus-visible { outline-color: #FFFFFF; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Верхня панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  min-height: var(--topbar-h);
  padding: 10px clamp(16px, 4vw, 40px);
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left, 0px));
  padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right, 0px));
  background: var(--brand); color: var(--on-brand);
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--on-brand); }
.brand-logo { display: block; height: 34px; width: auto; }
.brand-sub {
  color: var(--on-brand-muted); font-size: 0.9rem; padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.22); line-height: 1.2;
}
.topbar .spacer { flex: 1; }
.user { color: var(--on-brand-muted); font-size: 0.875rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn-quiet { color: var(--on-brand-muted); }
.topbar .btn-quiet:hover { color: var(--on-brand); }
@media (max-width: 520px) { .brand-sub { display: none; } .user { display: none; } }

/* ---------- Кнопки й поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--sheet); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
  text-align: center; line-height: 1.25; touch-action: manipulation;
}
@media (prefers-reduced-motion: no-preference) {
  .btn { transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, filter 150ms ease; }
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { border-color: var(--primary); filter: brightness(1.15); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 0.875rem; }
/* Сенсорні екрани: кожна ціль щонайменше 44 px */
@media (pointer: coarse) {
  :root { --topbar-h: 64px; }
  .btn, .btn-sm { min-height: var(--tap); }
  .btn-sm { padding: 6px 14px; }
}

label.field { display: grid; gap: 6px; font-size: 0.875rem; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--sheet); color: var(--ink); font: inherit; font-size: 15px;
}
/* 16 px на телефонах, щоб iOS не збільшував сторінку під час введення */
@media (max-width: 600px), (pointer: coarse) {
  .input, textarea.input, select.input { font-size: 16px; min-height: var(--tap); }
}
textarea.input { min-height: 88px; resize: vertical; }
.input:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.9rem; cursor: pointer; }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
@media (pointer: coarse) {
  .check { padding: 8px 0; }
  .check input { width: 22px; height: 22px; margin-top: 1px; }
}

.hint { color: var(--muted); font-size: 0.85rem; }
.error-box {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--danger-wash); color: var(--danger); font-size: 0.9rem;
}
.error-box:empty { display: none; }

/* ---------- Статуси ---------- */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 500; white-space: nowrap;
  background: var(--paper); color: var(--muted); border: 1px solid var(--line);
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-in_progress { color: var(--info); background: var(--info-wash); border-color: transparent; }
.status-completed { color: var(--ok); background: var(--ok-wash); border-color: transparent; }
.status-completed::before { background: var(--ok-dot); }
.status-cancelled { color: var(--muted); }
.status-finalize_failed, .status-finalizing { color: var(--danger); background: var(--danger-wash); border-color: transparent; }

/* ---------- PDF ---------- */
.pdf-pages { display: grid; gap: 20px; justify-items: center; }
.pdf-page {
  position: relative; width: 100%; background: #fff;
  box-shadow: var(--shadow); border-radius: 2px;
  touch-action: pan-x pan-y pinch-zoom;
}
.pdf-page canvas { display: block; width: 100%; height: auto; border-radius: 2px; }
.pdf-page-num {
  position: absolute; left: -2px; top: -22px; font-size: 0.75rem; color: var(--muted);
}
.pdf-loading { padding: 64px 0; text-align: center; color: var(--muted); }

/* Поле підпису: колір = чорнило сторони */
.sig-field {
  position: absolute;
  border: 2px dashed var(--field-color);
  background: color-mix(in srgb, var(--field-wash) 85%, transparent);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  color: var(--field-color); font-size: clamp(10px, 1.6vw, 13px); font-weight: 600;
  text-align: center; line-height: 1.2; padding: 2px;
  user-select: none;
}
.sig-field[data-role="company"] { --field-color: var(--company); --field-wash: var(--company-wash); }
.sig-field[data-role="employee"] { --field-color: var(--employee); --field-wash: var(--employee-wash); }
.sig-field.is-muted { opacity: 0.5; border-style: dotted; }
.sig-field.is-filled { border-style: solid; background: transparent; border-color: transparent; }
.sig-field img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Діалог ---------- */
dialog {
  border: none; border-radius: 10px; padding: 0;
  width: min(560px, calc(100vw - 24px)); max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--sheet); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(18, 22, 28, 0.55); }
/* Поки відкрито діалог, сторінка під ним не прокручується */
html:has(dialog[open]) { overflow: hidden; }
.dialog-body { padding: 24px; display: grid; gap: 18px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 520px) {
  dialog { width: calc(100vw - 16px); max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .dialog-body { padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px)); gap: 16px; }
  .dialog-actions { flex-direction: column-reverse; align-items: stretch; }
  .dialog-actions .btn { width: 100%; min-height: var(--tap); }
}

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--brand); color: #fff; padding: 10px 18px; border-radius: var(--radius);
  font-size: 0.9rem; z-index: 100; box-shadow: var(--shadow);
  width: max-content; max-width: calc(100vw - 32px); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 180ms ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
}
