/*
 * Phase Academy — common application shell + form/visual system (Phase 3 pilot).
 *
 * Presentation only. This stylesheet never participates in any calculation.
 * Every rule is scoped under `.pa-shell-active` (set on <html> by app-shell.js)
 * so it can only affect applications that opt into the pilot.
 *
 * Target size: interactive controls are held at >= 44x44 CSS px with >= 8px
 * spacing to satisfy WCAG 2.2 SC 2.5.8 (Target Size, Minimum) with margin.
 */

.pa-shell-active {
  --pa-navy: #15233e;
  --pa-sky: #7dbcdc;
  --pa-sand: #e89b1a;
  --pa-cream: #faf6eb;
  --pa-ink: #16202f;
  --pa-muted: #5b6675;
  --pa-line: #d9d3c4;
  --pa-ok: #1d7a4c;
  --pa-warn: #96631a;
  --pa-bad: #a52d2d;
  --pa-target: 44px;
  scroll-padding-top: 120px;
}

/* ---------- shell bar ---------- */
.pa-shell {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--pa-line);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.pa-shell__back,
.pa-shell button {
  min-height: var(--pa-target);
  min-width: var(--pa-target);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--pa-line);
  border-radius: 8px;
  background: #fff;
  color: var(--pa-navy);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.pa-shell__back:hover,
.pa-shell button:hover {
  background: var(--pa-cream);
}

.pa-shell__id {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1 1 240px;
}

.pa-shell__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--pa-navy);
}

.pa-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid var(--pa-line);
  border-radius: 999px;
  background: var(--pa-cream);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--pa-muted);
  white-space: nowrap;
}

.pa-shell__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Responsive navigation: secondary actions collapse into a menu on narrow
   viewports so the bar never overflows horizontally at 320px. */
@media (max-width: 760px) {
  .pa-shell__actions .pa-secondary {
    display: none;
  }
  .pa-shell__menu-toggle {
    display: inline-flex;
  }
  .pa-shell__actions.pa-open .pa-secondary {
    display: inline-flex;
  }
  .pa-shell__actions.pa-open {
    width: 100%;
  }
}

@media (min-width: 761px) {
  .pa-shell__menu-toggle {
    display: none;
  }
}

/* ---------- skip link ---------- */
.pa-skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: 10px 14px;
  min-height: var(--pa-target);
  display: inline-flex;
  align-items: center;
  background: var(--pa-navy);
  color: #fff;
  border-radius: 0 0 8px 0;
}

.pa-skip:focus {
  left: 0;
}

/* ---------- focus handling ---------- */
.pa-shell-active :focus-visible {
  outline: 3px solid var(--pa-sky);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- form + control system ---------- */
.pa-shell-active input:not([type="range"]):not([type="checkbox"]):not([type="radio"]),
.pa-shell-active select,
.pa-shell-active .btn,
.pa-shell-active button,
.pa-shell-active .tab-btn,
.pa-shell-active .preset-btn,
.pa-shell-active .toggle-group button,
.pa-shell-active .equip-btn {
  min-height: var(--pa-target);
}

.pa-shell-active input[type="range"] {
  min-height: 32px;
  padding: 12px 0; /* enlarges the pointer target around a thin track */
}

.pa-shell-active .toggle-group,
.pa-shell-active .tab-bar {
  gap: 8px;
}

.pa-shell-active .ctrl-label {
  font-weight: 600;
  color: var(--pa-navy);
}

.pa-shell-active .ctrl-help {
  color: var(--pa-muted);
  line-height: 1.45;
}

/* Inline validation + status semantics shared across pilot apps. */
.pa-invalid {
  border-color: var(--pa-bad) !important;
  box-shadow: 0 0 0 1px var(--pa-bad);
}

.pa-inline-error {
  display: block;
  margin-top: 4px;
  color: var(--pa-bad);
  font-size: 0.78rem;
  font-weight: 600;
}

/* ---------- dialogs ---------- */
.pa-dialog {
  border: 1px solid var(--pa-line);
  border-radius: 12px;
  padding: 0;
  max-width: 640px;
  width: calc(100vw - 32px);
  color: var(--pa-ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.pa-dialog::backdrop {
  background: rgba(21, 35, 62, 0.45);
}

.pa-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--pa-line);
}

.pa-dialog__head h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--pa-navy);
}

.pa-dialog__body {
  padding: 16px;
  max-height: 65vh;
  overflow: auto;
  font-size: 0.9rem;
  line-height: 1.55;
}

.pa-dialog__body h3 {
  margin: 16px 0 4px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pa-muted);
}

.pa-dialog__foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--pa-line);
}

.pa-dialog button,
.pa-tour button {
  min-height: var(--pa-target);
  min-width: var(--pa-target);
  padding: 0 14px;
  border: 1px solid var(--pa-line);
  border-radius: 8px;
  background: #fff;
  color: var(--pa-navy);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.pa-primary {
  background: var(--pa-navy) !important;
  border-color: var(--pa-navy) !important;
  color: #fff !important;
}

/* ---------- toast ---------- */
.pa-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 1100;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--pa-navy);
  color: #fff;
  font-size: 0.85rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
}

/* ---------- guided tour ---------- */
.pa-tour {
  position: fixed;
  z-index: 1200;
  max-width: min(360px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid var(--pa-navy);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.85rem;
  color: var(--pa-ink);
}

.pa-tour h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--pa-navy);
}

.pa-tour__step {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pa-muted);
}

.pa-tour__foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
}

.pa-tour-highlight {
  outline: 3px solid var(--pa-sand) !important;
  outline-offset: 3px;
  scroll-margin-top: 130px;
}

/* ---------- mode switch (Basic / Advanced) ---------- */
.pa-modebar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--pa-line);
  background: var(--pa-cream);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.8rem;
  color: var(--pa-muted);
}

.pa-modebar button[aria-pressed="true"] {
  background: var(--pa-navy);
  border-color: var(--pa-navy);
  color: #fff;
}

.pa-modebar button {
  min-height: var(--pa-target);
  padding: 0 14px;
  border: 1px solid var(--pa-line);
  border-radius: 8px;
  background: #fff;
  color: var(--pa-navy);
  font-weight: 600;
  cursor: pointer;
}

.pa-hidden-advanced {
  display: none !important;
}

/* ---------- no horizontal overflow at small widths / 200% zoom ---------- */
.pa-shell-active body,
.pa-shell-active .pa-shell,
.pa-shell-active .pa-modebar {
  max-width: 100%;
}

@media (max-width: 520px) {
  .pa-shell__title {
    font-size: 0.85rem;
  }
  /* Status text is long; keep it inside the viewport on small screens. */
  .pa-chip {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .pa-shell__id {
    flex-basis: 100%;
  }
  .pa-shell {
    padding: 8px;
  }
}

@media print {
  .pa-shell,
  .pa-modebar,
  .pa-tour {
    display: none !important;
  }
}

/* Pilot apps ship a fixed-padding sidebar that overflowed by a few px at
   320 CSS px. Box-sizing keeps it inside the viewport without moving layout
   at any larger width. */
@media (max-width: 380px) {
  .pa-shell-active .sidebar,
  .pa-shell-active .content-area,
  .pa-shell-active .app-main {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .pa-shell-active .main-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}


/* ---------------- mini chart preview ---------------- */
.pa-mini {
  position: fixed;
  right: 16px;
  bottom: 64px; /* clears the persistent disclaimer bar */
  z-index: 40;
  width: 284px;
  background: var(--pa-surface, #fff);
  border: 1px solid var(--pa-border, #d8dee9);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(12, 26, 48, 0.16);
  font-size: 0.8rem;
}
.pa-mini__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--pa-border, #d8dee9);
}
.pa-mini__head p {
  margin: 0;
  font-weight: 600;
}
.pa-mini__toggle {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--pa-border, #d8dee9);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}
.pa-mini__body {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
}
.pa-mini__body canvas {
  width: 100%;
  height: auto;
  background: #fff;
  border-radius: 8px;
}
.pa-mini__cap {
  margin: 0;
  color: var(--pa-muted, #4a5568);
}
.pa-mini--collapsed .pa-mini__body {
  display: none;
}
@media (max-width: 900px) {
  .pa-mini {
    display: none;
  }
}
