:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-alt: #f0efea;
  --text: #171717;
  --muted: #6a6b6d;
  --line: #deded8;
  --orange: #ff7900;
  --orange-strong: #dc5f00;
  --teal: #0f8b8d;
  --green: #208a5d;
  --red: #c43d3d;
  --amber: #b97812;
  --plum: #7d4cc2;
  --shadow: 0 18px 60px rgba(22, 22, 18, 0.09);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 121, 0, 0.06), transparent 360px),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

code {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--orange-strong);
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px);
}

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

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

.brand-lockup span {
  color: var(--muted);
  font-size: 0.84rem;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: var(--orange);
  box-shadow: inset 0 0 0 7px #111;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  border-color: var(--line);
  background: var(--surface-alt);
  color: var(--text);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
}

.status-dot.online {
  background: var(--green);
}

.dashboard {
  width: min(1480px, 100%);
  min-width: 0;
  padding: 34px;
}

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

.topbar h1,
.panel h2,
.modal h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  max-width: 860px;
  font-size: clamp(2rem, 5vw, 4.9rem);
  line-height: 0.95;
}

.panel h2,
.modal h2 {
  font-size: 1.05rem;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--orange-strong);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 750;
}

.primary-button {
  background: var(--text);
  color: #fff;
}

.primary-button:hover {
  background: #000;
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.ghost-button:hover {
  border-color: #bdbdb7;
}

.icon-button {
  width: 38px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
}

.full-width {
  width: 100%;
}

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 121, 0, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 121, 0, 0.08);
  color: #5b3212;
}

.notice.error {
  flex-wrap: wrap;
  border-color: rgba(196, 61, 61, 0.3);
  background: rgba(196, 61, 61, 0.08);
  color: #7a2020;
}

.notice.error .ghost-button {
  margin-left: auto;
}

.status-dot.error {
  background: var(--red);
}

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

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

.metric-card strong {
  display: block;
  margin-top: 18px;
  font-size: clamp(1.9rem, 3.6vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.metric-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-chip {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 14px;
  min-width: 0;
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

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

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-badge {
  white-space: nowrap;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.chart-wrap {
  min-height: 320px;
  overflow: hidden;
}

#volumeChart {
  width: 100%;
  height: 320px;
  display: block;
}

.axis-text {
  fill: #777;
  font-size: 11px;
}

.donut-layout {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}

.donut {
  width: 150px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--green) 0 0);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.legend,
.insight-stack,
.ledger,
.country-list,
.event-list {
  display: grid;
  gap: 10px;
}

.legend-item,
.insight-item,
.ledger-item,
.country-item,
.event-item {
  display: grid;
  gap: 4px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.legend-item:last-child,
.insight-item:last-child,
.ledger-item:last-child,
.country-item:last-child,
.event-item:last-child {
  border-bottom: 0;
}

.legend-row,
.country-top,
.event-top,
.ledger-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.legend-name,
.country-name,
.event-name,
.ledger-name {
  font-weight: 800;
}

.legend-value,
.country-value,
.event-value,
.ledger-value {
  color: var(--muted);
  font-size: 0.86rem;
}

.color-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
}

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

.insight-item::before {
  content: "";
  width: 4px;
  border-radius: 999px;
  background: var(--teal);
}

.insight-item.warning::before {
  background: var(--amber);
}

.insight-item.danger::before {
  background: var(--red);
}

.insight-item.good::before {
  background: var(--green);
}

.insight-title {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.insight-value {
  display: block;
  margin-top: 2px;
  font-size: 1.24rem;
  font-weight: 850;
}

.insight-detail {
  color: var(--muted);
  font-size: 0.88rem;
}

.table-wrap {
  min-width: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
}

td {
  font-size: 0.93rem;
}

.app-name {
  display: grid;
  gap: 4px;
}

.app-name strong {
  font-size: 0.96rem;
}

.app-name span {
  color: var(--muted);
  font-size: 0.8rem;
}

.progress {
  height: 7px;
  width: 130px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-alt);
}

.progress span {
  display: block;
  height: 100%;
  max-width: 100%;
  background: linear-gradient(90deg, var(--orange), var(--teal));
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 850;
}

.status-delivered {
  background: rgba(32, 138, 93, 0.12);
  color: var(--green);
}

.status-pending {
  background: rgba(185, 120, 18, 0.13);
  color: var(--amber);
}

.status-failed {
  background: rgba(196, 61, 61, 0.12);
  color: var(--red);
}

.event-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(255, 121, 0, 0.25);
  outline-offset: 2px;
}

.modal {
  width: min(460px, calc(100vw - 24px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
}

.modal::backdrop {
  background: rgba(20, 20, 20, 0.45);
  backdrop-filter: blur(6px);
}

.modal-panel {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #151515;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 750;
  z-index: 10;
}

.kv-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv-key {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.kv-val {
  text-align: right;
  font-size: 0.9rem;
  word-break: break-word;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state strong {
  color: var(--text);
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(32, 138, 93, 0.5);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(32, 138, 93, 0.45); }
  70% { box-shadow: 0 0 0 6px rgba(32, 138, 93, 0); }
  100% { box-shadow: 0 0 0 0 rgba(32, 138, 93, 0); }
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .nav-stack {
    display: flex;
    min-width: max-content;
  }

  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
  }

  .dashboard {
    padding: 22px;
  }

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

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

@media (max-width: 720px) {
  .sidebar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
    width: 100%;
    min-width: 0;
  }

  .sidebar-footer {
    margin-left: 0;
  }

  .nav-stack {
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    flex: 0 0 auto;
  }

  .topbar {
    display: grid;
  }

  .topbar h1 {
    font-size: 2.45rem;
  }

  .topbar-actions,
  .topbar-actions button {
    width: 100%;
  }

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

  .metric-card {
    min-height: 132px;
  }

  .donut-layout {
    grid-template-columns: 1fr;
  }

  .donut {
    margin: 0 auto;
  }

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