  :root{
    --navy:#16283F;
    --navy-deep:#0E1B2C;
    --cream:#F7F4EC;
    --cream-dim:#EFEADC;
    --amber:#E4A33B;
    --amber-dim:#C88A28;
    --teal:#2F6E64;
    --asphalt:#3D4652;
    --white:#FFFFFF;
    --line:rgba(22,40,63,0.12);
    --shadow:0 20px 50px -25px rgba(14,27,44,0.35);
  }
  *{box-sizing:border-box;}
  html{-webkit-font-smoothing:antialiased;}
  body{
    margin:0;
    min-height:100vh;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    background:var(--cream);
    color:var(--asphalt);
    font-family:'Inter', -apple-system, sans-serif;
    font-size:16px;
    line-height:1.6;
    padding:32px 24px;
  }
  a{ color:var(--teal); }
  h1,h2,h3,h4{ font-family:'Fraunces', Georgia, serif; color:var(--navy); margin:0; font-weight:600; }
  :focus-visible{ outline:3px solid var(--amber); outline-offset:2px; }
  button{ font-family:inherit; }

  .portal-brand{
    display:inline-block;
    margin-bottom:28px;
  }
  .portal-brand img{ display:block; height:38px; width:auto; }

  /* ---------- Sign-in screen: feature carousel + divider ----------
     A true split: the divider marks the actual midpoint of the
     screen (well, of the wrap — capped at max-width so it doesn't run
     the full width of an ultra-wide monitor), and each side centers
     its own content within its own half — not the group centered
     together with a fixed gap. */
  .portal-auth-wrap{
    display:grid;
    grid-template-columns:1fr 2px 1fr;
    align-items:stretch;
    width:100%;
    max-width:1700px;
    margin:0 auto;
  }
  .portal-auth-divider{
    background:linear-gradient(180deg, transparent 0%, var(--amber) 20%, var(--amber) 80%, transparent 100%);
  }
  .portal-features{
    justify-self:center; align-self:center;
    width:300px; text-align:center;
  }
  .portal-feature-slide{ display:none; }
  .portal-feature-slide.is-active{ display:block; animation:portalFeatureFadeIn 0.4s ease; }
  @keyframes portalFeatureFadeIn{ from{ opacity:0; transform:translateY(4px); } to{ opacity:1; transform:translateY(0); } }
  @media (prefers-reduced-motion: reduce){ .portal-feature-slide.is-active{ animation:none; } }
  .portal-feature-art{ width:100%; max-width:220px; margin:0 auto 20px; color:var(--asphalt); opacity:0.3; }
  .portal-feature-art svg{ width:100%; height:auto; display:block; }
  .portal-feature-title{ font-size:1.3rem; margin-bottom:10px; }
  .portal-feature-text{ font-size:0.92rem; opacity:0.7; line-height:1.6; }
  .portal-feature-dots{ display:flex; gap:8px; justify-content:center; margin-top:24px; }
  .portal-feature-dot{ width:8px; height:8px; border-radius:50%; border:none; padding:0; background:var(--line); cursor:pointer; }
  .portal-feature-dot.is-active{ background:var(--amber); }
  @media (max-width:860px){
    .portal-features{ display:none; }
    .portal-auth-divider{ display:none; }
    /* Hiding those two doesn't just make them invisible — display:none
       removes them as actual grid items, so the grid's 3 explicit
       column tracks (1fr / 2px / 1fr) still all exist and reserve
       their space, and the one remaining item (the card) gets
       auto-placed into the FIRST track instead of centering across
       the whole width. That's the exact bug this overrides: on
       narrow screens the wrap drops the grid entirely and goes back
       to a plain centered flex row, same as before the split-screen
       layout existed. */
    .portal-auth-wrap{ display:flex; justify-content:center; }
  }

  .spinner{
    display:inline-block; width:15px; height:15px;
    border:2px solid rgba(14,27,44,0.3);
    border-top-color:var(--navy-deep);
    border-radius:50%;
    margin-right:8px; vertical-align:-2px;
    animation:spin 0.7s linear infinite;
  }
  @keyframes spin{ to{ transform:rotate(360deg); } }
  @media (prefers-reduced-motion: reduce){ .spinner{ animation-duration:0.01ms; } }

  .form-alert{
    display:none;
    align-items:flex-start; gap:10px;
    background:#FBEAE9;
    border:1px solid #E8B4B0;
    color:#8A3226;
    border-radius:10px;
    padding:13px 15px;
    font-size:0.88rem;
    line-height:1.5;
    margin-bottom:20px;
  }
  .form-alert.show{ display:flex; }
  .form-alert a{ color:#8A3226; font-weight:700; text-decoration:underline; }

  .balance-warning{
    display:flex;
    align-items:flex-start; gap:10px;
    background:#FCEFDD;
    border:1px solid #EAD2A3;
    color:#8A5A16;
    border-radius:10px;
    padding:13px 15px;
    font-size:0.88rem;
    line-height:1.5;
    margin-bottom:20px;
  }
  .balance-warning svg{ flex:none; margin-top:1px; }

  .form-privacy{
    display:flex; align-items:flex-start; gap:10px;
    margin:8px 0 24px;
    font-size:0.85rem;
    opacity:0.85;
    line-height:1.5;
  }
  .form-privacy input{ margin-top:3px; accent-color:var(--teal); flex:none; }
  .form-privacy a{ color:var(--teal); font-weight:600; text-decoration:underline; text-underline-offset:2px; }

  .portal-success-icon{
    width:56px; height:56px;
    border-radius:50%;
    background:rgba(47,110,100,0.12);
    color:var(--teal);
    display:flex; align-items:center; justify-content:center;
    margin:8px auto 18px;
  }
  .portal-success-icon svg{ width:28px; height:28px; }

  /* ---------- Client Portal card ---------- */
  .portal-card{
    width:100%; max-width:420px; min-width:0;
    background:var(--white);
    border-radius:22px;
    box-shadow:var(--shadow);
    padding:36px 32px 32px;
    position:relative;
  }
  .portal-card.is-dashboard{ max-width:640px; }
  #portalCard{ justify-self:center; align-self:center; } /* centers within its half of the auth-wrap grid — a no-op for the other .portal-card views, which aren't grid items */
  .portal-view{ display:none; }
  .portal-view.active{ display:block; }

  .portal-close{
    position:absolute; top:18px; right:18px;
    width:34px; height:34px;
    border-radius:50%;
    border:none;
    background:var(--cream-dim);
    color:var(--navy);
    cursor:pointer;
    display:flex; align-items:center; justify-content:center;
    text-decoration:none;
  }
  .portal-close:hover{ background:var(--line); }
  .portal-close svg{ width:16px; height:16px; }

  .portal-eyebrow-row{ display:flex; align-items:center; gap:10px; margin-bottom:6px; }
  .portal-tag{
    font-family:'Barlow Semi Condensed', sans-serif;
    text-transform:uppercase;
    letter-spacing:0.1em;
    font-size:0.68rem;
    font-weight:600;
    color:var(--teal);
    background:rgba(47,110,100,0.1);
    padding:3px 9px;
    border-radius:100px;
  }
  .portal-card h3{ font-size:1.5rem; margin:0 0 6px; padding-right:20px; }
  .portal-card p.portal-sub{ margin:0 0 26px; font-size:0.92rem; opacity:0.75; }

  .portal-field{ margin-bottom:16px; }
  .portal-field label{
    display:block;
    font-family:'Barlow Semi Condensed', sans-serif;
    text-transform:uppercase;
    letter-spacing:0.06em;
    font-size:0.72rem;
    font-weight:600;
    color:var(--asphalt);
    opacity:0.75;
    margin-bottom:6px;
  }
  .portal-field input{
    width:100%;
    padding:12px 14px;
    border-radius:10px;
    border:1.5px solid var(--line);
    background:var(--cream);
    font-family:'Inter', sans-serif;
    font-size:0.95rem;
    color:var(--navy);
  }
  .portal-field input:focus-visible{ border-color:var(--teal); }

  .portal-row-between{
    display:flex; align-items:center; justify-content:space-between;
    margin-bottom:22px;
    font-size:0.86rem;
  }
  .portal-remember{ display:flex; align-items:center; gap:8px; opacity:0.8; }
  .portal-remember input{ accent-color:var(--teal); }
  .portal-forgot{
    background:none; border:none; padding:0;
    color:var(--teal); font-weight:600; cursor:pointer;
    font-size:0.86rem; text-decoration:underline; text-underline-offset:3px;
  }

  .portal-submit{
    width:100%;
    padding:13px;
    border:none;
    border-radius:100px;
    background:var(--amber);
    color:var(--navy-deep);
    font-weight:700;
    font-size:0.98rem;
    cursor:pointer;
    transition:background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  }
  .portal-submit[disabled]{ opacity:0.5; cursor:not-allowed; }
  .portal-submit[disabled]:hover{ background:var(--amber); transform:none; }
  .portal-submit:hover{ background:var(--amber-dim); transform:translateY(-1px); }

  .portal-help{ text-align:center; margin-top:20px; font-size:0.84rem; opacity:0.65; }
  .portal-help a{ color:var(--teal); font-weight:600; text-decoration:underline; text-underline-offset:3px; }

  /* Forgot-password view */
  .portal-back{
    display:inline-flex; align-items:center; gap:6px;
    background:none; border:none; padding:0;
    color:var(--teal); font-weight:600; cursor:pointer;
    font-size:0.86rem; margin-bottom:18px;
    text-decoration:none;
  }
  .portal-confirm{
    background:var(--cream-dim);
    border-left:3px solid var(--teal);
    border-radius:8px;
    padding:14px 16px;
    font-size:0.9rem;
    margin-bottom:6px;
  }

  /* Dashboard view */
  .portal-dash-head{
    display:flex; align-items:flex-start; justify-content:space-between;
    gap:16px;
    margin-bottom:24px;
    padding-right:20px;
  }
  .portal-dash-logo{ height:45px; width:auto; flex:none; }
  .portal-dash-head-right{ display:flex; flex-direction:row; align-items:center; gap:16px; flex:none; }
  .portal-dash-head-right h3{ margin:0; font-size:1.4rem; text-align:right; white-space:nowrap; }
  .portal-dash-actions{ display:flex; align-items:center; gap:10px; flex:none; }
  .portal-settings-gear{
    background:none;
    border:1.5px solid var(--line);
    border-radius:50%;
    width:40px;
    height:40px;
    padding:0;
    display:flex;
    align-items:center;
    justify-content:center;
    color:var(--navy);
    cursor:pointer;
    flex:none;
  }
  .portal-settings-gear:hover{ border-color:var(--teal); color:var(--teal); }
  .portal-logout{
    background:none;
    border:1.5px solid var(--line);
    border-radius:100px;
    padding:8px 16px;
    font-size:0.82rem;
    font-weight:600;
    color:var(--navy);
    cursor:pointer;
    flex:none;
  }
  .portal-logout:hover{ border-color:var(--teal); color:var(--teal); }

  /* Dashboard panel layout — single stacked column by default (phones
     and tablets); a named grid-template-areas layout is what lets the
     wide-screen version below reflow into two columns (My Schedule
     moved beside Program Progress/Next Session) without depending on
     DOM order, so the stacked reading order here stays sensible on
     its own. */
  .portal-grid{
    display:grid;
    grid-template-columns:1fr;
    grid-template-areas:
      "progress"
      "next"
      "calendar"
      "balance"
      "documents"
      "message";
    gap:16px;
    margin-bottom:16px;
  }
  .panel-progress{ grid-area:progress; }
  .panel-next{ grid-area:next; }
  .panel-calendar{ grid-area:calendar; }
  .panel-balance{ grid-area:balance; }
  .panel-documents{ grid-area:documents; }
  .panel-message{ grid-area:message; }
  .portal-panel{ background:var(--cream-dim); border-radius:16px; padding:20px; }
  .portal-panel h4{
    font-family:'Barlow Semi Condensed', sans-serif;
    text-transform:uppercase;
    letter-spacing:0.06em;
    font-size:0.74rem;
    font-weight:600;
    color:var(--asphalt);
    opacity:0.7;
    margin:0 0 10px;
  }
  .portal-big{ font-family:'Fraunces', serif; font-size:1.7rem; color:var(--navy); }
  .portal-panel .fine{ font-size:0.82rem; opacity:0.7; margin-top:4px; }

  .progress-count-btn{ background:none; border:none; padding:0; margin:0; cursor:pointer; display:block; text-align:left; }
  .progress-count-btn:hover{ text-decoration:underline; }
  .progress-count-btn:focus-visible{ outline:2px solid var(--amber); outline-offset:3px; border-radius:4px; }

  .modal-overlay{ position:fixed; inset:0; background:rgba(14,27,44,0.5); z-index:200; display:none; align-items:center; justify-content:center; padding:20px; }
  .modal-overlay.open{ display:flex; }
  .modal-card{ background:var(--white); border-radius:16px; padding:24px; max-width:560px; width:100%; box-shadow:var(--shadow); max-height:85vh; overflow-y:auto; }
  .modal-header{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:16px; }
  .modal-header h3{ font-family:'Fraunces', serif; color:var(--navy); font-size:1.15rem; margin:0; }
  .modal-close{ background:var(--cream-dim); border:none; border-radius:50%; width:32px; height:32px; display:flex; align-items:center; justify-content:center; cursor:pointer; color:var(--navy); flex:none; }
  .progress-table-wrap{ overflow-x:auto; }
  .progress-table{ width:100%; border-collapse:collapse; font-size:0.88rem; }
  .progress-table th{
    text-align:left;
    font-family:'Barlow Semi Condensed', sans-serif;
    text-transform:uppercase;
    letter-spacing:0.04em;
    font-size:0.68rem;
    font-weight:600;
    color:var(--asphalt);
    opacity:0.65;
    padding:10px 12px;
    border-bottom:1px solid var(--line);
    white-space:nowrap;
  }
  .progress-table td{ padding:11px 12px; border-bottom:1px solid var(--line); color:var(--navy); }
  .progress-table tr:last-child td{ border-bottom:none; }
  .progress-table td:not(:first-child), .progress-table th:not(:first-child){ text-align:center; }
  @media (max-width:480px){
    .progress-table{ min-width:440px; }
  }

  /* Signature pad (attendance verification) */
  .sig-pad-wrap{ position:relative; border:1.5px dashed var(--line); border-radius:12px; background:var(--cream); overflow:hidden; }
  .sig-pad{ display:block; width:100%; height:170px; cursor:crosshair; touch-action:none; }
  .sig-pad-placeholder{
    position:absolute; top:50%; left:50%;
    transform:translate(-50%, -50%);
    color:var(--asphalt);
    opacity:0.32;
    font-family:'Barlow Semi Condensed', sans-serif;
    text-transform:uppercase;
    letter-spacing:0.1em;
    font-size:0.85rem;
    pointer-events:none;
  }
  .sig-actions{ display:flex; justify-content:flex-end; margin-top:8px; }
  .sig-clear-btn{
    background:none;
    border:1.5px solid var(--line);
    border-radius:100px;
    padding:6px 16px;
    font-size:0.8rem;
    font-weight:600;
    color:var(--navy);
    cursor:pointer;
  }
  .sig-clear-btn:hover{ border-color:var(--teal); color:var(--teal); }

  .portal-progress-track{ height:8px; border-radius:100px; background:var(--line); overflow:hidden; margin:12px 0 8px; }
  .portal-progress-fill{ height:100%; border-radius:100px; background:var(--teal); width:30%; }

  .portal-doc-row{
    display:flex; align-items:center; justify-content:space-between;
    padding:11px 0;
    border-bottom:1px solid var(--line);
    font-size:0.9rem;
    gap:12px;
  }
  .portal-doc-row:last-child{ border-bottom:none; }
  .portal-doc-btn{
    background:var(--white);
    border:1.5px solid var(--line);
    border-radius:100px;
    padding:6px 14px;
    font-size:0.78rem;
    font-weight:600;
    color:var(--navy);
    cursor:pointer;
    flex:none;
  }
  .portal-doc-btn:hover{ border-color:var(--teal); color:var(--teal); }

  .portal-settings-row{ display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:12px; margin-bottom:14px; }
  .portal-settings-row:last-child{ margin-bottom:0; }
  .portal-settings-select{
    border-radius:10px;
    border:1.5px solid var(--line);
    background:var(--white);
    font-family:'Inter', sans-serif;
    font-size:0.88rem;
    padding:7px 10px;
    color:var(--navy);
  }

  .portal-msg-box{
    width:100%;
    min-height:70px;
    border-radius:10px;
    border:1.5px solid var(--line);
    background:var(--white);
    font-family:'Inter', sans-serif;
    font-size:0.9rem;
    padding:12px;
    resize:vertical;
    margin-bottom:10px;
  }
  .portal-send-btn{
    background:var(--navy);
    color:var(--cream);
    border:none;
    border-radius:100px;
    padding:10px 20px;
    font-size:0.85rem;
    font-weight:600;
    cursor:pointer;
  }
  .portal-send-btn:hover{ background:var(--amber-dim); color:var(--navy-deep); }
  .portal-toast{ margin-top:10px; font-size:0.84rem; color:var(--teal); font-weight:600; display:none; }
  .portal-toast.show{ display:block; }

  .portal-msg-thread{ max-height:220px; overflow-y:auto; margin-bottom:12px; display:flex; flex-direction:column; gap:8px; }
  .portal-msg-resolved-banner{ font-size:0.82rem; color:var(--teal); font-weight:600; margin-bottom:10px; }
  .portal-msg-bubble{ max-width:85%; padding:8px 12px; border-radius:12px; font-size:0.85rem; line-height:1.4; white-space:pre-wrap; word-break:break-word; }
  .portal-msg-bubble.from-client{ align-self:flex-end; background:var(--navy); color:var(--cream); border-bottom-right-radius:3px; }
  .portal-msg-bubble.from-facility{ align-self:flex-start; background:var(--white); border:1.5px solid var(--line); border-bottom-left-radius:3px; }
  .portal-msg-bubble .msg-meta{ display:block; font-size:0.7rem; opacity:0.65; margin-top:3px; }
  .msg-delete-btn{
    background:none; border:none; padding:0; margin-left:8px;
    font-size:0.7rem; font-weight:600; text-decoration:underline;
    color:inherit; opacity:0.85; cursor:pointer;
  }
  .msg-delete-btn:hover{ opacity:1; }
  .msg-delete-btn:disabled{ opacity:0.4; cursor:not-allowed; }

  /* My Schedule calendar — embedded directly in the dashboard, always
     visible (no button to reveal it). */
  .portal-cal-nav{
    display:flex; align-items:center; justify-content:center; gap:14px;
    margin-bottom:14px;
  }
  .portal-cal-nav button{
    width:30px; height:30px; border-radius:8px;
    border:1.5px solid var(--line); background:var(--white);
    color:var(--navy); cursor:pointer;
    display:flex; align-items:center; justify-content:center;
    flex:none;
  }
  .portal-cal-nav button:hover{ border-color:var(--teal); color:var(--teal); }
  .portal-cal-month-label{
    font-family:'Fraunces', serif;
    font-size:1rem;
    color:var(--navy);
    min-width:130px;
    text-align:center;
  }
  .portal-cal-grid-wrap{
    border:1px solid var(--line);
    border-radius:12px;
    overflow:hidden;
  }
  .portal-cal-weekdays{
    display:grid; grid-template-columns:repeat(7, 1fr);
    background:var(--white);
    font-family:'Barlow Semi Condensed', sans-serif;
    text-transform:uppercase;
    letter-spacing:0.05em;
    font-size:0.66rem;
    font-weight:700;
    color:var(--asphalt);
    opacity:0.65;
  }
  .portal-cal-weekdays div{ padding:8px 2px; text-align:center; }
  .portal-cal-days{ display:grid; grid-template-columns:repeat(7, 1fr); }
  .portal-cal-day{
    min-height:52px;
    border-right:1px solid var(--line);
    border-bottom:1px solid var(--line);
    padding:4px 3px;
    display:flex; flex-direction:column; align-items:center; gap:3px;
  }
  .portal-cal-day:nth-child(7n){ border-right:none; }
  .portal-cal-day.other-month{ background:var(--white); }
  .portal-cal-day.other-month .portal-cal-day-number{ opacity:0.35; }
  .portal-cal-day-number{ font-size:0.78rem; font-weight:600; color:var(--navy); }
  .portal-cal-day.today .portal-cal-day-number{
    background:var(--navy); color:var(--cream);
    width:19px; height:19px; border-radius:50%;
    display:flex; align-items:center; justify-content:center;
    font-size:0.7rem;
  }
  .portal-cal-dot-row{ display:flex; gap:3px; flex-wrap:wrap; justify-content:center; }
  .portal-cal-dot{ width:7px; height:7px; border-radius:50%; background:var(--teal); flex:none; }
  .portal-cal-dot.is-completed{ background:var(--teal); }
  .portal-cal-dot.is-cancelled{ background:#C0392B; }
  .portal-cal-dot.is-missed{ background:#C0392B; }
  .portal-cal-day.has-sessions{ cursor:pointer; }
  .portal-cal-day.has-sessions:hover{ background:var(--white); }
  .portal-cal-day.selected{ background:var(--white); box-shadow:inset 0 0 0 1.5px var(--teal); }
  .portal-cal-empty{ text-align:center; padding:24px; opacity:0.6; font-size:0.88rem; }

  .portal-cal-detail{
    margin-top:14px;
    background:var(--white);
    border:1px solid var(--line);
    border-radius:12px;
    padding:14px 16px;
  }
  .portal-cal-detail-head{
    display:flex; align-items:center; justify-content:space-between;
    font-family:'Fraunces', serif;
    font-size:0.95rem;
    color:var(--navy);
    margin-bottom:10px;
  }
  .portal-cal-detail-head button{
    background:none; border:none; cursor:pointer; color:var(--asphalt); opacity:0.6;
    display:flex; align-items:center; padding:2px;
  }
  .portal-cal-detail-head button:hover{ opacity:1; }
  .portal-cal-session-row{
    background:var(--cream-dim);
    border-radius:10px;
    padding:10px 12px;
    margin-bottom:8px;
    font-size:0.85rem;
  }
  .portal-cal-session-row:last-child{ margin-bottom:0; }
  .portal-cal-session-time{ font-weight:700; color:var(--navy); }
  .portal-cal-session-meta{ opacity:0.7; font-size:0.8rem; margin-top:2px; }
  .portal-cal-status{
    display:inline-block;
    font-family:'Barlow Semi Condensed', sans-serif;
    text-transform:uppercase;
    letter-spacing:0.05em;
    font-size:0.64rem;
    font-weight:700;
    padding:2px 9px;
    border-radius:100px;
    margin-top:6px;
  }
  .portal-cal-status.scheduled{ background:#FCEFDD; color:#8A5A16; }
  .portal-cal-status.completed{ background:rgba(47,110,100,0.12); color:var(--teal); }
  .portal-cal-status.cancelled{ background:#FBEAE9; color:#8A3226; }
  .portal-cal-status.no-show{ background:var(--white); color:var(--asphalt); border:1px solid var(--line); }
  .portal-cal-status.missed{ background:#FBEAE9; color:#8A3226; }

  /* Wide-screen dashboard: Account Balance/Documents/Message form a
     left column; Program Progress and Next Session sit side by side
     at the top of a right column, with My Schedule (the calendar)
     moved beside them, spanning the same width below. Below this
     breakpoint the dashboard stays a single stacked column — plenty
     of room for a 4-track grid is genuinely a desktop-only luxury
     here, not something a phone or most tablets have to spare. */
  @media (min-width:860px){
    .portal-card.is-dashboard-wide{ max-width:1160px; }
    .portal-grid{
      grid-template-columns:repeat(4, 1fr);
      grid-template-areas:
        "balance   balance   progress  next"
        "documents documents calendar  calendar"
        "message   message   calendar  calendar";
    }
  }

  @media (max-width:560px){
    .portal-card{ padding:28px 22px 24px; }
    .portal-cal-day{ min-height:40px; padding:3px 2px; }
    .portal-cal-month-label{ min-width:110px; font-size:0.92rem; }
    .portal-dash-head{ flex-direction:column; align-items:flex-start; gap:14px; padding-right:0; }
    .portal-dash-head-right{ justify-content:space-between; width:100%; }
    .portal-dash-head-right h3{ text-align:left; font-size:1.25rem; }
  }
