/* WerkSys brand styles — derived from ModWerks + Cubic Fans brand language.

   Light mode (default) is for legibility-first daily ERP use.
   Dark mode (data-theme="dark") matches the ModWerks website aesthetic
   (#0a0f1a navy + brand-blue accents). Toggle in the top nav; persisted
   via localStorage and applied pre-paint via inline script in base.html.

   Color tokens come from ModWerks_Brand_Identity.md:
   - ModWerks Blue (primary):   #0064A9
   - Deep Blue (secondary):     #0D6CAD
*/

:root {
  /* Brand palette (stable across themes) */
  --mw-blue:        #0064A9;
  --mw-deep:        #0D6CAD;
  --mw-blue-bright: #2E8FE8;       /* used for accents in dark mode */
  --mw-tint:        #E1EDF5;
  --mw-tint-2:      #C7DFEC;
  --mw-blue-glow:   rgba(0, 100, 169, 0.15);
  --mw-blue-glow-2: rgba(0, 100, 169, 0.30);

  /* HG palette (steel) */
  --hg-steel:       #475569;
  --hg-steel-deep:  #334155;
  --hg-tint:        #E2E8F0;
  --hg-glow:        rgba(71, 85, 105, 0.15);

  /* Neutrals — LIGHT theme defaults (overridden in [data-theme="dark"]) */
  --ink:            #0F172A;
  --ink-2:          #1E293B;
  --muted:          #64748B;
  --muted-2:        #94A3B8;
  --line:           #E2E8F0;
  --line-soft:      #F1F5F9;
  --paper:          #FFFFFF;
  --paper-tinted:   #F8FAFC;
  --card-bg:        #FFFFFF;
  --card-border:    #E2E8F0;
  --header-tint-mw: linear-gradient(180deg, var(--mw-tint) 0%, var(--paper) 100%);
  --header-tint-hg: linear-gradient(180deg, var(--hg-tint) 0%, var(--paper) 100%);
  --table-header-bg: var(--mw-tint);
  --table-header-fg: var(--mw-deep);
  --table-row-hover: var(--paper-tinted);

  /* Status colors */
  --ok:             #16A34A;
  --warn:           #D97706;
  --bad:            #DC2626;

  /* Fonts */
  --font-display: 'Rajdhani', 'Barlow Condensed', system-ui, sans-serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Menlo', monospace;
}

/* ─── Dark theme tokens (active when html[data-theme="dark"]) ───────────── */
html[data-theme="dark"] {
  --ink:            #E2E8F0;
  --ink-2:          #CBD5E1;
  --muted:          #94A3B8;
  --muted-2:        #64748B;
  --line:           rgba(255, 255, 255, 0.07);
  --line-soft:      rgba(255, 255, 255, 0.04);
  --paper:          #0F1822;
  --paper-tinted:   #0a0f1a;          /* matches ModWerks website mw-dark */
  --card-bg:        #111827;          /* mw-dark-card */
  --card-border:    rgba(255, 255, 255, 0.07);
  --header-tint-mw: linear-gradient(180deg, rgba(0, 100, 169, 0.18) 0%, var(--card-bg) 100%);
  --header-tint-hg: linear-gradient(180deg, rgba(71, 85, 105, 0.22) 0%, var(--card-bg) 100%);
  --table-header-bg: rgba(0, 100, 169, 0.18);
  --table-header-fg: var(--mw-blue-bright);
  --table-row-hover: rgba(255, 255, 255, 0.03);
  --mw-tint:        rgba(0, 100, 169, 0.18);
  --mw-tint-2:      rgba(0, 100, 169, 0.32);
  --hg-tint:        rgba(71, 85, 105, 0.22);
}

html, body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper-tinted);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.15s ease, color 0.15s ease;
}

::selection {
  background: var(--mw-blue);
  color: white;
}

/* ─── Typography ─── */
h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

h1 { font-size: 2rem; line-height: 1.1; }
h2 { font-size: 1.5rem; line-height: 1.15; }
h3 { font-size: 1.125rem; line-height: 1.2; }

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* Section tag pattern from ModWerks website (small uppercase + leading dash) */
.section-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mw-blue);
  margin-bottom: 0.75rem;
}
.section-tag::before {
  content: "";
  display: inline-block;
  width: 20px;
  height: 2px;
  background: var(--mw-blue);
}
.section-tag.hg { color: var(--hg-steel); }
.section-tag.hg::before { background: var(--hg-steel); }

/* ─── App chrome ─── */
.app-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--line);
}
.app-header.tenant-mw {
  border-top: 3px solid var(--mw-blue);
  background: var(--header-tint-mw);
}
.app-header.tenant-hg {
  border-top: 3px solid var(--hg-steel);
  background: var(--header-tint-hg);
}
.app-title { color: var(--ink); }
html[data-theme="dark"] .app-title { color: var(--ink); }

.app-title {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.app-subtitle {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

/* Module nav row */
.app-nav-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
}
.app-nav-row a {
  padding: 0.3rem 0.7rem;
  border-radius: 0.375rem;
  color: var(--ink-2);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.app-nav-row a:hover {
  background: var(--mw-tint);
  color: var(--mw-blue);
}
.tenant-hg .app-nav-row a:hover {
  background: var(--hg-tint);
  color: var(--hg-steel-deep);
}

/* Grouped-nav dropdowns (P3) */
.nav-group { position: relative; display: inline-block; }
.nav-group-trigger {
  background: none;
  border: 0;
  padding: 0.3rem 0.7rem;
  border-radius: 0.375rem;
  color: var(--ink-2);
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-group-trigger:hover,
.nav-group:hover .nav-group-trigger,
.nav-group:focus-within .nav-group-trigger {
  background: var(--mw-tint);
  color: var(--mw-blue);
}
.tenant-hg .nav-group-trigger:hover,
.tenant-hg .nav-group:hover .nav-group-trigger,
.tenant-hg .nav-group:focus-within .nav-group-trigger {
  background: var(--hg-tint);
  color: var(--hg-steel-deep);
}
.nav-group-menu {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 12rem;
  display: none;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 0.5rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  padding: 0.25rem;
  z-index: 60;
}
.nav-group:hover .nav-group-menu,
.nav-group:focus-within .nav-group-menu {
  display: flex;
}
.nav-group-menu a {
  padding: 0.4rem 0.7rem;
  border-radius: 0.375rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ─── Mobile nav (FE review #8) ───
   Below lg (1024px) the grouped nav row collapses behind the ☰ hamburger
   in base.html; everything here is media-scoped so desktop is untouched. */
.app-nav-toggle { display: none; }
@media (max-width: 1023.98px) {
  .app-nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 0.375rem;
    padding: 0.45rem 0.8rem;
    color: var(--ink-2);
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
  }
  .app-nav-row { display: none; }
  .app-nav-row.is-open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .app-nav-row.is-open a { padding: 0.55rem 0.7rem; }
  .app-nav-row.is-open .nav-group { display: block; }
  .app-nav-row.is-open .nav-group-trigger {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.7rem;
  }
  /* Group menus render expanded inline (no hover on touch). */
  .app-nav-row.is-open .nav-group-menu {
    position: static;
    display: flex;
    min-width: 0;
    border: 0;
    box-shadow: none;
    padding: 0 0 0 1rem;
  }
  .app-nav-row.is-open form { margin-left: 0; }
}

/* ─── Cards ─── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 0.5rem;
  padding: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.card:hover {
  border-color: var(--mw-tint-2);
  box-shadow: 0 4px 16px var(--mw-blue-glow);
}
.card-header {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

/* ─── Pills ─── */
.pill {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
}
.pill-brand    { background: var(--mw-tint);  color: var(--mw-deep); }
.pill-brand-hg { background: var(--hg-tint);  color: var(--hg-steel-deep); }
.pill-muted    { background: #F1F5F9; color: var(--ink-2); }
.pill-ok       { background: #DCFCE7; color: #166534; }
.pill-warn     { background: #FEF3C7; color: #92400E; }
.pill-bad      { background: #FEE2E2; color: #991B1B; }
.pill-info     { background: #DBEAFE; color: #1E40AF; }

/* Dark mode pill variants — same semantics, readable on dark surfaces */
html[data-theme="dark"] .pill-brand    { background: rgba(0, 100, 169, 0.25); color: var(--mw-blue-bright); }
html[data-theme="dark"] .pill-brand-hg { background: rgba(71, 85, 105, 0.30); color: #CBD5E1; }
html[data-theme="dark"] .pill-muted    { background: rgba(255, 255, 255, 0.08); color: var(--ink-2); border: 1px solid rgba(255, 255, 255, 0.05); }
html[data-theme="dark"] .pill-ok       { background: rgba(16, 163, 74, 0.20); color: #6EE7B7; }
html[data-theme="dark"] .pill-warn     { background: rgba(245, 158, 11, 0.20); color: #FBBF24; }
html[data-theme="dark"] .pill-bad      { background: rgba(239, 68, 68, 0.20); color: #FCA5A5; }
html[data-theme="dark"] .pill-info     { background: rgba(37, 99, 235, 0.22); color: #93C5FD; }

/* Tailwind-styled chip filter buttons (e.g. on shipment / bid / quote / project /
   PO / inventory list pages). Templates use `pill bg-white border text-gray-700`
   for unselected and `pill bg-blue-600 text-white` for selected. Default
   `border` color is invisible on dark surfaces — force visible variants. */
html[data-theme="dark"] a.pill.bg-white,
html[data-theme="dark"] a.pill.border {
  background-color: rgba(255, 255, 255, 0.06) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: var(--ink-2) !important;
}
html[data-theme="dark"] a.pill.bg-white:hover,
html[data-theme="dark"] a.pill.border:hover {
  background-color: rgba(255, 255, 255, 0.10) !important;
  color: var(--mw-blue-bright) !important;
}
html[data-theme="dark"] a.pill.bg-blue-600 {
  background-color: var(--mw-blue-bright) !important;
  color: #FFFFFF !important;
  border: 1px solid var(--mw-blue-bright) !important;
}

/* ─── Tables ─── */
table.app-table {
  width: 100%;
  font-size: 0.875rem;
  border-collapse: collapse;
}
table.app-table thead th {
  background: var(--table-header-bg);
  color: var(--table-header-fg);
  text-align: left;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--mw-tint-2);
}
.tenant-hg table.app-table thead th {
  background: var(--hg-tint);
  color: var(--hg-steel-deep);
  border-bottom-color: var(--card-border);
}
html[data-theme="dark"] .tenant-hg table.app-table thead th {
  color: #CBD5E1;
}
table.app-table tbody tr {
  border-top: 1px solid var(--line-soft);
  transition: background 0.1s;
}
table.app-table tbody tr:hover {
  background: var(--table-row-hover);
}
table.app-table td {
  color: var(--ink);
}
table.app-table td {
  padding: 0.6rem 0.75rem;
  vertical-align: top;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: 0.4rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}
.btn:hover { transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--mw-blue), var(--mw-deep));
  color: white;
  box-shadow: 0 2px 8px var(--mw-blue-glow);
}
.btn-primary:hover {
  box-shadow: 0 4px 16px var(--mw-blue-glow-2);
}
.tenant-hg .btn-primary {
  background: linear-gradient(135deg, var(--hg-steel), var(--hg-steel-deep));
  box-shadow: 0 2px 8px var(--hg-glow);
}

.btn-outline {
  background: var(--paper);
  color: var(--mw-blue);
  border-color: var(--mw-blue);
}
.btn-outline:hover { background: var(--mw-tint); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--mw-blue); background: var(--mw-tint); }

.btn-warn { background: var(--warn); color: white; }
.btn-bad  { background: var(--bad);  color: white; }
.btn-ok   { background: var(--ok);   color: white; }

/*
 * Button hierarchy (P9 — UIUX review 2026-05-12):
 *   .btn .btn-primary       — 1 per page; THE main action (filled MW blue)
 *   .btn .btn-positive      — definitive / forward (Approve, Mark won, Advance)
 *   .btn .btn-destructive   — irreversible (Delete, Mark lost, Reject)
 *   .btn .btn-outline       — secondary action (View PDF, Cancel)
 *   .btn .btn-ghost         — tertiary / text-button (clear filter, expand)
 */
.btn-positive    { background: var(--ok);  color: white; border-color: var(--ok); }
.btn-destructive { background: var(--bad); color: white; border-color: var(--bad); }

/* ─── Forms ─── */
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="url"], input[type="date"], input[type="file"], input[type="search"], select, textarea {
  font-family: var(--font-body);
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  background: var(--card-bg);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--mw-blue);
  box-shadow: 0 0 0 3px var(--mw-blue-glow);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: var(--muted-2); }

/* ─── Footer ─── */
.app-footer {
  border-top: 1px solid var(--line);
  color: var(--muted-2);
  font-size: 0.75rem;
  margin-top: 3rem;
}

/* ─── Theme toggle button (in nav) ─── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border-radius: 0.375rem;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--ink-2);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  background: var(--mw-tint);
  border-color: var(--mw-blue);
  color: var(--mw-blue);
}
html[data-theme="dark"] .theme-toggle:hover {
  color: var(--mw-blue-bright);
}

/* ─── Tailwind utility class overrides for dark mode ─────────────────────
   Existing templates use Tailwind utilities like bg-white, text-gray-700,
   border-gray-200. Rewriting them all would be churn; instead override the
   handful that conflict with dark mode.
   ──────────────────────────────────────────────────────────────────────── */
html[data-theme="dark"] .bg-white { background-color: var(--card-bg) !important; }
html[data-theme="dark"] .bg-gray-50  { background-color: var(--paper-tinted) !important; }
html[data-theme="dark"] .bg-gray-100 { background-color: rgba(255,255,255,0.04) !important; }
html[data-theme="dark"] .bg-gray-200 { background-color: rgba(255,255,255,0.08) !important; }
html[data-theme="dark"] .bg-blue-50  { background-color: rgba(37, 99, 235, 0.15) !important; }
html[data-theme="dark"] .bg-emerald-50 { background-color: rgba(16, 163, 74, 0.12) !important; }
html[data-theme="dark"] .bg-amber-50 { background-color: rgba(245, 158, 11, 0.12) !important; }
html[data-theme="dark"] .bg-red-50   { background-color: rgba(239, 68, 68, 0.12) !important; }
html[data-theme="dark"] .bg-purple-50 { background-color: rgba(168, 85, 247, 0.12) !important; }
html[data-theme="dark"] .bg-indigo-50 { background-color: rgba(99, 102, 241, 0.12) !important; }
html[data-theme="dark"] .bg-cyan-50  { background-color: rgba(6, 182, 212, 0.12) !important; }

html[data-theme="dark"] .text-gray-900 { color: var(--ink) !important; }
html[data-theme="dark"] .text-gray-800 { color: var(--ink) !important; }
html[data-theme="dark"] .text-gray-700 { color: var(--ink-2) !important; }
html[data-theme="dark"] .text-gray-600 { color: var(--muted) !important; }
html[data-theme="dark"] .text-gray-500 { color: var(--muted) !important; }
html[data-theme="dark"] .text-gray-400 { color: var(--muted-2) !important; }
html[data-theme="dark"] .text-gray-300 { color: var(--muted-2) !important; }

html[data-theme="dark"] .border, html[data-theme="dark"] .border-t,
html[data-theme="dark"] .border-b, html[data-theme="dark"] .border-l,
html[data-theme="dark"] .border-r {
  border-color: var(--card-border) !important;
}
html[data-theme="dark"] .border-gray-100,
html[data-theme="dark"] .border-gray-200,
html[data-theme="dark"] .border-gray-300 { border-color: var(--card-border) !important; }
html[data-theme="dark"] .border-blue-200 { border-color: rgba(37, 99, 235, 0.4) !important; }
html[data-theme="dark"] .border-emerald-200 { border-color: rgba(16, 163, 74, 0.4) !important; }
html[data-theme="dark"] .border-amber-200 { border-color: rgba(245, 158, 11, 0.4) !important; }

/* Pastel pill backgrounds: keep readable on dark */
html[data-theme="dark"] .bg-emerald-100 { background-color: rgba(16, 163, 74, 0.20) !important; }
html[data-theme="dark"] .bg-emerald-200 { background-color: rgba(16, 163, 74, 0.30) !important; }
html[data-theme="dark"] .bg-blue-100 { background-color: rgba(37, 99, 235, 0.22) !important; }
html[data-theme="dark"] .bg-amber-100 { background-color: rgba(245, 158, 11, 0.20) !important; }
html[data-theme="dark"] .bg-amber-200 { background-color: rgba(245, 158, 11, 0.30) !important; }
html[data-theme="dark"] .bg-red-100 { background-color: rgba(239, 68, 68, 0.20) !important; }
html[data-theme="dark"] .bg-purple-100 { background-color: rgba(168, 85, 247, 0.22) !important; }
html[data-theme="dark"] .bg-cyan-100 { background-color: rgba(6, 182, 212, 0.22) !important; }
html[data-theme="dark"] .bg-indigo-100 { background-color: rgba(99, 102, 241, 0.22) !important; }

html[data-theme="dark"] .text-emerald-800 { color: #6EE7B7 !important; }
html[data-theme="dark"] .text-emerald-900 { color: #A7F3D0 !important; }
html[data-theme="dark"] .text-blue-800   { color: #93C5FD !important; }
html[data-theme="dark"] .text-amber-800  { color: #FDE68A !important; }
html[data-theme="dark"] .text-amber-900  { color: #FEF3C7 !important; }
html[data-theme="dark"] .text-red-800    { color: #FCA5A5 !important; }
html[data-theme="dark"] .text-purple-800 { color: #DDD6FE !important; }
html[data-theme="dark"] .text-cyan-800   { color: #A5F3FC !important; }
html[data-theme="dark"] .text-indigo-800 { color: #C7D2FE !important; }
html[data-theme="dark"] .text-blue-700   { color: var(--mw-blue-bright) !important; }
html[data-theme="dark"] .text-amber-700  { color: #FBBF24 !important; }

html[data-theme="dark"] code, html[data-theme="dark"] pre {
  background-color: rgba(255,255,255,0.05);
  color: var(--ink-2);
  padding: 0 4px;
  border-radius: 3px;
}

/* GH #71 home attention cards — left-border = urgency (the ONLY place color
   means urgency; see mockup doc 19). Builders emit attn-* class names. */
.attn-card { border-left-width: 3px; }
.attn-approvals { border-left-color: #8b5cf6; }
.attn-ar       { border-left-color: #ef4444; }
.attn-bids     { border-left-color: #f59e0b; }
.attn-unread   { border-left-color: #38bdf8; }

/* GH #71 — single-underline active nav tab (mockup doc 19). */
#app-nav a.nav-active { color: var(--ink); border-bottom: 2px solid #60a5fa; padding-bottom: 2px; }

/* ════════════════════════════════════════════════════════════════════════
   Mobile layout overhaul (GH #77 — phone-emulation audit 2026-06-11).
   Strategy: tables scroll horizontally INSIDE the page instead of crushing;
   money/identifiers never wrap mid-value; header stacks; touch targets meet
   the ~44px floor on coarse pointers. Desktop (≥1024px) is untouched.
   ════════════════════════════════════════════════════════════════════════ */

/* Identifiers + money never break mid-value (all widths). */
a.font-mono, td .font-mono, .mono { white-space: nowrap; }

@media (max-width: 1023.98px) {
  /* Header: allow the brand/nav row to stack; hide the subtitle line;
     per-page nav links scroll sideways instead of wrapping into a jumble. */
  .app-header { padding-left: 1rem; padding-right: 1rem; }
  .app-header-row { flex-wrap: wrap; row-gap: 0.5rem; }
  .app-subtitle { display: none; }
  .app-header-nav {
    flex-basis: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding-bottom: 2px;          /* keep descenders out of the scrollbar */
    scrollbar-width: thin;
  }
  /* The nav row already scrolls, so its links must keep natural width —
     the global .flex > * min-width:0 guard would shrink them into each
     other (nowrap text paints over the neighbor). */
  .app-header-nav > * { flex-shrink: 0; min-width: max-content; }

  /* CoWork R4 addendum M-1: on phones, identity items in the home nav row
     duplicate the user menu (kyle ▾ holds System admin + Logout) — hide
     the inline copies so the row is just actions, not a crowd. */
  .identity-inline { display: none !important; }

  /* Data tables: block-scroll container — UNIVERSAL (r2: the selector-list
     version missed .card tables on the dashboards and bare tables on
     /imports/). Inner table keeps row semantics; nowrap keeps columns
     readable — you swipe, you don't squint. Opt out with .no-scroll. */
  table:not(.no-scroll) {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table:not(.no-scroll) th, table:not(.no-scroll) td {
    white-space: nowrap;
  }
  /* Grid/flex blowout guard: children default to min-width:auto and refuse
     to shrink, which clips content instead of wrapping ("$60,4"). */
  .grid > *, .flex > * { min-width: 0; }
  /* File inputs have a large intrinsic width that blows out upload grids. */
  input[type="file"] { max-width: 100%; min-width: 0; }
  /* Exceptions that should keep wrapping — bounded, not crushed. */
  td.events-cell { white-space: normal; min-width: 16rem; max-width: 22rem; }
  td .whitespace-pre-wrap, td.wrap { white-space: normal; min-width: 14rem; }
}

/* Touch targets — applies on touch devices at ANY width (tablets too). */
@media (pointer: coarse) {
  #app-nav a, .nav-group-menu a, .app-nav-toggle {
    padding-top: 12px; padding-bottom: 12px; min-height: 44px;
    display: inline-flex; align-items: center;
  }
  .nav-group-menu a { display: flex; }
  /* CoWork R4 addendum M-2: header dropdown items (kyle ▾ / Tenant ▾) were
     ~32px on touch — same 44px treatment as the nav menus. */
  .dropdown-menu a, .dropdown-menu button {
    min-height: 44px; display: flex; align-items: center;
  }
  button, input[type="submit"], .btn { min-height: 40px; }
  /* Inline text actions (edit/delete/remove links in panels + tables):
     grow the hit area without shifting layout. */
  td a, .panel a {
    position: relative; display: inline-block;
    padding: 8px 4px; margin: -8px -4px;
  }
  summary { padding-top: 8px; padding-bottom: 8px; }
}

/* Mobile r2 (GH #77 follow-up — Kyle's real-phone findings on /dashboard/):
   GLOBAL guard against unconditional multi-column grids. Any grid-cols-3..6
   without responsive prefixes collapses to 2-up below the sm breakpoint, so
   stat cards can never crush money again — and templates written tomorrow
   inherit the guard. !important because the Tailwind CDN injects its styles
   at runtime with unpredictable cascade order vs this stylesheet.
   grid-cols-7 (calendar weekdays) is deliberately exempt. */
@media (max-width: 639.98px) {
  .grid-cols-3, .grid-cols-4, .grid-cols-5, .grid-cols-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Owner call (r3): side-scrolling a table is only fair UX once it already
     has the whole screen. Any grid cell containing a table takes the full
     row on phones; the half-width squeeze-then-swipe combo is banned. */
  .grid > *:has(table) {
    grid-column: 1 / -1 !important;
  }

  /* r4: an unconditional col-span-N child inside a grid that collapses to
     one column on phones forces IMPLICIT extra columns and crushes its
     siblings (PO create: vendor select rendered 26px wide). Neutralize
     spans when the grid is explicitly single-column. */
  .grid-cols-1 > [class*="col-span"] {
    grid-column: auto !important;
  }
}

/* Header dropdowns: hover doesn't exist on touch. JS click-toggle adds
   .dropdown-open; hover keeps working for mouse users via the existing
   Tailwind group-hover classes. */
.dropdown-open > .dropdown-menu { display: block !important; }
