/* ============================================================
   WAAPI - Reusable Components Stylesheet
   ============================================================ */

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
  user-select: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--grad-primary);
  color: white;
  box-shadow: var(--shadow-brand);
}

.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 6px 25px rgba(255,153,51,0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-success {
  background: var(--grad-success);
  color: white;
  box-shadow: var(--shadow-green);
}

.btn-success:hover { filter: brightness(1.1); transform: translateY(-1px); }

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

.btn-outline:hover { background: var(--bg-hover); border-color: var(--saffron); color: var(--saffron); }

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

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

.btn-danger {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.3);
  color: #EF4444;
}

.btn-danger:hover { background: #EF4444; color: white; }

.btn-sm { padding: 6px 12px; font-size: 0.8125rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-xl { padding: 14px 28px; font-size: 1.0625rem; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-icon.btn-sm { width: 30px; height: 30px; padding: 5px; }

.btn-loading { pointer-events: none; }
.btn-loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-5); }
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-label.required::after { content: ' *'; color: #EF4444; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--saffron);
  box-shadow: 0 0 0 3px rgba(255,153,51,0.1);
}

.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); }
.form-select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238B9AB0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.form-input.error, .form-select.error, .form-textarea.error { border-color: #EF4444; }
.form-error { font-size: 0.75rem; color: #EF4444; margin-top: var(--space-1); }
.form-help { font-size: 0.75rem; color: var(--text-muted); margin-top: var(--space-1); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 600px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }

.input-group { position: relative; }
.input-group .form-input { padding-left: 40px; }
.input-group .input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.input-group .input-suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

/* Toggle / Switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-muted);
  top: 2px;
  left: 2px;
  transition: var(--transition);
}

input:checked + .toggle-slider { background: var(--green); border-color: var(--green); }
input:checked + .toggle-slider::before { transform: translateX(20px); background: white; }

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--saffron);
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

.card-title {
  font-size: 1rem;
  font-weight: 700;
}

.card-body { padding: var(--space-5); }
.card-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }

/* Glassmorphism card */
.card-glass {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.1);
}

/* Stat cards */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

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

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}

.stat-card.orange::after { background: var(--grad-primary); }
.stat-card.green::after { background: var(--grad-success); }
.stat-card.blue::after { background: linear-gradient(90deg, var(--navy), #0000CC); }
.stat-card.purple::after { background: linear-gradient(90deg, #7C3AED, #A855F7); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
}

.stat-icon.orange { background: rgba(255,153,51,0.12); color: var(--saffron); }
.stat-icon.green { background: rgba(19,136,8,0.12); color: var(--green); }
.stat-icon.blue { background: rgba(0,0,128,0.15); color: #4040CC; }
.stat-icon.purple { background: rgba(124,58,237,0.12); color: #7C3AED; }
.stat-icon svg { width: 22px; height: 22px; }

.stat-value { font-size: 1.75rem; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 0.8125rem; color: var(--text-secondary); }
.stat-change { font-size: 0.75rem; margin-top: var(--space-2); display: flex; align-items: center; gap: 4px; }
.stat-change.up { color: var(--green); }
.stat-change.down { color: #EF4444; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.table tr:hover td { background: var(--bg-hover); }
.table tr:last-child td { border-bottom: none; }

/* ── Badges / Tags ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-primary { background: rgba(255,153,51,0.15); color: var(--saffron); }
.badge-success { background: rgba(19,136,8,0.15); color: var(--green); }
.badge-danger { background: rgba(239,68,68,0.15); color: #EF4444; }
.badge-warning { background: rgba(245,158,11,0.15); color: #F59E0B; }
.badge-info { background: rgba(59,130,246,0.15); color: #3B82F6; }
.badge-neutral { background: var(--bg-tertiary); color: var(--text-secondary); }
.badge-navy { background: rgba(0,0,128,0.15); color: #4040CC; }

/* Status dot */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.connected, .status-dot.active, .status-dot.completed { background: var(--green); }
.status-dot.disconnected, .status-dot.inactive, .status-dot.failed { background: #EF4444; }
.status-dot.connecting, .status-dot.qr_pending { background: var(--saffron); animation: pulse 1.5s infinite; }
.status-dot.pending { background: #F59E0B; }

/* ── Avatar ─────────────────────────────────────────────────── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--grad-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  color: white;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 28px; height: 28px; font-size: 0.75rem; }
.avatar-lg { width: 48px; height: 48px; font-size: 1rem; }
.avatar-xl { width: 64px; height: 64px; font-size: 1.25rem; }

/* ── Search bar ──────────────────────────────────────────────── */
.search-box {
  position: relative;
  max-width: 320px;
}

.search-box input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 9px 14px 9px 38px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  width: 100%;
  outline: none;
  transition: var(--transition);
}

.search-box input:focus { border-color: var(--saffron); box-shadow: 0 0 0 3px rgba(255,153,51,0.1); }
.search-box input::placeholder { color: var(--text-muted); }

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
}

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  gap: 0;
  overflow-x: auto;
}

.tab-item {
  padding: var(--space-3) var(--space-5);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: var(--transition);
}

.tab-item:hover { color: var(--text-primary); }
.tab-item.active { color: var(--saffron); border-bottom-color: var(--saffron); }

.tab-content > div { display: none; }
.tab-content > div.active { display: block; }

/* ── Progress bars ───────────────────────────────────────────── */
.progress { height: 6px; background: var(--bg-tertiary); border-radius: var(--radius-full); overflow: hidden; }
.progress-bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--grad-primary);
  transition: width 0.5s ease;
}

.progress-bar.green { background: var(--grad-success); }
.progress-bar.navy { background: var(--grad-navy); }

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  justify-content: center;
}

.page-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  background: none;
  color: var(--text-secondary);
}

.page-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-btn.active { background: var(--saffron); color: white; border-color: var(--saffron); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-5);
  opacity: 0.4;
}

.empty-state-title { font-size: 1.125rem; font-weight: 600; color: var(--text-secondary); margin-bottom: var(--space-2); }
.empty-state-desc { font-size: 0.875rem; margin-bottom: var(--space-5); max-width: 400px; }

/* ── QR Code display ─────────────────────────────────────────── */
.qr-display {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  border: 3px solid var(--saffron);
}

.qr-display img { width: 220px; height: 220px; }
.qr-status { font-size: 0.875rem; color: var(--text-secondary); }

/* ── Alert ───────────────────────────────────────────────────── */
.alert {
  padding: var(--space-4);
  border-radius: var(--radius);
  display: flex;
  gap: var(--space-3);
  font-size: 0.875rem;
  margin-bottom: var(--space-4);
}

.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-info { background: rgba(59,130,246,0.08); border: 1px solid rgba(59,130,246,0.2); color: #3B82F6; }
.alert-success { background: rgba(19,136,8,0.08); border: 1px solid rgba(19,136,8,0.2); color: var(--green); }
.alert-warning { background: rgba(255,153,51,0.08); border: 1px solid rgba(255,153,51,0.2); color: var(--saffron); }
.alert-error { background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.2); color: #EF4444; }

/* ── Skeleton loading ────────────────────────────────────────── */
.skeleton {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 60%; }
.skeleton-avatar { width: 40px; height: 40px; border-radius: 50%; }

/* ── Chip / Tag ──────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 3px 10px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.chip .chip-remove {
  width: 14px;
  height: 14px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: none;
  border: none;
}

.chip .chip-remove:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Divider ─────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-4) 0;
}

.divider-label {
  text-align: center;
  position: relative;
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin: var(--space-4) 0;
}

.divider-label::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 1px;
  background: var(--border);
}

.divider-label span { background: var(--bg-card); padding: 0 var(--space-3); position: relative; }
