/* TapHome Customer Portal — visual style ported from the marketing-site palette
 * (template_generator branch, taphome.com brand language). Functionality follows
 * knowledge/mockups/customer-portal/.
 *
 * - Primary: TapHome Brand Blue (#3EB4FB) with -dark / -light / -superlight variants
 * - Typography: Aeonik (loaded via @font-face from /fonts/aeonikvf.ttf)
 * - Pill-shaped buttons (rounded-full) matching the marketing site CTA treatment
 * - gray1 (almost white) → gray9 (near-black) scale
 */

@font-face {
  font-family: 'Aeonik';
  src: url('/fonts/aeonikvf.ttf') format('truetype-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Aeonik';
  src: url('/fonts/aeonikvf-italic.ttf') format('truetype-variations');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

:root {
  /* TapHome brand blue */
  --tph-primary-dark:        #0091F5;
  --tph-primary:             #3EB4FB;
  --tph-primary-medium:      #4AC3FC;
  --tph-primary-light:       #BEEAFF;
  --tph-primary-superlight:  #E5F7FF;

  /* Secondary accents (used sparingly — violet for AI / Claude callouts, mint for success states) */
  --tph-violet-dark:    #B374E1;
  --tph-violet-medium:  #CE92F8;
  --tph-violet-light:   #E1DDFF;
  --tph-mint-dark:      #19B0C4;
  --tph-mint-medium:    #6CEEDF;
  --tph-mint-light:     #C6F2ED;

  /* System colors (from main.css) */
  --tph-error:         #FE5449;
  --tph-error-light:   #FFDBE1;
  --tph-warning:       #FFA312;
  --tph-warning-light: #FFEBC1;
  --tph-success:       #5AD251;
  --tph-success-light: #D7F8D5;

  /* Gray scale — gray1 lightest, gray9 darkest */
  --tph-gray1: #F7F8FC;
  --tph-gray2: #EDEFF7;
  --tph-gray3: #DFE2F0;
  --tph-gray4: #C1C4D4;
  --tph-gray5: #9C9FAD;
  --tph-gray6: #747680;
  --tph-gray7: #45464F;
  --tph-gray8: #3C3D47;
  --tph-gray9: #25252E;

  /* Surfaces */
  --tph-bg-app:     #FFFFFF;     /* the marketing site is white-first */
  --tph-bg-subtle:  var(--tph-gray1);
  --tph-bg-muted:   var(--tph-gray2);

  /* Text */
  --tph-text:        var(--tph-gray9);
  --tph-text-muted:  var(--tph-gray6);
  --tph-text-subtle: var(--tph-gray5);

  --tph-border:        var(--tph-gray3);
  --tph-border-hover:  var(--tph-gray4);

  /* Radius — marketing site uses md (~10px) for cards, full for buttons */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-sm: 0 1px 2px rgba(37,37,46,0.04);
  --shadow:    0 4px 16px rgba(37,37,46,0.06);
  --shadow-lg: 0 12px 32px rgba(37,37,46,0.08);

  /* === 007-portal-mobile-responsive ===
     Breakpoints — mirror these literal values in @media rules below.
     CSS doesn't yet accept var() inside @media, so any change must be made
     in both places. */
  --bp-edit: 900px;
  --bp-portal: 768px;
  --page-chrome-desktop: 220px;
  --page-chrome-mobile: 140px;
  --page-chrome: var(--page-chrome-desktop);
  --fab-size: 56px;
  --fab-offset: 20px;
  --z-fab: 950;
  --z-toast: 1000;
  --z-modal: 1000;
  --z-mobile-drawer: 1050;
  --z-chat-overlay: 1050;
  --z-action-log: 1100;
}

/* Mobile chrome height — narrower top padding + collapsed nav reclaims ~80px */
@media (max-width: 767px) {
  :root {
    --page-chrome: var(--page-chrome-mobile);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Aeonik', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--tph-bg-app);
  color: var(--tph-text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Monaco, monospace; font-size: 12.5px; }
code { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: .92em; background: var(--tph-bg-muted); padding: 1px 6px; border-radius: 6px; }

a { color: var(--tph-primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { letter-spacing: -0.01em; line-height: 1.2; margin: 0; font-weight: 500; color: var(--tph-gray9); }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }

/* === Buttons (pill-shaped, brand-blue primary, brightness hover) === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--tph-gray3);
  background: var(--tph-bg-app);
  color: var(--tph-gray9);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: filter .15s, background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--tph-gray1); border-color: var(--tph-gray4); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--tph-primary); color: white; border-color: var(--tph-primary); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.10); background: var(--tph-primary); border-color: var(--tph-primary); }
.btn-danger { background: var(--tph-error); color: white; border-color: var(--tph-error); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); background: var(--tph-error); border-color: var(--tph-error); color: white; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--tph-gray6); }
.btn-ghost:hover:not(:disabled) { background: var(--tph-gray1); color: var(--tph-gray9); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 13px 22px; font-size: 15px; }

/* === Layout === */
/* `grid-template-columns: minmax(0, 1fr)` clamps the implicit column to the
   container width — without it, grid auto-sizes to its widest item's min-content
   and any unwrappable child blows the page past viewport. */
.layout { display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); min-height: 100vh; }
.main { max-width: 1280px; margin: 0 auto; padding: 28px; width: 100%; min-width: 0; }
body { overflow-x: hidden; }

/* === Topbar === */
.topbar {
  background: var(--tph-bg-app);
  border-bottom: 1px solid var(--tph-gray2);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 16px;
  color: var(--tph-gray9);
}
.topbar-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--tph-primary);
  color: white;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
}
/* taphome wordmark sized for the topbar — height matches the original "TH" badge.
 * The SVG keeps its baked-in #3EB4FB fill (matches --tph-primary). */
.topbar-brand-logo {
  height: 22px;
  width: auto;
  display: inline-block;
}
/* "portal" suffix sits next to the wordmark — gray, lowercase, slightly smaller. */
.topbar-brand-suffix {
  color: var(--tph-gray6);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.01em;
}
.topbar-nav { display: flex; gap: 4px; }
.topbar-nav a {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--tph-gray6);
  font-weight: 500;
  font-size: 14px;
  transition: background .12s, color .12s;
}
.topbar-nav a:hover { background: var(--tph-gray1); color: var(--tph-gray9); text-decoration: none; }
.topbar-nav a.active { background: var(--tph-primary-superlight); color: var(--tph-primary-dark); }
.topbar-user { display: flex; gap: 14px; align-items: center; font-size: 13px; color: var(--tph-gray6); }
.topbar-user-name { font-weight: 500; color: var(--tph-gray9); }

/* === 007 — Topbar mobile drawer === */
.topbar-hamburger {
  display: none;
  border: none;
  background: transparent;
  padding: 8px;
  cursor: pointer;
  color: var(--tph-gray9);
  border-radius: var(--radius-sm);
}
.topbar-hamburger:hover { background: var(--tph-gray1); }
.topbar-hamburger:focus-visible { outline: 2px solid var(--tph-primary); outline-offset: 2px; }

.topbar-mobile-drawer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-mobile-drawer);
  background: rgba(15, 19, 26, 0.45);
}
.topbar-mobile-drawer.open { display: block; }

.topbar-mobile-drawer-panel {
  position: absolute;
  top: 0; left: 0; right: 0;
  background: var(--tph-bg-app);
  border-bottom: 1px solid var(--tph-gray2);
  padding: 12px 20px 20px;
  max-height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar-mobile-nav { display: flex; flex-direction: column; gap: 2px; }
.topbar-mobile-nav a {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--tph-gray9);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}
.topbar-mobile-nav a:hover { background: var(--tph-gray1); }
.topbar-mobile-nav a.active {
  background: var(--tph-primary-superlight);
  color: var(--tph-primary-dark);
}

.topbar-mobile-user {
  border-top: 1px solid var(--tph-gray2);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.topbar-mobile-userrow { display: flex; gap: 12px; align-items: center; }

/* Inside the mobile drawer, the LangSwitcher otherwise stretches to fill the
   drawer panel and its `right: 0`-anchored dropdown pops far off to the right.
   Shrink it to its button width and anchor the menu to the left so the dropdown
   sits directly under the EN button. */
.topbar-mobile-user .lang-switcher {
  align-self: flex-start;
}
.topbar-mobile-user .lang-switcher-menu {
  left: 0;
  right: auto;
}

@media (max-width: 767px) {
  .topbar { padding: 12px 16px; }
  .topbar-nav { display: none; }
  .topbar-user { display: none; }
  .topbar-hamburger { display: inline-flex; align-items: center; justify-content: center; }
}

/* === Language switcher === */
/* Mirrors the marketing-site dropdown in layouts/partials/components/header-dark.html
   (globe icon + uppercase 2-letter code, white rounded panel). */
.lang-switcher { position: relative; }
.lang-switcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  color: var(--tph-gray6);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
}
.lang-switcher-btn:hover { color: var(--tph-gray9); }
.lang-switcher-btn svg { display: block; flex: none; }
.lang-switcher-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 8px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
  padding: 6px 0;
  min-width: 100px;
  z-index: 50;
  overflow: hidden;
}
.lang-switcher-item {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 16px;
  text-align: left;
  font-size: 14px;
  color: var(--tph-gray6);
  cursor: pointer;
}
.lang-switcher-item:hover { background: var(--tph-gray1); color: var(--tph-gray9); }

/* === Cards === */
.card {
  background: var(--tph-bg-app);
  border-radius: var(--radius-md);
  padding: 22px;
  border: 1px solid var(--tph-gray2);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-title { margin: 0 0 12px; font-size: 15px; font-weight: 500; color: var(--tph-gray9); }
.card-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--tph-gray5); font-weight: 600; margin-bottom: 10px; }

/* === Chips / Badges === */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--tph-gray2);
  color: var(--tph-gray7);
}
.chip-primary { background: var(--tph-primary-superlight); color: var(--tph-primary-dark); }
.chip-success { background: var(--tph-success-light); color: #1F7C2A; }
.chip-warning { background: var(--tph-warning-light); color: #8A4F00; }
.chip-error   { background: var(--tph-error-light);   color: #A6121C; }
.chip-info    { background: var(--tph-primary-superlight); color: var(--tph-primary-dark); }
.chip-violet  { background: var(--tph-violet-light); color: #6F3AB7; }
.chip-staff   { background: var(--tph-violet-light); color: #6F3AB7; border: 1px solid var(--tph-violet-medium); }

/* "● running / queued" chip — pulsing live-indicator dot. The chip itself
   gets a soft halo that breathes in sync with the dot so it reads as
   "in progress" at a glance even with peripheral vision. */
.chip.state-running {
  background: var(--tph-primary-superlight);
  color: var(--tph-primary-dark);
  text-transform: capitalize;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip.state-running .state-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tph-primary);
  flex-shrink: 0;
  animation: state-running-pulse 1.6s ease-in-out infinite;
}
@keyframes state-running-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 134, 222, 0.55); transform: scale(1); }
  50%      { box-shadow: 0 0 0 6px rgba(46, 134, 222, 0);    transform: scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .chip.state-running .state-dot { animation: none; }
}

/* AI POWERED uppercase tag (mockup detail; very specific) */
.tag-ai {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  background: var(--tph-primary-superlight);
  color: var(--tph-primary-dark);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}

/* === Online dot === */
.online-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--tph-gray4); }
.online-dot.on { background: var(--tph-success); box-shadow: 0 0 0 3px rgba(90,210,81,0.18); }

/* === Location grid === */
.location-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.location-tile {
  padding: 20px;
  border-radius: var(--radius-md);
  background: var(--tph-bg-app);
  border: 1px solid var(--tph-gray2);
  cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.location-tile:hover { border-color: var(--tph-primary); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.location-tile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.location-name { font-weight: 500; font-size: 16px; color: var(--tph-gray9); margin-bottom: 2px; }
.location-meta { font-size: 12.5px; color: var(--tph-gray6); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; color: var(--tph-gray7); }
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--tph-gray3);
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  background: var(--tph-bg-app);
  color: var(--tph-gray9);
  transition: border-color .12s, box-shadow .12s;
}
.form-textarea {
  border-radius: var(--radius);
  min-height: 80px;
  resize: vertical;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--tph-primary);
  box-shadow: 0 0 0 3px var(--tph-primary-superlight);
}
.form-help { font-size: 12px; color: var(--tph-gray5); margin-top: 4px; }

/* === CHECK warnings banner (PackagePreview) === */
.check-warnings-banner {
  background: var(--tph-warning-light);
  border: 1px solid var(--tph-warning);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  color: #6B3700;
}
.check-warnings-banner-head {
  font-size: 14px;
  margin-bottom: 6px;
}
.check-warnings-list {
  margin: 6px 0 0;
  padding-left: 22px;
  font-size: 13px;
  font-family: var(--mono-stack, ui-monospace, SFMono-Regular, Menlo, monospace);
  line-height: 1.55;
}
.check-warnings-list li { margin-bottom: 2px; word-break: break-word; }

/* === Engine progress live ticker ===
   Fixed-height window (responsive: ~12 rows on phones, ~20 on desktop).
   New events append at the bottom and push older ones up; rows that scroll
   off the top fade out via a CSS mask gradient. The user doesn't need to
   *read* the log — just see that something's moving. Buffer is also capped
   in JS (TICKER_BUFFER = 30) so the DOM stays small. */
.job-progress-list {
  height: clamp(220px, 32vh, 420px);
  overflow: hidden;
  margin: 8px 0 0;
  padding: 8px 12px 8px 24px;
  background: var(--tph-gray1);
  border: 1px solid var(--tph-gray2);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;       /* anchor newest to bottom */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.15) 8%, black 32%, black 100%);
          mask-image: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.15) 8%, black 32%, black 100%);
}
.job-progress-list li { margin-bottom: 4px; line-height: 1.45; flex-shrink: 0; }
.job-progress-list li:last-child { margin-bottom: 0; }
.job-progress-list .step { font-weight: 600; margin-right: 8px; color: var(--tph-gray9); }
.job-progress-list .msg { color: var(--tph-gray7); word-break: break-word; }

/* "Live…" indicator — dots appear one by one, then all clear and restart.
   Frame timing across a 1.6s cycle (each frame = 400ms):
     0–400 ms   only dot 1 visible
     400–800    dots 1,2 visible
     800–1200   dots 1,2,3 visible
     1200–1600  all hidden (resets the eye for the next cycle) */
.live-dots {
  display: inline-block;
  margin-left: 1px;
  letter-spacing: 1px;
}
.live-dots > span {
  display: inline-block;
  opacity: 0;
  animation: 1.6s steps(1, end) infinite;
}
.live-dots > span:nth-child(1) { animation-name: live-dot-1; }
.live-dots > span:nth-child(2) { animation-name: live-dot-2; }
.live-dots > span:nth-child(3) { animation-name: live-dot-3; }
@keyframes live-dot-1 { 0%, 74% { opacity: 1; } 75%, 100% { opacity: 0; } }
@keyframes live-dot-2 { 0%, 24% { opacity: 0; } 25%, 74% { opacity: 1; } 75%, 100% { opacity: 0; } }
@keyframes live-dot-3 { 0%, 49% { opacity: 0; } 50%, 74% { opacity: 1; } 75%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .live-dots > span { animation: none; opacity: 1; }
}

/* === PDF drop-zone (TemplateIntake) === */
.pdf-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 22px 16px;
  border: 1.5px dashed var(--tph-gray3);
  border-radius: var(--radius);
  background: var(--tph-gray1);
  color: var(--tph-gray7);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  user-select: none;
}
.pdf-drop-zone:hover,
.pdf-drop-zone:focus-visible {
  border-color: var(--tph-primary);
  background: var(--tph-primary-superlight);
  color: var(--tph-gray9);
  outline: none;
}
.pdf-drop-zone.is-over {
  border-color: var(--tph-primary);
  border-style: solid;
  background: var(--tph-primary-superlight);
  color: var(--tph-gray9);
}
.pdf-drop-zone[aria-disabled="true"] { cursor: wait; opacity: 0.7; }
.pdf-drop-zone-icon { font-size: 26px; line-height: 1; margin-bottom: 4px; opacity: 0.65; }
.pdf-drop-zone:hover .pdf-drop-zone-icon,
.pdf-drop-zone.is-over .pdf-drop-zone-icon { opacity: 1; }
.pdf-drop-zone-primary { font-size: 14px; }
.pdf-drop-zone-meta { font-size: 12px; color: var(--tph-gray5); margin-top: 2px; }

/* === Empty / center states === */
.center-msg { text-align: center; padding: 64px 24px; color: var(--tph-gray6); }
.empty-state { text-align: center; padding: 56px 24px; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--tph-gray6); margin-bottom: 16px; max-width: 480px; margin-left: auto; margin-right: auto; }

/* === Spinner === */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--tph-gray3); border-top-color: var(--tph-primary); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.pulse-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--tph-primary); animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* === Session / template list grid === */
.session-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }
.session-card {
  background: var(--tph-bg-app);
  border: 1px solid var(--tph-gray2);
  border-radius: var(--radius-md);
  padding: 18px;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  cursor: pointer;
}
.session-card:hover { border-color: var(--tph-primary); transform: translateY(-1px); box-shadow: var(--shadow); }
.session-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.session-card-title { font-weight: 500; font-size: 15px; color: var(--tph-gray9); }
.session-card-slug { font-size: 12px; color: var(--tph-gray5); margin-top: 2px; }
.session-card-meta { font-size: 12px; color: var(--tph-gray6); margin-top: 12px; }

/* state colour mapping for chips */
.state-draft           { background: var(--tph-gray2); color: var(--tph-gray7); }
.state-extracting      { background: var(--tph-primary-superlight); color: var(--tph-primary-dark); }
.state-extracted       { background: var(--tph-mint-light);  color: var(--tph-mint-dark); }
.state-pending_publish { background: var(--tph-warning-light); color: #8A4F00; }
.state-published       { background: var(--tph-success-light); color: #1F7C2A; }
.state-archived        { background: var(--tph-gray2); color: var(--tph-gray5); }
.state-failed          { background: var(--tph-error-light); color: #A6121C; }
.state-portal_listed   { background: var(--tph-violet-light); color: #6F3AB7; }

/* === Engine-generated markdown (description.md / report.md from R2) === */
.markdown { color: var(--tph-gray9); line-height: 1.6; font-size: 14px; }
.markdown h1 { font-size: 22px; margin: 24px 0 10px; }
.markdown h2 { font-size: 18px; margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--tph-gray2); }
.markdown h3 { font-size: 15.5px; margin: 22px 0 8px; color: var(--tph-gray9); }
.markdown h4 { font-size: 14px; margin: 18px 0 6px; color: var(--tph-gray7); text-transform: uppercase; letter-spacing: 0.04em; }
.markdown p { margin: 0 0 12px; }
.markdown ul, .markdown ol { margin: 0 0 12px; padding-left: 22px; }
.markdown li { margin-bottom: 4px; }
.markdown li > p { margin-bottom: 6px; }
.markdown code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12.5px;
  background: var(--tph-gray1);
  border: 1px solid var(--tph-gray2);
  border-radius: 4px;
  padding: 1px 5px;
}
.markdown pre {
  background: var(--tph-gray9);
  color: #e7e9ee;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0 0 14px;
}
.markdown pre code {
  background: transparent; border: none; padding: 0; color: inherit; font-size: inherit;
}
.markdown blockquote {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-left: 3px solid var(--tph-primary);
  background: var(--tph-primary-superlight);
  color: var(--tph-gray9);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.markdown blockquote p:last-child { margin-bottom: 0; }
.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 14px;
  font-size: 13px;
}
.markdown th, .markdown td {
  padding: 8px 12px;
  border: 1px solid var(--tph-gray2);
  text-align: left;
  vertical-align: top;
}
.markdown th { background: var(--tph-gray1); font-weight: 500; color: var(--tph-gray7); }
.markdown a { color: var(--tph-primary); text-decoration: underline; }
.markdown a:hover { color: var(--tph-primary-dark); }
.markdown hr { border: none; border-top: 1px solid var(--tph-gray2); margin: 22px 0; }

/* === Editor (TemplateEdit) === */
.editor-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-areas: "chat preview";
  gap: 16px;
  height: calc(100dvh - var(--page-chrome));
  min-height: 520px;
}
.editor-chat-portal {
  grid-area: chat;
  background: var(--tph-bg-app);
  border: 1px solid var(--tph-gray2);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.editor-chat-portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.editor-main { grid-area: preview; }

/* === 007 — TemplateEdit narrow layout === */
@media (max-width: 899px) {
  .editor-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "preview";
  }
  .editor-chat-portal {
    position: fixed;
    inset: 0;
    z-index: var(--z-chat-overlay);
    border-radius: 0;
    border: none;
    background: var(--tph-bg-app);
    transform: translateY(100%);
    transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
    pointer-events: none;
  }
  .editor-shell.chat-open .editor-chat-portal {
    transform: translateY(0);
    pointer-events: auto;
  }
  .editor-shell:not(.chat-open) .editor-chat-portal {
    visibility: hidden;
  }
}

.editor-chat-fab {
  position: fixed;
  right: var(--fab-offset);
  bottom: var(--fab-offset);
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  border: none;
  background: var(--tph-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: var(--z-fab);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
.editor-chat-fab:hover {
  background: var(--tph-primary-dark);
  transform: scale(1.04);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}
.editor-chat-fab:focus-visible {
  outline: 2px solid var(--tph-primary-light);
  outline-offset: 3px;
}

.editor-chat-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
  color: var(--tph-gray6);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.editor-chat-close:hover { background: var(--tph-gray1); color: var(--tph-gray9); }

@media (prefers-reduced-motion: reduce) {
  .editor-chat-portal { transition: none; }
}
.editor-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--tph-bg-app);
  border: 1px solid var(--tph-gray2);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 0;
  /* Feature 009 B-4 — positioned container so .modal-variant-pane (DeviceDialog
     on desktop) can overlay the editor pane via `position: absolute; inset: 0`,
     keeping the chat sidebar visible in column 1. */
  position: relative;
}

/* Feature 009 B-4 — pane variant of <Modal>: render inline (no overlay
   backdrop), absolute-position over the parent .editor-main, keep the chat
   sidebar visible. Used by DeviceDialog on desktop (≥900px); on narrow
   (≤899px) DeviceDialog falls back to the default overlay variant. */
.modal-variant-pane {
  position: absolute;
  inset: 0;
  background: var(--tph-bg-app);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2;
  animation: modal-pane-in 0.16s ease-out;
}
.modal-variant-pane > .modal-body { flex: 1; overflow-y: auto; }
@keyframes modal-pane-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* The default overlay variant keeps its existing styling (rule at line ~1098). */
.editor-tabs { display: flex; gap: 4px; padding: 12px 16px 0; border-bottom: 1px solid var(--tph-gray2); }
.editor-tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--tph-gray6);
  font-weight: 500;
  font-family: inherit;
  font-size: 13.5px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.editor-tab.active { color: var(--tph-gray9); border-bottom-color: var(--tph-primary); }
.editor-tab:hover:not(.active) { color: var(--tph-gray9); }
.editor-pane { padding: 18px; overflow: auto; min-height: 0; }
.editor-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--tph-gray2); background: var(--tph-gray1); }

.device-card {
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--tph-gray2);
  background: var(--tph-bg-app);
  cursor: pointer;
  margin-bottom: 6px;
  transition: background .12s, border-color .12s;
}
.device-card:hover { background: var(--tph-gray1); border-color: var(--tph-primary); }
.device-card.selected { background: var(--tph-primary-superlight); border-color: var(--tph-primary); }
.device-card-name { font-weight: 500; font-size: 13.5px; color: var(--tph-gray9); }
.device-card-meta { font-size: 11.5px; color: var(--tph-gray6); margin-top: 2px; display: flex; gap: 6px; align-items: center; }

/* Preformatted JSON / XML block */
.code-block {
  background: var(--tph-gray9);
  color: #E8EAF2;
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.55;
  overflow: auto;
  max-height: 60vh;
}

/* === Chat (refine) === */
.chat-shell { display: grid; grid-template-rows: 1fr auto; height: 100%; min-height: 0; }
.chat-list { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { padding: 10px 14px; border-radius: var(--radius); max-width: 78%; line-height: 1.45; font-size: 13.5px; }
.chat-msg-user { background: var(--tph-primary-superlight); border: 1px solid var(--tph-primary-light); color: var(--tph-primary-dark); margin-left: auto; }
.chat-msg-assistant { background: var(--tph-gray1); border: 1px solid var(--tph-gray2); color: var(--tph-gray9); }
.chat-msg-tool { background: var(--tph-violet-light); border: 1px solid var(--tph-violet-medium); color: #6F3AB7; font-family: 'JetBrains Mono', monospace; font-size: 12.5px; }
.chat-input-row { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--tph-gray2); background: var(--tph-bg-app); }
.chat-input-row .form-input { flex: 1; }

/* === Trace panel (Run on real core) === */
.trace-panel {
  background: var(--tph-gray9);
  color: #E8EAF2;
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.6;
}
.trace-step { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 4px 0; }
.trace-time { color: var(--tph-gray5); }
.trace-ok { color: #6CEEDF; }
.trace-warn { color: #FFA312; }
.trace-err { color: #FE5449; }

/* === Admin two-pane === */
.admin-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}
.admin-queue { background: var(--tph-bg-app); border: 1px solid var(--tph-gray2); border-radius: var(--radius-md); overflow: hidden; }
.admin-queue-item { padding: 14px 16px; border-bottom: 1px solid var(--tph-gray2); cursor: pointer; transition: background .12s; }
.admin-queue-item:last-child { border-bottom: none; }
.admin-queue-item:hover { background: var(--tph-gray1); }
.admin-queue-item.selected { background: var(--tph-primary-superlight); border-left: 3px solid var(--tph-primary); padding-left: 13px; }
.admin-detail { display: grid; gap: 16px; }
.gate-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 13.5px; border-bottom: 1px dashed var(--tph-gray2); }
.gate-item:last-child { border-bottom: none; }
.gate-pass { color: #1F7C2A; }
.gate-fail { color: #A6121C; }
.gate-icon { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 10px; flex-shrink: 0; }
.gate-icon.pass { background: var(--tph-success-light); color: #1F7C2A; }
.gate-icon.fail { background: var(--tph-error-light); color: #A6121C; }

/* === Toast === */
.toast-host {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  /* Cap the row width so a burst of toasts can't push past the viewport — the
     toasts themselves clip with text-overflow at their own max-width. */
  max-width: calc(100vw - 48px);
  flex-wrap: wrap-reverse;
  justify-content: flex-end;
}
.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.18s ease-out, toast-out 0.4s ease-in 3.6s forwards;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.toast-success { background: var(--tph-success); color: white; }
.toast-error   { background: var(--tph-error);   color: white; }
.toast-info    { background: var(--tph-primary); color: white; }
/* The persistent action-log badge reuses .toast-info but overrides the
   auto-fade so it stays put. */
.toast.toast-info {
  animation: toast-in 0.18s ease-out;
  border: none;
  font: inherit;
  font-size: 13.5px;
}

/* === Action log panel === */
.action-log-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 31, 0.42);
  z-index: 1100;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 24px;
  animation: toast-in 0.18s ease-out;
}
.action-log-panel {
  background: var(--tph-bg-app);
  border: 1px solid var(--tph-gray2);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: min(440px, calc(100vw - 48px));
  max-height: min(520px, calc(100vh - 96px));
  display: flex;
  flex-direction: column;
}
.action-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--tph-gray2);
  font-size: 14px;
  font-weight: 500;
  color: var(--tph-gray9);
}
.action-log-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  overflow-y: auto;
  flex: 1;
}
.action-log-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  padding: 10px 16px;
  align-items: start;
  border-bottom: 1px solid var(--tph-gray1);
}
.action-log-item:last-child { border-bottom: none; }
.action-log-glyph {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  margin-top: 1px;
}
.action-log-success .action-log-glyph { background: var(--tph-success-light); color: #1F7C2A; }
.action-log-error   .action-log-glyph { background: var(--tph-error-light);   color: #A6121C; }
.action-log-tool {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--tph-gray9);
  word-break: break-word;
}
.action-log-detail {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--tph-gray6);
  line-height: 1.45;
  word-break: break-word;
}
.action-log-time {
  font-size: 11.5px;
  color: var(--tph-gray5);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-top: 2px;
}
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateY(8px); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* === Chat "typing" indicator (assistant bubble waiting for first token) === */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}
.typing-dots > span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tph-gray5);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dots > span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots > span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30%           { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .typing-dots > span { animation: none; opacity: 0.7; }
}

/* === Login (centered glass-ish card) === */
.auth-shell {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(at 30% 20%, var(--tph-primary-superlight) 0%, transparent 50%),
    radial-gradient(at 80% 80%, var(--tph-violet-light) 0%, transparent 50%),
    var(--tph-bg-app);
}
.auth-card {
  max-width: 420px;
  width: calc(100% - 32px);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-xl);
  padding: 40px 32px 28px;
  border: 1px solid var(--tph-gray2);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-md);
  background: var(--tph-primary);
  color: white;
  font-weight: 700;
  font-size: 22px;
  margin-bottom: 16px;
  letter-spacing: 0.04em;
}
/* Login-card wordmark — larger than topbar to anchor the centred card. */
.auth-mark-logo {
  display: block;
  margin: 0 auto 4px;
  height: 36px;
  width: auto;
}
/* "portal" subtitle under the wordmark — lowercase, gray, h1-sized but lighter. */
.auth-title {
  margin: 0 0 6px;
  font-weight: 400;
  font-size: 22px;
  color: var(--tph-gray6);
  letter-spacing: 0.01em;
}

/* === Misc === */
.divider { height: 1px; background: var(--tph-gray2); margin: 16px 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row-spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.text-muted { color: var(--tph-gray6); }
.text-subtle { color: var(--tph-gray5); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.flex-1 { flex: 1; }

/* === Run on core dialog (mockup-matching) === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.40);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 32px;
  animation: modal-fade-in 0.16s ease-out;
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--tph-bg-app);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.20);
  width: min(720px, 100%);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-pop-in 0.18s cubic-bezier(0.2, 0.8, 0.4, 1);
}
@keyframes modal-pop-in { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  padding: 22px 24px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--tph-gray2);
}
.modal-title { font-size: 19px; font-weight: 500; margin-bottom: 4px; color: var(--tph-gray9); }
.modal-subtitle { font-size: 13px; color: var(--tph-gray6); }
.modal-close {
  background: transparent; border: none; padding: 4px 8px; cursor: pointer;
  color: var(--tph-gray5); font-size: 20px; line-height: 1;
}
.modal-close:hover { color: var(--tph-gray9); }

.modal-body { padding: 22px 24px; overflow: auto; flex: 1; }

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--tph-gray2);
  background: var(--tph-gray1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-footer-status { font-size: 13.5px; color: var(--tph-gray7); flex: 1; }
.modal-footer-status.is-error { color: #A6121C; }
.modal-footer-status.is-success { color: #1F7C2A; }

/* === 007-portal-mobile-responsive — modal as bottom-sheet ≤ 767px ===
   Pure-CSS sheet variant. Targets `.modal` and `.modal-lg` (.modal-lg widens
   beyond .modal so it must be re-overridden here). Covers both Modal.tsx
   consumers and hand-rolled .modal-overlay JSX in ApplyToCoreDialog /
   RunOnCoreDialog. */
@media (max-width: 767px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal,
  .modal-lg,
  .modal-md {
    width: 100%;
    max-width: none;
    max-height: 90dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
    animation: tph-sheet-in 220ms cubic-bezier(0.32, 0.72, 0, 1) forwards;
  }
  .modal-body {
    overscroll-behavior: contain;
  }
}

@keyframes tph-sheet-in {
  to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-lg,
  .modal-md {
    animation: none;
    transform: none;
  }
}

/* Connected-core card */
.core-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--tph-mint-light);
  margin-bottom: 18px;
}
.core-card-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.core-card-info { flex: 1; min-width: 0; }
.core-card-name { font-size: 15px; font-weight: 500; color: var(--tph-gray9); margin-bottom: 2px; }
.core-card-meta { font-size: 12.5px; color: var(--tph-gray7); }

/* Stats grid (RUN ID / DURATION / MODE / RESULT) */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat-card {
  border: 1px solid var(--tph-gray2);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.stat-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--tph-gray5);
  font-weight: 600;
  margin-bottom: 6px;
}
.stat-value {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 15px;
  font-weight: 500;
  color: var(--tph-gray9);
  line-height: 1.2;
}
.stat-value-muted { color: var(--tph-gray4); }
.stat-card.is-mode-dry .stat-value { color: var(--tph-warning); }
.stat-card.is-result-success .stat-value { color: #1F7C2A; }
.stat-card.is-result-error .stat-value { color: #A6121C; }

.script-label {
  font-size: 13px; font-weight: 500; color: var(--tph-gray7); margin-bottom: 8px;
}
.script-block {
  background: #0A1424;
  color: #E8EAF2;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow: auto;
  margin-bottom: 16px;
  white-space: pre;
}
.script-block .comment { color: #64748B; }
.script-block .keyword { color: #6CEEDF; }
.script-block .number  { color: #FFA312; }
.script-block .ident   { color: #BEEAFF; }

/* Inline trace inside the modal */
.modal .trace-panel { margin-top: 4px; }

/* Resolve-by-AI special-cased button — purple to match the AI / Claude callout style */
.btn-ai {
  background: var(--tph-violet-dark);
  color: white;
  border-color: var(--tph-violet-dark);
}
.btn-ai:hover:not(:disabled) { filter: brightness(1.10); background: var(--tph-violet-dark); border-color: var(--tph-violet-dark); }

/* ─── Device editor — UI primitives ────────────────────────────────── */

.modal-md { width: min(720px, 100%); }
.modal-lg { width: min(1100px, 100%); max-height: 90vh; }

.tabs { display: flex; flex-direction: column; }
.tabs-bar {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--tph-gray2);
  margin-bottom: 16px;
}
.tab {
  background: none; border: none;
  padding: 10px 16px;
  font-size: 13px; font-weight: 500;
  cursor: pointer; color: var(--tph-gray6);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--tph-gray9); }
.tab-active { color: var(--tph-primary-dark); border-bottom-color: var(--tph-primary-dark); }
.tab-count {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  background: var(--tph-gray2); color: var(--tph-gray7);
  padding: 1px 6px; border-radius: 999px;
}

.ui-select {
  font: inherit; padding: 7px 10px;
  border: 1px solid var(--tph-gray3); border-radius: var(--radius-md, 6px);
  background: var(--tph-bg-app); color: var(--tph-text);
  min-width: 160px;
}
.ui-select:focus { outline: 2px solid var(--tph-primary); outline-offset: 1px; border-color: var(--tph-primary); }

.ui-switch {
  appearance: none; -webkit-appearance: none;
  width: 38px; height: 22px;
  background: var(--tph-gray3); border: none; border-radius: 999px;
  position: relative; cursor: pointer; transition: background 0.12s;
  padding: 0;
}
.ui-switch.is-checked { background: var(--tph-primary-dark); }
.ui-switch:disabled { opacity: 0.5; cursor: not-allowed; }
.ui-switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: white; border-radius: 50%;
  transition: transform 0.12s;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.18);
}
.ui-switch.is-checked .ui-switch-thumb { transform: translateX(16px); }

.ui-toggle { display: inline-flex; gap: 0; border: 1px solid var(--tph-gray3); border-radius: var(--radius-md, 6px); overflow: hidden; }
.ui-toggle-btn {
  background: var(--tph-bg-app); border: none;
  padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer;
  color: var(--tph-gray7);
}
.ui-toggle-btn:hover { background: var(--tph-gray1); }
.ui-toggle-btn.is-active { background: var(--tph-primary-dark); color: white; }

.ui-tooltip { display: inline-flex; cursor: help; }

.ui-disclosure { border: 1px solid var(--tph-gray2); border-radius: var(--radius-md, 6px); margin: 12px 0; }
.ui-disclosure-summary {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px;
  font-size: 13px; font-weight: 500; color: var(--tph-gray8);
  cursor: pointer; user-select: none;
  list-style: none;
}
.ui-disclosure-summary::-webkit-details-marker { display: none; }
.ui-disclosure-chevron { display: inline-block; transition: transform 0.15s; font-size: 14px; color: var(--tph-gray5); }
.ui-disclosure[open] .ui-disclosure-chevron { transform: rotate(90deg); }
.ui-disclosure-body { padding: 8px 14px 14px; border-top: 1px solid var(--tph-gray2); }

/* ─── Field grid / labels (used by ModelFieldRenderer) ────────────── */

.field-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px 16px;
  align-items: center;
  padding: 8px 0;
}
.field-row + .field-row { border-top: 1px solid var(--tph-gray1); }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.85fr);
}

.linklike {
  border: 0;
  background: transparent;
  color: var(--tph-primary);
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.field-label { font-size: 13px; color: var(--tph-gray7); font-weight: 500; }
.field-input { font: inherit; padding: 7px 10px; border: 1px solid var(--tph-gray3); border-radius: var(--radius-md, 6px); width: 100%; }
.field-input:focus { outline: 2px solid var(--tph-primary); outline-offset: 1px; border-color: var(--tph-primary); }
.field-section-heading {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--tph-gray6); text-transform: uppercase;
  margin: 16px 0 8px; padding-bottom: 4px;
  border-bottom: 1px solid var(--tph-gray2);
}

/* ─── Script editor (textarea + line-numbers) ─────────────────────── */

.script-field {
  display: grid; grid-template-columns: 40px 1fr;
  border: 1px solid var(--tph-gray3); border-radius: var(--radius-md, 6px);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  font-size: 13px; background: var(--tph-bg-app);
  overflow: hidden;
}
.script-line-numbers {
  background: var(--tph-gray1); color: var(--tph-gray5);
  text-align: right; padding: 8px 6px; margin: 0;
  user-select: none; white-space: pre; line-height: 1.5;
}
.script-textarea {
  border: none; padding: 8px 10px;
  resize: vertical; min-height: 220px;
  outline: none; background: transparent;
  font: inherit; line-height: 1.5;
  color: var(--tph-text);
}
.script-textarea:focus { box-shadow: inset 0 0 0 2px var(--tph-primary); }

/* ─── Icon picker ─────────────────────────────────────────────────── */

.icon-picker-search {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--tph-gray3); border-radius: var(--radius-md, 6px);
  font: inherit; margin-bottom: 16px;
}
.icon-picker-grid { display: flex; flex-direction: column; gap: 18px; }
.icon-picker-section h4 {
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--tph-gray7); text-transform: uppercase;
  margin: 0 0 8px;
}
/* Feature 009 E-17 — bumped grid cell minimum from 56→72px and inner glyph
   from 28→40px so icons are easier to scan in the picker. Tester feedback. */
.icon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}
.icon-tile {
  background: var(--tph-bg-app); border: 1px solid var(--tph-gray2);
  border-radius: var(--radius-md, 6px);
  padding: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1; transition: border-color 0.12s, background 0.12s;
  color: var(--tph-gray8);
}
.icon-tile:hover { border-color: var(--tph-primary-medium); background: var(--tph-primary-superlight); color: var(--tph-primary-dark); }
.icon-tile.selected { border-color: var(--tph-primary-dark); border-width: 2px; background: var(--tph-primary-superlight); color: var(--tph-primary-dark); }
/* Legacy mask-tinted glyph — kept for components still using it. New code uses
 * `.icon-tile-img` (real <img>) so multi-path SVGs with background fills render
 * with their authored colors instead of collapsing to the outermost shape. */
.icon-tile-glyph {
  display: inline-block;
  width: 40px; height: 40px;
  background: currentColor;
}
.icon-tile-img {
  display: inline-block;
  width: 40px; height: 40px;
  object-fit: contain;
}

/* Feature 009 E-16 — per-register semantic-meaning sub-label rendered in
   DeviceOverview between the register name and the script body. Distinct
   from `.text-subtle` description rendering; italic + slightly muted. */
.overview-script-meaning {
  font-size: 12px;
  color: var(--tph-gray6);
  font-style: italic;
  margin: 2px 0 6px 0;
}

/* Feature 009 E-18 — provenance Sources panel above the editor tabs. */
.sources-panel {
  margin: 0 0 12px 0;
  padding: 8px 12px;
  background: var(--tph-gray1);
  border: 1px solid var(--tph-gray2);
  border-radius: var(--radius-md, 6px);
  font-size: 13px;
}
.sources-panel summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--tph-gray8);
  user-select: none;
}
.sources-panel-list {
  list-style: none;
  margin: 8px 0 0 0;
  padding: 0;
}
.sources-panel-list li { margin: 2px 0; }
.sources-panel-list a {
  color: var(--tph-primary);
  text-decoration: none;
}
.sources-panel-list a:hover { text-decoration: underline; }
.sources-panel-list a.is-primary { font-weight: 600; }

/* ─── Value grid (MultiValueSwitch) ───────────────────────────────── */

.value-grid {
  display: grid;
  grid-template-columns: 60px 1fr 80px 32px;
  gap: 8px 12px;
  align-items: center;
}
.value-grid-header { font-size: 11px; font-weight: 600; color: var(--tph-gray6); text-transform: uppercase; }
.value-grid-icon-btn {
  width: 48px; height: 48px;
  border: 1px solid var(--tph-gray3); border-radius: var(--radius-md, 6px);
  background: var(--tph-bg-app); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.value-grid-icon-btn img { width: 28px; height: 28px; }
.value-grid-add { margin-top: 12px; }

/* ─── Custom variables / service scripts editor ───────────────────── */

.cv-editor, .ss-editor { display: flex; flex-direction: column; gap: 6px; }
.cv-row, .ss-row {
  display: grid;
  grid-template-columns: 1fr 140px 1fr 32px;
  gap: 8px;
  align-items: center;
}
.ss-row { grid-template-columns: 1fr 32px; }
.cv-row .field-input, .ss-row .field-input { width: 100%; }

/* ─── Device list / cards ─────────────────────────────────────────── */

.device-list { display: flex; flex-direction: column; gap: 8px; }
.device-card {
  display: grid;
  grid-template-columns: 36px 1fr auto auto;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--tph-gray2); border-radius: var(--radius-md, 6px);
  background: var(--tph-bg-app);
  align-items: center;
  cursor: pointer; transition: border-color 0.12s, background 0.12s;
}
.device-card:hover { border-color: var(--tph-primary-medium); background: var(--tph-primary-superlight); }
.device-card-icon { width: 32px; height: 32px; color: var(--tph-gray7); }
.device-card-name { font-size: 14px; font-weight: 500; color: var(--tph-gray9); }
.device-card-model { font-size: 12px; color: var(--tph-gray6); margin-top: 2px; }
.device-card-actions { display: flex; gap: 6px; align-items: center; }

.editor-pane {
  display: flex; flex-direction: column; gap: 12px;
}
.editor-pane-heading {
  font-size: 14px; font-weight: 600; color: var(--tph-gray9);
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.editor-pane-status {
  font-size: 12px; color: var(--tph-gray5);
}
.editor-pane-status.is-error { color: var(--tph-error); }

/* ─── Overview-style read-only details (DeviceOverview / ModuleEditor) ─── */

.device-overview { display: flex; flex-direction: column; gap: 4px; }
.overview-section { margin-top: 14px; }

.overview-details {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 6px 16px;
  margin: 0; padding: 0;
}
.overview-detail-row { display: contents; }
.overview-detail-row dt {
  font-size: 13px; color: var(--tph-gray6); margin: 0;
  padding: 4px 0;
}
.overview-detail-row dd {
  margin: 0; padding: 4px 0;
  font-size: 13px; color: var(--tph-gray9);
  word-break: break-word;
}

.overview-script-label {
  font-size: 12px; font-weight: 600; color: var(--tph-gray7);
  margin-bottom: 4px;
}

.overview-hint {
  margin: 16px 0 0;
  padding: 10px 12px;
  background: var(--tph-primary-superlight);
  border-left: 3px solid var(--tph-primary-medium);
  border-radius: 4px;
  font-size: 12.5px; color: var(--tph-gray7);
  line-height: 1.5;
}

.script-field-readonly { background: var(--tph-gray1); }
.script-readonly-body {
  margin: 0; padding: 8px 10px;
  font: inherit; line-height: 1.5;
  color: var(--tph-gray8);
  white-space: pre-wrap; word-break: break-word;
  overflow-x: auto;
}

.value-grid-byte-pill {
  display: inline-block;
  padding: 2px 8px;
  background: var(--tph-gray2);
  color: var(--tph-gray7);
  border-radius: 999px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  white-space: nowrap;
}

/* ─── Community ratings ────────────────────────────────────────────── */

.rating-widget {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px;
  background: var(--tph-gray1); border-radius: var(--radius-md, 6px);
}
.rating-widget-stars {
  display: inline-flex; gap: 2px; line-height: 1;
}
.rating-star {
  background: none; border: none; padding: 4px 6px;
  cursor: pointer; font-size: 28px;
  color: var(--tph-gray3);
  transition: color 0.1s, transform 0.05s;
  line-height: 1;
}
.rating-star:hover { transform: scale(1.08); }
.rating-star:disabled { cursor: wait; opacity: 0.7; }
.rating-star.is-filled { color: var(--tph-warning); }
.rating-star.is-mine { text-shadow: 0 0 0 var(--tph-warning); }
.rating-widget-aggregate { font-size: 13px; color: var(--tph-gray8); }
.rating-widget-error {
  font-size: 12.5px; color: var(--tph-error);
  margin-top: 4px;
}

/* ─── Community comments ───────────────────────────────────────────── */

.comments-section { display: flex; flex-direction: column; gap: 16px; }
.comments-form {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 16px;
  background: var(--tph-gray1); border-radius: var(--radius-md, 6px);
}
.comments-input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--tph-gray3); border-radius: var(--radius-md, 6px);
  font: inherit; resize: vertical;
  background: var(--tph-bg-app);
}
.comments-input:focus { outline: 2px solid var(--tph-primary); outline-offset: 1px; border-color: var(--tph-primary); }
.comments-form-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}

.comments-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 12px;
}
.comments-item {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--tph-gray2); border-radius: var(--radius-md, 6px);
  background: var(--tph-bg-app);
}
.comments-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--tph-primary); color: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
}
.comments-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.comments-meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--tph-gray8);
}
.comments-text {
  font-size: 14px; color: var(--tph-gray9);
  line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.comments-delete {
  margin-left: auto;
  background: transparent; border: none;
  color: var(--tph-gray5); cursor: pointer;
  font-size: 18px; padding: 0 6px;
}
.comments-delete:hover { color: var(--tph-error); }
.comments-delete:disabled { opacity: 0.4; cursor: wait; }

/* === 007-portal-mobile-responsive — page padding + admin-shell sweep === */
@media (max-width: 767px) {
  .main { padding: 16px; }
  .location-grid { gap: 12px; }
  .session-grid { gap: 12px; }

  .admin-shell {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  /* Cap the queue height so the detail pane is reachable without scrolling
     past the entire list. The plan suggested per-row chevron disclosure but
     `.admin-queue-item` rows are already short summaries (slug + 1-2 lines)
     so capping the list region is materially better UX. */
  .admin-queue {
    max-height: 220px;
    overflow-y: auto;
  }
}

/* Single column at very narrow widths — auto-fill normally collapses .session-grid
   below ~360px, but lock the explicit fallback so future card-min-width tweaks
   can't regress mobile. */
@media (max-width: 479px) {
  .session-grid { grid-template-columns: 1fr; }
}

/* === 007 — CommunityDetail hero, TemplateEdit titlebar, content overflow guards === */

/* CommunityDetail hero — 2-col on desktop, stacks on mobile */
.cd-hero {
  display: grid;
  grid-template-columns: minmax(0, 240px) 1fr;
  gap: 32px;
  align-items: start;
}
.cd-hero-info { min-width: 0; }
.cd-hero-title {
  font-size: 34px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 767px) {
  .cd-hero {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .cd-hero-image {
    max-width: 200px;
    margin: 0 auto;
  }
  .cd-hero-title {
    font-size: 26px;
  }
}

/* TemplateEdit titlebar — title + chip on left, actions on right; stacks on mobile */
.editor-titlebar-text { min-width: 0; flex: 1; }
.editor-title {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
.editor-titlebar-titlerow { flex-wrap: wrap; min-width: 0; }
.editor-titlebar-actions { flex-wrap: wrap; }

@media (max-width: 767px) {
  .editor-titlebar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .editor-title { font-size: 22px; line-height: 1.25; }
  .editor-titlebar-actions {
    justify-content: flex-start;
  }
}

/* Markdown content — never push parent past viewport */
.markdown {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.markdown pre {
  max-width: 100%;
}
.markdown table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

/* Tabs — content panel must not force the bar wide */
.tabs, .tabs-panel { min-width: 0; max-width: 100%; }
.tabs-panel { overflow-wrap: anywhere; }
@media (max-width: 767px) {
  .tabs-bar { flex-wrap: wrap; }
}

/* Field rows — 200px label + 1fr value column on desktop, stacked on mobile.
   Without this, value column collapses to ~150px and long values like
   `$[IpAddress]` wrap letter-by-letter. */
@media (max-width: 767px) {
  .field-row {
    grid-template-columns: 1fr;
    gap: 4px 0;
    padding: 10px 0;
  }
  .field-label {
    font-size: 12px;
    color: var(--tph-gray6);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  /* Same stacking for the schema-driven Connection details grid (220px + 1fr) */
  .overview-details {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .overview-detail-row dt {
    font-size: 11px;
    color: var(--tph-gray6);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 10px;
  }
  .overview-detail-row dd {
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tph-gray1);
  }
}

/* ─── Reference photo tiles — image with overlay action buttons ─────── */

.photo-tile {
  position: relative;
  border: 1px solid var(--tph-gray2);
  border-radius: 8px;
  background: var(--tph-bg-card, white);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.photo-tile.is-hero {
  border-color: var(--tph-primary);
  box-shadow: 0 0 0 2px var(--tph-primary-superlight, rgba(0, 134, 230, 0.18));
}
.photo-tile-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--tph-gray2);
  overflow: hidden;
}
.photo-tile-img-wrap > img,
.photo-tile-img-wrap > div {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--tph-gray6);
  border-top: 1px solid var(--tph-gray1);
}
.photo-hero-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tph-primary);
  color: white;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.photo-tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px;
  background: linear-gradient(180deg, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
  opacity: 0;
  transition: opacity .15s;
}
.photo-tile:hover .photo-tile-overlay,
.photo-tile:focus-within .photo-tile-overlay {
  opacity: 1;
}
.photo-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.92);
  color: var(--tph-gray9);
  cursor: pointer;
  padding: 0;
  transition: background .15s, color .15s, transform .15s;
}
.photo-action-btn:hover:not(:disabled) {
  background: white;
  color: var(--tph-primary);
  transform: scale(1.05);
}
.photo-action-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.photo-action-btn.is-active { background: var(--tph-primary); color: white; border-color: var(--tph-primary); }
.photo-action-btn.is-danger:hover:not(:disabled) { color: var(--tph-error); }
.photo-action-btn svg { width: 16px; height: 16px; display: block; }

/* Styled file-upload button that wraps a hidden <input type="file">. */
.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px dashed var(--tph-gray3);
  background: var(--tph-bg-app);
  color: var(--tph-gray9);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.upload-btn:hover { border-color: var(--tph-primary); color: var(--tph-primary); background: var(--tph-primary-superlight, rgba(0, 134, 230, 0.08)); }
.upload-btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.upload-btn svg { width: 14px; height: 14px; }
.upload-btn input[type="file"] { display: none; }
