/* 05-B local integration. All values map to docs/UI_FOUNDATION.md tokens. */
.app-shell-mode {
  --shell-surface-page: #fdfbf7;
  --shell-surface-card: #fffefa;
  --shell-surface-subtle: #f5f3ee;
  --shell-border-subtle: #d9ddd9;
  --shell-border-strong: #b7c0c8;
  --shell-brand-primary: #4163a1;
  --shell-brand-dark: #324e82;
  --shell-brand-soft: #eef3fc;
  --shell-brand-yellow: #f9d387;
  --shell-brand-coral: #f49882;
  --shell-text-primary: #24354a;
  --shell-text-secondary: #4e5e70;
  --shell-text-support: #667487;
  --shell-text-helper: #5f6e7d;
  --shell-text-caption: #637184;
  --shell-text-action: #365a98;
  --shell-status-danger: #8f4346;
  --shell-status-danger-soft: #fbece8;
  --shell-focus: 0 0 0 3px rgba(65, 99, 161, .24);
  --shell-header-min-height: 72px;
  --shell-header-height: var(--shell-header-min-height);
  background: var(--shell-surface-page);
}

.app-shell-mode body {
  min-width: 0;
  overflow-x: clip;
  background: var(--shell-surface-page);
}

.app-shell-mode :where(.shared-app-shell, .shared-login-home) *,
.app-shell-mode :where(.shared-app-shell, .shared-login-home) *::before,
.app-shell-mode :where(.shared-app-shell, .shared-login-home) *::after {
  box-sizing: border-box;
}

.app-shell-mode:not(.app-shell-authenticated) :where(.p4-module-outlet, #login-home, #authenticated-shell, #toast, #action-dialog),
.app-shell-login-visible > :not(.shared-login-home):not(script) {
  display: none !important;
}

.shared-login-home {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--shell-text-primary);
  background: var(--shell-surface-page);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", sans-serif;
}

.shared-login-content {
  position: relative;
  z-index: 2;
  width: min(704px, calc(100% - 48px));
  margin: 0 auto;
  padding-top: clamp(248px, 34vh, 360px);
  padding-bottom: 304px;
}

.shared-login-copy {
  display: grid;
  gap: 12px;
  padding-inline: 16px;
}

.shared-login-copy h1 {
  margin: 0;
  color: var(--shell-text-primary);
  font-size: 32px;
  font-weight: 600;
  line-height: 40px;
}

.shared-login-copy p {
  margin: 0;
  color: var(--shell-text-support);
  font-size: 17px;
  font-weight: 400;
  line-height: 26px;
}

.shared-login-actions { margin-top: 64px; }

.shared-login-button {
  display: grid;
  width: 100%;
  min-height: 56px;
  grid-template-columns: 28px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: #fff;
  background: var(--shell-brand-primary);
  font: 600 16px/24px -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", sans-serif;
  cursor: pointer;
}

.shared-login-button:hover { background: var(--shell-brand-dark); }
.shared-login-button:disabled { cursor: progress; }
.shared-login-button:focus-visible {
  outline: 2px solid var(--shell-brand-primary);
  outline-offset: 4px;
  box-shadow: var(--shell-focus);
}

.shared-google-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  color: var(--shell-brand-primary);
  background: #fff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.shared-login-spinner {
  width: 20px;
  height: 20px;
  justify-self: end;
  border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: shared-login-spin .8s linear infinite;
}

@keyframes shared-login-spin { to { transform: rotate(360deg); } }

.shared-login-helper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 24px 0 0;
  color: var(--shell-text-helper);
  font-size: 14px;
  line-height: 21px;
  text-align: center;
}

.shared-login-helper svg {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  fill: none;
  stroke: var(--shell-brand-coral);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.shared-login-error {
  margin: 12px 0 0;
  color: var(--shell-status-danger);
  font-size: 14px;
  line-height: 21px;
  text-align: center;
}

.shared-login-release {
  margin: 10px 0 0;
  color: var(--shell-text-helper);
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}

.shared-login-top-decoration,
.shared-login-bottom-decoration {
  position: absolute;
  z-index: 1;
  inset-inline: 0;
  pointer-events: none;
}

.shared-login-top-decoration { top: 0; height: 250px; }
.shared-login-bottom-decoration { bottom: 0; height: 300px; overflow: hidden; }
.shared-brand-pattern { display: block; object-fit: contain; }
.shared-login-pattern { position: absolute; height: auto; }
.shared-login-pattern-top-pink { top: 120px; left: 17%; width: 44px; }
.shared-login-pattern-top-yellow { top: 84px; right: 27%; width: 48px; }
.shared-login-pattern-top-blue { top: 198px; right: 21%; width: 40px; }
.shared-login-wave { position: absolute; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5; }
.shared-login-wave path { vector-effect: non-scaling-stroke; }
.shared-login-wave-top { top: 58px; right: 9%; width: 88px; stroke: #8ab5d5; }
.shared-login-bottom-scene { position: absolute; z-index: 0; inset: 0; width: 100%; height: 100%; overflow: visible; }
.shared-login-cloud { stroke: none; }
.shared-login-cloud-blue { fill: #bfd2e3; }
.shared-login-cloud-pink { fill: #fb946c; }
.shared-login-cloud-yellow { fill: #f9ca88; }
.shared-login-scene-line { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; vector-effect: non-scaling-stroke; }
.shared-login-scene-line-left { stroke: #cfdfeb; }
.shared-login-scene-line-middle { stroke: #b9d4e7; }
.shared-login-scene-line-coral { stroke: #fb987e; }
.shared-login-bottom-decoration .shared-login-pattern,
.shared-login-bottom-decoration .shared-login-dot { z-index: 2; }
.shared-login-pattern-bottom-blue-one { top: 60px; left: 24%; width: 46px; }
.shared-login-pattern-bottom-yellow { top: 126px; left: 34%; width: 50px; }
.shared-login-pattern-bottom-pink { top: 132px; left: 47%; width: 52px; }
.shared-login-pattern-bottom-blue-two { top: 232px; left: 50%; width: 48px; }
.shared-login-dot { position: absolute; width: 16px; height: 16px; border-radius: 50%; }
.shared-login-dot-one { top: 36px; left: 9%; background: var(--shell-brand-coral); }
.shared-login-dot-two { top: 72px; right: 22%; width: 18px; height: 18px; background: var(--shell-brand-yellow); }
.shared-login-dot-three { top: 116px; right: 16%; background: var(--shell-brand-coral); }
.shared-login-dot-four { top: 156px; left: 61%; background: var(--shell-brand-primary); }
.shared-login-dot-five { top: 184px; left: 29%; background: var(--shell-brand-coral); }
.shared-login-dot-six { top: 100px; left: 58%; width: 18px; height: 18px; background: var(--shell-brand-yellow); }

.shared-app-shell {
  position: relative;
  z-index: 100;
  width: 100%;
  height: var(--shell-header-height);
  color: var(--shell-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", sans-serif;
}

.shared-shell-header {
  position: fixed;
  z-index: 100;
  inset: 0 0 auto;
  min-height: var(--shell-header-min-height);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--shell-border-subtle);
  background: color-mix(in srgb, var(--shell-surface-page) 96%, transparent);
  backdrop-filter: blur(16px);
}

.shared-shell-inner {
  display: flex;
  width: min(100%, 1020px);
  min-height: var(--shell-header-min-height);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto;
  padding: 8px 16px;
}

.shared-module-button,
.shared-shell-icon-button {
  min-height: 44px;
  border: 0;
  color: var(--shell-text-action);
  background: transparent;
  cursor: pointer;
}

.shared-module-button {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  font-size: 20px;
  font-weight: 600;
  line-height: 28px;
  text-align: left;
}

.shared-module-button span { min-width: 0; overflow-wrap: anywhere; }
.shared-module-button svg { width: 20px; height: 20px; flex: 0 0 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.shared-shell-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; }
.shared-shell-icon-button { display: grid; width: 44px; padding: 10px; place-items: center; border-radius: 12px; }
.shared-shell-icon-button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.shared-module-button:hover,
.shared-shell-icon-button:hover { background: var(--shell-brand-soft); }
.shared-module-button:focus-visible,
.shared-shell-icon-button:focus-visible,
.shared-module-menu button:focus-visible,
.shared-p4-context button:focus-visible,
.shared-discard-dialog button:focus-visible {
  outline: 2px solid var(--shell-brand-primary);
  outline-offset: 2px;
  box-shadow: var(--shell-focus);
}

.shared-notification-icon { position: relative; display: block; width: 24px; height: 24px; }
.shared-notification-button[data-has-unfinished-responsibility="true"] { color: #8f4346; }
.shared-notification-button[data-has-unfinished-responsibility="true"] svg path:first-child { fill: var(--shell-brand-coral); }
.shared-notification-dot { position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border: 2px solid var(--shell-surface-page); border-radius: 50%; background: var(--shell-brand-primary); }

.shared-shell-scrim {
  position: fixed;
  z-index: 101;
  inset: var(--shell-header-height) 0 0;
  background: rgba(36, 53, 74, .22);
}

.shared-module-menu {
  position: fixed;
  z-index: 102;
  top: calc(var(--shell-header-height) + 8px);
  left: max(16px, calc((100vw - 1020px) / 2 + 16px));
  width: min(304px, calc(100vw - 32px));
  padding: 8px;
  border: 1px solid var(--shell-border-subtle);
  border-radius: 16px;
  background: var(--shell-surface-card);
  box-shadow: 0 12px 32px rgba(36, 53, 74, .10);
}

.shared-module-menu > p { margin: 4px 8px 8px; color: var(--shell-text-caption); font-size: 12px; line-height: 18px; }
.shared-module-menu button {
  display: flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  color: var(--shell-text-secondary);
  background: transparent;
  font-size: 16px;
  line-height: 24px;
  text-align: left;
  cursor: pointer;
}
.shared-module-menu button[aria-checked="true"] { color: var(--shell-text-action); background: var(--shell-brand-soft); font-weight: 600; }
.shared-module-menu button:hover { background: var(--shell-surface-subtle); }

.shared-discard-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--shell-border-subtle);
  border-radius: 24px;
  color: var(--shell-text-primary);
  background: var(--shell-surface-card);
  box-shadow: 0 24px 64px rgba(36, 53, 74, .18);
}
.shared-discard-dialog::backdrop { background: rgba(36, 53, 74, .38); }
.shared-discard-dialog form { padding: 24px; }
.shared-discard-dialog h2 { margin: 0; font-size: 22px; font-weight: 600; line-height: 30px; }
.shared-discard-dialog p { margin: 12px 0 24px; color: var(--shell-text-secondary); font-size: 16px; line-height: 24px; }
.shared-discard-dialog form > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; }
.shared-discard-dialog button { min-height: 44px; padding: 10px 16px; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; }
.shared-dialog-safe { border: 1px solid var(--shell-border-strong); color: var(--shell-text-action); background: var(--shell-surface-card); }
.shared-dialog-danger { border: 1px solid var(--shell-status-danger); color: #fff; background: var(--shell-status-danger); }

.app-shell-module-p4.app-shell-authenticated {
  --p4-module-sticky-offset: var(--shell-header-height);
}
.app-shell-module-p5.app-shell-authenticated {
  --p5-module-sticky-offset: var(--shell-header-height);
}
.app-shell-module-p4.app-shell-authenticated .p4-module-outlet {
  min-height: calc(100vh - var(--shell-header-height));
  padding-top: 20px;
}
.app-shell-module-p4.app-shell-authenticated :is(.treatment-transition-sheet, .treatment-schedule-query-sheet, .waiting-case-action-sheet, .group-management-sheet) {
  top: calc(var(--shell-header-height) + env(safe-area-inset-top));
  height: calc(100dvh - var(--shell-header-height) - env(safe-area-inset-top));
  max-height: calc(100dvh - var(--shell-header-height) - env(safe-area-inset-top));
}
.app-shell-module-p4.app-shell-authenticated .p4-module-header,
.app-shell-module-p4.app-shell-authenticated .role-preview,
.app-shell-module-p4.app-shell-authenticated .identity-strip {
  display: none !important;
}
.shared-p4-context { margin: 0 0 12px; }
.shared-access-denied {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-left: 4px solid var(--shell-status-danger);
  border-radius: 8px;
  color: var(--shell-status-danger);
  background: var(--shell-status-danger-soft);
  font-size: 14px;
  line-height: 21px;
}
.shared-p4-context-row { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 12px; }
.shared-p4-role-switch,
.shared-p4-context-label,
.shared-p4-secondary-context { margin: 0; color: var(--shell-text-caption); font-size: 14px; line-height: 21px; }
.shared-p4-role-switch {
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  color: var(--shell-text-support);
  background: transparent;
  cursor: pointer;
}
.shared-p4-role-switch::first-letter { color: var(--shell-text-action); }
.shared-p4-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; }
.shared-p4-actions button { display: grid; width: 44px; min-height: 44px; padding: 10px; place-items: center; border: 0; border-radius: 12px; color: var(--shell-text-action); background: transparent; cursor: pointer; }
.shared-p4-actions button:hover { background: var(--shell-brand-soft); }
.shared-p4-actions svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.shared-tune-icon circle { fill: var(--shared-surface, #fff); }
.shared-p4-secondary-context { padding: 0 0 8px; }

.shared-p5-action-summary {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 16px;
  padding: 10px 12px;
  border-left: 4px solid var(--shell-brand-yellow);
  border-radius: 8px;
  background: var(--shell-surface-subtle);
}
.shared-p5-action-summary[hidden] { display: none; }
.shared-p5-action-summary div { min-width: 0; }
.shared-p5-action-summary strong,
.shared-p5-action-summary span { display: block; }
.shared-p5-action-summary strong { color: var(--shell-text-primary); font-size: 14px; line-height: 21px; }
.shared-p5-action-summary span { color: var(--shell-text-caption); font-size: 13px; line-height: 19px; }
.shared-p5-action-summary button {
  min-width: 44px;
  min-height: 44px;
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--shell-border-subtle);
  border-radius: 12px;
  color: var(--shell-text-action);
  background: var(--shell-surface-card);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.app-shell-module-p4 .view-tabs,
.app-shell-module-p4 .admin-entry-grid {
  margin-inline: 0;
  padding-inline: 0;
  border-bottom: 1px solid var(--shell-border-subtle);
  border-radius: 0;
  background: var(--shell-surface-page);
}
.app-shell-module-p4 .view-tabs .tab,
.app-shell-module-p4 .admin-entry-grid .admin-entry {
  min-height: 48px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--shell-text-secondary);
  background: transparent;
  box-shadow: none;
}
.app-shell-module-p4 .view-tabs .tab.active,
.app-shell-module-p4 .admin-entry-grid .admin-entry.active {
  border-bottom-color: var(--shell-brand-primary);
  color: var(--shell-text-action);
  background: transparent;
}

.app-shell-module-p5.app-shell-authenticated #login-home,
.app-shell-module-p5.app-shell-authenticated #authenticated-shell > .topbar,
.app-shell-module-p5.app-shell-authenticated #authenticated-shell > .scope-banner,
.app-shell-module-p5.app-shell-authenticated #fake-data-tools {
  display: none !important;
}
.app-shell-module-p5.app-shell-authenticated #authenticated-shell { min-height: calc(100vh - var(--shell-header-height)); }
.app-shell-module-p5.app-shell-authenticated #app {
  width: 100%;
  max-width: 1020px;
  margin: 0 auto 60px;
}
.app-shell-module-p5.app-shell-authenticated .therapist-screen .screen-appbar { display: none; }
.app-shell-module-p5.app-shell-authenticated .app-screen {
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: var(--shell-surface-page);
  box-shadow: none;
}
.app-shell-module-p5.app-shell-authenticated :is(.dashboard-screen, .foundation-screen) {
  border-radius: 0;
  box-shadow: none;
}

.app-shell-module-p4.app-shell-authenticated .connection-feedback {
  position: fixed;
  z-index: 95;
  top: calc(var(--shell-header-height) + 8px);
  left: 50%;
  width: min(520px, calc(100vw - 24px));
  min-height: 0;
  margin: 0;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgba(36, 53, 74, .12);
}
.app-shell-module-p4.app-shell-authenticated .connection-feedback[hidden] { display: none; }

.app-shell-module-p4.notification-sheet-open .backdrop { z-index: 199; }
.app-shell-module-p4.notification-sheet-open #notificationPanel {
  z-index: 200;
  height: min(92dvh, calc(100dvh - max(12px, env(safe-area-inset-top))));
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)));
}
.app-shell-module-p4.notification-sheet-open #notificationPanel > .sheet-title {
  z-index: 5;
}
.app-shell-module-p4.notification-sheet-open #notificationPanel > .notification-tabs {
  position: sticky;
  z-index: 5;
  top: 52px;
  margin-top: 12px;
  background: var(--shell-surface-card);
}

.app-shell-notification-proxy .p4-module-outlet > :not(.sheet) { visibility: hidden !important; }
.app-shell-notification-proxy .p4-module-outlet { min-height: calc(100vh - var(--shell-header-height)); }

.app-shell-mode[data-app-shell-text-scale="2"] .shared-module-button {
  font-size: 40px;
  line-height: 56px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-module-menu > p,
.app-shell-mode[data-app-shell-text-scale="2"] .shared-p4-context-label,
.app-shell-mode[data-app-shell-text-scale="2"] .shared-p4-secondary-context,
.app-shell-mode[data-app-shell-text-scale="2"] .shared-p4-role-switch {
  font-size: 28px;
  line-height: 42px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-module-menu button,
.app-shell-mode[data-app-shell-text-scale="2"] .shared-discard-dialog button {
  font-size: 32px;
  line-height: 48px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-discard-dialog h2 {
  font-size: 44px;
  line-height: 60px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-discard-dialog p {
  font-size: 32px;
  line-height: 48px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-login-home {
  overflow-x: hidden;
  overflow-y: auto;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-login-copy h1 {
  font-size: 64px;
  line-height: 80px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-login-copy p {
  font-size: 34px;
  line-height: 52px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-login-button {
  min-height: 88px;
  font-size: 32px;
  line-height: 48px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-login-helper {
  align-items: flex-start;
  font-size: 28px;
  line-height: 42px;
}
.app-shell-mode[data-app-shell-text-scale="2"] .shared-login-release {
  font-size: 24px;
  line-height: 36px;
}

@media (max-width: 600px) {
  .shared-login-home { --shared-login-artboard-top: 0px; }
  .shared-login-content {
    width: min(342px, calc(100% - 48px));
    padding-top: clamp(252px, 35.5vh, 300px);
    padding-bottom: 272px;
  }
  .shared-login-copy { padding-inline: 0; }
  .shared-login-actions { margin-top: 56px; }
  .shared-login-top-decoration { height: 232px; }
  .shared-login-bottom-decoration { height: 268px; }
  .shared-login-pattern-top-pink { top: 112px; left: 12%; width: 38px; }
  .shared-login-pattern-top-yellow { top: 72px; right: 24%; width: 42px; }
  .shared-login-pattern-top-blue { top: 184px; right: 14%; width: 36px; }
  .shared-login-wave-top { top: 48px; right: 6%; width: 80px; }
  .shared-login-pattern-bottom-blue-one { top: 54px; left: 18%; width: 42px; }
  .shared-login-pattern-bottom-yellow { top: 116px; left: 31%; width: 46px; }
  .shared-login-pattern-bottom-pink { top: 122px; left: 49%; width: 48px; }
  .shared-login-pattern-bottom-blue-two { top: 210px; left: 54%; width: 44px; }
  .shared-shell-inner { padding-inline: 12px; }
  .shared-module-button { max-width: calc(100vw - 112px); font-size: 18px; line-height: 26px; }
  .shared-shell-actions { gap: 0; }
  .shared-module-menu { left: 12px; width: min(304px, calc(100vw - 24px)); }
  .app-shell-module-p4.app-shell-authenticated .p4-module-outlet { padding-top: 12px; }
  .app-shell-mode[data-app-shell-text-scale="2"] .shared-login-content {
    padding-top: 160px;
    padding-bottom: 272px;
  }
  .app-shell-mode[data-app-shell-text-scale="2"] .shared-login-actions { margin-top: 56px; }
}

@media (min-width: 900px) {
  .shared-login-content { padding-top: clamp(248px, 30vh, 336px); }
  .shared-login-bottom-decoration { height: 330px; }
}

@media (prefers-reduced-motion: reduce) {
  .shared-login-spinner { animation: none; }
}

@media (forced-colors: active) {
  .shared-module-menu,
  .shared-discard-dialog,
  .shared-shell-header { border: 1px solid CanvasText; }
}
