:root {
  color-scheme: light;
  --bg: #f5f7f1;
  --surface: #ffffff;
  --surface-2: #eef4ec;
  --ink: #17201b;
  --muted: #637064;
  --line: #d9e2d7;
  --green: #277445;
  --green-dark: #1c5934;
  --teal: #126c70;
  --amber: #b66a12;
  --red: #b53a37;
  --blue: #2864a6;
  --shadow: 0 18px 45px rgba(23, 32, 27, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.icon-sprite {
  display: none;
}

svg {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #fbfcf8;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  margin-bottom: 24px;
}

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

.brand strong {
  font-size: 18px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  flex: 0 0 auto;
}

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

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  text-align: left;
}

.nav-tab:hover,
.nav-tab.is-active {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--green-dark);
}

.main {
  min-width: 0;
  max-width: 100vw;
  padding: 22px clamp(14px, 3vw, 34px) 34px;
}

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1.12;
}

h2 {
  margin-bottom: 2px;
  font-size: 17px;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.topbar-actions,
.toolbar,
.data-actions,
.form-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.role-select {
  width: auto;
  min-width: 116px;
  font-weight: 800;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 13px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.button-secondary {
  border-color: #aac8ad;
  background: #e6f2e7;
  color: var(--green-dark);
}

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

.button-danger {
  border-color: #efc4c1;
  background: #fff1f0;
  color: var(--red);
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.sync-status.is-offline {
  border-color: #efc4c1;
  background: #fff1f0;
  color: var(--red);
}

.button-icon {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
}

.tab-panel {
  display: none;
  min-width: 0;
}

.tab-panel.is-active {
  display: grid;
  gap: 18px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.panel-heading > div {
  min-width: 0;
}

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
}

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

.metric {
  min-height: 116px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric small {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 800;
}

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

.metric span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.9fr);
  gap: 18px;
  min-width: 0;
}

.dashboard-ux-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  min-width: 0;
}

.work-list,
.alert-list,
.quick-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.quick-list.compact {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.quick-item {
  display: grid;
  gap: 6px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
  min-width: 0;
}

.quick-item strong,
.approval-row strong {
  display: block;
}

.quick-item span,
.approval-row span {
  color: var(--muted);
  font-size: 13px;
}

.approval-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

#approvalQueue {
  grid-template-columns: 1fr;
}

.work-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.work-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.work-row strong,
.alert-item strong,
.lot-card strong {
  display: block;
}

.work-row span,
.alert-item span,
.lot-card span {
  color: var(--muted);
  font-size: 13px;
}

.alert-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid #edd4a8;
  border-radius: var(--radius);
  background: #fff9ec;
  padding: 12px;
}

.alert-item svg {
  color: var(--amber);
  margin-top: 2px;
}

.status-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
  overflow-x: auto;
}

.status-column {
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fbf6;
}

.status-column h3 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.status-column h3 span {
  color: var(--muted);
}

.lot-card {
  display: grid;
  gap: 5px;
  margin: 10px;
  border-left: 4px solid var(--green);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
}

.lot-card[data-state="保留"] {
  border-left-color: var(--red);
}

.lot-card[data-state="一部出荷"] {
  border-left-color: var(--blue);
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #6aaa78;
  box-shadow: 0 0 0 3px rgba(39, 116, 69, 0.14);
}

.form-wide {
  grid-column: span 2;
}

.form-actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
  padding-top: 2px;
}

.form-inline-action {
  display: flex;
  align-items: end;
}

.compact-input {
  width: min(260px, 100%);
}

.toolbar-heading {
  align-items: flex-start;
}

.search-field {
  position: relative;
  display: block;
  width: min(320px, 100%);
}

.search-field svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.search-field input {
  padding-left: 34px;
}

.table-wrap {
  min-width: 0;
  overflow-x: auto;
}

.sheet-body {
  min-width: 0;
  padding: 14px;
  overflow-x: auto;
}

.sheet-title {
  margin-bottom: 10px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
}

.sheet-meta-table {
  width: 100%;
  min-width: 720px;
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
  border-collapse: collapse;
  background: #fff;
}

.sheet-meta-table th,
.sheet-meta-table td {
  min-height: 34px;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 6px 8px;
  font-size: 13px;
  text-align: left;
}

.sheet-meta-table th {
  width: 190px;
  background: #eef4ec;
  color: var(--ink);
  white-space: nowrap;
}

.official-table {
  min-width: 1040px;
  margin-top: 12px;
  border-top: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.official-table th,
.official-table td {
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 8px;
  font-size: 12px;
}

.official-table th {
  background: #eef4ec;
  color: var(--ink);
  text-align: center;
  white-space: pre-line;
}

.official-table td {
  background: #fff;
  white-space: pre-line;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 930px;
}

.wide-table {
  min-width: 1120px;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #fbfdf8;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
}

.chip,
.chip-static {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
  font-size: 12px;
  font-weight: 800;
}

.chip {
  cursor: pointer;
}

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

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: #eef4ec;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
}

.tag-blue {
  background: #eaf2fb;
  color: var(--blue);
}

.tag-amber {
  background: #fff4de;
  color: var(--amber);
}

.tag-red {
  background: #fff1f0;
  color: var(--red);
}

td .tag {
  margin: 2px 3px 2px 0;
}

.producer-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.producer-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.producer-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.producer-card strong {
  display: block;
  font-size: 16px;
}

.producer-card span,
.producer-card p {
  color: var(--muted);
  font-size: 13px;
}

.producer-card p {
  margin-bottom: 7px;
}

.producer-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.producer-stats div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.producer-stats b {
  display: block;
  font-size: 18px;
}

.data-actions {
  padding: 18px;
}

.audit-list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.audit-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(0, 1fr) minmax(140px, 0.7fr);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
}

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

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

textarea {
  display: block;
  min-height: 260px;
  border: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  background: #111812;
  color: #d9f4dd;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  resize: vertical;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 36px));
  border-radius: var(--radius);
  background: #17201b;
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

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

.mobile-dock {
  display: none;
}

.print-body {
  background: #fff;
  padding: 18px;
}

.print-sheet {
  break-after: page;
  margin-bottom: 22px;
}

@media print {
  .sidebar,
  .topbar,
  .mobile-dock,
  .toast {
    display: none !important;
  }

  .app-shell,
  .main,
  .tab-panel,
  .panel {
    display: block !important;
    box-shadow: none;
    border: 0;
    padding: 0;
  }

  .sheet-body {
    padding: 0;
  }
}

@media (max-width: 1180px) {
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-layout,
  .dashboard-ux-grid,
  .producer-grid {
    grid-template-columns: 1fr;
  }

  .status-board {
    grid-template-columns: repeat(6, 190px);
  }

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

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

  .sidebar {
    position: static;
    height: auto;
    max-width: 100vw;
    overflow: hidden;
    padding: 12px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-tabs {
    display: flex;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }

  .nav-tab {
    flex: 0 0 74px;
    justify-content: center;
    min-width: 74px;
    padding: 0 8px;
  }

  .nav-tab span {
    display: none;
  }

  .main {
    width: 100%;
    max-width: 100vw;
    padding: 16px 12px 28px;
  }

  .topbar,
  .panel-heading,
  .toolbar-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .toolbar {
    width: 100%;
  }

  .toolbar select,
  .compact-input,
  .search-field {
    width: 100%;
  }
}

@media (max-width: 620px) {
  body {
    padding-bottom: 60px;
  }

  .metrics-grid,
  .entry-form,
  .producer-stats {
    grid-template-columns: 1fr;
  }

  .form-wide {
    grid-column: auto;
  }

  .button {
    flex: 1 1 auto;
  }

  .table-wrap {
    overflow-x: visible;
  }

  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .table-wrap table {
    border-collapse: separate;
    border-spacing: 0 10px;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tr {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 8px 22px rgba(23, 32, 27, 0.06);
  }

  .table-wrap tr:hover {
    background: #fff;
  }

  .table-wrap td {
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }

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

  .table-wrap td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
  }

  .table-wrap td[colspan]::before {
    display: none;
  }

  .table-wrap .table-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .table-wrap .button-icon {
    flex: 0 0 34px;
  }

  .work-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .work-row .tag {
    grid-column: 2;
    width: fit-content;
  }

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

  .mobile-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--line);
    background: #fff;
  }

  .mobile-dock button {
    display: grid;
    place-items: center;
    gap: 3px;
    min-height: 56px;
    border: 0;
    background: #fff;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
  }

  .mobile-dock svg {
    font-size: 18px;
  }
}
