:root {
  --navy: #12366b;
  --teal: #0f8f91;
  --teal-soft: #e7f6f6;
  --ink: #1f2937;
  --muted: #5b677a;
  --bg: #eef3f8;
  --white: #fff;
  --line: #d5dee8;
  --lent: #b45309;
  --lent-bg: #fff7ed;
  --stored: #0f766e;
  --stored-bg: #ecfdf8;
  --inspect: #1d4ed8;
  --inspect-bg: #eff6ff;
  --flash: #fef08a;
  --shadow: 0 10px 28px rgba(18, 54, 107, 0.08);
  --radius: 14px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

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

.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

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

.topbar h1 {
  margin: 4px 0 0;
  color: var(--navy);
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 800;
  line-height: 1.25;
}

.topbar h1 span {
  font-size: 0.55em;
  font-weight: 700;
  color: var(--muted);
  margin-left: 8px;
}

.topbar__sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

.hint-band {
  background: var(--teal-soft);
  border: 1px solid rgba(15, 143, 145, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  color: var(--navy);
  font-size: 14px;
}

.split {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

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

.panel h2 {
  margin: 0 0 6px;
  color: var(--navy);
  font-size: 18px;
  font-weight: 800;
}

.panel__lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.pair-box {
  display: flex;
  gap: 16px;
  align-items: center;
}

.pair-qr {
  flex: 0 0 auto;
  width: 212px;
  height: 212px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 4px #fff;
}

.pair-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}

.pair-warn {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fef2f2;
  color: #991b1b;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}

.connect-flash {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .25s ease, transform .25s ease;
}

.connect-flash.is-on {
  opacity: 1;
  transform: translateY(0);
}

.pair-qr img,
.pair-qr canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.pair-label {
  margin: 0 0 6px;
  color: var(--navy);
  font-weight: 800;
}

.pair-url {
  margin: 0 0 8px;
  font-size: 12px;
  word-break: break-all;
  color: var(--ink);
  background: #f5f8fc;
  border-radius: 8px;
  padding: 8px 10px;
}

.sample-group + .sample-group { margin-top: 14px; }

.sample-group h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--navy);
  font-weight: 800;
}

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

.sample-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #f8fbfe;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  min-width: 132px;
  transition: border-color .15s ease, transform .15s ease;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.sample-btn em {
  font-style: normal;
}

.sample-btn--lent {
  border-color: rgba(180, 83, 9, 0.45);
  background: var(--lent-bg);
}

.sample-btn--stored {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--stored-bg);
}

.sample-btn--inspect {
  border-color: rgba(29, 78, 216, 0.35);
  background: var(--inspect-bg);
}

.sample-btn:hover {
  border-color: var(--teal);
  transform: translateY(-1px);
}

.sample-btn strong {
  display: block;
  color: var(--navy);
  font-size: 13px;
}

.sample-btn span {
  display: block;
  margin-top: 0;
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.status-banner {
  margin: 0 0 4px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  text-align: left;
}

.status-banner--lent {
  background: var(--lent-bg);
  color: var(--lent);
}

.status-banner--stored {
  background: var(--stored-bg);
  color: var(--stored);
}

.status-banner--inspect {
  background: var(--inspect-bg);
  color: var(--inspect);
}

.slot.is-warn {
  border-color: rgba(180, 83, 9, 0.55);
  background: #fff7ed;
}

.mode-hint {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.5;
}

.ledger-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.sync-pill {
  margin: 0;
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: #e8eef6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sync-pill.is-live {
  background: var(--teal-soft);
  color: var(--teal);
}

.ledger-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.search { flex: 1 1 240px; }

.search input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: #fff;
}

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

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.chip.is-on {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: #fff;
}

.ledger-table th,
.ledger-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  vertical-align: middle;
}

.ledger-table th {
  background: #f4f7fb;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
}

.ledger-table tr:last-child td { border-bottom: 0; }

.ledger-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--navy);
  font-weight: 700;
}

.ledger-row.is-flash {
  animation: flashRow 2.4s ease;
}

@keyframes flashRow {
  0%, 25% { background: var(--flash); }
  100% { background: transparent; }
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge--lent { background: var(--lent-bg); color: var(--lent); }
.badge--stored { background: var(--stored-bg); color: var(--stored); }
.badge--inspect { background: var(--inspect-bg); color: var(--inspect); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px !important;
}

.footnote {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0 14px;
  min-height: 40px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}

.btn--sm { min-height: 34px; font-size: 13px; padding: 0 10px; }
.btn--block { width: 100%; min-height: 50px; font-size: 16px; }

.btn--primary {
  background: var(--navy);
  color: #fff;
}

.btn--accent {
  background: var(--teal);
  color: #fff;
}

.btn--accent:disabled,
.btn--primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--ghost {
  background: #fff;
  color: var(--navy);
  border-color: var(--line);
}

.code-dialog {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(440px, calc(100vw - 24px));
  box-shadow: var(--shadow);
}

.code-dialog::backdrop {
  background: rgba(18, 54, 107, 0.35);
}

.code-dialog__inner { margin: 0; padding: 18px; }

.code-dialog__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.code-dialog__head h3 {
  margin: 4px 0 0;
  color: var(--navy);
  font-size: 22px;
}

.code-dialog__body {
  margin-top: 14px;
  display: grid;
  gap: 14px;
  justify-items: center;
  padding: 16px;
  background: #f7fafc;
  border-radius: 12px;
}

.dialog-qr {
  width: 196px;
  height: 196px;
  background: #fff;
  border-radius: 12px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
}

.dialog-barcode {
  max-width: 100%;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
}

.code-dialog__foot {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

/* Field (mobile) */
body.field {
  background: linear-gradient(180deg, #e8f4f4 0%, var(--bg) 28%, var(--bg) 100%);
}

.field-page {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 14px 36px;
}

.field-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.field-top h1 {
  margin: 4px 0 0;
  color: var(--navy);
  font-size: 24px;
  font-weight: 800;
}

.field-top h1 span {
  display: inline-block;
  margin-left: 6px;
  font-size: 13px;
  color: var(--teal);
  font-weight: 800;
}

.field-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.field-tab {
  appearance: none;
  border: 0;
  border-radius: 10px;
  min-height: 44px;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.field-tab.is-on {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 4px 12px rgba(18, 54, 107, 0.18);
}

.tab-panel[hidden] { display: none !important; }

.lookup-panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.lookup-title {
  margin: 0 0 10px;
  color: var(--navy);
  font-size: 16px;
  font-weight: 800;
}

.lookup-search { display: block; margin-bottom: 10px; }

.lookup-filters { margin-bottom: 10px; }

.lookup-sync {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.lookup-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lookup-card {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbfe;
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}

.lookup-card:active {
  transform: scale(0.99);
}

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

.lookup-card__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-bottom: 6px;
}

.lookup-card__top strong {
  color: var(--navy);
  font-size: 15px;
}

.lookup-card__top code {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.lookup-card__line {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.lookup-empty {
  margin: 0;
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.lookup-dialog__body {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.lookup-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #f7fafc;
  border-radius: 10px;
}

.lookup-detail-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.lookup-detail-row strong {
  color: var(--navy);
  font-size: 14px;
  text-align: right;
}

.scan-panel,
.slots,
.field-actions {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.reader-wrap { margin-top: 12px; }

.reader {
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  background: #0b1728;
  min-height: 220px;
}

.scan-input-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--navy);
  font-size: 13px;
  font-weight: 800;
}

.scan-input {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--teal);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
  background: #fbffff;
}

.slots h2 {
  margin: 0 0 10px;
  color: var(--navy);
  font-size: 15px;
}

.slot {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #f8fbfe;
  transition: border-color .15s ease, background .15s ease;
}

.slot.is-filled {
  border-color: rgba(15, 143, 145, 0.45);
  background: var(--teal-soft);
}

.slot__head {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.slot__check {
  color: var(--teal);
  font-size: 16px;
}

.slot__value {
  margin: 4px 0 0;
  color: var(--navy);
  font-size: 16px;
  font-weight: 800;
}

.slot__code {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.mode-label {
  margin: 0;
  width: 100%;
  color: var(--navy);
  font-size: 13px;
  font-weight: 800;
}

.mode-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  font-size: 14px;
  font-weight: 700;
}

.toast-inline {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--teal-soft);
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
}

.toast-inline.is-error {
  background: #fef2f2;
  color: #991b1b;
}

@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .pair-box { flex-direction: column; align-items: flex-start; }
  .topbar { flex-direction: column; }
}

@media (max-width: 640px) {
  .page { padding: 14px 12px 28px; }
  .panel { padding: 14px; }
}

@media print {
  body.printing-code * { visibility: hidden; }
  body.printing-code .code-dialog,
  body.printing-code .code-dialog * { visibility: visible; }
  body.printing-code .code-dialog {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    border: 0;
    box-shadow: none;
  }
  body.printing-code .code-dialog__foot,
  body.printing-code .code-dialog__head button { display: none !important; }
}
