/* ---------- Tokeny ---------- */
:root {
  --bg: #f2f3f6;
  --surface: #ffffff;
  --raised: #e9ebf0;
  --outline: #dadde5;
  --text: #0e1118;
  --muted: #5e6678;
  --accent: #d10500;
  --on-accent: #ffffff;
  --live: #0fa65a;
  --warning: #b86e00;
  --shadow: 0 10px 30px rgb(14 17 24 / 0.12);
  --radius: 16px;
  --font: 'Titillium Web', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b0d12;
    --surface: #141821;
    --raised: #1c212d;
    --outline: #2a3040;
    --text: #f3f5f9;
    --muted: #8d95a8;
    --accent: #e10600;
    --live: #22d37a;
    --warning: #ffb020;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0b0d12;
  --surface: #141821;
  --raised: #1c212d;
  --outline: #2a3040;
  --text: #f3f5f9;
  --muted: #8d95a8;
  --accent: #e10600;
  --live: #22d37a;
  --warning: #ffb020;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  color-scheme: dark;
}

/* ---------- Základ ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.ic {
  width: 22px;
  height: 22px;
  flex: none;
}

.ic.inline {
  width: 1.1em;
  height: 1.1em;
  vertical-align: -0.2em;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
}

.icon-btn:hover {
  background: var(--raised);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
  background: transparent;
}

.icon-btn.small {
  width: 32px;
  height: 32px;
}

.icon-btn.small .ic {
  width: 18px;
  height: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--outline);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 700;
}

.btn .ic {
  width: 18px;
  height: 18px;
}

.btn.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn.wide {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* ---------- Sticky záhlaví ---------- */
.top {
  flex: none;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  border-bottom: 1px solid var(--outline);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px max(4px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}

.stripe {
  flex: none;
  width: 4px;
  height: 40px;
  border-radius: 2px;
  background: var(--accent);
}

.brand-text {
  flex: 1;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live {
  --c: var(--live);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--c);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.live[data-status='offline'] {
  --c: var(--warning);
}

.live[data-status='error'] {
  --c: var(--accent);
}

.live-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c);
}

.live:is([data-status='idle'], [data-status='syncing']) .live-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--c);
  opacity: 0;
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  from {
    transform: scale(0.4);
    opacity: 0.5;
  }
  to {
    transform: scale(1.6);
    opacity: 0;
  }
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 12px 16px 8px;
}

.search-icon {
  position: absolute;
  left: 12px;
  display: grid;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 44px;
  padding: 0 44px;
  border: 1px solid var(--outline);
  border-radius: 14px;
  background: var(--surface);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.search input::-webkit-search-cancel-button {
  display: none;
}

.search input::placeholder {
  color: var(--muted);
}

.search input:focus {
  border-color: var(--accent);
}

.search .icon-btn {
  position: absolute;
  right: 6px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 2px 16px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.tab-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}

.tab[aria-selected='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.tab[aria-selected='true'] .tab-count {
  color: rgb(255 255 255 / 0.75);
}

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 10px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  --c: var(--warning);
  color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
  animation: slide-down 0.25s ease-out;
}

.banner[data-kind='error'] {
  --c: var(--accent);
}

.banner .ic {
  width: 18px;
  height: 18px;
}

@keyframes slide-down {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* ---------- Stránky kategorií (swipe) ---------- */
.pages {
  flex: 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}

.pages::-webkit-scrollbar {
  display: none;
}

.page {
  flex: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overscroll-behavior-y: contain;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.doc {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 8px 14px 16px;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  overflow: hidden;
  transition: transform 0.12s, border-color 0.2s;
}

.doc:active {
  transform: scale(0.985);
}

.doc.is-new {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.doc.is-new::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--accent);
}

.doc.enter {
  animation: enter 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i) * 40ms);
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

.doc-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--raised);
}

.doc-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.doc-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.doc-meta {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  vertical-align: 2px;
}

.doc-offline {
  display: grid;
  color: var(--live);
}

.doc-offline .ic {
  width: 18px;
  height: 18px;
}

.doc-chevron {
  display: grid;
  color: var(--muted);
}

/* Skeleton */
.skeleton {
  pointer-events: none;
}

.sk {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--raised) 30%, var(--outline) 50%, var(--raised) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.3s linear infinite;
}

.sk-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  flex: none;
}

.sk-line {
  height: 16px;
  width: 100%;
}

.sk-line.short {
  height: 12px;
  width: 140px;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* Prázdné stavy */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 32px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 16px;
  border: 1.5px solid var(--outline);
  border-radius: 50%;
  color: var(--muted);
}

.empty-icon .ic {
  width: 32px;
  height: 32px;
}

.empty h3 {
  margin: 0;
  font-size: 18px;
}

.empty p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 34ch;
}

.empty .btn {
  margin-top: 20px;
}

/* Instalace */
.install-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px 12px 14px;
  border: 1px dashed var(--outline);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
}

.install-card > .ic {
  color: var(--accent);
}

.install-card > div {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.install-card span {
  color: var(--muted);
}

/* ---------- Prohlížeč dokumentu ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--raised);
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.viewer.open {
  transform: none;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: env(safe-area-inset-top) max(4px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
  min-height: calc(56px + env(safe-area-inset-top));
  background: var(--bg);
}

.viewer-heading {
  flex: 1;
  min-width: 0;
  padding: 0 4px;
}

.viewer-heading h2,
.viewer-heading p {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-heading h2 {
  font-size: 18px;
  font-weight: 700;
}

.viewer-heading p {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.viewer-progress {
  height: 2px;
  background: var(--bg);
  overflow: hidden;
}

.viewer-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s;
}

.viewer-progress.indeterminate span {
  width: 30%;
  animation: indeterminate 1.1s ease-in-out infinite;
}

.viewer-progress.done span {
  opacity: 0;
  transition: opacity 0.4s;
}

@keyframes indeterminate {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(400%);
  }
}

.viewer-body {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.viewer-state {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
}

.pages-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 100%;
  margin: 0 auto;
  padding: 10px 10px calc(16px + env(safe-area-inset-bottom));
}

.pdf-page {
  position: relative;
  width: 100%;
  background: #fff;
  border-radius: 4px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pdf-page canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.viewer-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: var(--shadow);
}

body.viewer-open .top,
body.viewer-open .pages {
  visibility: hidden;
}

/* ---------- Nastavení (sheet) ---------- */
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--outline);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.sheet[open] {
  animation: sheet-up 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0.45);
}

@media (min-width: 640px) {
  .sheet {
    margin: auto;
    border-bottom: 1px solid var(--outline);
    border-radius: 22px;
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

.sheet-inner {
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
}

.sheet-label {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--raised);
}

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  background: var(--surface);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.15);
}

.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
}

.segmented .ic {
  width: 18px;
  height: 18px;
}

.row-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--outline);
  border-radius: 14px;
  cursor: pointer;
}

.row-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.row-text small {
  color: var(--muted);
  font-size: 13px;
}

input[role='switch'] {
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--outline);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background 0.2s;
}

input[role='switch']::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transition: transform 0.2s;
}

input[role='switch']:checked {
  background: var(--accent);
}

input[role='switch']:checked::after {
  transform: translateX(20px);
}

input[role='switch']:disabled {
  opacity: 0.4;
  cursor: default;
}

.hint {
  margin: 0;
  color: var(--muted);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(520px, calc(100% - 32px));
  padding: 12px 12px 12px 16px;
  border: 1px solid var(--outline);
  border-left: 4px solid var(--accent);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translate(-50%, 24px);
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

.toast-text span {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast-btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
