:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #f9fbfc;
  --ink: #172026;
  --muted: #68747d;
  --line: #dce3e8;
  --accent: #007a78;
  --accent-strong: #005f5d;
  --accent-soft: #dff4f1;
  --danger: #c53b34;
  --danger-soft: #fde9e7;
  --warning: #a86b00;
  --warning-soft: #fff0cf;
  --success: #20734c;
  --success-soft: #e1f3ea;
  --shadow: 0 18px 50px rgba(27, 39, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(0, 122, 120, 0.12), rgba(255, 255, 255, 0) 42%),
    var(--bg);
}

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

.login-brand {
  color: var(--ink);
}

.login-brand span {
  color: var(--muted);
}

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

.login-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.login-card label {
  display: grid;
  gap: 7px;
}

.login-card label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-card input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.login-card input:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.login-submit {
  width: 100%;
  min-height: 44px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 750;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #172026;
  color: #f7fbfb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #2fb8ad;
  color: #062421;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: #aebcc4;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ced9de;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

.icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: #63d3c8;
}

.sidebar-panel {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.panel-kicker,
.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-panel strong {
  display: block;
  line-height: 1.3;
}

.sidebar-panel p {
  margin: 10px 0 0;
  color: #b7c4cb;
  font-size: 13px;
  line-height: 1.5;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.topbar h1 {
  max-width: 860px;
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.07;
}

.connection-strip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin-top: 14px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #94a3ad;
}

.connection-strip.live .connection-dot {
  background: var(--success);
}

.connection-strip.demo .connection-dot {
  background: var(--warning);
}

.connection-strip.error .connection-dot {
  background: var(--danger);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  font-weight: 750;
  white-space: nowrap;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: var(--surface);
  color: var(--ink);
}

.ghost-button:hover,
.icon-button:hover {
  border-color: #b9c7cf;
  transform: translateY(-1px);
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card {
  min-height: 132px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: 30px;
  line-height: 1;
}

.metric-card.warning {
  border-color: #f1c980;
  background: #fffaf0;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  align-items: start;
}

.main-column {
  min-width: 0;
}

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

.segmented-control {
  display: flex;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segment {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.segment.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(420px, 100%);
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
}

.invoice-table-section,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-header,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.section-header h2,
.section-header h3,
.detail-header h2,
.extracted-data h3,
.recommendation h3,
.alerts h3,
.ocr-result h3 {
  margin: 0;
}

.section-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.section-header.compact {
  padding: 0;
  border: 0;
}

.invoice-table {
  display: grid;
}

.invoice-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) 130px 130px 120px 116px;
  gap: 14px;
  align-items: center;
  min-height: 78px;
  padding: 14px 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}

.invoice-row:last-child {
  border-bottom: 0;
}

.invoice-row:hover,
.invoice-row.selected {
  background: var(--surface-strong);
}

.invoice-row strong,
.invoice-row span,
.invoice-row small {
  display: block;
}

.invoice-row small {
  margin-top: 4px;
  color: var(--muted);
}

.amount {
  font-weight: 800;
}

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

.status-pill,
.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-review {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-approved {
  background: var(--success-soft);
  color: var(--success);
}

.status-processing {
  background: #e8eefb;
  color: #334d8f;
}

.risk-badge.low {
  background: var(--success-soft);
  color: var(--success);
}

.risk-badge.medium {
  background: var(--warning-soft);
  color: var(--warning);
}

.risk-badge.high {
  background: var(--danger-soft);
  color: var(--danger);
}

.detail-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
}

.detail-header {
  margin-bottom: 16px;
}

.detail-header h2 {
  margin-top: 8px;
  font-size: 22px;
}

.document-preview {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.document-preview span {
  display: block;
  color: var(--muted);
}

.document-preview strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
}

.paper {
  height: 156px;
  padding: 18px 16px;
  border: 1px solid #cfd9df;
  border-radius: 6px;
  background: #ffffff;
}

.paper-line {
  height: 8px;
  width: 64%;
  margin-bottom: 10px;
  border-radius: 4px;
  background: #d9e2e7;
}

.paper-line.wide {
  width: 82%;
}

.paper-line.short {
  width: 42%;
}

.paper-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 20px;
}

.paper-grid span {
  height: 16px;
  border-radius: 3px;
  background: #edf2f5;
}

.extracted-data,
.recommendation,
.alerts,
.ocr-result {
  margin-top: 18px;
}

.data-form {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
}

.data-form label {
  display: grid;
  gap: 5px;
}

.data-form span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.data-form input {
  width: 100%;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}

.data-form input:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.data-form input:disabled {
  background: var(--surface-strong);
  color: var(--muted);
}

.save-fields-button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.save-fields-button:hover {
  background: var(--accent-strong);
}

.advice-box {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
  background: #eef8f6;
}

.advice-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.advice-line span {
  color: var(--muted);
}

.advice-line strong {
  text-align: right;
}

.alerts ul {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.alerts li {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

.method-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e8eefb;
  color: #334d8f;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.method-badge.ready {
  background: var(--success-soft);
  color: var(--success);
}

.method-badge.empty {
  background: var(--warning-soft);
  color: var(--warning);
}

.file-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.file-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-top: 10px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.file-link:hover {
  border-color: #b9c7cf;
  background: var(--surface-strong);
}

.file-link.disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.64;
}

.file-link.disabled:hover {
  border-color: var(--line);
  background: var(--surface);
}

.ocr-result pre {
  max-height: 220px;
  margin: 10px 0 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: #263139;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172026;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 38, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(520px, 100%);
  max-height: min(680px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(23, 32, 38, 0.22);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.modal-body p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.modal-stat {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-strong);
}

.modal-stat span {
  color: var(--muted);
}

.modal-stat strong {
  text-align: right;
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .sidebar {
    padding: 18px 12px;
    align-items: center;
  }

  .brand div:not(.brand-mark),
  .nav-item:not(.active) {
    font-size: 0;
  }

  .nav-item {
    justify-content: center;
    padding: 9px;
  }

  .sidebar-panel {
    display: none;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    justify-content: space-between;
    padding: 12px;
  }

  .brand div:not(.brand-mark),
  .nav-list {
    display: none;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .toolbar {
    display: grid;
  }

  .topbar-actions,
  .segmented-control {
    justify-content: stretch;
    overflow-x: auto;
  }

  .primary-button,
  .ghost-button {
    flex: 1;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .invoice-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }
}

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

  .document-preview {
    grid-template-columns: 1fr;
  }

  .paper {
    width: 132px;
  }

}
