/* Apps screen (spec 5.2 / 5.4). Mobile first, one column, dark workshop system. */
#view-tools .apps-view { max-width: 720px; margin: 0 auto; padding: 4px 0 40px; }
#view-tools .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
#view-tools .apps-head { margin: 0 0 18px; }
#view-tools .apps-title { margin: 0; font-family: 'Fraunces', serif; font-style: italic; font-weight: 500; font-size: clamp(28px, 6vw, 36px); letter-spacing: -.03em; color: var(--display); }
#view-tools .apps-intro { margin: 6px 0 0; max-width: 60ch; color: var(--body); font-size: 15px; line-height: 1.55; }
#view-tools .apps-group { margin-top: 26px; }
#view-tools .apps-group-title { margin: 0 0 10px; font: 600 11px/1.2 'JetBrains Mono', monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#view-tools .apps-attention .apps-group-title { color: var(--warn); }
#view-tools .apps-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); overflow: hidden; }
#view-tools .apps-list:empty { display: none; }
#view-tools .apps-empty { padding: 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }

#view-tools .app-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
#view-tools .app-row:first-child { border-top: 0; }
#view-tools .app-row.attention { background: rgba(232, 184, 75, .06); }
#view-tools .app-row-main { display: flex; gap: 12px; align-items: flex-start; min-width: 0; padding: 0; margin: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 10px; }
#view-tools .app-row-main.static { cursor: default; }
#view-tools .app-row-main:focus-visible { outline: 2px solid var(--orange-text); outline-offset: 4px; }
#view-tools .app-row-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
#view-tools .app-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; color: var(--strong); font-weight: 650; font-size: 15px; }
#view-tools .app-copy { color: var(--body); font-size: 13.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#view-tools .app-sub { color: var(--muted); font-size: 12px; line-height: 1.4; }
#view-tools .app-row-action { display: flex; justify-content: flex-end; }
#view-tools .app-row-state { grid-column: 1 / -1; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
#view-tools .app-row-state:empty { display: none; }
#view-tools .app-row-state.ok { color: var(--ok); }
#view-tools .app-row-state.stop { color: var(--stop); }

#view-tools .app-logo { position: relative; flex: 0 0 40px; width: 40px; height: 40px; border-radius: 10px; overflow: hidden; background: var(--panel-raised); }
#view-tools .app-logo img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: contain; padding: 6px; background: #f5f1e8; }
#view-tools .app-logo-letters { display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; color: var(--display); font: 650 14px/1 'Public Sans', sans-serif; letter-spacing: .02em; }

#view-tools .app-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); font: 600 11px/1.3 'JetBrains Mono', monospace; color: var(--body); white-space: nowrap; }
#view-tools .app-chip-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
#view-tools .app-chip.ok { color: var(--ok); border-color: rgba(52, 211, 153, .35); }
#view-tools .app-chip.off { color: var(--muted); }
#view-tools .app-chip.off .app-chip-dot { background: none; border: 1.5px solid currentColor; }
#view-tools .app-chip.warn { color: var(--warn); border-color: rgba(232, 184, 75, .4); }
#view-tools .app-chip.warn .app-chip-dot { border-radius: 0; background: none; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 7px solid currentColor; }
#view-tools .app-chip.stop { color: var(--stop); border-color: rgba(255, 120, 100, .4); }
#view-tools .app-spinner { width: 9px; height: 9px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: app-spin .9s linear infinite; }
@keyframes app-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #view-tools .app-spinner { animation: none; } }

#view-tools .app-btn { min-height: 44px; padding: 9px 16px; border-radius: 12px; border: 1px solid var(--line-strong); background: transparent; color: var(--strong); font: 600 14px/1.2 'Public Sans', sans-serif; cursor: pointer; white-space: nowrap; }
#view-tools .app-btn.primary { background: var(--orange); border-color: var(--orange); color: #140b05; }
#view-tools .app-btn.primary:hover:not(:disabled) { background: var(--orange-press); border-color: var(--orange-press); color: var(--display); }
#view-tools .app-btn.quiet { color: var(--orange-text); border-color: transparent; padding-inline: 8px; }
#view-tools .app-btn.danger { color: var(--stop); border-color: rgba(255, 120, 100, .45); }
#view-tools .app-btn:disabled { opacity: .6; cursor: progress; }
#view-tools .app-btn:focus-visible, #view-tools .apps-link:focus-visible, #view-tools .app-switch input:focus-visible + .app-switch-track { outline: 2px solid var(--orange-text); outline-offset: 3px; }
#view-tools .apps-link { padding: 0; border: 0; background: none; color: var(--orange-text); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
#view-tools .apps-link.secondary { color: var(--muted); }

#view-tools .app-switch { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; cursor: pointer; }
#view-tools .app-switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
#view-tools .app-switch input:disabled { cursor: progress; }
#view-tools .app-switch-track { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--panel-raised); border: 1px solid var(--line-strong); transition: background .15s; }
#view-tools .app-switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
#view-tools .app-switch input:checked + .app-switch-track { background: rgba(52, 211, 153, .25); border-color: rgba(52, 211, 153, .55); }
#view-tools .app-switch input:checked + .app-switch-track::after { transform: translateX(18px); background: var(--ok); }
#view-tools .app-switch input:disabled + .app-switch-track { opacity: .55; }
#view-tools .app-switch-label { font-size: 11px; line-height: 1.2; color: var(--muted); text-align: center; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { #view-tools .app-switch-track, #view-tools .app-switch-track::after { transition: none; } }

#view-tools .apps-search input { width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--strong); font: 15px/1.3 'Public Sans', sans-serif; }
#view-tools .apps-search input::placeholder { color: var(--muted); }
#view-tools .apps-search input:focus-visible { outline: 2px solid var(--orange-text); outline-offset: 2px; }
#view-tools #appsSearchResults { margin-top: 10px; }
#view-tools .apps-foot { margin: 12px 0 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
#view-tools .apps-foot-sep { margin: 0 6px; }
#view-tools .apps-toast, #view-tools .apps-load-error { margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; }
#view-tools .apps-toast { border: 1px solid rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .08); color: var(--strong); }
#view-tools .apps-toast.stop { border-color: rgba(255, 120, 100, .4); background: rgba(255, 120, 100, .08); }
#view-tools .apps-load-error { border: 1px solid rgba(255, 120, 100, .4); color: var(--strong); }
#view-tools .apps-toast[hidden], #view-tools .apps-load-error[hidden], #view-tools .apps-group[hidden] { display: none; }
#view-tools .first-itch { margin-top: 32px; }

/* Bottom sheet */
.app-sheet-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .55); }
.app-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 81; max-height: 88dvh; overflow: auto; padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; background: var(--panel); color: var(--body); box-shadow: 0 -18px 56px rgba(0, 0, 0, .4); }
.app-sheet[hidden], .app-sheet-backdrop[hidden] { display: none; }
body.app-sheet-open { overflow: hidden; }
.app-sheet-grip { width: 40px; height: 4px; margin: 4px auto 12px; border-radius: 4px; background: var(--line-strong); }
.app-sheet-head { display: grid; grid-template-columns: 40px minmax(0, 1fr) 44px; gap: 12px; align-items: center; }
.app-sheet-title { margin: 0 0 4px; color: var(--display); font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
.app-sheet-close { width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; }
.app-sheet-close:focus-visible { outline: 2px solid var(--orange-text); outline-offset: 2px; }
.app-sheet-section { margin-top: 18px; }
.app-sheet-section h4 { margin: 0 0 8px; font: 600 11px/1.2 'JetBrains Mono', monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.app-sheet ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.app-sheet li { position: relative; padding-left: 22px; font-size: 14px; line-height: 1.5; color: var(--strong); }
.app-list-yes li::before { content: '✓'; position: absolute; left: 0; color: var(--ok); font-weight: 700; }
.app-list-no li::before { content: '✕'; position: absolute; left: 0; color: var(--stop); font-weight: 700; }
.app-sheet-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0 0; }
.app-sheet-facts div { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.app-sheet-facts dt { font-size: 11px; color: var(--muted); }
.app-sheet-facts dd { margin: 3px 0 0; font-size: 14px; color: var(--strong); overflow-wrap: anywhere; }
.app-sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.app-sheet-actions .app-btn { flex: 1 1 160px; }
.app-sheet .app-row-state { margin-top: 10px; font-size: 13px; color: var(--muted); }
.app-sheet .app-row-state:empty { display: none; }
.app-sheet .app-row-state.ok { color: var(--ok); }
.app-sheet .app-row-state.stop { color: var(--stop); }
.app-sheet-note { margin: 14px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.app-sheet .app-logo { position: relative; width: 40px; height: 40px; border-radius: 10px; overflow: hidden; background: var(--panel-raised); }
.app-sheet .app-logo img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: contain; padding: 6px; background: #f5f1e8; }
.app-sheet .app-logo-letters { display: flex; width: 100%; height: 100%; align-items: center; justify-content: center; color: var(--display); font: 650 14px/1 'Public Sans', sans-serif; }
.app-sheet .app-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); font: 600 11px/1.3 'JetBrains Mono', monospace; color: var(--body); }
.app-sheet .app-chip-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.app-sheet .app-chip.ok { color: var(--ok); }
.app-sheet .app-chip.off { color: var(--muted); }
.app-sheet .app-btn { min-height: 44px; padding: 9px 16px; border-radius: 12px; border: 1px solid var(--line-strong); background: transparent; color: var(--strong); font: 600 14px/1.2 'Public Sans', sans-serif; cursor: pointer; }
.app-sheet .app-btn.primary { background: var(--orange); border-color: var(--orange); color: #140b05; }
.app-sheet .app-btn.danger { color: var(--stop); border-color: rgba(255, 120, 100, .45); }
.app-sheet .app-btn:disabled { opacity: .6; cursor: progress; }
.app-sheet .app-btn:focus-visible, .app-sheet .apps-link:focus-visible { outline: 2px solid var(--orange-text); outline-offset: 3px; }
.app-sheet .apps-link { padding: 0; border: 0; background: none; color: var(--orange-text); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

@media (min-width: 760px) {
  .app-sheet { left: 50%; right: auto; bottom: 50%; width: min(520px, calc(100vw - 48px)); transform: translate(-50%, 50%); border-radius: 18px; border-bottom: 1px solid var(--line); padding-bottom: 22px; }
  .app-sheet-grip { display: none; }
}

/* Needs-attention copy is the instruction, so it is never clipped; on a phone
   the button drops under it instead of squeezing it. */
#view-tools .app-row.attention .app-copy { -webkit-line-clamp: unset; display: block; }
@media (max-width: 559px) {
  #view-tools .app-row.attention { grid-template-columns: minmax(0, 1fr); }
  #view-tools .app-row.attention .app-row-action { justify-content: flex-start; padding-left: 52px; }
}
#view-tools .apps-link { min-height: 0; line-height: inherit; vertical-align: baseline; }
@media (max-width: 439px) { .app-sheet-facts { grid-template-columns: 1fr; } }
.app-sheet-plain { margin: 0; font-size: 14px; line-height: 1.5; color: var(--body); }
.app-sheet .apps-link { min-height: 0; line-height: inherit; vertical-align: baseline; }

/* Pre-connect sheet and return toast (spec 5.3) */
.app-sheet-why { margin: 12px 0 0; font-size: 15px; line-height: 1.5; color: var(--strong); }
#view-tools .apps-toast-retry { margin-left: 6px; padding: 6px 12px; min-height: 36px; }
#view-tools .apps-toast .app-row-state { display: block; }
#view-tools .apps-toast .app-row-state:empty { display: none; }

/* An employee's app link (spec 5.6): their reason, on top of the connect sheet. */
.app-sheet-ask { margin: 14px 0 0; padding: 10px 12px; border-left: 3px solid var(--accent, #c2410c); background: rgba(194, 65, 12, 0.06); border-radius: 0 8px 8px 0; font-size: 15px; line-height: 1.5; color: var(--strong); }
.app-sheet-ask span { display: block; font-size: 13px; font-weight: 600; color: var(--muted, #57534e); margin-bottom: 2px; }
