:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #14171f;
  --text-strong: #080b12;
  --muted: #657083;
  --muted-2: #8993a3;
  --line: #d9dee7;
  --line-strong: #c7cfdb;
  --accent: #0f766e;
  --accent-2: #1d4ed8;
  --accent-dark: #115e59;
  --danger: #b42318;
  --warning: #b45309;
  --shadow: 0 12px 34px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 5px 18px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 260px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 28px;
  border-bottom: 1px solid rgba(217, 222, 231, 0.9);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-strong);
  font-weight: 780;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: #121826;
  color: #fff;
  font-size: 0.72rem;
  letter-spacing: 0;
}

.shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 28px auto 42px;
}

.panel {
  background: var(--surface);
  border: 1px solid rgba(217, 222, 231, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.page-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--text-strong);
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 1.02;
  letter-spacing: 0;
  max-width: 820px;
}

.upload-screen {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(380px, 1.05fr);
  gap: 32px;
  align-items: start;
  padding-top: 24px;
}

.upload-form {
  display: grid;
  gap: 18px;
  padding: 22px;
}

label {
  display: grid;
  gap: 8px;
  color: #2d3542;
  font-weight: 720;
}

input[type="text"],
input[type="file"],
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input[type="text"]:focus,
input[type="file"]:focus,
select:focus {
  border-color: rgba(15, 118, 110, 0.62);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

.file-drop {
  min-height: 136px;
  align-content: center;
  padding: 22px;
  border: 1px dashed #aab4c3;
  border-radius: 8px;
  background: linear-gradient(180deg, #fbfcfe, #f5f8fb);
}

.file-drop-title {
  color: var(--text-strong);
  font-size: 1.05rem;
}

.file-drop input[type="file"] {
  border-style: solid;
  background: #fff;
}

.grid.two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 250px);
  gap: 14px;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: #374151;
  font-size: 0.9rem;
  font-weight: 680;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 7px;
  padding: 10px 16px;
  border: 1px solid transparent;
  font-weight: 780;
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease;
}

.primary {
  color: #fff;
  background: #111827;
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.16);
}

.primary:hover {
  background: #0f766e;
  transform: translateY(-1px);
}

.secondary {
  color: #263142;
  background: rgba(255, 255, 255, 0.92);
  border-color: var(--line);
}

.secondary:hover {
  border-color: var(--line-strong);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.summary {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 18px;
}

.summary h1 {
  font-size: clamp(1.9rem, 3vw, 2.7rem);
}

.stats,
.result-metrics {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.stats span,
.result-metrics span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.86);
  color: #475569;
  font-weight: 760;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.review-form {
  display: grid;
  gap: 14px;
}

.toolbar,
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar {
  justify-content: flex-end;
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(430px, 0.88fr) minmax(0, 1.12fr);
  gap: 16px;
  align-items: start;
}

.preview-panel,
.table-wrap {
  background: var(--surface);
  border: 1px solid rgba(217, 222, 231, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.preview-panel {
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 104px);
  overflow: hidden;
  padding: 14px;
}

.preview-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preview-header h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: 1rem;
  line-height: 1.25;
  max-width: 320px;
  overflow-wrap: anywhere;
}

.preview-count {
  flex: 0 0 auto;
  border: 1px solid #c7ded9;
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--accent-dark);
  background: #eef7f5;
  font-size: 0.8rem;
  font-weight: 820;
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-size: 1.14rem;
  font-weight: 860;
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.icon-button:disabled {
  opacity: 0.42;
  cursor: default;
}

.page-indicator {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 740;
  margin-right: auto;
}

.preview-scroll {
  max-height: calc(100vh - 250px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #dfe5ed;
  padding: 14px;
}

.pdf-stage {
  position: relative;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.22);
}

.pdf-page-image {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
}

.preview-box {
  position: absolute;
  padding: 0;
  border: 2px solid rgba(180, 35, 24, 0.92);
  border-radius: 3px;
  background: rgba(180, 35, 24, 0.14);
  cursor: pointer;
}

.preview-box:hover,
.preview-box.is-hovered {
  border-color: var(--accent-2);
  background: rgba(29, 78, 216, 0.17);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.16);
}

.preview-state {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 760;
}

.preview-error {
  color: var(--danger);
}

.variables-panel {
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
}

.variables-panel .table-wrap {
  max-height: calc(100vh - 178px);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 820px;
}

th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f6f8fb;
  color: #526072;
  font-size: 0.74rem;
  font-weight: 860;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

tr[data-variable-id] td {
  background: #fff;
  transition: background 120ms ease;
}

tr[data-variable-id]:hover td {
  background: #f7fbfb;
}

.content-cell {
  max-width: 520px;
  color: #202938;
  font-weight: 620;
  overflow-wrap: anywhere;
}

.type-pill {
  display: inline-flex;
  max-width: 160px;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #f1f5f9;
  color: #334155;
  font-size: 0.82rem;
  font-weight: 760;
}

code {
  border-radius: 6px;
  padding: 4px 7px;
  background: #eef7f5;
  color: var(--accent-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  font-weight: 780;
}

.muted {
  color: var(--muted);
  line-height: 1.5;
}

.loading {
  display: none;
  color: var(--muted);
  font-weight: 760;
}

.htmx-request .loading,
.loading.htmx-request {
  display: block;
}

.floating-loading {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
}

.result-panel,
.error-panel {
  display: grid;
  gap: 18px;
  max-width: 760px;
  margin: 42px auto;
  padding: 26px;
}

.result-panel h1,
.error-panel h1 {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.error-panel h1 {
  color: var(--danger);
}

.empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 22px;
  color: var(--muted);
}

@media (max-width: 1080px) {
  .upload-screen,
  .review-layout {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: relative;
    top: auto;
    max-height: none;
  }

  .preview-scroll,
  .variables-panel .table-wrap {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 0 16px;
  }

  .shell {
    width: min(100vw - 20px, 1440px);
    margin: 18px auto 28px;
  }

  .upload-screen {
    padding-top: 8px;
    gap: 18px;
  }

  .upload-form,
  .result-panel,
  .error-panel {
    padding: 18px;
  }

  .grid.two,
  .summary {
    grid-template-columns: 1fr;
    display: grid;
  }

  .summary {
    align-items: start;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar .primary,
  .toolbar .secondary,
  .actions .primary,
  .actions .secondary {
    width: 100%;
  }

  .preview-controls {
    flex-wrap: wrap;
  }
}
