:root {
  --primary: #2563eb;
  --bg: #ffffff;
  --fg: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --error: #dc2626;
  --success: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 1.25rem; margin: 0; }
header nav { display: flex; gap: 0.5rem; }
header a, header button {
  padding: 0.5rem 0.75rem; border-radius: 6px;
  text-decoration: none; color: var(--fg); font: inherit;
  background: transparent; border: 1px solid transparent; cursor: pointer;
}
header a[aria-current="page"] { background: var(--primary); color: white; }

main { padding: 1rem; max-width: 720px; margin: 0 auto; }

body.login main {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 90vh;
}
body.login form {
  display: flex; flex-direction: column; gap: 0.75rem; width: 100%; max-width: 320px;
}
body.login label { display: flex; flex-direction: column; font-weight: 500; }
body.login input {
  margin-top: 0.25rem; padding: 0.6rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: 1rem;
}
body.login button {
  background: var(--primary); color: white; border: none; padding: 0.6rem;
  border-radius: 6px; font-size: 1rem; cursor: pointer;
}
body.login #error { color: var(--error); margin: 0; }

#dropzone {
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 3rem 1rem; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
#dropzone:hover, #dropzone.dragover {
  border-color: var(--primary); background: rgba(37, 99, 235, 0.04);
}
#dropzone p { margin: 0 0 1rem; color: var(--muted); }
.btn {
  display: inline-block; background: var(--primary); color: white;
  padding: 0.6rem 1rem; border-radius: 6px; cursor: pointer;
}

#status-list { list-style: none; padding: 0; margin: 1.5rem 0 0; }
#status-list li {
  padding: 0.5rem 0.75rem; border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 0.5rem;
  display: flex; align-items: center; justify-content: space-between;
}
.status-uploading { color: var(--muted); }
.status-done { color: var(--success); }
.status-error { color: var(--error); }

table {
  width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.95rem;
}
th, td { text-align: left; padding: 0.5rem 0.5rem; border-bottom: 1px solid var(--border); }
th { background: #f9fafb; font-weight: 600; }
.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.8rem; background: var(--border); color: var(--fg);
}
.badge.done { background: #dcfce7; color: #166534; }
.badge.uploaded { background: #dbeafe; color: #1e40af; }
.badge.classifying { background: #fef3c7; color: #92400e; }
.badge.needs_review { background: #fee2e2; color: #991b1b; }
.badge.failed { background: #f3f4f6; color: #374151; }

.app-version {
  position: fixed; bottom: 0; right: 0;
  padding: 0.25rem 0.6rem;
  font-size: 0.72rem; color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: rgba(255, 255, 255, 0.85);
  border-top-left-radius: 6px;
  pointer-events: auto;
}
.app-version a { color: inherit; text-decoration: none; }
.app-version a:hover { color: var(--primary); text-decoration: underline; }

/* ── Modal dialog ─────────────────────────────────────── */
dialog.modal {
  border: none; border-radius: 12px; padding: 0;
  max-width: 640px; width: 100%; max-height: 90vh;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
dialog.modal::backdrop { background: rgba(0,0,0,0.4); }
dialog.modal form { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
dialog.modal h2 { margin: 0; font-size: 1.25rem; }
dialog.modal label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 500; font-size: 0.9rem; }
dialog.modal input[type=text],
dialog.modal textarea {
  padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.95rem; font-family: inherit;
}
dialog.modal textarea { min-height: 4rem; resize: vertical; }
dialog.modal .modal-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem;
}
dialog.modal .modal-actions .danger {
  margin-right: auto; background: white; color: var(--error);
  border: 1px solid var(--error);
}

/* ── Placeholder list editor ──────────────────────────── */
.placeholder-list { display: flex; flex-direction: column; gap: 0.5rem; }
.placeholder-row {
  display: grid; grid-template-columns: 1fr 2fr auto; gap: 0.5rem; align-items: center;
}
.placeholder-row input { padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; }
.placeholder-row button.remove {
  background: white; border: 1px solid var(--border); border-radius: 4px;
  width: 2rem; height: 2rem; cursor: pointer; color: var(--error);
}

/* ── Preview box ──────────────────────────────────────── */
.preview-box {
  background: #f9fafb; border: 1px solid var(--border);
  border-radius: 6px; padding: 0.75rem; font-family: ui-monospace, Menlo, monospace;
  font-size: 0.85rem;
}
.preview-box .preview-line { margin: 0.1rem 0; }

/* ── Categories list ──────────────────────────────────── */
.categories-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.category-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem;
  display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; align-items: center;
}
.category-card.inactive { opacity: 0.55; }
.category-card .meta { font-size: 0.85rem; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.category-card .badge { font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 999px; background: var(--border); }
.category-card .badge.active { background: #dcfce7; color: #166534; }

/* ── View toggle (Seznam | Strom) ─────────────────────── */
.view-toggle { display: inline-flex; gap: 0; margin: 1rem 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.view-toggle button {
  border: none; background: white; padding: 0.4rem 0.9rem; cursor: pointer;
  font-family: inherit; font-size: 0.9rem;
}
.view-toggle button.active { background: var(--primary); color: white; }

/* ── Tree view ────────────────────────────────────────── */
.tree, .tree ul { list-style: none; padding-left: 1rem; margin: 0; }
.tree details > summary { cursor: pointer; padding: 0.2rem 0; font-weight: 500; }
.tree details > summary::marker { color: var(--muted); }
.tree-doc {
  padding: 0.2rem 0 0.2rem 1.25rem; font-size: 0.9rem;
  display: grid; grid-template-columns: 1fr auto auto; gap: 0.5rem;
  cursor: pointer;
}
.tree-doc:hover { background: rgba(37, 99, 235, 0.05); border-radius: 4px; }
.tree-doc .meta { color: var(--muted); font-size: 0.8rem; }

/* ── Field hints ──────────────────────────────────────── */
.hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; line-height: 1.4; }
.hint code { background: #f3f4f6; padding: 0.05rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.hint-panel { font-size: 0.85rem; margin-bottom: 0.5rem; }
.hint-panel summary { cursor: pointer; color: var(--primary); padding: 0.25rem 0; }
.placeholders-help { padding: 0.5rem 0.75rem; background: #f9fafb; border-radius: 6px; font-size: 0.85rem; }
.placeholders-help ul { margin: 0.25rem 0 0.5rem 1rem; padding: 0; }
.placeholders-help li { margin: 0.15rem 0; }
.placeholders-help code { background: white; padding: 0.05rem 0.3rem; border-radius: 3px; border: 1px solid var(--border); font-size: 0.9em; }
.hint-note { font-size: 0.78rem; color: var(--muted); margin-top: 0.4rem; font-style: italic; }

/* ── Document preview (detail modal) ─────────────────── */
.doc-preview { margin: 0.5rem 0; min-height: 120px; display: flex; align-items: center; justify-content: center; background: #f9fafb; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.preview-img { max-width: 100%; max-height: 60vh; object-fit: contain; }
.preview-pdf { width: 100%; height: 60vh; border: none; }
.preview-fallback { padding: 1.5rem; text-align: center; color: var(--muted); }
.preview-fallback .meta { font-size: 0.85rem; }
.preview-loading, .preview-error { padding: 2rem; color: var(--muted); font-size: 0.9rem; }
.preview-error { color: var(--error); }
.doc-meta { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem 0.75rem; background: #f9fafb; border-radius: 6px; font-size: 0.9rem; }
.modal-actions a.btn { background: white; color: var(--primary); border: 1px solid var(--primary); padding: 0.4rem 0.75rem; border-radius: 6px; text-decoration: none; font-size: 0.9rem; }
.modal-actions a.btn:hover { background: rgba(37, 99, 235, 0.05); }
