/**
 * BEM-compliant Button Styles - Following CSS_DOMAIN_CONTRACT.json
 * 
 * This file provides standard button styles following the BEM methodology
 * and uses CSS variables from theme.css
 */

/* 
 * Base button component
 * Block: .btn
 */
.btn {
  /* Box model */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  gap: var(--space-1);

  /* Typography */
  font-family: var(--font-primary);
  font-size: var(--btn-font-size);
  font-weight: var(--btn-font-weight);
  letter-spacing: var(--btn-letter-spacing);
  text-transform: none;

  /* Appearance */
  background: var(--btn-bg);
  border: var(--btn-border);
  border-radius: var(--radius-sm);
  color: var(--btn-text);
  cursor: pointer;

  /* Animation */
  transition: var(--btn-transition);
}

/* Button states */
.btn:hover:not(:disabled) {
  background: var(--btn-hover-bg);
  border-color: var(--btn-hover-border);
  box-shadow: var(--btn-hover-shadow);
}

.btn:active:not(:disabled) {
  background: var(--btn-active-bg);
  border-color: var(--btn-active-border);
  transform: translateY(1px);
}

/* FIXED: Button contrast states for user visibility */

/* Disabled state - LOW contrast for inactive buttons */
.btn:disabled {
  opacity: 0.5;
  color: var(--text-secondary, rgba(255, 255, 255, 0.5));
  cursor: not-allowed;
  box-shadow: none;
  font-weight: normal;
  pointer-events: none;
}

/* Focus-visible states for keyboard navigation (WCAG AAA) */
.btn:focus-visible {
  outline: 2px solid var(--accent-primary, rgb(0, 200, 100));
  outline-offset: 2px;
}

.btn--primary:focus-visible {
  outline-color: var(--accent-primary, rgb(0, 200, 100));
}

.btn--ghost:focus-visible {
  outline-color: var(--cyan, rgb(0, 200, 255));
}

.btn--danger:focus-visible {
  outline-color: var(--status-error, #ff4444);
}

.btn--warning:focus-visible {
  outline-color: var(--status-warning, #ff9500);
}

/* Enabled state - HIGH contrast for ready buttons */
.btn:enabled:not(.btn--inactive) {
  color: var(--text-primary, #fff) !important;
  opacity: 1 !important;
  font-weight: 500;
}

/* Special ready state - MAXIMUM contrast for action-ready buttons */
.btn--ready {
  color: var(--text-primary, #fff) !important;
  font-weight: 600 !important;
  opacity: 1 !important;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
  animation: pulse-ready 2s ease-in-out infinite;
}

.btn--ready:not(:disabled) {
  box-shadow: 0 0 12px rgba(var(--accent-primary-rgb), 0.4);
}

/* Button modifiers - using BEM convention */

/* Primary variant */
.btn--primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--text-inverse);
  font-weight: 600;
}

.btn--primary:disabled {
  background: var(--surface-muted);
  border-color: var(--border-muted);
  color: var(--text-tertiary, rgba(255, 255, 255, 0.3));
  opacity: 0.6;
}

/* Secondary variant (default already covered) */

/* Ghost variant */
.btn--ghost {
  background: rgba(var(--accent-primary-rgb), 0.05);
  border-color: rgba(var(--accent-primary-rgb), 0.3);
  color: rgba(var(--accent-primary-rgb), 0.9);
}

.btn--ghost:disabled {
  color: rgba(var(--accent-primary-rgb), 0.4);
  border-color: rgba(var(--accent-primary-rgb), 0.2);
  opacity: 0.6;
}

.btn--ghost:hover:not(:disabled) {
  background: rgba(var(--accent-primary-rgb), 0.15);
  border-color: rgba(var(--accent-primary-rgb), 0.5);
  box-shadow: 0 0 6px rgba(var(--accent-primary-rgb), 0.3);
}

/* DOPE button - cyan accent when active */
.btn--dope.btn--active {
  background: rgba(0, 200, 255, 0.1);
  border-color: rgba(0, 200, 255, 0.6);
  color: rgb(0, 200, 255);
}

.btn--dope.btn--active:hover {
  background: rgba(0, 200, 255, 0.2);
  border-color: rgba(0, 200, 255, 0.8);
  box-shadow: 0 0 8px rgba(0, 200, 255, 0.4);
}

/* Danger variant */
.btn--danger {
  background: transparent;
  border-color: var(--status-error);
  color: var(--status-error);
}

.btn--danger:hover:not(:disabled) {
  background: rgba(var(--status-error-rgb), 0.1);
  border-color: var(--status-error);
}

/* Warning variant */
.btn--warning {
  background: transparent;
  border-color: var(--status-warning);
  color: var(--status-warning);
}

.btn--warning:hover:not(:disabled) {
  background: rgba(var(--status-warning-rgb), 0.1);
}

/* Size modifiers */
.btn--sm {
  padding: var(--space-1) var(--space-2);
  font-size: calc(var(--btn-font-size) * 0.85);
}

.btn--lg {
  padding: var(--space-3) var(--space-5);
  font-size: calc(var(--btn-font-size) * 1.2);
}

/* Icon-only button */
.btn--icon {
  padding: var(--space-1);
  min-width: 28px;
  min-height: 28px;
  justify-content: center;
}

/* Toggle button */
.btn--toggle {
  background: var(--btn-bg);
  color: var(--text-secondary);
  border-color: var(--border-muted);
  font-size: calc(var(--btn-font-size) * 0.9);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn--toggle.btn--active {
  background: var(--btn-active-bg);
  color: var(--text-primary);
  border-color: var(--btn-active-border);
}

/* Animation for ready state */
@keyframes pulse-ready {
  0%,
  100% {
    box-shadow: 0 0 8px rgba(var(--accent-primary-rgb), 0.3);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 20px rgba(var(--accent-primary-rgb), 0.5);
    transform: scale(1.02);
  }
}

/* Full width variant */
.btn--full {
  width: 100%;
}

/* Button groups */
.btn-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.btn-group--vertical {
  flex-direction: column;
}

/* Add data-uid attribute to all buttons for tracking */
[data-uid] {
  position: relative;
}

/* KNOMAD Title - Secret clickable brand text */
.btn--title {
  font-family: 'Arial Black', 'Arial Bold', Impact, sans-serif;
  letter-spacing: 0.175em;
  transform: scaleX(2) scaleY(0.75);
  transform-origin: left center;
  display: inline-block;
  font-weight: 900;
  margin-right: 80px; /* Account for 2x scale visual width */
  transition: opacity 0.15s ease;
  background: transparent !important;
  border: none !important;
  color: inherit;
  cursor: default; /* Hide button cursor */
  padding: 0;
  font-size: inherit;
  box-shadow: none !important;
  -webkit-user-select: none;
  user-select: none;
}

/* Very subtle hover - barely noticeable */
.btn--title:hover {
  opacity: 0.95;
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  transform: scaleX(2) scaleY(0.75); /* Prevent any transform changes */
}

.btn--title:active {
  transform: scaleX(2) scaleY(0.75) !important; /* No button press effect */
}

.btn--title:focus {
  outline: none;
  box-shadow: none !important;
}

/* BLACK TEAM LLC - Secret dev mode toggle */
.btn--stealth {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent !important;
  border: none !important;
  color: rgba(255, 255, 255, 0.4); /* Very subtle text */
  padding: 0;
  font-size: 0.65em;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.5;
  transition: all 0.3s ease;
  z-index: 15; /* Above status-banner */
  white-space: nowrap;
  cursor: default; /* Hide button cursor */
  box-shadow: none !important;
  -webkit-user-select: none;
  user-select: none;
}

/* Responsive adjustment for smaller screens */
@media (max-width: 768px) {
  .btn--stealth {
    position: static;
    transform: none;
    margin-left: auto;
    opacity: 0.5;
  }

  .btn--title {
    transform: scaleX(1.5) scaleY(0.75);
    margin-right: 40px;
  }
}

/* Very subtle hover - barely noticeable */
.btn--stealth:hover {
  opacity: 0.6;
  color: rgba(255, 255, 255, 0.45);
  background: transparent !important;
  box-shadow: none !important;
}

/* Active state - Glowing when dev mode is on */
.btn--stealth.active,
#devModeToggle.active {
  color: rgba(0, 200, 255, 0.8) !important;
  opacity: 0.9 !important;
  text-shadow:
    0 0 8px rgba(0, 200, 255, 0.5),
    0 0 16px rgba(0, 200, 255, 0.3),
    0 0 24px rgba(0, 200, 255, 0.2);
  animation: subtle-glow 3s ease-in-out infinite;
}

/* Subtle glow animation */
@keyframes subtle-glow {
  0%,
  100% {
    opacity: 0.9;
    text-shadow:
      0 0 8px rgba(0, 200, 255, 0.5),
      0 0 16px rgba(0, 200, 255, 0.3),
      0 0 24px rgba(0, 200, 255, 0.2);
  }
  50% {
    opacity: 1;
    text-shadow:
      0 0 12px rgba(0, 200, 255, 0.6),
      0 0 20px rgba(0, 200, 255, 0.4),
      0 0 32px rgba(0, 200, 255, 0.3);
  }
}

.btn--stealth:active {
  transform: translateY(-50%) !important; /* No button press effect */
}

/* ===========================================
   FEATURE FLAGS - Hide/disable based on mode
   =========================================== */

/* Hidden features */
.feature-hidden {
  display: none !important;
}

/* Production mode - hide beta and dev features */
.mode-production [data-stage='beta'],
.mode-production [data-stage='dev'] {
  display: none !important;
}

/* Beta mode - hide dev features only */
.mode-beta [data-stage='dev'] {
  display: none !important;
}

/* Developer mode - show everything */
.mode-developer [data-stage] {
  display: inherit;
}

/* Disabled feature styling (alternative to hiding) */
[data-stage].feature-disabled {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(0.5);
}

/* Badge for beta features (visible in beta/dev mode) */
[data-stage='beta']::after {
  content: 'β';
  font-size: 0.6em;
  vertical-align: super;
  color: var(--status-warning, #ff9500);
  margin-left: 2px;
}

/* Badge for dev features (visible in dev mode) */
[data-stage='dev']::after {
  content: '⚙';
  font-size: 0.6em;
  vertical-align: super;
  color: var(--accent-primary, #00c8ff);
  margin-left: 2px;
}

/* Legacy class fallbacks */
button.ghost {
  background: rgba(var(--accent-primary-rgb), 0.05);
  border: 1px solid rgba(var(--accent-primary-rgb), 0.3);
  color: rgba(var(--accent-primary-rgb), 0.9);
}

button.ghost:hover:not(:disabled) {
  background: rgba(var(--accent-primary-rgb), 0.15);
  border-color: rgba(var(--accent-primary-rgb), 0.5);
  box-shadow: 0 0 6px rgba(var(--accent-primary-rgb), 0.3);
}

.icon-button {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-panel);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.icon-button:hover {
  background: var(--surface-muted-strong);
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

.icon-button.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--text-inverse);
}

.toggle-button {
  font-family: var(--font-primary);
  background: var(--surface-panel);
  color: var(--text-secondary, rgba(255, 255, 255, 0.6));
  border: 1px solid var(--border-muted);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.9em;
}

.toggle-button:enabled {
  color: var(--text-primary, #fff);
  opacity: 1;
}

.toggle-button:disabled {
  color: var(--text-tertiary, rgba(255, 255, 255, 0.3));
  opacity: 0.5;
}

.toggle-button.active {
  background: var(--accent-primary);
  color: var(--text-inverse, #fff) !important;
  border-color: var(--accent-primary);
  font-weight: 600;
  opacity: 1 !important;
}

.toggle-button:hover:not(:disabled) {
  background: var(--surface-muted-strong);
  border-color: var(--border-default);
  color: var(--text-primary, #fff);
}

/* Rotation Controls */
.rotation-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0.5rem;
  background: var(--surface-panel);
  border-top: 1px solid var(--border-subtle);
}

/* Special Controls */

/* MV and BC controls - these are critical elements with custom styling */
#mvDecrease,
#mvIncrease,
#bcDecrease,
#bcIncrease,
#resetBallisticsButton {
  padding: 2px 6px;
  min-width: auto;
}

#mvValue,
#bcValue {
  width: 70px;
  text-align: center;
  background: var(--surface-input-bg, rgba(0, 0, 0, 0.5));
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.2));
  color: var(--text-primary, #fff);
  padding: 4px;
  border-radius: var(--radius-sm, 3px);
  font-weight: bold;
}

.controls-label {
  color: var(--text-special, #ff6b35);
  font-weight: bold;
  font-size: 0.85em;
}

.controls-unit {
  color: var(--text-muted, #888);
  font-size: 0.75em;
}
