:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f2430;
  --line: #2a3040;
  --text: #e7eaf0;
  --muted: #8b93a7;
  --accent: #5b8def;
  --accent-2: #4ade80;
  --bad: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2433 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .25rem; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem 0 .4rem; }
.muted { color: var(--muted); font-size: .85rem; }
code { background: var(--panel-2); padding: .1rem .35rem; border-radius: 5px; font-size: .8rem; }

/* Flash messages */
.flash-stack { position: fixed; top: 1rem; right: 1rem; z-index: 50; display: flex; flex-direction: column; gap: .5rem; }
.flash { padding: .7rem 1rem; border-radius: 10px; font-size: .85rem; border: 1px solid var(--line); background: var(--panel-2); box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.flash-error { border-color: #5a2730; color: #fda4af; }
.flash-success { border-color: #235a3b; color: #86efac; }

/* Brand */
.brand { display: flex; align-items: center; gap: .8rem; }
.brand.small .brand-mark { width: 34px; height: 34px; font-size: 1rem; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; font-size: 1.3rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
}
.brand div span { display: block; font-size: .78rem; color: var(--muted); }

/* Login */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2rem; padding: 1.5rem; }
.login-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 1.8rem; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-card .brand { margin-bottom: 1.4rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label, .grid label { display: flex; flex-direction: column; gap: .35rem; font-size: .82rem; color: var(--muted); }
.field-hint { font-size: .72rem; color: var(--muted); }
.footnote { font-size: .75rem; }

input, select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: .6rem .7rem; font-size: .9rem; outline: none; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,141,239,.18); }

button { cursor: pointer; font-size: .9rem; border-radius: 9px; padding: .65rem 1.1rem; border: 1px solid transparent; font-weight: 600; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #6d6cff); color: #fff; }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); text-decoration: none; display: inline-block; }
.btn-ghost:hover { border-color: var(--accent); }

/* Topbar + dashboard */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--line); }
.dash { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.2rem; padding: 1.5rem; max-width: 1200px; margin: 0 auto; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; margin-top: 1rem; }
.grid .span2 { grid-column: 1 / -1; }
.opt { color: var(--muted); font-weight: 400; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; }
.actions { display: flex; gap: .6rem; margin-top: .4rem; }

/* Results */
.results { position: sticky; top: 1.5rem; }
#output { margin-top: .8rem; display: flex; flex-direction: column; gap: .5rem; max-height: 65vh; overflow: auto; }
.rrow { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); font-size: .85rem; }
.rrow.ok { border-left: 3px solid var(--accent-2); }
.rrow.err { border-left: 3px solid var(--bad); }
.rrow .tag { font-size: .7rem; background: #2b3344; padding: .15rem .45rem; border-radius: 6px; color: var(--muted); }
.rrow .oname { font-weight: 600; }
.rrow .total { margin-left: auto; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.err-msg { font-family: monospace; font-size: .72rem; }
.bad { color: var(--bad); }

/* Tabs */
.tabs { display: flex; gap: .4rem; padding: 0 1.5rem; max-width: 1200px; margin: 1rem auto 0; flex-wrap: wrap; }
.tab { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); border-color: var(--accent); }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* Loader */
.loader { display: flex; flex-direction: column; align-items: center; gap: .7rem; padding: 1.4rem 0; }
.loader.hidden { display: none; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: .85rem; color: var(--text); }
.progressbar { width: 80%; height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progressfill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }

/* Danger button + danger tab */
.btn-danger { background: linear-gradient(135deg, #ef4444, #b91c1c); color: #fff; }
.tab.danger.active { border-color: var(--bad); color: #fda4af; }

/* Checkboxes */
.chk { flex-direction: row !important; align-items: center; gap: .5rem !important; color: var(--text) !important; }
.chk input { width: auto; }

/* Edge-case fieldset */
.edge { border: 1px dashed var(--line); border-radius: 10px; padding: .8rem; display: flex; flex-direction: column; gap: .5rem; }
.edge legend { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 0 .4rem; }

/* Nested grid (inside action panes) */
.grid.nested { margin-top: 0; }

/* Variant picker */
.picker-bar { display: flex; align-items: center; gap: .8rem; margin: 1rem 0 .5rem; }
.variant-list { max-height: 220px; overflow: auto; display: flex; flex-direction: column; gap: .3rem; margin-bottom: .6rem; }
.variant-list:empty { display: none; }
.vrow { display: flex; align-items: center; gap: .6rem; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: .82rem; color: var(--text); }
.vrow .vtitle { font-weight: 600; flex: 1; }
.vrow .vqty { width: 60px; }
.vchk { width: auto; }

/* Subform divider */
.subform { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* Cleanup counts */
.counts { margin: .8rem 0; }
.countgrid { display: flex; gap: .6rem; flex-wrap: wrap; }
.countgrid span { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .8rem; font-size: .85rem; font-weight: 600; }

@media (max-width: 860px) {
  .dash { grid-template-columns: 1fr; }
  .results { position: static; }
  .tabs { overflow-x: auto; }
}
