: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; }
.hidden { display: none !important; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background-color: var(--bg-paper);
  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-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; }

.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; overflow-y: auto;
}

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

.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: 9.5px; line-height: 1.4;
}
.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-plugins-slot {
  margin-top: 10px; margin-bottom: 10px;
}
.nav-item-plugins {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.plugin-nav-badge {
  border: 1px solid currentColor; padding: 1px 6px; font-size: 9px; line-height: 1.2;
}

.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; display: inline-block; }
.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%; min-width: 0; }
.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 { 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; }

.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); }

.market-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.market-controls { display: flex; gap: 10px; flex-wrap: wrap; }

.products-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px;
}
.presets-layout {
  display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start;
}
.plugins-layout {
  display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 16px; align-items: start;
}
.plugin-card-btn {
  width: 100%; text-align: left; background: var(--bg-paper);
  border: var(--border-w) solid var(--ink); padding: 10px;
  cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  font-family: var(--font-mono); color: var(--ink);
}
.plugin-card-btn.active { background: var(--ink); color: var(--surface); box-shadow: var(--shadow-sm); }
.plugin-card-btn.active .muted { color: var(--surface-alt); }
.plugin-card-btn.active .badge { border-color: var(--surface); }
.plugin-card-head {
  display: flex; justify-content: space-between; align-items: center; gap: 6px; font-weight: 700;
}
.plugin-subtabs {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px;
  padding-bottom: 10px; border-bottom: 2px dashed var(--ink);
}
.s3-status-box {
  border: 1.5px solid var(--ink); background: var(--bg-paper); padding: 9px 11px;
  font-size: 12px; color: var(--ink); margin: 0;
}
.s3-mapping-row {
  background: var(--bg-paper); border: var(--border-w) solid var(--ink); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.s3-mapping-inputs {
  display: grid; grid-template-columns: minmax(200px, 1fr) 150px 88px; gap: 8px;
}
.s3-mapping-inputs .input { margin-top: 0; padding: 6px 8px; font-size: 12px; }
.preset-editor-area { font-size: 12px; line-height: 1.45; min-height: 380px; }
.preset-file-btn {
  width: 100%; text-align: left; background: var(--bg-paper);
  border: var(--border-w) solid var(--ink); padding: 9px 10px;
  cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 12px; font-weight: 700;
}
.preset-file-btn.active { background: var(--ink); color: var(--surface); }
.product-card {
  background: var(--surface); border: var(--border-w) solid var(--ink);
  box-shadow: var(--shadow); padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.product-card-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  border-bottom: 1px dashed var(--ink); padding-bottom: 8px;
}
.product-title { font-weight: 700; font-size: 13.5px; line-height: 1.35; }
.product-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.product-desc-snip {
  color: var(--ink-muted); font-size: 12px; white-space: pre-line;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.product-meta {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  background: var(--bg-paper); border: 1px solid var(--ink); padding: 7px 10px; font-size: 12px;
}
.product-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }

.product-cover-wrap {
  width: 100%; height: 132px; border: 1.5px solid var(--ink);
  background: var(--bg-paper); overflow: hidden; display: grid; place-items: center;
}
.product-cover-img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.cover-editor-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--bg-paper); border: var(--border-w) solid var(--ink); padding: 10px 12px;
}
.cover-editor-box .muted { margin: 0; }
.cover-empty-label { font-size: 11px; white-space: nowrap; }
.cover-preview-img {
  display: block; max-width: 180px; max-height: 120px; width: auto; height: auto;
  object-fit: contain; border: 1.5px solid var(--ink); background: var(--surface);
}
.cover-editor-controls {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; flex: 1; min-width: 190px;
}
.cover-file-input {
  width: 100%; margin-top: 0; padding: 6px 8px; line-height: 1.3; font-size: 12px;
}
.cover-file-input::file-selector-button {
  border: 1.5px solid var(--ink); background: var(--surface-alt); color: var(--ink);
  font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  padding: 4px 10px; margin-right: 10px; cursor: pointer;
}
.cover-file-input::file-selector-button:hover { background: var(--surface); }
.po-search-row {
  display: flex; gap: 8px; align-items: stretch; margin-top: 5px;
}
.po-search-row .input { margin-top: 0; flex: 1; }
.po-cat-options {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-paper); border: 1.5px solid var(--ink); padding: 10px; font-size: 12px;
}
.po-cat-hint {
  font-size: 11px; color: var(--ink-muted); white-space: pre-line;
  border-left: 3px solid var(--ink); padding-left: 8px;
}

.slots-list { display: flex; flex-direction: column; gap: 8px; }
.slot-row {
  background: var(--bg-paper); border: var(--border-w) solid var(--ink); padding: 8px 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}

.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-meta { color: var(--ink-muted); font-size: 11px; margin-bottom: 2px; font-weight: 700; }

.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;
}

.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; }

.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);
  text-transform: uppercase; text-decoration: none;
}
.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;
}

.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; }

.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: 330px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.chat-msg {
  max-width: 90%; 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);
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 15, 15, 0.55);
  display: grid; place-items: center; z-index: 80; padding: 16px;
}
.modal {
  background: var(--surface); border: var(--border-w) solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink); width: 100%; max-width: 580px; 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; flex-wrap: wrap; margin-top: 6px; }

.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); }

.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;
}

@media (max-width: 1040px) {
  .products-grid, .presets-layout, .plugins-layout { grid-template-columns: 1fr; }
  .s3-mapping-inputs { grid-template-columns: 1fr; }
}

@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; 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; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .two-col, .two-col-tight { grid-template-columns: 1fr; }
  .input-sm { width: 100%; }

  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 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; }
}
