/* ============================================================================
   TradeWorth — style.css : the logged-in app shell (public/app/*, public/admin/*)

   Brand colour, type and the shared .btn/.brand-* primitives live in brand.css.
   This file only carries what is specific to a dense, data-heavy workspace:
   tighter type scale, tighter button geometry, the navy top bar, tables.
   Selectors are load-bearing — 21 pages target these exact class names, so
   nothing here may be renamed, only re-skinned.
   ==========================================================================*/
@import url('/brand.css');

:root {
  /* App-only measurements. Derived from brand tokens where one exists; the
     rest are geometry the marketing site has no opinion about. */
  --nav-h:     56px;
  --app-h1:    24px;    /* Oswald caps: reads like the old 22px Inter h1 */
  --app-lh:    1.5;     /* denser than --lh-body (1.6): tables and forms */
  --wrap-w:    1080px;
  /* Chrome that only exists on the navy bar. Alpha-on-white keeps these in
     step with whatever --navy resolves to. */
  --nav-hover: rgba(255,255,255,.10);
  --nav-idle:  rgba(255,255,255,.82);
  --nav-line:  rgba(255,255,255,.35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: var(--app-lh);
}

/* ---------- top nav ---------- */
/* The bar is a dark surface, so it acts as an .on-dark context even when the
   markup that renders it (app.js renderNav / admin/nav.js) forgets the class. */
.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--navy);
  border-bottom: 1px solid var(--navy-700);
  padding: 0 var(--sp-5);
  height: var(--nav-h);
  position: sticky;
  top: 0;
  z-index: 10;
}
/* Works for both the lockup markup (mark + .brand-word) and the older plain
   text brand, which is why the type properties are set on .brand itself. */
.nav .brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-right: var(--sp-5);
  padding: 0;
  background: none;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 21px;
  text-transform: uppercase;
  letter-spacing: -.02em;
  line-height: 1;
  color: var(--white);
  text-decoration: none;
  white-space: nowrap;
}
.nav .brand:hover { background: none; }
.nav .brand-mark { width: 28px; height: 28px; }
.nav .brand-word { color: var(--white); font-size: inherit; }
.nav .brand .worth, .nav .brand .rig { color: var(--orange); }
/* admin/*.html mark the console with a small "internal" tag in --grey-500,
   which is a light-background value and near-invisible on navy. */
.nav .brand span.int { color: var(--steel-400); }

.nav a {
  color: var(--nav-idle);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.nav a:hover { background: var(--nav-hover); color: var(--white); }
/* Top-level items only (dropdown children stay in Inter, see .navmenu a). */
.nav > a, .nav .navtrigger {
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.nav a.active {
  color: var(--orange);
  background: var(--nav-hover);
  box-shadow: inset 0 -2px 0 var(--orange);
}
/* Keyboard focus has to survive on navy, where the orange halo is too faint. */
.nav a:focus-visible, .nav .navtrigger:focus-visible, .nav button:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: -2px;
  box-shadow: none;
}

/* Grouped dropdown navigation */
.nav .navgroup { position: relative; }
.nav .navtrigger {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--nav-idle); background: none; border: none; cursor: pointer;
  padding: 8px 14px; border-radius: var(--radius-sm); line-height: 1.4;
}
.nav .navtrigger:hover { background: var(--nav-hover); color: var(--white); }
.nav .navtrigger.active {
  color: var(--orange);
  background: var(--nav-hover);
  box-shadow: inset 0 -2px 0 var(--orange);
}
.nav .navtrigger .caret { font-size: 10px; opacity: .7; }
/* The panel itself is a light surface hanging off the dark bar. */
.nav .navmenu {
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 180px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; display: none; flex-direction: column; gap: 2px; z-index: 20;
}
.nav .navgroup:hover .navmenu, .nav .navgroup:focus-within .navmenu { display: flex; }
.nav .navmenu a {
  padding: 8px 12px; border-radius: 7px; white-space: nowrap;
  font-family: var(--font-body); font-size: var(--fs-sm); text-transform: none; letter-spacing: 0;
  color: var(--text);
}
.nav .navmenu a:hover { background: var(--light); color: var(--text); }
/* Small text on a light panel: ink orange, never --orange (2.9:1). */
.nav .navmenu a.active {
  color: var(--orange-ink); background: var(--orange-soft);
  box-shadow: inset 3px 0 0 var(--orange);
}

.nav .spacer { flex: 1; }
.nav .who { color: var(--text-muted-dark); font-size: var(--fs-sm); margin-right: var(--sp-3); }
/* .btn-ghost is authored for light surfaces — on the bar it needs dark-mode ink. */
.nav .btn-ghost { color: var(--white); background: transparent; border-color: var(--nav-line); }
.nav .btn-ghost:hover { background: var(--nav-hover); color: var(--white); }

/* ---------- layout ---------- */
.wrap { max-width: var(--wrap-w); margin: var(--sp-5) auto; padding: 0 var(--sp-5); }
h1 { font-size: var(--app-h1); margin: 0 0 var(--sp-1); }
.sub { color: var(--text-muted); margin: 0 0 var(--sp-5); }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card .label {
  color: var(--text-muted); font-size: var(--fs-xs); text-transform: uppercase;
  letter-spacing: var(--ls-wide); font-weight: 600;
}
.card .value {
  font-family: var(--font-heading); font-size: 30px; font-weight: 700;
  margin-top: 6px; letter-spacing: var(--ls-tight); line-height: var(--lh-tight);
  color: var(--navy);
}
/* Orange is the loudest thing on the page — it belongs to ONE metric per view,
   which is why it is an opt-in modifier. 30px bold clears the display-type bar
   for using --orange rather than --orange-ink. */
.card .value.accent { color: var(--orange); }

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: var(--sp-4);
  /* overflow:hidden is what clips a table's square corners inside the rounded
     panel, but on its own it silently AMPUTATES wide tables: admin/tenants is
     12 columns / ~1300px inside a ~1030px panel, so Health and Onboarding were
     unreachable. Keep the y-axis clipped, let the x-axis scroll. */
  overflow-x: auto;
  overflow-y: hidden;
}
.panel h2 {
  font-size: var(--fs-base); margin: 0; padding: 14px 18px;
  border-bottom: 1px solid var(--border); color: var(--navy); letter-spacing: .02em;
}

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 18px; border-bottom: 1px solid var(--border); }
th {
  font-family: var(--font-heading); font-weight: 500; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--navy); background: var(--surface-alt);
  border-bottom: 1px solid var(--border-strong);
}
td { color: var(--text); }
tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--light-100); }
tbody tr:hover { background: var(--light); cursor: default; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- badges ---------- */
/* Status must never read as brand accent: an orange badge and an orange CTA
   would be the same signal. Job/invoice states map to the status ramp only. */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .01em;
}
.badge.grey { background: var(--light); color: var(--steel-600); }
/* STATUS_BADGE maps in_progress -> .orange. Amber (--warn), not Trade Orange. */
.badge.orange { background: var(--warn-bg); color: var(--warn-ink); }
.badge.green { background: var(--success-bg); color: var(--success-ink); }
.badge.blue { background: var(--info-bg); color: var(--info-ink); }
.badge.red { background: var(--danger-bg); color: var(--danger-ink); }

/* ---------- buttons ---------- */
/* brand.css sizes .btn for marketing CTAs; the app needs a compact control.
   The bare `button` selector is here because several pages ship unclassed
   buttons that still have to look like the system. */
button, .btn {
  font-family: var(--font-heading); font-weight: 500; font-size: var(--fs-sm);
  text-transform: uppercase; letter-spacing: .04em; line-height: 1.3;
  cursor: pointer; border-radius: var(--radius-sm);
  padding: 9px 16px; border: 1px solid transparent;
}
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); box-shadow: none; }
.btn-primary:hover { background: var(--accent-hover); }
/* Pages use .btn-ghost as the standard secondary action, so it carries
   .btn-secondary semantics (navy outline) rather than brand.css's chromeless one. */
.btn-ghost { background: var(--surface); color: var(--navy); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--light); color: var(--navy); border-color: var(--steel); }
.btn-sm { padding: 5px 11px; font-size: var(--fs-xs); }
.btn-lg { padding: 12px 22px; font-size: var(--fs-base); }
.btn-danger { background: var(--surface); color: var(--danger-ink); border-color: var(--danger-border); }
.btn-danger:hover { background: var(--danger-bg); color: var(--danger-ink); }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: var(--fs-sm); margin-bottom: var(--sp-1); color: var(--navy); }
input, select, textarea {
  width: 100%; font-family: var(--font-body); font-size: var(--fs-base); padding: 9px 11px;
  color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
input::placeholder, textarea::placeholder { color: var(--steel-400); }
/* Focus has to be unmistakable — the orange halo plus a colour-shifted border
   so it does not rely on hue alone. */
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--orange); box-shadow: var(--focus-ring);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-3); padding: var(--sp-4) 18px; }
.form-actions { padding: 0 18px var(--sp-4); }

/* ---------- two column ---------- */
.split { display: grid; grid-template-columns: 1fr 1.3fr; gap: var(--sp-4); align-items: start; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; } }

/* ---------- pipeline board ---------- */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
@media (max-width: 820px) { .board { grid-template-columns: 1fr; } }
.col { background: var(--surface-alt); border-radius: var(--radius); padding: var(--sp-3); }
.col h3 {
  margin: 0 0 10px; font-size: var(--fs-sm); letter-spacing: .06em;
  color: var(--navy); display: flex; justify-content: space-between;
}
.col h3 .count { color: var(--text-muted); }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-3); margin-bottom: 10px; }
.pcard .t { font-weight: 700; color: var(--text); }
.pcard .c { color: var(--text-muted); font-size: var(--fs-sm); margin: 2px 0 var(--sp-2); }
.pcard .row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- misc ---------- */
.muted { color: var(--text-muted); }
.empty { padding: 26px 18px; text-align: center; color: var(--text-muted); }
.right { text-align: right; }
.mt { margin-top: var(--sp-4); }
.hidden { display: none !important; }
.list-item { padding: var(--sp-3) 18px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-item:hover { background: var(--light-100); }
.list-item.sel { background: var(--orange-soft); box-shadow: inset 3px 0 0 var(--orange); }
.list-item .n { font-weight: 700; color: var(--text); }
.list-item .m { color: var(--text-muted); font-size: var(--fs-sm); }
.flash {
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: var(--sp-3); font-weight: 600;
  background: var(--success-bg); color: var(--success-ink);
}
.flash.err { background: var(--danger-bg); color: var(--danger-ink); }

/* ---------- phone layout ---------- */
/* app.js/admin/nav.js build the bar as ONE non-wrapping flex row. For an owner
   that row is ~990px, so at 360px it dragged the whole DOCUMENT into horizontal
   scroll on every app page — worst on tech.html, which is the phone-first field
   view. Wrap rather than scroll the bar: the .navmenu dropdowns are absolutely
   positioned children, so giving .nav an overflow would clip them shut. */
@media (max-width: 900px) {
  .nav {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--nav-h);
    padding: var(--sp-2) var(--sp-3);
    row-gap: var(--sp-2);
    /* A wrapped owner nav is ~200px tall — fine as a banner you scroll past,
       not as a sticky band eating a quarter of a phone screen. */
    position: static;
  }
  .nav .brand { margin-right: var(--sp-3); }
  /* The spacer exists to push identity + logout to the far right on desktop;
     once the bar wraps it would strand them on a line of their own. */
  .nav .spacer { display: none; }
  .nav .who { margin-left: auto; }
  .nav a, .nav .navtrigger { padding: 8px 10px; }
  /* A dropdown opened near the right edge would otherwise overflow the screen. */
  .nav .navmenu { left: auto; right: 0; max-width: calc(100vw - var(--sp-5)); }
}
