/* ============================================================
   PulseIQ — Shared Component Library
   css/components.css

   Reusable UI components used across all module pages.
   Depends on design-tokens.css being loaded first.
============================================================ */

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
  min-height: 44px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--action-primary);
  color: var(--action-primary-text);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--action-primary-hover);
  box-shadow: 0 6px 24px var(--accent-glow);
  transform: translateY(-1px);
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--surface3);
  border-color: var(--border2);
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red-text);
  border: 1px solid var(--red-border);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-success {
  background: var(--green-soft);
  color: var(--green-text);
  border: 1px solid var(--green-border);
}
.btn-success:hover {
  background: rgba(34, 197, 94, 0.18);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 11px 22px;
  font-size: 14px;
}

.btn-icon {
  padding: 7px;
  border-radius: var(--radius-sm);
}

/* ── Badges / Pills ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.badge-green  { background: var(--green-soft);  color: var(--green-text);  border: 1px solid var(--green-border); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow-text); border: 1px solid var(--yellow-border); }
.badge-red    { background: var(--red-soft);    color: var(--red-text);    border: 1px solid var(--red-border); }
.badge-blue   { background: rgba(59,130,246,.10); color: #93c5fd; border: 1px solid rgba(59,130,246,.25); }
.badge-purple { background: rgba(139,92,246,.10); color: #c4b5fd; border: 1px solid rgba(139,92,246,.25); }
.badge-gray   { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }

/* Legacy class aliases used across older pages */
.pill-green  { background: var(--green-soft);  color: var(--green-text);  border: 1px solid var(--green-border); border-radius: 100px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.pill-yellow { background: var(--yellow-soft); color: var(--yellow-text); border: 1px solid var(--yellow-border); border-radius: 100px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.pill-red    { background: var(--red-soft);    color: var(--red-text);    border: 1px solid var(--red-border); border-radius: 100px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.pill-blue   { background: rgba(59,130,246,.10); color: #93c5fd; border: 1px solid rgba(59,130,246,.25); border-radius: 100px; padding: 2px 8px; font-size: 11px; font-weight: 600; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-sm  { padding: 14px; border-radius: var(--radius); }
.card-lg  { padding: 28px; border-radius: var(--radius-xl); }

.card-hover {
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.card-hover:hover {
  border-color: var(--border2);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

/* Stat card */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
}
.stat-card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.stat-card-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}
.stat-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.18s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
}
.modal-close {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--transition);
  line-height: 1;
}
.modal-close:hover {
  background: var(--surface2);
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}
.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-dim);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238892a4' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.form-error {
  font-size: 11px;
  color: var(--red);
  margin-top: 4px;
}

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.table-title {
  font-size: 14px;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid rgba(46, 51, 80, 0.4);
  transition: background var(--transition);
}
:root[data-theme="light"] tbody tr {
  border-bottom-color: rgba(221, 225, 237, 0.6);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

tbody td {
  padding: 12px 16px;
  vertical-align: middle;
  color: var(--text);
}

/* ── Empty / Loading States ───────────────────────────────── */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.6;
}
.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.empty-state-sub {
  font-size: 13px;
  line-height: 1.6;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── Toast Notifications ──────────────────────────────────── */
#piq-toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.piq-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 360px;
  pointer-events: auto;
  animation: toast-in 0.22s ease;
  transition: opacity 0.2s, transform 0.2s;
}

.piq-toast.toast-out {
  opacity: 0;
  transform: translateX(12px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: none; }
}

.piq-toast-icon { font-size: 16px; flex-shrink: 0; }
.piq-toast-msg  { flex: 1; line-height: 1.4; }

.piq-toast.toast-success { border-left: 3px solid var(--green); }
.piq-toast.toast-error   { border-left: 3px solid var(--red); }
.piq-toast.toast-warning { border-left: 3px solid var(--yellow); }
.piq-toast.toast-info    { border-left: 3px solid var(--accent); }

/* ── Search Bar ───────────────────────────────────────────── */
.search-bar {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-bar-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  color: var(--text-dim);
  pointer-events: none;
}
.search-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px 7px 30px;
  font-size: 13px;
  color: var(--text);
  width: 220px;
  transition: border-color var(--transition), width 0.2s;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  width: 280px;
}
.search-input::placeholder { color: var(--text-dim); }

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover  { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ── Divider ──────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── Section header row ───────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.section-title {
  font-size: 15px;
  font-weight: 700;
}
.section-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Progress bar ─────────────────────────────────────────── */
.progress-track {
  height: 6px;
  background: var(--surface3);
  border-radius: 100px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 100px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.4s ease;
}
.progress-fill.green  { background: var(--green); }
.progress-fill.yellow { background: var(--yellow); }
.progress-fill.red    { background: var(--red); }

/* ── Avatar ───────────────────────────────────────────────── */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar-sm { width: 26px; height: 26px; font-size: 10px; }
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }

/* ── Tooltip ──────────────────────────────────────────────── */
[data-tip] {
  position: relative;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1d27;
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: var(--z-dropdown);
}
[data-tip]:hover::after {
  opacity: 1;
}

/* ── Responsive utilities ─────────────────────────────────── */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .form-row    { grid-template-columns: 1fr; }
  .modal       { max-width: 100%; margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}

@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}
