:root {
  --ink: #1f2925;
  --ink-soft: #5e6b66;
  --brand: #26342f;
  --brand-hover: #18231f;
  --surface: #ffffff;
  --surface-soft: #f4f6f4;
  --line: #d9dfdc;
  --line-strong: #bdc8c3;
  --success: #1d6c4d;
  --success-bg: #e8f4ee;
  --warning: #8a5b00;
  --warning-bg: #fff5d9;
  --danger: #a33131;
  --danger-bg: #fbeaea;
  --focus: #1d6caa;
  --shadow: 0 2px 12px rgba(24, 35, 31, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  color: var(--ink);
  background: var(--surface-soft);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.55;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--surface-soft);
}

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

button,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

:focus-visible {
  outline: 3px solid rgba(29, 108, 170, 0.3);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  transform: translateY(-150%);
  padding: 8px 12px;
  border-radius: 4px;
  color: #fff;
  background: var(--brand);
}

.skip-link:focus {
  transform: translateY(0);
}

.demo-notice {
  position: relative;
  z-index: 20;
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 20px;
  border-bottom: 1px solid #e5cc8d;
  color: #5f4308;
  background: var(--warning-bg);
  font-size: 13px;
  text-align: center;
}

.demo-badge {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid #c58a16;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: calc(100vh - 40px);
  flex-direction: column;
  padding: 24px 16px 18px;
  color: #edf2ef;
  background: var(--brand);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 8px;
  font-size: 20px;
  font-weight: 700;
}

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

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

.brand small {
  margin-top: 1px;
  color: #bfcac5;
  font-size: 11px;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  color: #dce4e0;
  background: transparent;
  font-size: 14px;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  font-weight: 700;
}

.nav-item span {
  display: inline-grid;
  width: 18px;
  place-items: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.sidebar-footer p {
  margin: 0 0 12px;
  color: #bfcac5;
  font-size: 11px;
}

.main-content {
  min-width: 0;
  padding: 32px clamp(20px, 4vw, 56px) 64px;
}

.page-header {
  display: flex;
  max-width: 1280px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto 24px;
}

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

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.25;
}

h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.4;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.updated-at {
  color: var(--ink-soft);
  font-size: 11px;
}

.mobile-only {
  display: none;
}

.view,
#app-content,
.loading-panel,
.alert {
  max-width: 1280px;
  margin-right: auto;
  margin-left: auto;
}

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

.loading-panel {
  display: grid;
  min-height: 280px;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--ink-soft);
}

.loading-panel p {
  margin: 0;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.alert {
  padding: 18px;
  border: 1px solid;
  border-radius: var(--radius);
}

.alert p {
  margin: 6px 0 14px;
}

.alert-error {
  border-color: #dfb0b0;
  color: #742525;
  background: var(--danger-bg);
}

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

.summary-card {
  min-height: 126px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card.is-warning {
  border-color: #e5cc8d;
  background: #fffdf7;
}

.summary-card.is-danger {
  border-color: #dfb0b0;
  background: #fffafa;
}

.summary-label {
  display: block;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

.summary-value {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  font-weight: 750;
  line-height: 1;
}

.summary-note {
  display: block;
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 11px;
}

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

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

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

.panel-header p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.text-button {
  flex: 0 0 auto;
  padding: 4px;
  border: 0;
  color: var(--success);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.mini-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mini-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.mini-list-item:last-child {
  border-bottom: 0;
}

.mini-list-item strong,
.mini-list-item small {
  display: block;
}

.mini-list-item strong {
  font-size: 13px;
}

.mini-list-item small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}

.stock-value {
  font-size: 16px;
  font-weight: 750;
  white-space: nowrap;
}

.stock-value.is-low {
  color: var(--warning);
}

.stock-value.is-out,
.delta-negative {
  color: var(--danger);
}

.delta-positive {
  color: var(--success);
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
}

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

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

.button-secondary {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #fff;
}

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

.button-quiet {
  border-color: rgba(255, 255, 255, 0.28);
  color: #edf2ef;
  background: transparent;
}

.button-small {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 11px;
}

.table-action {
  min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: #fff;
  font-size: 11px;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  flex: 1 1 420px;
}

.select-compact {
  flex: 0 0 180px;
}

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

input,
select {
  min-height: 42px;
  padding: 8px 11px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: var(--ink-soft);
  background: #fafbfa;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fafbfa;
}

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

.item-name {
  display: block;
  min-width: 180px;
  font-weight: 700;
}

.item-sku,
.cell-subtext {
  display: block;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 10px;
}

.status-badge,
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}

.status-ok {
  color: var(--success);
  background: var(--success-bg);
}

.status-low {
  color: var(--warning);
  background: var(--warning-bg);
}

.status-out {
  color: var(--danger);
  background: var(--danger-bg);
}

.status-inactive {
  color: var(--ink-soft);
  background: #ecefed;
}

.type-in,
.type-initial,
.type-stocktake_adjustment {
  color: var(--success);
  background: var(--success-bg);
}

.type-use,
.type-damage,
.type-waste,
.type-reversal {
  color: var(--danger);
  background: var(--danger-bg);
}

.empty-state {
  padding: 42px 20px;
  color: var(--ink-soft);
  text-align: center;
}

.form-layout {
  display: grid;
  grid-template-columns: minmax(0, 760px) minmax(240px, 1fr);
  gap: 18px;
  align-items: start;
}

.form-panel form {
  padding: 20px;
}

.field-group {
  min-width: 0;
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

.field-group > label,
.field-group > legend {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

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

.required {
  margin-left: 4px;
  color: var(--danger);
  font-size: 10px;
}

.optional {
  margin-left: 4px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 400;
}

.field-hint {
  margin: 5px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.field-hint.is-danger {
  color: var(--danger);
  font-weight: 700;
}

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

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-control span {
  display: grid;
  min-height: 42px;
  place-items: center;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
}

.segmented-control input:checked + span {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

.segmented-control input:focus-visible + span {
  outline: 3px solid rgba(29, 108, 170, 0.3);
  outline-offset: 2px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

.guidance-panel {
  padding: 20px;
}

.check-list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.check-list li {
  position: relative;
  margin-top: 11px;
  padding-left: 22px;
  color: var(--ink-soft);
  font-size: 12px;
}

.check-list li::before {
  position: absolute;
  top: 0;
  left: 0;
  color: var(--success);
  content: "✓";
  font-weight: 800;
}

.detail-list {
  margin: 12px 0 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}

.detail-list div:last-child {
  border-bottom: 0;
}

.detail-list dt {
  font-weight: 750;
}

.detail-list dd {
  margin: 0;
  color: var(--ink-soft);
}

.reorder-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.reorder-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.reorder-card.is-out {
  border-color: #dfb0b0;
  background: #fffafa;
}

.reorder-card h3 {
  margin: 0;
  font-size: 14px;
}

.reorder-card p {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.reorder-number {
  text-align: right;
}

.reorder-number strong,
.reorder-number span {
  display: block;
}

.reorder-number strong {
  font-size: 19px;
}

.reorder-number span {
  color: var(--ink-soft);
  font-size: 10px;
}

.toast-region {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  display: grid;
  width: min(360px, calc(100vw - 36px));
  gap: 8px;
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 8px 28px rgba(24, 35, 31, 0.2);
  font-size: 13px;
}

.toast.is-error {
  border-color: #7e2626;
  background: var(--danger);
}

.confirm-dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
  box-shadow: 0 18px 60px rgba(24, 35, 31, 0.24);
}

.confirm-dialog::backdrop {
  background: rgba(20, 28, 25, 0.52);
}

.confirm-dialog form {
  padding: 22px;
}

.confirm-dialog p {
  margin: 10px 0 20px;
  color: var(--ink-soft);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

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

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

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

  .guidance-panel {
    order: -1;
  }
}

@media (max-width: 760px) {
  .demo-notice {
    align-items: flex-start;
    padding: 8px 12px;
    text-align: left;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: sticky;
    z-index: 15;
    top: 0;
    display: block;
    width: 100%;
    height: auto;
    padding: 10px 12px 0;
    overflow: hidden;
  }

  .brand {
    padding: 0 2px 9px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    font-size: 16px;
  }

  .brand small {
    display: none;
  }

  .nav-list {
    display: flex;
    gap: 3px;
    padding-bottom: 9px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
    padding: 7px 9px;
    font-size: 11px;
  }

  .nav-item span {
    display: none;
  }

  .sidebar-footer {
    display: none;
  }

  .main-content {
    padding: 20px 12px 48px;
  }

  .page-header {
    align-items: flex-start;
  }

  .header-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 5px;
  }

  .mobile-only {
    display: inline-flex;
  }

  .header-actions .button {
    min-height: 38px;
    padding: 7px 11px;
    font-size: 11px;
  }

  .updated-at {
    font-size: 9px;
  }

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

@media (max-width: 520px) {
  .demo-notice {
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.6;
  }

  .page-header {
    display: block;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 13px;
  }

  .header-actions .updated-at {
    grid-column: 1 / -1;
  }

  .header-actions .button {
    width: 100%;
  }

  .updated-at {
    text-align: right;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .summary-card {
    min-height: 112px;
    padding: 14px;
  }

  .summary-value {
    font-size: 25px;
  }

  .panel-header,
  .toolbar,
  .form-panel form {
    padding-right: 14px;
    padding-left: 14px;
  }

  .toolbar {
    display: grid;
  }

  .select-compact {
    flex-basis: auto;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

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

  .form-actions .button {
    width: 100%;
  }

  th,
  td {
    padding: 10px 11px;
  }

  .reorder-list {
    padding: 12px;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
