:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f6;
  --line: #d9e1e6;
  --text: #18232d;
  --muted: #657281;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #d9f2ee;
  --blue: #2563eb;
  --blue-soft: #e7efff;
  --amber: #b45309;
  --amber-soft: #fff3d6;
  --danger: #c24132;
  --danger-soft: #fde8e3;
  --ok: #198754;
  --shadow: 0 14px 40px rgba(26, 36, 48, 0.08);
  --radius: 8px;
  font-family:
    "Segoe UI",
    "Microsoft JhengHei",
    system-ui,
    sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08), transparent 38%),
    var(--bg);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #152733;
  color: #eef7f7;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 52px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #f2c94c;
  color: #152733;
  font-weight: 800;
}

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

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

.brand span {
  color: #a8bdc6;
  margin-top: 2px;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  padding: 12px 12px;
  background: transparent;
  color: #c8d7dd;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-panel {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: var(--radius);
  padding: 16px;
  background: rgba(255, 255, 255, 0.06);
}

.mini-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mini-stat:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.mini-stat strong {
  font-size: 24px;
}

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

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

.topbar-actions,
.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 300px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

.search-field input {
  border: 0;
  outline: 0;
  min-width: 0;
  width: 100%;
  background: transparent;
}

.primary-button,
.danger-button,
.ghost-button,
.text-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

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

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

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

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

.text-button {
  color: var(--primary);
  background: transparent;
  padding: 0 4px;
}

.icon-button {
  width: 38px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  font-size: 22px;
}

.view {
  display: none;
}

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

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

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

.kpi-card {
  padding: 18px;
}

.kpi-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
}

.kpi-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.panel {
  padding: 18px;
}

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

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.out {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.in {
  background: var(--blue-soft);
  color: var(--blue);
}

.warehouse-map {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
}

.zone-tile {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background:
    linear-gradient(180deg, #ffffff, #f7fbfb);
  min-height: 154px;
}

.zone-tile header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.zone-tile strong {
  font-size: 18px;
}

.shelf-bars {
  display: grid;
  gap: 8px;
}

.shelf-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.bar {
  height: 9px;
  border-radius: 999px;
  background: #e3e8ec;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.alert-list {
  display: grid;
  gap: 10px;
}

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

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

.alert-item strong,
.alert-item span {
  display: block;
}

.alert-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
  background: #f8fafb;
}

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

tbody tr:hover {
  background: #fbfcfd;
}

.product-cell {
  display: flex;
  gap: 10px;
  align-items: center;
}

.product-mark {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #ffffff;
  background: var(--blue);
  font-weight: 800;
}

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

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
}

select {
  min-height: 38px;
  padding: 0 36px 0 10px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.segmented.fill {
  display: flex;
}

.segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segmented.fill button {
  flex: 1;
}

.segmented button.is-active {
  color: var(--text);
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(26, 36, 48, 0.08);
}

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

.location-card {
  padding: 16px;
  box-shadow: none;
}

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

.location-card h3 {
  margin: 0;
  font-size: 18px;
}

.location-metric {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.modal {
  width: min(560px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 28px 80px rgba(21, 39, 51, 0.22);
}

.modal::backdrop {
  background: rgba(21, 39, 51, 0.38);
}

.modal-card {
  padding: 20px;
  display: grid;
  gap: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

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

.modal input,
.modal select,
.modal textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  color: var(--text);
  font-weight: 500;
}

.modal textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 2px 0 0;
  padding: 0;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .brand div:not(.brand-mark),
  .nav-item span:last-child,
  .sidebar-panel {
    display: none;
  }

  .brand {
    justify-content: center;
  }

  .nav-item {
    justify-content: center;
  }

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
    overflow: hidden;
  }

  .brand div:not(.brand-mark),
  .nav-item span:last-child {
    display: block;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
  }

  .nav-item {
    justify-content: center;
    min-height: 58px;
    min-width: 0;
    padding: 8px 4px;
    flex-direction: column;
    gap: 4px;
    font-size: 10px;
  }

  .nav-item span:last-child {
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
  }

  .main {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    align-items: stretch;
  }

  .search-field {
    min-width: 100%;
  }

  .kpi-grid,
  .dashboard-grid,
  .warehouse-map,
  .location-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
