:root {
  --bg: #0f131b;
  --panel: #171d29;
  --panel-alt: #1e2636;
  --border: #2c374e;
  --text: #e6edf7;
  --muted: #8ea0bd;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --slot-bg: #232b3c;
  --slot-craft: #1a2d42;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.pixel-icon {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  object-fit: contain;
}

.pixel-icon.sm { width: 32px; height: 32px; }
.pixel-icon.lg { width: 56px; height: 56px; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled { opacity: 0.48; cursor: not-allowed; }
.btn-primary { background: var(--accent-strong); color: #06101b; }
.btn-primary:hover:not(:disabled) { background: var(--accent); }
.btn-success { background: var(--success); color: #05160c; }
.btn-success:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--panel-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--panel-alt); }
.full-width { width: 100%; margin-top: 12px; }

input, select {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
}

input:focus, select:focus { border-color: var(--accent); }

.field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

.error-banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
  font-size: 13px;
}

.login-backdrop {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.login-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
}

.login-card h1 { margin: 12px 0 6px; font-size: 22px; }
.login-sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login-card input { width: 100%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 19, 27, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.topbar-left, .topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.brand { font-weight: 800; font-size: 16px; color: var(--accent); }
.select-compact { padding: 6px 10px; font-size: 13px; }

.tab-group {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.tab-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active { background: var(--panel-alt); color: var(--text); }
.pill-count {
  margin-left: 4px;
  font-size: 11px;
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 999px;
}

.requester-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.requester-box input { width: 110px; padding: 6px 8px; font-size: 13px; }

.pane { max-width: 1460px; margin: 0 auto; padding: 16px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.search-input { flex: 1 1 260px; min-width: 200px; }

.filter-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.pill.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.stats-text { font-size: 13px; color: var(--muted); margin-left: auto; }

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.item-card {
  background: var(--slot-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  color: inherit;
  transition: border-color 0.12s ease, transform 0.1s ease;
}

.item-card.craftable {
  background: linear-gradient(135deg, var(--slot-craft), var(--slot-bg));
  border-color: #2e4a6d;
  cursor: pointer;
}

.item-card.craftable:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.item-info { min-width: 0; flex: 1; }
.item-title {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-sub {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
}

.qty-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.55);
  padding: 2px 6px;
  border-radius: 5px;
}

.craft-tag {
  font-size: 11px;
  font-weight: 600;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.14);
  padding: 2px 6px;
  border-radius: 5px;
}

.fluid-tag {
  font-size: 11px;
  color: #93c5fd;
  background: rgba(37, 99, 235, 0.18);
  padding: 2px 5px;
  border-radius: 5px;
}

.pager {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.pager-info { font-size: 13px; color: var(--muted); }

/* CPU Monitor */
.cpu-layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 14px;
  align-items: start;
}

.cpu-sidebar, .cpu-detail {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.sidebar-header { font-size: 14px; font-weight: 700; margin-bottom: 10px; color: var(--muted); }
.cpu-list { display: flex; flex-direction: column; gap: 8px; max-height: 75vh; overflow-y: auto; }

.cpu-btn {
  width: 100%;
  text-align: left;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  cursor: pointer;
}

.cpu-btn.selected { border-color: var(--accent); background: #1c2e45; }
.cpu-btn-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 700; }
.cpu-btn-specs { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.cpu-btn-job { display: flex; align-items: center; gap: 7px; margin-top: 6px; font-size: 12px; }
.progress-track { height: 4px; background: #0d121a; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; background: var(--success); }

.cpu-detail-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.cpu-detail-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 10px 0 12px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(6, 9, 15, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 960px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.modal-item-head { display: flex; align-items: center; gap: 12px; }
.modal-item-head h2 { margin: 0; font-size: 18px; }
.muted-line { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.order-controls { margin-top: 14px; }
.qty-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.qty-field { flex: 1 1 160px; }
.qty-field input { width: 100%; }
.mode-field { flex: 1 1 200px; }
.mode-field select { width: 100%; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.plan-section { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.plan-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.sum-chip {
  font-size: 12.5px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 7px;
}
.sum-chip.ok { border-color: rgba(34, 197, 94, 0.5); color: #86efac; }
.sum-chip.warn { border-color: rgba(239, 68, 68, 0.55); color: #fca5a5; }

.plan-filter-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.checkbox-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
}

.plan-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-alt);
}

.plan-entry.state-missing { border-color: #ef4444; background: rgba(127, 29, 29, 0.25); }
.plan-entry.state-active { border-color: #22c55e; background: rgba(20, 83, 45, 0.28); }
.plan-entry.state-craft { border-color: #eab308; background: rgba(113, 63, 18, 0.24); }
.plan-entry-info { min-width: 0; flex: 1; }
.plan-entry-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-entry-stats { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.text-missing { color: #fca5a5; font-weight: 700; }
.text-active { color: #86efac; font-weight: 600; }
.text-craft { color: #fde047; font-weight: 600; }

.submit-bar {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}

.submit-left { display: flex; flex-direction: column; gap: 8px; flex: 1 1 280px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  background: #14532d;
  border: 1px solid #22c55e;
  color: #f0fdf4;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.toast.error { background: #7f1d1d; border-color: #ef4444; color: #fef2f2; }

@media (max-width: 820px) {
  .cpu-layout { grid-template-columns: 1fr; }
  .item-grid { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
}
