:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f4;
  --line: #d8e1e4;
  --text: #162023;
  --muted: #647276;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --danger: #b42318;
  --warning: #946200;
  --shadow: 0 16px 40px rgba(22, 32, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.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: 20px;
  background: #182427;
  color: #f8fbfb;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #0f766e;
  color: #ffffff;
  font-weight: 800;
  font-size: 13px;
}

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

.brand span {
  margin-top: 2px;
  color: rgba(248, 251, 251, 0.7);
  font-size: 13px;
}

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

.nav-group {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.nav-group-label {
  padding: 0 12px 4px;
  color: rgba(248, 251, 251, 0.58);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.nav-button {
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(248, 251, 251, 0.78);
  text-align: left;
}

.nav-sub-button {
  padding-left: 26px;
  font-size: 14px;
}

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

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

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

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

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

h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.date-pill,
.count-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.view {
  display: none;
}

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

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

.metric {
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.metric strong {
  display: block;
  margin-top: 14px;
  font-size: 25px;
  line-height: 1.15;
}

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

.compact-metric {
  min-height: 96px;
}

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

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

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

.compact-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.compact-filter select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 30px 6px 10px;
  background: #ffffff;
  color: var(--text);
}

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

.form-grid,
.cost-grid {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.import-workflow {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #f8fafb;
}

.supplier-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  align-self: stretch;
}

.supplier-button,
.upload-tile {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
}

.supplier-button {
  padding: 10px;
  font-weight: 800;
}

.supplier-button.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: #e9f7f5;
  color: var(--primary-dark);
}

.upload-tile {
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px 12px;
}

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

.upload-tile strong {
  font-size: 13px;
}

.upload-tile input {
  display: none;
}

.hidden {
  display: none !important;
}

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

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

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

.finance-section {
  border-top: 1px solid var(--line);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
}

.stacked-form {
  display: grid;
}

label {
  display: grid;
  gap: 7px;
  color: #344145;
  font-size: 13px;
  font-weight: 650;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(15, 118, 110, 0.16);
}

textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px 18px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 9px 12px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #ffffff;
}

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

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.danger-button {
  border: 1px solid rgba(180, 35, 24, 0.35);
  background: #fff5f4;
  color: var(--danger);
}

.file-button {
  display: grid;
  place-items: center;
}

.file-button input {
  display: none;
}

.compact-file {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.import-summary {
  display: none;
  margin: 0 18px 18px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 6px;
  padding: 10px 12px;
  background: #effaf8;
  color: #25514e;
  font-size: 13px;
}

.import-summary.active {
  display: block;
}

.purchase-helper-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 0 18px 18px;
}

.workflow-guide {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.workflow-guide {
  padding: 14px;
}

.workflow-guide .section-title {
  margin-bottom: 8px;
}

.upload-guide {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 6px;
  background: #effaf8;
}

.upload-guide > strong {
  font-size: 13px;
}

.upload-guide-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
}

.upload-guide-row span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #0f766e;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
}

.upload-guide-row p {
  margin: 1px 0 0;
  color: #25514e;
  font-size: 12px;
  line-height: 1.35;
}

.workflow-checklist {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.workflow-checklist li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.workflow-checklist span {
  display: grid;
  place-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #eef3f4;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.workflow-checklist p {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.workflow-checklist li.done {
  border-color: rgba(15, 118, 110, 0.24);
  background: #effaf8;
}

.workflow-checklist li.done span {
  background: #0f766e;
  color: #ffffff;
}

.workflow-checklist li.warning {
  border-color: rgba(148, 98, 0, 0.28);
  background: #fff8e8;
}

.workflow-checklist li.warning span {
  background: #946200;
  color: #ffffff;
}

.sync-log {
  display: grid;
  padding: 4px 18px 18px;
}

.sync-log-row {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.sync-log-row span {
  color: var(--muted);
  font-size: 13px;
}

.sync-log-row strong {
  min-width: 0;
  font-size: 13px;
}

.bulk-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.bulk-toolbar > div:first-child {
  display: grid;
  gap: 2px;
}

.compact-button {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.product-select-checkbox {
  width: 16px;
  height: 16px;
}

.document-list {
  display: grid;
  gap: 8px;
  padding: 0 18px 18px;
}

.document-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.document-row > div:first-child {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.document-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.document-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  white-space: nowrap;
}

.document-row small {
  color: var(--muted);
  font-size: 12px;
}

.empty-document-row {
  justify-content: start;
}

.line-entry {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 110px 120px 150px auto;
  gap: 10px;
  padding: 0 18px 14px;
}

.table-input {
  min-height: 32px;
  width: 112px;
  max-width: 112px;
  padding: 6px 8px;
  text-align: right;
}

.table-text-input {
  min-height: 32px;
  width: 100%;
  padding: 6px 8px;
}

.edit-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  min-width: 0;
}

.edit-cell:has(input) {
  min-width: max-content;
}

.number-edit-cell {
  justify-content: flex-end;
}

.locked-cell-value {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 26px;
}

.number-edit-cell .locked-cell-value {
  text-align: right;
}

.icon-edit-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  opacity: 0;
  transition: opacity 120ms ease, border-color 120ms ease, color 120ms ease;
}

tr:hover .icon-edit-button,
.edit-cell:focus-within .icon-edit-button,
.icon-edit-button:focus {
  opacity: 1;
}

.icon-edit-button:hover {
  border-color: rgba(15, 118, 110, 0.35);
  color: var(--primary-dark);
}

.barcode-input {
  min-width: 190px;
}

.product-name-input {
  min-width: 520px;
}

.product-thumb {
  display: block;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #f8fafb;
}

.table-wrap {
  width: 100%;
  max-height: calc(100vh - 220px);
  overflow: auto;
}

.table-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.table-controls label {
  width: min(320px, 100%);
}

.table-controls .secondary-button {
  min-height: 40px;
}

.table-sort-direction {
  min-width: 112px;
}

.table-wrap.compact {
  max-height: calc(100vh - 280px);
  padding: 0 18px 16px;
}

.table-wrap.compact table {
  min-width: 1380px;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafb;
  color: #4b5a5f;
  font-size: 12px;
  text-transform: uppercase;
  box-shadow: 0 1px 0 var(--line);
}

th[data-sort-ready="true"] {
  cursor: pointer;
  user-select: none;
}

th.sort-active {
  color: var(--primary-dark);
  background: #eef8f6;
}

th.sort-active::after {
  content: " ↑";
  font-size: 11px;
}

th.sort-active[data-sort-direction="desc"]::after {
  content: " ↓";
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #fbfdfd;
}

.table-row-hidden {
  display: none;
}

.number {
  text-align: right;
}

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

.small-button {
  display: inline-flex;
  align-items: center;
  min-height: 31px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 9px;
  background: #ffffff;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.danger-text-button {
  color: #b42318;
  border-color: #f3b7ae;
}

.status-warn {
  color: var(--warning);
  font-weight: 700;
}

.status-good {
  color: var(--primary-dark);
  font-weight: 700;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  color: var(--text);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .nav-group {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 0;
  }

  .nav-group-label {
    grid-column: 1 / -1;
    text-align: center;
  }

  .nav-button {
    text-align: center;
  }

  .nav-sub-button {
    padding-left: 12px;
  }

  .metric-grid,
  .split-layout,
  .form-grid,
  .cost-grid,
  .purchase-helper-grid,
  .import-workflow {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .workspace {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

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

  .bulk-toolbar .row-actions {
    justify-content: start;
    flex-wrap: wrap;
  }

  .metric-grid,
  .split-layout,
  .form-grid,
  .cost-grid,
  .line-entry,
  .sync-log-row,
  .nav,
  .nav-group,
  .purchase-helper-grid,
  .import-workflow {
    grid-template-columns: 1fr;
  }

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

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

  .primary-button,
  .secondary-button,
  .danger-button {
    width: 100%;
  }
}
