/* ═══════════════════════════════════════════════════
   COMPONENTS — Buttons, Inputs, Cards, Table, Badge, Modal, Toast
   ═══════════════════════════════════════════════════ */

/* ══════════════════════════════
   BUTTONS
══════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast);
  border: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  text-decoration: none;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #9B8FFF 100%);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow-strong);
}
.btn-primary:active { transform: translateY(0); }

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

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

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.25);
}
.btn-danger:hover {
  background: rgba(239,68,68,0.22);
  border-color: var(--danger);
}

.btn-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(34,197,94,0.25);
}

.btn-sm { padding: 0.4rem 0.875rem; font-size: 0.8rem; }
.btn-sm svg { width: 14px; height: 14px; }

.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}
.btn-icon svg { width: 16px; height: 16px; }

.btn-lg { padding: 0.875rem 2rem; font-size: 1rem; border-radius: var(--radius); }

.btn[disabled], .btn.loading {
  opacity: 0.55; cursor: not-allowed; pointer-events: none;
}

/* Loading spinner inside button */
.btn.loading::after {
  content: '';
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 0.5rem;
}

/* ══════════════════════════════
   FORM ELEMENTS
══════════════════════════════ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.form-group:last-child { margin-bottom: 0; }

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

label .required { color: var(--danger); margin-left: 2px; }

.input, .select, .textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font);
  width: 100%;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

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

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

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

.select {
  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='%237777AA' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

.select option { background: var(--bg-card); color: var(--text-primary); }

.form-hint {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 0.25rem;
}

.form-error {
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 0.25rem;
  display: flex; align-items: center; gap: 0.35rem;
}

.input-prefix {
  position: relative;
}
.input-prefix .prefix-icon {
  position: absolute; left: 0.875rem; top: 50%; transform: translateY(-50%);
  color: var(--text-muted);
  display: flex;
}
.input-prefix .input { padding-left: 2.5rem; }

/* Password toggle */
.input-suffix {
  position: relative;
}
.input-suffix .suffix-btn {
  position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); background: none; border: none; cursor: pointer;
  padding: 0; display: flex; align-items: center;
  transition: color var(--t-fast);
}
.input-suffix .suffix-btn:hover { color: var(--accent); }
.input-suffix .input { padding-right: 2.75rem; }

/* Form row grid */
.form-row { display: grid; gap: 1rem; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ══════════════════════════════
   CARD
══════════════════════════════ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--t);
}

.card:hover {
  border-color: var(--accent-glow-strong);
  box-shadow: var(--shadow-card), 0 0 0 1px var(--accent-glow);
}

.card-body { padding: 1.5rem; }
.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

/* ── Report Card ── */
.report-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  text-decoration: none;
  display: block;
  transition: all var(--t);
  position: relative;
}

.report-card::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--accent-glow);
  opacity: 0;
  transition: opacity var(--t);
  border-radius: var(--radius-lg);
  pointer-events: none;
}

.report-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-glow-strong);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-glow-strong);
}

.report-card:hover::before { opacity: 1; }

.report-card-thumbnail {
  height: 140px;
  background: linear-gradient(135deg, #1A1A2C 0%, #12121E 100%);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
}

.report-card-thumbnail img {
  width: 100%; height: 100%; object-fit: cover;
}

.report-card-thumbnail .thumb-icon {
  color: var(--accent-glow-strong);
  display: flex;
}

.report-card-thumbnail .thumb-icon svg {
  width: 48px; height: 48px;
  stroke: var(--accent);
  opacity: 0.6;
}

.report-card-body {
  padding: 1.125rem 1.25rem 1.25rem;
}

.report-card-category {
  margin-bottom: 0.5rem;
}

.report-card-title {
  font-size: 0.9rem; font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.report-card-desc {
  font-size: 0.775rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.report-card-footer {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Reports Grid ── */
.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

/* ── Stat Card ── */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all var(--t-fast);
}

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

.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}

.stat-icon.purple { background: var(--accent-bg); color: var(--accent); }
.stat-icon.teal   { background: var(--teal-bg);   color: var(--teal); }
.stat-icon.green  { background: var(--success-bg); color: var(--success); }
.stat-icon.red    { background: var(--danger-bg);  color: var(--danger); }
.stat-icon svg    { width: 20px; height: 20px; }

.stat-value {
  font-size: 1.75rem; font-weight: 800;
  color: var(--text-primary); line-height: 1;
}

.stat-label {
  font-size: 0.775rem; color: var(--text-muted);
  font-weight: 500;
}

/* ══════════════════════════════
   BADGE
══════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.badge-purple  { background: var(--accent-bg);  color: var(--accent-light); }
.badge-teal    { background: var(--teal-bg);     color: var(--teal); }
.badge-green   { background: var(--success-bg);  color: var(--success); }
.badge-red     { background: var(--danger-bg);   color: var(--danger); }
.badge-yellow  { background: var(--warning-bg);  color: var(--warning); }
.badge-gray    { background: rgba(255,255,255,0.06); color: var(--text-muted); }
.badge-blue    { background: var(--info-bg);     color: var(--info); }

/* ══════════════════════════════
   TABLE
══════════════════════════════ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 0.875rem 1.25rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.9rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

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

tbody tr:hover { background: rgba(255,255,255,0.025); }

.td-name { font-weight: 600; color: var(--text-primary); }
.td-actions {
  display: flex; align-items: center; gap: 0.5rem;
  justify-content: flex-end;
}

/* ── Search bar ── */
.search-bar {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  padding: 0 1rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.search-bar:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-bar svg { color: var(--text-faint); width: 16px; height: 16px; flex-shrink: 0; }

.search-bar input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 0.875rem;
  padding: 0.65rem 0;
}

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

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

.toggle-slider {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.1);
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--t-fast);
}

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

.toggle input:checked + .toggle-slider { background: var(--accent-glow-strong); }
.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: var(--accent);
}

/* ── Checkbox custom ── */
.checkbox-custom {
  width: 18px; height: 18px;
  border: 2px solid var(--border-input);
  border-radius: 4px;
  background: var(--bg-input);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--t-fast);
  flex-shrink: 0;
}

.checkbox-custom.checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-custom.checked::after {
  content: '';
  width: 5px; height: 9px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg) translateY(-1px);
  display: block;
}

/* ══════════════════════════════
   MODAL
══════════════════════════════ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--bg-modal);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0;
  animation: fadeIn var(--t) forwards;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: slideUp var(--t) forwards;
  overflow: hidden;
}

.modal-header {
  padding: 1.5rem 1.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
}

.modal-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.modal-icon.danger { background: var(--danger-bg); color: var(--danger); }
.modal-icon.info   { background: var(--info-bg);   color: var(--info);   }

.modal-title    { font-size: 1rem; font-weight: 700; }
.modal-subtitle { font-size: 0.825rem; color: var(--text-muted); margin-top: 0.2rem; }

.modal-body   { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex; gap: 0.75rem; justify-content: flex-end;
}

/* ══════════════════════════════
   TOAST
══════════════════════════════ */
#toast-container {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1.125rem;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  min-width: 280px; max-width: 380px;
  animation: toastIn 0.3s ease forwards;
  transition: opacity 0.3s;
}

.toast.hide { animation: toastOut 0.3s ease forwards; }

.toast-icon {
  flex-shrink: 0;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}

.toast.success { border-color: rgba(34,197,94,0.3);  }
.toast.error   { border-color: rgba(239,68,68,0.3);  }
.toast.warning { border-color: rgba(245,158,11,0.3); }
.toast.info    { border-color: rgba(56,189,248,0.3); }

.toast.success .toast-icon { color: var(--success); }
.toast.error   .toast-icon { color: var(--danger);  }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info    .toast-icon { color: var(--info);    }

.toast-msg {
  flex: 1;
  font-size: 0.85rem; font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
}

.toast-close {
  color: var(--text-faint); cursor: pointer;
  display: flex; align-items: center;
  transition: color var(--t-fast); flex-shrink: 0;
}
.toast-close:hover { color: var(--text-primary); }

/* ══════════════════════════════
   SKELETON LOADERS
══════════════════════════════ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-card-hover) 25%,
    rgba(255,255,255,0.04) 50%,
    var(--bg-card-hover) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-card {
  height: 220px;
  border-radius: var(--radius-lg);
}

/* ══════════════════════════════
   CATEGORY FILTER PILLS
══════════════════════════════ */
.category-filter {
  display: flex; align-items: center; gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}

.filter-pill {
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem; font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--t-fast);
}

.filter-pill:hover {
  border-color: var(--border-hover);
  color: var(--text-secondary);
}

.filter-pill.active {
  background: var(--accent-bg);
  border-color: var(--accent-glow-strong);
  color: var(--accent-light);
  font-weight: 600;
}

/* ══════════════════════════════
   PERMISSION MATRIX
══════════════════════════════ */
.matrix-wrap {
  overflow: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
  max-height: calc(100vh - 260px);
}

.matrix-table {
  border-collapse: collapse;
  min-width: 100%;
}

.matrix-table th, .matrix-table td {
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  white-space: nowrap;
  font-size: 0.8rem;
}

.matrix-table thead th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0; z-index: 2;
  text-align: center;
}

.matrix-table thead th:first-child {
  text-align: left;
  position: sticky;
  left: 0; z-index: 3;
}

.matrix-table tbody td:first-child {
  position: sticky; left: 0;
  background: var(--bg-card);
  font-weight: 600; color: var(--text-primary);
  border-right: 2px solid var(--border);
  z-index: 1;
}

.matrix-table tbody td {
  text-align: center;
}

.matrix-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.matrix-table tbody tr:hover td:first-child { background: var(--bg-card-hover); }

.matrix-cb {
  width: 18px; height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ══════════════════════════════
   ALERT BANNERS
══════════════════════════════ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}

.alert svg { flex-shrink: 0; margin-top: 1px; width: 18px; height: 18px; }

.alert-error  { background: var(--danger-bg);  border: 1px solid rgba(239,68,68,0.25);  color: #FCA5A5; }
.alert-success{ background: var(--success-bg); border: 1px solid rgba(34,197,94,0.25);  color: #86EFAC; }
.alert-warning{ background: var(--warning-bg); border: 1px solid rgba(245,158,11,0.25); color: #FCD34D; }

/* ══════════════════════════════
   IFRAME VIEWER
══════════════════════════════ */
.viewer-header {
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky; top: 0; z-index: 50;
}

.viewer-title {
  font-size: 0.9rem; font-weight: 700;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 0.5rem;
}

.viewer-actions { display: flex; align-items: center; gap: 0.5rem; }

.viewer-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 56px);
  border: none;
  background: var(--bg-base);
}

.viewer-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-base);
  flex-direction: column; gap: 1rem;
  color: var(--text-muted); font-size: 0.875rem;
}

/* ── iframe preview ── */
.iframe-preview {
  width: 100%;
  height: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-base);
  overflow: hidden;
  margin-top: 0.5rem;
}

.iframe-preview iframe { width: 100%; height: 100%; border: none; }

/* Responsive */
@media (max-width: 768px) {
  .form-row.cols-2,
  .form-row.cols-3 { grid-template-columns: 1fr; }
  .reports-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .stats-grid   { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-grid   { grid-template-columns: 1fr; }
  .reports-grid { grid-template-columns: 1fr; }
}
