:root {
  --bg: #f7f7f3;
  --ink: #111111;
  --muted: #6b6b6b;
  --line: rgba(0, 0, 0, 0.08);
  --card: #ffffff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --max: 980px;
  --hero-height: 120px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Sora", "Manrope", sans-serif;
  font-size: 15px;
}

html {
  scrollbar-gutter: stable;
  overflow-y: scroll;
}

body {
  overflow-y: scroll;
  min-height: 100%;
}

img { max-width: 100%; display: block; }

a { color: inherit; text-decoration: none; }

.container {
  max-width: var(--max);
  width: min(100%, var(--max));
  margin: 0 auto;
  padding: 0 24px;
}

.nav {
  position: sticky;
  top: 0;
  background: rgba(247, 247, 245, 0.9);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #111111;
}

.nav-links {
  display: flex;
  gap: 20px;
  font-size: 0.92rem;
  color: var(--muted);
}

.menu-button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  background: #111111;
  box-shadow: 0 6px 0 #111111, 0 -6px 0 #111111;
}

.app-menu {
  position: absolute;
  top: 60px;
  left: 24px;
  right: 24px;
  transform: none;
  width: auto;
  border-radius: 0 0 14px 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-sizing: border-box;
}

.app-menu a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--ink);
  flex: 1 1 0;
  text-align: center;
  white-space: nowrap;
}

.app-menu a:hover { background: #f2f2f2; }

.menu-logout {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
}

.menu-logout:hover {
  background: #f2f2f2;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 15, 15, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: min(100%, 420px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.auth-card h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.auth-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.auth-error {
  min-height: 18px;
  color: #b42318;
  font-size: 0.88rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 600;
  cursor: pointer;
}

.button.primary {
  background: #111111;
  color: #ffffff;
  border-color: #111111;
}

.hero {
  padding: 96px 0 80px;
}

.hero h1 {
  font-size: clamp(2.6rem, 4.2vw, 3.4rem);
  line-height: 1.03;
  letter-spacing: -0.03em;
  margin: 0 0 14px;
}

.hero p {
  font-size: 1.02rem;
  color: var(--muted);
  margin: 0 0 22px;
  max-width: 520px;
}

.section {
  padding: 70px 0;
  border-top: 1px solid var(--line);
}

.section h2 {
  font-size: clamp(1.4rem, 2.8vw, 2rem);
  margin: 0 0 10px;
}

.section p { color: var(--muted); max-width: 650px; }

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 18px;
}

.cards-full {
  grid-template-columns: 1fr;
}

.card {
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 14px;
  box-shadow: var(--shadow);
}

.footer {
  padding: 40px 0 56px;
  border-top: 1px solid var(--line);
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
}

/* App */

.app-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-hero {
  padding: 22px 0 14px;
  height: var(--hero-height);
  overflow: hidden;
}

.app-title {
  font-size: clamp(1.8rem, 3.6vw, 2.4rem);
  margin: 0;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-hero p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0;
}

.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.ocr-badge {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.app-main {
  padding-top: 0;
  width: 100%;
}

.app-main.container {
  max-width: 980px;
}

.app-panel {
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 20px;
  width: 100%;
}

.app-hero + .app-panel {
  margin-top: 0;
}

.empty-shell {
  min-height: 260px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  border: 1px dashed rgba(0,0,0,0.16);
  background: #fafafa;
}

.typing-line {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-text {
  white-space: pre;
}

.app-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.app-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  margin-top: 20px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tag {
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f5f5f5;
}

.tag.subtle {
  background: #f2f4f7;
  color: var(--muted);
}

.tag.ok {
  background: #eef4f0;
  color: #2f6b4c;
  border-color: #d7e7df;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.cursor {
  display: inline-block;
  width: 10px;
  height: 1.1em;
  background: #111111;
  vertical-align: -0.1em;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

.hidden { display: none !important; }

.fade-in {
  opacity: 0;
  transform: translateY(10px);
  animation: fadeIn 0.6s ease forwards;
}

@keyframes fadeIn { to { opacity: 1; transform: translateY(0); } }

@media (max-width: 980px) {
  .app-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .nav-links { display: none; }
}

@media (max-width: 600px) {
  .button { width: 100%; }
  .app-actions { flex-direction: column; }
}

@media (max-width: 900px) {
  .group-actions { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .table-row { min-width: 0; }
}

@media (max-width: 600px) {
  .prompt .button { width: auto; }
}

.muted { color: var(--muted); }

.chat-shell {
  border-radius: 20px;
  border: 1px dashed rgba(0,0,0,0.16);
  background: #fafafa;
  padding: 20px;
  min-height: 220px;
  display: grid;
  gap: 16px;
}

.chat-center {
  text-align: center;
}

.prompt {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.prompt-input {
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: #fff;
  font-size: 0.9rem;
}

.prompt .button {
  height: 40px;
  padding: 0 14px;
  line-height: 40px;
}

.stream {
  display: grid;
  gap: 8px;
  padding: 10px 2px 2px;
}

.stream-line {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  animation: fadeIn 0.5s ease forwards;
}

.chat-panel {
  margin-top: 12px;
  min-height: 440px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
  width: 100%;
}

.chat-panel.drag-over {
  border-color: #111111;
  box-shadow: 0 0 0 2px rgba(17, 17, 17, 0.08);
}

.chat-messages {
  display: grid;
  gap: 10px;
  align-content: start;
  width: 100%;
}

.chat-line {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  max-width: 100%;
  white-space: pre-wrap;
  line-height: 1.42;
}

.chat-answer {
  display: grid;
  gap: 8px;
}

.chat-answer-head {
  font-weight: 700;
  font-size: 1rem;
  margin-top: 2px;
}

.chat-answer-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.chat-answer-par {
  margin: 0;
}

.chat-inline-fact {
  font-weight: 700;
  font-size: inherit;
  color: inherit;
}

.chat-section {
  display: grid;
  gap: 6px;
}

.chat-section-title {
  font-weight: 600;
  color: #111;
}

.chat-evidence {
  display: grid;
  gap: 8px;
}

.chat-evidence-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 8px 10px;
}

.chat-evidence-item summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  gap: 6px;
}

.chat-evidence-item summary::-webkit-details-marker {
  display: none;
}

.chat-evidence-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.chat-evidence-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #111;
}

.chat-evidence-doc {
  font-size: 0.78rem;
  color: #6a6a6a;
}

.chat-evidence-preview {
  font-size: 0.9rem;
  color: #333;
}

.chat-fact-wrap {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: 6px;
}

.chat-fact-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f2f2f2;
  font-size: 0.78rem;
  color: #111;
}

.chat-tooltip {
  position: absolute;
  left: 0;
  right: auto;
  bottom: calc(100% + 8px);
  background: #111;
  color: #fff;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.35;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  pointer-events: none;
  max-height: 200px;
  overflow: auto;
  z-index: 2;
  width: min(360px, 70vw);
}

.chat-tooltip-doc {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 6px;
}

.chat-tooltip-text {
  white-space: normal;
}

.chat-tooltip-translation {
  margin-top: 6px;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.72);
}

.chat-fact-pill:hover .chat-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-evidence-body {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.chat-evidence-quote {
  margin-top: 8px;
  font-size: 0.9rem;
  color: #111;
}

.chat-evidence-translation {
  margin-top: 6px;
  font-size: 0.85rem;
  color: #6a6a6a;
}


.chat-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 18px;
}

.chat-meta {
  margin-top: 4px;
  font-size: 0.85rem;
  color: #6a6a6a;
}

.chat-note {
  margin-top: 4px;
  font-size: 0.85rem;
  color: #8b5e00;
}

.chat-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.chat-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.chat-table th,
.chat-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.chat-table th {
  background: #f7f6f2;
  font-weight: 600;
  color: #222;
}

.chat-line.user {
  justify-self: end;
  background: #111111;
  color: #fff;
  border-color: #111111;
}

.chat-line.assistant {
  justify-self: start;
}

.chat-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.8rem;
  cursor: pointer;
}

.chat-input {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) 1fr auto auto;
  gap: 8px;
}

.chat-input .button {
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
}

.chat-scope {
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0 12px;
  background: #fff;
  font-size: 0.88rem;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.group-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
  align-items: center;
}

.group-actions .button {
  width: 100%;
  justify-content: center;
}

.filter-input {
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 0 12px;
  background: #fff;
  font-size: 0.88rem;
}

.table {
  display: grid;
  gap: 6px;
  overflow-x: auto;
  width: 100%;
}

.fields-table .table-row {
  grid-template-columns: minmax(180px, 1.2fr) minmax(220px, 1.6fr) minmax(120px, 0.6fr) 110px 110px;
  min-width: 0;
}

.fields-table .table-head {
  grid-template-columns: minmax(180px, 1.2fr) minmax(220px, 1.6fr) minmax(120px, 0.6fr) 110px 110px;
}

.fields-table .table-row .filter-input {
  width: -webkit-fill-available;
  width: 100%;
  max-width: 100%;
  display: block;
}

.bag-docs-table .table-row {
  grid-template-columns: minmax(240px, 1.8fr) minmax(120px, 0.7fr) 110px 130px;
  min-width: 0;
}

.bag-docs-table .table-head {
  grid-template-columns: minmax(240px, 1.8fr) minmax(120px, 0.7fr) 110px 130px;
}

.bag-fields-table .table-row {
  grid-template-columns: minmax(220px, 1.2fr) minmax(360px, 2.8fr) minmax(70px, 0.4fr) 110px;
  min-width: 0;
}

.bag-fields-table .table-head {
  grid-template-columns: minmax(220px, 1.2fr) minmax(360px, 2.8fr) minmax(70px, 0.4fr) 110px;
}

.bag-fields-table .field-history-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.bag-fields-table .field-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.bag-fields-table .table-head > div:nth-child(3),
.bag-fields-table .table-head > div:nth-child(4) {
  justify-self: end;
}

.bag-fields-table .table-head > div:nth-child(4) {
  padding-right: 20px;
}

.bag-fields-table .table-row.table-subrow {
  grid-template-columns: 1fr;
  align-items: start;
  background: #f9fafc;
  border-style: dashed;
  display: none;
}

.bag-fields-table .table-row.table-subrow.is-open {
  display: grid;
}

.bag-fields-table .table-row.table-subrow > div {
  grid-column: 1 / -1;
}

.field-history {
  display: grid;
  gap: 10px;
}

.field-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.field-history-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.field-edit {
  display: grid;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}

.field-edit-title {
  font-weight: 600;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field-edit-title a,
.value-doc a {
  color: inherit;
  text-decoration: none;
}

.field-edit-title a:hover,
.value-doc a:hover {
  text-decoration: underline;
}

.field-edit-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(160px, 0.6fr) auto auto;
  gap: 8px;
  align-items: center;
}

.field-edit-form .filter-input {
  height: 34px;
}

.history-empty {
  font-size: 0.82rem;
}

.value-cell {
  word-break: break-word;
}

.table-row {
  display: grid;
  grid-template-columns: 32px minmax(320px, 2fr) minmax(140px, 0.7fr) 110px 90px 56px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  min-width: 680px;
  font-size: 0.88rem;
  line-height: 1.25;
}

.table-group {
  grid-template-columns: 1fr;
  background: #f9fafc;
  border-style: dashed;
}

.table-group > div {
  grid-column: 1 / -1;
}

.table-row > div {
  min-width: 0;
}

.table-row a {
  word-break: break-word;
}

.doc-cell {
  display: grid;
  gap: 6px;
}

.doc-title a {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.table-row.table-doc {
  grid-template-columns: 28px minmax(320px, 2fr) minmax(140px, 0.7fr) 96px 80px 70px;
  grid-template-rows: auto auto;
  grid-template-areas:
    "check title title title title title"
    "check meta type facts risks actions";
  row-gap: 6px;
  align-items: start;
}

.table-row.table-doc .doc-check { grid-area: check; }
.table-row.table-doc .doc-title { grid-area: title; }
.table-row.table-doc .doc-cell { grid-area: meta; }
.table-row.table-doc .doc-type { grid-area: type; }
.table-row.table-doc .doc-facts { grid-area: facts; }
.table-row.table-doc .doc-risks { grid-area: risks; }
.table-row.table-doc .doc-actions {
  grid-area: actions;
  justify-self: end;
}

.table-row.table-doc .doc-type,
.table-row.table-doc .doc-facts,
.table-row.table-doc .doc-risks,
.table-row.table-doc .doc-actions {
  align-self: center;
}

.role-edit {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.6fr);
  gap: 6px;
  align-items: center;
}

.parent-edit {
  display: grid;
  grid-template-columns: minmax(220px, 1fr);
}

.role-select,
.role-input {
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--line);
  padding: 0 8px;
  background: #fff;
  font-size: 0.78rem;
}

.role-input::placeholder {
  color: #9aa0a6;
}

.row-child {
  margin-left: 12px;
}

.row-child .doc-cell,
.row-child .doc-title {
  padding-left: 12px;
  border-left: 2px solid #e6e9ee;
}

.group-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.group-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.group-title-actions {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.section-header {
  cursor: pointer;
}

.section-header .pill.action {
  cursor: pointer;
}

.section-hidden {
  display: none !important;
}

.toggle-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.toggle-header::after {
  content: "▼";
  font-size: 0.7rem;
  color: var(--muted);
}

.toggle-header.is-open::after {
  content: "▲";
}

.group-link {
  color: inherit;
  text-decoration: none;
}

.group-link:hover {
  text-decoration: underline;
}

.value-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.value-entries {
  display: grid;
  gap: 8px;
}

.value-entry {
  font-size: 0.82rem;
}

.value-entry.history-entry {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(160px, 0.6fr) auto auto;
  gap: 8px;
  align-items: center;
}

.value-entry.history-entry .value-meta {
  grid-column: 1 / span 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.value-entry.history-entry .value-status {
  grid-column: 4;
  justify-self: end;
}

.value-entry.conflict-entry {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.value-entry .value-date {
  font-variant-numeric: tabular-nums;
}

.value-entry .value-doc {
  color: var(--muted);
}

.conflict-block {
  border: 1px dashed #f0b429;
  border-radius: 10px;
  padding: 6px 8px;
  background: #fff7e6;
}

.doc-date-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.doc-date-row label {
  font-size: 0.8rem;
  color: var(--muted);
}

.doc-date-row input {
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--line);
  padding: 0 8px;
  background: #fff;
  font-size: 0.8rem;
}

.group-sub {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 0.8rem;
}

.group-meta {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  font-size: 0.8rem;
}

.group-hierarchy {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

.parent-edit {
  display: grid;
  grid-template-columns: minmax(220px, 1fr);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  border: 1px solid var(--line);
  background: #f5f5f5;
}

.pill.ok { background: #eef4f0; }
.pill.no { background: #f5f5f5; }
.pill.action {
  cursor: pointer;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}

.pill.action:hover { background: #eeeeee; }

.pill.action:focus-visible {
  outline: 2px solid rgba(17, 17, 17, 0.2);
  outline-offset: 2px;
}

.pill.danger { color: #9b1c1c; }

.row-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.button.small {
  height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.button.subtle {
  background: #f6f6f6;
  border-color: #e3e3e3;
}

.hero-actions {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-busy {
  opacity: 0.9;
}

.chat-line.typing .typing-text {
  white-space: pre-wrap;
}

.typing-cursor {
  display: inline-block;
  margin-left: 4px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to { opacity: 0; }
}
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  width: 32px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}

.select-col {
  display: flex;
  align-items: center;
  justify-content: center;
}

.select-col input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #111111;
  cursor: pointer;
}

.stage2-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 20px;
}

.stage2-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.stage2-toggle span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #e7e9ee;
  border: 1px solid var(--line);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.stage2-toggle span::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #d2d6dc;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stage2-toggle input:checked + span {
  background: #111111;
  border-color: #111111;
}

.stage2-toggle input:checked + span::after {
  transform: translate(18px, -50%);
  border-color: #111111;
}

.stage2-toggle input:focus-visible + span {
  outline: 2px solid rgba(17, 17, 17, 0.2);
  outline-offset: 2px;
}

.icon-button.danger {
  color: #9b1c1c;
}

.table-head {
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border: none;
  padding: 0 2px 4px;
}

.risk-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.risk-card {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px;
  box-shadow: var(--shadow);
}

.risk-row {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
}

.risk-cta {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.quote {
  padding: 10px;
  border-radius: 12px;
  background: #f9f9f7;
  border: 1px dashed rgba(0,0,0,0.12);
  font-size: 0.88rem;
  color: var(--muted);
}

.facts-list {
  display: grid;
  gap: 10px;
}

.fact-card {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px;
  box-shadow: var(--shadow);
}

.fact-head {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.fact-row {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.fact-label {
  font-size: 0.76rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.fact-text {
  white-space: pre-wrap;
  line-height: 1.4;
}

.fact-details {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.fact-details summary {
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  list-style: none;
}

.fact-details summary::-webkit-details-marker {
  display: none;
}

.fact-details .fact-text {
  margin-top: 6px;
}

.fact-preview {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumbs {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 22px;
}

.breadcrumbs-spacer {
  visibility: hidden;
}

.breadcrumbs a {
  color: var(--ink);
}

.breadcrumbs .crumb-current {
  color: var(--muted);
  font-weight: 600;
}

.doc-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-meta-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 18px;
  align-items: center;
}

.doc-meta-row p {
  margin: 0;
  min-width: 0;
}

.doc-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: nowrap;
  white-space: nowrap;
  justify-self: end;
}

.doc-actions .button {
  white-space: nowrap;
}

.pdf-preview {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  margin-bottom: 18px;
}

.pdf-preview iframe {
  width: 100%;
  height: 540px;
  border: none;
}

.pdf-modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 17, 17, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 24px;
}

.pdf-modal.hidden {
  display: none;
}

.pdf-modal-content {
  width: min(980px, 96vw);
  max-height: 90vh;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.pdf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.pdf-modal-title {
  font-weight: 600;
}

.pdf-canvas-wrap {
  position: relative;
  overflow: auto;
  background: #f7f7f5;
  padding: 16px;
}

.pdf-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.pdf-overlay-canvas,
#pdfOverlay {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 2;
}

.pdf-inline {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  overflow: hidden;
}

.pdf-inline.hidden {
  display: none;
}

.pdf-inline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.pdf-inline-title {
  font-weight: 600;
}

.pdf-inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pdf-inline-wrap {
  max-height: 460px;
}

.fact-toggle {
  font-size: 0.85rem;
  color: var(--muted);
}

.fact-details[open] .fact-toggle {
  content: "Zwiń";
}

.fact-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0 8px;
}

.chat-presets {
  display: grid;
  gap: 10px;
  margin: 14px 0 8px;
}

.chat-presets-label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.chip:hover {
  border-color: #111111;
  transform: translateY(-1px);
}

.link-button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
}

.timeline {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 12px;
  align-items: start;
}

.timeline-item .dot {
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  background: #111111;
}

.meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.meta .tag {
  background: #f2f2f2;
}

@media (max-width: 600px) {
  .prompt { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .chat-input { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .chat-input { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .risk-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .hero-row { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 720px) {
  .table-row { grid-template-columns: 1fr; min-width: 0; }
  .table-row.table-doc {
    grid-template-columns: 1fr;
    grid-template-areas:
      "check"
      "title"
      "meta"
      "type"
      "facts"
      "risks"
      "actions";
  }
  .table-row.table-doc .doc-actions { justify-self: start; }
}

@media (max-width: 720px) {
  .field-edit-form { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-hero {
    height: auto;
    overflow: visible;
  }
  .app-title,
  .app-hero p {
    white-space: normal;
  }
}

@media (max-width: 720px) {
  .doc-meta-row {
    grid-template-columns: 1fr;
    row-gap: 10px;
  }

  .doc-actions { flex-wrap: wrap; }
}
