/* ============================================================
   DerejFact Admin — Components
   Buttons, Cards, Tables, Badges, Modals, Toasts, Forms
   ============================================================ */

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: var(--radius); font-family: var(--font);
  font-size: 0.85rem; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition),
              box-shadow var(--transition), transform var(--transition);
  white-space: nowrap; text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary-dark); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-glow); }

.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent-dark); }
.btn-accent:hover { background: var(--accent-dark); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger-dark); }
.btn-danger:hover { background: var(--danger-dark); }

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

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

.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ── CARDS ────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border-subtle);
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  display: flex; align-items: flex-start; gap: 14px;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
  cursor: default;
}
.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); border-color: var(--primary); }
.kpi-icon {
  width: 44px; height: 44px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-icon.blue { background: var(--primary-subtle); color: var(--primary-light); }
.kpi-icon.green { background: var(--accent-subtle); color: var(--accent); }
.kpi-icon.red { background: var(--danger-subtle); color: var(--danger); }
.kpi-icon.yellow { background: var(--warning-subtle); color: var(--warning); }
.kpi-icon.info { background: var(--info-subtle); color: var(--info); }
.kpi-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1; }
.kpi-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.kpi-sub { font-size: 0.7rem; color: var(--text-disabled); margin-top: 2px; }

/* ── TABLES ───────────────────────────────────────────────── */
.table-wrapper {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm);
}
.table-header-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}
.table-title { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.table-count { font-size: 0.78rem; color: var(--text-muted); margin-left: 8px; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--bg-secondary); color: var(--text-muted);
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.7px; padding: 11px 16px; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 13px 16px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; font-size: 0.85rem; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-hover); }

/* ── BADGES ───────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge-green { background: var(--accent-subtle); color: var(--accent); }
.badge-green::before { background: var(--accent); }
.badge-blue { background: var(--primary-subtle); color: var(--primary-light); }
.badge-blue::before { background: var(--primary-light); }
.badge-red { background: var(--danger-subtle); color: var(--danger); }
.badge-red::before { background: var(--danger); }
.badge-yellow { background: var(--warning-subtle); color: var(--warning-dark); }
.badge-yellow::before { background: var(--warning); }
.badge-gray { background: var(--surface-2); color: var(--text-muted); }
.badge-gray::before { background: var(--text-disabled); }

/* ── PROGRESS BAR ─────────────────────────────────────────── */
.progress-bar { height: 6px; background: var(--border); border-radius: var(--radius-full); overflow: hidden; min-width: 80px; }
.progress-fill { height: 100%; border-radius: var(--radius-full); transition: width 0.6s ease; background: var(--accent); }
.progress-fill.danger { background: var(--danger); }
.progress-fill.warning { background: var(--warning); }

/* ── EMPTY STATE ──────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 24px; gap: 12px; color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; opacity: 0.35; }
.empty-state-title { font-size: 0.95rem; font-weight: 600; color: var(--text-muted); }
.empty-state-desc { font-size: 0.82rem; color: var(--text-disabled); text-align: center; }

/* ── LOADING SPINNER ──────────────────────────────────────── */
.spinner-wrapper { display: flex; align-items: center; justify-content: center; padding: 60px; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── MODAL ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal); padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95) translateY(10px); transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-lg { max-width: 720px; }

.modal-header {
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.modal-title { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.modal-close {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 4px; border-radius: var(--radius-sm); display: flex;
  align-items: center; justify-content: center; transition: background var(--transition), color var(--transition);
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-close svg { width: 20px; height: 20px; }

.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px 20px; border-top: 1px solid var(--border-subtle); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* API Key reveal modal */
.token-reveal-banner {
  background: var(--warning-subtle); border: 1px solid var(--warning);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
  display: flex; gap: 10px; align-items: flex-start;
}
.token-reveal-banner svg { width: 18px; height: 18px; color: var(--warning); flex-shrink: 0; margin-top: 2px; }
.token-reveal-banner p { font-size: 0.82rem; color: var(--warning-dark); font-weight: 500; }
.token-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; font-family: var(--font-mono); font-size: 0.8rem;
  color: var(--accent); word-break: break-all; line-height: 1.6;
  margin-bottom: 12px; user-select: all;
}
.btn-copy-token { width: 100%; justify-content: center; }
.btn-copy-token.copied { background: var(--accent); border-color: var(--accent-dark); }

/* ── FORMS ────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 16px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.form-label .required { color: var(--danger); margin-left: 3px; }
.form-input, .form-select, .form-textarea {
  padding: 9px 12px; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-family: var(--font); font-size: 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition); width: 100%;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-disabled); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-subtle);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 0.75rem; color: var(--text-disabled); }
.form-section-title { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); padding-top: 8px; margin-bottom: -4px; }
.form-divider { border: none; border-top: 1px solid var(--border-subtle); margin: 4px 0; }

/* Checkbox / Toggle */
.form-check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.form-check-label { font-size: 0.85rem; color: var(--text); cursor: pointer; }

/* Tag input for scopes / IPs */
.tags-input-wrapper {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px; display: flex; flex-wrap: wrap;
  gap: 6px; min-height: 42px; cursor: text;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.tags-input-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-subtle); }
.tag-item {
  background: var(--primary-subtle); color: var(--primary-light); border: 1px solid var(--primary);
  border-radius: var(--radius-full); padding: 2px 10px; font-size: 0.75rem; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.tag-remove { background: none; border: none; color: inherit; cursor: pointer; padding: 0; line-height: 1; font-size: 1rem; opacity: 0.7; }
.tag-remove:hover { opacity: 1; }
.tags-input { border: none; background: transparent; color: var(--text); font-family: var(--font); font-size: 0.85rem; outline: none; flex: 1; min-width: 80px; }

/* ── TOAST NOTIFICATIONS ──────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: var(--z-toast); pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 18px; min-width: 280px; max-width: 380px;
  box-shadow: var(--shadow-lg); pointer-events: all;
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 3.7s forwards;
}
.toast.success { border-left: 3px solid var(--accent); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }
.toast-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast.success .toast-icon { color: var(--accent); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--info); }
.toast-body { flex: 1; }
.toast-title { font-size: 0.85rem; font-weight: 600; color: var(--text); }
.toast-message { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; pointer-events: none; } }

/* ── TABS ─────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-secondary); border-radius: var(--radius); width: fit-content; margin-bottom: 16px; }
.tab-btn {
  padding: 7px 16px; border-radius: var(--radius-sm); border: none; background: transparent;
  color: var(--text-muted); font-family: var(--font); font-size: 0.82rem; font-weight: 600;
  cursor: pointer; transition: background var(--transition), color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ── ACTION BUTTONS (table row) ───────────────────────────── */
.action-btns { display: flex; gap: 6px; }

/* ── CONFIRM DIALOG ───────────────────────────────────────── */
.confirm-dialog { max-width: 400px; }
.confirm-dialog .modal-body { text-align: center; padding: 28px 24px 16px; }
.confirm-dialog .confirm-icon { width: 52px; height: 52px; margin: 0 auto 12px; border-radius: var(--radius-full); display: flex; align-items: center; justify-content: center; }
.confirm-icon.danger { background: var(--danger-subtle); color: var(--danger); }
.confirm-icon.warning { background: var(--warning-subtle); color: var(--warning); }
.confirm-icon svg { width: 26px; height: 26px; }
.confirm-text { font-size: 0.9rem; color: var(--text-muted); }

/* ── CHART WRAPPER ────────────────────────────────────────── */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.chart-title { font-size: 0.88rem; font-weight: 600; color: var(--text); margin-bottom: 16px; }
.chart-container { position: relative; height: 220px; }

@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } .form-grid-2 { grid-template-columns: 1fr; } }
