/**
 * Workspace-specific styles
 * Design system tokens loaded from static.minxi.ai (tokens.css + reset.css)
 */

/* ============================================
   Modern dark-theme alias map
   ============================================
   Cards/shell were authored against a `--color-*` / `--surface*` /
   `--minxi-*` namespace that the dark theme does not define. Map
   them here — but the goal isn't just bridging, it's a stricter
   2026 dark theme.

   The previous bridge used solid mid-greys (`--minxi-color-neutral-100`
   = `#374151`) for surfaces. That reads as "panel" but is jarring
   against the deep purple gradient body — small, almost-white
   patches that shout for attention.

   Now: translucent layered overlays. Floating panels (menus,
   awning, board cards on desktop) get a frosted-glass treatment via
   `backdrop-filter` so the gradient body bleeds through softly
   instead of being blocked. Borders are barely-there (6%) and lift
   to medium (12%) on hover. Shadows are deep + soft (no harsh
   edges). High-contrast text remains; everything else is dialled
   way back.
   ============================================ */
:root {
  /* === Surface levels — translucent overlays over the gradient body ===
     Each is a `text-primary`-tinted overlay so the surface picks up
     the body colour underneath but reads as a subtly raised plane.
     `surface-deep` is a true recess (darker than body) for inputs. */
  --surface:        color-mix(in srgb, var(--text-primary)  4%, transparent);
  --surface-alt:    color-mix(in srgb, var(--text-primary)  7%, transparent);
  --surface-raised: color-mix(in srgb, var(--text-primary) 10%, transparent);
  --surface-deep:   color-mix(in srgb, #000                25%, transparent);

  /* Refined borders — barely visible by default; accent or strong on
     focus/hover (defined per-element). `--border-color` is already
     defined by static.minxi.ai/css/theme-dark.css; we add softer +
     stronger variants here. */
  --border-soft:   color-mix(in srgb, var(--text-primary)  6%, transparent);
  --border-medium: color-mix(in srgb, var(--text-primary) 12%, transparent);

  /* Hover wash — lighter than --surface but still translucent. */
  --hover-bg: color-mix(in srgb, var(--text-primary) 6%, transparent);

  /* `--color-*` aliases used by cards in Waves 4–8 */
  --color-surface:        var(--surface);
  --color-surface-alt:    var(--surface-alt);
  --color-text-primary:   var(--text-primary);
  --color-text-secondary: var(--text-secondary);
  --color-text-tertiary:  var(--text-tertiary);
  --color-text-muted:     var(--text-muted);
  --color-border:         var(--border-soft);
  --color-accent:         var(--accent-primary);
  --color-accent-subtle:  color-mix(in srgb, var(--accent-primary) 18%, transparent);
  --color-error:          var(--color-danger);
  --color-update:         var(--color-warning);
  --color-urgent:         var(--color-danger);
  --color-calm:           var(--color-success);

  /* `--minxi-*` aliases used by card-poster + reminder + chat */
  --minxi-text-primary:    var(--text-primary);
  --minxi-text-secondary:  var(--text-secondary);
  --minxi-text-tertiary:   var(--text-tertiary);
  --minxi-card-bg:         var(--surface);
  --minxi-colour-calm:     var(--awning-ring-calm,     var(--color-success));
  --minxi-colour-whisper:  var(--awning-ring-whisper,  var(--accent-secondary));
  --minxi-colour-update:   var(--awning-ring-update,   var(--color-warning));
  --minxi-colour-question: var(--awning-ring-question, var(--color-warning));
  --minxi-colour-urgent:   var(--awning-ring-urgent,   var(--color-danger));

  /* Shell short-form tokens */
  --primary:       var(--accent-primary);
  --primary-hover: var(--minxi-color-primary-500, var(--accent-primary));
  --error:         var(--color-danger);
}

/* ============================================
   Frosted-glass treatment for floating panels
   ============================================
   The translucent `--surface-*` tokens above are too see-through on
   their own — text would compete with whatever's behind the panel.
   Add `backdrop-filter: blur()` on every floating panel so the
   body gradient is softened to a clean wash, and use
   `--surface-raised` so the panel reads slightly above the body.
   Soft, deep shadows (no harsh edges) and a 1px hairline border
   mark the panel's boundary. */
.belong-menu,
.card-type-menu,
.awning-panel,
.awning-float-panel,
.overflow-panel {
  background: var(--surface-raised);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--border-medium);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--text-primary) 6%, transparent),
    0 12px 40px -8px rgba(0, 0, 0, 0.45);
}

/* Desktop board cards — same frosted-glass treatment when they
   float on the spatial board (override the inline fallback white). */
minxi-shell[data-form-factor="desktop"] .active-surface .board-card {
  background: var(--surface);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border-color: var(--border-soft);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.4);
}

/* Form inputs — deep recess so they read as something you press into,
   not a chip floating on top. */
.awning-input,
.search-input {
  background: var(--surface-deep);
  border-color: var(--border-soft);
}
.awning-input:focus,
.search-input:focus {
  border-color: var(--accent-primary);
  background: color-mix(in srgb, var(--accent-primary) 4%, var(--surface-deep));
}

/* ============================================
   Screen management
   ============================================ */
.screen {
  width: 100%;
  height: 100dvh;
  position: absolute;
  top: 0;
  left: 0;
}

.screen[hidden] {
  display: none !important;
}

/* ============================================
   Auth Screen
   ============================================ */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--background-start), var(--background-end));
  color: var(--text-primary);
}

.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-lg);
  max-width: 400px;
  width: 100%;
}

.auth-logo {
  border-radius: var(--radius-lg);
}

.auth-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin: 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  width: 100%;
}

.auth-form[hidden] {
  display: none;
}

.auth-label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.auth-input {
  padding: 0.75rem var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--primary-surface);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--transition-fast);
}

.auth-input:focus {
  border-color: var(--accent-primary);
}

.auth-button {
  padding: 0.75rem var(--space-md);
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  color: var(--text-on-accent);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.auth-button:hover {
  opacity: 0.9;
}

.auth-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-link {
  background: none;
  border: none;
  color: var(--accent-primary);
  cursor: pointer;
  font-size: var(--font-size-sm);
  text-align: center;
  padding: var(--space-sm);
}

.auth-error {
  color: var(--color-error, #ef4444);
  font-size: var(--font-size-sm);
  min-height: 1.25rem;
  margin: 0;
}

/* ============================================
   Workspace Screen
   ============================================ */
#workspace-screen {
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--background-start), var(--background-end));
  color: var(--text-primary);
}

/* Header */
#workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-color);
  background: var(--primary-surface);
  height: 48px;
  flex-shrink: 0;
  z-index: 1000;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.header-icon {
  border-radius: var(--radius-sm);
}

.header-org {
  font-weight: var(--font-weight-semibold);
  font-size: 0.9375rem;
}

/* Org selector dropdown */
.org-selector-wrapper {
  position: relative;
}

.org-selector {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: var(--font-weight-semibold);
  padding: 0.25rem 1.5rem 0.25rem 0.5rem;
  cursor: pointer;
  outline: none;
  max-width: 200px;
  text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M3 5l3 3 3-3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.35rem center;
  transition: border-color var(--transition-fast);
}

.org-selector:hover {
  border-color: var(--accent-primary);
}

.org-selector:focus {
  border-color: var(--accent-primary);
}

.org-selector option {
  background: var(--primary-surface);
  color: var(--text-primary);
}

.header-action {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: var(--font-size-lg);
  transition: background var(--transition-fast);
}

.header-action:hover {
  background: var(--secondary-surface);
}

/* ============================================
   Workspace Board — Layout Modes
   ============================================ */
.workspace-board {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Desktop: spatial card board with free positioning */
.workspace-board[data-layout="desktop"] {
  overflow: auto;
}

/* Tablet: split view (2 cards side by side) */
.workspace-board[data-layout="tablet"] {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  padding: var(--space-sm);
  overflow-y: auto;
}

/* Mobile: card stack (one card visible, swipe navigation) */
.workspace-board[data-layout="mobile"] {
  display: flex;
  overflow: hidden;
}

/* ============================================
   Cards
   ============================================ */
.workspace-card {
  background: var(--primary-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition-base), opacity var(--transition-base);
}

.workspace-card:hover {
  box-shadow: 0 0 24px var(--glow-color);
}

.workspace-card.minimized .workspace-card-body,
.workspace-card.minimized .card-resize-handle {
  display: none;
}

.workspace-card.minimized {
  height: auto !important;
  min-height: 0 !important;
}

/* Desktop: absolute positioned */
.workspace-board[data-layout="desktop"] .workspace-card {
  position: absolute;
  min-width: 300px;
  min-height: 200px;
}

/* Tablet: fill grid cell */
.workspace-board[data-layout="tablet"] .workspace-card {
  min-height: 300px;
}

/* Mobile: full width, one visible */
.workspace-board[data-layout="mobile"] .workspace-card {
  flex: 0 0 100%;
  height: 100%;
}

.workspace-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) 0.75rem;
  border-bottom: 1px solid var(--border-color);
  cursor: grab;
  user-select: none;
}

.card-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: var(--space-sm);
}

.card-controls {
  display: flex;
  gap: 0.25rem;
}

.card-control-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.card-control-btn:hover {
  background: var(--secondary-surface);
  color: var(--text-primary);
}

.card-archive-btn:hover {
  color: var(--color-error, #ef4444);
}

.workspace-card-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* Card resize handle */
.card-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.card-resize-handle::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
}

.workspace-card:hover .card-resize-handle {
  opacity: 1;
}

/* Card sections */
.card-widget-area {
  flex: 1;
  padding: 0.75rem;
  min-height: 60px;
}

.card-chat-area {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border-color);
  min-height: 120px;
  max-height: 50%;
}

/* Show only chat in chat-only cards */
.workspace-card[data-card-type="standalone_chat"] .card-chat-area,
.workspace-card[data-card-type="chat_primary"] .card-chat-area {
  flex: 1;
  max-height: none;
  border-top: none;
}

.card-summary {
  padding: 0.5rem 0.75rem;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
}

.card-summary:empty {
  display: none;
}

.card-summary.has-summary {
  display: block;
}

/* ============================================
   Chat Interface
   ============================================ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-message {
  max-width: 85%;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-message-user {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: var(--text-on-accent);
}

.chat-message-assistant {
  align-self: flex-start;
  background: var(--secondary-surface);
  color: var(--text-primary);
}

.chat-message.streaming .chat-message-content::after {
  content: '\u258c';
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.chat-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0.75rem;
  align-self: flex-start;
}

.chat-typing-indicator[hidden] {
  display: none;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border-color);
}

.chat-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--secondary-surface);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--transition-fast);
}

.chat-input:focus {
  border-color: var(--accent-primary);
}

.chat-send-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--text-on-accent);
  cursor: pointer;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-bold);
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
}

.chat-send-btn:hover {
  opacity: 0.9;
}

/* ============================================
   Co-editing Shimmer
   ============================================ */
.coediting-shimmer {
  position: relative;
  overflow: hidden;
}

.coediting-shimmer::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 192, 203, 0.15),
    transparent
  );
  animation: shimmer 1.5s ease-in-out;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.coediting-field-locked {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.coediting-suggestion-pending {
  border-color: var(--accent-secondary);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.2);
}

/* ============================================
   Notifications
   ============================================ */
.notification-container {
  position: fixed;
  top: 56px;
  right: var(--space-md);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-width: 360px;
  width: 100%;
  pointer-events: none;
}

.notification {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: 0.75rem var(--space-md);
  border-radius: var(--radius-md);
  background: var(--secondary-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  pointer-events: all;
  animation: notificationSlideIn 0.3s ease-out;
}

.notification-info { border-left: 3px solid var(--accent-primary); }
.notification-success { border-left: 3px solid #22c55e; }
.notification-warning { border-left: 3px solid var(--accent-secondary); }
.notification-error { border-left: 3px solid var(--color-error, #ef4444); }

.notification-dismissing {
  animation: notificationSlideOut 0.3s ease-in forwards;
}

@keyframes notificationSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes notificationSlideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

.notification-message {
  flex: 1;
}

.notification-dismiss {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: var(--font-size-lg);
  padding: 0;
  line-height: 1;
}

.notification-dismiss:hover {
  color: var(--text-primary);
}

/* ============================================
   Mobile Card Navigation
   ============================================ */
.mobile-card-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: 0.75rem;
  border-top: 1px solid var(--border-color);
  background: var(--primary-surface);
  flex-shrink: 0;
}

.mobile-card-nav[hidden] {
  display: none;
}

.mobile-nav-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: var(--font-size-xl);
  transition: background var(--transition-fast);
}

.mobile-nav-btn:hover {
  background: var(--secondary-surface);
}

.card-indicator {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ============================================
   Empty Workspace State
   ============================================ */
.workspace-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: var(--space-md);
  color: var(--text-secondary);
}

.workspace-empty-icon {
  font-size: var(--font-size-5xl);
  opacity: 0.5;
}

.workspace-empty-text {
  font-size: var(--font-size-base);
}

/* ============================================
   Loading state
   ============================================ */
.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Responsive utilities
   ============================================ */
@media (max-width: 767px) {
  #btn-layout-toggle {
    display: none;
  }
}

@media (min-width: 768px) {
  .mobile-card-nav {
    display: none !important;
  }
}

/* ============================================
   Keyboard Focus Indicator (P2)
   ============================================ */
.workspace-card.keyboard-focused {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  box-shadow: 0 0 24px var(--glow-color), 0 0 0 3px rgba(255, 192, 203, 0.15);
}

/* ============================================
   Quick Switcher / Search Dialog (P2)
   ============================================ */
.search-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}

.search-dialog[hidden] {
  display: none;
}

.search-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 0, 20, 0.7);
}

.search-panel {
  position: relative;
  width: 100%;
  max-width: 500px;
  background: var(--primary-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  animation: searchSlideDown 0.15s ease-out;
}

@keyframes searchSlideDown {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.search-input {
  width: 100%;
  padding: 0.875rem var(--space-md);
  border: none;
  border-bottom: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-primary);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  outline: none;
  box-sizing: border-box;
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.search-filters {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-color);
}

.search-filter-btn {
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.search-filter-btn:hover {
  background: var(--secondary-surface);
  color: var(--text-primary);
}

.search-filter-btn.active {
  background: var(--accent-gradient);
  color: var(--text-on-accent);
  border-color: transparent;
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem var(--space-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.search-result-item:hover,
.search-result-item.highlighted {
  background: var(--secondary-surface);
}

.search-result-item[aria-selected="true"] {
  background: var(--secondary-surface);
}

.search-result-title {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: var(--space-sm);
}

.search-result-meta {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

.search-result-empty {
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

/* ============================================
   Sound toggle button (P2)
   ============================================ */
.sound-toggle {
  position: relative;
}

.sound-toggle[data-sound="off"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 25%;
  width: 50%;
  height: 2px;
  background: var(--text-secondary);
  transform: rotate(-45deg);
}

/* ============================================
   P3: Accessibility — Screen reader only
   ============================================ */
.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;
}

.sr-only-focusable:focus {
  position: fixed;
  top: 8px;
  left: 8px;
  width: auto;
  height: auto;
  padding: 0.75rem 1rem;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--primary-surface);
  color: var(--accent-primary);
  border: 2px solid var(--accent-primary);
  border-radius: var(--radius-md);
  z-index: 10000;
  font-size: var(--font-size-base);
  text-decoration: none;
}

/* ============================================
   P3: Accessibility — High contrast mode
   ============================================ */
.high-contrast {
  --border-color: #ffffff;
  --text-primary: #ffffff;
  --text-secondary: #e0e0e0;
  --glow-color: rgba(255, 255, 255, 0.3);
}

.high-contrast .workspace-card {
  border-width: 2px;
}

.high-contrast .card-control-btn:focus,
.high-contrast .header-action:focus,
.high-contrast .mobile-nav-btn:focus,
.high-contrast button:focus {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

.high-contrast .workspace-card.keyboard-focused {
  outline-width: 3px;
  outline-color: #ffffff;
}

.high-contrast .chat-message-user {
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.high-contrast .chat-message-assistant {
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ============================================
   P3: Accessibility — Reduced motion
   ============================================ */
.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ============================================
   P3: Animation — AI intelligence indicators
   ============================================ */
.ai-layer1-active {
  box-shadow: 0 0 8px rgba(255, 192, 203, 0.15);
}

.ai-layer2-active {
  box-shadow: 0 0 20px rgba(255, 192, 203, 0.3);
}

.ambient-active {
  /* Applied via JS animation, this class is a marker */
}

/* ============================================
   P3: Animation — Enhanced co-editing shimmer
   ============================================ */
.coediting-shimmer-enhanced {
  position: relative;
  overflow: hidden;
}

.coediting-shimmer-enhanced::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 192, 203, 0.08) 25%,
    rgba(255, 192, 203, 0.18) 50%,
    rgba(255, 192, 203, 0.08) 75%,
    transparent 100%
  );
  animation: shimmerEnhanced 1.5s ease-in-out;
}

@keyframes shimmerEnhanced {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* ============================================
   P4: Locale selector panel
   ============================================ */
.locale-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: var(--space-md);
  z-index: 2100;
  background: var(--primary-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  min-width: 220px;
  max-width: 280px;
  overflow: hidden;
  animation: localePanelSlideDown 0.15s ease-out;
}

.locale-panel[hidden] {
  display: none;
}

@keyframes localePanelSlideDown {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.locale-panel-header {
  padding: 0.625rem var(--space-md);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

.locale-panel-empty {
  padding: var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-align: center;
}

.locale-options {
  max-height: 280px;
  overflow-y: auto;
  padding: var(--space-xs) 0;
}

.locale-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: 0.5rem var(--space-md);
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast);
}

.locale-option:hover {
  background: var(--secondary-surface);
}

.locale-option:focus {
  outline: none;
  background: var(--secondary-surface);
}

.locale-option--active {
  color: var(--accent-primary);
}

.locale-flag {
  font-size: 1.125rem;
  line-height: 1;
  flex-shrink: 0;
  width: 1.5rem;
  text-align: center;
}

.locale-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.locale-name-en {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.locale-checkmark {
  font-size: var(--font-size-xs);
  color: var(--accent-primary);
  flex-shrink: 0;
  margin-left: auto;
}

/* ============================================
   P3: TWA mode
   ============================================ */
.twa-mode .browser-only {
  display: none !important;
}

.twa-mode {
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ============================================
   P3: Capacitor / iOS safe area
   ============================================ */
.capacitor-ios #workspace-header {
  padding-top: env(safe-area-inset-top, 0);
}

.capacitor-ios #mobile-card-nav {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ============================================================ *
 *  Global Assistant slide-out panel
 *  Mirrors the Min-in-internal-console pattern: a single
 *  persistent assistant outside the card canvas, toggled from
 *  the workspace header, sliding in from the right edge.
 * ============================================================ */

/* Backdrop — captures click-outside to close the panel.
 * Skips on mobile where the panel takes the whole viewport. */
.assistant-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease-out;
  z-index: 60;
}
.assistant-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
@media (max-width: 720px) {
  .assistant-backdrop { display: none; }
}

/* Panel itself. */
.assistant-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 90vw);
  background: var(--bg-elevated, #14111c);
  border-left: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.32);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 220ms ease-out;
  z-index: 70;
}
.assistant-panel.open {
  transform: translateX(0);
}
@media (max-width: 720px) {
  .assistant-panel {
    width: 100vw;
  }
}

.assistant-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md, 16px);
  padding: var(--space-md, 16px) var(--space-lg, 20px);
  border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
  flex: 0 0 auto;
}
.assistant-panel-title-wrap {
  flex: 1;
  min-width: 0;
}
.assistant-panel-title {
  margin: 0;
  font-size: var(--font-size-md, 1rem);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-primary, #fff);
  line-height: 1.2;
}
.assistant-panel-subtitle {
  margin: 4px 0 0 0;
  font-size: var(--font-size-xs, 0.8125rem);
  color: var(--text-secondary, rgba(255, 255, 255, 0.6));
  line-height: 1.3;
}
.assistant-panel-close {
  background: transparent;
  border: none;
  color: var(--text-secondary, rgba(255, 255, 255, 0.6));
  font-size: 1.5rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  cursor: pointer;
  border-radius: 4px;
  flex: 0 0 auto;
  transition: background 120ms ease-out, color 120ms ease-out;
}
.assistant-panel-close:hover,
.assistant-panel-close:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #fff);
}

/* Chat host fills the rest of the panel — chat.js's #buildUI
 * already produces a vertical column with messages-flex-fill +
 * fixed input area, which works nicely inside this. */
.assistant-panel-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--space-md, 16px) var(--space-lg, 20px);
}
.assistant-panel-chat .chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Toolbar Assistant toggle: emphasise active state to give
 * keyboard users + screen-reader users a clear "panel is open"
 * affordance. */
.header-action[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent-primary, #a78bfa);
}


/* ============================================================ *
 *  Service Recommender (formerly Sponsorship Offers panel)
 *  Subtle, non-pushy, only materialised when there's actually
 *  something to surface. Lives in the top-right corner so it
 *  doesn't compete with the workspace board's working area.
 * ============================================================ */

.service-recommender {
  position: fixed;
  top: 80px;
  right: 16px;
  z-index: 30;
  width: 340px;
  max-width: calc(100vw - 32px);
  background: var(--surface-bg, rgba(20, 20, 28, 0.94));
  color: var(--text-primary, #fff);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  padding: 12px 14px;
  font-size: 14px;
}

.service-recommender-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
}

.service-recommender-title {
  font-size: 13px;
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-primary, #fff);
}

.service-recommender-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}

.service-recommender-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary, rgba(255, 255, 255, 0.6));
  cursor: pointer;
  font-size: 14px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.service-recommender-btn:hover,
.service-recommender-btn:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #fff);
}

.service-recommender-body {
  display: flex;
  flex-direction: column;
}

.service-recommender-offer {
  padding: 8px 0;
  border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}

.service-recommender-offer:first-child { border-top: 0; }

.service-recommender-offer-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.service-recommender-offer-title {
  font-size: 13px;
  font-weight: var(--font-weight-semibold, 600);
}

.service-recommender-offer-provider {
  font-size: 11px;
  color: var(--text-secondary, rgba(255, 255, 255, 0.6));
  margin-top: 2px;
}

.service-recommender-offer-desc {
  margin: 4px 0 6px;
  font-size: 12px;
  line-height: 1.4;
}

.service-recommender-offer-reasons {
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--text-secondary, rgba(255, 255, 255, 0.55));
}

.service-recommender-offer-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.service-recommender-offer-error {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--accent-error, #ef4444);
}

.service-recommender-offer-confirm {
  margin: 0;
  font-size: 12px;
  color: var(--accent-primary, #a78bfa);
  font-weight: var(--font-weight-semibold, 600);
}

.service-recommender-offer-engaged {
  background: rgba(167, 139, 250, 0.06);
  border-radius: 6px;
  padding: 6px 8px;
}

.service-recommender-engage {
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  background: var(--accent-primary, #a78bfa);
  color: #fff;
  border: 1px solid var(--accent-primary, #a78bfa);
}

.service-recommender-engage:hover { filter: brightness(1.06); }
.service-recommender-engage[disabled] { opacity: 0.55; cursor: wait; }

.service-recommender-skip {
  padding: 4px 10px;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
  color: inherit;
  border-radius: 4px;
  cursor: pointer;
}

.service-recommender-skip:hover {
  background: rgba(255, 255, 255, 0.04);
}

/* Mode chip — small pill in the offer's top-right */
.service-recommender-chip {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: var(--font-weight-semibold, 600);
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.service-recommender-chip-paid {
  background: rgba(74, 222, 128, 0.16);
  color: #4ade80;
}

.service-recommender-chip-free {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary, rgba(255, 255, 255, 0.7));
}

.service-recommender-chip-rewarded {
  background: rgba(251, 191, 36, 0.16);
  color: #fbbf24;
}


/* ============================================================ *
 *  Settings card
 *  Houses workspace-level toggles like the service-recommender
 *  visibility flag. Lives as a regular card so it can be dragged
 *  and dismissed.
 * ============================================================ */

.card-settings-area {
  padding: var(--space-md, 16px);
  display: flex;
  flex-direction: column;
  gap: var(--space-md, 16px);
  overflow-y: auto;
}

.settings-card-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: var(--space-md, 16px);
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}
.settings-card-section:last-child { border-bottom: 0; padding-bottom: 0; }

.settings-card-section-title {
  margin: 0;
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-primary, #fff);
}
.settings-card-section-body {
  margin: 0;
  font-size: var(--font-size-xs, 0.8125rem);
  color: var(--text-secondary, rgba(255, 255, 255, 0.65));
  line-height: 1.4;
}

/* Toggle pill — checkbox visually swapped for a sliding pill */
.settings-card-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  margin-top: 4px;
}
.settings-card-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  position: relative;
  transition: background 160ms ease;
  cursor: pointer;
  margin: 0;
}
.settings-card-toggle input[type="checkbox"]:checked {
  background: var(--accent-primary, #a78bfa);
}
.settings-card-toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  pointer-events: none;
  transition: transform 160ms ease;
}
.settings-card-toggle input[type="checkbox"]:checked + .settings-card-toggle-slider {
  transform: translateX(14px);
}
.settings-card-toggle-label {
  font-size: var(--font-size-xs, 0.8125rem);
  color: var(--text-secondary, rgba(255, 255, 255, 0.65));
}

/* Toolbar icon buttons — make them render the SVG cleanly */
.header-action.header-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

