:root {
  --bg: #12151a;
  --bg-elev: #1a1f27;
  --bg-panel: #1e2530;
  --line: #2c3544;
  --text: #e8eef6;
  --muted: #9aa8ba;
  --accent: #c45c26;
  --accent-2: #e8a05c;
  --ok: #3d9b6e;
  --danger: #c44b4b;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a1c14 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a2433 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

.shell { max-width: 1120px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }

.hero {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}
.brand {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-weight: 600;
}
.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.lede { margin: 0.4rem 0 1rem; color: var(--muted); }
.status-strip {
  display: inline-flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.panel {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-elev));
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1.1rem 1.15rem 1.25rem;
}
.panel.wide { grid-column: 1 / -1; }
.panel h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
}
.panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent-2);
}
.hint { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.85rem; }
.hint.mono, .mono { font-family: var(--mono); font-size: 0.78rem; }
code {
  font-family: var(--mono);
  font-size: 0.8em;
  color: var(--accent-2);
}

.form {
  display: grid;
  gap: 0.65rem;
}
label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}
label.check {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}
input[type="text"],
input[type="email"],
input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #12161d;
  color: var(--text);
  border-radius: 3px;
  padding: 0.55rem 0.65rem;
  font: inherit;
}
input:focus, select:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.actions, .row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.pq-test { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }
.pq-test .row input, .pq-test .row select { width: auto; min-width: 5rem; }

.btn {
  border: 1px solid var(--line);
  background: #252d3a;
  color: var(--text);
  border-radius: 3px;
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { border-color: #4a5870; background: #2c3646; }
.btn.primary {
  background: var(--accent);
  border-color: #a34a1c;
  color: #fff;
}
.btn.primary:hover { background: #d4682e; }
.btn.danger {
  background: #5a2424;
  border-color: #8a3535;
}
.btn:disabled { opacity: 0.5; cursor: wait; }

.mode-block + .mode-block {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.on {
  color: #b7f0d0;
  border-color: #2f6b4c;
  background: #173528;
}
.pill.off {
  color: #f0c0c0;
  border-color: #6b2f2f;
  background: #351717;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.chip {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #151a22;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
th, td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--line);
}
th { color: var(--muted); font-weight: 500; }
td.sku { font-family: var(--mono); font-size: 0.78rem; }
button.link-sku {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-family: var(--mono);
  color: var(--accent, #0b5fff);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.link-sku:hover { opacity: 0.85; }
tr.needs-cost td { background: rgba(180, 120, 40, 0.08); }
tr.needs-cost input.profit-cost { border-color: #b47828; }
tr.profit-group-summary td {
  background: rgba(80, 120, 180, 0.1);
  font-weight: 500;
}
tr.profit-group-summary { cursor: pointer; }
tr.profit-group-detail td {
  background: rgba(255, 255, 255, 0.02);
}
tr.profit-group-detail td:first-child {
  padding-left: 2rem;
}
tr.profit-group-total td {
  background: rgba(80, 120, 180, 0.08);
  font-weight: 600;
  border-top: 2px solid var(--line);
}
tr.profit-group-total td:first-child {
  padding-left: 1rem;
}
button.profit-toggle {
  min-width: 1.4rem;
  padding: 0.1rem 0.25rem;
  margin-right: 0.35rem;
  font-size: 0.7rem;
  line-height: 1;
}
tr.hidden { display: none; }
.profit-items-label { color: var(--muted); font-weight: 400; font-size: 0.78rem; }
input.profit-cost, input.profit-source {
  width: 100%;
  min-width: 5rem;
  max-width: 9rem;
  font: inherit;
  padding: 0.25rem 0.4rem;
}

.log {
  margin: 0;
  min-height: 8rem;
  max-height: 18rem;
  overflow: auto;
  padding: 0.85rem;
  background: #0e1218;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c5d0de;
}

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .panel.wide { grid-column: auto; }
}

.hero-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 1.1rem;
}
.tab {
  border: 1px solid var(--line);
  background: #1a212c;
  color: var(--muted);
  border-radius: 3px;
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: #2a221c;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; }
label.inline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
}
label.inline select { width: auto; }
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}
ul.plain {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
}
ul.plain li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--line);
}
.form-inline input[type="search"],
.form-inline input[type="text"] {
  min-width: 14rem;
  flex: 1;
}
input[type="search"],
input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #12161d;
  color: var(--text);
  border-radius: 3px;
  padding: 0.55rem 0.65rem;
  font: inherit;
}
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem;
}
.login-shell {
  width: min(420px, 100%);
  padding: 1.75rem 1.5rem;
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-elev));
  border: 1px solid var(--line);
  border-radius: 4px;
}
.login-shell h1 {
  margin: 0;
  font-size: 1.7rem;
}
.login-form { margin-top: 1.25rem; }
.hint.error { color: #f0a0a0; }
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
}

/* —— Loading overlay (must cover full viewport, centered) —— */
.busy-overlay {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  margin: 0 !important;
  z-index: 99999 !important;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  box-sizing: border-box;
  background:
    radial-gradient(800px 400px at 50% 40%, rgba(196, 92, 38, 0.18), transparent 60%),
    rgba(8, 10, 14, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.busy-overlay.is-visible {
  display: flex !important;
}
.busy-card {
  position: relative;
  width: min(360px, 100%);
  margin: 0 auto;
  padding: 1.6rem 1.4rem 1.35rem;
  text-align: center;
  background: linear-gradient(165deg, #243041 0%, #1a212c 55%, #151b24 100%);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  animation: busy-rise 0.35s ease both;
}
@keyframes busy-rise {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.busy-ring {
  width: 52px;
  height: 52px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  border: 3px solid #2c3544;
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  animation: busy-spin 0.85s linear infinite;
}
@keyframes busy-spin {
  to { transform: rotate(360deg); }
}
.busy-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.busy-sub {
  margin: 0.35rem 0 1rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
  min-height: 1.2em;
}
.busy-bar {
  height: 3px;
  border-radius: 2px;
  background: #12161d;
  overflow: hidden;
}
.busy-bar span {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: busy-slide 1.35s ease-in-out infinite;
}
@keyframes busy-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
body.is-busy {
  overflow: hidden;
}
