:root {
  /* Light theme defaults */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #6c757d;
  --border: #e9ecef;
  --primary: #007bff;
  --primary-hover: #0056b3;
  --success: #28a745;
  --error: #dc3545;
  --warning: #ffc107;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.15);
  --radius: 8px;
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: all 0.2s ease;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-card: #242424;
    --text-primary: #ffffff;
    --text-secondary: #adb5bd;
    --border: #404040;
    --primary: #4dabf7;
    --primary-hover: #339af0;
    --success: #51cf66;
    --error: #ff6b6b;
    --warning: #ffd43b;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.4);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 16px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-lg) var(--spacing-md);
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.brand {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary);
}

.session-indicator {
  font-weight: 500;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

/* Primary Grid */
.primary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

@media (min-width: 860px) {
  .primary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--spacing-md);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

.card h2 {
  margin: 0 0 var(--spacing-md) 0;
  font-size: 1.25rem;
  color: var(--text-primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: var(--spacing-xs);
}

/* Form Elements */
.form-group {
  margin-bottom: var(--spacing-md);
}

label {
  display: block;
  margin-bottom: var(--spacing-xs);
  font-weight: 500;
  color: var(--text-primary);
}

input[type="text"],
input[type="email"] {
  width: 100%;
  padding: var(--spacing-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition);
}

input[type="text"]:focus,
input[type="email"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

input[type="text"]:invalid:required,
input[type="email"]:invalid:required {
  border-color: var(--error);
}

.help-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: var(--spacing-xs);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  min-height: 44px;
  width: 100%;
  margin-bottom: var(--spacing-xs);
}

@media (min-width: 860px) {
  .btn {
    width: auto;
  }
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

@media (min-width: 860px) {
  .button-group {
    flex-direction: row;
  }
}

/* Result and Session Panels */
.result-content,
.session-content {
  min-height: 100px;
  padding: var(--spacing-sm);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 0.875rem;
  overflow-x: auto;
}

.placeholder {
  color: var(--text-secondary);
  font-style: italic;
  margin: 0;
}

/* Info Text */
.info-text {
  margin-top: var(--spacing-md);
  padding: var(--spacing-sm);
  background: var(--bg-secondary);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.info-text code {
  background: var(--text-secondary);
  color: var(--text-primary);
  padding: 0.125rem 0.25rem;
  border-radius: 3px;
  font-family: inherit;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  max-width: 400px;
}

.toast {
  padding: var(--spacing-md);
  margin-bottom: var(--spacing-sm);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  border-left: 4px solid;
  animation: slideIn 0.3s ease-out;
  word-wrap: break-word;
}

.toast.success {
  background: rgba(40, 167, 69, 0.1);
  color: var(--success);
  border-left-color: var(--success);
}

.toast.error {
  background: rgba(220, 53, 69, 0.1);
  color: var(--error);
  border-left-color: var(--error);
}

.toast.info {
  background: rgba(0, 123, 255, 0.1);
  color: var(--primary);
  border-left-color: var(--primary);
}

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

@media (max-width: 480px) {
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .container {
    padding: 0 var(--spacing-sm);
  }
  
  .header {
    flex-direction: column;
    gap: var(--spacing-sm);
    text-align: center;
  }
  
  .card {
    padding: var(--spacing-sm);
  }
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary);
  color: white;
  padding: 8px;
  font-size: 14px;
  text-decoration: none;
  border-radius: 0 0 4px 4px;
  z-index: 1000;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 6px;
}

/* Error messages */
.error-message {
  display: block;
  color: var(--error);
  font-size: 0.75rem;
  margin-top: 0.25rem;
  min-height: 1em;
}

.error-message:empty {
  display: none;
}

.error-message[aria-live] {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

.error-message:not(:empty) {
  position: static;
  clip: auto;
  height: auto;
  width: auto;
  overflow: visible;
  margin: 0.25rem 0 0 0;
}

/* Form validation states */
input:invalid {
  border-color: var(--error);
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.25);
}

input:focus:invalid {
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.5), 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Focus visible for accessibility */
@media (prefers-reduced-motion: no-preference) {
  *:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
  
  /* Override for buttons and inputs */
  .btn:focus-visible,
  input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border: #000;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  }
  
  .btn:focus-visible {
    outline: 3px solid var(--primary);
  }
}