/* Clickfarm 2026 — Industrial Console theme */

/* ── CSS vars ─────────────────────────────────────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg:          #0a0d10;
  --panel:       #10141a;
  --panel-2:     #0d1116;
  --grid:        rgba(120, 200, 180, 0.06);
  --border:      rgba(120, 200, 180, 0.18);
  --border-soft: rgba(120, 200, 180, 0.08);
  --ink:         #ecf4ee;
  --ink-2:       #a8bcb4;
  --ink-3:       #8ea49c;
  --accent:      #ffb24d;
  --good:        #6ed388;
  --bad:         #ff6b5a;
  --warn:        #f5c842;
  --cyan:        #5ad6c8;
  --magenta:     #d68fc4;
}

[data-theme="light"] {
  --bg:          #eef0eb;
  --panel:       #ffffff;
  --panel-2:     #f3f5ef;
  --grid:        rgba(20, 40, 30, 0.06);
  --border:      rgba(20, 40, 30, 0.22);
  --border-soft: rgba(20, 40, 30, 0.10);
  --ink:         #0e1a14;
  --ink-2:       #42554c;
  --ink-3:       #7a8a82;
  --accent:      #a85a10;
  --good:        #1f6a32;
  --bad:         #a82918;
  --warn:        #8a6a10;
  --cyan:        #0e6a64;
  --magenta:     #8a3a78;
}

[data-accent="green"]                      { --accent: #6ed388; }
[data-accent="green"][data-theme="light"]  { --accent: #1f6a32; }
[data-accent="cyan"]                       { --accent: #5ad6c8; }
[data-accent="cyan"][data-theme="light"]   { --accent: #0e6a64; }
[data-accent="magenta"]                    { --accent: #d68fc4; }
[data-accent="magenta"][data-theme="light"]{ --accent: #8a3a78; }

/* ── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'JetBrains Mono', 'Geist Mono', ui-monospace, 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.55;
  font-feature-settings: "tnum" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  min-height: 100vh;
  padding-top: 80px; /* nav 40px + ticker 40px */
}

h1, h2, h3, h4 {
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 8px 0 4px;
  font-family: inherit;
}
p { margin: 4px 0; color: var(--ink-2); font-size: 11px; }
a { color: var(--accent); text-decoration: none; }
::selection { background: var(--accent); color: var(--bg); }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
*::-webkit-scrollbar         { width: 8px; height: 8px; }
*::-webkit-scrollbar-track   { background: var(--panel-2); }
*::-webkit-scrollbar-thumb   { background: var(--border); }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button { font-family: inherit; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px; font-size: 11px; font-family: inherit;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--ink);
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
  transition: background .12s, border-color .12s, color .12s;
  cursor: pointer; white-space: nowrap;
}
.btn:hover    { background: var(--panel); border-color: var(--accent); color: var(--accent); }

.btn-primary  { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.15); color: var(--bg); border-color: var(--accent); }

.btn-ghost    { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--panel-2); color: var(--ink); border-color: transparent; }

.btn-danger   { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn-danger:hover { background: var(--bad); color: var(--bg); }

.btn-success  { background: var(--good); color: var(--bg); border-color: var(--good); }
.btn-success:hover { background: var(--good); filter: brightness(1.15); color: var(--bg); border-color: var(--good); }

.btn-warning  { color: var(--warn); border-color: var(--warn); background: transparent; }
.btn-warning:hover { background: var(--warn); color: var(--bg); }

.btn-dark     { background: var(--panel-2); color: var(--ink-2); border-color: var(--border); }
.btn-dark:hover { border-color: var(--ink-2); color: var(--ink); }

.btn-link     { background: none; border: none; color: var(--accent); padding: 4px 0; font-size: 11px; text-transform: none; letter-spacing: 0; }

.btn-sm  { padding: 3px 8px; font-size: 10px; }
.btn:disabled, button:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
input[type="text"], input[type="password"], input[type="number"], select {
  font-family: inherit; font-size: 12px;
  padding: 6px 10px; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--ink); width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px; height: 14px; cursor: pointer;
}

input[type="range"], .theme-range, .custom-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 999px;
  background: var(--border); outline: none; cursor: pointer;
  accent-color: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}
@keyframes ticker-in {
  from { transform: translateY(6px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
@keyframes flash-accent {
  0%   { background: var(--accent); }
  100% { background: transparent; }
}

.live-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--good); animation: pulse 1.6s ease-in-out infinite;
}
.ticker-in   { animation: ticker-in   .25s ease-out; }
.flash-accent{ animation: flash-accent .6s  ease-out; }

/* ── Top nav ──────────────────────────────────────────────────────────────── */
#topNav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 40px;
  display: flex; align-items: center; gap: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 100%;
  border-right: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.nav-logo-icon { color: var(--accent); font-size: 14px; }
.nav-logo-text { font-weight: 800; letter-spacing: 0.12em; font-size: 12px; }
.nav-version   { font-size: 9px; color: var(--ink-3); padding: 1px 4px; border: 1px solid var(--border); }

.nav-tabs { display: flex; height: 100%; }

.nav-tab {
  height: 100%; padding: 0 14px;
  background: transparent; border: none;
  border-right: 1px solid var(--border-soft);
  border-bottom: 2px solid transparent;
  color: var(--ink-2); font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  cursor: pointer; white-space: nowrap;
  transition: color .12s, border-color .12s, background .12s;
}
.nav-tab:hover  { color: var(--ink); background: var(--panel-2); }
.nav-tab.active { background: var(--panel-2); border-bottom-color: var(--accent); color: var(--ink); }

.nav-spacer { flex: 1; }

.nav-stats {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; font-size: 10px; color: var(--ink-2);
  flex-shrink: 0;
}
.nav-live { display: flex; align-items: center; gap: 5px; }
.nav-sep  { opacity: 0.35; }
.nav-money { color: var(--accent); font-weight: 700; font-size: 11px; }

.nav-ws .ws-dot         { font-size: 8px; vertical-align: middle; margin-right: 3px; }
.nav-ws .ws-dot--online { color: var(--good); }
.nav-ws .ws-dot--offline{ color: var(--bad); }
.nav-ws .ws-label       { font-size: 10px; color: var(--ink-3); }

.nav-actions {
  display: flex; align-items: center; gap: 2px;
  padding: 0 8px; flex-shrink: 0;
}

/* Options dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown-menu {
  position: absolute; top: calc(100% + 2px); right: 0;
  background: var(--panel); border: 1px solid var(--border);
  min-width: 220px; z-index: 200;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.dropdown-item {
  padding: 6px 12px; font-size: 11px; font-family: inherit;
  background: transparent; border: none; color: var(--ink-2);
  text-align: left; cursor: pointer; text-transform: uppercase; letter-spacing: 0.04em;
  font-weight: 600; transition: background .1s, color .1s;
}
.dropdown-item:hover { background: var(--panel-2); color: var(--ink); }
.dropdown-sep { border: none; border-top: 1px solid var(--border-soft); margin: 3px 0; }

/* nav XP label + segmented bar */
.nav-xp { font-size: 10px; color: var(--accent); font-weight: 700; letter-spacing: 0.06em; }

.nav-xp-segs {
  display: inline-flex; align-items: center; gap: 2px;
  vertical-align: middle; margin-left: 5px;
}
.nav-xp-seg {
  width: 7px; height: 10px;
  background: var(--border);
  transition: background .2s;
}
.nav-xp-seg.filled { background: var(--accent); }

/* ── Resource ticker ──────────────────────────────────────────────────────── */
#resourceTicker {
  position: fixed; top: 40px; left: 0; right: 0; z-index: 90;
  height: 40px;
  display: flex; align-items: stretch;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.ticker-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px;
  border-right: 1px solid var(--border-soft);
  font-size: 11px; font-weight: 600; white-space: nowrap;
  min-width: 100px;
}
.ticker-pill:last-child { border-right: none; }
.ticker-ic { font-size: 9px; font-weight: 700; }

/* ── Game content ─────────────────────────────────────────────────────────── */
#gameContent {
  padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
}

/* ── Page visibility ──────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── Clusters ─────────────────────────────────────────────────────────────── */
.cluster {
  --cc: var(--ink-2);
  border: 1px solid color-mix(in oklab, var(--cc) 30%, transparent);
  background: linear-gradient(180deg, color-mix(in oklab, var(--cc) 6%, transparent), transparent 100px);
  display: flex; flex-direction: column;
}

.cluster-hd {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: linear-gradient(90deg, color-mix(in oklab, var(--cc) 18%, transparent), color-mix(in oklab, var(--cc) 4%, transparent) 60%, transparent);
  border-bottom: 1px solid color-mix(in oklab, var(--cc) 25%, transparent);
}
.cluster-bar  { width: 3px; align-self: stretch; background: var(--cc); flex-shrink: 0; }
.cluster-id   { color: var(--cc); font-size: 10px; font-weight: 800; letter-spacing: 0.18em; }
.cluster-title{ font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); }
.cluster-sub  { font-size: 10px; color: var(--ink-2); }
.cluster-space{ flex: 1; }
.cluster-status { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; color: var(--cc); }

.cluster-grid {
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

/* ── Panels ───────────────────────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0;
}

.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }

.panel-hd {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.panel-arr   { color: var(--accent); font-size: 10px; flex-shrink: 0; }
.panel-title { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.panel-code  { font-size: 9px; color: var(--ink-2); letter-spacing: 0.04em; }
.panel-space { flex: 1; }
.panel-status {
  font-size: 9px; color: var(--good);
  display: flex; align-items: center; gap: 4px;
}

.panel-body {
  padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
  flex: 1; overflow: visible;
}

/* ── Layout helpers ───────────────────────────────────────────────────────── */
.btn-row {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0;
}

.autosell-row {
  padding: 6px 0;
  border-bottom: 1px dashed var(--border-soft);
  display: flex; flex-direction: column; gap: 4px;
}
.autosell-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* ── Sell menu (quick sell row) ───────────────────────────────────────────── */
#sellMenu {
  display: none; /* shown by base.js at lvl9 */
  flex-wrap: wrap; gap: 6px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid color-mix(in oklab, var(--accent) 30%, transparent);
}
.sell-item {
  flex: 1; min-width: 120px;
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  font-size: 11px;
}

/* ── Energy gauge ─────────────────────────────────────────────────────────── */
.energy-gauge { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }

.gauge-hd {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--ink-2);
}
.gauge-val { font-weight: 700; }

.gauge-track {
  display: flex; gap: 1px; height: 12px;
}
.gauge-seg {
  flex: 1;
  background: var(--border-soft);
  transition: background .25s;
}
.gauge-seg.filled { background: var(--gc, var(--good)); }

.gauge-ruler { position: relative; height: 20px; margin-top: 2px; overflow: visible; }
.gauge-tick {
  position: absolute; display: flex; flex-direction: column; align-items: center;
  transform: translateX(-50%); color: var(--ink-2);
}
.gauge-tick::before { content: ''; width: 1px; height: 4px; background: currentColor; display: block; }
.gauge-tick-label { font-size: 9px; white-space: nowrap; color: inherit; }
.gauge-tick--prod { color: var(--good); }
.gauge-tick--usage { color: var(--bad); }

/* ── System log ───────────────────────────────────────────────────────────── */
.console-log {
  font-size: 11px; line-height: 1.5; color: var(--ink-2);
  max-height: 240px; overflow-y: auto;
  padding: 4px 0;
}

.log-row {
  display: grid;
  grid-template-columns: 54px 18px 1fr;
  gap: 4px;
  align-items: baseline;
  padding: 3px 10px;
  border-bottom: 1px dashed var(--border-soft);
}
.log-row:last-child { border-bottom: none; }
.log-ts   { font-size: 9px; color: var(--ink-3); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.log-icon { font-size: 11px; text-align: center; line-height: 1; }
.log-text { color: var(--ink); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Standalone pages (farm / markt / stats) ──────────────────────────────── */
.page-content {
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}

.page-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}
.page-header-sub   { color: var(--ink-3); font-weight: 400; }
.page-header-space { flex: 1; }

.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.market-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.farm-actions { display: grid; grid-template-columns: 1fr; gap: 6px; }

/* ── Notification container ───────────────────────────────────────────────── */
#notif {
  position: fixed; top: 92px; right: 16px; z-index: 999;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
#notif > * { pointer-events: all; }

.notification { overflow: hidden; opacity: 1; transition: opacity 2s, height 2s; }

.notification-tooltip {
  margin-bottom: 0;
  min-width: 240px; max-width: 320px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--ink);
  display: flex; align-items: center; gap: 12px;
  position: relative; cursor: pointer;
  animation: ticker-in .25s ease-out;
}

.notification-tooltip .icon { font-size: 16px; flex-shrink: 0; }

.notification-tooltip p  { margin: 0; font-size: 11px; color: var(--ink-2); }
.notification-tooltip h5 { margin: 0 0 2px; font-size: 11px; color: var(--ink); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }

.close-notification {
  position: absolute; right: 10px; top: 10px;
  width: 16px; height: 16px; opacity: 0.4; cursor: pointer;
}
.close-notification:hover { opacity: 1; }
.close-notification::before,
.close-notification::after {
  content: ''; position: absolute; left: 7px; top: 1px;
  height: 14px; width: 2px; background: var(--ink);
}
.close-notification::before { transform: rotate(45deg); }
.close-notification::after  { transform: rotate(-45deg); }

/* ── WS indicator (global) ────────────────────────────────────────────────── */
#wsIndicator .ws-dot--online  { color: var(--good); }
#wsIndicator .ws-dot--offline { color: var(--bad); }

/* ── Compatibility shims for base.js-generated HTML ──────────────────────── */
kbd2 {
  font-family: inherit;
  padding: 2px 5px; font-size: 10px;
  color: var(--bg); background: var(--ink-2);
}

/* base.js writes h2/h3 inside panels at runtime for section headers */
.panel-body h2,
.panel-body h3 {
  font-size: 10px; font-weight: 700;
  color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.08em;
  margin: 6px 0 2px; border-top: 1px dashed var(--border-soft); padding-top: 6px;
}
.panel-body h2:first-child,
.panel-body h3:first-child { border-top: none; padding-top: 0; margin-top: 0; }

/* base.js table/inline layout elements */
.panel-body table { border-collapse: collapse; width: 100%; font-size: 11px; }
.panel-body td, .panel-body th {
  padding: 2px 4px; border-bottom: 1px dashed var(--border-soft); color: var(--ink-2);
}
.panel-body th { color: var(--ink-3); font-weight: 600; text-transform: uppercase; font-size: 9px; }

/* base.js progress bars use Bootstrap progress — restyle.
   Text lives inside .progress-bar so the container must be tall enough to hold
   it; overflow:hidden prevents it expanding the layout when the filled width is
   narrower than the label text. */
.progress {
  height: 18px;
  overflow: hidden;
  background: var(--border-soft);
  border-radius: 0;
  display: flex;
  align-items: stretch;
}
.progress-bar {
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 10px;
  white-space: nowrap;
  color: var(--ink);
  background: color-mix(in oklab, var(--accent) 55%, transparent);
  transition: width .3s;
  overflow: visible;
}

.phx-tab        { color: var(--ink-3); border-color: var(--border-soft); }
.phx-tab.active { color: var(--cyan);  border-color: var(--cyan); }
