:root {
  --ink-900: #0f2742;
  --ink-700: #284d73;
  --ink-500: #4e708f;
  --surface-0: #f3f8fc;
  --surface-1: #ffffff;
  --surface-2: #eaf3fb;
  --line: #c9d8e6;
  --brand-700: #005f96;
  --brand-600: #0a79b7;
  --brand-100: #d9ecf9;
  --accent-600: #3da646;
  --accent-100: #e6f5e8;
  --danger: #b92f2f;
  --shadow-sm: 0 6px 16px rgba(18, 30, 44, 0.08);
  --shadow-md: 0 16px 38px rgba(15, 30, 48, 0.13);
  --radius-lg: 18px;
  --radius-md: 12px;
  /* Horizontal gutter of the shell. Full-bleed children (the sticky tab
     scroller) cancel it with a negative margin, so it has to be a token. */
  --shell-pad: 1rem;
  /* Coarse-pointer hit target floor. */
  --tap: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink-900);
  background:
    radial-gradient(circle at 10% 0%, #cfe8fb 0, transparent 40%),
    radial-gradient(circle at 100% 100%, #dcf2df 0, transparent 36%),
    var(--surface-0);
}

.portal-shell {
  max-width: 1200px;
  margin: 0 auto;
  /* Gutters respect display cutouts in landscape (webview on a notched phone). */
  padding: 1.5rem max(var(--shell-pad), env(safe-area-inset-right))
           calc(2.4rem + env(safe-area-inset-bottom))
           max(var(--shell-pad), env(safe-area-inset-left));
}

main {
  min-width: 0;
}

.portal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(112deg, #fdfefe 0%, #f0f7fc 54%, #e8f6ef 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 2.7rem;
  height: 2.7rem;
  display: block;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 4px 10px rgba(17, 32, 47, 0.18);
}

.portal-header h1 {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  font-family: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: 0.005em;
}

.demo-badge {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.54em;
  letter-spacing: 0.06em;
  font-weight: 800;
  vertical-align: middle;
  color: #7c4f00;
  background: #ffe9bf;
  border: 1px solid #e8c27a;
}

.eyebrow {
  margin: 0;
  color: var(--ink-500);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.73rem;
  font-weight: 700;
}

.account-block {
  text-align: right;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
}

.header-actions .link-button,
.header-action-btn {
  white-space: nowrap;
}

/* Bare header links (Log out, Manage Access) were an 18px-tall text run — under
   the 24px target floor even for a mouse. Padding only; the look is unchanged. */
.header-actions .link-button {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0.3rem 0.55rem;
}

.header-action-btn {
  border: 1px solid #2f9346;
  border-radius: 999px;
  background: linear-gradient(180deg, #42b05f, #2f9346);
  color: #fff;
  font: inherit;
  font-weight: 800;
  padding: 0.42rem 0.9rem;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(39, 115, 58, 0.22);
}

@media (hover: hover) and (pointer: fine) {
  .header-action-btn:hover {
    filter: brightness(1.05);
  }
}

.header-action-btn:active {
  transform: translateY(1px);
}

.account-block p {
  margin: 0 0 0.25rem;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--ink-500);
}

.link-button,
a {
  color: var(--brand-700);
  text-decoration: none;
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .link-button:hover,
  a:hover {
    text-decoration: underline;
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.portal-tabs {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.portal-tabs button {
  border: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--ink-700);
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  padding: 0.5rem 0.95rem;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 120ms ease, border-color 180ms ease, background-color 180ms ease;
}

/* Hover lift is for pointers only — on touch it sticks after the tap and
   reads as a stuck state. Touch gets an explicit press instead. */
@media (hover: hover) and (pointer: fine) {
  .portal-tabs button:hover {
    transform: translateY(-1px);
    border-color: #b6c7d7;
  }
}

.portal-tabs button:active {
  background: var(--brand-100);
  border-color: var(--brand-600);
}

.portal-tabs button.active {
  border-color: var(--brand-600);
  background: linear-gradient(180deg, #edf7fe, var(--brand-100));
  color: var(--brand-700);
}

/* One element, two jobs: a hairline group divider in the desktop pill row, a
   group heading in the mobile drawer. The label text stays in the DOM at both
   sizes so a screen reader announces the grouping either way. */
.tab-group {
  width: 1px;
  height: 1.1rem;
  align-self: center;
  margin: 0 0.15rem;
  background: #c5d3df;
  overflow: hidden;
  text-indent: -999em;
}

.nav-toggle,
.nav-backdrop,
.nav-drawer-head,
.tab-count {
  display: none; /* drawer furniture: phone and tablet only */
}

.tabs-helper {
  margin: 0.45rem 0 0.2rem;
  color: var(--ink-500);
  font-size: 0.88rem;
}

/* Below the desktop pill row's width, the same eight buttons become a
   slide-over drawer behind a trigger that names the current section. A row of
   eight pills at phone width was either four stacked rows of chrome or a
   horizontal scroller that hid half its destinations off-screen; a drawer costs
   one 44px bar and shows every section, grouped, when it is opened. */
@media (max-width: 1100px) {
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    min-height: var(--tap);
    /* Breathing room below the bar: the tiles, filters or first table used to
       sit right against it (noticed in Chrome device mode). */
    margin: 0.85rem 0 1.15rem;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-1);
    box-shadow: var(--shadow-sm);
    color: var(--ink-900);
    font: inherit;
    font-weight: 800;
    text-align: left;
    cursor: pointer;
  }

  /* The bar now carries the gap, so the filter row directly under it does
     not add a full rem of its own. */
  .panel > .controls:first-child {
    margin-top: 0;
  }

  .nav-toggle:active {
    background: var(--surface-2);
  }

  .nav-toggle-mark {
    flex: 0 0 auto;
    width: 1.15rem;
    height: 1.15rem;
    stroke: var(--brand-700);
    stroke-width: 1.8;
    stroke-linecap: round;
    fill: none;
  }

  .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(9, 20, 34, 0.44);
  }

  .nav-backdrop:not([hidden]) {
    display: block;
  }

  .portal-tabs {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 80;
    width: min(84vw, 20rem);
    margin: 0;
    padding: 0.4rem 0.7rem calc(1rem + env(safe-area-inset-bottom));
    padding-left: max(0.7rem, env(safe-area-inset-left));
    flex-direction: column;
    /* The desktop pill row wraps; a column that inherits that wraps into a
       second column on a short landscape phone instead of scrolling. */
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.15rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface-1);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-md);
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  body.nav-open .portal-tabs {
    transform: none;
  }

  .nav-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    padding: 0.35rem 0.2rem 0.6rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0.5rem;
  }

  .nav-drawer-title {
    margin: 0;
    color: var(--ink-500);
    font-size: 0.73rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
  }

  /* Rows, not pills: a drawer item spans the panel and reads as a destination. */
  .portal-tabs button[data-tab] {
    display: flex;
    align-items: center;
    /* The coarse-pointer rule centres pill buttons; drawer rows are always
       left-aligned, whether or not a count pill is pushing the label over. */
    justify-content: flex-start;
    gap: 0.6rem;
    border: 0;
    border-radius: 10px;
    padding: 0.7rem 0.7rem;
    background: none;
    color: var(--ink-900);
    font-weight: 700;
    text-align: left;
  }

  .portal-tabs button[data-tab].active {
    background: var(--brand-100);
    color: var(--brand-700);
    font-weight: 800;
  }

  .portal-tabs button[data-tab]:active {
    background: var(--surface-2);
  }

  /* Group headings replace the desktop hairlines. */
  .tab-group {
    display: block;
    width: auto;
    height: auto;
    margin: 0.85rem 0 0.25rem;
    padding: 0 0.7rem;
    background: none;
    color: var(--ink-500);
    font-size: 0.71rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    text-indent: 0;
  }

  .tab-count {
    display: inline-block;
    margin-left: auto;
    min-width: 1.6rem;
    padding: 0.1rem 0.42rem;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--ink-700);
    font-size: 0.78rem;
    font-weight: 800;
    text-align: center;
  }

  .portal-tabs button[data-tab].active .tab-count {
    background: var(--surface-1);
    color: var(--brand-700);
  }
}

@media (prefers-reduced-motion: reduce) {
  .portal-tabs {
    transition: none;
  }
}

.panel {
  display: none;
  animation: panel-reveal 240ms ease;
}

.panel.active {
  display: block;
}

.portal-footer {
  margin: 1rem 0 0.35rem;
  padding: 0.55rem 0.1rem 0;
  border-top: 1px solid #d5e2ee;
  color: var(--ink-500);
  font-size: 0.82rem;
  text-align: center;
}

/* Embedded in the Stark mobile app's webview (`?embed=1`). The host app supplies
   identity, account context, and its own chrome, so the portal drops the brand
   lockup, the "signed in as" line, and the footer — but keeps the action row,
   which the host app does not provide. Previously this lived in two places
   under two different query params (`embed` in the template, `embedded` in JS);
   one class, set by both paths, is the whole mechanism now. */
body.embed .portal-footer,
body.embed .portal-header .brand-block,
body.embed .portal-header .account-block .muted {
  display: none;
}

/* Embedded in the app: the host shows the title and identity, so the header
   is just the two actions. No card around them; an empty white bar with two
   buttons in the corner read as a broken header. */
body.embed .portal-header {
  justify-content: flex-end;
  padding: 0 0 0.35rem;
  background: none;
  border: none;
  box-shadow: none;
}

body.embed .portal-shell {
  padding-top: max(0.65rem, env(safe-area-inset-top));
}

body.embed .nav-toggle {
  margin-top: 0.65rem;
}

.controls {
  margin: 1rem 0;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

label {
  color: var(--ink-700);
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea,
button.action,
.auth-card button {
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
}

input,
select,
textarea {
  min-height: 2.4rem;
  margin-top: 0.25rem;
  padding: 0.5rem 0.68rem;
  width: min(100%, 360px);
  background: #fff;
}

label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

label.checkbox input {
  width: auto;
  min-height: 0;
  margin: 0;
}

textarea {
  width: 100%;
  resize: vertical;
}

button.action,
.auth-card button {
  min-height: 2.4rem;
  margin-top: 1.2rem;
  padding: 0.5rem 1.1rem;
  background: linear-gradient(170deg, var(--brand-600), var(--brand-700));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  border-color: transparent;
}

@media (hover: hover) and (pointer: fine) {
  button.action:hover,
  .auth-card button:hover {
    filter: brightness(1.05);
  }
}

/* Touch/stylus primary input: every control clears a 44px hit target. Keyed on
   the pointer, not the viewport — a tablet in landscape is wide AND touched,
   and a touch laptop still reports a fine primary pointer. */
@media (pointer: coarse) {
  input,
  select,
  textarea,
  button.action,
  .auth-card button,
  .header-action-btn,
  .header-actions .link-button,
  .modal-close,
  .portal-tabs button {
    min-height: var(--tap);
  }

  .portal-tabs button,
  .modal-close,
  .header-actions .link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

}

.section-card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin: 0 0 1rem;
  overflow: hidden;
}

.section-card h2 {
  margin: 0;
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfdff, var(--surface-2));
  color: var(--ink-700);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.3;
}

.section-card > .muted {
  margin: 0.9rem 1rem 1.05rem;
}

/* An Overview bucket with nothing in it is one line, not a card with an empty
   body: the real work (usually Unscheduled) moves up the page. */
.section-card.is-empty h2 {
  display: flex;
  align-items: center;
  border-bottom: 0;
  padding-block: 0.7rem;
}

.section-card.is-empty {
  margin-bottom: 0.6rem;
}

.section-card.is-empty .empty-note {
  margin-left: auto;
  color: var(--ink-500);
  font-size: 0.84rem;
  font-weight: 600;
}

.deficiency-form {
  padding: 0.95rem 1rem 1rem;
}

/* Intro line under a modal head (business-hours note on Request Service). */
.modal-card > .muted {
  margin: 0.9rem 1rem 0;
  line-height: 1.45;
}

.deficiency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.deficiency-grid select {
  width: 100%;
  max-width: none;
}

.deficiency-form > label {
  display: block;
  margin-bottom: 0.7rem;
}

/* Every other field in this form is required, so the one that isn't says so. */
.label-optional {
  margin-left: 0.3rem;
  color: var(--ink-500);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.deficiency-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
}

.deficiency-actions .action {
  margin-top: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 20, 34, 0.44);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: min(100%, 720px);
  /* dvh so mobile browser chrome can't push the form's submit button out of
     reach; vh first for engines without dynamic viewport units. */
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-1);
  box-shadow: var(--shadow-md);
}

.modal-head {
  /* Stays put while a long job or invoice scrolls, so Close is always a tap away. */
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  border-bottom: 1px solid var(--line);
  padding: 0.8rem 1rem;
  background: var(--surface-1);
}

.modal-close {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-700);
  font: inherit;
  font-weight: 700;
  padding: 0.36rem 0.76rem;
  cursor: pointer;
}

body.modal-open {
  overflow: hidden;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  margin-left: 0.4rem;
  padding: 0.14rem 0.46rem;
  border-radius: 999px;
  background: #dbe9f4;
  color: #23445d;
  font-size: 0.78rem;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Wide tables between phone cards and full desktop: fade the edges that hide
   more columns, and say so once for touch users. Both are driven by JS
   (watchTableScroll) toggling is-scrollable / at-start / at-end. */
.table-wrap.is-scrollable {
  --fade-l: 0;
  --fade-r: 1;
  background:
    linear-gradient(90deg, rgba(15, 39, 66, 0.18), transparent 26px) left / 26px 100% no-repeat,
    linear-gradient(270deg, rgba(15, 39, 66, 0.18), transparent 26px) right / 26px 100% no-repeat;
  background-attachment: scroll;
}

.table-wrap.is-scrollable.at-start {
  background-image:
    linear-gradient(90deg, transparent, transparent),
    linear-gradient(270deg, rgba(15, 39, 66, 0.18), transparent 26px);
}

.table-wrap.is-scrollable.at-end {
  background-image:
    linear-gradient(90deg, rgba(15, 39, 66, 0.18), transparent 26px),
    linear-gradient(270deg, transparent, transparent);
}

.table-wrap.is-scrollable.at-start.at-end {
  background-image: none;
}

.table-wrap.is-scrollable table {
  /* Let the gradients show through the row backgrounds at the edges. */
  background: transparent;
}

.table-wrap.is-scrollable::before {
  content: "Swipe for more columns \2192";
  position: sticky;
  left: 0;
  display: block;
  width: max-content;
  margin: 0.5rem 0.82rem 0.25rem;
  color: var(--ink-500);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.table-wrap.is-scrollable.at-end::before {
  content: "\2190 Swipe back";
}

/* Mouse users: the scrollbar sits at the bottom of a tall table, so the only
   hint of hidden columns was off-screen. Same line, worded for a mouse. */
@media (hover: hover) and (pointer: fine) {
  .table-wrap.is-scrollable::before {
    content: "Scroll sideways for more columns \2192";
  }

  .table-wrap.is-scrollable.at-end::before {
    content: "\2190 Scroll back";
  }
}

/* Long/short label pairs on cell links (quoteLink in app.js). */
.label-short {
  display: none;
}

@media (max-width: 1100px) {
  .label-long {
    display: none;
  }

  .label-short {
    display: inline;
  }
}

/* Long prose in a cell: three lines, tap for the rest (see table() in app.js). */
.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

.clamp.expanded {
  display: inline;
  -webkit-line-clamp: unset;
}

/* Columns that are blank in every row (see table() in app.js). */
@media (max-width: 1100px) {
  .col-blank {
    display: none;
  }

  /* Tablet tables: eight columns in 800px. Slightly tighter cells and header
     letter-spacing buy back the ~40px that pushed the last column off-screen. */
  .table-wrap th,
  .table-wrap td {
    padding: 0.62rem 0.6rem;
  }

  .table-wrap th {
    letter-spacing: 0.03em;
    /* "Resolution Status" on one line cost 174px of an 800px screen. */
    white-space: normal;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.68rem 0.82rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #e6edf3;
  font-size: 0.93rem;
}

th {
  color: var(--ink-700);
  background: #fbfdff;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

td {
  white-space: normal;
  word-break: normal;
  /* break-word, not anywhere: `anywhere` also shrinks the column's min-content
     width, so the browser narrowed columns and then split ordinary words
     ("Schedule / d", "Complete / d"). break-word still breaks a word that
     genuinely cannot fit. */
  overflow-wrap: break-word;
}

.table-wrap td a {
  white-space: nowrap;
}

.docs-thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.docs-thumb-item {
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 96px;
}

.docs-thumb-preview {
  display: inline-flex;
  border: 1px solid #d7e3ee;
  border-radius: 8px;
  background: #f8fbfe;
  padding: 0.18rem;
}

.docs-thumb-image {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 6px;
  background: #eef4fa;
}

.docs-thumb-label {
  font-size: 0.74rem;
  color: var(--ink-600);
  text-transform: capitalize;
}

@media (hover: hover) and (pointer: fine) {
  tbody tr:hover {
    background: #f8fbfd;
  }
}

tbody tr.job-row {
  cursor: pointer;
}

/* Touch has no hover, so the row tap needs its own acknowledgement. */
tbody tr.job-row:active {
  background: var(--surface-2);
}

.cell-link {
  border: none;
  /* Vertical padding only: keeps the underline aligned with cell text while
     lifting the hit area off the 16px text box. */
  padding: 0.25rem 0;
  /* The vertical padding grows the hit area; pull it back out of the flow so
     the link text sits on the same baseline as its neighbours. */
  margin: -0.25rem 0;
  vertical-align: baseline;
  background: none;
  color: var(--brand-700);
  text-decoration: underline;
  text-underline-offset: 2px;
  font: inherit;
  font-weight: 700;
  /* A job number or dollar amount broken across two lines ("$2,184.5 / 5")
     reads as a data error. */
  white-space: nowrap;
  cursor: pointer;
}

/* Inline drill-in controls (job number, invoice amount, upload count) are the
   smallest targets in the app. On touch the row grows with them, which is the
   right rhythm for a thumb anyway. Placed after the base rule so it wins. */
@media (pointer: coarse) {
  .cell-link,
  .table-wrap td a {
    padding-block: 0.9rem; /* 14.4 * 2 + 16px line = 44.8 */
    /* Short labels ("View", "1 job") were ~32px wide. Pad sideways and pull the
       padding back with a matching negative margin so the text does not move. */
    padding-inline: 0.5rem;
    margin-inline: -0.5rem;
  }
}

.job-overview-body {
  padding: 1rem;
}

.job-overview-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.job-overview-sub {
  margin: 0 0 0.8rem;
}

.job-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem;
}

.job-overview-item {
  background: #f8fbfd;
  border: 1px solid #e2eaf2;
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
}

.job-overview-item strong {
  display: block;
  color: var(--ink-700);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.22rem;
}

.err {
  color: var(--danger);
  font-weight: 700;
}

.sev-inoperable,
.sev-critical {
  color: var(--danger);
  font-weight: 700;
}

.auth-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  background: #2a6ea5;
}

.auth-card {
  width: min(100%, 440px);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 1.4rem 1.3rem;
}

.auth-logo {
  display: block;
  width: min(190px, 52%);
  max-height: 64px;
  height: auto;
  object-fit: contain;
  margin: 0 auto 0.55rem;
}

.auth-brand {
  margin: 0;
  color: var(--ink-500);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 800;
  text-align: center;
}

.auth-card h1 {
  margin-top: 0.15rem;
  margin-bottom: 0.6rem;
}

.help {
  color: var(--ink-500);
  font-size: 0.91rem;
}

/* Landing page: the "Sign in with Stark Tech" link looks like the primary button. */
.auth-primary {
  display: block;
  margin: 1.1rem 0 0.6rem;
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  background: linear-gradient(170deg, var(--brand-600), var(--brand-700));
  color: #fff;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

@media (hover: hover) and (pointer: fine) {
  .auth-primary:hover {
    filter: brightness(1.05);
  }
}

.auth-note {
  margin: 0.4rem 0 0.8rem;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  background: var(--surface-2, #eef4fa);
  border: 1px solid var(--line);
  font-size: 0.93rem;
}

.errorlist {
  margin: 0.3rem 0;
  padding-left: 1.1rem;
  color: var(--danger);
}

form p {
  margin: 0.6rem 0;
}

form p label {
  display: block;
}

form p input {
  width: 100%;
}

/* Filters at tablet widths: controls flex to fill rows, button sits on the
   baseline of the last row instead of floating on its own. */
@media (max-width: 1100px) {
  .controls {
    align-items: end;
    gap: 0.5rem 0.6rem;
  }

  .controls label {
    flex: 1 1 11rem;
    width: auto;
  }

  .controls input,
  .controls select,
  .controls textarea {
    width: 100%;
    max-width: none;
  }

  .controls button.action {
    margin-top: 0;
    flex: 0 1 auto;
  }
}

@media (max-width: 720px) {
  .portal-shell {
    --shell-pad: 0.7rem;
    padding-top: 1rem;
  }

  /* Phone header: one grid, three rows, ~150px instead of ~210px.
       [logo] Stark Tech Service Portal [DEMO]
              Signed in as name@example.com
       [ Request Service                ] [Log out]
     brand-block, account-block and header-actions dissolve (display: contents)
     so each piece can be placed on the grid directly. */
  .portal-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 0.7rem;
    row-gap: 0.5rem;
    padding: 0.8rem 0.9rem 0.9rem;
  }

  .brand-block,
  .account-block,
  .header-actions {
    display: contents;
  }

  .brand-mark {
    grid-column: 1;
    grid-row: 1;
  }

  .brand-block > div {
    grid-column: 2 / -1;
    grid-row: 1;
    min-width: 0;
  }

  .portal-header h1 {
    font-size: 1.2rem;
  }

  .demo-badge {
    font-size: 0.56em;
    padding: 0.12rem 0.4rem;
  }

  .account-block .muted {
    grid-column: 2 / -1;
    grid-row: 2;
    margin: -0.15rem 0 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.86rem;
    text-align: left;
  }

  .header-action-btn {
    grid-column: 1 / 3;
    grid-row: 3;
    text-align: center;
  }

  .header-actions .logout-link {
    grid-column: 3;
    grid-row: 3;
    justify-self: end;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    padding: 0.38rem 0.82rem;
  }

  /* Embedded: the host app shows identity, so the row is just the two actions. */
  body.embed .header-action-btn,
  body.embed .header-actions .logout-link {
    grid-row: 1;
  }

  /* Staff-only admin surface; not something to do from a phone. Still reachable
     at /manage/ by URL for anyone who needs it there. */
  .header-actions .link-button[href$="/manage/"] {
    display: none;
  }

  /* Filters pair up two-per-row (the 1100px rule above sets the flex layout;
     the narrower basis here is what makes it two per row on a phone). The
     Jobs tab has five controls plus a button: stacked, that was ~380px of
     filter UI above the first job. */
  .controls label {
    flex-basis: 9rem;
  }

  /* Furniture. On a phone the heading already says where you are. */
  .eyebrow {
    display: none;
  }

  .tabs-helper {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  #overviewMeta {
    width: 100%;
  }

  .section-card h2 {
    padding: 0.85rem 0.8rem;
    font-size: 0.95rem;
  }

  .count-pill {
    margin-left: 0.32rem;
  }

  th,
  td {
    padding: 0.58rem 0.62rem;
    font-size: 0.88rem;
  }

  .auth-card {
    padding: 1.2rem 1rem;
  }

  .deficiency-form {
    padding: 0.85rem 0.8rem 0.9rem;
  }

  .deficiency-grid {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 0;
  }

  .modal-card {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    /* Home indicator / bottom chrome must not sit on the submit button. */
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-width: 520px) {
  /* The "0" pill already says it; the note made long bucket titles wrap. */
  .section-card.is-empty .empty-note {
    display: none;
  }

  .brand-mark {
    width: 2.3rem;
    height: 2.3rem;
  }

  h1 {
    font-size: 1.28rem;
  }

  .table-wrap td a {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

@media (max-width: 460px) {
  h1 {
    font-size: clamp(1.25rem, 5vw, 1.55rem);
  }

  .brand-mark {
    width: 2.4rem;
    height: 2.4rem;
  }

  .auth-body {
    padding: 1rem 0.7rem;
  }

  .auth-card {
    border-radius: 16px;
    padding: 1rem 0.85rem;
  }
}

@keyframes panel-reveal {
  from {
    opacity: 0;
    transform: translateY(7px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile-only KPI tiles at top of content (hidden on desktop). Overview only:
   on the other tabs they repeated the section's own count pill and, with the
   header and filters, pushed the first row below the fold on every iPhone. */
.mobile-metrics { display: none; }
@media (max-width: 720px) {
  body[data-tab="overview"] .mobile-metrics {
    display: flex;
    gap: 0.75rem;
    margin: 0 0 1rem;
  }
  .metric-tile {
    flex: 1;
    background: var(--surface-1);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 0.6rem 0.5rem;
    text-align: center;
  }
  .metric-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.05;
    color: var(--brand-700);
  }
  /* Until the count arrives the value is a shimmering bar, not a dash that
     reads as "no data". loadMobileMetrics() removes is-loading. */
  .metric-tile.is-loading .metric-value {
    width: 2.4rem;
    height: 1.6rem;
    margin: 0 auto;
    border-radius: 7px;
    color: transparent;
    background: linear-gradient(90deg, #dfe9f2 25%, #f1f6fa 50%, #dfe9f2 75%);
    background-size: 200% 100%;
    animation: shimmer 1.3s linear infinite;
  }
  @keyframes shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
  }
  @media (prefers-reduced-motion: reduce) {
    .metric-tile.is-loading .metric-value { animation: none; }
  }
  .metric-label {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-500);
  }
}

/* Non-contract customers: Quotes + Invoices only (server also enforces this). */
.non-contract .portal-tabs button[data-tab]:not([data-tab="quotes"]):not([data-tab="invoices"]),
.non-contract .tab-group,
.non-contract .mobile-metrics,
.non-contract #openServiceRequestBtn { display: none !important; }

/* Sortable column headers. */
.table-wrap th { cursor: pointer; user-select: none; }
.table-wrap th[aria-sort="ascending"]::after { content: " \25B2"; font-size: 0.7em; }
.table-wrap th[aria-sort="descending"]::after { content: " \25BC"; font-size: 0.7em; }

.warn { color: #8b6400; font-weight: 600; }

/* Open-deficiencies advisory panel in the service request modal. */
.sr-open-defs {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  color: var(--ink-700);
}
.sr-open-defs ul { margin: 0.45rem 0 0; padding-left: 1.25rem; }
.sr-open-defs li { margin-bottom: 0.25rem; }

/* Inline loading spinner. */
.spinner {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  vertical-align: -0.1em;
  border: 2px solid var(--line);
  border-top-color: var(--brand-600);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Mobile tables: each row becomes a card — title line, then compact
   label/value pairs on one line each (stacking them made 9-column invoice
   rows absurdly tall). Prose columns still stack so they read left-aligned. */
@media (max-width: 720px) {
  .table-wrap { overflow: visible; }

  table {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  thead { display: none; }

  tbody {
    display: grid;
    gap: 0.6rem;
    width: 100%;
    min-width: 0;
  }

  /* Flex column so the heading can be pulled to the top regardless of which
     column it came from (Job # is the 3rd cell, but titles the card). */
  tbody tr {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface-1);
    box-shadow: var(--shadow-sm);
    padding: 0 0.75rem 0.3rem;
  }

  tbody tr:hover { background: var(--surface-1); }

  td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    min-width: 0;
    padding: 0.42rem 0;
    /* Separator on top, not bottom: hidden/reordered cells would otherwise
       leave a dangling rule at the end of the card. */
    border-top: 1px dashed #e6eef6;
    font-size: 0.88rem;
    text-align: right;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    max-width: 45%;
    color: var(--ink-500);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: left;
  }

  /* Card heading (see table() in app.js) — hoisted to the top of the card. */
  td[data-card-title] {
    order: -1;
    display: block;
    padding: 0.6rem 0 0.5rem;
    border-top: 0;
    color: var(--ink-900);
    font-size: 1.05rem;
    font-weight: 800;
    text-align: left;
  }

  td[data-card-title]::before { display: none; }

  /* Empty values are noise in a card — the desktop table still shows them. */
  td[data-blank] { display: none; }

  /* Prose/long-text columns read badly right-aligned — stack these. */
  td[data-label="Description"],
  td[data-label="Address"],
  td[data-label="Services"] {
    display: block;
    text-align: left;
  }

  td[data-label="Description"]::before,
  td[data-label="Address"]::before,
  td[data-label="Services"]::before {
    display: block;
    max-width: none;
    margin-bottom: 0.15rem;
  }
}
