/* ======================================================
   Orbitrex Admin Portal — UI styles
   Alpine + HTMX + a tiny utility set. Self-contained;
   intentionally does NOT pull tokens.css to keep the
   portal visually distinct from the customer storefront
   (different audience, different look).
   ====================================================== */

:root {
  /* Forest green primary, lighter on white surfaces. Reuses the same
     brand hue as the storefront so it doesn't look like a different
     product, but the chrome around it is its own thing. */
  --p-bg:           #f5f7f6;
  --p-surface:      #ffffff;
  --p-surface-alt:  #fafbfa;
  --p-border:       #e1e6e3;
  --p-border-strong:#cdd5cf;

  --p-text:         #161917;
  --p-text-muted:   #5a635c;
  --p-text-subtle:  #8a948e;

  --p-primary:      #1a8443;
  --p-primary-hover:#166b37;
  --p-primary-bg:   #e9f6ee;

  --p-danger:       #b3261e;
  --p-danger-hover: #8c1d17;
  --p-danger-bg:    #fdecea;

  --p-warning:      #b07206;
  --p-warning-bg:   #fff5e0;

  --p-info:         #0b5a9e;
  --p-info-bg:      #e3f0fb;

  --p-radius:       6px;
  --p-radius-sm:    4px;
  --p-radius-lg:    10px;

  --p-shadow-sm:    0 1px 2px rgba(0,0,0,.04);
  --p-shadow:       0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);

  --p-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --p-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

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

/* ---- Layout shell ---- */
.p-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
.p-sidebar {
  background: #1a3c28;
  color: #e6efe9;
  padding: 18px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.p-sidebar-brand {
  font-weight: 700;
  font-size: 16px;
  padding: 0 20px 18px;
  letter-spacing: .02em;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.p-sidebar-brand small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: #9ec1ad;
  margin-top: 2px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.p-nav { list-style: none; padding: 12px 0; margin: 0; }
.p-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  color: #cfdcd4;
  font-weight: 500;
  font-size: 13px;
  border-left: 3px solid transparent;
}
.p-nav a:hover {
  color: #fff;
  background: rgba(255,255,255,.04);
  text-decoration: none;
}
.p-nav a.is-active {
  color: #fff;
  background: rgba(255,255,255,.08);
  border-left-color: #4eb573;
}
.p-nav a[hidden] { display: none; }

.p-main {
  padding: 24px 28px 64px;
  max-width: 1400px;
  width: 100%;
  /* A grid item defaults to min-width:auto, meaning it refuses to shrink below
     its content. So a wide table did not scroll inside .p-table-wrap — the
     whole 1fr column grew instead and the PAGE scrolled sideways, taking the
     header and toolbar with it while the sidebar stayed put. min-width:0 lets
     the track keep its size and hands the overflow back to .p-table-wrap,
     which already has overflow-x:auto and is the thing that should scroll.
     Surfaced by the 12-column COA table; every wide admin table hit it. */
  min-width: 0;
}
.p-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.p-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}
.p-header .p-meta {
  font-size: 12px;
  color: var(--p-text-muted);
}

/* ---- Cards ---- */
.p-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-lg);
  box-shadow: var(--p-shadow-sm);
  padding: 18px;
  margin-bottom: 18px;
}
.p-card h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}
.p-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Analytics card header — title on the left, date range on the right.
   Wraps on mobile so the date picker drops below the title. */
.p-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}
.p-card-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.p-date-range {
  display: flex;
  align-items: center;
  gap: 6px;
}
.p-date-range .p-input {
  width: auto;
  padding: 4px 8px;
  font-size: 13px;
}

/* Product-velocity "days remaining" cell tints. <14d = red, <30d = amber.
   Bare CSS — no JS color logic, just classes from velocityCellClass(). */
.p-v-critical { color: var(--p-danger, #8a2735); font-weight: 600; }
.p-v-warn     { color: #8a5a16; font-weight: 600; }

/* Stat tile (dashboard) */
.p-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.p-stat {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-lg);
  padding: 16px 18px;
}
.p-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--p-text-muted);
  margin-bottom: 4px;
}
.p-stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.p-stat-sub {
  font-size: 12px;
  color: var(--p-text-subtle);
  margin-top: 4px;
}

/* Performance card headline (big revenue total above the KPI row) */
.p-perf-headline {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.1;
  margin: 4px 0 18px;
}

/* ---- Tables ---- */
.p-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-lg);
  background: var(--p-surface);
}
.p-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.p-table th, .p-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--p-border);
  vertical-align: middle;
}
.p-table th {
  background: var(--p-surface-alt);
  font-weight: 600;
  color: var(--p-text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--p-border-strong);
}
.p-table tbody tr:hover { background: #f4f8f5; }
.p-table tbody tr:last-child td { border-bottom: 0; }
.p-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.p-table .mono { font-family: var(--p-mono); font-size: 12px; }
.p-table .actions { text-align: right; white-space: nowrap; }

/* ---- Forms / inputs ---- */
.p-input,
.p-select,
.p-textarea {
  width: 100%;
  font: inherit;
  color: var(--p-text);
  background: #fff;
  border: 1px solid var(--p-border-strong);
  border-radius: var(--p-radius);
  padding: 7px 10px;
  transition: border-color .12s, box-shadow .12s;
}
.p-input:focus,
.p-select:focus,
.p-textarea:focus {
  outline: none;
  border-color: var(--p-primary);
  box-shadow: 0 0 0 3px rgba(26,132,67,.15);
}
.p-input[disabled],
.p-select[disabled],
.p-textarea[disabled] { opacity: .6; cursor: not-allowed; }
.p-textarea { min-height: 80px; resize: vertical; }
.p-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--p-text-muted);
  margin-bottom: 4px;
}
.p-field { margin-bottom: 12px; }
.p-field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.p-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}

/* ---- Buttons ---- */
.p-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--p-border-strong);
  border-radius: var(--p-radius);
  background: #fff;
  color: var(--p-text);
  font: inherit;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.p-btn:hover { background: var(--p-surface-alt); }
.p-btn[disabled] { opacity: .55; cursor: not-allowed; }
.p-btn-primary {
  background: var(--p-primary);
  color: #fff;
  border-color: var(--p-primary);
}
.p-btn-primary:hover { background: var(--p-primary-hover); border-color: var(--p-primary-hover); color:#fff; }
.p-btn-danger {
  background: #fff;
  color: var(--p-danger);
  border-color: var(--p-danger);
}
.p-btn-danger:hover { background: var(--p-danger); color: #fff; }
.p-btn-ghost {
  border-color: transparent;
  color: var(--p-text-muted);
}
.p-btn-ghost:hover { color: var(--p-text); background: var(--p-surface-alt); }
.p-btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---- Badges / pills ---- */
.p-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: #eef0ee;
  color: #444b46;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.p-badge-success { background: var(--p-primary-bg); color: var(--p-primary); }
.p-badge-danger  { background: var(--p-danger-bg);  color: var(--p-danger); }
.p-badge-warning { background: var(--p-warning-bg); color: var(--p-warning); }
.p-badge-info    { background: var(--p-info-bg);    color: var(--p-info); }

/* ---- Per-order gateway pill ----
   Small color-coded chip in the Pay column. Source of truth for the
   color choice is the gateway, not the order status — so a refunded
   Argyle order still shows Argyle-green. Unknown (NULL payment_gateway)
   gets a neutral grey + warning hue to flag the row for backfill. */
.p-gw {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  letter-spacing: .02em;
  white-space: nowrap;
  cursor: help; /* paired with title= refund-hint tooltip */
}
.p-gw-argyle    { background: #e6f3ec; color: #1a6b3a; }
.p-gw-lunar     { background: #e6eef8; color: #1d3f74; }
.p-gw-linkmoney { background: #fff3df; color: #8a5a16; }
.p-gw-idem      { background: #f7e9da; color: #7a4318; }
.p-gw-manual    { background: #ececec; color: #4a4a4a; }
.p-gw-unknown   { background: #fde7e9; color: #8a2735; }

/* ---- Toolbar / filters ---- */
.p-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.p-toolbar > * { min-width: 0; }
.p-toolbar .p-input,
.p-toolbar .p-select { width: auto; min-width: 180px; }
.p-toolbar-spacer { flex: 1; }

/* ---- Pagination ---- */
.p-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px 0;
  font-size: 12px;
  color: var(--p-text-muted);
}

/* ---- Drawer / modal ---- */
.p-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,28,24,.45);
  display: flex;
  justify-content: flex-end;
  z-index: 100;
}
.p-drawer {
  width: min(560px, 100%);
  background: #fff;
  height: 100vh;
  overflow-y: auto;
  box-shadow: -4px 0 24px rgba(0,0,0,.18);
  padding: 20px 22px;
}
.p-drawer h2 { margin-top: 0; }
.p-drawer-foot {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--p-border);
  padding: 12px 0 0;
  margin-top: 18px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---- Toast ---- */
.p-toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 200;
}
.p-toast {
  background: #1a3c28;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--p-radius);
  font-size: 13px;
  box-shadow: var(--p-shadow);
  max-width: 360px;
}
.p-toast-error { background: var(--p-danger); }
.p-toast-success { background: var(--p-primary); }

/* ---- Empty / loading states ---- */
.p-empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--p-text-muted);
  font-size: 13px;
}
.p-loading {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--p-border-strong);
  border-top-color: var(--p-primary);
  border-radius: 50%;
  animation: p-spin .7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes p-spin { to { transform: rotate(360deg); } }

/* Tabs (used inside customer/order detail drawers) */
.p-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--p-border);
  margin-bottom: 14px;
}
.p-tabs button {
  background: none;
  border: 0;
  padding: 8px 14px;
  font: inherit;
  font-weight: 500;
  font-size: 13px;
  color: var(--p-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.p-tabs button.is-active {
  color: var(--p-primary);
  border-bottom-color: var(--p-primary);
}

/* Money helper — right-aligned, mono */
.money { font-variant-numeric: tabular-nums; text-align: right; }

/* Mobile breakpoint — collapse sidebar to a top bar */
@media (max-width: 800px) {
  .p-shell { grid-template-columns: 1fr; }
  .p-sidebar {
    position: static;
    height: auto;
    padding: 12px 0;
  }
  .p-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 12px 0;
  }
  .p-nav a { padding: 6px 12px; border-left: 0; border-radius: 999px; }
  .p-nav a.is-active { background: rgba(255,255,255,.12); border-left: 0; }
  .p-main { padding: 16px; }
}

/* ======================================================
   Project Tracker — kanban board
   ====================================================== */
.p-kanban {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 16px;
  align-items: start;
}
.p-kanban-col {
  background: var(--p-surface-alt);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-lg);
  padding: 12px;
  min-height: 120px;
  transition: outline-color .15s, background .15s;
  outline: 2px dashed transparent;
  outline-offset: -2px;
}
.p-kanban-col.is-drop {
  outline-color: var(--p-primary);
  background: var(--p-primary-bg);
}
.p-kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  color: var(--p-text);
  margin-bottom: 12px;
  padding: 2px 4px;
}
.p-kanban-col-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--p-text-muted);
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: 999px;
}
.p-kanban-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  box-shadow: var(--p-shadow-sm);
  padding: 12px;
  margin-bottom: 10px;
  cursor: grab;
}
.p-kanban-card:last-child { margin-bottom: 0; }
.p-kanban-card:active { cursor: grabbing; }
.p-kanban-card.is-dragging { opacity: .45; }
.p-kanban-card-title {
  font-weight: 600;
  color: var(--p-text);
  word-break: break-word;
}
.p-kanban-card-desc {
  font-size: 13px;
  color: var(--p-text-muted);
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.p-kanban-card-img {
  display: block;
  margin-top: 10px;
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--p-border);
  object-fit: cover;
  cursor: zoom-in;
}
.p-kanban-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--p-text-subtle);
}
.p-kanban-card-del {
  background: none;
  border: 0;
  color: var(--p-text-subtle);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: var(--p-radius-sm);
}
.p-kanban-card-del:hover { color: var(--p-danger); background: var(--p-danger-bg); }
.p-kanban-empty {
  font-size: 13px;
  color: var(--p-text-subtle);
  text-align: center;
  padding: 18px 8px;
  border: 1px dashed var(--p-border);
  border-radius: var(--p-radius);
}

/* Image upload field + preview in the new-task drawer */
.p-file-preview {
  display: block;
  margin-top: 10px;
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--p-border);
  object-fit: cover;
}

@media (max-width: 760px) {
  .p-kanban { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------
   Muted text and inline alerts.

   Added with the affiliate Network tab (Phase 1). The portal had been
   expressing both with one-off inline styles — `class="p-meta"
   style="color:var(--p-danger);"` — which meant every new screen
   reinvented them and none of them matched. These are the same colours
   the badges already use, so an alert and its matching badge agree.
   ------------------------------------------------------------------ */
.p-muted {
  color: var(--p-text-muted);
  font-size: 13px;
}

.p-alert {
  padding: 10px 12px;
  border-radius: var(--p-radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  margin-bottom: 12px;
}
.p-alert-error {
  background: var(--p-danger-bg);
  border-color: var(--p-danger);
  color: var(--p-danger);
}
.p-alert-success {
  background: var(--p-primary-bg);
  border-color: var(--p-primary);
  color: var(--p-primary-hover);
}
.p-alert-warning {
  background: var(--p-warning-bg);
  border-color: var(--p-warning);
  color: var(--p-warning);
}

/* ------------------------------------------------------------------
   Affiliate tag chips (Phase 2).

   Eight fixed colours, matching the CHECK constraint in migration 065
   and TAG_COLOURS in src/lib/affiliate-segments.ts. The palette is
   closed on purpose: the value comes from a field an admin types into
   and lands in a class name, so there is no free-text colour to
   sanitise. Adding a ninth means editing all three places, which is
   the point — they cannot drift silently.
   ------------------------------------------------------------------ */
.p-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  border: 1px solid transparent;
}
.p-tag + .p-tag { margin-left: 4px; }

.p-tag-slate  { background: #eef1ef; color: #45504a; border-color: #d5dcd8; }
.p-tag-green  { background: var(--p-primary-bg); color: var(--p-primary-hover); border-color: var(--p-primary); }
.p-tag-blue   { background: var(--p-info-bg);    color: var(--p-info);          border-color: var(--p-info); }
.p-tag-amber  { background: var(--p-warning-bg); color: var(--p-warning);       border-color: var(--p-warning); }
.p-tag-red    { background: var(--p-danger-bg);  color: var(--p-danger);        border-color: var(--p-danger); }
.p-tag-purple { background: #f2ecfb; color: #5b3a91; border-color: #a583d8; }
.p-tag-teal   { background: #e3f5f2; color: #0f6b60; border-color: #4faea0; }
.p-tag-pink   { background: #fdecf3; color: #9c2f5c; border-color: #e18aac; }
