/* ============================================================
 *  ZING PLATFORM — shared design system ("cool classic")
 *  SINGLE SOURCE OF TRUTH: Zing Platform/_shared/platform.css
 *  Copied into each app (public/ or src/) by sync-shared.sh.
 *  Edit THIS file only — per-app copies are overwritten on sync.
 *
 *  Decided 2026-07-07: this replaces the retired "Canvas" system.
 *  Tokens are UN-prefixed (apps already use these var names).
 *  Components are .zp-* so they never collide with an app's
 *  existing classes; apps migrate to them screen by screen.
 *
 *  Per-app accent: an app may set --accent in its own stylesheet
 *  (e.g. Grow green #2f8f5b). It colours the nav active state and
 *  the app mark ONLY. Everything else stays identical.
 * ============================================================ */

/* ---------- 1. Tokens ---------- */
:root {
  /* Surfaces */
  --bg:         #f4f6fb;
  --surface:    #fff;
  --surface-2:  #f8fafc;
  --border:     #e6e9f0;

  /* Text */
  --text:       #1f2433;
  --text-soft:  #5b6478;
  --text-faint: #8a93a6;

  /* Brand */
  --primary:      #c1272d;
  --primary-dark: #a31f24;
  --primary-soft: #fbeaec;

  /* Per-app accent — defaults to brand red; an app may override */
  --accent:      var(--primary);
  --accent-dark: var(--primary-dark);
  --accent-soft: var(--primary-soft);

  /* Status intents — ONE naming, everywhere */
  --ok-bg:   #e7f6ec;  --ok-fg:   #1b8a4b;
  --warn-bg: #fef4e4;  --warn-fg: #b9741a;
  --bad-bg:  #fde7e9;  --bad-fg:  #c0314a;
  --info-bg: #e8f0fc;  --info-fg: #1f5fb0;
  --muted-bg:#eef1f6;  --muted-fg:#6b7486;
  --purple-bg:#f0e9fb; --purple-fg:#6b3fc0;

  /* Elevation & shape */
  --shadow:    0 1px 3px rgba(20,25,50,.06), 0 8px 24px rgba(20,25,50,.06);
  --shadow-lg: 0 12px 40px rgba(20,25,50,.18);
  --radius:    14px;   /* cards, modals, drawers */
  --radius-sm: 9px;    /* buttons, inputs, small chips */

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Shell */
  --topbar-h:  58px;
  --sidebar-w: 222px;
}

/* Legacy aliases so older per-app CSS keeps working while it migrates.
   New code uses the intent names above. */
:root {
  --green-bg: var(--ok-bg);   --green-fg: var(--ok-fg);
  --amber-bg: var(--warn-bg); --amber-fg: var(--warn-fg);
  --red-bg:   var(--bad-bg);  --red-fg:   var(--bad-fg);
  --blue-bg:  var(--info-bg); --blue-fg:  var(--info-fg);
  --gray-bg:  var(--muted-bg);--gray-fg:  var(--muted-fg);
}

/* ---------- 2. Buttons (.zp-btn) ---------- */
.zp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 8px 15px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .12s, border-color .12s;
}
.zp-btn:hover { background: var(--surface-2); }
.zp-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.zp-btn.primary:hover { background: var(--primary-dark); }
.zp-btn.danger { background: var(--surface); border-color: #f0c8cb; color: var(--primary); }
.zp-btn.danger:hover { background: var(--bad-bg); }
.zp-btn.danger-solid { background: var(--primary); border-color: var(--primary); color: #fff; }
.zp-btn.danger-solid:hover { background: var(--primary-dark); }
.zp-btn.ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.zp-btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.zp-btn.sm { font-size: 12.5px; padding: 5px 11px; }
.zp-btn:disabled { opacity: .5; cursor: not-allowed; }
.zp-btn:focus-visible { outline: 2px solid var(--info-fg); outline-offset: 2px; }

/* Segmented control */
.zp-seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.zp-seg button {
  font: inherit; font-size: 12.5px; font-weight: 600; border: 0; background: transparent;
  color: var(--text-soft); padding: 5px 13px; border-radius: 8px; cursor: pointer;
}
.zp-seg button.on { background: var(--surface); color: var(--primary); box-shadow: 0 1px 2px rgba(20,25,50,.08); }

/* ---------- 3. Status pills ---------- */
.zp-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.zp-pill.ok    { background: var(--ok-bg);    color: var(--ok-fg); }
.zp-pill.warn  { background: var(--warn-bg);  color: var(--warn-fg); }
.zp-pill.bad   { background: var(--bad-bg);   color: var(--bad-fg); }
.zp-pill.info  { background: var(--info-bg);  color: var(--info-fg); }
.zp-pill.muted { background: var(--muted-bg); color: var(--muted-fg); }
.zp-pill.purple{ background: var(--purple-bg);color: var(--purple-fg); }

/* ---------- 4. Cards & KPI tiles ---------- */
.zp-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px;
}
.zp-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; }
.zp-kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; position: relative; overflow: hidden;
}
.zp-kpi .accent { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.zp-kpi .label { font-size: 11.5px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.zp-kpi .value { font-size: 27px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.zp-kpi .sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.zp-kpi.clickable { cursor: pointer; transition: box-shadow .12s, border-color .12s; }
.zp-kpi.clickable:hover { box-shadow: var(--shadow); border-color: #d5dae6; }

/* ---------- 5. Table card ---------- */
.zp-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.zp-table-wrap .scroll { overflow-x: auto; }
table.zp-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.zp-table th {
  background: var(--surface-2); text-align: left; font-size: 11px; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase; color: var(--text-soft);
  padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.zp-table th.sortable { cursor: pointer; user-select: none; }
table.zp-table th.sortable:hover { color: var(--text); }
table.zp-table th .arr { color: var(--text-faint); }
table.zp-table th .arr.on { color: var(--primary); }
table.zp-table td { padding: 12px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
table.zp-table tbody tr:first-child td { border-top: none; }
table.zp-table tbody tr:hover td { background: var(--surface-2); }
table.zp-table tr.inactive td { opacity: .55; }
table.zp-table .num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- 6. Toolbar (the ONE filter bar) ---------- */
.zp-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.zp-toolbar .end { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.zp-search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; flex: 1 1 200px; max-width: 340px; }
.zp-search svg, .zp-search .ico { color: var(--text-faint); flex: none; }
.zp-search input { border: 0; background: none; outline: none; flex: 1; font: inherit; font-size: 13.5px; color: var(--text); min-width: 0; }
.zp-search input::placeholder { color: var(--text-faint); }
.zp-select { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; }
.zp-clear-filters { font-size: 12.5px; color: var(--primary); background: none; border: 0; cursor: pointer; font-weight: 600; padding: 6px 8px; }
@media (max-width: 700px) { .zp-toolbar .zp-select { flex: 1 1 45%; } .zp-search { max-width: none; } }

/* ---------- 7. Forms ---------- */
.zp-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.zp-field > label { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.zp-input, .zp-textarea, select.zp-input {
  font: inherit; font-size: 14px; color: var(--text); width: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; outline: none; box-sizing: border-box;
}
.zp-input:focus, .zp-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.zp-input:disabled { background: var(--surface-2); color: var(--text-faint); }
.zp-textarea { min-height: 84px; resize: vertical; }
.zp-field.error > label { color: var(--bad-fg); }
.zp-field.error .zp-input { border-color: var(--bad-fg); }
.zp-field .err-msg { font-size: 12px; color: var(--bad-fg); }

/* ---------- 8. Modal & confirm (used by platform-ui.js) ---------- */
.zp-overlay {
  position: fixed; inset: 0; background: rgba(20,25,50,.35); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.zp-modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 440px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
}
.zp-modal .mh { display: flex; align-items: center; gap: 10px; padding: 16px 20px 0; }
.zp-modal .mh h3 { margin: 0; font-size: 16px; font-weight: 700; }
.zp-modal .mb { padding: 10px 20px 16px; overflow-y: auto; font-size: 13.5px; color: var(--text-soft); }
.zp-modal .mf { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
.zp-modal .mf .left { margin-right: auto; }

/* ---------- 9. Toast (used by platform-ui.js) ---------- */
#zp-toast-host { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.zp-toast {
  background: #23293b; color: #fff; font-size: 13.5px; font-weight: 500;
  padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 14px; max-width: 92vw;
}
.zp-toast button { font: inherit; font-size: 13px; font-weight: 700; color: #ffb3b7; background: none; border: 0; cursor: pointer; padding: 0; }
@media (prefers-reduced-motion: no-preference) {
  .zp-toast { animation: zp-toast-in .18s ease-out; }
  @keyframes zp-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

/* ---------- 10. Sidebar nav pieces (shared shell) ---------- */
.zp-nav-group { font-size: 10.5px; font-weight: 700; letter-spacing: .09em; color: var(--text-faint); text-transform: uppercase; padding: 12px 10px 4px; }
.zp-nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: var(--radius-sm); border: 0; background: none;
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--text-soft);
  cursor: pointer; position: relative; text-decoration: none;
}
.zp-nav-item:hover { background: var(--surface-2); }
.zp-nav-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.zp-nav-item.on::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 3px; background: var(--accent); }
.zp-nav-item .bdg { margin-left: auto; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.zp-nav-item.soon { opacity: .45; cursor: default; }
.zp-nav-item.soon:hover { background: none; }

/* ---------- 11. Empty state ---------- */
.zp-empty { text-align: center; padding: 44px 24px; color: var(--text-soft); }
.zp-empty .t { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.zp-empty .s { font-size: 13px; color: var(--text-faint); margin-bottom: 14px; }
