:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --border: #c7cdd4;
  --text: #1b2430;
  --text-dim: #5b6672;
  --accent: #2c5aa0;
  --success: #1a7a3c;
  --success-bg: #e3f4e8;
  --failure: #b3261e;
  --failure-bg: #fbe4e2;
  --dup: #8a5a00;
  --dup-bg: #fbedd3;
  --backfill: #5b3a9c;
  --backfill-bg: #ece3f8;
  --header-bg: #1b2430;
  --header-text: #eef1f4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
}

body.chaos {
  background: #3a0e0e;
}

table { font-variant-numeric: tabular-nums; }

header.topbar {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--accent);
}

body.chaos header.topbar {
  border-bottom-color: var(--failure);
  background: #1b0a0a;
}

header.topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}

header.topbar .subtitle {
  font-size: 12px;
  color: #aab3bd;
  margin-top: 2px;
}

.chaos-banner {
  display: none;
  background: var(--failure);
  color: #fff;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px;
  font-size: 15px;
}

body.chaos .chaos-banner {
  display: block;
}

.actions {
  display: flex;
  gap: 10px;
  padding: 12px 24px;
  background: #dde2e8;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
}

.actions button {
  font-size: 14px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 3px;
  cursor: pointer;
  font-weight: 600;
}

.actions button:hover { background: #f4f6f8; }
.actions button:active { background: #e5e9ed; }

.actions button.chaos-btn.is-on {
  background: var(--failure);
  color: #fff;
  border-color: var(--failure);
}

.actions .status-pill {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-dim);
}

.actions .status-pill strong { color: var(--text); }

main {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
  padding: 16px 24px 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #f4f6f8;
}

#panel-stock { grid-column: 1; grid-row: 1; }
#panel-orders { grid-column: 1; grid-row: 2; }
#panel-log { grid-column: 2; grid-row: 1 / span 2; max-height: calc(100vh - 160px); }

.panel-body { overflow-y: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.data th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
}

table.data td {
  padding: 7px 14px;
  border-bottom: 1px solid #edf0f3;
}

table.data tr:last-child td { border-bottom: none; }

.stock-low { color: var(--failure); font-weight: 700; }

.source-badge {
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 2px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.source-badge.webhook { background: var(--success-bg); color: var(--success); }
.source-badge.backfill { background: var(--backfill-bg); color: var(--backfill); }

.log-row {
  display: grid;
  grid-template-columns: 90px 90px 1fr 130px;
  gap: 10px;
  align-items: baseline;
  padding: 9px 14px;
  border-bottom: 1px solid #edf0f3;
  font-size: 14px;
}

.log-row .time { color: var(--text-dim); font-size: 12px; }
.log-row .dir { font-size: 11px; text-transform: uppercase; color: var(--text-dim); }
.log-row .detail { color: var(--text); }
.log-row .event { font-weight: 600; }

.log-row.flash { animation: flash-in 1.4s ease-out; }
@keyframes flash-in {
  from { background: #fff4c2; }
  to { background: transparent; }
}

.status-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 3px;
  text-align: center;
}
.status-badge.success { background: var(--success-bg); color: var(--success); }
.status-badge.failure { background: var(--failure-bg); color: var(--failure); }
.status-badge.duplicate-ignored { background: var(--dup-bg); color: var(--dup); }
.status-badge.backfilled { background: var(--backfill-bg); color: var(--backfill); }

.empty-state {
  padding: 24px 14px;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
}

.cost-line {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: #f4f6f8;
}
