:root {
  --bg: #07080a;
  --panel: #12151b;
  --panel-2: #171b22;
  --line: #2a3342;
  --text: #e8edf5;
  --muted: #9aa6b8;
  --blue: #3d7ecf;
  --blue-deep: #1d4f8c;
  --green: #8fe3a3;
  --green-bg: rgba(72, 150, 96, 0.22);
  --danger: #d06a6a;
  --gold: #d7c48a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #050607;
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

.window {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 20% -10%, rgba(61, 126, 207, 0.08), transparent 50%),
    var(--bg);
  border: 1px solid #1c2430;
}

.chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 12px;
  background: linear-gradient(#1a2230, #10151d);
  border-bottom: 1px solid var(--line);
}

.view-tabs {
  display: flex;
  gap: 4px;
}

.brand {
  min-width: 0;
}

.chrome-title {
  font-size: 15px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.chrome-sub {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap;
}

.chrome-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.region-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

select,
input,
.ghost,
.footer-actions button {
  background: #10141b;
  border: 1px solid #3a4a60;
  border-radius: 2px;
}

select {
  min-width: 160px;
  padding: 4px 8px;
}

.ghost,
.icon-btn,
.footer-actions button {
  cursor: pointer;
}

.ghost {
  padding: 4px 10px;
}

.chrome-icons {
  display: flex;
  gap: 6px;
}

.chrome-icons span {
  width: 12px;
  height: 12px;
  border: 1px solid #6b7c93;
}

.workspace {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 400px;
}

.workspace.home-analysis {
  grid-template-columns: 250px minmax(0, 1fr);
}

.workspace.home-analysis .main,
.workspace.home-analysis .industry {
  display: none;
}

.workspace #analysisView {
  display: none;
  min-width: 0;
}

.workspace.home-analysis #analysisView,
.workspace.full-analysis #analysisView {
  display: flex;
}

.workspace.full-analysis {
  grid-template-columns: 1fr;
}

.workspace.full-analysis .sidebar,
.workspace.full-analysis .main,
.workspace.full-analysis .industry,
.workspace.full-analysis .mobile-market-nav {
  display: none;
}

.workspace > * {
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #0d1117;
}

.side-tabs,
.main-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
}

.tab {
  background: #1a2230;
  border: 1px solid var(--line);
  border-bottom: none;
  padding: 6px 14px;
  cursor: pointer;
}

.tab.active {
  background: #24344d;
  color: #fff;
}

.search-row {
  display: flex;
  gap: 6px;
  padding: 8px;
}

.search-row input {
  flex: 1;
  padding: 6px 8px;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 2px 6px;
}

.icon-btn:hover,
.ghost:hover,
.footer-actions button:hover,
.tab:hover {
  border-color: var(--blue);
}

.tree-pane,
.search-results {
  flex: 1;
  overflow: auto;
  padding: 0 6px 10px;
}

.search-results {
  max-height: 220px;
  border-bottom: 1px solid var(--line);
}

.hidden {
  display: none !important;
}

.tree-item,
.search-hit {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 6px;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
}

.tree-item:hover,
.search-hit:hover {
  background: rgba(61, 126, 207, 0.15);
}

.tree-item.active,
.search-hit.active {
  background: var(--blue-deep);
}

.tree-children {
  padding-left: 14px;
}

.chevron {
  width: 12px;
  color: var(--muted);
}

.mini-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.search-hit small,
.tree-item small {
  color: var(--muted);
  margin-left: auto;
}

.main {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #0c0f14;
}

.item-head {
  padding: 8px 14px 10px;
}

.crumb {
  color: var(--gold);
  font-size: 12px;
  margin-bottom: 8px;
}

.item-line {
  display: flex;
  gap: 12px;
  align-items: center;
}

.item-icon {
  width: 64px;
  height: 64px;
  background: #10151d;
  border: 1px solid var(--line);
  object-fit: contain;
}

.item-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-name-row h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
}

.industry {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  background: #0b0f15;
  border-left: 1px solid var(--line);
}

.industry-head {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
  background: #121821;
}

.industry-head h2 {
  margin: 0 0 8px;
  font-size: 14px;
}

.industry-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.industry-controls select,
.industry-controls input {
  width: 64px;
  padding: 2px 4px;
}

.industry-body {
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 12px 16px;
}

.industry-empty,
.industry-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.industry-card {
  margin-bottom: 12px;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  background: #12171f;
}

.industry-card h3 {
  margin: 0;
  padding: 6px 8px;
  font-size: 13px;
  background: #182230;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.industry-list,
.kv {
  margin: 0;
  padding: 8px;
}

.kv {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 4px 8px;
  font-size: 12px;
}

.kv dt {
  color: var(--muted);
}

.chance {
  color: var(--gold);
  font-weight: 600;
}

.source-row {
  padding: 8px;
  min-width: 0;
  border-top: 1px solid #1c2430;
}

.source-title {
  color: var(--gold);
  font-size: 13px;
  margin-bottom: 4px;
}

.ai-table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 12px;
}

.ai-table th,
.ai-table td {
  padding: 5px 6px;
  border-top: 1px solid #1c2430;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ai-table th {
  color: var(--muted);
  font-weight: 400;
}

.ai-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  min-width: 0;
}

.ai-form select,
.ai-form input {
  min-width: 0;
  max-width: 100%;
  background: #0d1117;
  border: 1px solid var(--line);
  padding: 4px 6px;
}

.ai-form select {
  flex: 0 1 140px;
}

.ai-form input {
  flex: 1 1 140px;
}

.ai-form button {
  flex: 0 0 auto;
  background: var(--blue-deep);
  border: 1px solid var(--blue);
  padding: 4px 8px;
  cursor: pointer;
}

.mat-row,
.link-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 6px;
  align-items: center;
  width: 100%;
  padding: 4px 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid #1c2430;
  text-align: left;
  color: inherit;
  text-decoration: none;
}

.mat-row:last-child,
.link-row:last-child {
  border-bottom: none;
}

.mat-row .sub,
.cost-line {
  color: var(--muted);
  font-size: 11px;
}

.cost-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px;
  font-size: 12px;
}

.cost-box div {
  background: #0e141c;
  padding: 6px 8px;
}

.guide-price {
  color: #f0c36d;
  font-weight: 600;
}

.profit-up {
  color: var(--green);
}

.profit-down {
  color: var(--danger);
}

.analysis-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0c0f14;
}

.analysis-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.analysis-toolbar select {
  min-width: 120px;
  max-width: 220px;
}

.check-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.check-filters label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.check-filters input {
  margin: 0;
  accent-color: var(--blue);
}

.analysis-status {
  margin-left: auto;
}

.analysis-grid {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.analysis-grid .panel {
  min-height: 0;
  overflow: hidden;
}

.analysis-grid .single-panel {
  display: none;
}

.analysis-view.single-list .analysis-grid {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.analysis-view.single-list .analysis-grid .panel {
  display: none;
}

.analysis-view.single-list .analysis-grid .single-panel {
  display: flex;
}

.faction-grid {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
}

.faction-grid .panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.offer-box > summary {
  cursor: pointer;
  color: var(--gold);
  user-select: none;
  list-style: none;
}

.offer-box > summary::-webkit-details-marker {
  display: none;
}

.offer-box > summary::before {
  content: "▸ ";
}

.offer-box[open] > summary {
  margin-bottom: 6px;
}

.offer-box[open] > summary::before {
  content: "▾ ";
}

.offer-line {
  padding: 6px 0;
  border-bottom: 1px solid #1c2430;
}

.offer-line:last-child {
  border-bottom: none;
}

.faction-table td.wrap {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.faction-table .need-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 8px 4px 0;
}

#factionSearch {
  min-width: 220px;
  background: #0d1117;
  border: 1px solid var(--line);
  padding: 3px 6px;
}

.analysis-grid table {
  font-size: 12px;
}

.analysis-grid h2 small {
  margin-left: 8px;
  color: var(--muted);
  font-weight: 400;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #141a22;
  padding-right: 8px;
}

.panel-head h2 {
  background: transparent;
}

.analysis-pager {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}

.analysis-pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

#worldContractBody .click-row {
  cursor: pointer;
}

#worldContractBody td.wrap {
  white-space: normal;
  min-width: 220px;
}

.click-row td:first-child,
.analysis-grid td:first-child,
.faction-table td:first-child {
  display: flex;
  align-items: center;
  gap: 6px;
}

.item-name-link {
  color: var(--gold);
  text-decoration: none;
}

.item-name-link:hover {
  text-decoration: underline;
}

.tech-tag {
  display: inline-block;
  min-width: 28px;
  padding: 0 4px;
  border: 1px solid #3a4a60;
  color: var(--gold);
  font-size: 11px;
  text-align: center;
}

.tech-tag.on {
  color: var(--green);
  border-color: #3d6a4a;
}

.tech-tag.off {
  color: var(--danger);
  border-color: #6a3d3d;
}

.tech-tag.dim {
  color: var(--muted);
}

.item-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.market-bar {
  display: flex;
  justify-content: space-between;
  padding: 6px 14px;
  background: #151b24;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.split-tables {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr 1fr;
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line);
}

.panel h2 {
  margin: 0;
  padding: 6px 12px;
  font-size: 14px;
  background: #141a22;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 5px 10px;
  border-bottom: 1px solid #1c2430;
  text-align: left;
  white-space: nowrap;
}

.ai-table th,
.ai-table td {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  position: sticky;
  top: 0;
  background: #10151c;
  color: var(--muted);
  font-weight: 400;
  cursor: pointer;
}

th.sorted {
  color: #dce8ff;
}

th.sorted::after {
  content: " ▲";
  font-size: 10px;
}

th.sorted.desc::after {
  content: " ▼";
}

tbody tr:hover {
  background: rgba(61, 126, 207, 0.12);
}

tbody tr.best {
  background: var(--green-bg);
}

.price {
  color: #cfe4ff;
}

.empty td {
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: #10151c;
  border-top: 1px solid var(--line);
}

.ticker {
  overflow: hidden;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.ticker-inner {
  display: inline-flex;
  gap: 28px;
  animation: marquee 48s linear infinite;
}

.up {
  color: var(--green);
}

.down {
  color: var(--danger);
}

.footer-actions {
  display: flex;
  gap: 8px;
}

.footer-actions button {
  padding: 6px 12px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  width: min(920px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-summary {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: #2c3a4d;
}

.mobile-market-nav {
  display: none;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr) minmax(280px, 34vw);
  }

  .workspace.home-analysis,
  .workspace.full-analysis {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .workspace.full-analysis {
    grid-template-columns: 1fr;
  }

  .analysis-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, minmax(280px, 1fr));
    overflow: auto;
  }

  .account-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  html,
  body {
    height: 100dvh;
  }

  .window {
    height: 100dvh;
    border: 0;
  }

  .chrome {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-top));
  }

  .view-tabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .view-tabs .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 13px;
  }

  .chrome-actions {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  .chrome-icons,
  #refreshCatalogBtn {
    display: none;
  }

  .pilot-badge {
    max-width: 88px;
  }

  select,
  input,
  .ghost,
  .tab,
  .footer-actions button {
    font-size: 16px;
  }

  select {
    min-width: 108px;
    max-width: 42vw;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .mobile-market-nav {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    background: #10151d;
  }

  .mobile-market-nav .tab {
    flex: 1;
    border-bottom: 1px solid var(--line);
    text-align: center;
  }

  .workspace.pane-catalog .sidebar {
    display: flex;
  }

  .workspace.pane-catalog .main,
  .workspace.pane-catalog .industry,
  .workspace.pane-catalog #analysisView,
  .workspace.pane-orders .sidebar,
  .workspace.pane-orders .industry,
  .workspace.pane-industry .sidebar,
  .workspace.pane-industry .main {
    display: none;
  }

  .workspace.pane-orders .main,
  .workspace.pane-industry .industry {
    display: flex;
  }

  .workspace.home-analysis.pane-orders .main {
    display: none;
  }

  .workspace.home-analysis.pane-orders #analysisView {
    display: flex;
  }

  .sidebar,
  .industry {
    border: 0;
  }

  .item-name-row {
    flex-wrap: wrap;
  }

  .item-name-row h1 {
    font-size: 18px;
  }

  .item-icon {
    width: 48px;
    height: 48px;
  }

  .split-tables {
    grid-template-rows: minmax(220px, 1fr) minmax(220px, 1fr);
  }

  .footer {
    grid-template-columns: 1fr;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .analysis-toolbar,
  .account-toolbar,
  .account-form {
    grid-template-columns: 1fr;
  }

  .analysis-toolbar {
    gap: 8px;
  }

  .analysis-toolbar label,
  .analysis-toolbar select {
    min-width: 0;
    width: 100%;
  }

  .analysis-status {
    margin-left: 0;
  }

  .analysis-grid {
    grid-template-rows: none;
    overflow: auto;
  }

  .analysis-grid .panel {
    min-height: 320px;
  }

  .account-layout {
    grid-template-columns: 1fr;
  }

  .account-nav {
    display: flex;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 6px 8px;
    gap: 4px;
  }

  .account-nav button {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 10px;
  }

  .account-form {
    display: flex;
    flex-direction: column;
  }

  .modal-card {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .tree-item,
  .search-hit,
  .item-name-link,
  .need-item,
  .pack-btn {
    min-height: 40px;
  }

  th,
  td {
    padding: 8px 8px;
  }
}

.pilot-badge {
  color: var(--gold);
  font-size: 12px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-layout {
  display: grid;
  grid-template-columns: 168px 1fr;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.account-nav {
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 8px;
}

.account-nav button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 6px 8px;
  color: var(--muted);
}

.account-nav button.active,
.account-nav button:hover {
  color: var(--text);
  background: #182230;
}

.account-main {
  min-width: 0;
  overflow: auto;
  padding: 10px 12px;
}

.account-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px;
}

.account-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.account-form input {
  background: #0d1117;
  border: 1px solid var(--line);
  padding: 4px 6px;
}

.pack-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
}

.pack-btn {
  border: 1px solid var(--line);
  background: #12171f;
  padding: 8px 10px;
  text-align: left;
}

.pack-btn small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.pack-btn.ok {
  border-color: #3d6b4a;
}

.account-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  padding: 0 10px 10px;
}

.account-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.account-table th,
.account-table td {
  border-bottom: 1px solid #1c2430;
  padding: 4px 6px;
  text-align: left;
}

.account-body .industry-card {
  max-width: none;
}
