:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e2d6;
  --muted: #8d8a80;
  --gold: #e9b949;
  --silver: #c7cdd6;
  --copper: #c9814d;
  --up: #5cc98a;
  --down: #e5675e;
  --accent: #e9b949;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }

button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  background: var(--accent); color: #1a1406; border: 0; border-radius: 8px;
  padding: 8px 14px; font-weight: 600;
}
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); padding: 0 4px; text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.coin {
  width: 28px; height: 28px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe08a, #c8901f 70%);
  box-shadow: 0 0 0 2px #6b4a10 inset;
}
h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }
h2 { font-size: 15px; margin: 0; }
.sub { color: var(--muted); font-size: 12px; }
.status { margin-left: auto; text-align: right; max-width: 55%; }
.last { font-weight: 600; }
#statusText { font-size: 12px; }

/* ---------- house picker ---------- */
.house-panel {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.house-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px; width: min(560px, 92vw); max-height: 80vh; overflow: auto;
}
.house-box p { line-height: 1.5; }
.house-list { display: grid; gap: 8px; margin: 14px 0; }
.house-list button {
  text-align: left; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px;
}
.house-list button:hover { border-color: var(--accent); }
.house-list .selected { border-color: var(--accent); }
.error { color: var(--down); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 330px 1fr; gap: 16px;
  padding: 16px; height: calc(100vh - 66px);
}
.sidebar {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 0;
}
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tab {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px;
}
.tab.active { border-color: var(--accent); color: var(--accent); }
.sidebar input, .sidebar select, .chart-toolbar select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; font: inherit; width: 100%;
}
.list-hint { font-size: 11px; }

.item-list { overflow: auto; flex: 1; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.cat-head {
  position: sticky; top: 0; background: var(--panel);
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  padding: 10px 2px 4px; border-bottom: 1px solid var(--line);
}
.item-row {
  display: grid; grid-template-columns: 22px 20px 1fr auto; align-items: center; gap: 6px;
  padding: 5px 2px; border-bottom: 1px solid #20242c;
}
.item-row:hover { background: var(--panel-2); }
.item-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .name.nodata { color: var(--muted); }
.item-row .price { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.star { background: none; border: 0; color: #555; font-size: 16px; padding: 0; line-height: 1; }
.star.on { color: var(--gold); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.empty-list { padding: 18px 4px; }

/* ---------- content ---------- */
.content { display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 10px; }

.chart-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.chart-toolbar select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel-2); border: 0; padding: 7px 12px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: #1a1406; font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

.chart-wrap { position: relative; height: 380px; }
.chart-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none;
}

/* ---------- table ---------- */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; border-bottom: 1px solid #22262f; white-space: nowrap; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; }
.num { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.charted td:nth-child(2) { color: var(--accent); }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------- money ---------- */
.g { color: var(--gold); }
.s { color: var(--silver); }
.c { color: var(--copper); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { max-height: 60vh; }
  .status { display: none; }
}

/* ---------- v3: views + crafting ---------- */
.views { display: inline-flex; gap: 6px; margin-left: 12px; }
.view-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 16px;
}
.view-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.craft-layout { padding: 16px; height: calc(100vh - 66px); overflow: auto; }
.craft-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.craft-toolbar input, .craft-toolbar select, .form-grid input, .reagent-row input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; font: inherit;
}
.craft-toolbar input[type=search] { min-width: 240px; }
.craft-toolbar .btn { margin-left: auto; }
.craft-note { margin: 10px 0 6px; }

#craftTable th[data-sort] { cursor: pointer; user-select: none; }
#craftTable th.sorted { color: var(--accent); }
#craftTable tr.incomplete td { opacity: .75; }
.detail-row td { background: #13161c; cursor: default; white-space: normal; }
.detail { display: grid; gap: 10px; padding: 6px 4px 10px; }
.detail table { width: auto; min-width: 560px; }
.detail th, .detail td { padding: 4px 10px; }
.detail-actions { display: flex; gap: 12px; }
.src {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 6px; margin-left: 6px;
  border: 1px solid var(--line); color: var(--muted); vertical-align: middle;
}
.src.manual { color: var(--accent); border-color: var(--accent); }
.src.vendor { color: #5fa8ff; border-color: #5fa8ff; }
.src.none { color: var(--down); border-color: var(--down); }
.pencil { background: none; border: 0; color: var(--muted); padding: 0 4px; }
.pencil:hover { color: var(--accent); }

.editor { width: min(720px, 94vw); }
.editor h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.form-grid label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.reagent-row { display: grid; grid-template-columns: 1fr 90px 28px; gap: 8px; margin-bottom: 6px; }
.editor-actions { display: flex; justify-content: flex-end; gap: 14px; align-items: center; margin-top: 10px; }

/* ---------- v5: sortable summary table ---------- */
#weekTable th[data-sort] { cursor: pointer; user-select: none; }
#weekTable th.sorted { color: var(--accent); }

/* ---------- v5: History tab ---------- */
#historyView { display: flex; flex-direction: column; gap: 16px; }
#historyView.hidden { display: none; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 20px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col h2 { margin-bottom: 8px; }
.small-chart { height: 240px; }
#ledgerItems th[data-sort] { cursor: pointer; user-select: none; }
#ledgerItems th.sorted { color: var(--accent); }
#ledgerItems tbody tr, #ledgerRecent tbody tr { cursor: default; }
.setup-steps { line-height: 1.7; padding-left: 20px; }
.path-row { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
.path-row input {
  flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; font: inherit;
}
code { background: #0b0d11; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; }
.kind { font-size: 11px; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); }
.kind.sold { color: var(--up); border-color: var(--up); }
.kind.bought { color: var(--down); border-color: var(--down); }
.kind.posted { color: #5fa8ff; border-color: #5fa8ff; }
.kind.expired, .kind.cancelled, .kind.outbid { color: var(--muted); }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- v6: Characters tab ---------- */
#charsView { display: flex; flex-direction: column; gap: 16px; }
#charsView.hidden { display: none; }
#invItems th[data-isort], #invCraft th[data-sort] { cursor: pointer; user-select: none; }
#invItems th.sorted, #invCraft th.sorted { color: var(--accent); }
#invItems tbody tr { cursor: default; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.char-card { display: grid; gap: 10px; }
.char-head { display: flex; align-items: baseline; gap: 10px; }
.char-name { font-size: 18px; font-weight: 700; }
.char-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-variant-numeric: tabular-nums; }
.prof-line { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }

/* ---------- v8: coins, item quality colours, Wowhead icons ---------- */
.m { white-space: nowrap; }
.coin {
  display: inline-block; width: 0.72em; height: 0.72em; border-radius: 50%;
  margin: 0 1px 0 2px; vertical-align: -0.02em;
  box-shadow: inset -1px -1px 0 rgba(0,0,0,.35);
}
.coin.g { background: radial-gradient(circle at 35% 30%, #fff1a8, #e8b02a 55%, #8f6210); }
.coin.s { background: radial-gradient(circle at 35% 30%, #ffffff, #b9c0c9 55%, #6d737b); }
.coin.c { background: radial-gradient(circle at 35% 30%, #ffd2ad, #c9814d 55%, #7a4420); }

.item-name { text-decoration: none; color: var(--text); }
a.item-name:hover { text-decoration: underline; }
.q0 { color: #9d9d9d !important; }
.q1 { color: #ffffff !important; }
.q2 { color: #1eff00 !important; }
.q3 { color: #0070dd !important; }
.q4 { color: #a335ee !important; }
.q5 { color: #ff8000 !important; }
.q6 { color: #e6cc80 !important; }
.q7 { color: #00ccff !important; }
/* Wowhead puts a small icon in front of the link */
.item-name ins, .iconsmall { vertical-align: middle; }

/* ---------- v11: Crates tab ---------- */
#cratesView { display: flex; flex-direction: column; gap: 16px; }
#cratesView.hidden { display: none; }
#crTable tbody tr[data-crate] { cursor: pointer; }
.seal { font-size: 11px; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); }
.seal.white { color: #fff; border-color: #888; }
.seal.green { color: #1eff00; border-color: #1eff00; }
.src.craft { color: #c38bff; border-color: #c38bff; }
.best-row td { background: rgba(92, 201, 138, .08); }

/* ---------- v12: login, server bits ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 20px; }
.login-box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 24px; }
.login-box .brand { margin-bottom: 8px; }
.login-box input[type=password] {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font: inherit; font-size: 16px;
}
.login-box .btn { padding: 10px 14px; margin-top: 4px; }
.login-error { color: var(--down); min-height: 1.2em; margin: 0; font-size: 13px; }
.sub .sep { opacity: .5; margin: 0 2px; }
.upload-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0 4px; }
