/* ===== Top bar ===== */
.top-bar {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
}

@media (max-width: 860px) {
  .top-bar { padding: 10px 14px; }
}

.top-bar-left { display: flex; align-items: center; gap: 12px; }
.top-bar-right { display: flex; align-items: center; gap: 8px; }

.logo-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.balance-chip {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1.3px solid currentColor;
  white-space: nowrap;
}

.balance-chip.ok { color: var(--success); }
.balance-chip.low { color: var(--warn); }

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 600px) { .user-name { display: none; } }

.btn-logout,
.btn-topbar {
  background: transparent;
  border: 1.3px solid var(--line-soft);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 5px 12px;
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-topbar:hover:not(:disabled) { background: var(--surface-hover); color: var(--ink); }
.btn-logout:hover:not(:disabled) { background: var(--surface-hover); color: var(--error); border-color: var(--error); }

/* ===== Buttons ===== */
.btn {
  background: var(--accent);
  color: var(--accent-text);
  border: 1.3px solid var(--accent);
  border-radius: var(--border-radius);
  padding: 12px 24px;
  cursor: pointer;
  font-weight: 600;
  font-family: var(--font-sans);
  font-size: 15px;
  letter-spacing: 0.075px;
  line-height: normal;
  transition: background 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--line-soft);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--neutral-300);
  color: var(--ink);
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.row--end { justify-content: flex-end; }
.row--center { justify-content: center; }

/* ===== Cards ===== */
.card {
  border-radius: var(--border-radius-lg);
  padding: 28px;
  margin-bottom: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.card h2,
.card h3 { margin-bottom: 16px; }

/* ===== Forms ===== */
.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-title);
  letter-spacing: 0.07px;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.3px solid var(--line);
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
  font-size: 15px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}

textarea {
  resize: vertical;
  font-family: var(--font-sans);
  line-height: 22px;
}

input:focus,
select:focus,
textarea:focus { border-color: var(--accent); }

input[type="file"] {
  padding: 8px 10px;
  background: var(--surface-subtle);
  cursor: pointer;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 18px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--ink); }

.tab.tab--active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ===== Key/value list ===== */
.kv {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 24px;
  margin: 0 0 20px 0;
  font-size: 14px;
}

.kv dt {
  color: var(--muted);
  font-weight: 500;
}

.kv dd {
  margin: 0;
  color: var(--text-title);
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.kv dd.cost {
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
}

.kv-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

/* ===== Alerts ===== */
.alert {
  border-radius: var(--border-radius);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 20px;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert--warn {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

.alert--info {
  background: var(--color-primary-50);
  color: var(--color-primary-900);
  border-color: var(--color-primary-150);
}

/* ===== Spinner ===== */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 8px auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ===== Login ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-subtle);
  padding: 24px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.login-card .logo { max-width: 180px; margin-bottom: 4px; }
.login-card h1 { font-size: 22px; line-height: 28px; }
.login-card .sub { font-size: 14px; }

.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  border: 1.3px solid var(--line);
  border-radius: var(--border-radius);
  background: var(--panel);
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.btn-oauth:hover { background: var(--surface-hover); border-color: var(--neutral-300); }
.btn-oauth svg { flex-shrink: 0; }

.login-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.email-section,
.otp-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-email {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 16px;
  background: var(--ink);
  color: var(--panel);
  border: 1.3px solid var(--ink);
  border-radius: var(--border-radius);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-email:hover { opacity: 0.85; }
.btn-email:disabled { opacity: 0.5; cursor: default; }

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-link:hover { color: var(--ink); }

.otp-input {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 10px;
  padding: 11px 8px;
}

.otp-instruction {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
  text-align: center;
}

.login-legal-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.login-legal-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.login-legal-link:hover { color: var(--ink); }

/* ===== Comparison full-page view (.docx preview) =====
 * Activated by `body.compare-active`, which also hides the page header
 * + tabs and lets <main> expand to the full viewport width so the two
 * columns aren't squeezed by the 880-px page container.
 */
body.compare-active main { max-width: 100%; padding: 16px 20px 20px; }
body.compare-active .header-container,
body.compare-active .tabs { display: none; }

.compare {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 96px);       /* top bar (~56) + main top padding (~16) + margin */
  gap: 12px;
}

.compare__header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 4px 0;
  flex-wrap: wrap;
}

.compare__back {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  flex: 0 0 auto;
}

.compare__title {
  flex: 1 1 auto;
  min-width: 200px;
}

.compare__title h2 {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 26px;
}

.compare__title .caption {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.compare__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.compare__actions .btn {
  padding: 8px 16px;
  font-size: 13px;
}

.compare__actions .btn:disabled {
  opacity: 0.4;
}

.compare__grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-height: 0;                     /* allow flex children to overflow */
}

@media (max-width: 860px) {
  .compare__grid { grid-template-columns: 1fr; }
}

.compare__col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
}

.compare__col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.compare__col-header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.compare__col-header .btn {
  padding: 6px 14px;
  font-size: 13px;
}

.compare__preview-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.compare__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(2px);
  z-index: 5;
}

.compare__overlay.hidden { display: none; }

.compare__preview {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  background: var(--panel);
}

/* ===== Rendered .docx preview =====
 * docx-preview injects its own <style> tags into <head> with classes like
 * `.docx_styleName`, applied inline to runs/paragraphs. We deliberately keep
 * .docx-preview itself style-free so the library's per-document styling
 * wins (fonts, sizes, colors, alignment all come from the .docx).
 */
.docx-preview {
  color: var(--ink);
  /* Native .docx pages are ~8.5in wide; let the rendered content keep
     its intended page width but cap it for narrow viewports. */
  max-width: 100%;
}

/* Highlight overlay — works the same whether the renderer is
 * docx-preview, LibreOffice HTML, or our legacy server-rendered HTML. */
.docx-preview mark.anon-hl,
mark.anon-hl {
  background: var(--highlight-soft);
  padding: 0 1px;
  border-radius: 2px;
  color: inherit;
}

/* docx-preview sometimes wraps sections in inline-block elements with
 * fixed width matching the original .docx page. Let them scroll instead
 * of overflowing the column. */
.compare__preview section.docx,
.compare__preview .docx {
  max-width: 100%;
  box-sizing: border-box;
}

/* ===== Result output ===== */
.output-box {
  width: 100%;
  min-height: 240px;
  border: 1px solid var(--line);
  border-radius: var(--border-radius);
  padding: 14px 16px;
  background: var(--surface-subtle);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 22px;
  resize: vertical;
  outline: none;
}

/* ===== Placeholder review / remap ===== */
.review {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review__row {
  display: grid;
  grid-template-columns: minmax(96px, auto) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

@media (max-width: 640px) {
  .review__row {
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
}

.review__token {
  font-family: var(--font-mono, monospace);
  font-size: 13px;
  color: var(--accent);
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  white-space: nowrap;
  justify-self: start;
}

.review__original {
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review__original .count {
  font-size: 12px;
  opacity: 0.8;
}

.review__input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
}

.review__input:focus {
  border-color: var(--accent);
}

/* Remap panel inside the compare view (collapsible) */
.compare__remap {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.compare__remap > summary {
  cursor: pointer;
  padding: 12px 24px;
  font-weight: 600;
  color: var(--ink);
  list-style: none;
}

.compare__remap > summary::-webkit-details-marker { display: none; }

.compare__remap > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.compare__remap[open] > summary::before { transform: rotate(90deg); }

.compare__remap__body {
  padding: 4px 24px 18px;
  max-height: 38vh;
  overflow-y: auto;
}

.compare__remap__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ===== Add / remove PII corrections ===== */

/* Original text rendered for the text path so detections can be clicked
 * (remove) or selected (add). Mirrors the .docx left preview. */
.pii-source {
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  border-radius: var(--border-radius);
  padding: 14px 16px;
  background: var(--surface-subtle);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 22px;
  max-height: 320px;
  overflow-y: auto;
}

/* A highlighted detection is removable on click. */
.pii-source mark.anon-hl,
.compare__preview mark.anon-hl {
  cursor: pointer;
}
/* Hovering a removable highlight signals deletion (red), not selection. */
.pii-source mark.anon-hl:hover,
.compare__preview mark.anon-hl:hover {
  outline: 1.5px solid var(--error);
  background: rgba(239, 68, 68, 0.18);
}
/* Held state while the "Remover?" confirm popover is open. */
.pii-source mark.anon-hl.anon-hl--pending,
.compare__preview mark.anon-hl.anon-hl--pending {
  outline: 1.5px solid var(--error);
  background: rgba(239, 68, 68, 0.22);
}

/* "Add a missed item" control: value + category + button(s). */
.add-pii {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.add-pii__value {
  flex: 1 1 240px;
  min-width: 0;
}
.add-pii .combo {
  flex: 0 0 160px;
  position: relative;
}
.add-pii .combo .add-pii__cat {
  flex: none;
  width: 100%;
}
.add-pii__value,
.add-pii__cat {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
}
.add-pii__value:focus,
.add-pii__cat:focus { border-color: var(--accent); }

/* Edit bar above the compare grid. */
.compare__editbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.compare__editbar .add-pii { margin-top: 6px; }
.compare__editbar__hint {
  font-size: 13px;
  color: var(--muted);
}

/* Each review item now groups the remap row with its per-occurrence list. */
.review__item {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft, var(--line));
}
.review__occs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 0 8px;
}
.review__occ {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.review__occ-ctx {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.review__occ-x {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 3px 7px;
}
.review__occ-x:hover {
  border-color: var(--danger, #c0392b);
  color: var(--danger, #c0392b);
}

/* ===== Category combobox (styled replacement for native <datalist>) ===== */
.combo { position: relative; }
.combo__menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 4px;
}
.combo__option {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.combo__option:hover,
.combo__option.is-active {
  background: var(--surface-hover);
}

/* ===== "Remover este realce?" confirm popover ===== */
.remove-pop {
  position: absolute;
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
}
.remove-pop__msg {
  color: var(--ink);
  white-space: nowrap;
}
.remove-pop button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  background: var(--panel);
  color: var(--ink);
}
.remove-pop__no:hover { background: var(--surface-hover); }
.remove-pop__yes {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
.remove-pop__yes:hover { filter: brightness(0.95); }
