:root {
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #d9dee8;
  --paper: #ffffff;
  --page: #f3f5f9;
  --navy: #1f3a68;
  --label: #2b5ea7;
  --existing: #2b5ea7;
  --existing-bg: #e8f0fb;
  --application: #1f7a4d;
  --application-bg: #e5f4ec;
  --older: #6b7385;
  --older-bg: #eef0f4;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --focus: #f0a030;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 10px 16px;
  background: var(--navy);
  color: #fff;
}
.topbar h1 { margin: 0 8px 0 0; font-size: 17px; letter-spacing: 0.2px; }
.source-label { padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); font-size: 12px; }
.empty-note { opacity: 0.6; font-style: italic; }
.eval-pick { display: flex; align-items: center; gap: 4px; }
.eval-pick select { padding: 0 2px; border: 0; background: transparent; color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; }
.eval-pick option { color: var(--ink); }
.actions, .account { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions { margin-left: auto; }
.account { font-size: 13px; }
#profile-button { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.4); font-weight: 500; }
.source { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.source label { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: 0.9; }
.source input { width: 120px; padding: 5px 7px; border: 0; border-radius: 4px; background: #fff; color: var(--ink); }
#filter-key, #filter-value { width: 80px; }

button, .file-button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.topbar button, .topbar .file-button { border-color: transparent; font-weight: 600; }
.file-button { display: inline-flex; align-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-button:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

.message { margin: 10px 16px 0; padding: 8px 12px; border-radius: 4px; background: #fff; border: 1px solid var(--line); }
.message-error { background: var(--bad-bg); border-color: #f2b8b5; color: var(--bad); }

.recordbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.recordbar > button { font-size: 18px; line-height: 1; padding: 4px 14px; }
.position { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.position input { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; text-align: right; }
.mode-pick { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.mode-pick select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); }
.find { display: flex; align-items: center; gap: 6px; }
.find input { width: 150px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; }
.find button { padding: 4px 10px; }
.find-status { font-size: 12px; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.chip { padding: 2px 8px; border-radius: 999px; background: var(--older-bg); font-size: 12px; white-space: nowrap; }
.chip b { font-weight: 600; color: var(--muted); }
.tone-mode { background: var(--existing-bg); }
.tone-bad { background: var(--bad-bg); color: var(--bad); }
.switch { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.switch button { border: 0; border-radius: 0; padding: 5px 12px; }
.switch button[aria-pressed="true"] { background: var(--navy); color: #fff; }

.mapping { display: flex; flex-wrap: wrap; gap: 16px; padding: 6px 16px; background: var(--paper); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.mapping select { margin-left: 6px; padding: 3px 6px; }

#workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(260px, 0.7fr);
  gap: 12px;
  padding: 12px 16px;
}
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.panel h2 { margin: 0; padding: 8px 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: #fff; background: var(--navy); border-radius: 6px 6px 0 0; }
.panel-body { height: calc(100vh - 210px); min-height: 320px; overflow: auto; padding: 4px 12px 12px; }

.field { padding: 8px 0; border-bottom: 1px solid #edf0f5; }
.field:last-child { border-bottom: 0; }
.field h4 { margin: 4px 0 6px; font-size: 13px; color: var(--label); }
.field h5 { margin: 6px 0 2px; font-size: 12px; font-style: italic; font-weight: 600; color: var(--label); }
.field p, .field ul { margin: 2px 0; line-height: 1.45; }
.field ul { padding-left: 18px; }
.empty { color: var(--muted); font-style: italic; }
.item { margin: 6px 0 10px; }
.label { display: flex; align-items: baseline; gap: 6px; font-weight: 600; color: var(--label); margin-bottom: 2px; }
.value { padding-left: 2px; white-space: normal; overflow-wrap: anywhere; }
.tag { flex: none; padding: 1px 6px; border-radius: 3px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase; }
.tag-existing { background: var(--existing-bg); color: var(--existing); }
.tag-application { background: var(--application-bg); color: var(--application); }
.tag-older, .tag-context { background: var(--older-bg); color: var(--older); }
.item-application .label { color: var(--application); }
.item-older .label, .item-context .label { color: var(--older); }
.note-list { padding-left: 18px; }
.note-list li { margin-bottom: 8px; }
.note-list q { display: block; margin: 2px 0; font-style: italic; }
.note-list .reason { display: block; color: var(--muted); }
.error-box { margin: 10px 0; padding: 8px 10px; border-radius: 4px; background: var(--bad-bg); color: var(--bad); white-space: pre-wrap; }

pre.json, pre.inline-json { margin: 8px 0; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.inline-json { padding: 6px 8px; background: #f7f8fb; border-radius: 4px; }

.finding { padding-bottom: 12px; }
.finding textarea { flex: 1; min-height: 260px; margin: 12px 12px 8px; padding: 10px; border: 1px solid var(--line); border-radius: 4px; resize: vertical; line-height: 1.45; }
.finding-actions { display: flex; align-items: center; gap: 10px; padding: 0 12px; }
#save-n8n { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.finding-status { color: var(--muted); font-size: 12px; }
.finding-count { margin: 8px 12px 0; color: var(--muted); font-size: 12px; }

.extra { margin: 0 16px 24px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.extra summary { padding: 10px 12px; cursor: pointer; font-weight: 600; color: var(--navy); }
#extra-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; padding: 0 12px 12px; }
.extra-item { border: 1px solid #edf0f5; border-radius: 4px; padding: 6px 10px; max-height: 420px; overflow: auto; }
.extra-item h3 { margin: 4px 0; font-size: 12px; color: var(--label); }

.start { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; max-width: 860px; margin: 48px auto; padding: 0 16px; }
.start-card { display: flex; flex-direction: column; gap: 10px; padding: 20px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.start-card h2 { margin: 0; font-size: 16px; color: var(--navy); }
.start-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.start-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.start-card input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); }
.start-row { display: flex; gap: 10px; }
.start-row label { flex: 1; }
.start-card button[type="submit"], .start-card .file-button { align-self: flex-start; background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.start-note { color: var(--muted); font-size: 12px; }

.admin { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 8px; padding: 20px; color: var(--ink); }
.admin::backdrop { background: rgba(20, 30, 50, 0.35); }
.admin h2 { margin: 0 0 6px; font-size: 15px; color: var(--navy); }
.admin h2 + p { margin: 0 0 12px; color: var(--muted); }
.admin-close { position: absolute; top: 10px; right: 10px; }
.admin-close button { border: 0; font-size: 20px; line-height: 1; padding: 2px 8px; }
.admin-row { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 10px; }
.admin-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.admin-row select { padding: 5px 7px; }
#create-invite { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.invite-link { display: flex; gap: 8px; margin-bottom: 18px; }
.invite-link input { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; font-size: 12px; }
.user-list { list-style: none; margin: 0 0 8px; padding: 0; }
.user-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid #edf0f5; }
.muted { color: var(--muted); font-size: 12px; }

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: min(380px, 100%); padding: 28px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.auth-card h1 { margin: 0 0 4px; font-size: 20px; color: var(--navy); }
.auth-lead { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.auth-card input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); font-size: 14px; }
.auth-card small { color: var(--muted); }
.auth-card button { padding: 9px; background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.auth-error { margin: 0; color: var(--bad); }
.auth-foot { margin: 16px 0 0; font-size: 12px; color: var(--muted); }
.auth-foot a { color: var(--label); }

@media (max-width: 1000px) {
  #workspace { grid-template-columns: 1fr; }
  .panel-body { height: auto; max-height: 70vh; }
}

/* Profile menu */
.account { position: relative; }
#profile-button { display: inline-flex; align-items: center; gap: 6px; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 210px; padding: 6px; background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(20, 30, 50, 0.18); }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--ink); padding: 8px 10px; font-weight: 500; }
.menu button:hover, .menu button:focus-visible { background: var(--page); }
.menu-role { margin: 4px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }

/* Dialog forms */
.admin.wide { width: min(720px, calc(100vw - 32px)); }
.stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.stack input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); }
.stack small, .admin small { color: var(--muted); font-size: 11.5px; }
.stack .check, .check { flex-direction: row; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink); }
.sub-settings { border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; }
.sub-settings summary { cursor: pointer; font-size: 12.5px; color: var(--navy); }
.sub-settings[open] { display: flex; flex-direction: column; gap: 10px; }
button.primary { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; align-self: flex-start; }
.table-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow: auto; }
.table-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 8px 0; border-bottom: 1px solid #edf0f5; }
.table-list select { margin-left: 4px; padding: 3px 6px; }

/* Review view: before and after, field help, editable lines */
.field h4, .field h5 { display: flex; align-items: center; gap: 6px; }
.info { position: relative; display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: var(--existing-bg); color: var(--label); font: italic 600 10px/1 Georgia, serif; cursor: help; }
.info:hover::after, .info:focus::after {
  content: attr(data-tip);
  position: absolute; left: -6px; top: calc(100% + 6px); z-index: 30;
  width: max-content; max-width: 260px; padding: 7px 9px; border-radius: 5px;
  background: var(--ink); color: #fff; font: 400 12px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-style: normal;
  white-space: normal; box-shadow: 0 6px 18px rgba(20, 30, 50, 0.25);
}
.before { position: relative; padding: 4px 8px 4px 10px; border-left: 3px solid var(--bad); background: var(--bad-bg); border-radius: 0 4px 4px 0; }
.before ul, .before p { color: var(--bad); }
.arrow { margin: 2px 0 2px 10px; color: var(--muted); font-size: 15px; line-height: 1; }
.after.changed { padding: 4px 8px 4px 10px; border-left: 3px solid var(--application); background: var(--application-bg); border-radius: 0 4px 4px 0; }
.mark { display: inline-block; margin: 2px 0 2px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }
.mark-before { color: var(--bad); }
.mark-after { color: var(--application); }
.editable-list { list-style: disc; }
.editable { padding: 1px 3px; margin: 0 -3px; border-radius: 3px; outline: none; cursor: text; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.editable:hover { background: rgba(43, 94, 167, 0.08); }
.editable:focus { background: #fff; box-shadow: 0 0 0 2px var(--focus); }
.editable:empty::before { content: attr(data-placeholder); color: var(--muted); font-style: italic; }
.editable.edited { background: #fff4d6; box-shadow: inset 0 -2px 0 var(--focus); }
