:root {
  --bg: #0c0f14;
  --panel: #121821;
  --text: #e7eef7;
  --muted: #9fb3c8;
  --accent: #5cc8ff;
  --accent-2: #7ef7c5;
  --danger: #ff6b6b;
  --border: #253142;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
  line-height: 1.45;
}

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

.app__header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #101823, #0e1420);
}
.brand { font-size: 24px; font-weight: 900; letter-spacing: 0.6px; }
.tabs { margin-top: 12px; display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.tab { 
  background: #0f1622;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 16px;
  transition: all .15s ease;
}
.tab:hover { border-color: var(--accent); transform: translateY(-1px); }
.tab.active { 
  background: #142235;
  border-color: var(--accent);
  box-shadow: 0 2px 0 0 var(--accent) inset, 0 0 0 2px rgba(92,200,255,.15);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.subtitle { color: var(--muted); margin: 4px 0 0; }

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-direction: column;
}

.controls__row { display: flex; align-items: center; gap: 16px; width: 100%; }
.controls__row.topbar { justify-content: space-between; }
.controls__row.topbar .left { display: flex; gap: 8px; align-items: center; }
.filters-section { width: 100%; margin-top: 8px; }
.section-title { color: var(--muted); font-weight: 600; margin: 6px 0; }
.filters-grid { display: grid; grid-template-columns: repeat(8, minmax(120px, 1fr)); gap: 8px; }
.filters-grid .search-container { display: flex; width: 100%; }
.filters-grid .search-container input { width: 100%; }
.btn-secondary { background: #0d1420; color: var(--muted); }
.filters { display: flex; gap: 8px; padding-top: 8px; flex-wrap: wrap; }
.filters input, .filters select { background: #0f1622; color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; height: 32px; }
.filters-grid select, .filters-grid input { height: 32px; }
.filters-grid button { height: 32px; padding: 6px 12px; }
.filters.analysis { border-top: 1px dashed var(--border); margin-top: 8px; padding-top: 12px; }
.res-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; background: #0f1622; border: 1px solid var(--border); }
.res-chip { position: relative; }
.has-tooltip { position: relative; display: inline-block; }
.res-chip .tooltip, .has-tooltip .tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px); /* show below to avoid header clipping */
  left: 50%; transform: translateX(-50%);
  background: #00e5ff; /* bright cyan */
  color: #001018; /* dark text for contrast */
  border: 2px solid #67f3ff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 18px; /* ~4x browser tooltip size */
  font-weight: 700;
  white-space: pre-wrap;
  width: 360px; /* wider so lines fit */
  text-align: left;
  z-index: 2000; /* above sticky header */
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}
.res-chip:hover .tooltip, .has-tooltip:hover .tooltip { display: block; }
.tier-1 { background: rgba(126, 247, 197, 0.15); border-color: #2db080; } /* green */
.tier-2 { background: rgba(255, 221, 87, 0.18); border-color: #ffd857; } /* yellow */
.tier-3 { background: rgba(255, 165, 0, 0.18); border-color: #ff9a3d; } /* orange */
.tier-4 { background: rgba(255, 107, 107, 0.18); border-color: #ff6b6b; } /* red */
.tier-5 { background: rgba(255, 107, 107, 0.18); border-color: #ff6b6b; } /* red alias */
.res-chip .ab { color: var(--muted); }

.checkbox { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }

.controls__buttons { display: flex; gap: 8px; }

button {
  background: #1a2230;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.status { color: var(--muted); margin-left: auto; }

.table-container { padding: 16px 20px; overflow: auto; }

/* Map */
.map-container { position: relative; padding: 0; margin: 0; height: calc(100vh - 220px); min-height: 400px; background: radial-gradient(1200px 800px at 70% 20%, #0e1826 0%, #0b1120 50%, #08101a 100%); }
#hexMap { width: 100%; height: 100%; }

/* Market hover panel */
.market-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 1260px;
  max-width: 95vw;
  max-height: 90vh;
  background: #0f1622;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  padding: 36px;
  z-index: 2500;
  display: none;
  overflow-y: auto;
}
.market-panel.show { display: block; }
.market-panel__title { 
  font-weight: 800; 
  font-size: 28px;
  margin-bottom: 18px; 
  text-align: center;
}
.market-panel__row { display: flex; gap: 24px; align-items: center; margin: 18px 0; }
.market-panel__metrics { 
  display: flex; 
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-top: 12px;
  font-size: 14px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 12px;
}
.market-panel__metrics > div {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}
.sparkline { height: 192px; width: 100%; }
.barline { height: 120px; width: 100%; }

/* Chart tooltip for market combined chart */
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(10, 16, 26, 0.95);
  color: #e7eef7;
  border: 1px solid #3b86c6;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 2600;
  opacity: 0;
  transition: opacity .08s ease;
}
.chart-tooltip.show { opacity: 1; }

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

thead th {
  position: sticky;
  top: 0;
  background: #0f1724;
  z-index: 1;
}

th, td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: center;
  white-space: nowrap;
}
.tier-cell { border-radius: 6px; padding: 4px 8px; display: inline-block; }
.tier-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; min-height: 28px; border-radius: 8px; padding: 2px 8px; border: 2px solid transparent; font-weight: 700; }
/* Vibrant colors for tier badges only */
.tier-badge.tier-1 { background: #22c55e; border-color: #22c55e; color: #06120a; }
.tier-badge.tier-2 { background: #facc15; border-color: #facc15; color: #1a1400; }
.tier-badge.tier-3 { background: #fb923c; border-color: #fb923c; color: #210d00; }
.tier-badge.tier-4, .tier-badge.tier-5 { background: #ef4444; border-color: #ef4444; color: #2b0707; }

/* Market material cell with icon */
.mat-name { display: inline-flex; align-items: center; gap: 8px; }
.mat-name img { width: 20px; height: 20px; object-fit: contain; }

tbody tr:nth-child(even) { background: #0e1522; }

.app__footer {
  margin-top: auto;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

.price-pos { color: var(--accent-2); }
.price-neg { color: var(--danger); }


/* NewMap integration */
.search-container { position: relative; width: 100%; }
#systemSearch {
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid #B0C4DE;
  color: #B0C4DE;
  padding: 8px 12px;
  font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  border-radius: 4px;
  width: 100%;
  outline: none;
}
#systemSearch:focus { border-color: #00BFFF; box-shadow: 0 0 5px rgba(0, 191, 255, 0.3); }
#corpSearch {
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid #B0C4DE;
  color: #B0C4DE;
  padding: 8px 12px;
  font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  border-radius: 4px;
  width: 100%;
  outline: none;
}
#corpSearch:focus { border-color: #00BFFF; box-shadow: 0 0 5px rgba(0, 191, 255, 0.3); }
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.9);
  border: 1px solid #B0C4DE;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  z-index: 20;
}
.suggestion-item {
  padding: 8px 12px;
  color: #B0C4DE;
  cursor: pointer;
  font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
}
.suggestion-item:hover { background: rgba(176, 196, 222, 0.1); }

/* Canvas map styling */
#hexMap {
  border: 1px solid #1a1a3a;
  background: #000011;
  cursor: grab;
  box-shadow: 0 0 20px rgba(0, 50, 150, 0.1);
  max-width: 100%;
  max-height: 100%;
}
#hexMap:active { cursor: grabbing; }

/* Shopping tab */
.shopping-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#shoppingBuildingSelect, #shoppingTierSelect, #shoppingQtyInput {
  background: #0f1622; color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; height: 32px;
}
#shoppingAddBtn { height: 32px; padding: 6px 12px; }

/* Building level dropdown - ensure dark theme on Windows */
#buildingLevelSelect, select[id="buildingLevelSelect"], .building-level-select {
  background-color: #0f1622 !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  padding: 4px 28px 4px 8px !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  cursor: pointer !important;
  position: relative !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2 4L6 8L10 4' stroke='%23a5b4fc' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 8px center !important;
  background-size: 12px 12px !important;
}

/* Style option elements for Windows compatibility */
#buildingLevelSelect option, select[id="buildingLevelSelect"] option, .building-level-select option {
  background: #0f1622 !important;
  color: var(--text) !important;
  padding: 4px 8px !important;
}

/* Ensure select dropdown list stays dark on Windows */
#buildingLevelSelect:focus, select[id="buildingLevelSelect"]:focus, .building-level-select:focus {
  background-color: #0f1622 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2 4L6 8L10 4' stroke='%23a5b4fc' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 8px center !important;
  background-size: 12px 12px !important;
  color: var(--text) !important;
  outline: 1px solid var(--accent) !important;
  outline-offset: -1px !important;
}

/* Hover state for better UX */
#buildingLevelSelect:hover, select[id="buildingLevelSelect"]:hover, .building-level-select:hover {
  border-color: var(--accent) !important;
}

/* General select styling for Windows compatibility */
select {
  background: #0f1622 !important;
  background-color: #0f1622 !important;
  color: #e0e7ff !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  padding: 4px 8px !important;
}

/* Style all option elements for Windows compatibility */
select option {
  background: #0f1622 !important;
  background-color: #0f1622 !important;
  color: #e0e7ff !important;
  padding: 4px 8px !important;
}

/* Selected option styling */
select option:checked,
select option[selected] {
  background: #5cc8ff !important;
  background-color: #5cc8ff !important;
  color: #0a0f1a !important;
}

/* Hover state for options (when dropdown is open) */
select option:hover {
  background: #1a2332 !important;
  background-color: #1a2332 !important;
  color: #e0e7ff !important;
}

/* Focus state */
select:focus {
  background: #0f1622 !important;
  background-color: #0f1622 !important;
  color: #e0e7ff !important;
  outline: none !important;
  border-color: var(--accent) !important;
}

/* Specific select elements */
#filterTier,
#catalogCategory,
#marketFilterCategory,
#marketFilterTier,
#corpSortSelect,
#corpSortOrder {
  background: #0f1622 !important;
  background-color: #0f1622 !important;
  color: #e0e7ff !important;
}

#filterTier option,
#catalogCategory option,
#marketFilterCategory option,
#marketFilterTier option,
#corpSortSelect option,
#corpSortOrder option {
  background: #0f1622 !important;
  background-color: #0f1622 !important;
  color: #e0e7ff !important;
}
.strategy-toggle { display: inline-flex; gap: 6px; align-items: center; }
.badge { display: inline-block; border: 1px solid var(--border); background: #0f1622; padding: 2px 6px; border-radius: 6px; font-size: 12px; color: var(--muted); }

/* Shopping catalog */
.shopping-layout { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; padding: 12px 20px; }
.catalog-left { display: flex; flex-direction: column; gap: 16px; }
.catalog-right { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; min-height: 420px; }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.catalog-card { display: flex; flex-direction: column; align-items: center; gap: 6px; background: #0f1622; border: 1px solid var(--border); border-radius: 10px; padding: 10px; cursor: pointer; transition: transform .1s ease, border-color .1s ease; }
.catalog-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.catalog-card img { width: 64px; height: 64px; object-fit: contain; }
.catalog-card .label { text-align: center; font-size: 12px; color: var(--text); }
.tier-toggles label { display: inline-flex; align-items: center; gap: 6px; margin-right: 8px; color: var(--muted); }
.catalog-detail h3 { margin: 0 0 6px 0; }
.detail-header { display: flex; gap: 12px; align-items: flex-start; background: #0f1622; border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.detail-header img { width: 56px; height: 56px; object-fit: contain; }
.detail-header .info { display: flex; flex-direction: column; gap: 4px; }
.detail-header .meta { color: var(--muted); font-size: 13px; }

.recipe-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.ingredient { position: relative; display: inline-flex; flex-direction: column; align-items: center; gap: 4px; }
.ingredient img { width: 48px; height: 48px; object-fit: contain; }
.qty-badge { position: absolute; top: -6px; right: -6px; background: #1e293b; color: #a5b4fc; border: 1px solid #334155; padding: 2px 6px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.detail-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.detail-actions input { width: 96px; }

/* Map system info panel */
.system-info { 
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin: 12px 12px;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  overflow-x: hidden;
}
.system-info h3 { color: var(--accent); margin: 0 0 6px 0; font-size: 16px; }
.system-info h4 { margin: 8px 0 4px 0; font-size: 14px; color: var(--muted); }
.system-info h5 { margin: 6px 0 4px 0; font-size: 14px; color: var(--text); }
.system-info p { margin: 4px 0; font-size: 13px; }
.planet-info { 
  margin: 8px 0; 
  padding: 8px; 
  background: #0f1622; 
  border-left: 3px solid var(--accent); 
  border-radius: 6px;
  overflow: hidden;
  word-wrap: break-word;
}
.planet-info ul { margin: 6px 0; padding-left: 18px; }
/* Map planet info enhancements */
.planet-info .planet-name { 
  font-size: 16px; 
  font-weight: 900; 
  color: var(--accent); 
  margin: 0 0 8px 0; 
  padding: 6px 12px;
  background: linear-gradient(135deg, rgba(92, 200, 255, 0.15), rgba(92, 200, 255, 0.05));
  border: 1px solid rgba(92, 200, 255, 0.3);
  border-radius: 6px;
  letter-spacing: 0.3px;
  text-shadow: 0 0 8px rgba(92, 200, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
  flex-wrap: nowrap;
  overflow: visible;
}

/* Container for badges (fertility and tier) */
.planet-info .planet-name .planet-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

/* Tier badge inline with planet name - smaller size */
.planet-info .planet-name .planet-tier-badge {
  min-width: 20px;
  min-height: 20px;
  font-size: 12px;
  padding: 2px 4px;
  flex-shrink: 0;
}

/* Fertility badge */
.planet-info .fertility-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  min-height: 20px;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 8px;
  font-weight: 700;
  background: #22c55e;
  border: 2px solid #22c55e;
  color: #06120a;
  flex-shrink: 0;
}

/* Planet name text - don't truncate, let panel width adjust */
.planet-info .planet-name > *:first-child {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: visible;
}
.planet-info .res-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.planet-info .res-chips .res-chip { background: #0f1622; border: 1px solid #2b8aa6; padding: 2px 10px; border-radius: 999px; font-size: 12px; color: #c2d7e5; }
.planet-info .res-chips .res-chip.tier-1 { background: rgba(126, 247, 197, 0.15) !important; border-color: #2db080 !important; }
.planet-info .res-chips .res-chip.tier-2 { background: rgba(255, 221, 87, 0.18) !important; border-color: #ffd857 !important; }
.planet-info .res-chips .res-chip.tier-3 { background: rgba(255, 165, 0, 0.18) !important; border-color: #ff9a3d !important; }
.planet-info .res-chips .res-chip.tier-4 { background: rgba(255, 107, 107, 0.18) !important; border-color: #ff6b6b !important; }
/* Also apply tier colors to any res-chip anywhere to avoid specificity conflicts */
.res-chip.tier-1 { background: rgba(126, 247, 197, 0.15) !important; border-color: #2db080 !important; }
.res-chip.tier-2 { background: rgba(255, 221, 87, 0.18) !important; border-color: #ffd857 !important; }
.res-chip.tier-3 { background: rgba(255, 165, 0, 0.18) !important; border-color: #ff9a3d !important; }
.res-chip.tier-4 { background: rgba(255, 107, 107, 0.18) !important; border-color: #ff6b6b !important; }
.planet-info .res-chips .res-chip .ab { color: #9fb3c8; margin-right: 6px; }

/* Planet name links in Planets tab table */
.planet-link {
  color: #00BFFF !important;
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.2s ease;
}
.planet-link:hover {
  color: #1E90FF !important;
  text-decoration: underline;
}

/* Map split layout (left info 15%, right map 85%) */
.map-split { display: flex; gap: 8px; padding: 0 12px 12px 12px; }
.map-left { 
  width: 15% !important; 
  min-width: 260px; 
  max-width: 15% !important;
  flex-shrink: 0;
}
.map-right { flex: 1; min-width: 0; }

/* Detail shopping list below the item detail */
.detail-shopping { margin-top: 14px; }
.detail-shopping h3 { margin: 8px 0; font-size: 18px; }
.detail-shopping table { width: 100%; border-collapse: collapse; }
.detail-shopping thead th { position: sticky; top: 0; background: #0f1724; z-index: 1; }
.detail-shopping th, .detail-shopping td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.detail-shopping tfoot td { font-weight: 800; }
