/* ===================================
   Iuventus WMS v5.0 - Components
   =================================== */

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 0.625rem 1.25rem;
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

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

.btn-success {
  background: var(--color-success-600);
  color: white;
}
.btn-success:hover { background: var(--color-success-700); }

.btn-danger {
  background: var(--color-danger-600);
  color: white;
}
.btn-danger:hover { background: var(--color-danger-700); }

.btn-warning {
  background: var(--color-warning-500);
  color: white;
}
.btn-warning:hover { background: var(--color-warning-600); }

.btn-info {
  background: var(--color-info-500);
  color: white;
}
.btn-info:hover { background: var(--color-info-600); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-color-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-outline-primary {
  background: transparent;
  color: var(--color-primary-600);
  border-color: var(--color-primary-600);
}
.btn-outline-primary:hover {
  background: var(--color-primary-600);
  color: white;
}

.btn-outline-danger {
  background: transparent;
  color: var(--color-danger-600);
  border-color: var(--color-danger-600);
}
.btn-outline-danger:hover {
  background: var(--color-danger-600);
  color: white;
}

/* Button Sizes */
.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: var(--font-size-xs);
}

.btn-lg {
  padding: 0.875rem 1.75rem;
  font-size: var(--font-size-base);
}

.btn-xl {
  padding: 1rem 2rem;
  font-size: var(--font-size-lg);
  height: 52px;
}

.btn-block {
  width: 100%;
}

/* Button with loading */
.btn-loading {
  position: relative;
  pointer-events: none;
}

.btn-loading .btn-text {
  visibility: hidden;
}

.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

/* ===== FORM CONTROLS ===== */
.form-group {
  margin-bottom: var(--space-2);
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label-optional {
  font-weight: var(--font-weight-normal);
  color: var(--text-muted);
  font-size: var(--font-size-xs);
}

.form-input,
.form-select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--color-primary-500);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.form-input:disabled,
.form-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

.form-input-error {
  border-color: var(--color-danger-500);
}

.form-input-error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.form-error-text {
  font-size: var(--font-size-xs);
  color: var(--color-danger-500);
  margin-top: 4px;
}

.form-hint {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

.form-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 180px;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition-fast);
}

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

.card-header {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin: 0;
}

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

.card-footer {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
}

/* ===== STAT CARDS ===== */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  text-align: center;
  transition: all var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xl);
  margin: 0 auto var(--space-2);
}

.stat-icon-primary {
  background: rgba(14, 165, 233, 0.1);
  color: var(--color-primary-600);
}

.stat-icon-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-success-600);
}

.stat-icon-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-warning-600);
}

.stat-icon-danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger-600);
}

.stat-value {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-extrabold);
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-1);
}

.stat-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-subtitle {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  margin-top: var(--space-1);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.stat-trend-up {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-success-600);
}

.stat-trend-down {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger-600);
}

/* ===== TABLES ===== */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-toolbar {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.table-search {
  max-width: 300px;
}

.table-wrapper {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.table th {
  background: var(--bg-input);
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.table th:hover {
  color: var(--text-primary);
}

.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.table tbody tr {
  transition: background var(--transition-fast);
}

.table tbody tr:hover {
  background: var(--bg-input);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table-empty {
  text-align: center;
  padding: var(--space-4);
  color: var(--text-muted);
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-primary {
  background: rgba(14, 165, 233, 0.1);
  color: var(--color-primary-700);
}

[data-theme="dark"] .badge-primary {
  color: var(--color-primary-400);
}

.badge-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-success-700);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-warning-700);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger-700);
}

.badge-info {
  background: rgba(6, 182, 212, 0.1);
  color: var(--color-info-600);
}

.badge-neutral {
  background: var(--bg-hover);
  color: var(--text-muted);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  animation: fadeIn var(--transition-base);
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-xl);
  animation: scaleIn var(--transition-base);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--font-size-lg);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-3);
}

.modal-footer {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-1);
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
  position: fixed;
  top: var(--space-3);
  right: var(--space-3);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  min-width: 300px;
  max-width: 420px;
  pointer-events: auto;
  animation: slideInRight var(--transition-slow) ease-out;
}

.toast-success {
  background: var(--color-success-600);
  color: white;
}

.toast-error {
  background: var(--color-danger-600);
  color: white;
}

.toast-warning {
  background: var(--color-warning-500);
  color: white;
}

.toast-info {
  background: var(--color-primary-600);
  color: white;
}

.toast-icon {
  font-size: var(--font-size-lg);
  flex-shrink: 0;
}

.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 4px;
  font-size: var(--font-size-base);
}

.toast-close:hover {
  color: white;
}

/* ===== PROGRESS BAR ===== */
.progress {
  width: 100%;
  height: 8px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-lg {
  height: 24px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-success-500), #34d399);
  border-radius: var(--radius-full);
  transition: width var(--transition-slower);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
}

/* ===== SYNC INDICATOR ===== */
.sync-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
}

.sync-online {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-success-600);
}

.sync-offline {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger-600);
}

.sync-pending {
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-warning-600);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: currentColor;
}

/* ===== PRODUCT INFO BOX ===== */
.product-info-box {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
}

.product-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-sm);
}

.product-info-row + .product-info-row {
  margin-top: var(--space-1);
}

.product-info-label {
  color: var(--text-muted);
  font-weight: var(--font-weight-medium);
}

.product-info-value {
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
}

/* ===== SCAN STATUS ===== */
.scan-status {
  text-align: center;
  font-weight: var(--font-weight-semibold);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  margin: var(--space-2) 0;
  transition: all var(--transition-fast);
}

/* Camera reader container */
#reader {
  width: 100% !important;
  border: none !important;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
}

#reader video {
  width: 100% !important;
  height: auto !important;
  border-radius: var(--radius-md);
  object-fit: cover;
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
  #reader video {
    width: 100% !important;
    max-height: 400px;
  }
}

.scan-status-success {
  color: var(--color-success-700);
  background: var(--color-success-50);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.scan-status-error {
  color: var(--color-danger-700);
  background: var(--color-danger-50);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.scan-status-info {
  color: var(--color-primary-700);
  background: var(--color-primary-50);
  border: 1px solid rgba(14, 165, 233, 0.2);
}

.scan-status-warning {
  color: var(--color-warning-700);
  background: var(--color-warning-50);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .scan-status-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-success-500);
  border-color: var(--color-success-500);
}

[data-theme="dark"] .scan-status-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger-500);
  border-color: var(--color-danger-500);
}

[data-theme="dark"] .scan-status-info {
  background: rgba(14, 165, 233, 0.1);
  color: var(--color-primary-500);
  border-color: var(--color-primary-500);
}

[data-theme="dark"] .scan-status-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--color-warning-500);
  border-color: var(--color-warning-500);
}

/* ===== LOADING SKELETON ===== */
.skeleton {
  background: linear-gradient(90deg,
    var(--bg-hover) 25%,
    var(--bg-input) 50%,
    var(--bg-hover) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

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

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
}

.skeleton-circle {
  border-radius: var(--radius-full);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: var(--space-6) var(--space-3);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-2);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.empty-state-text {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  max-width: 400px;
  margin: 0 auto;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--space-3);
  overflow-x: auto;
}

.tab {
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.tab.active {
  color: var(--color-primary-600);
  border-bottom-color: var(--color-primary-600);
  font-weight: var(--font-weight-semibold);
}

/* ===== MODULE CONTENT (Tab panels) ===== */
.module-content {
  display: none;
  animation: fadeIn var(--transition-slow);
}

.module-content.active {
  display: block;
}
