/* =============================================================
   Context Grammar Simulator — UI Preview styles
   =============================================================
   Pure-CSS device frames, monochrome with one accent (red, used
   only for `data-priority="critical"`). All state changes via
   data-attribute selectors.
   ============================================================= */

/* ─── Stage (holds the device) ─── */
.preview-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(420px, 55vh, 580px);
  padding: clamp(20px, 3vw, 40px);
  background: var(--bg-2);
  /* Subtle radial spotlight under the device — gives the frame somewhere to sit. */
  background-image: radial-gradient(ellipse 70% 55% at 50% 60%, var(--bg) 0%, var(--bg-2) 70%);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Device flash on scenario / preset / reset change.
   Duration tuned to finish *just after* the form-factor morph (preview transition: 0.32s). */
@keyframes device-flash {
  0%   { box-shadow: 0 22px 56px -16px rgba(0,0,0,0.45), 0 0 0 0 rgba(104, 137, 180, 0.5); }
  60%  { box-shadow: 0 22px 56px -16px rgba(0,0,0,0.45), 0 0 0 10px rgba(104, 137, 180, 0); }
  100% { box-shadow: 0 22px 56px -16px rgba(0,0,0,0.45), 0 0 0 0 rgba(104, 137, 180, 0); }
}
.device.is-flashing {
  animation: device-flash 0.45s var(--ease-out-soft) 1;
}
@media (prefers-reduced-motion: reduce) {
  .device.is-flashing { animation: none; }
}

.preview-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.2px;
  padding: 6px 12px;
  background: var(--cat-escalation);
  color: #fff;
  z-index: 10;
}
.preview-banner[hidden] { display: none; }

/* ─── Device frame (pure CSS — no images) ─── */
.device {
  position: relative;
  background: #0a0a0a;
  padding: 12px;
  transition:
    width 0.32s var(--ease-out-soft),
    aspect-ratio 0.32s var(--ease-out-soft),
    border-radius 0.32s var(--ease-out-soft);
  /* Two-layer shadow: tight contact shadow + soft floating shadow */
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 24px 48px -20px rgba(0, 0, 0, 0.22);
}

.device-bezel {
  width: 100%;
  height: 100%;
  position: relative;
}

.device-screen {
  background: #fafafa;
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px;
  box-sizing: border-box;
}

/* Hide all detail elements by default; per-form rules show them */
.device-notch, .device-speaker { display: none; }

/* ─── Per-form geometry ─── */
.device[data-form="phone_handheld"] {
  aspect-ratio: 9 / 19.5;
  width: 240px;
  border-radius: 36px;
}
.device[data-form="phone_handheld"] .device-screen { border-radius: 24px; }
.device[data-form="phone_handheld"] .device-notch {
  /* Dynamic Island — proper floating pill INSIDE the screen, not stuck to bezel */
  display: block;
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 22px;
  background: #0a0a0a;
  border-radius: 12px;
  z-index: 5;
}

.device[data-form="phone_unfolded"] {
  aspect-ratio: 7 / 8;
  width: 320px;
  border-radius: 18px;
}
.device[data-form="phone_unfolded"] .device-screen {
  border-radius: 8px;
  background: linear-gradient(90deg, #fafafa 0%, #fafafa 49.6%, #e4e4e7 50%, #e4e4e7 50.4%, #fafafa 50.8%, #fafafa 100%);
}

.device[data-form="phone_folded"] {
  aspect-ratio: 1 / 1.4;
  width: 140px;
  border-radius: 22px;
}
.device[data-form="phone_folded"] .device-screen { border-radius: 14px; }

.device[data-form="tablet"] {
  aspect-ratio: 4 / 3;
  width: 460px;
  border-radius: 16px;
}
.device[data-form="tablet"] .device-screen { border-radius: 6px; }

.device[data-form="tv_display"] {
  aspect-ratio: 16 / 9;
  width: 560px;
  border-radius: 8px;
  padding: 8px;
}
.device[data-form="tv_display"] .device-screen { border-radius: 2px; }
/* TV stand: thin neck + flat base (no trapezoid clip-path) */
.device[data-form="tv_display"]::before {
  content: '';
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 16px;
  background: #1a1a1a;
}
.device[data-form="tv_display"]::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90px;
  height: 4px;
  background: #1a1a1a;
  border-radius: 2px;
}

.device[data-form="fridge_display"] {
  aspect-ratio: 1 / 1.05;
  width: 360px;
  border-radius: 12px;
  padding: 10px 10px 14px;
}
.device[data-form="fridge_display"] .device-screen { border-radius: 6px; }
.device[data-form="fridge_display"] .device-speaker {
  display: block;
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 4px;
  background: repeating-linear-gradient(
    90deg,
    transparent 0,
    transparent 2px,
    rgba(255,255,255,0.18) 2px,
    rgba(255,255,255,0.18) 4px
  );
  z-index: 5;
}

.device[data-form="car_display"] {
  aspect-ratio: 21 / 9;
  width: 620px;
  border-radius: 14px;
  padding: 10px;
}
.device[data-form="car_display"] .device-screen { border-radius: 4px; background: #1a1a1a; color: #f0ece4; }
.device[data-form="car_display"] .app-card { background: #0f0f0f; border-color: #2a2a2a; color: #f0ece4; }
.device[data-form="car_display"] .app-card .card-meta { color: #a1a1aa; }
.device[data-form="car_display"] .app-title { color: #f0ece4; }

.device[data-form="watch"] {
  aspect-ratio: 1 / 1.15;
  width: 160px;
  border-radius: 36px;
  padding: 8px;
}
.device[data-form="watch"] .device-screen { border-radius: 28px; padding: 10px; background: #0a0a0a; color: #f0ece4; }
.device[data-form="watch"] .app-statusbar { color: #a1a1aa; }
.device[data-form="watch"] .app-card { background: #1a1a1a; border-color: #2a2a2a; color: #f0ece4; padding: 8px; }
.device[data-form="watch"] .app-card .card-meta { color: #a1a1aa; }
.device[data-form="watch"] .app-title { color: #f0ece4; }
.device[data-form="watch"] .app-action { display: none; }
.device[data-form="watch"]::before {
  /* Crown nub on right */
  content: '';
  position: absolute;
  top: 38%;
  right: -4px;
  width: 4px;
  height: 24px;
  background: #2a2a2a;
  border-radius: 0 2px 2px 0;
}

.device[data-form="desktop_monitor"] {
  aspect-ratio: 16 / 10;
  width: 580px;
  border-radius: 10px;
  padding: 10px;
}
.device[data-form="desktop_monitor"] .device-screen { border-radius: 2px; }
/* Desktop stand: thin neck + flat base */
.device[data-form="desktop_monitor"]::before {
  content: '';
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 22px;
  background: #1a1a1a;
}
.device[data-form="desktop_monitor"]::after {
  content: '';
  position: absolute;
  bottom: -26px;
  left: 50%;
  transform: translateX(-50%);
  width: 130px;
  height: 4px;
  background: #1a1a1a;
  border-radius: 2px;
}

/* Mobile shrink */
@media (max-width: 768px) {
  .device[data-form="tv_display"]      { width: 320px; }
  .device[data-form="fridge_display"]  { width: 280px; }
  .device[data-form="tablet"]          { width: 280px; }
  .device[data-form="car_display"]     { width: 320px; }
  .device[data-form="desktop_monitor"] { width: 320px; }
  .device[data-form="phone_unfolded"]  { width: 240px; }
}

/* ─── App contents inside device-screen ─── */
.app-statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: #737373;
  margin-bottom: 8px;
}
.app-statusbar__icons { letter-spacing: 1px; font-size: 8px; }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e4e4e7;
}
.app-title {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.2px;
  color: #0a0a0a;
}
.app-priority-badge {
  display: none;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 1.5px;
  font-weight: 600;
  padding: 3px 7px;
}
.app-priority-badge[data-priority="critical"] { display: inline-block; background: #cc3344; color: #fff; }
.app-priority-badge[data-priority="high"]     { display: inline-block; background: #0a0a0a; color: #fff; }
.app-priority-badge[data-priority="standard"] { display: inline-block; background: #e4e4e7; color: #525252; }
.app-priority-badge[data-priority="low"]      { display: inline-block; background: transparent; color: #a1a1aa; border: 1px solid #e4e4e7; }

/* ─── App grid (cards) ─── */
.app-grid {
  display: grid;
  gap: 6px;
  flex: 1;
  align-content: start;
  margin-bottom: 10px;
}
.app-grid[data-count="1"] { grid-template-columns: 1fr; }
.app-grid[data-count="2"] { grid-template-columns: 1fr; }
.app-grid[data-count="3"] { grid-template-columns: 1fr 1fr; }
.app-grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.app-grid[data-count="5"] { grid-template-columns: 1fr 1fr; }
.app-grid[data-count="6"] { grid-template-columns: 1fr 1fr 1fr; }
.app-grid[data-count="7"] { grid-template-columns: 1fr 1fr 1fr; }
.app-grid[data-count="8"] { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* TV / desktop / tablet — use wider grids */
.device[data-form="tv_display"] .app-grid,
.device[data-form="desktop_monitor"] .app-grid,
.device[data-form="tablet"] .app-grid {
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
}

.app-card {
  position: relative;
  background: #fff;
  border: 1px solid #e4e4e7;
  padding: 10px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11px;
  color: #0a0a0a;
  transition: opacity 0.18s var(--ease-out-soft), transform 0.18s var(--ease-out-soft);
}
.app-card.is-entering {
  opacity: 0;
  transform: translateY(6px);
  animation: card-enter 0.24s var(--ease-out-soft) forwards;
}
.app-card.is-leaving {
  opacity: 0;
  transform: translateY(-4px);
}
@keyframes card-enter {
  to { opacity: 1; transform: translateY(0); }
}

[data-density="low"] .app-card    { padding: 16px; min-height: 72px; }
[data-density="medium"] .app-card { padding: 10px; min-height: 52px; }
[data-density="high"] .app-card   { padding: 7px;  min-height: 36px; font-size: 10px; }

.card-icon {
  font-family: var(--font-mono);
  font-size: 14px;
  color: #525252;
  flex-shrink: 0;
  line-height: 1;
}
.card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.card-title {
  font-weight: 500;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  font-family: var(--font-mono);
  font-size: 9px;
  color: #737373;
  letter-spacing: 0.3px;
}
.card-price {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  margin-top: 2px;
  color: #0a0a0a;
}
.card-lock {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #a1a1aa;
  position: absolute;
  top: 6px;
  right: 6px;
}
.card-pill {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #737373;
  background: #f4f4f5;
  padding: 2px 5px;
  position: absolute;
  bottom: 4px;
  right: 4px;
}

/* Redaction */
.app-card[data-redact="prices"] .card-price { filter: blur(5px); user-select: none; }
.app-card[data-redact="full"]   .card-title,
.app-card[data-redact="full"]   .card-meta,
.app-card[data-redact="full"]   .card-price { filter: blur(6px); user-select: none; }

/* Strikethrough (feasibility partial/infeasible) */
.app-card.is-strikethrough .card-title { text-decoration: line-through; color: #a1a1aa; }

/* ─── Action button ─── */
.app-action { margin-top: auto; }
.app-button {
  width: 100%;
  padding: 10px 14px;
  background: #0a0a0a;
  color: #fff;
  border: none;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s var(--ease-hover);
}
.app-button:hover { background: #1a1a1a; }
.app-button[data-autonomy="auto"] {
  background: transparent;
  color: #737373;
  border: 1px dashed #d4d4d8;
  font-style: italic;
}
.app-button[data-autonomy="auto"]:hover { background: #f4f4f5; }
.app-button[data-autonomy="suggest"] {
  background: #fff;
  color: #0a0a0a;
  border: 1px solid #0a0a0a;
}
.app-button[data-autonomy="notify"] {
  background: #525252;
}

/* ─── Driving overlay ─── */
.device[data-driving="true"] .app-grid,
.device[data-driving="true"] .app-action,
.device[data-driving="true"] .app-header {
  opacity: 0.18;
  pointer-events: none;
  filter: grayscale(1);
  transition: opacity 0.24s var(--ease-out-soft), filter 0.24s var(--ease-out-soft);
}
.app-voice-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(250, 250, 250, 0.92);
  text-align: center;
  z-index: 4;
}
.device[data-form="car_display"] .app-voice-overlay,
.device[data-form="watch"] .app-voice-overlay {
  background: rgba(10, 10, 10, 0.92);
  color: #f0ece4;
}
.app-voice-overlay[hidden] { display: none; }
.app-voice-waves {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  align-items: center;
  height: 32px;
}
.app-voice-waves span {
  display: block;
  width: 4px;
  height: 100%;
  background: currentColor;
  animation: wave 1.4s ease-in-out infinite alternate;
}
.app-voice-waves span:nth-child(2) { animation-delay: 0.2s; }
.app-voice-waves span:nth-child(3) { animation-delay: 0.4s; }
@keyframes wave {
  0%   { transform: scaleY(0.3); }
  100% { transform: scaleY(1); }
}
.app-voice-text {
  font-size: 12px;
  line-height: 1.5;
  margin: 0;
  color: inherit;
}
.app-voice-text em { font-style: italic; opacity: 0.7; }

/* ─── Empty state (disclosure = none) ─── */
.app-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border: 1px dashed #d4d4d8;
  background: #f9f9f9;
  text-align: center;
  margin: 4px 0;
}
.app-empty-state[hidden] { display: none; }
.app-empty-text {
  font-size: 13px;
  font-weight: 500;
  color: #525252;
  margin: 0 0 6px;
}
.app-empty-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #a1a1aa;
  letter-spacing: 0.5px;
  margin: 0;
}

/* ─── Legend caption below preview — single descriptive line, not a chip strip ─── */
.preview-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: clamp(16px, 2vw, 24px) 0 0;
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.55;
  max-width: 640px;
  margin: 0 auto;
  text-align: center;
}
.legend-form {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-3);
}
.legend-sep { color: var(--text-3); margin: 0 2px; }
.legend-state {
  color: var(--text);
  font-weight: 500;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .device,
  .app-card,
  .app-card.is-entering { transition: none; animation: none; }
  .app-voice-waves span { animation: none; transform: scaleY(0.6); }
}
