:root {
  --bg: #11141a;
  --panel: #171c26;
  --panel-alt: #1d2330;
  --border: #2a313f;
  --text: #e8eaed;
  --text-muted: #8993a4;
  --text-dim: #5b6478;

  --accent: #e8973a;       /* amber - priority / action */
  --accent-soft: rgba(232, 151, 58, 0.16);
  --good: #3ddc97;         /* teal-green - mined / healthy */
  --good-soft: rgba(61, 220, 151, 0.14);
  --alert: #e2545a;        /* red - conflicts */
  --alert-soft: rgba(226, 84, 90, 0.16);
  --info: #5b9bd9;

  --font-display: "Bahnschrift", "Segoe UI Semibold", "Segoe UI", system-ui, sans-serif;
  --font-body: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SF Mono", monospace;

  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  overflow: hidden;
}

#shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
}

#shell.with-detail {
  grid-template-columns: 232px 1fr 340px;
}

/* ---------- Sidebar ---------- */

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  overflow-y: auto;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 18px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.nav-group { margin-bottom: 18px; }

.nav-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 0 8px 6px 8px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-label::after {
  content: '▾';
  font-size: 10px;
  transition: transform 0.15s;
}
.nav-group.collapsed .nav-label::after {
  transform: rotate(-90deg);
}
.nav-group.collapsed .nav-item {
  display: none;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  text-align: left;
  padding: 8px 8px;
  border-radius: var(--radius);
  cursor: pointer;
}

.nav-item:hover:not(.disabled) {
  background: var(--panel-alt);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.nav-item.active .nav-dot { background: var(--accent); }

.nav-item.disabled {
  color: var(--text-dim);
  cursor: default;
  display: flex;
  justify-content: space-between;
}

.soon {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 1px 6px;
  border-radius: 999px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px 8px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  border-top: 1px solid var(--border);
}

/* ---------- Content ---------- */

#content {
  overflow-y: auto;
  padding: 28px 34px;
  min-height: 0;
}

.view-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}

.view-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
}

.view-subtitle {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-top: 3px;
}

.btn {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1408;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Cards / stats ---------- */

.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-card .stat-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
}

.stat-card .stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-card.alert .stat-value { color: var(--alert); }
.stat-card.good .stat-value { color: var(--good); }
.stat-card.accent .stat-value { color: var(--accent); }

/* ---------- Tables ---------- */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
}

table.data-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr { cursor: pointer; }
table.data-table tbody tr:hover { background: var(--panel-alt); }

td.num, th.num { font-family: var(--font-mono); text-align: right; }
table.data-table th.num { text-align: right; }
table.data-table tr.group-total td { border-top: 1px solid var(--border); background: transparent; cursor: default; }
table.data-table tr.group-total:hover { background: transparent; }
table.data-table tr.group-first td { border-top: 2px solid var(--border); }

.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.type-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}

.resource-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}
.filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-right: 4px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}
.filter-chip:has(input:checked) {
  border-color: var(--chip-color, var(--accent));
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 15%, var(--panel));
}
.filter-chip input[type=checkbox] {
  display: none;
}
.filter-all {
  --chip-color: var(--accent);
}

.paste-panel {
  position: fixed;
  bottom: 0;
  left: 230px;
  right: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
}
.paste-panel.hidden { display: none; }
.paste-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}
.paste-panel-body {
  padding: 16px 20px;
}
.paste-panel-body textarea {
  width: 100%;
  height: 140px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 8px;
  resize: vertical;
  box-sizing: border-box;
}
.paste-panel-body textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.ship-class-btn {
  padding: 3px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.ship-class-btn.active, .ship-class-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.resource-mix-table {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
  width: 100%;
}
.resource-mix-table thead th {
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  padding: 0 8px 4px 0;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.resource-mix-table thead th.num,
.resource-mix-table td.num {
  text-align: right;
}
.resource-mix-table td {
  padding: 2px 8px 2px 0;
  vertical-align: middle;
}
.resource-mix-table td .type-swatch {
  margin-right: 5px;
  vertical-align: middle;
}

.change-system-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 10px;
  font-family: var(--font-body);
  cursor: pointer;
  padding: 0;
  margin-top: 2px;
  opacity: 0.8;
  text-align: left;
}
.change-system-btn:hover { opacity: 1; text-decoration: underline; }

.attention-card-grid {
  display: flex;
  gap: 16px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.attention-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px 28px;
  min-width: 200px;
  flex: 1;
}
.attention-card.clickable {
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.attention-card.clickable:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}
.attention-card-count {
  font-size: 48px;
  font-weight: 700;
  font-family: 'Bahnschrift', sans-serif;
  line-height: 1;
}
.attention-card-label {
  font-size: 14px;
  font-weight: 600;
  margin-top: 6px;
}
.attention-card-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.attention-card.empty .attention-card-label { color: var(--text-dim); }
.attention-card {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, background 0.15s;
  min-width: 140px;
  padding: 16px 20px;
}
.attention-card:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.attention-card-count { font-size: 36px; }
.attention-section-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 28px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.attention-count {
  font-size: 14px;
  font-weight: 700;
  font-family: 'Bahnschrift', sans-serif;
}

.system-card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 8px;
}
.system-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px 32px;
  cursor: pointer;
  text-align: left;
  min-width: 200px;
  transition: border-color 0.15s, background 0.15s;
}
.system-card:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}
.system-card-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.system-card-meta {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-bottom: 8px;
}
.system-card-desc {
  font-size: 13px;
  color: var(--text-dim);
}

.section-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  margin: 28px 0 10px 0;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .btn { margin-top: 14px; }

/* ---------- Planet grid view ---------- */

.planet-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.planet-pill {
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-muted);
  cursor: pointer;
}
.planet-pill.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

#grid-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 20px;
}

.grid-table {
  border-collapse: collapse;
}

.grid-table .axis-corner, .grid-table .axis-x, .grid-table .axis-y {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
}

.grid-cell {
  width: 58px;
  height: 58px;
  border: 1px solid var(--border);
  border-radius: 4px;
  vertical-align: middle;
  text-align: center;
  cursor: pointer;
  position: relative;
}

.grid-cell:hover {
  outline: 1.5px solid var(--text-muted);
}

.grid-cell.empty { background: rgba(255,255,255,0.015); }

.grid-cell .cell-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  line-height: 1.25;
  color: var(--text);
  pointer-events: none;
}

.grid-cell.mined { border-style: solid; }
.grid-cell.unmined { border-style: dashed; border-width: 1.5px; }

.grid-cell .flag {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--alert);
}

.grid-cell .running-dot {
  position: absolute;
  bottom: 3px;
  left: 3px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid #fff;
  opacity: 0.9;
}

.legend {
  display: flex;
  gap: 18px;
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.legend span.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}

/* ---------- Detail panel ---------- */

#detail-panel {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#detail-panel.hidden { display: none; }

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 14px;
}

#detail-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

#detail-body {
  padding: 16px 18px;
  overflow-y: auto;
  font-size: 13px;
  flex: 1;
  min-height: 0;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row .k { color: var(--text-muted); }
.detail-row .v { font-family: var(--font-mono); text-align: right; }

.issue-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.issue-item {
  background: var(--panel);
  border: 1px solid var(--alert-soft);
  border-left: 3px solid var(--alert);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12.5px;
}
.issue-item .issue-meta {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 11.5px;
  margin-top: 3px;
}

.stat-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------- System map ---------- */

.sys-cell {
  width: 32px;
  height: 32px;
  border-radius: 3px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  transition: transform 0.1s, box-shadow 0.1s;
}
.sys-cell.occupied {
  cursor: pointer;
}
.sys-cell.occupied:hover {
  transform: scale(1.15);
  z-index: 2;
  box-shadow: 0 0 6px rgba(255,255,255,0.2);
}
.sys-cell.selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 3;
}

/* ---------- Scans dashboard ---------- */

.scan-system-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 220px;
  max-width: 260px;
  flex: 1;
  transition: border-color 0.15s;
}
.scan-system-card:hover { border-color: var(--accent); }
.scan-system-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.scan-system-date {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.scan-type-cell:hover { color: var(--accent) !important; text-decoration: underline; }

.scan-system-iff {
  font-size: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.filter-btn {
  padding: 3px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.filter-btn.active, .filter-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 5px 10px;
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }

.detail-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
  font-size: 13px;
}
.detail-dl dt {
  color: var(--text-muted);
  white-space: nowrap;
}
.detail-dl dd {
  margin: 0;
  word-break: break-all;
}

/* NPC Cargo */
.cargo-calc-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cargo-calc-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cargo-calc-row label {
  width: 140px;
  font-size: 13px;
  color: var(--text-dim);
}
.cargo-calc-input {
  width: 64px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 4px 8px;
  text-align: center;
}
.cargo-calc-input:focus { outline: none; border-color: var(--accent); }
.cargo-calc-result {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
}
.cargo-calc-result strong {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 18px;
}

/* Scan detail — entity tracking */
.scan-entity-id {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-left: 6px;
  opacity: .7;
}
.scan-history-entry {
  padding: 8px 10px;
  border-left: 2px solid var(--border);
  margin-bottom: 8px;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--bg);
}
.scan-history-entry.current {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg));
}
.scan-history-header {
  display: flex;
  align-items: center;
  margin-bottom: 3px;
}
.scan-owner-cell:hover { color: var(--accent) !important; text-decoration: underline; }

/* Overview module grid */
.overview-module-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 8px;
}
.overview-module-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.overview-module-card:hover { background: var(--panel-hover, #1e2330); border-color: var(--text-dim); }
.scan-id-link { color: #7eb8f7; cursor: pointer; }
.scan-id-link:hover { text-decoration: underline; }
