/* ══════════════════════════════════════════════════════════════════════
   UNCS AI — Shared Responsive Stylesheet
   ══════════════════════════════════════════════════════════════════════
   WHY: Centralized responsive rules for all uncs.ai pages. Each page
   has its own prefixed header class (dashboard-header, cf-header, etc.)
   but shares nav-link, header-nav, role-badge, signout-btn, and table
   patterns. This file handles the shared patterns; page-specific
   overrides remain in each page's <style> block.

   Breakpoints:
     1200px — large tablets / small laptops (constrain wide layouts)
     1024px — tablets landscape
      768px — tablets portrait / large phones landscape
      480px — phones portrait
      320px — small phones (iPhone SE)
   ══════════════════════════════════════════════════════════════════════ */

/* ── Touch Target Minimum ─────────────────────────────────────────────
   WHY: Apple HIG and WCAG recommend 44px minimum tap targets. Buttons
   and links that are too small cause mis-taps on mobile. */
@media (pointer: coarse) {
  button, .nav-link, .tab-btn, .signout-btn, .role-badge {
    min-height: 44px;
    min-width: 44px;
  }

  .nav-link {
    padding: 10px 12px;
  }

  .signout-btn {
    padding: 8px 14px;
  }
}

/* ── Prevent iOS Zoom on Input Focus ──────────────────────────────────
   WHY: iOS auto-zooms when font-size < 16px on inputs. Force 16px
   minimum on all inputs/textareas/selects on mobile. */
@media (max-width: 768px) {
  input, textarea, select {
    font-size: 16px !important;
  }
}

/* ── Tables — Horizontal Scroll Wrapper ───────────────────────────────
   WHY: Data tables shouldn't break layout on narrow screens. Wrapping
   in overflow-x: auto lets users swipe horizontally while keeping the
   page width stable. Pages should wrap tables in .table-scroll. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.5em 0;
}

/* ── 1024px — Tablets Landscape ──────────────────────────────────────── */
@media (max-width: 1024px) {

  /* Nav links: shrink padding */
  .header-nav {
    gap: 2px;
  }

  .nav-link {
    font-size: 11px;
    padding: 4px 8px;
  }
}

/* ── 768px — Tablets Portrait / Large Phones ─────────────────────────── */
@media (max-width: 768px) {

  /* Nav header: make scrollable so links don't overflow */
  .header-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;      /* Firefox */
    -ms-overflow-style: none;   /* IE/Edge */
    flex-wrap: nowrap;
    gap: 2px;
    margin-right: 4px;
    max-width: 55vw;
  }

  .header-nav::-webkit-scrollbar {
    display: none;              /* Chrome/Safari */
  }

  .nav-link {
    font-size: 12px;
    padding: 6px 10px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Role badge + sign out: compact */
  .role-badge {
    font-size: 10px;
    padding: 3px 8px;
  }

  .signout-btn {
    font-size: 11px;
    padding: 4px 8px;
  }

  /* Card rows: stack vertically */
  .card-row {
    flex-direction: column !important;
  }

  .card-row .card {
    flex: none !important;
    width: 100% !important;
  }

  /* Big metrics: 2 across instead of 4 */
  .big-metrics {
    flex-wrap: wrap !important;
  }

  .big-metrics .big-metric {
    flex: 1 1 45% !important;
    min-width: 120px !important;
  }

  /* Flow diagrams: wrap to stack */
  .flow {
    flex-wrap: wrap !important;
    gap: 0.5em !important;
  }

  .flow-box {
    min-width: 100px !important;
    flex: 1 1 40% !important;
  }

  .flow-arrow {
    font-size: 14pt !important;
    padding: 0 0.3em !important;
  }

  /* KPI grids: 2 columns */
  .kpi-grid, .kpi-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Tab bars: scrollable */
  .tab-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
  }

  .tab-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Tables: ensure horizontal scroll */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  thead, tbody, tr, th, td {
    white-space: normal;
  }

  /* Reduce body padding for document-style pages */
  body {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  /* Login cards: full width with margin */
  .login-card {
    max-width: calc(100vw - 32px) !important;
    padding: 32px 24px !important;
  }
}

/* ── 480px — Phones Portrait ─────────────────────────────────────────── */
@media (max-width: 480px) {

  /* Nav: show only 3-4 most important links, rest scroll */
  .header-nav {
    max-width: 45vw;
  }

  .nav-link {
    font-size: 11px;
    padding: 6px 8px;
  }

  /* Big metrics: 2 across, smaller */
  .big-metrics .big-metric .val {
    font-size: 14pt !important;
  }

  .big-metrics .big-metric .label {
    font-size: 7pt !important;
  }

  /* Flow diagrams: fully vertical */
  .flow {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .flow-box {
    flex: none !important;
    width: 100% !important;
    min-width: unset !important;
  }

  .flow-arrow {
    transform: rotate(90deg);
    text-align: center;
    padding: 0.2em 0 !important;
  }

  /* KPI grids: single column */
  .kpi-grid, .kpi-row {
    grid-template-columns: 1fr !important;
  }

  /* Callouts: tighter padding */
  .callout {
    padding: 0.5em 0.7em !important;
  }

  /* Tables: smaller font */
  table {
    font-size: 8pt !important;
  }

  th, td {
    padding: 4px 6px !important;
  }

  /* Section headings: smaller */
  .section h2, h2 {
    font-size: 13pt !important;
  }

  .section h3, h3 {
    font-size: 11pt !important;
  }

  /* Ensure readable body font on tiny screens */
  body {
    font-size: 14px !important;
    line-height: 1.5 !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  /* Login card: even tighter */
  .login-card {
    padding: 24px 16px !important;
  }

  .login-brand {
    font-size: 22px !important;
  }
}

/* ── 320px — Small Phones (iPhone SE) ────────────────────────────────── */
@media (max-width: 320px) {

  .nav-link {
    font-size: 10px;
    padding: 5px 6px;
  }

  .role-badge {
    display: none;  /* WHY: No room on tiny screens; user knows who they are */
  }

  .big-metrics .big-metric {
    flex: 1 1 100% !important;
  }

  body {
    padding-left: 6px !important;
    padding-right: 6px !important;
  }
}

/* ── Kairos Document — Page-Specific ─────────────────────────────────
   WHY: Kairos is a document-style page with print layout. These rules
   make it readable on mobile without breaking print output. */
@media (max-width: 768px) and (not print) {

  /* Kairos nav header (uses inline styles with id="nav-header") */
  #nav-header {
    padding: 0 8px !important;
    height: auto !important;
    min-height: 44px !important;
    flex-wrap: wrap !important;
    gap: 4px !important;
  }

  /* Kairos updates toolbar */
  .updates-toolbar {
    height: auto !important;
    min-height: 36px !important;
    flex-wrap: wrap !important;
    padding: 4px 10px !important;
    gap: 8px !important;
  }

  /* Kairos body padding (overrides the 0.7in for print) */
  #main-content {
    padding: 60px 16px 16px 16px !important;
  }

  /* Kairos doc header */
  .doc-header h1 {
    font-size: 16pt !important;
  }

  .doc-header .subtitle {
    font-size: 11pt !important;
  }

  .doc-header .meta {
    font-size: 8pt !important;
  }

  /* Kairos comment buttons — easier to tap */
  .comment-add-btn {
    width: 32px !important;
    height: 32px !important;
    margin-left: -36px !important;
    opacity: 0.6 !important;
  }

  /* Kairos responsibility matrix — allow scroll */
  .section table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Presentation / Large Screen ─────────────────────────────────────
   WHY: When displayed on lobby TVs or presentation screens (>1600px),
   increase font sizes and spacing for readability at distance. */
@media (min-width: 1600px) {

  .nav-link {
    font-size: 14px;
    padding: 6px 14px;
  }

  .role-badge {
    font-size: 13px;
    padding: 4px 14px;
  }

  /* KPI values: bigger for readability at distance */
  .big-metric .val, .kpi-value {
    font-size: 28pt !important;
  }

  /* Tables: increase font for readability */
  table {
    font-size: 12pt !important;
  }

  th, td {
    padding: 8px 14px !important;
  }
}

/* ── Print — Universal ───────────────────────────────────────────────
   WHY: Shared print rules so any page prints cleanly without nav
   chrome, login overlays, or interactive elements. */
@media print {
  .header-nav,
  .signout-btn,
  .role-badge,
  .login-overlay,
  .tab-bar,
  .comment-add-btn,
  .comment-thread,
  .comment-form,
  .updates-toolbar,
  #nav-header {
    display: none !important;
  }

  body {
    padding: 0 !important;
    font-size: 11pt !important;
  }

  table {
    display: table !important;
    overflow: visible !important;
    white-space: normal !important;
  }
}
