:root {
  --bg-paper: #f0f0ea;
  --surface: #ffffff;
  --surface-alt: #e4e4dc;
  --ink: #0f0f0f;
  --ink-muted: #52524c;
  --border-w: 2px;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --font-pixel: "Press Start 2P", "Courier New", monospace;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
  border-radius: 0 !important;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-paper);
  /* Classic 1-bit pixel dot dithering */
  background-image: radial-gradient(var(--ink) 0.75px, transparent 0.75px);
  background-size: 6px 6px;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: none;
}

.pixel-font {
  font-family: var(--font-pixel);
  letter-spacing: 0.02em;
}

/* CRT scanline overlay (togglable) */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(15, 15, 15, 0.045) 0px,
    rgba(15, 15, 15, 0.045) 1px,
    transparent 1px,
    transparent 3px
  );
  transition: opacity 0.15s;
}
.crt-overlay.off {
  opacity: 0;
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.cursor {
  display: inline-block;
  animation: blink 1s steps(1, end) infinite;
}

/* Desktop + Shell layout */
.app-shell {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: var(--border-w) solid var(--ink);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: var(--border-w) solid var(--ink);
  background: var(--bg-paper);
  box-shadow: var(--shadow-sm);
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: var(--ink);
  color: var(--surface);
  display: grid;
  place-items: center;
  font-size: 12px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 12px;
  line-height: 1.3;
}
.brand-sub {
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 700;
  margin-top: 3px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 18px;
  flex: 1;
}

.nav-item {
  background: var(--surface);
  color: var(--ink);
  border: var(--border-w) solid var(--ink);
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  font-family: var(--font-pixel);
  font-size: 10px;
  line-height: 1.4;
  transition: transform 0.08s, box-shadow 0.08s;
}
.nav-item:hover {
  background: var(--surface-alt);
  box-shadow: 2px 2px 0 var(--ink);
}
.nav-item.active {
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow-sm);
}

.sidebar-footer {
  border-top: var(--border-w) solid var(--ink);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  padding: 8px 10px;
  border: var(--border-w) solid var(--ink);
  background: var(--bg-paper);
}

.dot {
  width: 10px;
  height: 10px;
  border: 2px solid var(--ink);
  flex-shrink: 0;
}
.dot.online {
  background: var(--ink);
}
.dot.offline {
  background: var(--surface);
}

.worker-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.main-content {
  padding: 24px 28px 40px;
  max-width: 1320px;
  width: 100%;
}

.tab { display: none; }
.tab.active { display: block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
}
h2 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 11px;
  line-height: 1.4;
}
h3 {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 11px;
}
.muted {
  color: var(--ink-muted);
  margin: 5px 0 0;
  font-size: 12px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow);
  padding: 14px;
}
.kpi-label {
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 700;
  border-bottom: 1px dashed var(--ink);
  padding-bottom: 6px;
}
.kpi-value {
  font-size: 20px;
  margin: 10px 0 6px;
  line-height: 1.2;
}
.kpi-sub {
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col-tight { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three-col-tight { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* Classic Mac 1-bit Window Chrome */
.panel {
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow);
  padding: 14px;
  overflow-x: auto;
}
.narrow-panel { max-width: 580px; }

.panel-header {
  margin: -14px -14px 14px -14px;
  padding: 9px 12px;
  border-bottom: var(--border-w) solid var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--surface-alt);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--ink) 0px,
    var(--ink) 1px,
    transparent 1px,
    transparent 3px
  );
}
.panel-header h2 {
  background: var(--surface);
  padding: 2px 8px;
  border: 1px solid var(--ink);
}

/* Slots & ASCII bars */
.slots-list { display: flex; flex-direction: column; gap: 10px; }
.slot-row {
  background: var(--bg-paper);
  border: var(--border-w) solid var(--ink);
  padding: 10px 12px;
}
.slot-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-weight: 700;
  flex-wrap: wrap;
}
.ascii-bar {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 13px;
}
.ascii-bar-lg {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

/* Logs */
.logs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}
.log-item {
  font-size: 12px;
  padding: 8px 10px;
  background: var(--bg-paper);
  border: 1px solid var(--ink);
  border-left: 5px solid var(--ink);
}
.log-item.WARN {
  border-left-style: double;
  background: var(--surface-alt);
}
.log-item.ERROR {
  background: var(--ink);
  color: var(--surface);
}
.log-item.ERROR .log-meta {
  color: var(--surface-alt);
}
.log-meta {
  color: var(--ink-muted);
  font-size: 11px;
  margin-bottom: 2px;
  font-weight: 700;
}

/* Tables */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--ink);
  vertical-align: middle;
}
.data-table th {
  background: var(--surface-alt);
  border-bottom: var(--border-w) solid var(--ink);
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.4;
}

/* Badges (1-bit strict B&W) */
.badge {
  display: inline-block;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  border: 1.5px solid var(--ink);
  text-transform: uppercase;
}
.badge-green { background: var(--ink); color: var(--surface); }
.badge-amber { background: var(--surface-alt); color: var(--ink); border-style: dashed; }
.badge-red { background: var(--surface); color: var(--ink); text-decoration: line-through; }

/* Tactile 1-bit Pixel Buttons */
.btn {
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 9px 13px;
  cursor: pointer;
  font-family: var(--font-pixel);
  font-size: 10px;
  line-height: 1.3;
  color: var(--ink);
  background: var(--surface);
  transition: transform 0.06s, box-shadow 0.06s;
  text-transform: uppercase;
}
.btn:hover { background: var(--surface-alt); }
.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}
.btn-sm { padding: 6px 9px; font-size: 9px; }
.btn-xs { padding: 5px 7px; font-size: 8px; box-shadow: 2px 2px 0 var(--ink); }
.btn-primary { background: var(--ink); color: var(--surface); }
.btn-primary:hover { background: #262626; }
.btn-secondary { background: var(--surface); color: var(--ink); }
.btn-danger {
  background: var(--surface);
  color: var(--ink);
  border-style: dashed;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 3px 6px;
  cursor: pointer;
}

/* Inputs & Forms */
.input {
  width: 100%;
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  color: var(--ink);
  padding: 9px 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  margin-top: 5px;
}
.input:focus {
  outline: none;
  box-shadow: var(--shadow-sm);
}
.input-sm { width: auto; min-width: 190px; margin-top: 0; }
textarea.input { resize: vertical; }

.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-stack label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}
.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
}
.checkbox-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--ink);
  margin: 0;
}
.sep { border: none; border-top: 2px dashed var(--ink); margin: 4px 0; }

/* Sandbox Chat */
.chat-panel { display: flex; flex-direction: column; gap: 10px; }
.chat-box {
  background: var(--bg-paper);
  border: var(--border-w) solid var(--ink);
  padding: 12px;
  height: 310px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg {
  max-width: 88%;
  padding: 9px 12px;
  border: var(--border-w) solid var(--ink);
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 12px;
  box-shadow: 2px 2px 0 var(--ink);
}
.chat-msg.buyer {
  align-self: flex-end;
  background: var(--ink);
  color: var(--surface);
}
.chat-msg.bot {
  align-self: flex-start;
  background: var(--surface);
  color: var(--ink);
}
.quick-cmds { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row .input { margin-top: 0; }

body.auth-locked .app-shell,
body.auth-locked .mobile-topbar,
body.auth-locked .bottom-nav {
  display: none !important;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 120;
  background-color: var(--bg-paper);
  background-image: radial-gradient(var(--ink) 0.75px, transparent 0.75px);
  background-size: 6px 6px;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
}
.auth-titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: var(--border-w) solid var(--ink);
  background-color: var(--surface-alt);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--ink) 0px,
    var(--ink) 1px,
    transparent 1px,
    transparent 3px
  );
}
.auth-titlebar-label,
.auth-titlebar .badge {
  background: var(--surface);
  padding: 2px 8px;
  border: 1px solid var(--ink);
  font-family: var(--font-pixel);
  font-size: 9px;
}
.auth-body {
  padding: 20px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.auth-emblem {
  width: 48px;
  height: 48px;
  background: var(--ink);
  color: var(--surface);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 3px 3px 0 var(--surface-alt);
}
.auth-brand-row h2 {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
}
.auth-sub {
  margin: 4px 0 0;
  font-size: 11.5px;
}
.auth-input-wrap {
  display: flex;
  align-items: stretch;
  margin-top: 5px;
}
.auth-input-wrap .input {
  margin-top: 0;
  flex: 1;
}
.auth-reveal-btn {
  margin-left: -2px;
  padding: 0 11px;
  font-family: var(--font-mono);
  font-size: 13px;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
}
.auth-error {
  background: var(--ink);
  color: var(--surface);
  border: var(--border-w) solid var(--ink);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
}
.auth-submit {
  width: 100%;
  padding: 11px 14px;
}
.auth-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-top: 1px dashed var(--ink);
  padding-top: 10px;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.55);
  display: grid;
  place-items: center;
  z-index: 80;
  padding: 16px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  width: 100%;
  max-width: 520px;
  padding: 16px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-sm { max-width: 380px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -16px -16px 14px -16px;
  padding: 10px 14px;
  border-bottom: var(--border-w) solid var(--ink);
  background-color: var(--surface-alt);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--ink) 0px,
    var(--ink) 1px,
    transparent 1px,
    transparent 3px
  );
}
.modal-header h3 {
  background: var(--surface);
  padding: 2px 8px;
  border: 1px solid var(--ink);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.mafile-drop {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px;
  border: 2px dashed var(--ink);
  background: var(--bg-paper);
}

.guard-box { text-align: center; padding: 12px 0; }
.guard-code {
  font-size: 32px;
  letter-spacing: 6px;
  background: var(--ink);
  color: var(--surface);
  display: inline-block;
  padding: 12px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

/* Toasts */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 95;
}
.toast {
  background: var(--surface);
  color: var(--ink);
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow-sm);
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
}
.toast.error {
  background: var(--ink);
  color: var(--surface);
}

.actions-cell { white-space: nowrap; width: 1%; }
.actions-row { display: inline-flex; align-items: center; gap: 10px; flex-wrap: nowrap; }

.market-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.market-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.templates-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.template-card {
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.template-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px dashed var(--ink);
  padding-bottom: 6px;
}
.section-subhead {
  font-family: var(--font-pixel);
  font-size: 10px;
  margin-top: 2px;
}
.preview-meta {
  font-weight: 700;
  padding: 8px 10px;
  background: var(--bg-paper);
  border: 1px solid var(--ink);
}
.link-plain {
  color: var(--ink);
  text-decoration: underline;
  font-weight: 700;
}
.checklist-box {
  margin-top: 5px;
  max-height: 140px;
  overflow-y: auto;
  border: var(--border-w) solid var(--ink);
  background: var(--bg-paper);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Mobile-only chrome hidden on desktop */
.mobile-topbar, .bottom-nav { display: none; }
.pixel-badge-inv {
  background: var(--ink);
  color: var(--surface);
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 4px 6px;
}

/* ================= MOBILE ADAPTATION (<= 860px) ================= */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .app-shell { grid-template-columns: 1fr; }

  .mobile-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--surface);
    border-bottom: var(--border-w) solid var(--ink);
    padding: 8px 12px;
  }
  .mobile-brand { display: flex; align-items: center; gap: 8px; }
  .mobile-title { font-size: 11px; }
  .mobile-topbar-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px; }
  .mobile-status-chip {
    font-size: 10px;
    font-weight: 700;
    border: 1.5px solid var(--ink);
    padding: 3px 6px;
    background: var(--bg-paper);
  }
  .mobile-status-chip.online {
    background: var(--ink);
    color: var(--surface);
  }

  .main-content {
    padding: 14px 12px calc(92px + env(safe-area-inset-bottom));
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }
  h1 { font-size: 13px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-value { font-size: 16px; }
  .two-col, .two-col-tight, .three-col-tight, .templates-grid { grid-template-columns: 1fr; }
  .market-controls { width: 100%; }
  .input-sm { width: 100%; }

  /* Tables become 1-bit mobile cards */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    border: var(--border-w) solid var(--ink);
    box-shadow: var(--shadow-sm);
    background: var(--bg-paper);
    padding: 10px;
    margin-bottom: 12px;
  }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px dashed var(--ink);
    text-align: right;
  }
  .data-table td:last-child { border-bottom: none; padding-top: 10px; }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 11px;
    color: var(--ink-muted);
    text-align: left;
    flex-shrink: 0;
  }
  .data-table td.empty-cell {
    display: block;
    text-align: center;
    border: none;
  }
  .data-table td.empty-cell::before { content: none; }
  .actions-cell { width: 100%; white-space: normal; }
  .actions-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }

  .btn { min-height: 36px; }
  .btn-xs { min-height: 28px; }

  /* Fixed bottom navigation bar */
  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 60;
    background: var(--surface);
    border-top: var(--border-w) solid var(--ink);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 2px;
    border: none;
    border-right: 1px solid var(--ink);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
  }
  .bottom-nav-item:last-child { border-right: none; }
  .bottom-nav-item.active {
    background: var(--ink);
    color: var(--surface);
  }
  .px-icon { width: 16px; height: 16px; display: block; }

  .toast-container {
    bottom: calc(74px + env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
  }
}

/* Unified Bot Hub Switcher */
.hidden { display: none !important; }
.bot-switcher {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 10px;
}
.bot-switch-btn, .bot-switch-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
}
.dot-xs {
  width: 8px;
  height: 8px;
  border-width: 1.5px;
}
