/* Dangerous Pi - Base Styles (Theme-Agnostic) */
/* Optimized for Pi Zero 2 W - Minimal, Fast, Beautiful */

/* ============================================================================
   Default token values (overridden by theme files via data-brand attribute)
   ============================================================================ */
:root {
  /* Spacing (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;

  /* Bevel sizes (DT theme sets real values; Classic/Supra set 0px) */
  --bevel-sm: 0px;
  --bevel-md: 0px;
  --bevel-lg: 0px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition: 250ms ease;

  /* Font stacks — themes override --font-heading and --font-body */
  --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: var(--font-sans);
  --font-body: var(--font-sans);
}

/* ============================================================================
   Reset & Base
   ============================================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================================================================
   Typography
   ============================================================================ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: var(--space-4);
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

p {
  margin-bottom: var(--space-4);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-accent);
}

/* ============================================================================
   Layout
   ============================================================================ */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* Header */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
  background: rgba(var(--color-surface-rgb), 0.9);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1280px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  border-radius: var(--radius);
}

/* ============================================================================
   Navigation
   ============================================================================ */
.nav {
  display: flex;
  gap: var(--space-2);
}

.nav-link {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  color: var(--color-text-secondary);
  font-weight: 500;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.nav-link:hover {
  color: var(--color-primary);
  background: var(--color-surface-hover);
  border-color: var(--color-primary);
}

.nav-link.active {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.1);
}

/* Mobile Navigation */
@media (max-width: 768px) {
  .nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: var(--space-2);
    justify-content: space-around;
    z-index: 100;
  }

  .nav-link {
    flex-direction: column;
    align-items: center;
    font-size: 0.75rem;
    padding: var(--space-2);
    min-width: 60px;
  }

  body {
    padding-bottom: 60px;
  }
}

/* Main Content */
.main {
  padding: var(--space-6) var(--space-4);
  max-width: 1280px;
  margin: 0 auto;
}

/* ============================================================================
   Cards
   ============================================================================ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: border-color var(--transition-fast);
}

.card:hover {
  border-color: var(--color-primary);
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--color-text-primary);
}

.card-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* ============================================================================
   Buttons
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  min-height: 44px;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-bg);
  border-color: var(--color-primary);
  box-shadow: 0 0 20px rgba(var(--color-primary-rgb), 0.3);
}

.btn-primary:hover {
  background: var(--color-accent);
  color: var(--color-bg);
  border-color: var(--color-accent);
  box-shadow: 0 0 30px rgba(var(--color-accent-rgb), 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn-secondary:hover {
  background: rgba(var(--color-primary-rgb), 0.1);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.btn-danger {
  background: var(--color-error);
  color: var(--color-bg);
  border-color: var(--color-error);
}

.btn-danger:hover {
  color: var(--color-bg);
  filter: brightness(0.85);
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ============================================================================
   Status Badges
   ============================================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-success {
  background: rgba(var(--color-success-rgb), 0.2);
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.badge-error {
  background: rgba(var(--color-error-rgb), 0.2);
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

.badge-warning {
  background: rgba(var(--color-warning-rgb), 0.2);
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
}

.badge-info {
  background: rgba(var(--color-info-rgb), 0.2);
  color: var(--color-info);
  border: 1px solid var(--color-info);
}

.badge-pulse {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ============================================================================
   Forms
   ============================================================================ */
.form-group {
  margin-bottom: var(--space-4);
}

.label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: var(--space-2);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-primary);
  font-size: 1rem;
  font-family: var(--font-mono);
  transition: all var(--transition-fast);
  min-height: 44px;
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.1);
}

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

/* ============================================================================
   Terminal / Code Output
   ============================================================================ */
.terminal {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--color-accent);
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
}

.terminal::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.terminal::-webkit-scrollbar-track {
  background: var(--color-surface);
}

.terminal::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-sm);
}

.terminal::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}

/* ============================================================================
   Loading States
   ============================================================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface) 0%,
    var(--color-surface-hover) 50%,
    var(--color-surface) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ============================================================================
   Toast Notifications
   ============================================================================ */
.toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  z-index: 200;
  animation: toast-in 250ms ease;
}

@keyframes toast-in {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ============================================================================
   Utility Classes
   ============================================================================ */
.text-primary { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }
.text-warning { color: var(--color-warning); }

.text-center { text-align: center; }
.text-right { text-align: right; }

.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus Styles */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 768px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .card {
    padding: var(--space-4);
  }

  .main {
    padding: var(--space-4) var(--space-4);
  }
}

/* ============================================================================
   Power Widget
   ============================================================================ */
.power-widget {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  cursor: default;
  transition: all var(--transition-fast);
  position: relative;
}

.power-widget:hover {
  border-color: var(--color-primary);
}

.power-widget__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 14px;
}

.power-widget__percentage {
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-mono);
  min-width: 2.5em;
  text-align: right;
}

.power-widget__plug-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent);
  animation: plug-pulse 2s ease-in-out infinite;
}

.plug-icon {
  width: 12px;
  height: 12px;
}

@keyframes plug-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Battery Icon */
.battery-icon {
  width: 24px;
  height: 14px;
  color: currentColor;
}

.battery-icon__fill {
  transition: width var(--transition);
}

.battery-icon__bolt {
  animation: bolt-flash 1s ease-in-out infinite;
}

@keyframes bolt-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Power Widget States */
.power-widget--loading {
  opacity: 0.6;
}

.power-widget--loading .battery-icon__fill {
  animation: loading-fill 1.5s ease-in-out infinite;
}

@keyframes loading-fill {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

.power-widget--normal {
  color: var(--color-accent);
}

.power-widget--charging {
  color: var(--color-accent);
  border-color: rgba(var(--color-accent-rgb), 0.3);
}

.power-widget--full {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.power-widget--low {
  color: var(--color-warning);
  border-color: rgba(var(--color-warning-rgb), 0.3);
}

.power-widget--critical {
  color: var(--color-error);
  border-color: rgba(var(--color-error-rgb), 0.3);
  animation: critical-pulse 1s ease-in-out infinite;
}

@keyframes critical-pulse {
  0%, 100% {
    border-color: rgba(var(--color-error-rgb), 0.3);
    box-shadow: none;
  }
  50% {
    border-color: var(--color-error);
    box-shadow: 0 0 10px rgba(var(--color-error-rgb), 0.4);
  }
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .power-widget {
    padding: var(--space-1) var(--space-2);
  }

  .power-widget__percentage {
    font-size: 0.7rem;
  }
}

/* ============================================================================
   Header Widgets - Notification banners below header
   ============================================================================ */
.header-widgets {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.widget {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  font-size: 0.9rem;
  animation: widget-slide-in 0.3s ease-out;
}

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

.widget-info {
  background: rgba(var(--color-info-rgb), 0.1);
  border-left: 3px solid var(--color-info);
  color: var(--color-info);
}

.widget-warning {
  background: rgba(var(--color-warning-rgb), 0.1);
  border-left: 3px solid var(--color-warning);
  color: var(--color-warning);
}

.widget-error {
  background: rgba(var(--color-error-rgb), 0.1);
  border-left: 3px solid var(--color-error);
  color: var(--color-error);
}

.widget-success {
  background: rgba(var(--color-success-rgb), 0.1);
  border-left: 3px solid var(--color-success);
  color: var(--color-success);
}

.widget-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.widget-message {
  flex: 1;
  line-height: 1.4;
  color: var(--color-text-primary);
}

.widget-action {
  padding: var(--space-1) var(--space-3);
  background: rgba(var(--color-primary-rgb), 0.1);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background var(--transition-fast);
  white-space: nowrap;
}

.widget-action:hover {
  background: rgba(var(--color-primary-rgb), 0.2);
}

.widget-dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: var(--space-1);
  opacity: 0.6;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
  width: 24px;
  height: 24px;
}

.widget-dismiss:hover {
  opacity: 1;
}

.dismiss-icon {
  width: 12px;
  height: 12px;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .header-widgets {
    padding: var(--space-2);
  }

  .widget {
    font-size: 0.85rem;
    padding: var(--space-2);
    gap: var(--space-2);
  }

  .widget-action {
    padding: var(--space-1) var(--space-2);
    font-size: 0.8rem;
  }
}
