:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #1d252c;
  --muted: #6b7680;
  --line: #d8dee4;
  --primary: #14746f;
  --primary-dark: #0f5b57;
  --accent: #b7791f;
  --danger: #c2410c;
  --shadow: 0 16px 48px rgba(29, 37, 44, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #152026;
  color: #f7fafc;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

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

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.toolbar h3,
.data-form h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  letter-spacing: 0;
}

.brand p {
  color: #a8b3bd;
  margin-top: 3px;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item,
.ghost-btn {
  width: 100%;
  border: 0;
  color: #dce5ea;
  background: transparent;
  min-height: 42px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  text-align: left;
}

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

.nav-item svg,
.ghost-btn svg,
.primary-btn svg,
.secondary-btn svg,
.icon-btn svg,
.search svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.danger {
  color: #fed7c3;
}

.main {
  padding: 24px;
  overflow: auto;
}

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

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.topbar h2 {
  font-size: 28px;
  line-height: 1.1;
}

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

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

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

.icon-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  color: var(--text);
}

.primary-btn,
.secondary-btn,
.text-btn {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
}

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

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

.secondary-btn {
  color: var(--primary);
  border-color: rgba(20, 116, 111, 0.28);
  background: #eef8f6;
}

.text-btn {
  border: 0;
  color: var(--primary);
  background: transparent;
  padding: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric {
  min-height: 112px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
  font-size: 14px;
}

.metric strong {
  font-size: 30px;
  letter-spacing: 0;
}

.metric.warn strong {
  color: var(--danger);
}

.content-grid,
.form-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-layout {
  align-items: start;
  grid-template-columns: minmax(320px, 420px) 1fr;
}

.panel,
.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

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

.toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 64px;
  padding: 12px 14px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.trade-layout {
  grid-template-columns: minmax(340px, 460px) minmax(0, 1fr);
}

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

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

.compact-list.tall {
  max-height: 560px;
  overflow: auto;
}

.list-row {
  min-height: 54px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: 8px;
  padding: 10px 12px;
}

.list-row small,
.muted {
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.pill.sale {
  background: #fff1e8;
  color: #9a3412;
}

.pill.purchase {
  background: #e9f8f3;
  color: #0f766e;
}

.pill.adjustment {
  background: #f4f0ff;
  color: #6d28d9;
}

.pill.status-ordered {
  background: #eef2f5;
  color: #374151;
}

.pill.status-in_transit {
  background: #e0f2fe;
  color: #075985;
}

.pill.status-delayed {
  background: #fff7ed;
  color: #9a3412;
}

.pill.status-arrived {
  background: #e9f8f3;
  color: #0f766e;
}

.pill.status-cancelled {
  background: #f3f4f6;
  color: #6b7280;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

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

.progress-table {
  min-width: 2100px;
}

.progress-table th,
.progress-table td {
  white-space: nowrap;
  padding: 9px 10px;
  font-size: 13px;
}

.progress-table th:first-child,
.progress-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #ffffff;
}

.progress-table th:first-child {
  z-index: 3;
  background: #fbfcfd;
}

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

th {
  color: var(--muted);
  background: #fbfcfd;
  font-size: 13px;
  font-weight: 700;
}

td {
  font-size: 14px;
}

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

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.mini-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  display: inline-grid;
  place-items: center;
}

.mini-btn svg {
  width: 16px;
  height: 16px;
}

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

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

.data-form input,
.data-form select,
.toolbar select,
.auth-form input {
  width: 100%;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 12px;
  background: #ffffff;
  color: var(--text);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.auth-panel {
  display: grid;
  grid-template-columns: 1fr minmax(320px, 560px);
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.auth-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
}

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(21, 32, 38, 0.42);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}

.drawer-panel {
  width: min(440px, 100%);
  background: #ffffff;
  min-height: 100%;
  padding: 20px;
  box-shadow: var(--shadow);
}

dialog {
  border: 0;
  border-radius: 8px;
  width: min(520px, calc(100vw - 28px));
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(21, 32, 38, 0.42);
}

.dialog-form {
  padding: 20px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  min-width: 240px;
  max-width: min(420px, calc(100vw - 40px));
  background: #152026;
  color: #ffffff;
  border-radius: 8px;
  padding: 13px 14px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 74px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px;
  }

  .brand,
  .sidebar-actions {
    display: none;
  }

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

  .nav-item {
    justify-content: center;
    min-height: 44px;
    padding: 0 8px;
  }

  .nav-item span {
    display: none;
  }

  .main {
    padding: 16px;
  }

  .metrics,
  .content-grid,
  .form-layout,
  .auth-panel {
    grid-template-columns: 1fr;
  }

  .auth-form {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

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

@media (max-width: 560px) {
  .metrics {
    gap: 10px;
  }

  .metric {
    min-height: 92px;
  }

  .metric strong {
    font-size: 24px;
  }

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

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
