:root {
  --bg: oklch(0.16 0.012 250);
  --bg-2: oklch(0.19 0.013 250);
  --surface: oklch(0.22 0.014 250);
  --surface-hi: oklch(0.26 0.015 250);
  --border: oklch(0.3 0.015 250);
  --border-hi: oklch(0.38 0.018 250);
  --text: oklch(0.96 0.005 250);
  --text-2: oklch(0.78 0.008 250);
  --muted: oklch(0.6 0.012 250);
  --dim: oklch(0.45 0.012 250);
  --accent: oklch(0.78 0.13 60);
  --accent-soft: oklch(0.78 0.13 60 / 0.18);
  --danger: oklch(0.72 0.16 25);
  --warn: oklch(0.82 0.14 75);
  --ok: oklch(0.74 0.12 150);

  --font-sans: 'Inter', 'Helvetica Neue', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#root {
  min-height: 100vh;
}

button {
  font-family: inherit;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Top bar ============ */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 32px;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, oklch(0.55 0.16 35), oklch(0.78 0.16 60));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: oklch(0.18 0.01 250);
  font-size: 20px;
}
.brand-name {
  font-weight: 700;
  letter-spacing: 1.5px;
  font-size: 13px;
}
.brand-sub {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1.2px;
  margin-top: 2px;
}

.topbar-stats {
  display: flex;
  gap: 28px;
  justify-content: center;
}
.stat {
  text-align: left;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.stat-hi .stat-value {
  color: var(--accent);
}
.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin-top: 2px;
}

.topbar-tools {
  display: flex;
  gap: 12px;
  align-items: center;
}

.search {
  position: relative;
}
.search input {
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 28px 8px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.18s;
}
.search input:focus {
  border-color: var(--accent);
}
.search input::placeholder {
  color: var(--muted);
}
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 16px;
}
.search-clear:hover {
  background: var(--surface-hi);
  color: var(--text);
}

.view-switch {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.view-switch button {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  border-radius: 4px;
  letter-spacing: 0.4px;
}
.view-switch button.active {
  background: var(--surface-hi);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border-hi);
}
.view-switch button:hover:not(.active) {
  color: var(--text);
}

/* ============ Filter strip ============ */
.filter-strip {
  display: flex;
  gap: 8px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  overflow-x: auto;
  scrollbar-width: thin;
}
.f-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s;
}
.f-chip:hover {
  border-color: var(--border-hi);
  color: var(--text);
}
.f-chip.active {
  background: var(--surface-hi);
  color: var(--text);
  border-color: var(--chip-color, var(--accent));
}
.f-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chip-color, var(--accent));
}
.f-chip-count {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 11px;
}
.f-chip.active .f-chip-count {
  color: var(--text-2);
}

/* ============ Main ============ */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  transition: grid-template-columns 0.25s ease;
  min-height: 0;
}
.main.with-panel {
  grid-template-columns: 1fr 420px;
}

.canvas {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at top, oklch(0.2 0.014 250 / 0.4), transparent 70%),
    var(--bg);
}

/* ============ Network view ============ */
.net-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.net-svg {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 180px);
}

/* Floating cards on the canvas */
.legend-card,
.hint-card {
  position: absolute;
  background: oklch(0.2 0.013 250 / 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px;
}
.legend-card {
  top: 20px;
  right: 20px;
  width: 260px;
}
.legend-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin-bottom: 10px;
}
.legend-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.legend-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  text-align: left;
  color: var(--text-2);
  font-size: 12px;
}
.legend-row:hover {
  background: var(--surface);
  color: var(--text);
}
.lr-name {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.lr-days {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 11px;
}
.lr-days.soon {
  color: var(--warn);
}

.hint-card {
  bottom: 20px;
  left: 20px;
  font-size: 12px;
  color: var(--text-2);
  max-width: 360px;
}
.hint-card strong {
  color: var(--accent);
  font-weight: 600;
  margin-right: 4px;
}

/* ============ Departments view ============ */
.dept-grid {
  padding: 24px 28px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}
.dept-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  border-top: 3px solid var(--dept-color);
}
.dept-card-head {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.dept-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.dept-card-title h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.dept-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: oklch(0.18 0.012 250);
  padding: 3px 6px;
  border-radius: 4px;
}
.dept-card-stats {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.dept-card-stats .num {
  font-family: var(--font-mono);
  color: var(--text);
  font-weight: 500;
}
.dept-card-stats .num + .lbl {
  margin-right: 8px;
}
.dept-tools {
  display: flex;
  flex-direction: column;
}
.dept-tool-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid oklch(0.24 0.014 250);
  text-align: left;
  transition: background 0.15s;
}
.dept-tool-row:last-child {
  border-bottom: none;
}
.dept-tool-row:hover {
  background: var(--surface-hi);
}
.dept-tool-info {
  min-width: 0;
}
.dept-tool-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.dept-tool-use {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.dept-tool-price {
  text-align: right;
}
.dept-tool-annual {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}
.dept-tool-monthly {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}
.dept-tool-connects {
  display: flex;
  gap: 3px;
}
.connect-chip {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 2px 5px;
  background: oklch(0.24 0.014 250);
  border-radius: 3px;
}

/* ============ Table view ============ */
.table-wrap {
  padding: 16px 28px;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}
.stack-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.stack-table th {
  position: sticky;
  top: 0;
  background: var(--bg-2);
  z-index: 1;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
}
.sort-arrow {
  color: var(--accent);
  font-size: 10px;
  margin-left: 2px;
}
.stack-table td {
  padding: 10px 12px;
  border-bottom: 1px solid oklch(0.22 0.013 250);
}
.stack-table tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}
.stack-table tbody tr:hover {
  background: var(--surface);
}
.t-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}
.num-cell {
  font-family: var(--font-mono);
  text-align: right;
  white-space: nowrap;
}
td.muted {
  color: var(--text-2);
}
td.small {
  font-size: 12px;
}
.dept-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* ============ Detail panel ============ */
.detail-panel {
  position: relative;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  padding: 24px 24px;
  overflow-y: auto;
  max-height: calc(100vh - 130px);
  animation: slidein 0.22s ease;
}

@keyframes slidein {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 22px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.detail-close:hover {
  background: var(--surface);
  color: var(--text);
}

.detail-hero {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-right: 36px;
}
.detail-hero h2 {
  margin: 4px 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.15;
}
.detail-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 1.4px;
}
.detail-usecase {
  font-size: 13px;
  color: var(--text-2);
}

.dept-hero-tile {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 1.5px;
  color: oklch(0.18 0.012 250);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 24px;
}
.detail-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.detail-stat-big {
  grid-column: span 2;
  background: linear-gradient(135deg, oklch(0.24 0.018 60 / 0.5), var(--surface));
  border-color: oklch(0.4 0.06 60 / 0.4);
}
.ds-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.ds-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.detail-stat-big .ds-value {
  font-size: 26px;
  color: var(--accent);
}
.ds-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}

.detail-section {
  margin-bottom: 18px;
}
.detail-text {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}
.detail-text.muted {
  color: var(--text-2);
}

.dept-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.dept-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--dept-color);
  background: oklch(0.24 0.014 250);
  border: 1px solid var(--border);
  transition: all 0.15s;
}
.dept-chip:hover {
  background: oklch(0.28 0.014 250);
  border-color: var(--dept-color);
}
.dept-chip.primary {
  background: color-mix(in oklch, var(--dept-color) 18%, transparent);
  border-color: var(--dept-color);
}

.expires-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.ex-date {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
}
.ex-rel {
  font-size: 11px;
  color: var(--muted);
}
.expires-badge.ex-soon {
  background: color-mix(in oklch, var(--warn) 12%, transparent);
  border-color: color-mix(in oklch, var(--warn) 40%, transparent);
}
.expires-badge.ex-soon .ex-rel {
  color: var(--warn);
}
.expires-badge.ex-expired {
  background: color-mix(in oklch, var(--danger) 12%, transparent);
  border-color: color-mix(in oklch, var(--danger) 40%, transparent);
}
.expires-badge.ex-expired .ex-rel {
  color: var(--danger);
}

.detail-tool-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dept-tool-mini {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  text-align: left;
  background: transparent;
  transition: background 0.12s;
}
.dept-tool-mini:hover {
  background: var(--surface);
}
.dtm-name {
  font-size: 13px;
  font-weight: 500;
}
.dtm-cost {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
}
.dtm-cost-muted {
  font-size: 10px;
  color: var(--muted);
  font-style: italic;
  font-family: var(--font-sans);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-hi);
}

/* Responsive niceties */
@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .topbar-stats {
    justify-content: flex-start;
    gap: 18px;
    overflow-x: auto;
  }
  .main.with-panel {
    grid-template-columns: 1fr;
  }
  .detail-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ============ Password gate ============ */
.gate-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, oklch(0.24 0.04 60 / 0.4), transparent 60%),
    radial-gradient(ellipse at 70% 80%, oklch(0.22 0.04 220 / 0.3), transparent 60%),
    var(--bg);
  z-index: 1000;
}
.gate-card {
  width: 380px;
  padding: 36px 36px 28px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 30px 80px oklch(0 0 0 / 0.5);
}
.gate-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 18px;
  border-radius: 12px;
  background: linear-gradient(135deg, oklch(0.55 0.16 35), oklch(0.78 0.16 60));
  display: flex;
  align-items: center;
  justify-content: center;
  color: oklch(0.18 0.01 250);
  font-size: 28px;
  font-weight: 800;
}
.gate-title {
  font-weight: 700;
  letter-spacing: 1.8px;
  font-size: 13px;
  color: var(--text);
}
.gate-sub {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1.2px;
  margin-top: 4px;
  margin-bottom: 28px;
}
.gate-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}
.gate-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  font-weight: 600;
}
.gate-form input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.gate-form input:focus {
  border-color: var(--accent);
}
.gate-btn {
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: oklch(0.18 0.01 250);
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.4px;
  transition: filter 0.15s;
}
.gate-btn:hover:not(:disabled) { filter: brightness(1.1); }
.gate-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.gate-err {
  font-size: 12px;
  color: var(--danger);
  text-align: center;
  margin-top: 4px;
}
.gate-foot {
  font-size: 11px;
  color: var(--muted);
  margin-top: 22px;
}

/* ============ Boot loading ============ */
.boot-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
}
.boot-spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot-msg {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

/* ============ Data-source pill ============ */
.data-source {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ds-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.data-source.ds-live .ds-dot {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}
.data-source.ds-warn .ds-dot {
  background: var(--warn);
  box-shadow: 0 0 8px var(--warn);
}
.ds-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.1;
}
.ds-source {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}
.ds-time {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.6px;
}
.data-source.ds-warn .ds-source { color: var(--warn); }
.ds-btn {
  margin-left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ds-btn:hover {
  background: var(--surface-hi);
  color: var(--text);
}
