:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #152033;
  --muted: #667085;
  --line: #d9e0ea;
  --teal: #00a6a6;
  --teal-dark: #087b7b;
  --red: #ff5757;
  --amber: #f4a62a;
  --shadow: 0 18px 45px rgba(21, 32, 51, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand img {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  object-fit: cover;
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.brand span,
.panel-heading p,
.work-header p,
.results-head p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-pill {
  min-width: 104px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
}

.status-pill.ok {
  color: var(--teal-dark);
  border-color: rgba(0, 166, 166, 0.35);
  background: rgba(0, 166, 166, 0.08);
}

.status-pill.error {
  color: #ad2f2f;
  border-color: rgba(255, 87, 87, 0.35);
  background: rgba(255, 87, 87, 0.08);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.user-pill {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.logout-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.logout-link:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
  max-width: 1680px;
  margin: 0 auto;
}

.config-panel,
.workspace {
  min-width: 0;
}

.config-panel {
  align-self: start;
  position: sticky;
  top: 96px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-heading,
.work-header,
.results-head,
.section-block,
.upload-zone,
.results {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-heading {
  padding: 22px;
}

.panel-heading h1,
.work-header h2,
.results-head h2 {
  margin: 4px 0 0;
  font-size: 26px;
  line-height: 1.15;
}

.section-block {
  padding: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 16px;
}

.section-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
}

.section-title > span,
.section-actions > span:first-child {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}

.help-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
}

.info-button {
  width: 24px;
  height: 24px;
  min-height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(0, 166, 166, 0.35);
  border-radius: 50%;
  background: rgba(0, 166, 166, 0.08);
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.info-button:hover,
.info-button:focus-visible {
  border-color: var(--teal);
  background: rgba(0, 166, 166, 0.14);
  outline: none;
}

.tooltip-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: min(280px, calc(100vw - 48px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(21, 32, 51, 0.16);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  text-transform: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 120ms ease, transform 120ms ease, visibility 120ms ease;
}

.help-tooltip:hover .tooltip-panel,
.help-tooltip:focus-within .tooltip-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.account-block {
  display: grid;
  gap: 10px;
}

.usage-meter {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.usage-meter > div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 160ms ease;
}

.usage-meter > div.usage-danger {
  background: var(--red);
}

.account-usage,
.account-subscription,
.account-backend {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.account-subscription {
  color: var(--text);
  font-weight: 800;
}

.account-backend {
  font-size: 12px;
  font-weight: 700;
}

.billing-block {
  display: grid;
  gap: 10px;
}

.plan-list {
  display: grid;
  gap: 8px;
}

.plan-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.plan-card.current {
  border-color: rgba(0, 166, 166, 0.42);
  background: rgba(0, 166, 166, 0.06);
}

.plan-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.plan-head strong,
.plan-head span {
  overflow-wrap: anywhere;
}

.plan-head span {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
}

.plan-card p,
.billing-note {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.plan-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.plan-card .secondary-action,
.plan-card .ghost-action {
  width: 100%;
}

.plan-card .ghost-action:disabled {
  cursor: default;
  border-color: var(--line);
}

.billing-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field > span,
.switch-row span {
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 166, 166, 0.15);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(110px, 0.45fr);
  gap: 10px;
}

.form-grid .field:first-child {
  grid-column: 1 / -1;
}

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

.segmented button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
}

.segmented button.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.segmented.compact button {
  min-height: 34px;
  padding: 7px 10px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  margin-top: 8px;
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.secondary-action,
.ghost-action,
.primary-action {
  border-radius: 7px;
  min-height: 40px;
  padding: 9px 14px;
  font-weight: 800;
  border: 1px solid transparent;
}

.primary-action {
  background: var(--red);
  color: #fff;
}

.primary-action:disabled {
  background: #c3c9d4;
  cursor: not-allowed;
}

.secondary-action {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.secondary-action:hover,
.ghost-action:hover {
  border-color: var(--teal);
}

.ghost-action {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.action-row,
.process-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.company-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.company-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface-2);
}

.company-row strong,
.company-row span {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.company-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.work-header,
.results-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px;
}

.notice {
  display: none;
  border-radius: 8px;
  padding: 13px 14px;
  border: 1px solid rgba(244, 166, 42, 0.35);
  background: rgba(244, 166, 42, 0.12);
  color: #7b4d00;
  font-weight: 700;
}

.notice.show {
  display: block;
}

.upload-zone {
  min-height: 190px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.upload-zone.dragging {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(0, 166, 166, 0.12), var(--shadow);
}

.upload-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-zone .secondary-action {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.upload-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 166, 166, 0.12);
  color: var(--teal-dark);
  font-size: 30px;
  font-weight: 800;
}

.upload-zone strong {
  display: block;
  font-size: 22px;
}

.upload-zone span {
  color: var(--muted);
  display: block;
  margin-top: 4px;
}

.file-list {
  display: grid;
  gap: 8px;
}

.file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
}

.file-row strong {
  overflow-wrap: anywhere;
}

.file-row span {
  color: var(--muted);
  font-size: 13px;
}

.download-list {
  display: grid;
  gap: 8px;
}

.download-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.download-row strong,
.download-row span {
  display: block;
  overflow-wrap: anywhere;
}

.download-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.process-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

#processStatus {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

#processStatus.status-success {
  color: var(--teal-dark);
}

#processStatus.status-error {
  color: #ad2f2f;
}

#processStatus.status-busy {
  color: #6d4b00;
}

.process-alert,
.result-alerts {
  border-radius: 8px;
  padding: 13px 14px;
  font-weight: 700;
  line-height: 1.45;
}

.process-alert.alert-warning,
.result-alerts {
  border: 1px solid rgba(244, 166, 42, 0.35);
  background: rgba(244, 166, 42, 0.12);
  color: #7b4d00;
}

.process-alert.alert-error {
  border: 1px solid rgba(255, 87, 87, 0.35);
  background: rgba(255, 87, 87, 0.1);
  color: #ad2f2f;
}

.results {
  padding: 0;
  overflow: hidden;
}

.results-head {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  border-bottom: 1px solid var(--line);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.result-alerts {
  margin: 16px 16px 0;
  display: grid;
  gap: 6px;
}

.as-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 12px 14px;
  font-weight: 800;
}

.tabs button.active {
  color: var(--teal-dark);
  border-bottom-color: var(--teal);
}

.tab-panel {
  padding: 18px;
}

.data-grid,
.source-grid,
#documentTable,
#nameTable {
  display: grid;
  gap: 10px;
}

.result-block {
  display: grid;
  gap: 10px;
}

.result-block + .result-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.result-block-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.result-block-title h3 {
  margin: 0;
  font-size: 15px;
}

.result-block-title span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kv-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.kv-table thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.kv-table th {
  width: 32%;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.matrix-table th {
  width: auto;
}

.matrix-table td {
  overflow-wrap: anywhere;
}

.kv-table tr:last-child th,
.kv-table tr:last-child td {
  border-bottom: 0;
}

#messageText {
  min-height: 280px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.login-body {
  min-height: 100vh;
}

.login-shell {
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 430px);
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.login-card h1 {
  margin: -8px 0 2px;
  font-size: 28px;
  line-height: 1.12;
}

.google-action {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-weight: 900;
  text-decoration: none;
}

.google-action:hover {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 166, 166, 0.1);
}

.google-mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: #1a73e8;
  font-weight: 900;
}

.login-note {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.legal-mini-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.legal-mini-links a {
  color: var(--teal-dark);
  text-decoration: none;
}

.legal-mini-links a:hover {
  text-decoration: underline;
}

.legal-shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

.legal-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 34px;
}

.legal-kicker {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.legal-card h1 {
  margin: 0 0 20px;
  font-size: 34px;
  line-height: 1.12;
}

.legal-card h2 {
  margin: 26px 0 8px;
  font-size: 18px;
}

.legal-card p {
  margin: 0 0 12px;
  color: var(--text);
  line-height: 1.65;
}

.legal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .config-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    padding: 16px;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .user-pill {
    max-width: 100%;
  }

  .brand img {
    width: 38px;
    height: 38px;
  }

  .app-shell {
    padding: 14px;
  }

  .form-grid,
  .upload-zone,
  .file-row,
  .download-row {
    grid-template-columns: 1fr;
  }

  .upload-zone {
    min-height: 220px;
  }

  .work-header,
  .results-head,
  .process-row {
    align-items: stretch;
    flex-direction: column;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .legal-shell {
    padding: 16px 14px 36px;
  }

  .legal-card {
    padding: 22px;
  }

  .legal-card h1 {
    font-size: 27px;
  }
}
