:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #667382;
  --line: #d9e1e8;
  --panel: #ffffff;
  --soft: #f5f7f9;
  --accent: #0d766e;
  --accent-2: #b33939;
  --warn: #a76408;
  --good: #1d7a46;
  --shadow: 0 18px 45px rgba(23, 33, 43, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--soft);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  min-width: 260px;
}

.brand-logo {
  display: block;
  height: 48px;
  max-width: min(320px, 56vw);
  object-fit: contain;
  object-position: left center;
  width: auto;
}

.brand p {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 0;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab {
  align-items: center;
  background: transparent;
  border-radius: 8px;
  color: var(--muted);
  display: inline-flex;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.tab.active {
  background: #e3f4f1;
  color: var(--accent);
  font-weight: 700;
}

.subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.subtab {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  min-height: 40px;
  padding: 0 12px;
  white-space: nowrap;
}

.subtab.active {
  background: #e3f4f1;
  border-color: #b6ded7;
  color: var(--accent);
}

.workspace {
  padding: 24px clamp(16px, 4vw, 40px) 48px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

.dashboard-insights {
  grid-template-columns: minmax(320px, 1.25fr) minmax(280px, 0.9fr) minmax(260px, 0.85fr);
}

.two-col {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

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

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

.panel-header h2,
.panel-header h3 {
  font-size: 16px;
  margin: 0;
}

.panel-body {
  padding: 16px;
}

.metric {
  padding: 16px;
}

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

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 8px;
}

.metric small {
  color: var(--muted);
  display: block;
  margin-top: 5px;
}

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

.inventory-filters {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1.5fr) minmax(150px, 1fr) minmax(130px, 0.8fr) minmax(130px, 0.8fr) auto;
}

.consignment-filter-grid {
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.5fr);
}

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

.field.full {
  grid-column: 1 / -1;
}

.field.double {
  grid-column: span 2;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

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

textarea {
  min-height: 76px;
  resize: vertical;
}

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

.btn {
  align-items: center;
  background: var(--accent);
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-weight: 700;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
}

.btn.secondary {
  background: #eef2f4;
  color: var(--ink);
}

.btn.danger {
  background: #f6e8e8;
  color: var(--accent-2);
}

.btn.small {
  min-height: 32px;
  padding: 0 10px;
}

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

.icon-btn {
  align-items: center;
  background: #eef2f4;
  border-radius: 8px;
  color: var(--ink);
  display: inline-flex;
  height: 32px;
  justify-content: center;
  padding: 0;
  width: 32px;
}

.icon-btn:hover {
  background: #e2e8ed;
}

.icon-btn.danger {
  background: #f6e8e8;
  color: var(--accent-2);
}

.icon-btn.danger:hover {
  background: #efd3d3;
}

.icon-btn svg {
  height: 16px;
  stroke: currentColor;
  width: 16px;
}

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

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

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

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

td.num,
th.num {
  text-align: right;
}

.sort-link {
  color: inherit;
  font: inherit;
  font-weight: 800;
  padding: 0;
  text-align: left;
  width: 100%;
}

.sort-link.num {
  text-align: right;
}

.sort-link:hover {
  color: var(--accent);
}

.table-link {
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 800;
  padding: 0;
  text-align: left;
}

.table-link:hover {
  text-decoration: underline;
}

tr.selected-row {
  background: #eef7f4;
}

.ledger-detail-row > td {
  background: #f8fbfb;
  padding: 0 10px 14px 32px;
}

.inline-ledger {
  border-left: 3px solid #b6ded7;
  margin-top: -1px;
  padding: 12px 0 0 14px;
}

.inline-ledger table {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 620px;
  overflow: hidden;
}

.inventory-table.colored tbody tr:nth-child(even) {
  background: #fbfcfd;
}

.inventory-table.colored tbody tr.priority-row {
  background: #fff8e8;
}

.inventory-table.colored .stock-in-col {
  background: rgba(222, 244, 232, 0.9);
}

.stock-in-col {
  background: rgba(222, 244, 232, 0.55);
}

.inventory-table.colored .stock-out-col {
  background: rgba(255, 232, 232, 0.78);
}

.stock-out-col {
  background: rgba(255, 232, 232, 0.5);
}

.inventory-table.colored .balance-col {
  background: rgba(226, 238, 255, 0.84);
  font-weight: 800;
}

.balance-col {
  background: rgba(226, 238, 255, 0.6);
  font-weight: 800;
}

.inventory-table.colored .value-col {
  background: rgba(255, 244, 222, 0.9);
  font-weight: 800;
}

.inventory-table.colored tbody tr:hover {
  background: #eef7f4;
}

.sales-chart {
  align-items: end;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  min-height: 240px;
  overflow: hidden;
}

.sales-column {
  align-items: center;
  display: grid;
  gap: 5px;
  grid-template-rows: 170px 24px 16px;
  min-width: 0;
}

.sales-bar-vertical-wrap {
  align-items: end;
  background: #f2f5f7;
  border-radius: 6px;
  display: flex;
  height: 170px;
  overflow: hidden;
  width: 100%;
}

.sales-bar-vertical {
  background: #d94242;
  border-radius: 8px 8px 0 0;
  display: block;
  width: 100%;
}

.sales-column strong,
.sales-column span {
  font-size: 12px;
  text-align: right;
}

.sales-column strong {
  color: var(--ink);
  font-size: 10px;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sales-column span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-pie-wrap {
  align-items: center;
  display: grid;
  gap: 14px;
  justify-items: center;
}

.channel-pie {
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 0 0 18px #fff, 0 0 0 1px var(--line);
  width: min(260px, 100%);
}

.channel-legend {
  display: grid;
  gap: 8px;
  width: 100%;
}

.channel-legend div {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 12px 64px minmax(0, 1fr);
}

.channel-legend em {
  color: var(--muted);
  font-style: normal;
}

.legend-dot {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.legend-dot.direct {
  background: #2f80ed;
}

.legend-dot.dealer {
  background: #d94242;
}

.pill {
  background: #eef2f4;
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.pill.green {
  background: #dcf2e6;
  color: var(--good);
}

.pill.orange {
  background: #fff1d8;
  color: var(--warn);
}

.pill.red {
  background: #f8e1e1;
  color: var(--accent-2);
}

.muted {
  color: var(--muted);
}

.line-items {
  display: grid;
  gap: 10px;
}

.purchase-note {
  margin: 8px 0 12px;
}

.purchase-grid,
.movement-grid {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.purchase-grid-header,
.purchase-line,
.movement-grid-header,
.movement-line {
  align-items: center;
  display: grid;
  gap: 8px;
}

.purchase-grid-header,
.purchase-line {
  grid-template-columns: minmax(260px, 2fr) minmax(120px, 0.8fr) minmax(90px, 0.5fr) minmax(120px, 0.7fr) minmax(120px, 0.8fr) 76px;
}

.movement-grid-header,
.movement-line {
  grid-template-columns: minmax(280px, 2fr) minmax(120px, 0.7fr) minmax(90px, 0.5fr) 76px;
}

.movement-grid.with-prices .movement-grid-header,
.movement-grid.with-prices .movement-line {
  grid-template-columns: minmax(240px, 2fr) minmax(110px, 0.7fr) minmax(80px, 0.5fr) minmax(110px, 0.7fr) minmax(120px, 0.8fr) 76px;
}

.movement-grid:not(.with-prices) .price-header,
.movement-grid:not(.with-prices) .price-cell {
  display: none;
}

.movement-grid.auto-bucket .movement-grid-header span:nth-child(2),
.movement-grid.auto-bucket .movement-line [name="lineBucket"] {
  display: none;
}

.movement-grid.auto-bucket .movement-grid-header,
.movement-grid.auto-bucket .movement-line {
  grid-template-columns: minmax(280px, 2fr) minmax(90px, 0.5fr) 76px;
}

.purchase-grid-header,
.movement-grid-header {
  background: #eef2f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 10px;
}

.purchase-grid-body,
.movement-grid-body {
  display: grid;
}

.purchase-line,
.movement-line {
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 8px 10px;
}

.purchase-line:first-child,
.movement-line:first-child {
  border-top: 0;
}

.purchase-line input,
.purchase-line select,
.movement-line input,
.movement-line select {
  min-height: 36px;
}

.purchase-line output {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.movement-line output {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.purchase-total-bar {
  align-items: center;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 12px;
  padding: 12px;
}

.purchase-total-bar span {
  font-size: 13px;
}

.purchase-total-bar strong {
  color: var(--ink);
}

.bulk-import {
  background: #fbfcfd;
  border: 1px dashed var(--line);
  border-radius: 8px;
  margin-top: 12px;
  padding: 12px;
}

.line-item {
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.line-summary {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  margin-top: 8px;
}

.notice {
  background: #f0f7f6;
  border: 1px solid #c8e2df;
  border-radius: 8px;
  color: #255a55;
  font-size: 13px;
  line-height: 1.45;
  padding: 12px;
}

.startup-notice {
  margin-bottom: 16px;
}

.empty {
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filters > * {
  max-width: 220px;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .dashboard-grid,
  .dashboard-insights,
  .two-col {
    grid-template-columns: 1fr;
  }

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

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

  .channel-pie {
    width: min(220px, 100%);
  }
}

@media (max-width: 640px) {
  .workspace {
    padding-inline: 12px;
  }

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

  .inventory-filters {
    grid-template-columns: 1fr;
  }

  .sales-chart {
    gap: 6px;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .channel-pie {
    width: min(220px, 70vw);
  }

  .field.double {
    grid-column: 1 / -1;
  }

  .purchase-grid-header,
  .movement-grid-header {
    display: none;
  }

  .purchase-grid,
  .movement-grid {
    border: 0;
    display: grid;
    gap: 10px;
    overflow: visible;
  }

  .purchase-line,
  .movement-line,
  .movement-grid.with-prices .movement-line {
    border: 1px solid var(--line);
    border-radius: 8px;
    grid-template-columns: 1fr;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

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