/* ==========================================================================
   SparkHub Components - Mobile-First Styles
   - Built on top of tokens.css
   - All components are mobile-optimized first, then enhanced for desktop
   - Use CSS variables for easy theme switching
   ========================================================================== */

/* ==========================================================================
   Container System (Responsive Padding)
   ========================================================================== */
.container-responsive {
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;        /* 16px mobile */
  padding-right: 1rem;
}

@media (min-width: 640px) {
  .container-responsive {
    padding-left: 1.5rem;  /* 24px tablet */
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container-responsive {
    padding-left: 2rem;    /* 32px desktop */
    padding-right: 2rem;
  }
}

/* ==========================================================================
   Button System (Mobile-Optimized Touch Targets)
   ========================================================================== */

/* Base Button - Minimum 44x44px touch target for mobile */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.75rem 1.25rem;
  font-weight: 500;
  font-size: 0.9375rem;      /* 15px - optimal for mobile */
  line-height: 1.5;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary Button */
.btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

/* Secondary Button */
.btn-secondary {
  background: var(--color-card);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Accent/Success Button */
.btn-accent {
  background: var(--color-accent);
  color: white;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.btn-accent:hover {
  background: #16a34a;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.35);
  transform: translateY(-1px);
}

/* Danger Button */
.btn-danger {
  background: var(--color-danger);
  color: white;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
  background: #dc2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
  transform: translateY(-1px);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--color-text);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: var(--color-card);
  border-color: var(--color-border);
}

/* Button Sizes */
.btn-sm {
  min-height: 36px;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn-lg {
  min-height: 52px;
  padding: 1rem 1.75rem;
  font-size: 1rem;
}

/* Icon-only button */
.btn-icon {
  min-width: 44px;
  padding: 0.75rem;
}

.btn-icon.btn-sm {
  min-width: 36px;
  min-height: 36px;
  padding: 0.5rem;
}

/* Full-width mobile button */
.btn-mobile-full {
  width: 100%;
}

@media (min-width: 640px) {
  .btn-mobile-full {
    width: auto;
  }
}

/* ==========================================================================
   Card System (Mobile-First)
   ========================================================================== */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;              /* 16px mobile */
  transition: all 0.2s ease;
}

@media (min-width: 640px) {
  .card {
    padding: 1.25rem;         /* 20px tablet */
  }
}

@media (min-width: 1024px) {
  .card {
    padding: 1.5rem;          /* 24px desktop */
  }
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Interactive Card (clickable) */
.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

.card-interactive:active {
  transform: translateY(0);
}

/* Card with header */
.card-header {
  margin: -1rem -1rem 1rem -1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
}

@media (min-width: 640px) {
  .card-header {
    margin: -1.25rem -1.25rem 1.25rem -1.25rem;
    padding: 1.25rem;
  }
}

@media (min-width: 1024px) {
  .card-header {
    margin: -1.5rem -1.5rem 1.5rem -1.5rem;
    padding: 1.5rem;
  }
}

.card-title {
  font-size: 1.125rem;        /* 18px */
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

@media (min-width: 1024px) {
  .card-title {
    font-size: 1.25rem;       /* 20px desktop */
  }
}

/* ==========================================================================
   Form Controls (Mobile-Optimized)
   ========================================================================== */

/* Input Groups */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}

.form-label-required::after {
  content: " *";
  color: var(--color-danger);
}

/* Text Inputs */
.form-input {
  width: 100%;
  min-height: 44px;           /* Touch-friendly */
  padding: 0.75rem 1rem;
  font-size: 1rem;            /* Prevents iOS zoom on focus */
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.form-input::placeholder {
  color: var(--color-faint);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--glow-primary);
}

.form-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.02);
}

/* Input with icon */
.input-icon-wrapper {
  position: relative;
}

.input-icon-wrapper .form-input {
  padding-left: 2.75rem;
}

.input-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted);
  pointer-events: none;
}

/* Select Dropdown */
.form-select {
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.7)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>') no-repeat right 0.75rem center;
  background-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  appearance: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--glow-primary);
}

/* Textarea */
.form-textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: all 0.2s ease;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--glow-primary);
}

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
  min-height: 44px;           /* Touch-friendly */
  padding: 0.5rem 0;
}

.form-check-input {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 0.25rem;
  cursor: pointer;
  appearance: none;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: 4px;
  transition: all 0.2s ease;
}

.form-check-input:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>');
  background-position: center;
  background-repeat: no-repeat;
  background-size: 14px;
}

.form-check-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--glow-primary);
}

.form-check-input[type="radio"] {
  border-radius: 50%;
}

.form-check-input[type="radio"]:checked {
  background-image: none;
  box-shadow: inset 0 0 0 4px var(--color-surface);
}

.form-check-label {
  flex: 1;
  font-size: 0.9375rem;
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
}

/* Form Help Text */
.form-help {
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  color: var(--color-muted);
}

/* Form Error State */
.form-input.error,
.form-select.error,
.form-textarea.error {
  border-color: var(--color-danger);
}

.form-input.error:focus,
.form-select.error:focus,
.form-textarea.error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.form-error {
  margin-top: 0.375rem;
  font-size: 0.8125rem;
  color: var(--color-danger);
}

/* ==========================================================================
   Alert/Toast Messages (Mobile-Optimized)
   ========================================================================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9375rem;
  line-height: 1.5;
}

@media (min-width: 640px) {
  .alert {
    padding: 1rem 1.25rem;
  }
}

.alert-icon {
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.alert-message {
  color: inherit;
  opacity: 0.9;
}

/* Alert Variants */
.alert-success {
  background: rgba(34, 197, 94, 0.12);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.alert-info {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.alert-warning {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.alert-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Dismissible Alert */
.alert-dismissible {
  padding-right: 3rem;
  position: relative;
}

.alert-close {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  padding: 0.25rem;
  background: transparent;
  border: none;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.alert-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Badge System
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  border-radius: 6px;
  white-space: nowrap;
}

.badge-primary {
  background: rgba(37, 99, 235, 0.15);
  color: #60a5fa;
}

.badge-success {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.badge-info {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

.badge-neutral {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-muted);
}

/* Badge with dot indicator */
.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ==========================================================================
   Table (Mobile-Optimized with Card View)
   ========================================================================== */

/* Desktop Table View */
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table thead {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.table th {
  padding: 0.875rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

.table td {
  padding: 1rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text);
}

.table tbody tr {
  transition: background 0.2s ease;
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Mobile Card View */
@media (max-width: 767px) {
  .table-responsive-cards {
    display: none;
  }
  
  .table-mobile-cards {
    display: grid;
    gap: 1rem;
  }
  
  .table-mobile-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
  }
  
  .table-mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--color-divider);
  }
  
  .table-mobile-card-row:last-child {
    border-bottom: none;
  }
  
  .table-mobile-card-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-muted);
    margin-bottom: 0.25rem;
  }
  
  .table-mobile-card-value {
    font-size: 0.9375rem;
    color: var(--color-text);
    text-align: right;
  }
}

@media (min-width: 768px) {
  .table-mobile-cards {
    display: none;
  }
  
  .table-responsive-cards {
    display: table;
  }
}

/* ==========================================================================
   Modal/Dialog (Mobile-Optimized)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
}

.modal {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 500px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay.show .modal {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.modal-close {
  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* Mobile: Stack footer buttons */
@media (max-width: 640px) {
  .modal-footer {
    flex-direction: column-reverse;
  }
  
  .modal-footer .btn {
    width: 100%;
  }
}

/* ==========================================================================
   Dropdown Menu (Mobile-Optimized)
   ========================================================================== */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 200px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 0.5rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 40;
}

.dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  color: var(--color-text);
  text-align: left;
  text-decoration: none;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 40px;           /* Touch-friendly */
}

.dropdown-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.dropdown-item:active {
  background: rgba(255, 255, 255, 0.08);
}

.dropdown-divider {
  height: 1px;
  background: var(--color-divider);
  margin: 0.5rem 0;
}

/* Mobile: Full-width dropdown */
@media (max-width: 640px) {
  .dropdown-menu.dropdown-mobile-full {
    left: 0;
    right: 0;
    min-width: 100%;
  }
}

/* ==========================================================================
   Skeleton Loaders
   ========================================================================== */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
}

.skeleton-title {
  height: 1.5em;
  width: 60%;
  margin-bottom: 0.75em;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

/* Text Colors */
.text-primary { color: var(--color-primary); }
.text-accent { color: var(--color-accent); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-info { color: var(--color-info); }
.text-text { color: var(--color-text); }
.text-muted { color: var(--color-muted); }
.text-faint { color: var(--color-faint); }

/* Background Colors */
.bg-primary { background: var(--color-primary); }
.bg-accent { background: var(--color-accent); }
.bg-surface { background: var(--color-surface); }
.bg-card { background: var(--color-card); }

/* Border */
.border-color { border-color: var(--color-border); }

/* Divider */
.divider {
  height: 1px;
  background: var(--color-divider);
  margin: 1.5rem 0;
}

/* Safe Area Insets (for iOS notch) */
@supports (padding: max(0px)) {
  .safe-top {
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  
  .safe-bottom {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}