:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --line: #d7e0e5;
  --line-strong: #aebdc6;
  --text: #18252d;
  --muted: #60727e;
  --primary: #23636e;
  --primary-dark: #194d56;
  --accent: #8b5e34;
  --danger: #a13b3b;
  --shadow: 0 12px 32px rgba(17, 39, 49, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "YuGothic", sans-serif;
  line-height: 1.6;
}

body {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 0 18px;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--primary-dark);
}

button.secondary:hover {
  background: #eef5f6;
}

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

.app-shell {
  min-height: 100vh;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 32px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: clamp(1.55rem, 2.4vw, 2.1rem);
}

h2 {
  font-size: 1.08rem;
}

h3 {
  border-left: 4px solid var(--primary);
  color: var(--primary-dark);
  font-size: 0.96rem;
  padding-left: 9px;
}

.login-form,
.entry-form {
  display: grid;
  gap: 18px;
}

.login-form {
  margin-top: 28px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

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

textarea {
  min-height: 92px;
  resize: vertical;
}

label.needs-review {
  border: 1px solid #d9a34f;
  border-radius: 6px;
  background: #fff8ed;
  padding: 8px;
}

label.needs-review input,
label.needs-review select,
label.needs-review textarea {
  border-color: #d09a3a;
  box-shadow: 0 0 0 2px rgba(217, 163, 79, 0.18);
}

label.is-confirmed input,
label.is-confirmed select,
label.is-confirmed textarea {
  border-color: #8eb9a4;
}

.review-note {
  color: #6b4a18;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.35;
}

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

.form-message {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.workspace {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  align-items: center;
  margin-bottom: 18px;
}

.panel-head {
  margin-bottom: 16px;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.stepper,
.upload-actions,
.export-actions,
.sticky-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stepper {
  margin-bottom: 18px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.stepper button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

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

.step {
  display: none;
}

.step.active {
  display: block;
}

.patient-summary-bar {
  position: sticky;
  top: 8px;
  z-index: 20;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 8px 22px rgba(17, 39, 49, 0.1);
  padding: 10px 12px;
}

.summary-list {
  display: grid;
  grid-template-columns: minmax(220px, 1.8fr) minmax(130px, 1fr) minmax(78px, 0.55fr) minmax(120px, 0.8fr);
  gap: 8px 12px;
  margin: 0;
}

.summary-item {
  min-width: 0;
}

.summary-item dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
}

.summary-item dd {
  overflow: hidden;
  margin: 2px 0 0;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-item dd.is-empty {
  color: var(--muted);
  font-weight: 700;
}

.test-column-header {
  position: sticky;
  top: 78px;
  z-index: 18;
  display: grid;
  grid-template-columns: minmax(170px, 1.15fr) repeat(3, minmax(120px, 1fr));
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(232, 238, 241, 0.98);
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 800;
  margin-bottom: 14px;
  padding: 8px;
}

.test-column-header > div {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.test-period-heading {
  display: grid;
  gap: 2px;
  line-height: 1.25;
}

.test-period-heading small {
  min-height: 1em;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.upload-layout,
.review-layout {
  display: grid;
  grid-template-columns: minmax(280px, 430px) 1fr;
  gap: 16px;
}

.review-layout {
  grid-template-columns: 1fr minmax(280px, 380px);
}

.review-stack {
  display: grid;
  gap: 16px;
}

.file-picker {
  align-items: center;
  min-height: 120px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #f8fbfc;
  justify-items: center;
  padding: 18px;
}

.file-picker span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
}

.file-picker input {
  border: 0;
  padding: 0;
}

.preview-box {
  display: grid;
  min-height: 420px;
  max-height: 70vh;
  overflow: auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef3f5;
}

.preview-box img,
.preview-box object {
  width: 100%;
  height: 100%;
  min-height: 420px;
  object-fit: contain;
}

.field-grid,
.manual-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
}

.test-grid {
  display: grid;
  gap: 10px;
}

.manual-grid {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.category-stack,
.category-block {
  display: grid;
  gap: 18px;
}

.period-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.15fr) repeat(3, minmax(120px, 1fr));
  gap: 8px;
  align-items: end;
}

.period-input {
  display: block;
  min-width: 0;
}

.period-label {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfc;
  color: var(--text);
  display: grid;
  font-size: 0.86rem;
  font-weight: 700;
  place-items: center start;
  padding: 8px 10px;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 10;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  padding: 14px;
}

.check-list,
.record-list,
.duplicate-list {
  display: grid;
  gap: 10px;
}

.check-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

.check-item strong {
  display: block;
}

.check-item.warning {
  border-color: #d9a34f;
  background: #fff8ed;
}

.check-item.ok {
  border-color: #8eb9a4;
  background: #f1faf5;
}

.duplicate-status {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfc;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.duplicate-status.warning {
  border-color: #d9a34f;
  background: #fff8ed;
  color: #6b4a18;
}

.duplicate-status.ok {
  border-color: #8eb9a4;
  background: #f1faf5;
  color: #24533d;
}

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

.duplicate-card.same-date {
  border-color: var(--danger);
  background: #fff7f7;
}

.duplicate-card strong {
  display: block;
}

.duplicate-meta,
.duplicate-reasons {
  color: var(--muted);
  font-size: 0.86rem;
}

.duplicate-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.duplicate-reasons span {
  border-radius: 999px;
  background: #eef3f5;
  padding: 2px 8px;
}

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

.duplicate-actions button {
  min-height: 36px;
  padding-inline: 12px;
}

.search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.record-item {
  display: grid;
  min-height: auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  gap: 2px;
  justify-items: start;
  padding: 11px 12px;
  text-align: left;
}

.record-item:hover {
  border-color: var(--primary);
  background: #f2f8f9;
  color: var(--text);
}

.record-item span,
.selected-record {
  color: var(--muted);
  font-size: 0.88rem;
}

.selected-record {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfc;
  margin-bottom: 14px;
  padding: 12px;
}

.print-preview-panel {
  grid-column: 1 / -1;
}

.print-document {
  color: #111;
  background: #fff;
}

.kenshin-sheet {
  width: 190mm;
  margin: 0 auto;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  font-size: 8.6px;
  line-height: 1.18;
}

.sheet-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  margin-bottom: 4px;
}

.print-document h1 {
  margin: 0;
  letter-spacing: 0.04em;
  text-align: center;
}

.sheet-clinic {
  display: grid;
  min-width: 92px;
  border: 1px solid #9aa7ad;
  padding: 4px 6px;
  text-align: center;
}

.sheet-clinic span {
  font-size: 8px;
}

.sheet-layout {
  display: grid;
  grid-template-columns: 0.98fr 1.42fr;
  gap: 5px;
  align-items: start;
}

.sheet-left,
.sheet-right {
  display: grid;
  gap: 4px;
}

.sheet-section {
  break-inside: avoid;
}

.print-document h2 {
  margin: 0;
  border: 1px solid #9aa7ad;
  border-bottom: 0;
  background: #dfe6e9;
  font-size: 8.8px;
  padding: 2px 4px;
}

.print-document table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: inherit;
}

.print-document th,
.print-document td {
  border: 1px solid #9aa7ad;
  height: 13px;
  padding: 1px 3px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.print-document th {
  background: #f2f5f6;
  font-weight: 700;
}

.sheet-test-table th:first-child {
  width: 31%;
}

.sheet-test-table th:nth-child(2),
.sheet-test-table th:nth-child(3),
.sheet-test-table th:nth-child(4) {
  width: 18%;
  text-align: center;
}

.sheet-test-table th:nth-child(5),
.sheet-test-table td:nth-child(5) {
  width: 15%;
  font-size: 7.2px;
}

.sheet-test-table td {
  text-align: center;
}

.sheet-info-table th {
  width: 36%;
}

.sheet-opinion,
.sheet-judgement {
  margin-top: 5px;
}

.sheet-text-box {
  min-height: 32px;
  border: 1px solid #9aa7ad;
  padding: 5px 6px;
  white-space: normal;
}

.sheet-judgement .sheet-text-box {
  min-height: 22px;
}

.print-document small {
  color: #444;
  font-size: 7px;
}

.is-hidden {
  display: none !important;
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }

  html,
  body {
    background: #fff;
  }

  body * {
    visibility: hidden;
  }

  .print-preview-panel,
  .print-preview-panel * {
    visibility: visible;
  }

  .print-preview-panel {
    position: absolute;
    top: 0;
    left: 0;
    display: block !important;
    width: 100%;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .print-preview-actions {
    display: none !important;
  }

  .kenshin-sheet {
    width: 190mm;
    max-height: 277mm;
    overflow: hidden;
    font-size: 7.4px;
  }

  .print-document h1 {
    font-size: 15px;
  }

  .print-document h2 {
    font-size: 7.8px;
    padding: 1.5px 3px;
  }

  .print-document table {
    font-size: inherit;
    page-break-inside: auto;
  }

  .print-document tr {
    page-break-inside: avoid;
  }

  .print-document th,
  .print-document td {
    height: 10px;
    padding: 1px 2px;
  }

  .sheet-layout {
    gap: 4px;
  }

  .sheet-left,
  .sheet-right {
    gap: 3px;
  }

  .sheet-text-box {
    min-height: 25px;
    padding: 3px 4px;
  }
}

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

  .field-grid,
  .manual-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .period-row {
    grid-template-columns: minmax(140px, 1fr) repeat(3, minmax(88px, 1fr));
  }

  .test-column-header {
    grid-template-columns: minmax(140px, 1fr) repeat(3, minmax(88px, 1fr));
  }

  .summary-list {
    grid-template-columns: minmax(180px, 1fr) minmax(130px, 0.8fr) minmax(74px, 0.5fr) minmax(112px, 0.7fr);
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 14px;
  }

  .topbar,
  .panel-head {
    display: grid;
  }

  .field-grid,
  .manual-grid,
  .search-form {
    grid-template-columns: 1fr;
  }

  .period-row {
    grid-template-columns: 1fr;
  }

  .test-column-header {
    top: 150px;
    grid-template-columns: minmax(80px, 1fr) repeat(3, minmax(58px, 0.65fr));
    gap: 4px;
    font-size: 0.7rem;
    padding: 6px;
  }

  .test-period-heading small {
    font-size: 0.64rem;
  }

  .period-input {
    display: grid;
    gap: 4px;
  }

  .period-input .sr-only {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    white-space: normal;
  }

  .patient-summary-bar {
    top: 0;
    margin-inline: -2px;
    padding: 9px 10px;
  }

  .summary-list {
    grid-template-columns: 1fr 0.75fr;
  }

  .summary-company {
    grid-column: 1 / -1;
  }

  .summary-item dd {
    font-size: 0.9rem;
  }

  .login-panel,
  .panel {
    padding: 18px;
  }

  .stepper button,
  .upload-actions button,
  .export-actions button,
  .sticky-actions button,
  .duplicate-actions button {
    width: 100%;
  }
}
