/* Základ: reset, typografie a sdílené komponenty (tlačítka, pole, menu, dialogy, toasty). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg, canvas, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
/* Viditelný fokus: obrys (funguje i v režimu vysokého kontrastu), pole formulářů mají vlastní rámeček */
:where(button, a, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:where(input, select, textarea):focus-visible { outline: none; box-shadow: var(--focus-ring); }
@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; }
}
a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 var(--sp-3); letter-spacing: -0.01em; }
p { margin: 0 0 var(--sp-3); }
[hidden] { display: none !important; }

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

/* Ikony ze sprite (Lucide) */
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.85;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

/* ---------- Tlačítka ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 38px; padding: 0 var(--sp-4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  user-select: none; -webkit-user-select: none;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgb(37 99 235 / 0.25); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-lg { height: 50px; padding: 0 var(--sp-6); font-size: 16px; border-radius: var(--r-lg); }
.btn-sm { height: 32px; padding: 0 var(--sp-3); font-size: 13px; border-radius: var(--r-sm); }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-block { width: 100%; }

/* ---------- Formulářové prvky ---------- */
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 var(--sp-3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.textarea { height: auto; min-height: 90px; padding: var(--sp-2) var(--sp-3); resize: vertical; line-height: 1.45; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px;
}
.field { display: grid; gap: 6px; margin-bottom: var(--sp-4); }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.hint { font-size: 13px; color: var(--text-3); }
.check { display: flex; align-items: center; gap: var(--sp-2); font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.check:has(input:disabled) { opacity: 0.55; cursor: default; }

/* Segmentový přepínač */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: var(--r-md); }
.seg > button {
  border: 0; background: transparent; border-radius: 7px; height: 32px; padding: 0 var(--sp-3);
  font-size: 13px; font-weight: 600; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px;
}
.seg > button[aria-pressed="true"], .seg > button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Klávesové zkratky */
kbd {
  font-family: var(--font-mono); font-size: 12px; padding: 1px 6px; min-width: 22px; display: inline-block; text-align: center;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); color: var(--text-2);
}

/* ---------- Plovoucí menu (popover) ---------- */
.menu {
  position: fixed; z-index: 1000; min-width: 200px; max-width: min(320px, calc(100vw - 16px));
  padding: 6px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur) var(--ease);
}
.menu-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  padding: 8px 10px; border: 0; background: transparent; border-radius: var(--r-sm);
  font-size: 14px; text-align: left; color: var(--text);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); box-shadow: none; }
.menu-item:focus-visible { outline-offset: -2px; }
.menu-item .icon { color: var(--text-2); }
.menu-item[aria-checked="true"] { color: var(--accent-text); font-weight: 600; }
.menu-item[aria-checked="true"] .icon { color: var(--accent); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .icon { color: var(--danger); }
.menu-item .kbd { margin-left: auto; font-size: 12px; color: var(--text-3); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-label { padding: 6px 10px 2px; font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Dialogy (<dialog>) ---------- */
dialog.dlg {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--r-xl);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.dlg[open] { display: flex; flex-direction: column; animation: dlg-in var(--dur-slow) var(--ease); }
dialog.dlg::backdrop { background: var(--overlay-bg); backdrop-filter: blur(2px); animation: fade-in var(--dur) var(--ease); }
dialog.dlg.dlg-wide { width: min(760px, calc(100vw - 24px)); }
.dlg-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-6) var(--sp-3); }
.dlg-head h2 { font-size: 20px; margin: 0; flex: 1; }
.dlg-body { padding: var(--sp-2) var(--sp-6) var(--sp-4); overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-4) var(--sp-6) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); }
.dlg-foot .spacer { flex: 1; }

/* ---------- Toasty ---------- */
.toasts {
  position: fixed; z-index: 2000; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: grid; gap: var(--sp-2); width: min(440px, calc(100vw - 24px)); pointer-events: none;
}
/* nad modálním dialogem (ui/toast.js): popover bez výchozího vzhledu prohlížeče */
.toasts[popover] { inset: auto; top: auto; right: auto; left: 50%; bottom: 20px; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; height: auto; }
.toasts[popover]:not(:popover-open) { display: grid; }
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: 12px 14px;
  background: #0f172a; color: #f8fafc; border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  font-size: 14px; pointer-events: none; animation: toast-in var(--dur-slow) var(--ease);
}
.toast .icon { margin-top: 1px; }
.toast.success .icon { color: #4ade80; }
.toast.error .icon { color: #f87171; }
.toast.warning .icon { color: #fbbf24; }
.toast .toast-msg { flex: 1; }
.toast .toast-action { background: transparent; border: 0; color: #93c5fd; font-weight: 600; padding: 0 2px; pointer-events: auto; }
.toast .toast-close { display: grid; place-items: center; width: 24px; height: 24px; margin: -2px -4px -2px 0; padding: 0; border: 0; border-radius: 6px; background: transparent; color: inherit; opacity: 0.7; pointer-events: auto; }
.toast .toast-close:hover { opacity: 1; background: rgb(255 255 255 / 0.12); }
:root[data-theme="dark"] .toast .toast-close:hover { background: rgb(0 0 0 / 0.08); }
.toast.leaving { animation: toast-out var(--dur) var(--ease) forwards; }
:root[data-theme="dark"] .toast { background: #e6ebf5; color: #0b1020; }

/* ---------- Tooltip ---------- */
[data-tip] { position: relative; }
.tip {
  position: fixed; z-index: 3000; pointer-events: none; padding: 5px 9px; border-radius: 7px;
  background: #0f172a; color: #f8fafc; font-size: 12px; font-weight: 500; white-space: nowrap;
  box-shadow: var(--shadow-md); animation: fade-in 120ms var(--ease);
}
.tip kbd { background: rgb(255 255 255 / 0.12); color: #e2e8f0; border-color: rgb(255 255 255 / 0.2); margin-left: 6px; font-size: 11px; padding: 0 5px; }

/* Barevné vzorky */
.swatches { display: grid; grid-template-columns: repeat(8, 26px); gap: 6px; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgb(15 23 42 / 0.15); padding: 0;
  background: var(--c); position: relative;
}
.swatch[aria-checked="true"]::after { content: ''; position: absolute; inset: -4px; border: 2px solid var(--accent); border-radius: 50%; }
.swatch.none { background: linear-gradient(135deg, transparent 45%, var(--danger) 45%, var(--danger) 55%, transparent 55%), var(--surface); }

.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--accent-soft-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
.progress { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; width: var(--p, 0%); background: var(--accent); border-radius: inherit; transition: width 200ms var(--ease); }
.dl .progress { margin-top: var(--sp-4); }
.dl-status { margin: 8px 0 0; min-height: 1.4em; }

/* Obrázky do PDF (ui/dialogs/images-to-pdf.js) – i na úvodní stránce, proto tady */
.i2p-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 10px; }
.i2p-count { margin: 0; font-weight: 600; }
.i2p-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; max-height: min(44vh, 420px); overflow: auto; padding: 4px; margin: 0 -4px 6px; }
.i2p-tile { position: relative; display: grid; gap: 4px; min-width: 0; padding: 6px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.i2p-tile.is-dragging { opacity: .45; cursor: grabbing; }
.i2p-tile.is-target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.i2p-tile.is-failed { border-color: var(--danger); }
.i2p-tile.is-failed .i2p-name { color: var(--danger-hover); white-space: normal; }
.i2p-img { position: relative; height: 120px; display: grid; place-items: center; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.i2p-canvas { max-width: 100%; max-height: 100%; box-shadow: var(--shadow-sm); outline: 1px solid var(--border); }
.i2p-n { position: absolute; left: 4px; top: 4px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--text); color: var(--surface); font-size: 11.5px; font-weight: 700; display: grid; place-items: center; }
.i2p-name { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.i2p-acts { position: absolute; right: 6px; top: 6px; display: flex; gap: 2px; opacity: 0; transition: opacity var(--dur) var(--ease); }
.i2p-tile:hover .i2p-acts, .i2p-tile:focus-within .i2p-acts { opacity: 1; }
.i2p-acts .btn { background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow-sm); }
.i2p-move { display: none; }
@media (hover: none) { .i2p-acts { opacity: 1; } }
@media (pointer: coarse) { .i2p-move { display: inline-flex; } .i2p-acts { left: 6px; justify-content: flex-end; flex-wrap: wrap; } }
.i2p-field { margin-bottom: 10px; justify-items: start; }
.i2p-seg { flex-wrap: wrap; }
.i2p-hint { margin: 0 0 10px; font-size: 12.5px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  /* kurzor při psaní bliká i tak – stejně jako systémový */
  .text-caret { animation-duration: 1.06s !important; animation-iteration-count: infinite !important; }
}

/* ---------- Tisk dokumentu z editoru (ui/print.js) ---------- */
.print-root { display: none; }
@media print {
  /* tiskne se jen připravený dokument */
  body:has(> .print-root) > *:not(.print-root) { display: none !important; }
  .print-root { display: block; }
  html:has(.print-root), body:has(> .print-root) { background: #fff !important; margin: 0; }
  .print-page { break-after: page; page-break-after: always; overflow: hidden; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page img { display: block; width: 100%; height: 100%; object-fit: contain; }
  /* tisk z menu prohlížeče v editoru: místo obrazovky editoru jen rada */
  body.has-app:not(:has(> .print-root)) > * { display: none !important; }
  body.has-app:not(:has(> .print-root))::after {
    content: attr(data-print-hint);
    display: block; padding: 40px; font: 16px/1.5 system-ui, sans-serif; color: #000;
  }
}
