:root {
  --bg-0: #04111f;
  --bg-1: #081a2e;
  --bg-2: #0d2337;
  --side-pane-width: clamp(220px, 14vw, 270px);
  --card-bg: rgba(8, 21, 35, 0.76);
  --card-border: rgba(138, 185, 227, 0.22);
  --text-main: #eaf4ff;
  --text-dim: #92aac6;
  --accent: #2ec4b6;
  --accent-2: #4d96ff;
  --warn: #ffb703;
  --danger: #ef476f;
  --shadow: 0 18px 40px rgba(2, 7, 16, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans SC", sans-serif;
  color: var(--text-main);
  background: radial-gradient(circle at 20% 0%, #0e3350 0%, var(--bg-1) 32%, var(--bg-0) 80%);
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 28px 28px;
}

.app-shell {
  position: relative;
  max-width: 1920px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: linear-gradient(160deg, rgba(11, 29, 47, 0.85), var(--card-bg));
  border: 1px solid var(--card-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  align-items: center;
  animation: rise-in 420ms ease;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: "Sora", "Noto Sans SC", sans-serif;
  letter-spacing: 0.01em;
}

h1 {
  font-size: 30px;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  font-weight: 600;
}

.status-block {
  min-width: 320px;
  display: grid;
  gap: 6px;
}

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

.label {
  color: var(--text-dim);
  font-size: 13px;
}

.mono {
  font-family: "JetBrains Mono", monospace;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  border: 1px solid transparent;
}

.tag.warn {
  color: #2b1a01;
  background: #ffd166;
  border-color: #f8c14b;
}

.hidden {
  display: none !important;
}

.status-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.feedback {
  color: var(--text-dim);
  font-size: 12px;
}

.layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: var(--side-pane-width) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.controls {
  width: 100%;
  padding: 14px;
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 130px);
  overflow: auto;
}

.controls section {
  border: 1px solid rgba(147, 177, 209, 0.12);
  border-radius: 12px;
  padding: 12px;
  background: rgba(2, 13, 26, 0.42);
}

.controls h2 {
  margin-bottom: 10px;
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

input[type="search"],
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(157, 189, 224, 0.22);
  background: rgba(2, 16, 30, 0.84);
  color: var(--text-main);
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
}

input[type="search"]:focus,
select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(77, 150, 255, 0.18);
}

.btn {
  border: 1px solid rgba(160, 195, 233, 0.3);
  background: linear-gradient(180deg, rgba(23, 55, 86, 0.84), rgba(10, 31, 53, 0.94));
  color: var(--text-main);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 160ms ease, background 180ms ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(183, 221, 255, 0.55);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  border-color: rgba(46, 196, 182, 0.7);
  background: linear-gradient(180deg, #1f8078, #135952);
}

.btn.small {
  padding: 5px 10px;
  font-size: 13px;
}

.country-list {
  max-height: 240px;
  overflow: auto;
  display: grid;
  gap: 6px;
  padding-right: 2px;
}

.country-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(9, 24, 41, 0.55);
  border: 1px solid rgba(133, 173, 215, 0.16);
}

.country-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  cursor: pointer;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}

.range-slider {
  position: relative;
  height: 30px;
  margin: 4px 0 10px;
  touch-action: none;
}

.range-slider-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 8px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: rgba(206, 224, 243, 0.3);
}

.range-slider-fill {
  position: absolute;
  top: 50%;
  height: 8px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(90deg, #1f8bd8, #2ec4b6);
}

.range-slider-handle {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(236, 246, 255, 0.95);
  background: #0f6fc4;
  box-shadow: 0 0 0 4px rgba(46, 196, 182, 0.2);
  cursor: grab;
  padding: 0;
}

.range-slider-handle.start {
  z-index: 2;
}

.range-slider-handle.end {
  z-index: 3;
}

.range-slider-handle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(77, 150, 255, 0.28);
}

.range-slider.dragging .range-slider-handle {
  cursor: grabbing;
}

.quick-range {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.history-tab-btn.active {
  border-color: rgba(46, 196, 182, 0.75);
  background: linear-gradient(180deg, rgba(31, 128, 120, 0.95), rgba(19, 89, 82, 0.95));
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-pane-width);
  gap: 12px;
  align-items: start;
  min-height: calc(100vh - 130px);
  min-width: 0;
}

.main-column {
  display: grid;
  gap: 12px;
  grid-template-rows: 6fr 4fr;
  height: calc(100vh - 130px);
  min-height: 760px;
  min-width: 0;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

.chart-card,
.history-card {
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.chart {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(150, 182, 214, 0.12);
  background: rgba(3, 14, 26, 0.54);
}

.chart.large {
  height: 100%;
  min-height: 360px;
}

.right-sidebar {
  display: grid;
  gap: 14px;
  min-height: calc(100vh - 130px);
  min-width: 0;
}

.right-sidebar .inventory-card {
  position: static;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 130px);
}

.table-wrap {
  overflow: auto;
  max-height: 520px;
}

.history-table-wrap {
  flex: 1;
  max-height: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table {
  min-width: 960px;
  font-size: 11px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0f2a45;
  color: #cde5ff;
}

.history-table thead tr:nth-child(2) th {
  top: 35px;
  z-index: 3;
}

th,
td {
  padding: 7px 6px;
  border-bottom: 1px solid rgba(147, 181, 214, 0.16);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:hover {
  background: rgba(45, 119, 178, 0.15);
}

.history-table .country-merged {
  font-weight: 700;
  letter-spacing: 0.01em;
}

.inventory-card {
  padding: 14px;
}

.inventory-card .card-head {
  margin-bottom: 8px;
}

.inventory-card .card-head h2 {
  font-size: 16px;
  white-space: nowrap;
}

.inventory-card .card-head .hint {
  font-size: 11px;
  white-space: nowrap;
}

.inventory-panel {
  flex: 1;
  max-height: none;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
}

.inv-card {
  border: 1px solid rgba(133, 173, 215, 0.2);
  border-radius: 12px;
  background: rgba(9, 24, 41, 0.62);
  padding: 8px 10px;
}

.inv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.inv-head h3 {
  margin: 0;
  font-family: "Noto Sans SC", sans-serif;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-chip {
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
  border: 1px solid transparent;
  white-space: nowrap;
  flex: none;
}

.inv-chip.inv-up {
  color: #95f9e8;
  background: rgba(46, 196, 182, 0.22);
  border-color: rgba(46, 196, 182, 0.45);
}

.inv-chip.inv-down {
  color: #ffc2d0;
  background: rgba(239, 71, 111, 0.22);
  border-color: rgba(239, 71, 111, 0.45);
}

.inv-chip.inv-pending {
  color: #ffe3a1;
  background: rgba(255, 183, 3, 0.2);
  border-color: rgba(255, 183, 3, 0.42);
}

.inv-chip.inv-unconfigured {
  color: #d0dbe7;
  background: rgba(141, 164, 188, 0.2);
  border-color: rgba(141, 164, 188, 0.4);
}

.inv-label {
  margin: 4px 0 8px;
  color: #eaf4ff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-grid {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 3px 8px;
  font-size: 13px;
  color: #9fbcdd;
  min-width: 0;
}

.inv-grid span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-grid span:nth-child(2n) {
  color: #d6eaff;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1360px) {
  .layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .dashboard {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .right-sidebar {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .right-sidebar .inventory-card {
    position: static;
    min-height: auto;
  }

  .main-column {
    grid-template-rows: auto auto;
    height: auto;
    min-height: 0;
  }

  .chart.large {
    height: 540px;
  }
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls {
    max-height: none;
  }

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

  .status-block {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
  }

  h1 {
    font-size: 24px;
  }

  .chart.large {
    height: 440px;
  }
}
