/* ===================================================================
   Beastmode PO — internal ops tool
   Dense, scannable, sharp. No fluff.
   =================================================================== */

:root {
  --ink: #0f1115;
  --ink-2: #2a2e36;
  --ink-3: #565a64;
  --muted: #8a8f99;
  --rule: #e2e3e7;
  --rule-strong: #c8cad0;
  --bg: #fafaf7;
  --bg-card: #ffffff;
  --bg-sunken: #f3f3ef;
  --accent: #0b2545;
  --accent-2: #f97316;

  --green: #2f7d32;
  --green-bg: #e6f4e6;
  --amber: #b96e00;
  --amber-bg: #fdf3df;
  --red: #b3261e;
  --red-bg: #fae6e4;

  --radius: 6px;
  --radius-sm: 3px;

  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.num { text-align: right; }
.small { font-size: 12px; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--ink);
  color: #fff;
  border-bottom: 1px solid #000;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 10px 20px;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark {
  background: var(--accent-2);
  color: #000;
  font-weight: 700;
  font-size: 13px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; }
.navlinks { display: flex; gap: 4px; margin-left: 12px; flex: 1; }
.navlink {
  color: rgba(255,255,255,0.75);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.navlink:hover { color: #fff; background: rgba(255,255,255,0.06); text-decoration: none; }
.navlink-cta {
  background: var(--accent-2);
  color: #000;
  font-weight: 600;
}
.navlink-cta:hover { background: #fff; color: #000; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: rgba(255,255,255,0.85); }
.linkbtn {
  background: none; border: none; color: rgba(255,255,255,0.75);
  cursor: pointer; padding: 4px 8px; font-family: inherit; font-size: 13px;
}
.linkbtn:hover { color: #fff; }

/* ---------- Page ---------- */
.page { max-width: 1400px; margin: 0 auto; padding: 24px 20px; }
.page-title { font-size: 24px; font-weight: 600; margin: 0 0 24px; letter-spacing: -0.01em; }
.section-title { font-size: 16px; font-weight: 600; margin: 24px 0 12px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
.card h3 { font-size: 13px; font-weight: 600; margin: 18px 0 8px; color: var(--ink-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---------- Filters ---------- */
.filters {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.filter-form { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.filter-group label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.pillrow { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
  color: var(--ink-2);
  background: var(--bg-card);
}
.pill:hover { background: var(--bg-sunken); text-decoration: none; }
.pill-on { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill-on:hover { background: var(--ink); }
.pillcount {
  display: inline-block;
  background: rgba(255,255,255,0.18);
  padding: 0 6px; border-radius: 999px; font-size: 11px;
}
.pill:not(.pill-on) .pillcount { background: var(--bg-sunken); color: var(--muted); }
.entity-pill .entity-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--entity-primary, var(--ink));
  display: inline-block;
}
.filter-search { margin-left: auto; display: flex; align-items: flex-end; gap: 6px; }
.filter-search input { width: 240px; }

/* ---------- Inputs ---------- */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], select, textarea {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 37, 69, 0.12);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label, .stacked label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.stacked { display: flex; flex-direction: column; gap: 12px; }
.hint { font-size: 12px; color: var(--muted); }
.radiorow { display: flex; gap: 16px; padding: 6px 0; }
.radio { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.radio input { width: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font: inherit; font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: #000; color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--rule-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-sunken); }
.btn-tertiary { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn-tertiary:hover:not(:disabled) { background: var(--bg-sunken); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.iconbtn {
  background: transparent; border: 1px solid transparent;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 18px; line-height: 1; color: var(--muted);
}
.iconbtn:hover { background: var(--bg-sunken); color: var(--red); }

/* ---------- Tables ---------- */
.potable-wrap { background: var(--bg-card); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.potable { width: 100%; border-collapse: collapse; }
.potable th {
  text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600; color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--bg-sunken);
}
.potable th.num { text-align: right; }
.potable td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}
.potable tbody tr { cursor: pointer; transition: background 0.08s; }
.potable tbody tr:hover { background: var(--bg-sunken); }
.potable tbody tr:last-child td { border-bottom: none; }
.potable .empty { text-align: center; color: var(--muted); padding: 32px; cursor: default; }
.po-num { font-family: var(--font-mono); font-weight: 600; }

/* ---------- Entity tag ---------- */
.entity-tag {
  display: inline-flex; align-items: center;
  background: var(--entity-primary, var(--ink));
  color: var(--entity-accent, #fff);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
  margin-right: 8px;
}

/* ---------- Status badges ---------- */
.status {
  display: inline-block;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 3px 8px; border-radius: var(--radius-sm);
  background: var(--bg-sunken); color: var(--ink-2);
  border: 1px solid var(--rule);
}
.status-draft { background: #ffffff; color: var(--ink-3); border-color: var(--rule-strong); }
.status-sent { background: #e8eef8; color: #1f3d70; border-color: #c9d6ea; }
.status-partially_received { background: var(--amber-bg); color: var(--amber); border-color: #f3d99b; }
.status-received { background: var(--green-bg); color: var(--green); border-color: #b8dcb8; }
.status-invoiced { background: #e9e3f9; color: #4b2d8a; border-color: #cfc1ee; }
.status-closed { background: #1f2937; color: #f0f3f8; border-color: #1f2937; }
.status-cancelled { background: var(--red-bg); color: var(--red); border-color: #e9b8b5; }
.status-running { background: var(--amber-bg); color: var(--amber); border-color: #f3d99b; }
.status-success { background: var(--green-bg); color: var(--green); border-color: #b8dcb8; }
.status-failed { background: var(--red-bg); color: var(--red); border-color: #e9b8b5; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: var(--radius-sm); }
.badge-stock { background: #fdf3df; color: var(--amber); border: 1px solid #f3d99b; }
.badge-adhoc { background: #f1ecff; color: #5b2db5; border: 1px solid #ddd1f5; margin-left: 4px; }

/* ---------- Margin bands ---------- */
.margin { display: inline-block; padding: 1px 6px; border-radius: var(--radius-sm); font-weight: 600; }
.margin-green { background: var(--green-bg); color: var(--green); }
.margin-amber { background: var(--amber-bg); color: var(--amber); }
.margin-red { background: var(--red-bg); color: var(--red); }
.margin-na { color: var(--muted); background: transparent; }

/* ---------- PO new form ---------- */
.po-form .card, .po-form { background: var(--bg-card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px; }
.linetable { width: 100%; border-collapse: collapse; margin: 12px 0; }
.linetable th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; padding: 8px 8px; border-bottom: 1px solid var(--rule); text-align: left; }
.linetable th.num { text-align: right; }
.linetable td { padding: 8px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.linetable.static td, .linetable.static th { padding: 10px 14px; }
.linetable input { padding: 6px 8px; }
.line-product { position: relative; min-width: 280px; }
.line-desc { font-size: 12px; margin-top: 4px; }
.sku-results {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%;
  background: #fff; border: 1px solid var(--rule-strong); border-radius: var(--radius-sm);
  max-height: 280px; overflow-y: auto; box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}
.sku-hit { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--rule); font-size: 13px; }
.sku-hit:hover { background: var(--bg-sunken); }
.sku-hit:last-child { border-bottom: none; }
.line-actions { display: flex; gap: 8px; margin: 12px 0; }
.totals-row {
  display: flex; gap: 32px; justify-content: flex-end;
  padding: 14px 0; border-top: 2px solid var(--ink); margin-top: 8px;
}
.total-item { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.t-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule); }

/* ---------- PO detail ---------- */
.po-header {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}
.po-header-id { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.po-num-h1 { font-family: var(--font-mono); font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.po-meta { display: flex; gap: 28px; flex-wrap: wrap; font-size: 13px; }
.po-meta .muted { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; font-weight: 600; }
.po-header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--rule); display: flex; gap: 14px; align-items: baseline; font-size: 13px; }
.timeline li:last-child { border-bottom: none; }

/* ---------- Admin ---------- */
.sync-stats { display: flex; gap: 32px; margin: 12px 0 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .mono { font-size: 22px; font-weight: 600; }
.sync-actions { display: flex; gap: 8px; margin-bottom: 18px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: middle; margin-right: 6px; border: 1px solid var(--rule); }

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: var(--ink);
  background-image:
    radial-gradient(at 30% 20%, rgba(249, 115, 22, 0.07), transparent 50%),
    radial-gradient(at 70% 80%, rgba(11, 37, 69, 0.4), transparent 50%);
}
.login-card {
  background: var(--bg-card);
  padding: 36px;
  border-radius: 8px;
  width: 360px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.login-mark {
  background: var(--accent-2); color: #000;
  font-weight: 700; padding: 4px 10px; border-radius: 4px;
  display: inline-block; margin-bottom: 18px; letter-spacing: 0.5px;
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #e9b8b5; }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #b8dcb8; }

/* ---------- Entity cards (admin) ---------- */
.entity-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.entity-card { background: var(--bg-card); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.entity-card-head {
  padding: 10px 14px;
  display: flex; align-items: center; gap: 12px;
}
.entity-card-code { font-family: var(--font-mono); font-weight: 700; font-size: 14px; }
.entity-card-name { font-weight: 600; flex: 1; }
.entity-card-seq { font-size: 12px; opacity: 0.85; }
.entity-card-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.entity-card-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
@media (max-width: 900px) { .entity-grid { grid-template-columns: 1fr; } }

/* ---------- Responsive trim ---------- */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .po-header { flex-direction: column; }
  .filter-search { margin-left: 0; width: 100%; }
}
