:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --ink: #1a1a18;
  --ink-secondary: #5c5c56;
  --ink-tertiary: #8a8a82;
  --rule: #d8d6d0;
  --accent: #2d6a4f;
  --accent-hover: #245a42;
  --accent-light: #eaf3ee;
  --alert: #b44d12;
  --alert-light: #fdf1e8;
  --success: #2d6a4f;
  --success-light: #eaf3ee;
  --fedex-purple: #4d148c;
  --fedex-light: #f3eef8;
  --usps-blue: #004b87;
  --usps-light: #e8f0f7;
  --sync-blue: #1a6fb5;
  --sync-light: #e6f0fa;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171714;
    --surface: #222220;
    --ink: #e8e8e4;
    --ink-secondary: #a0a098;
    --ink-tertiary: #6e6e66;
    --rule: #3a3a36;
    --accent: #52b788;
    --accent-hover: #6fcf9a;
    --accent-light: #1e2e24;
    --alert: #e8853a;
    --alert-light: #2e2218;
    --success: #52b788;
    --success-light: #1e2e24;
    --fedex-purple: #9b7ec8;
    --fedex-light: #252030;
    --usps-blue: #5a9ec4;
    --usps-light: #1a2530;
    --sync-blue: #5a9ec4;
    --sync-light: #1a2530;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  line-height: 1.55;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 28px;
}
.header-brand {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  margin-bottom: 4px;
}
.title {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 2px;
}
.subtitle {
  font-size: 13px;
  color: var(--ink-secondary);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.last-updated {
  font-size: 11px;
  color: var(--ink-tertiary);
  white-space: nowrap;
}

.btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--accent-light); }
.btn-ghost {
  background: transparent;
  color: var(--ink-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface); border-color: var(--rule); }

.btn-group {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-info {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1px solid var(--ink-tertiary);
  background: transparent;
  color: var(--ink-tertiary);
  font-size: 11px;
  font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.btn-info:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--accent-light);
}
.tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-secondary);
  z-index: 100;
}
.tooltip.visible { display: block; }
@media (prefers-color-scheme: dark) {
  .tooltip { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
}

.sync-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--sync-light);
  border-left: 3px solid var(--sync-blue);
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--sync-blue);
  font-weight: 500;
}
.sync-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--sync-blue);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  background: var(--alert-light);
  border-left: 3px solid var(--alert);
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--alert);
}

.hidden { display: none !important; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.stat-row-bottom {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 16px 18px;
  border-radius: 8px;
}
.stat-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 8px;
}

.section { margin-bottom: 28px; }
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 14px;
}
.btn-sm {
  font-size: 11px;
  padding: 5px 12px;
}
.section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 14px;
}

.carrier-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.carrier-card {
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.carrier-card.usps { background: var(--usps-light); border-color: var(--usps-blue); border-left-width: 3px; }
.carrier-card.fedex { background: var(--fedex-light); border-color: var(--fedex-purple); border-left-width: 3px; }
.carrier-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.carrier-card.usps .carrier-name { color: var(--usps-blue); }
.carrier-card.fedex .carrier-name { color: var(--fedex-purple); }
.carrier-stats { display: flex; gap: 20px; }
.carrier-stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.carrier-stat-label {
  font-size: 11px;
  color: var(--ink-secondary);
  margin-top: 2px;
}

.projection-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px 18px;
}
.projection-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  color: var(--ink-secondary);
  border-bottom: 1px solid var(--rule);
}
.projection-row:last-child { border-bottom: none; }
.projection-row.total { color: var(--ink); font-weight: 600; }
.projection-row strong {
  font-variant-numeric: tabular-nums;
}
.projection-note {
  font-size: 11px;
  color: var(--ink-tertiary);
  margin-top: 6px;
}

.alert-box {
  background: var(--alert-light);
  border-left: 3px solid var(--alert);
  padding: 14px 18px;
  border-radius: 0 8px 8px 0;
}
.alert-box .alert-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--alert);
  margin-bottom: 8px;
}
.success-box {
  background: var(--success-light);
  border-left: 3px solid var(--success);
  padding: 14px 18px;
  border-radius: 0 8px 8px 0;
}
.success-box .success-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--success);
  margin-bottom: 4px;
}
.success-box .success-body {
  font-size: 13px;
  color: var(--ink-secondary);
}

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  background: var(--bg);
}
td {
  font-size: 13px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
}
tr:last-child td { border-bottom: none; }
tr.stale td { color: var(--alert); font-weight: 500; }

.tab-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
}
.tab-row:last-child { border-bottom: none; }
.tab-name { color: var(--ink); }
.tab-result {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-secondary);
  text-align: right;
}

.footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-tertiary);
  display: flex;
  justify-content: space-between;
}

.product-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  background: #fef3c7;
  color: #92400e;
  white-space: nowrap;
}
.product-tag.cgm {
  background: #dbeafe;
  color: #1e40af;
}

.inv-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 14px;
  margin-bottom: 14px;
}
.inv-stock-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 16px 18px;
}
.inv-breakdown {
  font-size: 12px;
  color: var(--ink-secondary);
  margin-top: 8px;
  line-height: 1.6;
}
.inv-form-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
}
.inv-form-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
}
.inv-input {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
}
.inv-input:focus {
  outline: none;
  border-color: var(--accent);
}
select.inv-input { min-width: 140px; }
input[type="number"].inv-input { width: 100px; }
.inv-notes { flex: 1; min-width: 120px; }
.inv-history { max-height: 200px; overflow-y: auto; }

input.pack-check {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}
td.pack-cell {
  text-align: center;
}

@media (max-width: 700px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .stat-row-bottom { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .carrier-grid { grid-template-columns: 1fr; }
  .inv-grid { grid-template-columns: 1fr; }
  .header { flex-direction: column; }
  .header-actions { flex-wrap: wrap; }
  .page { padding: 16px 12px 40px; }
  .title { font-size: 20px; }
}

.tag-delayed {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #dc2626;
  color: #fff;
  white-space: nowrap;
}
.tag-shipped-on {
  font-size: 11px;
  color: var(--ink-secondary);
  white-space: nowrap;
}
.tag-awaiting {
  font-size: 11px;
  color: var(--ink-tertiary);
  white-space: nowrap;
}
.tag-delivered {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #16a34a;
  color: #fff;
  white-space: nowrap;
}
.tag-reship {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: #f59e0b;
  color: #000;
  white-space: nowrap;
}

.btn-delete-inv {
  background: none;
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--ink-tertiary);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 6px;
  line-height: 1;
}
.btn-delete-inv:hover {
  color: #dc2626;
  border-color: #dc2626;
}

@media print {
  .header-actions { display: none; }
  .sync-banner, .error-banner { display: none; }
  .page { padding: 12px 0; max-width: 100%; }
  .btn { display: none; }
}
