:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --line: #ccd4dd;
  --text: #17202a;
  --muted: #66727f;
  --blue: #2459a6;
  --green: #167a43;
  --red: #a93434;
  --amber: #9a650d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 24px;
  background: #27313b;
  color: white;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

header p {
  margin-top: 4px;
  color: #d6dbe1;
}

nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

nav a,
nav button,
.button,
button {
  border: 1px solid #174684;
  background: var(--blue);
  color: white;
  padding: 8px 12px;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}

nav form {
  margin: 0;
}

.secondary {
  background: #eef3f8;
  color: var(--blue);
}

.danger {
  border-color: #8f2727;
  background: var(--red);
  color: white;
}

.danger-zone {
  border-color: #ddb6b6;
}

.delete-form {
  margin-top: 0;
}

.muted {
  color: var(--muted);
  margin-top: 8px;
}

.warn {
  color: var(--amber);
  font-weight: 700;
}

.notice {
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 10px 12px;
  margin-top: 12px;
  line-height: 1.4;
}

.notice.warning {
  border-color: #e3c477;
  background: #fff8e6;
  color: #5c3d08;
}

.ai-disclaimer {
  border-color: #e3c477;
  background: #fff8e6;
  display: grid;
  gap: 4px;
}

.mode-options {
  border: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 10px;
  padding: 10px 12px 12px;
}

.mode-options legend {
  padding: 0 6px;
  font-weight: 700;
}

.mode-options label,
.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.mode-options input,
.checkbox-line input {
  width: auto;
}

.inline-checkbox {
  align-items: center;
  display: inline-flex;
  flex-direction: row;
  gap: 8px;
  font-weight: 400;
}

.inline-checkbox input {
  width: auto;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.mode-card {
  border: 1px solid var(--line);
  background: #f8fafc;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  padding: 14px;
}

.mode-card.selected {
  border-color: var(--blue);
  background: #eef5ff;
  box-shadow: inset 0 0 0 1px var(--blue);
}

.mode-card input {
  grid-row: span 2;
  margin-top: 2px;
  width: auto;
}

.mode-card h4 {
  margin: 0;
  font-size: 16px;
}

.mode-card p {
  grid-column: 2;
}

.identity-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.segmented-field {
  border: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
}

.segmented-field legend {
  font-weight: 700;
  margin-bottom: 8px;
  width: 100%;
}

.segmented-field label {
  align-items: center;
  border: 1px solid var(--line);
  cursor: pointer;
  display: inline-flex;
  flex-direction: row;
  gap: 8px;
  padding: 9px 12px;
}

.segmented-field input {
  margin: 0;
  width: auto;
}

.document-group {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 12px;
}

.optional-document-upload {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr;
  gap: 12px;
}

.review-stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.review-stage {
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 14px;
}

.review-stage.active {
  border-color: #9db8dc;
  background: #f4f8ff;
}

.review-stage.reserved {
  background: #fafafa;
  color: var(--muted);
}

.review-stage h4 {
  margin: 0 0 10px;
}

.review-stage ul {
  margin: 0;
  padding-left: 18px;
}

.review-stage li + li {
  margin-top: 6px;
}

.case-options {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}

.case-option {
  border: 1px solid var(--line);
  background: #f8fafc;
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  padding: 12px;
  font-weight: 400;
}

.case-option input {
  width: 16px;
  margin-top: 2px;
}

.case-option strong,
.case-option small {
  display: block;
}

.case-option small {
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
}

.guide-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.guide-head h2 {
  font-size: 24px;
  margin-top: 5px;
}

.guide-head p {
  color: var(--muted);
  margin-top: 6px;
}

.guide-role {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.guide-jumps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 16px;
}

.guide-jumps a {
  border-bottom: 2px solid transparent;
  color: var(--blue);
  font-weight: 700;
  padding: 7px 2px 5px;
  text-decoration: none;
}

.guide-jumps a:hover {
  border-bottom-color: var(--blue);
}

.guide-section-head {
  align-items: baseline;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.guide-section-head > span {
  color: var(--muted);
}

.guide-process {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
}

.guide-process li {
  border-top: 2px solid #9db8dc;
  display: grid;
  gap: 10px;
  padding: 14px 18px 10px 0;
}

.guide-process li > span,
.guide-step-list li > span,
.guide-order-list li > span {
  align-items: center;
  background: var(--blue);
  color: #fff;
  display: inline-flex;
  font-weight: 700;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.guide-process strong,
.guide-process small {
  display: block;
}

.guide-process small {
  color: var(--muted);
  line-height: 1.35;
  margin-top: 5px;
}

.guide-choice-list {
  border-top: 1px solid var(--line);
  margin-top: 16px;
}

.guide-choice {
  align-items: start;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(180px, .65fr) 1.35fr;
  padding: 16px 0;
}

.guide-choice strong,
.guide-choice span {
  display: block;
}

.guide-choice strong {
  font-size: 16px;
}

.guide-choice span,
.guide-choice p {
  color: var(--muted);
  line-height: 1.45;
}

.guide-choice span {
  margin-top: 4px;
}

.guide-disclosure {
  padding: 0;
}

.guide-disclosure > summary {
  cursor: pointer;
  display: grid;
  gap: 4px;
  list-style: none;
  padding: 19px 22px;
  position: relative;
}

.guide-disclosure > summary::-webkit-details-marker {
  display: none;
}

.guide-disclosure > summary::after {
  content: "+";
  color: var(--blue);
  font-size: 22px;
  font-weight: 700;
  position: absolute;
  right: 22px;
  top: 18px;
}

.guide-disclosure[open] > summary::after {
  content: "-";
}

.guide-disclosure > summary span {
  font-size: 18px;
  font-weight: 700;
  padding-right: 40px;
}

.guide-disclosure > summary small {
  color: var(--muted);
}

.guide-detail-body {
  border-top: 1px solid var(--line);
  padding: 4px 22px 22px;
}

.guide-step-list,
.guide-order-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.guide-step-list li,
.guide-order-list li {
  border-bottom: 1px solid #e1e6eb;
  display: grid;
  gap: 14px;
  grid-template-columns: 30px minmax(0, 1fr);
  padding: 16px 0;
}

.guide-step-list strong,
.guide-step-list p,
.guide-order-list strong,
.guide-order-list small {
  display: block;
}

.guide-step-list p,
.guide-order-list small {
  color: var(--muted);
  line-height: 1.45;
  margin-top: 5px;
}

.guide-check-grid {
  display: grid;
  gap: 28px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 18px 0 4px;
}

.guide-check-grid h4 {
  margin: 0 0 8px;
}

.guide-check-grid ul,
.guide-rules {
  line-height: 1.5;
  margin: 0;
  padding-left: 19px;
}

.guide-check-grid li + li,
.guide-rules li + li {
  margin-top: 6px;
}

.guide-boundary {
  border-left: 4px solid var(--red);
  margin-top: 18px;
  padding: 4px 0 4px 14px;
}

.guide-boundary p {
  color: var(--muted);
  line-height: 1.45;
  margin-top: 5px;
}

.guide-order-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.guide-order-list li:nth-child(odd) {
  padding-right: 20px;
}

.guide-order-list li:nth-child(even) {
  border-left: 1px solid #e1e6eb;
  padding-left: 20px;
}

.guide-status-table td:first-child {
  font-weight: 700;
  width: 34%;
}

.guide-final-note {
  align-items: center;
  background: #fff8e6;
  border-color: #e3c477;
  display: flex;
  gap: 12px 24px;
  justify-content: space-between;
}

.guide-final-note span {
  color: #5c3d08;
}

@media (max-width: 720px) {
  .guide-head,
  .guide-section-head,
  .guide-final-note {
    align-items: stretch;
    flex-direction: column;
  }

  .guide-head .button {
    text-align: center;
  }

  .guide-process,
  .guide-order-list {
    grid-template-columns: 1fr;
  }

  .guide-process li {
    grid-template-columns: 30px minmax(0, 1fr);
    padding-right: 0;
  }

  .guide-choice,
  .guide-check-grid {
    gap: 10px;
    grid-template-columns: 1fr;
  }

  .guide-order-list li:nth-child(odd),
  .guide-order-list li:nth-child(even) {
    border-left: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .guide-disclosure > summary {
    padding: 17px 18px;
  }

  .guide-disclosure > summary::after {
    right: 18px;
    top: 16px;
  }

  .guide-detail-body {
    padding: 3px 18px 18px;
  }
}

.file-selection-summary {
  color: var(--muted);
  min-height: 16px;
}

.connect-box {
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 14px;
  margin: 14px 0;
}

.auth-shell {
  min-height: calc(100vh - 130px);
  display: grid;
  place-items: start center;
  padding-top: 32px;
}

.auth-card {
  width: min(100%, 520px);
  background: white;
  border: 1px solid var(--line);
  padding: 24px;
}

.auth-brand {
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.auth-brand h2 {
  font-size: 24px;
}

.auth-brand p {
  color: var(--muted);
  margin-top: 6px;
}

.connection-status {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 12px;
  margin-bottom: 14px;
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.security-note {
  border-left: 4px solid var(--blue);
  background: #f8fafc;
  color: var(--muted);
  padding: 10px 12px;
  line-height: 1.4;
}

.auth-disconnect {
  margin-top: 12px;
}

code {
  background: #edf1f5;
  border: 1px solid var(--line);
  padding: 2px 5px;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
  margin-bottom: 16px;
}

.narrow {
  max-width: 760px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 14px 18px;
  margin-top: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #aab4bf;
  padding: 8px;
  font: inherit;
  background: white;
}

textarea {
  min-height: 88px;
}

.consent {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: flex-start;
  font-weight: 400;
  line-height: 1.4;
}

.consent input {
  width: 18px;
  margin-top: 2px;
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: center;
}

.toolbar,
.case-head,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metrics div {
  background: white;
  border: 1px solid var(--line);
  padding: 14px;
}

.metrics strong {
  display: block;
  font-size: 24px;
}

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

.dashboard-compact h3 {
  margin-bottom: 8px;
}

.connection-strip {
  border: 1px solid var(--line);
  background: #f8fafc;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 16px;
  padding: 10px 12px;
}

.connection-strip a {
  color: var(--blue);
  font-weight: 700;
}

.dashboard-card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
}

.summary-card {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  display: block;
  min-height: 118px;
  padding: 16px;
  text-decoration: none;
}

.summary-card:hover,
.summary-card.selected {
  border-color: var(--blue);
  background: #eef5ff;
  box-shadow: inset 0 0 0 1px var(--blue);
}

.summary-card strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.summary-card span {
  display: block;
  font-weight: 700;
  margin-top: 10px;
}

.summary-card small {
  color: var(--muted);
  display: block;
  line-height: 1.35;
  margin-top: 6px;
}

.credit-strip {
  border: 1px solid var(--line);
  background: #f8fafc;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 14px;
  padding: 10px 12px;
}

.credit-strip a {
  color: var(--blue);
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: minmax(360px, 2fr) minmax(260px, 1fr);
  gap: 18px;
  align-items: start;
}

.compact-table {
  margin-top: 0;
}

.compact-table th,
.compact-table td {
  padding: 7px 8px;
}

.number-cell {
  text-align: right;
  white-space: nowrap;
}

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

.table-scroll table {
  min-width: 980px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

th,
td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #e5ebf2;
}

.status {
  display: inline-block;
  min-width: 120px;
  padding: 5px 8px;
  text-align: center;
  font-weight: 700;
  border: 1px solid var(--line);
  background: #eef1f5;
}

.status.completed {
  color: var(--green);
  background: #eaf7ef;
}

.status.failed {
  color: var(--red);
  background: #fae9e9;
}

.status.processing,
.status.uploading-to-merimen {
  color: var(--amber);
  background: #fff5dc;
}

.upload-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 14px;
  align-items: end;
}

.inline-form {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-top: 12px;
}

.inline-form label {
  max-width: 260px;
}

.compact-form {
  margin-top: 0;
}

.small-button {
  padding: 5px 8px;
  font-size: 12px;
}

dl {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px 16px;
  margin: 16px 0 0;
}

dt {
  color: var(--muted);
  font-weight: 700;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  header,
  .toolbar,
  .case-head,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  nav,
  .upload-form,
  .grid-form,
  .metrics,
  .dashboard-card-grid,
  .summary-grid,
  .review-stage-grid {
    grid-template-columns: 1fr;
    width: 100%;
  }

  nav {
    flex-wrap: wrap;
  }
}
