:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --line: #dbe3ee;
  --line-strong: #c7d2e0;
  --text: #172033;
  --muted: #667085;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --good: #16865a;
  --warn: #b7791f;
  --bad: #c24141;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

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

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

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

.brand small {
  margin-top: 2px;
  color: var(--muted);
}

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

.nav-button,
.primary-button,
.secondary-button,
.icon-button,
.text-button {
  border: 0;
  border-radius: 8px;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-button {
  width: 100%;
  padding: 11px 12px;
  text-align: left;
  color: var(--muted);
  background: transparent;
}

.nav-button:hover,
.nav-button.is-active {
  color: var(--text);
  background: var(--surface-2);
}

.sync-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--bg);
  font-size: 13px;
}

.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--warn);
}

.sync-dot.is-online {
  background: var(--good);
}

.sync-dot.is-error {
  background: var(--bad);
}

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

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

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

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

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

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

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

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.primary-button {
  min-height: 40px;
  padding: 0 15px;
  color: #ffffff;
  background: var(--brand);
  font-weight: 700;
}

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

.secondary-button,
.icon-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: #ffffff;
  font-weight: 700;
}

.secondary-button:hover,
.icon-button:hover {
  background: var(--surface-2);
}

.text-button {
  padding: 4px 0;
  color: var(--brand);
  background: transparent;
  font-weight: 700;
}

.text-button.danger {
  color: var(--bad);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

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

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

.metric-card {
  padding: 16px;
}

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

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 27px;
  line-height: 1.15;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-heading,
.section-heading,
.item-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.queue-list,
.status-stack,
.master-list,
.item-list,
.mini-list {
  display: grid;
  gap: 10px;
}

.queue-item,
.status-row,
.master-card,
.item-card,
.mini-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.queue-item,
.master-card,
.item-card,
.mini-row {
  padding: 12px;
}

.queue-item {
  display: grid;
  gap: 5px;
}

.status-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: #ffffff;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  outline: 3px solid rgba(37, 99, 235, 0.12);
}

.search-field {
  min-width: min(100%, 360px);
  flex: 1;
}

.select-field {
  width: 190px;
}

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

.table-panel {
  min-width: 0;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr {
  transition: background 160ms ease;
}

tbody tr:hover,
tbody tr.is-selected {
  background: #f4f7fb;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: #dbeafe;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.chip.good {
  color: var(--good);
  background: #dcfce7;
}

.chip.warn {
  color: var(--warn);
  background: #fef3c7;
}

.chip.bad {
  color: var(--bad);
  background: #fee2e2;
}

.detail-panel {
  min-width: 0;
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-content: center;
  color: var(--muted);
  text-align: center;
}

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

.pi-summary div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.pi-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.pi-summary strong {
  display: block;
  margin-top: 4px;
}

.item-card {
  display: grid;
  gap: 10px;
}

.item-card.is-selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.item-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.progress-tile {
  padding: 8px;
  border-radius: 8px;
  background: var(--surface-2);
}

.progress-tile span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.progress-tile strong {
  display: block;
  margin-top: 3px;
  font-size: 14px;
}

.workflow-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.workflow-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--muted);
  background: #ffffff;
  font-weight: 700;
}

.tab-button.is-active {
  color: var(--brand-dark);
  border-color: #bfdbfe;
  background: #eff6ff;
}

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

.form-grid.compact {
  grid-template-columns: repeat(6, minmax(110px, 1fr));
}

.full-field,
.stack-form {
  margin-top: 12px;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.form-panel {
  max-width: 1120px;
}

.item-editor-list {
  display: grid;
  gap: 12px;
}

.item-editor {
  padding: 14px;
  box-shadow: none;
}

.item-editor-head {
  margin-bottom: 10px;
}

.master-card {
  display: grid;
  gap: 4px;
}

.master-card strong {
  font-size: 14px;
}

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

.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

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

  .content-grid,
  .orders-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
    padding-bottom: 74px;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    display: block;
    height: auto;
    padding: 8px;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .brand,
  .sync-box {
    display: none;
  }

  .nav-list {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .nav-button {
    min-height: 48px;
    padding: 7px 6px;
    text-align: center;
    font-size: 13px;
  }

  .main {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 24px;
  }

  .form-grid,
  .form-grid.compact,
  .pi-summary,
  .progress-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button,
  .toolbar label,
  .select-field {
    width: 100%;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }
}
