:root {
  --bg: #f3f7f7;
  --surface: #ffffff;
  --surface-2: #e6f4f4;
  --ink: #1f3135;
  --muted: #5f7478;
  --line: #d4e3e3;
  --line-strong: #abc8c9;
  --teal: #0f7f88;
  --teal-dark: #0f6169;
  --navy: #0f7f88;
  --amber: #9a6518;
  --amber-bg: #fff4dc;
  --red: #a33c35;
  --red-bg: #fbe7e4;
  --green-bg: #e4f4ec;
  --shadow: 0 8px 22px rgba(37, 104, 108, 0.08);
  color: var(--ink);
  font-family: "Yu Gothic UI", Meiryo, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: linear-gradient(180deg, #62bec0 0%, #4ba8aa 100%);
  color: #fff;
}

.brand {
  display: grid;
  gap: 8px;
  min-height: 112px;
  margin-bottom: 12px;
}

.brand__mark {
  display: none;
}

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

.brand strong {
  font-size: 27px;
  line-height: 1.1;
}

.brand span {
  margin-top: 3px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a {
  color: #ffffff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
  font-weight: 700;
}

.nav a.is-active,
.nav a:hover {
  background: #0f7f88;
  border-color: #0f7f88;
  color: #ffffff;
}

.side-note {
  margin-top: 28px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.side-note p {
  color: #ffffff;
  line-height: 1.6;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar,
.panel__head,
.button-row,
.panel__actions,
.topbar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.topbar__buttons {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar__actions .button,
.topbar__buttons .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
}

.topbar,
.panel__head {
  justify-content: space-between;
}

.topbar {
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.25;
}

h2 {
  font-size: 17px;
}

p {
  color: var(--muted);
  margin-top: 5px;
}

.control-strip,
.workflow,
.grid,
.summary-grid {
  display: grid;
  gap: 12px;
}

.control-strip {
  grid-template-columns: 1.2fr 1.4fr 180px auto;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workflow {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 14px;
}

.workflow__step {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-weight: 700;
}

.workflow__step.is-active {
  background: #dff1ee;
  color: var(--teal-dark);
  border-color: #9acdc8;
}

.workflow__step.is-done {
  background: var(--green-bg);
  color: #256b48;
}

.grid {
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.1fr);
}

.panel {
  min-width: 0;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel--upload {
  align-self: start;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.toggle span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(17, 122, 122, 0.2);
  border-color: var(--teal);
}

.toggle {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle input {
  width: 16px;
  height: 16px;
}

.button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}

.button:hover {
  border-color: var(--teal);
}

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

.button--secondary {
  background: #edf4f8;
}

.button--danger {
  color: var(--red);
  border-color: #e4b8b1;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #edf4f8;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge--warning {
  background: var(--amber-bg);
  color: var(--amber);
}

.badge--error {
  background: var(--red-bg);
  color: var(--red);
}

.badge--ok {
  background: var(--green-bg);
  color: #256b48;
}

.drop-zone {
  min-height: 176px;
  border: 2px dashed #9fc8c8;
  border-radius: 8px;
  background: #f6fbfb;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  cursor: pointer;
  text-align: center;
}

.drop-zone input {
  display: none;
}

.drop-zone__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  position: relative;
}

.drop-zone__icon::before {
  content: "+";
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -52%);
  line-height: 1;
}

.drop-zone small {
  color: var(--muted);
}

.image-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.image-item {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdfe;
}

.image-item img,
.image-item__pdf {
  width: 54px;
  height: 44px;
  border-radius: 5px;
  object-fit: cover;
  background: #e8eef3;
}

.image-item__pdf {
  display: grid;
  place-items: center;
  color: var(--navy);
  font-weight: 800;
}

.image-item strong,
.image-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-item span {
  color: var(--muted);
  font-size: 12px;
}

.api-contract {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
}

.api-contract div {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
}

.api-contract dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.api-contract dd {
  margin: 0;
  min-width: 0;
}

.schema-preview {
  margin: 0;
  min-height: 158px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #162633;
  color: #eaf5f7;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
}

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

.table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  background: #f7fafb;
  font-size: 12px;
}

.table--ocr-results {
  min-width: 1040px;
  table-layout: fixed;
}

.table--ocr-results thead th,
.table--ocr-results thead th.num {
  text-align: center !important;
  white-space: nowrap;
}

.table--ocr-results th:nth-child(1),
.table--ocr-results td:nth-child(1) {
  width: 72px;
  min-width: 72px;
  text-align: center;
}

.table--ocr-results th:nth-child(2),
.table--ocr-results td:nth-child(2) {
  width: 96px;
  min-width: 96px;
  text-align: center;
}

.table--ocr-results th:nth-child(3),
.table--ocr-results td:nth-child(3) {
  width: 136px;
  min-width: 136px;
}

.table--ocr-results th:nth-child(4),
.table--ocr-results td:nth-child(4) {
  width: 360px;
  min-width: 360px;
}

.table--ocr-results th:nth-child(5),
.table--ocr-results td:nth-child(5),
.table--ocr-results th:nth-child(6),
.table--ocr-results td:nth-child(6),
.table--ocr-results th:nth-child(7),
.table--ocr-results td:nth-child(7) {
  width: 128px;
  min-width: 128px;
}

.table--ocr-results th:nth-child(8),
.table--ocr-results td:nth-child(8) {
  width: 86px;
  min-width: 86px;
  text-align: center;
}

.table--ocr-results input.description {
  min-width: 100%;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.table input[type="date"],
.table input[type="text"],
.table input[type="number"] {
  min-width: 92px;
  height: 34px;
}

.table input.description {
  min-width: 260px;
}

.row-status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.row-status--ok {
  background: var(--green-bg);
  color: #256b48;
}

.row-status--review {
  background: var(--amber-bg);
  color: var(--amber);
}

.row-status--approved {
  background: #e8eef8;
  color: var(--navy);
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  margin-bottom: 12px;
}

.summary-grid div {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  display: grid;
  align-content: space-between;
}

.summary-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-grid strong {
  font-size: 22px;
}

.table--preview {
  min-width: 760px;
}

.audit-log {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.audit-log li {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 260px;
  border-radius: 8px;
  background: var(--teal-dark);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .control-strip,
  .grid,
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .panel__head,
  .button-row,
  .panel__actions,
  .topbar__actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar__buttons,
  .topbar__actions .button,
  .topbar__buttons .button {
    width: 100%;
  }

  .control-strip,
  .workflow,
  .grid,
  .summary-grid,
  .api-contract div {
    grid-template-columns: 1fr;
  }
}
