:root {
  --bg: #eef2f0;
  --surface: #ffffff;
  --ink: #151d1b;
  --muted: #64716d;
  --line: #d8dfdc;
  --terminal: #101820;
  --terminal-2: #17232d;
  --green: #0f8f72;
  --green-soft: #dff5ed;
  --red: #c2413b;
  --red-soft: #fde9e7;
  --amber: #b7791f;
  --blue: #2563a8;
  --shadow: 0 10px 24px rgba(21, 29, 27, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.mobile-only {
  display: none;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(16, 24, 32, 0.05), transparent 180px),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.dashboard-shell {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  letter-spacing: 0;
}

.eyebrow,
.panel-kicker {
  margin-bottom: 3px;
  color: var(--green);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0;
}

#updateTime {
  display: inline-block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ghost-link,
.text-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  font-size: 13px;
  white-space: nowrap;
}

.text-link {
  border-color: transparent;
  color: var(--green);
  background: transparent;
}

.terminal-layout {
  display: grid;
  gap: 8px;
}

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

.market-strip > * {
  position: relative;
  min-height: 78px;
  display: grid;
  align-content: space-between;
  gap: 4px;
  overflow: hidden;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(21, 29, 27, 0.05);
}

.metric-card,
.actionable-panel {
  color: inherit;
  text-decoration: none;
}

.metric-card {
  cursor: pointer;
}

.market-strip > *::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--green);
}

.market-strip span,
.market-strip small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.market-strip strong {
  color: var(--ink);
  font-size: 21px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.market-strip > :nth-child(1) {
  background: linear-gradient(135deg, #eefaf5, #ffffff 62%);
}

.market-strip > :nth-child(1)::before {
  background: var(--green);
}

.market-strip > :nth-child(2) {
  background: linear-gradient(135deg, #fff3ee, #ffffff 62%);
}

.market-strip > :nth-child(2)::before {
  background: #e46f45;
}

.market-strip > :nth-child(3) {
  background: linear-gradient(135deg, #fff8e8, #ffffff 62%);
}

.market-strip > :nth-child(3)::before {
  background: var(--amber);
}

.market-strip > :nth-child(3) strong {
  color: #a84436;
}

.market-strip > :nth-child(4) {
  background: linear-gradient(135deg, #eef5ff, #ffffff 62%);
}

.market-strip > :nth-child(4)::before {
  background: var(--blue);
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 8px;
}

.panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(21, 29, 27, 0.04);
}

.panel.wide {
  grid-column: 1 / -1;
}

.primary-panel {
  background:
    linear-gradient(135deg, rgba(15, 143, 114, 0.1), transparent 42%),
    var(--surface);
}

.chart-panel {
  background: var(--terminal-2);
  color: #fff;
}

.chart-panel .panel-kicker,
.chart-panel h2 {
  color: #fff;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.big-number {
  display: grid;
  gap: 2px;
  padding: 2px 0 0;
}

.big-number span,
.big-number small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.big-number strong {
  color: var(--green);
  font-size: 24px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.gauge-row {
  display: grid;
  gap: 6px;
}

.gauge-track {
  height: 8px;
  display: flex;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eeeb;
}

.gauge-track span {
  display: block;
}

.gauge-track .paid {
  background: var(--green);
}

.gauge-track .unpaid {
  background: var(--red);
}

.gauge-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.gauge-labels strong {
  color: var(--red);
}

.stock-trend {
  min-height: 118px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  gap: 7px;
}

.trend-summary,
.mobile-alerts,
.mobile-cost-summary {
  display: none;
}

.trend-day {
  min-width: 0;
  display: grid;
  gap: 6px;
  justify-items: center;
}

.trend-bars {
  height: 76px;
  display: flex;
  align-items: end;
  gap: 5px;
}

.bar {
  width: 10px;
  min-height: 6px;
  display: block;
  border-radius: 6px 6px 0 0;
}

.bar.inbound {
  background: #36d399;
}

.bar.outbound {
  background: #ff8b7f;
}

.trend-day strong {
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
}

.mini-list,
.insight-list {
  display: grid;
  gap: 6px;
}

.mini-list div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 5px 0;
  border-bottom: 1px solid #edf0ec;
  font-size: 13px;
}

.mini-list div:last-child {
  border-bottom: 0;
}

.mini-list span,
.order-list span,
.order-list small {
  color: var(--muted);
  font-size: 12px;
}

.insight {
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.insight strong {
  font-size: 14px;
}

.insight span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.insight.good {
  background: var(--green-soft);
  border-color: #bce8d8;
}

.insight.warn {
  background: var(--red-soft);
  border-color: #f4c6c2;
}

.insight.info {
  background: #e8f1fb;
  border-color: #cbdff5;
}

.insight.muted {
  background: #f6f7f6;
}

.risk-table {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.risk-head,
.risk-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr 0.9fr 0.8fr;
  gap: 10px;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
}

.risk-head {
  background: #f3f6f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.risk-row {
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.danger {
  color: var(--red);
  font-weight: 950;
}

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

.order-list article {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  min-width: 0;
}

.order-list strong,
.risk-row strong {
  overflow-wrap: anywhere;
}

.empty-panel {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 18px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.empty-panel strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  transform: translate(-50%, 20px);
  opacity: 0;
  min-width: 220px;
  max-width: calc(100vw - 36px);
  padding: 13px 16px;
  border-radius: 8px;
  background: var(--terminal);
  color: #fff;
  text-align: center;
  font-weight: 850;
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .dashboard-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    align-items: center;
  }

  h1 {
    font-size: 21px;
  }

  .analysis-grid,
  .order-list {
    grid-template-columns: 1fr;
  }

  .market-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .market-strip > * {
    min-height: 74px;
    padding: 9px 10px;
  }

  .market-strip strong {
    font-size: 19px;
  }

  .market-strip span,
  .market-strip small {
    font-size: 11px;
  }

  .risk-head,
  .risk-row {
    grid-template-columns: 1.1fr 0.9fr 0.8fr;
  }

  .risk-head span:nth-child(4),
  .risk-row span:nth-child(4) {
    display: none;
  }
}

@media (max-width: 768px) {
  :root {
    --terminal: #0d1721;
    --terminal-2: #13212d;
    --surface: #152531;
    --ink: #edf8f7;
    --muted: #9db0b4;
    --line: rgba(159, 205, 200, 0.18);
    --green: #36d3ae;
    --red: #ff886f;
    --amber: #ffc45c;
    --blue: #71b8ff;
  }

  body {
    min-width: 0;
    background:
      linear-gradient(180deg, rgba(24, 80, 92, 0.3), transparent 210px),
      #0b141d;
    color: var(--ink);
  }

  .dashboard-shell {
    width: 100%;
    max-width: none;
    padding: max(9px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 61px;
    align-items: flex-start;
    padding: 3px 2px 7px;
  }

  .eyebrow {
    margin-bottom: 1px;
    color: var(--green);
    font-size: 10px;
    line-height: 1.15;
    letter-spacing: 0.8px;
  }

  h1 {
    color: #f5fffd;
    font-size: 19px;
    line-height: 1.25;
  }

  #updateTime {
    margin-top: 2px;
    color: #87a1a6;
    font-size: 11px;
    line-height: 1.1;
  }

  .ghost-link {
    min-height: 30px;
    padding: 0 9px;
    border-color: rgba(129, 193, 184, 0.27);
    border-radius: 8px;
    background: rgba(21, 43, 53, 0.74);
    color: #dff8f1;
    font-size: 12px;
  }

  .terminal-layout {
    gap: 8px;
  }

  .market-strip {
    gap: 8px;
  }

  .market-strip > * {
    min-width: 0;
    min-height: 80px;
    gap: 3px;
    padding: 9px 10px 8px 13px;
    border-color: rgba(158, 207, 202, 0.16);
    border-radius: 10px;
    background: linear-gradient(145deg, rgba(31, 54, 66, 0.98), rgba(18, 34, 45, 0.98));
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.14);
    touch-action: manipulation;
  }

  .market-strip > *::before {
    width: 3px;
    opacity: 0.95;
  }

  .market-strip > :nth-child(1) {
    background: linear-gradient(145deg, rgba(20, 71, 67, 0.94), rgba(18, 38, 47, 0.98));
  }

  .market-strip > :nth-child(2) {
    background: linear-gradient(145deg, rgba(89, 52, 41, 0.84), rgba(25, 37, 46, 0.98));
  }

  .market-strip > :nth-child(3) {
    background: linear-gradient(145deg, rgba(91, 58, 35, 0.86), rgba(29, 37, 43, 0.98));
  }

  .market-strip > :nth-child(4) {
    background: linear-gradient(145deg, rgba(28, 55, 81, 0.88), rgba(18, 36, 49, 0.98));
  }

  .market-strip span,
  .market-strip small {
    min-width: 0;
    overflow: hidden;
    color: #a8bac0;
    font-size: 11px;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .market-strip strong {
    min-width: 0;
    overflow: hidden;
    color: #f4fffd;
    font-size: 24px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .market-strip > :nth-child(3) strong {
    color: #ffd0c4;
    font-size: 18px;
    letter-spacing: 0;
  }

  .mobile-only {
    display: inline;
  }

  #shippingUnpaid,
  #shippingTotal {
    display: none;
  }

  .analysis-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .panel {
    min-width: 0;
    gap: 7px;
    padding: 10px;
    border-color: rgba(158, 207, 202, 0.16);
    border-radius: 10px;
    background: linear-gradient(145deg, rgba(22, 42, 54, 0.98), rgba(15, 31, 42, 0.98));
    box-shadow: 0 9px 20px rgba(0, 0, 0, 0.12);
  }

  .actionable-panel {
    touch-action: manipulation;
  }

  .panel-kicker {
    margin-bottom: 1px;
    color: var(--green);
    font-size: 10px;
    letter-spacing: 0.45px;
  }

  h2 {
    color: #f2fbf9;
    font-size: 15px;
    line-height: 1.2;
  }

  .text-link {
    min-height: 0;
    padding: 0;
    color: #82e1ca;
    font-size: 11px;
  }

  .primary-panel {
    min-height: 108px;
    background:
      linear-gradient(135deg, rgba(18, 125, 104, 0.25), transparent 58%),
      linear-gradient(145deg, rgba(22, 48, 55, 0.98), rgba(15, 32, 42, 0.98));
  }

  .big-number {
    gap: 3px;
  }

  .big-number span {
    color: #aabcc0;
    font-size: 11px;
  }

  .big-number strong {
    min-width: 0;
    overflow: hidden;
    color: #82ead0;
    font-size: 24px;
    font-variant-numeric: tabular-nums;
    line-height: 1.05;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .big-number small,
  .primary-panel .mini-list,
  .fees-panel .mini-list {
    display: none;
  }

  .gauge-row {
    gap: 4px;
  }

  .gauge-track {
    height: 7px;
    background: rgba(188, 221, 215, 0.16);
  }

  .gauge-labels {
    color: #a9bcc0;
    font-size: 11px;
  }

  .gauge-labels strong {
    color: #ffad99;
  }

  .chart-panel {
    min-height: 118px;
    gap: 5px;
    background:
      linear-gradient(145deg, rgba(26, 60, 70, 0.98), rgba(13, 29, 40, 0.98));
  }

  .stock-trend {
    min-height: 58px;
    gap: 5px;
  }

  .trend-day {
    gap: 3px;
  }

  .trend-bars {
    height: 40px;
    gap: 3px;
  }

  .bar {
    width: 8px;
    max-height: 40px;
    border-radius: 4px 4px 0 0;
  }

  .trend-day strong {
    color: rgba(222, 246, 242, 0.62);
    font-size: 9px;
  }

  .trend-summary {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #a7bdc2;
    font-size: 11px;
  }

  .trend-summary span {
    min-width: 0;
    white-space: nowrap;
  }

  .trend-summary strong {
    color: #eaf9f6;
    font-size: 12px;
  }

  .alerts-panel {
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .alerts-panel .panel-heading,
  .desktop-insights {
    display: none;
  }

  .mobile-alerts {
    display: flex;
    gap: 8px;
  }

  .mobile-alert {
    min-width: 0;
    min-height: 42px;
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 10px;
    border: 1px solid rgba(255, 196, 92, 0.3);
    border-radius: 9px;
    background: rgba(73, 56, 33, 0.55);
    color: #ffe0a5;
    font-size: 12px;
    text-decoration: none;
    touch-action: manipulation;
  }

  .mobile-alert strong {
    min-width: 0;
    overflow: hidden;
    color: #fff5d6;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-alert.is-unpaid {
    border-color: rgba(255, 136, 111, 0.36);
    background: rgba(92, 54, 45, 0.58);
    color: #ffb7a8;
  }

  .mobile-alert.is-low-stock {
    border-color: rgba(255, 196, 92, 0.36);
  }

  .mobile-alert.is-clear {
    justify-content: center;
    border-color: rgba(76, 209, 174, 0.28);
    background: rgba(19, 91, 76, 0.38);
    color: #d9fff4;
  }

  .fees-panel {
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
  }

  .fees-panel .panel-heading {
    min-width: 0;
  }

  .mobile-cost-summary {
    min-width: 0;
    display: grid;
    justify-items: end;
    gap: 2px;
    text-align: right;
  }

  .mobile-cost-summary strong {
    overflow: hidden;
    color: #f7fffd;
    font-size: 17px;
    font-variant-numeric: tabular-nums;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-cost-summary span {
    color: #9cb3b7;
    font-size: 11px;
    white-space: nowrap;
  }

  .desktop-detail-panel {
    display: none;
  }

  .empty-panel {
    border-color: rgba(158, 207, 202, 0.24);
    background: rgba(21, 40, 52, 0.98);
    color: #a9babf;
  }

  .empty-panel strong {
    color: #f0fcf9;
  }

  .toast {
    bottom: max(16px, env(safe-area-inset-bottom));
    border: 1px solid rgba(143, 212, 198, 0.24);
    background: #132934;
    color: #effffb;
  }
}

@media (min-width: 861px) {
  .panel:nth-child(3),
  .panel:nth-child(4) {
    align-self: start;
  }
}
