/* ===========================================================================
   CUSTOMER PORTAL — phone and small tablet

   The 1fr / 2fr grid in customer-portal.html is desktop furniture: it held its
   two columns down to 320px, which pushed the job status, invoices and service
   history 160px off the right edge of the phone. Below 900px it is one column,
   and the job status comes first - "where is my clean, what do I owe" is why a
   customer opens this page.

   Nothing here changes the desktop rendering.
   =========================================================================== */

/* The two-column grid is declared in a <style> block inside the page, which
   comes after this file, so the collapse needs to outrank it. */
@media (max-width: 900px) {
  /* Flex rather than a single grid column, and the two column wrappers
     dissolved with `display: contents`, so each card can be given a phone order
     of its own. In the grid they were stuck in their columns: Quick Links sat
     at the bottom of the left column, which meant under the whole service
     history, and that list only ever grows. */
  .portal-grid {
    display: flex !important;
    flex-direction: column;
    /* The page's own block sets `align-items: start` for the grid. In a column
       flex box that would size every card to its text instead of the screen. */
    align-items: stretch !important;
  }

  .portal-left,
  .portal-right {
    display: contents;
  }

  /* Quick Links first: it is the only route to a new quote or to Kate and
     Steph, and a customer should not have to scroll a year of visits to find
     it. The tracker stays directly beneath, so "what is next, what do I owe"
     is still on the first screen. */
  #quick-links-card {
    order: 1;
    margin-top: 0 !important;
  }

  #tracker-card {
    order: 2;
  }

  #quote-bookings-card {
    order: 3;
  }

  .profile-summary {
    order: 4;
  }

  #specialist-card {
    order: 5;
  }

  /* The archive goes last, where nothing below it matters. */
  #service-history-card {
    order: 6;
  }

  /* Thumb-sized actions, and 16px fields so iOS does not zoom the page when
     one takes focus (phones and iPads both). */
  /* There is no page-wide Pay button any more: each quote card carries its own,
     sized here so a thumb can hit it. */
  .portal-grid .btn-primary,
  .btn-quote-pay {
    min-height: 44px;
  }

  #form-edit-profile input {
    font-size: 16px;
    min-height: 44px;
  }
}

@media (max-width: 767.98px) {
  /* Four labels across ~330px: smaller type and a shorter rule so they stop
     running into each other. "In Progress" wraps, as it already did. */
  .status-tracker {
    padding: 0 2px;
  }

  .status-step {
    min-width: 0;
  }

  .status-label {
    font-size: 10px;
    line-height: 1.25;
  }

  .status-line {
    left: 26px;
    right: 26px;
  }

  /* Address block: city gets its own row, state and zip share the next one.
     (Desktop is 2fr / 1fr / 1fr across a 480px modal.) */
  .field-grid-city {
    grid-template-columns: 1fr 1fr !important;
  }

  .field-grid-city > :first-child {
    grid-column: 1 / -1;
  }
}

/* ===========================================================================
   SERVICE HISTORY — five visits, then a scroll box
   ===========================================================================
   A finished job adds a card here and nothing removes one, so after a season
   the list ran the page long. portal.js measures the real cards and sets the
   height; this only has to make the cut scrollable. A fixed height was not an
   option: a card with a Pay button is taller than one without, and every card
   is taller on a phone than on a desktop.
   =========================================================================== */

.job-history-scroll {
  /* The cards' offsetTop is measured against this box, which is what lets the
     page cut exactly above the sixth visit on any screen. */
  position: relative;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  /* Room for the scrollbar so it never sits on top of a Pay button. */
  padding-right: 6px;
}

/* Reached with Tab when it scrolls, so the older visits are not mouse-only. */
.job-history-scroll:focus-visible {
  outline: 2px solid var(--color-red, #c62828);
  outline-offset: 3px;
  border-radius: 6px;
}

.history-count {
  margin: 8px 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: #777;
}

/* ===========================================================================
   SERVICE HISTORY — the filter
   ===========================================================================
   Two native selects, not a custom dropdown: on a phone these open the system
   picker, which is a thumb-sized list with no typing and no page zoom. The bar
   only exists when portal.js unhides it, which it does only once the history is
   longer than the five-visit window.
   =========================================================================== */

.history-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin: 0 0 12px;
}

/* The class sets display, so the hidden attribute has to be said out loud. */
.history-filter[hidden] {
  display: none;
}

.history-filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 130px;
  min-width: 0;
}

.history-filter-field span {
  font-size: 0.75rem;
  font-weight: 600;
  color: #666;
}

.history-filter-field select {
  width: 100%;
  /* 16px: below it, iOS zooms the page the moment a field takes focus. */
  font-size: 16px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: #333;
}

.history-filter-clear {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #c62828;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: pointer;
}

.history-filter-clear[hidden] {
  display: none;
}

.history-filter-clear:hover {
  border-color: #c62828;
}

/* Prints the visits the filter leaves standing. It takes its own row, because
   it is the action and the two selects are the narrowing: on a phone a thumb
   should not have to aim between them. */
.history-download {
  flex: 1 1 100%;
  min-height: 44px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  background: #0284c7;
  border: 1px solid #0ea5e9;
  border-radius: 6px;
  cursor: pointer;
}

.history-download:disabled {
  opacity: 0.6;
  cursor: default;
}

/* The per-visit receipt sits next to that visit's Pay button, never on it: the
   two are different jobs and a thumb should not confuse them. */
.btn-history-receipt {
  white-space: nowrap;
}

.btn-history-receipt:hover {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(56, 189, 248, 0.14);
}

/* --------------------------------------------------------------------------
   Customer Portal Style Audit Cleanups (G5 Step 1C)
   -------------------------------------------------------------------------- */
.profile-complete-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 var(--space-lg);
  padding: 14px 18px;
  border: 1px solid #f0c36d;
  background: #fff8e6;
  border-radius: var(--radius-md);
}

.banner-text-subtle {
  color: #555;
}

.btn-nowrap {
  white-space: nowrap;
}

.btn-full-width {
  width: 100%;
}

.btn-full-width-mt10 {
  width: 100%;
  margin-top: 10px;
}

.btn-full-width-mb10 {
  width: 100%;
  margin-bottom: 10px;
}

.specialist-card-panel {
  margin-top: var(--space-md);
  background: #fdfaf6;
  border: 1px solid #faebd7;
  padding: 16px;
  border-radius: var(--radius-md);
}

.specialist-title {
  margin: 0 0 6px;
  color: var(--color-red, #e63946);
  font-size: 0.92rem;
}

.specialist-desc {
  margin: 0;
  font-size: 0.85rem;
  color: #555;
  line-height: 1.45;
}

.portal-card-mt-lg {
  margin-top: var(--space-lg);
}

.portal-card-hidden {
  margin-top: var(--space-lg);
  display: none;
}

.tracker-status-empty {
  text-align: center;
  font-style: italic;
  color: #666;
  margin-bottom: 0;
}

.tracker-invoice-banner {
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  background: #fafafa;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  transition: all 0.3s ease;
}

.tracker-invoice-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tracker-invoice-icon {
  font-size: 1.4rem;
}

.tracker-invoice-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #333;
}

.tracker-invoice-subtitle {
  font-size: 0.82rem;
  color: #666;
  margin-top: 2px;
}

.card-subtitle-text {
  font-size: 0.85rem;
  color: #777;
  margin: 0 0 12px;
}

.empty-history-text {
  font-size: 0.9rem;
  color: #888;
}

.portal-modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.portal-modal-box {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 480px;
  padding: 25px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.portal-modal-title {
  margin-top: 0;
  color: #333;
}

.portal-form-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-grid-name {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-grid-city {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
}

.portal-form-label {
  font-size: 0.8rem;
  font-weight: bold;
  color: #555;
}

.portal-form-input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.portal-status-msg {
  margin: 4px 0 0;
  font-size: 0.85rem;
  display: none;
}

.portal-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 15px;
}

.btn-cancel {
  background: none;
  border: 1px solid #ccc;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-save-modal {
  padding: 8px 18px;
  border-radius: 4px;
  cursor: pointer;
}

.delete-account-wrap {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.btn-delete-account {
  width: 100%;
  padding: 10px;
  background: #c62828;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
}

.delete-account-hint {
  font-size: 0.75rem;
  color: #888;
  margin-top: 8px;
  text-align: center;
}

.legal-links-footer {
  font-size: 0.8rem;
  color: #777;
  margin-top: 14px;
  text-align: center;
}

.link-underline {
  color: inherit;
  text-decoration: underline;
}


/* ---- Inlined Portal Layout & Components (Migrated from head style) ---- */
.portal-grid {
      display: grid;
      grid-template-columns: 1fr 2fr;
      gap: 2.25rem;
      align-items: start;
    }
    .status-tracker {
      display: flex;
      justify-content: space-between;
      position: relative;
      margin: var(--space-xl) 0;
      padding: 0 20px;
    }
    .status-step {
      text-align: center;
      z-index: 2;
      flex: 1;
    }
    .status-dot {
      width: 20px;
      height: 20px;
      background: #ddd !important;
      border-radius: 50%;
      margin: 0 auto 8px;
      transition: all 0.3s ease;
    }
    /* Green is a step that is done; red is the step in front of you. The red
       dot pulses while that is where the job is, and turns green the moment
       the job moves past it - so the bar has a current point instead of
       reading as finished or as a warning. */
    .status-dot.active {
      background: var(--color-red, #c62828) !important;
      transform: scale(1.15);
      animation: status-pulse 1.8s cubic-bezier(.4, 0, .2, 1) infinite;
    }
    @keyframes status-pulse {
      0%   { box-shadow: 0 0 0 0 rgba(198, 40, 40, .45), 0 0 8px rgba(198, 40, 40, .55); }
      70%  { box-shadow: 0 0 0 10px rgba(198, 40, 40, 0), 0 0 14px rgba(198, 40, 40, .6); }
      100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0), 0 0 8px rgba(198, 40, 40, .55); }
    }
    .status-dot.completed {
      background: #2e7d32 !important; /* Professional Green for completed steps */
      box-shadow: 0 0 5px #2e7d32;
    }
    .status-step:has(.status-dot.active) .status-label {
      color: var(--color-red, #c62828);
      font-weight: 700;
    }
    /* A pulse on repeat is exactly what some people cannot use; the colour and
       the scale still mark the current step without it. */
    @media (prefers-reduced-motion: reduce) {
      .status-dot.active {
        animation: none;
        box-shadow: 0 0 10px rgba(198, 40, 40, .55);
      }
    }
    .status-label {
      font-size: 12px;
      font-weight: 600;
      color: #666;
    }
    .status-line {
      position: absolute;
      top: 10px;
      left: 50px;
      right: 50px;
      height: 4px;
      background: #ddd;
      z-index: 1;
    }
    .status-line-fill {
      height: 100%;
      background: #2e7d32;
      width: 0%;
      transition: width 0.5s ease;
    }
    .profile-summary {
      background: var(--color-beige);
      padding: var(--space-lg);
      border-radius: var(--radius-md);
      border-left: 5px solid var(--color-red);
    }
    .action-card {
      background: var(--color-white);
      padding: var(--space-md);
      border-radius: var(--radius-md);
      box-shadow: var(--shadow-sm);
      margin-bottom: var(--space-md);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    /* One card per open quote. A customer with two live quotes used to get a
       single unlabelled tracker, so there was no way to tell which job it
       described - or which invoice a Pay button would charge. */
    .quote-card {
      background: #fafafa;
      border: 1px solid #eee;
      border-radius: 6px;
      padding: 12px 14px;
      margin-bottom: 10px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }
    .quote-card:last-child { margin-bottom: 0; }
    .quote-card-head {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 10px;
    }
    .quote-card-head strong { color: var(--color-red, #c62828); font-size: 0.95rem; }
    .quote-chip {
      font-size: 0.68rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.03em;
      padding: 3px 8px;
      border-radius: 999px;
      white-space: nowrap;
    }
    .quote-chip.step-1 { background: #fff8e1; color: #7a5c00; }
    .quote-chip.step-2 { background: #e8f5e9; color: #1b5e20; }
    .quote-chip.step-3 { background: #ffebee; color: #b71c1c; }
    .quote-chip.step-4 { background: #e8f5e9; color: #1b5e20; }
    .quote-when { font-size: 0.8rem; color: #666; }
    /* The four steps from the top tracker, at card size. Same steps, so the two
       cannot tell a customer different stories. */
    .mini-tracker {
      display: flex;
      align-items: center;
      justify-content: space-between;
      position: relative;
      padding: 4px 6px;
    }
    .mini-line {
      position: absolute;
      left: 14px;
      right: 14px;
      top: 50%;
      height: 3px;
      background: #ddd;
      transform: translateY(-50%);
      z-index: 0;
    }
    .mini-fill { height: 100%; background: #2e7d32; transition: width 0.3s ease; }
    .mini-fill.step-1 { width: 0%; }
    .mini-fill.step-2 { width: 33.333%; }
    .mini-fill.step-3 { width: 66.667%; }
    .mini-fill.step-4 { width: 100%; }

    .payment-line { font-size: 0.78rem; font-weight: 700; }
    .payment-line.payment-line-free { color: #34d399; }
    .payment-line.payment-line-refunded { color: #cbd5e1; }
    .payment-line.payment-line-paid { color: #34d399; }
    .payment-line.payment-line-partial { color: #38bdf8; }
    .payment-line.payment-line-pending { color: #fbbf24; }
    .mini-dot {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: #ddd;
      position: relative;
      z-index: 1;
    }
    .mini-dot.done { background: #2e7d32; }
    .mini-dot.now {
      background: var(--color-red, #c62828);
      box-shadow: 0 0 0 3px rgba(198, 40, 40, .18);
    }
    .quote-money { font-size: 0.82rem; color: #444; }
    .quote-money.muted { color: #777; font-style: italic; }
    .btn-quote-pay {
      margin-top: 2px;
      padding: 9px 16px;
      min-height: 40px;
      width: 100%;
      background: linear-gradient(135deg, #0ea5e9, #0284c7);
      color: white;
      border: none;
      border-radius: 6px;
      font-size: 0.85rem;
      font-weight: 700;
      cursor: pointer;
    }
    /* 16px, not the browser's 13.33px control default: below 16 iOS zooms the
       page on every field tap. The profile fields are styled inline and carry
       no size of their own, so the rule belongs here, not on the elements. */
    #form-edit-profile input { font-size: 16px; }

    /* Portal dynamic components */
    .tracker-paid-chip {
      font-weight: 700;
      color: #2e7d32;
      font-size: 0.85rem;
      padding: 6px 14px;
      background: #c8e6c9;
      border-radius: 6px;
      display: inline-block;
    }
    .btn-tracker-pay {
      padding: 8px 18px;
      color: white;
      border: none;
      border-radius: 6px;
      font-weight: 700;
      font-size: 0.85rem;
      cursor: pointer;
    }
    .btn-tracker-pay.btn-pay-red { background: #0284c7; }
    .btn-tracker-pay.btn-pay-blue { background: #0284c7; }
    .history-error-msg { color: #f87171; font-size: 0.8rem; }
    .history-empty-msg { font-size: 0.9rem; color: #94a3b8; }
    .history-job-card {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      gap: 6px;
      padding: 14px;
      background: rgba(15, 23, 42, 0.72);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 10px;
      margin-bottom: 10px;
    }
    .history-row-top {
      display: flex;
      justify-content: space-between;
      width: 100%;
      align-items: center;
    }
    .history-service-title { color: #f8fafc; font-size: 0.95rem; }
    .history-date { font-size: 0.8rem; color: #94a3b8; }
    .history-amount { font-size: 0.85rem; color: #cbd5e1; }
    .history-actions { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; margin-top: 6px; }
    .btn-pay-job {
      padding: 8px 16px;
      background: linear-gradient(135deg, #0ea5e9, #0284c7);
      color: white;
      border: none;
      border-radius: 6px;
      font-size: 0.82rem;
      font-weight: 700;
      cursor: pointer;
      flex: 1 1 140px;
      min-height: 38px;
      transition: filter 0.15s ease;
    }
    .btn-pay-job:hover {
      filter: brightness(1.1);
    }
    .btn-history-receipt,
    .btn-pdf {
      padding: 8px 14px;
      background: rgba(255, 255, 255, 0.06);
      color: #38bdf8;
      border: 1px solid rgba(56, 189, 248, 0.3);
      border-radius: 6px;
      font-size: 0.82rem;
      font-weight: 600;
      cursor: pointer;
      flex: 0 0 auto;
      min-height: 38px;
      transition: all 0.15s ease;
    }
    .print-loading-msg { font-family: sans-serif; padding: 24px; color: #555; }

/* ---- Stripe Elements Payment Modal ---- */
.payment-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.payment-modal-dialog {
  width: 100%;
  max-width: 480px;
  max-height: 92svh;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  color: #f8fafc;
}

.payment-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.95);
}

.payment-modal-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: #f8fafc;
}

.payment-modal-subtitle {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

.payment-modal-price-box {
  text-align: right;
  flex-shrink: 0;
}

.payment-modal-amount {
  font-size: 1.25rem;
  font-weight: 800;
  color: #38bdf8;
}

.payment-modal-brand {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 2px;
}

.payment-modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.payment-error-msg {
  color: #f87171;
  font-size: 0.85rem;
  margin-top: 10px;
  min-height: 1.2em;
}

.payment-modal-foot {
  padding: 14px 22px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 15, 25, 0.95);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-submit-payment {
  width: 100%;
  padding: 12px 18px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.btn-submit-payment:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-submit-payment:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-cancel-payment {
  width: 100%;
  padding: 10px 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #cbd5e1;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-cancel-payment:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

.payment-modal-trust {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 0.75rem;
  color: #94a3b8;
}
