/* ============================================================================
 * ui.css - the RiseLynk shared design-token + component layer.
 *
 * WHAT THIS IS
 *   One canonical, dependency-free stylesheet for the office console first, and
 *   reusable by the portal/field later. It carries two things:
 *     1) TOKENS  - named CSS custom properties for the green/dark palette, a
 *                  spacing scale, radii, a type scale, and elevation/shadow.
 *     2) COMPONENTS - opt-in, namespaced classes (rl-btn, rl-field, rl-table,
 *                  rl-modal, rl-badge ...) that match the office's current look
 *                  so a control can switch to them with zero visual change.
 *
 * HOW IT LOADS (same mechanism as the other shared files)
 *   The single-file apps already pull shared JS as classic, absolute-path tags:
 *     <script src="/apps/shared/format.js"></script>
 *   This file is the CSS parallel - link it in <head> BEFORE the app's own
 *   inline <style> so the inline rules win on equal specificity (last wins),
 *   and tokens are defined by the time anything paints:
 *     <link rel="stylesheet" href="/apps/shared/ui.css">
 *   No build step. Served as a file and precached by each service worker,
 *   exactly like demo-bar.js / format.js.
 *
 * WHY IT DOES NOT REGRESS THE OFFICE
 *   - The tokens below are defined with `var(--existing, fallback)`. Where the
 *     office already declares a palette var (--green, --card, --line, ...) the
 *     token simply ALIASES that exact value; where a surface has none, the
 *     fallback is the office's current hex. So this file never overrides a
 *     surface's palette - it reads it.
 *   - Every component class is namespaced `rl-`. There are NO bare element
 *     selectors (no `button {}`, no `table {}`), so nothing on the page changes
 *     until an element explicitly opts in by adding an `rl-` class.
 *
 * ADOPTION (incremental, never big-bang) - see the block at the bottom of the
 * office <style> for the step-by-step path.
 *
 * Office surface only: consistency, not animation. No transitions beyond the
 * cheap hover/focus the office already uses; no parallax, no scroll effects.
 * ========================================================================== */

/* ----------------------------------------------------------------------------
 * 1. TOKENS
 * Aliased to each surface's own vars when present, else the office defaults.
 * Adopt a token (var(--rl-...)) instead of a raw hex so a future theme change
 * is one edit here, not a hunt across 13k lines.
 * -------------------------------------------------------------------------- */
:root {
  /* -- palette: surfaces ------------------------------------------------- */
  --rl-bg:          var(--bg, #0f1412);
  --rl-card:        var(--card, #1a2420);
  --rl-card-2:      var(--card2, #21302a);
  --rl-surface-modal: #141d19;            /* the office modal/drawer panel bg */

  /* -- palette: lines / borders ---------------------------------------- */
  --rl-line:        var(--line, #2c3d35);
  /* WCAG 1.4.11: >=3:1 border on interactive controls (matches office). */
  --rl-line-strong: var(--line-strong, #7a8d82);

  /* -- palette: text --------------------------------------------------- */
  --rl-ink:         var(--ink, #e8efe9);
  --rl-dim:         var(--dim, #93a89d);
  --rl-faint:       var(--faint, #8a9d91);

  /* -- palette: brand green -------------------------------------------- */
  --rl-green:       var(--green, #5dcaa5);
  --rl-green-deep:  var(--green-deep, #085041);
  --rl-green-soft:  var(--green-soft, #9fe1cb);

  /* -- palette: accents (state colors the office already ships) -------- */
  --rl-rust:        var(--rust, #f0997b);
  --rl-rust-deep:   var(--rust-deep, #712b13);
  --rl-indigo:      var(--indigo, #afa9ec);
  --rl-indigo-deep: var(--indigo-deep, #3c3489);
  --rl-carry:       var(--carry, #eab308);
  --rl-carry-bg:    var(--carry-bg, #3a2f08);
  --rl-danger:      var(--danger, #f87171);
  --rl-safe:        var(--safe, #4ade80);

  /* -- spacing scale (px; the office's paddings cluster on these) ------- */
  --rl-space-0: 0;
  --rl-space-1: 2px;
  --rl-space-2: 4px;
  --rl-space-3: 6px;
  --rl-space-4: 8px;
  --rl-space-5: 10px;
  --rl-space-6: 12px;
  --rl-space-7: 14px;
  --rl-space-8: 16px;
  --rl-space-9: 18px;
  --rl-space-10: 20px;
  --rl-space-12: 26px;

  /* -- radii ----------------------------------------------------------- */
  --rl-radius-xs: 6px;
  --rl-radius-sm: 8px;
  --rl-radius-md: 10px;
  --rl-radius-lg: 12px;
  --rl-radius-xl: 14px;
  --rl-radius-pill: 999px;

  /* -- type scale (px) ------------------------------------------------- */
  --rl-text-2xs: 10px;
  --rl-text-xs:  11px;
  --rl-text-sm:  12px;
  --rl-text-md:  13px;
  --rl-text-base: 14px;     /* office body */
  --rl-text-lg:  16px;
  --rl-text-xl:  17px;
  --rl-font:     inherit;   /* inherit the surface's system font stack */

  /* -- elevation / shadow ---------------------------------------------- */
  --rl-shadow-sm: 0 1px 2px rgba(0, 0, 0, .25);
  --rl-shadow-md: 0 4px 14px rgba(0, 0, 0, .35);
  --rl-shadow-lg: 0 16px 48px rgba(0, 0, 0, .5);
  --rl-focus:     0 0 0 2px var(--rl-bg), 0 0 0 4px var(--rl-green);
}

/* ----------------------------------------------------------------------------
 * 2. COMPONENTS  (all namespaced `rl-`; opt-in only)
 * Each component mirrors the office's current pixels so adoption is seamless.
 * -------------------------------------------------------------------------- */

/* -- buttons ----------------------------------------------------------------
 * rl-btn                primary (green-deep fill, green-soft text)
 * rl-btn rl-btn--ghost  outlined / quiet (transparent, dim text)
 * rl-btn rl-btn--warn   destructive (rust)
 * rl-btn rl-btn--block  full-width (the office .btn default was block)
 * rl-btn rl-btn--sm     compact
 * States: hover, :focus-visible, :active, [disabled]/:disabled.
 * -------------------------------------------------------------------------- */
.rl-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--rl-space-3);
  border: 0; border-radius: var(--rl-radius-md);
  padding: var(--rl-space-6); /* 12px, matches .btn */
  font: 700 14.5px var(--rl-font); line-height: 1.1;
  cursor: pointer; text-align: center; white-space: nowrap;
  background: var(--rl-green-deep); color: var(--rl-green-soft);
}
.rl-btn:hover { filter: brightness(1.18); }                 /* office .btn:hover */
.rl-btn:active { filter: brightness(1.06); }
.rl-btn:focus-visible { outline: 2px solid var(--rl-green); outline-offset: 2px; }
.rl-btn[disabled], .rl-btn:disabled { opacity: .45; cursor: default; filter: none; }

.rl-btn--ghost {
  background: none; border: 1px solid var(--rl-line); color: var(--rl-dim);
  padding: var(--rl-space-4) var(--rl-space-6); font-size: var(--rl-text-md); font-weight: 600;
}
.rl-btn--ghost:hover { background: var(--rl-card-2); color: var(--rl-ink); filter: none; }

.rl-btn--warn { background: var(--rl-rust-deep); color: var(--rl-rust); }

.rl-btn--block { display: block; width: 100%; }
.rl-btn--sm { padding: var(--rl-space-3) var(--rl-space-5); font-size: var(--rl-text-md); }

/* -- fields: input / select / textarea --------------------------------------
 * Add `rl-field` to the control. Matches the office form look exactly:
 * card2 fill, line-strong border, radius 8, 9x10 padding, 14px.
 * -------------------------------------------------------------------------- */
.rl-field {
  width: 100%;
  background: var(--rl-card-2); border: 1px solid var(--rl-line-strong);
  color: var(--rl-ink); border-radius: var(--rl-radius-sm);
  padding: 9px var(--rl-space-5); font: var(--rl-text-base) var(--rl-font);
}
.rl-field::placeholder { color: var(--rl-faint); }
.rl-field:hover { border-color: var(--rl-green-soft); }
.rl-field:focus, .rl-field:focus-visible {
  outline: none; border-color: var(--rl-green);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--rl-green) 35%, transparent);
}
.rl-field:disabled { opacity: .5; cursor: not-allowed; }
textarea.rl-field { resize: vertical; min-height: 56px; }

/* the office's uppercase field label */
.rl-label {
  display: block; margin: var(--rl-space-6) 0 var(--rl-space-2);
  font-size: var(--rl-text-xs); font-weight: 700; color: var(--rl-faint);
  text-transform: uppercase; letter-spacing: .6px;
}

/* -- table ------------------------------------------------------------------
 * Add `rl-table` to the <table>. Mirrors `.tbl`: sticky uppercase faint head,
 * row hover. Use <tr class="rl-row"> for clickable rows; `.r` / `.right` on a
 * cell for right alignment.
 * -------------------------------------------------------------------------- */
.rl-table { width: 100%; border-collapse: collapse; }
.rl-table th {
  text-align: left; font-size: var(--rl-text-xs); text-transform: uppercase;
  letter-spacing: .7px; color: var(--rl-faint);
  padding: 7px var(--rl-space-5); border-bottom: 1px solid var(--rl-line);
  position: sticky; top: -14px; background: var(--rl-bg);
}
.rl-table td {
  padding: var(--rl-space-4) var(--rl-space-5);
  border-bottom: 1px solid var(--rl-line); font-size: var(--rl-text-md);
}
.rl-table td.r, .rl-table th.r { text-align: right; }
.rl-table tr.rl-row { cursor: pointer; }
.rl-table tr.rl-row:hover td { background: var(--rl-card); }

/* -- badge / chip (status pill, non-interactive) ----------------------------
 * Add `rl-badge` + a tone modifier. Mirrors `.chip`.
 * -------------------------------------------------------------------------- */
.rl-badge {
  display: inline-flex; align-items: center; gap: var(--rl-space-2);
  font-size: 10.5px; font-weight: 700; padding: var(--rl-space-1) 7px;
  border-radius: var(--rl-radius-xs); white-space: nowrap;
  background: var(--rl-card-2); color: var(--rl-dim);
}
.rl-badge--green  { background: var(--rl-green-deep); color: var(--rl-green-soft); }
.rl-badge--rust   { background: var(--rl-rust-deep);  color: var(--rl-rust); }
.rl-badge--carry  { background: var(--rl-carry-bg);   color: var(--rl-carry); }
.rl-badge--indigo { background: var(--rl-indigo-deep); color: var(--rl-indigo); }
.rl-badge--neutral{ background: var(--rl-card-2); color: var(--rl-dim);
                    border: 1px solid var(--rl-line); }

/* -- pill (interactive filter/toggle) ---------------------------------------
 * Mirrors `.pill`. Add `is-active` for the selected state.
 * -------------------------------------------------------------------------- */
.rl-pill {
  display: inline-flex; align-items: center; gap: var(--rl-space-3);
  font-size: var(--rl-text-sm); font-weight: 600;
  padding: var(--rl-space-2) var(--rl-space-6); border-radius: var(--rl-radius-pill);
  border: 1px solid var(--rl-line); color: var(--rl-dim);
  background: none; font-family: var(--rl-font); cursor: pointer;
}
.rl-pill:hover { border-color: var(--rl-green); color: var(--rl-ink); }
.rl-pill:focus-visible { outline: 2px solid var(--rl-green); outline-offset: 2px; }
.rl-pill.is-active {
  background: var(--rl-green-deep); border-color: var(--rl-green-deep);
  color: var(--rl-green-soft);
}

/* -- card -------------------------------------------------------------------
 * Mirrors `.card`. `rl-card--tap` for a clickable card.
 * -------------------------------------------------------------------------- */
.rl-card {
  background: var(--rl-card); border: 1px solid var(--rl-line);
  border-radius: var(--rl-radius-lg); padding: var(--rl-space-6) var(--rl-space-7);
}
.rl-card--tap { cursor: pointer; }
.rl-card--tap:hover { background: var(--rl-card-2); }

/* -- modal / dialog ---------------------------------------------------------
 * Mirrors the office `#modal` + `.box`. Markup pattern:
 *   <div class="rl-modal is-open">
 *     <div class="rl-modal__box"> ... </div>
 *   </div>
 * The office toggles `#modal.show` via display; `rl-modal` uses `.is-open` so
 * it can coexist without colliding with the existing id rule.
 * -------------------------------------------------------------------------- */
.rl-modal {
  position: fixed; inset: 0; z-index: 1300; display: none;
  align-items: flex-start; justify-content: center;
  background: rgba(0, 0, 0, .55); overflow-y: auto; padding: 5vh var(--rl-space-8);
}
.rl-modal.is-open { display: flex; }
.rl-modal__box {
  background: var(--rl-surface-modal); border: 1px solid var(--rl-line);
  border-radius: var(--rl-radius-xl); box-shadow: var(--rl-shadow-lg);
  width: 560px; max-width: 100%; padding: var(--rl-space-9) var(--rl-space-10) var(--rl-space-10);
}
.rl-modal__box h3 { font-size: var(--rl-text-lg); margin-bottom: var(--rl-space-2); }
.rl-modal__x {
  float: right; background: var(--rl-card-2); border: 1px solid var(--rl-line);
  color: var(--rl-dim); border-radius: var(--rl-radius-sm);
  width: 30px; height: 30px; cursor: pointer; font-size: var(--rl-text-base);
}
.rl-modal__x:hover { color: var(--rl-ink); }

/* ----------------------------------------------------------------------------
 * 3. REDUCED MOTION
 * The office already settles all motion globally; this is a belt-and-braces
 * branch so the shared layer is safe on a surface that has not added one.
 * -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .rl-btn, .rl-field, .rl-pill, .rl-card--tap, .rl-modal__x {
    transition: none !important;
  }
}

/* ----------------------------------------------------------------------------
 * .rl-ico - inline-SVG icon wrapper for apps/shared/icons.js. Sizes the glyph
 * relative to the surrounding text and inherits color via currentColor, so an
 * icon() call drops into any label/button/chip and matches its text. Apps that
 * do not link this file inline the same three rules.
 * -------------------------------------------------------------------------- */
.rl-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.18em;
  flex: none;
}
.rl-ico svg { width: 100%; height: 100%; display: block; }
