:root {
  color-scheme: light;
  font-family: Inter, Aptos, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #102f27;
  background: #f8faf8;
  font-synthesis: none;
  --forest-950: #063c31;
  --forest-900: #08483a;
  --forest-800: #0d5b48;
  --forest-700: #197054;
  --green-600: #25834c;
  --paper: #fffefb;
  --canvas: #f8faf8;
  --line: #dce5df;
  --line-soft: #e9eeeb;
  --muted: #687b74;
  --blue: #1667c8;
  --orange: #ec6b18;
  --purple: #7240b8;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid rgba(30, 130, 82, .3); outline-offset: 2px; }
h1, h2, p { margin-top: 0; }

.portal-app { min-height: 100vh; display: grid; grid-template-columns: 204px minmax(0, 1fr); background: var(--paper); }
.portal-sidebar { position: sticky; inset: 0 auto 0 0; height: 100vh; display: flex; flex-direction: column; color: #fff; background: linear-gradient(180deg, #073e33 0%, #075043 58%, #063b32 100%); box-shadow: 8px 0 30px rgba(5, 49, 39, .08); z-index: 10; }
.brand-lockup { min-height: 236px; display: grid; place-items: center; padding: 25px 24px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand-lockup img { display: block; width: 146px; height: 174px; object-fit: contain; border-radius: 10px; background: #fbfaf6; box-shadow: 0 10px 24px rgba(0, 0, 0, .12); }
.portal-nav { display: grid; gap: 7px; padding: 18px 0; }
.portal-nav a { position: relative; min-height: 64px; display: flex; align-items: center; gap: 15px; padding: 0 20px 0 28px; color: rgba(255, 255, 255, .88); text-decoration: none; font-size: 16px; font-weight: 650; transition: background .18s ease, color .18s ease; }
.portal-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.portal-nav a.active { color: #fff; background: rgba(61, 151, 98, .28); }
.portal-nav a.active::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: #82d19b; }
.portal-nav .ph { width: 24px; font-size: 24px; }
.nav-badge { margin-left: auto; padding: 4px 8px; border-radius: 7px; background: rgba(143, 212, 162, .28); color: #e7ffec; font-size: 11px; font-weight: 800; white-space: nowrap; }
.company-mark { margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 22px 26px 28px; border-top: 1px solid rgba(255, 255, 255, .1); color: #fff; font-size: 14px; font-weight: 700; }
.company-mark .ph { font-size: 22px; color: #b8e7c6; }

.portal-main { min-width: 0; background: var(--paper); }
.portal-topbar { min-height: 154px; display: flex; align-items: flex-start; justify-content: space-between; gap: 32px; padding: 30px 34px 24px; border-bottom: 1px solid var(--line); background: rgba(255, 254, 251, .98); }
.portal-topbar h1 { margin: 0 0 6px; font-size: clamp(25px, 2.1vw, 34px); line-height: 1.12; letter-spacing: -.035em; color: #0b3d32; }
.portal-topbar p { margin: 0; color: var(--muted); font-size: 14px; }
.mobile-brand { display: none; }
.topbar-actions { display: grid; justify-items: end; gap: 22px; }
.topbar-actions time { color: #42564f; font-size: 13px; }
.portal-button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--forest-900); border-radius: 5px; padding: 10px 16px; background: var(--forest-900); color: #fff; font-weight: 750; line-height: 1; cursor: pointer; box-shadow: 0 4px 12px rgba(7, 72, 58, .12); transition: background .18s ease, transform .18s ease, box-shadow .18s ease; }
.portal-button:hover { background: var(--forest-800); box-shadow: 0 6px 16px rgba(7, 72, 58, .18); transform: translateY(-1px); }
.portal-button:disabled { cursor: wait; opacity: .58; transform: none; }
.portal-button.compact { min-height: 34px; padding: 8px 12px; border-radius: 4px; font-size: 12px; }
.refresh-button { min-width: 130px; }
.refresh-button .ph { font-size: 19px; }
.portal-message { margin: 18px 34px 0; padding: 13px 15px; border: 1px solid #ead99e; border-radius: 7px; background: #fff8dd; color: #695317; font-size: 14px; }

.portal-stats { min-height: 114px; display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.portal-stat { display: grid; grid-template-columns: 50px auto; grid-template-rows: auto auto; align-content: center; column-gap: 14px; position: relative; padding: 18px 28px; }
.portal-stat:not(:last-child)::after { content: ""; position: absolute; right: 0; top: 24px; bottom: 24px; width: 1px; background: var(--line); }
.portal-stat .ph { grid-row: 1 / 3; align-self: center; font-size: 40px; color: #408c57; }
.portal-stat strong { font-size: 29px; line-height: 1; letter-spacing: -.03em; color: #0d3b31; }
.portal-stat span { align-self: end; color: #253b34; font-size: 13px; }
.mobile-segments { display: none; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 304px; }
.dashboard-content { min-width: 0; padding: 0 32px 54px; }
.data-section, .settings-section { scroll-margin-top: 22px; padding-top: 24px; }
.data-section:focus, .settings-section:focus { outline: none; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: -.02em; color: #15352d; }
.section-kicker { display: block; margin-bottom: 4px; color: #6d817a; font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.section-count { padding: 5px 8px; border-radius: 5px; background: #edf2ef; color: #53675f; font-size: 11px; font-weight: 800; }
.section-count.is-new { background: #e6f1e6; color: #287143; }
.section-count.is-on { background: #e3f1e5; color: #217442; }
.desktop-table { width: 100%; overflow: hidden; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { padding: 12px 9px; color: #294039; font-size: 11px; font-weight: 800; text-align: left; }
td { padding: 13px 9px; border-top: 1px solid var(--line-soft); color: #31453f; font-size: 12px; vertical-align: middle; }
th:nth-child(1), td:nth-child(1) { width: 12%; }
th:nth-child(2), td:nth-child(2) { width: 31%; }
th:nth-child(3), td:nth-child(3) { width: 16%; }
th:nth-child(4), td:nth-child(4) { width: 23%; }
th:nth-child(5), td:nth-child(5) { width: 18%; }
td strong { color: #173b31; }
.portal-action-cell { text-align: right; }
.portal-status { display: inline-flex; align-items: center; gap: 7px; color: var(--blue); font-size: 11px; font-weight: 750; line-height: 1.3; }
.status-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: currentColor; }
.portal-status.shipping { color: var(--orange); }
.portal-status.received, .portal-status.ready { color: var(--green-600); }
.portal-lock { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 4px; background: #efefed; color: #6d6d68; font-size: 11px; font-weight: 700; }
.portal-muted { color: #8d9b96; }
.mobile-list { display: none; }

.referrals-section { padding-top: 28px; }
.referral-list { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.referral-columns, .referral-row { display: grid; grid-template-columns: 1.25fr .65fr .75fr 1.25fr 1fr; gap: 16px; align-items: center; }
.referral-columns { padding: 11px 10px; color: #455b53; font-size: 10px; font-weight: 800; }
.referral-row { position: relative; padding: 14px 10px; border-top: 1px solid var(--line-soft); color: #3b5049; font-size: 11px; }
.referral-row.is-new::before { content: ""; position: absolute; inset: 7px auto 7px 0; width: 3px; border-radius: 3px; background: #7240b8; }
.referral-person { display: grid; gap: 4px; min-width: 0; }
.referral-person strong { color: #183a31; font-size: 12px; }
.referral-person span, .referral-context { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.referral-status { display: inline-flex; align-items: center; gap: 7px; color: #697671; font-weight: 750; }
.referral-status.new { color: var(--purple); }
.referral-date, .referral-context { color: #5e706a; }
.referral-action { text-align: right; }
.scheduled-note { display: inline-flex; align-items: center; gap: 6px; color: var(--green-600); font-weight: 700; line-height: 1.35; }
.scheduled-note .ph { font-size: 17px; }
.mobile-label { display: none; }
.schedule-panel { grid-column: 1 / -1; margin: 5px -1px -2px; padding: 16px; border-radius: 8px; background: #f3f7f4; }
.schedule-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.schedule-heading span { color: var(--muted); }
.schedule-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.schedule-slot { min-height: 40px; border: 1px solid #b9cec2; border-radius: 5px; background: #fff; color: var(--forest-900); font-size: 11px; font-weight: 750; cursor: pointer; }
.schedule-slot:hover { border-color: var(--forest-700); background: #eaf4ee; }

.activity-panel { min-width: 0; padding: 24px 24px 50px; border-left: 1px solid var(--line); background: #fffefb; }
.activity-list { display: grid; }
.activity-item { display: grid; grid-template-columns: 60px minmax(0, 1fr); gap: 10px; padding: 15px 0; border-bottom: 1px solid var(--line-soft); }
.activity-item time { color: #2f453e; font-size: 11px; }
.activity-item strong { display: block; margin-bottom: 4px; font-size: 11px; font-weight: 750; }
.activity-item p { margin: 0; overflow: hidden; color: #73817d; font-size: 10px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.activity-label.scheduled { color: var(--blue); }
.activity-label.shipping { color: var(--orange); }
.activity-label.received, .activity-label.ready { color: var(--green-600); }
.activity-label.referral { color: var(--purple); }
.activity-empty { padding: 20px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.settings-section { padding-top: 30px; }
.settings-panel { padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: #fbfdfb; }
.email-settings-stack { display: grid; gap: 18px; }
.portal-field { display: grid; gap: 7px; color: #29463c; font-size: 13px; font-weight: 800; }
.portal-field textarea { width: 100%; min-height: 86px; resize: vertical; border: 1px solid #b9cbc2; border-radius: 6px; padding: 11px 12px; color: #18352d; background: #fff; font-weight: 500; line-height: 1.5; }
.portal-field small, .portal-check small { color: #6c7f78; font-size: 11px; font-weight: 500; }
.settings-options { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 17px; }
.portal-check { display: flex; align-items: flex-start; gap: 10px; }
.portal-check input { width: 17px; height: 17px; flex: 0 0 auto; margin: 2px 0 0; accent-color: var(--forest-700); }
.portal-check span { display: grid; gap: 4px; color: #29463c; font-size: 12px; }
.portal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 20px; }
.portal-actions > span { color: #577168; font-size: 11px; font-weight: 800; }
.portal-empty { padding: 26px; border: 1px dashed #cbd8d1; border-radius: 7px; color: #657871; background: #fbfcfb; font-size: 13px; text-align: center; }

.portal-error { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--forest-950); }
.portal-error-card { width: min(480px, 100%); padding: 36px; border-radius: 10px; background: #fff; box-shadow: 0 24px 70px rgba(0, 0, 0, .2); text-align: center; }
.portal-error-card img { width: 165px; height: 132px; object-fit: contain; }
.portal-error-card h1 { margin: 16px 0 8px; font-size: 28px; }
.portal-error-card p { margin: 0; color: var(--muted); line-height: 1.55; }
.loading-icon { margin-top: 12px; font-size: 25px; color: var(--green-600); }
.loading-icon .ph-arrows-clockwise { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1120px) {
  .portal-app { grid-template-columns: 186px minmax(0, 1fr); }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr) 250px; }
  .dashboard-content { padding-inline: 22px; }
  .portal-stat { padding-inline: 20px; }
  .referral-columns, .referral-row { grid-template-columns: 1.15fr .58fr .72fr 1fr .9fr; gap: 10px; }
}

@media (max-width: 900px) {
  .portal-app { display: block; }
  .portal-sidebar { display: none; }
  .portal-topbar { min-height: auto; align-items: center; padding: 20px 22px; background: var(--forest-950); color: #fff; }
  .portal-topbar h1 { color: #fff; font-size: 24px; }
  .portal-topbar p:not(.mobile-brand) { color: rgba(255, 255, 255, .72); }
  .mobile-brand { display: block; margin-bottom: 5px !important; color: #a9dfb6 !important; font-size: 11px !important; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
  .topbar-actions time { display: none; }
  .refresh-button { min-width: 44px; width: 44px; height: 44px; padding: 0; overflow: hidden; font-size: 0; border-color: rgba(255, 255, 255, .28); background: rgba(255, 255, 255, .1); box-shadow: none; }
  .refresh-button .ph { font-size: 21px; }
  .portal-stats { min-height: auto; grid-template-columns: repeat(4, 1fr); }
  .portal-stat { padding: 18px 14px; }
  .portal-stat .ph { font-size: 34px; }
  .dashboard-grid { display: block; }
  .activity-panel { border: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 640px) {
  body { background: #f6f8f6; }
  .portal-main { background: #f6f8f6; }
  .portal-topbar { position: sticky; top: 0; z-index: 20; padding: 10px 14px; box-shadow: 0 4px 18px rgba(6, 60, 49, .16); }
  .portal-topbar h1 { margin-bottom: 0; font-size: 19px; }
  .portal-topbar p:not(.mobile-brand) { display: none; }
  .portal-message { margin: 12px 14px 0; }
  .portal-stats { grid-template-columns: repeat(2, 1fr); margin: 8px 14px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 4px 16px rgba(16, 63, 49, .04); }
  .portal-stat { min-height: 76px; grid-template-columns: 34px auto; padding: 11px 14px; }
  .portal-stat:nth-child(2)::after { display: none; }
  .portal-stat:nth-child(-n+2) { border-bottom: 1px solid var(--line-soft); }
  .portal-stat .ph { font-size: 27px; }
  .portal-stat strong { font-size: 22px; }
  .portal-stat span { font-size: 12px; }
  .mobile-segments { position: sticky; top: 60px; z-index: 15; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 6px 14px; border-bottom: 1px solid var(--line); background: rgba(246, 248, 246, .96); backdrop-filter: blur(8px); }
  .mobile-segments button { min-height: 44px; border: 0; border-radius: 7px; background: transparent; color: #63766f; font-size: 14px; font-weight: 800; cursor: pointer; }
  .mobile-segments button.active { background: var(--forest-900); color: #fff; box-shadow: 0 4px 12px rgba(7, 72, 58, .16); }
  .mobile-segments span { margin-left: 4px; padding: 2px 6px; border-radius: 5px; background: rgba(255, 255, 255, .18); font-size: 11px; }
  .dashboard-content { padding: 0 14px 32px; }
  .data-section { scroll-margin-top: 124px; padding-top: 12px; }
  .data-section .section-heading { margin-bottom: 8px; }
  .section-kicker { display: none; }
  .section-heading h2 { font-size: 19px; }
  .section-count { font-size: 12px; }
  .desktop-table { display: none; }
  .mobile-list { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: 0 4px 14px rgba(16, 63, 49, .04); }
  .mobile-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 12px; min-height: 68px; padding: 11px 12px; border-bottom: 1px solid var(--line-soft); background: #fff; }
  .mobile-item:last-child { border-bottom: 0; }
  .mobile-client { grid-column: 1; grid-row: 1 / 3; min-width: 0; }
  .mobile-client strong { color: #15392f; font-size: 15px; }
  .mobile-client p { margin: 4px 0 0; overflow: hidden; color: #687a74; font-size: 12px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-appointment { grid-column: 2; grid-row: 1; color: #586c64; font-size: 12px; text-align: right; white-space: nowrap; }
  .mobile-item .portal-status { grid-column: 2; grid-row: 2; max-width: 164px; justify-content: flex-end; font-size: 12px; text-align: right; }
  .mobile-item .status-dot { width: 7px; height: 7px; }
  .mobile-download { grid-column: 1 / -1; min-height: 46px; margin-top: 4px; font-size: 13px; }
  .mobile-payment { grid-column: 1 / -1; min-height: 44px; display: grid; place-items: center; padding: 9px; border-radius: 5px; background: #f0efeb; color: #706e66; font-size: 12px; font-weight: 750; text-align: center; }
  .referral-list { border: 0; }
  .referral-columns { display: none; }
  .referral-row { grid-template-columns: 1fr auto; gap: 12px; margin-bottom: 10px; padding: 15px; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: 0 4px 14px rgba(16, 63, 49, .04); }
  .referral-row.is-new::before { inset: 12px auto 12px 0; }
  .referral-person { grid-column: 1; }
  .referral-person strong { font-size: 16px; }
  .referral-person span { font-size: 13px; white-space: normal; line-height: 1.45; }
  .referral-date { grid-column: 1; display: flex; gap: 6px; font-size: 12px; }
  .mobile-label { display: inline; color: #7c8c86; font-size: 12px; font-weight: 750; }
  .referral-row > div:nth-child(3) { grid-column: 2; grid-row: 1; }
  .referral-status { font-size: 12px; }
  .referral-context { grid-column: 1 / -1; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 13px; line-height: 1.45; white-space: normal; }
  .referral-action { grid-column: 1 / -1; text-align: left; }
  .referral-action .portal-button { width: 100%; min-height: 48px; font-size: 14px; }
  .schedule-panel { grid-column: 1 / -1; margin: 0; }
  .schedule-heading { display: grid; font-size: 14px; }
  .schedule-heading span { font-size: 12px; }
  .schedule-grid { grid-template-columns: 1fr; }
  .schedule-slot { min-height: 48px; font-size: 13px; }
  .settings-section { padding-top: 22px; }
  .settings-panel { padding: 15px; background: #fff; }
  .portal-field { font-size: 14px; }
  .portal-field textarea { min-height: 100px; font-size: 14px; }
  .portal-field small, .portal-check small { font-size: 12px; line-height: 1.45; }
  .settings-options { grid-template-columns: 1fr; }
  .portal-check input { width: 20px; height: 20px; }
  .portal-check span { font-size: 14px; line-height: 1.4; }
  .portal-actions .portal-button { width: 100%; min-height: 48px; font-size: 14px; }
  .portal-actions > span { font-size: 12px; }
  .activity-panel { display: none; }
  .portal-error { padding: 16px; }
  .portal-error-card { padding: 28px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
