/* Customer portal shell. Theme tokens come from /styles.css (the staff stylesheet, read-only). */
.portal-page {
  margin: 0;
  min-height: 100vh;
  padding: 0 16px; /* keeps the card off the screen edge on a phone */
}

.portal-card {
  max-width: 28rem;
  margin: 4rem auto;
  padding: 1.5rem;
}

/* Sign-in page (login.html / login.js). Colors, sizes and radii come from the staff theme tokens. */
.portal-card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.portal-title {
  margin: 0 0 1rem;
  font-size: var(--fs-xl);
}

.portal-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0; /* the staff stylesheet pads every form; here the card already does */
}

.portal-form label {
  margin-top: 0.5rem;
  font-size: var(--fs-sm);
}

.portal-note {
  margin: 0 0 0.5rem;
  font-size: var(--fs-md);
  color: var(--text-muted);
}

.portal-error {
  margin: 0;
  min-height: 1.25em;
  font-size: var(--fs-sm);
  color: var(--danger);
}

.portal-form.has-error input:invalid,
.portal-form.has-error input:placeholder-shown {
  border-color: var(--danger);
}

.portal-submit {
  min-height: 44px;
  margin-top: 0.5rem;
}

.portal-link {
  align-self: flex-start;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary-text);
  font-size: var(--fs-sm);
  text-decoration: underline;
}

.portal-qr {
  align-self: center;
  width: 220px;
  height: 220px;
  background: #fff; /* a QR code needs a light quiet zone in every theme */
  border-radius: var(--radius-sm);
}

.portal-secret {
  word-break: break-all;
  user-select: all;
}

.portal-status {
  margin: 1rem 0 0;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--primary-tint);
  color: var(--primary-text);
  font-size: var(--fs-sm);
}

/* Signed-in pages: header/nav, page body, tables (orders, order detail, new order). */
.portal-header {
  margin: 0 -16px 1rem; /* spans the page padding so the bar reaches both screen edges */
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.portal-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-width: 64rem;
  margin: 0 auto;
}

.portal-nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 0;
  background: none;
  color: var(--text);
  font-size: var(--fs-md);
  text-decoration: none;
}

.portal-nav-link:hover,
.portal-nav-link:focus-visible {
  background: var(--primary-tint);
  color: var(--primary-text);
}

.portal-nav-link.is-active {
  color: var(--primary-text);
  font-weight: 600;
  border-bottom: 3px solid var(--primary);
}

.portal-signout {
  margin-left: auto;
}

.portal-main {
  max-width: 64rem;
  margin: 0 auto;
  padding-bottom: 3rem;
  color: var(--text);
}

.portal-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.portal-subtitle {
  margin: 1.5rem 0 0.5rem;
  font-size: var(--fs-lg);
}

.portal-section {
  margin-top: 1.5rem;
}

.portal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 1rem;
  text-decoration: none;
}

.portal-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: var(--fs-sm);
}

.portal-table th,
.portal-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.portal-table .num {
  text-align: right;
}

.portal-table a {
  color: var(--primary-text);
  white-space: nowrap; /* "SO-10162" never breaks at the dash */
}

.portal-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
  color: var(--text-muted);
}

.portal-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.portal-list-item {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.portal-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin: 1rem 0;
}

.portal-facts dt {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.portal-facts dd {
  margin: 0;
}

/* Order status timeline */
.portal-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 0;
  list-style: none;
}

.portal-step {
  flex: 1 1 8rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-top: 4px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
}

.portal-step.is-done {
  border-top-color: var(--primary);
  color: var(--text);
}

.portal-step.is-current {
  background: var(--primary-tint);
  color: var(--primary-text);
  font-weight: 600;
}

.portal-step-name,
.portal-step-date {
  display: block;
}

.portal-step-date {
  min-height: 1.25em;
  font-size: var(--fs-sm);
  font-weight: 400;
}

/* New order page */
.portal-order-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0; /* the staff stylesheet pads every form */
}

.portal-order-form label {
  margin-top: 0.5rem;
  font-size: var(--fs-sm);
}

.portal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.portal-tab {
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: none;
  color: var(--text);
}

.portal-tab.is-active {
  border-color: var(--border);
  background: var(--surface);
  color: var(--primary-text);
  font-weight: 600;
}

.portal-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 0;
}

.portal-mode {
  display: flex;
  gap: 1.5rem;
  margin: 0.5rem 0;
  padding: 0;
  border: 0;
}

.portal-mode label {
  display: inline-flex;
  flex-direction: row; /* the staff stylesheet stacks every label's contents; a radio sits beside its text */
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  margin-top: 0;
}

.portal-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

.portal-line select,
.portal-line input {
  flex: 1 1 10rem;
  min-height: 44px;
}

.portal-line.has-error {
  border-color: var(--danger);
  background: var(--danger-tint);
}

.portal-computed {
  min-width: 6rem;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.portal-blend-summary {
  margin: 0.5rem 0;
  font-weight: 600;
}

.portal-common-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.portal-order-form input,
.portal-order-form select,
.portal-order-form textarea {
  min-height: 44px;
}

.portal-confirmation {
  max-width: none;
  margin: 1rem 0;
}

.portal-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Invoices */
.portal-summary {
  margin: 1rem 0;
}

.portal-stat {
  min-width: 10rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.portal-stat dd {
  font-size: var(--fs-lg, 1.25rem);
  font-weight: 600;
}

.portal-stat.has-error {
  border-color: var(--danger, #b3261e);
}

.portal-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
}

.portal-badge.is-past-due {
  border-color: var(--danger, #b3261e);
  font-weight: 600;
}

/* Support page: cases and the report form */
.portal-case-form {
  margin: 1rem 0;
}

.portal-case-form.has-error textarea:invalid,
.portal-case-form.has-error input:invalid {
  border-color: var(--danger, #b3261e);
}

.portal-case-form > label {
  display: block; /* "Pounds affected (optional)" stays on one line */
}

/* Cards in lists use the full column, not the sign-in card's narrow centred box. */
.portal-case,
.portal-thread.portal-card {
  max-width: none;
}

.portal-thread.portal-card {
  margin: 0;
}

.portal-case {
  margin: 0 0 0.75rem;
}

.portal-case-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.portal-case-title {
  margin: 0;
  font-size: var(--fs-md, 1.05rem);
}

.portal-case-status.is-declined {
  border-color: var(--danger, #b3261e);
}

.portal-case-status.is-resolved,
.portal-case-status.is-approved {
  font-weight: 600;
}

.portal-case-description {
  margin: 0.5rem 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.portal-reply {
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-left: 3px solid var(--primary-text, currentColor);
  background: var(--surface);
  color: var(--text);
}

.portal-reply p {
  margin: 0.25rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Messages */
.portal-nav-badge {
  display: inline-block;
  min-width: 1.25rem;
  margin-left: 0.4rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--primary-text, currentColor);
  color: var(--surface);
  font-size: var(--fs-sm);
  text-align: center;
}

.portal-thread-list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.portal-thread {
  display: grid;
  gap: 0.25rem;
  width: 100%;
  min-height: 44px;
  text-align: left;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}

.portal-thread.has-unread {
  border-color: var(--primary-text, currentColor);
}

.portal-thread-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.portal-thread-subject {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.portal-thread-preview {
  overflow-wrap: anywhere;
}

.portal-unread {
  font-weight: 600;
}

.portal-msg-form {
  margin: 1rem 0;
}

.portal-msg-form.has-error textarea {
  border-color: var(--danger, #b3261e);
}

.portal-msg-list {
  display: grid;
  gap: 0.6rem;
  margin: 1rem 0;
  padding: 0;
  list-style: none;
}

.portal-bubble {
  max-width: 85%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.portal-bubble.is-customer {
  justify-self: end;
  border-color: var(--primary-text, currentColor);
}

.portal-bubble.is-staff {
  justify-self: start;
}

.portal-bubble p {
  margin: 0;
}

.portal-bubble-meta {
  margin-bottom: 0.25rem;
  font-size: var(--fs-sm);
}

.portal-bubble-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Home dashboard (index.html / index.js) */
.portal-home-title {
  margin-bottom: 0.25rem;
}

.portal-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); /* 4 across, 2 on a phone */
  gap: 0.75rem;
  margin: 1rem 0 1.5rem;
  padding: 0;
  list-style: none;
}

.portal-tile {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  height: 100%;
  box-sizing: border-box;
  min-height: 44px;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-top: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.portal-tile:hover,
.portal-tile:focus-visible {
  background: var(--primary-tint);
}

.portal-tile.has-error {
  border-top-color: var(--danger);
}

.portal-tile-label {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.portal-tile-value {
  font-size: var(--fs-xl);
  font-weight: 600;
}

.portal-tile-note {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.portal-tile.has-error .portal-tile-note {
  color: var(--danger);
  font-weight: 600;
}

.portal-home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1rem;
}

.portal-panel-card {
  min-width: 0; /* long previews wrap instead of widening the column */
  padding: 0.25rem 1rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.portal-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.portal-panel-head .portal-subtitle {
  margin: 0.75rem 0 0.25rem;
}

.portal-more {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--primary-text);
  font-size: var(--fs-sm);
}

.portal-panel-card [data-region].is-loading {
  min-height: 3rem; /* room for the spinner while the list loads */
}

.portal-home-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
}

.portal-home-row:last-child {
  border-bottom: 0;
}

.portal-home-row a {
  color: var(--primary-text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.portal-home-meta {
  flex-basis: 100%;
  margin: 0;
  overflow-wrap: anywhere;
}

/* "Report a problem" links on order and shipment pages */
.portal-report {
  margin-top: 1.5rem;
}

/* A link styled as a secondary button (View order, Report a problem): outlined, theme colours, not browser blue. */
a.portal-btn:not(.primary-btn) {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--primary-text);
  font-weight: 600;
}

a.portal-btn:not(.primary-btn):hover,
a.portal-btn:not(.primary-btn):focus-visible {
  border-color: var(--primary);
  background: var(--primary-tint);
}

.portal-list-item a {
  color: var(--primary-text);
}

/* Every table sits in a box that scrolls sideways when the table is wider than the screen (portal-common.js wraps
   them), so the page itself never does. */
.portal-table-wrap {
  position: relative; /* screen-reader-only labels in a cell (absolute) stay inside the box, not out past the page */
  max-width: 100%;
  overflow-x: auto;
}

/* Phones: the nav is one row that scrolls sideways. */
@media (max-width: 640px) {
  .portal-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0;
  }

  .portal-nav-link {
    flex: 0 0 auto;
    padding: 0 0.6rem;
    white-space: nowrap;
  }

  /* Cells keep "INV-10148-1" and "Nov 19, 2026" on one line; the table scrolls sideways instead. */
  .portal-table th,
  .portal-table td {
    padding: 0.5rem;
    white-space: nowrap;
  }
}

@media print {
  .portal-header,
  .portal-tabs,
  .portal-pager,
  .portal-heading + .portal-status,
  [data-action='open-pdf'] {
    display: none;
  }

  .portal-page {
    padding: 0;
    background: #fff;
    color: #000;
  }

  .portal-main {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .portal-title {
    font-size: 16pt;
  }

  .portal-table {
    font-size: 9pt;
  }

  .portal-table th,
  .portal-table td {
    padding: 3pt 4pt;
    border-bottom: 0.5pt solid #000;
  }

  .portal-stat {
    min-width: 0;
    padding: 4pt 8pt;
    border: 0.5pt solid #000;
    background: none;
  }

  .portal-remit {
    break-inside: avoid;
  }
}
