/* ==============================
   COMPONENTS — Lonvital Creative Hub
   Buttons, KPI cards, tables, badges, forms,
   modals, toasts, media cards, wizard, jobs
============================== */

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 600;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-hover); box-shadow: var(--shadow-sm); }
.btn-secondary {
  background: var(--color-surface-offset); color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface-dynamic); }
.btn-ghost {
  background: transparent; color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-text); }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--color-surface-offset); color: var(--color-text); }

/* TABS */
.tabs-bar {
  display: flex; gap: 4px;
  background: var(--color-surface-offset); padding: 4px;
  border-radius: var(--radius-lg); border: 1px solid var(--color-border);
  width: fit-content;
}
.tab-btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 500; color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
  display: flex; align-items: center; gap: var(--space-2);
}
.tab-btn:hover { color: var(--color-text); }
.tab-btn.active {
  background: var(--color-surface-2); color: var(--color-text);
  font-weight: 600; box-shadow: var(--shadow-sm);
}

/* KPI CARDS */
.kpi-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-2);
  transition: box-shadow var(--transition), transform var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-label {
  font-size: var(--text-xs); color: var(--color-text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  display: flex; align-items: center; gap: var(--space-2);
}
.kpi-value {
  font-size: var(--text-xl); font-weight: 700; color: var(--color-text);
  font-variant-numeric: tabular-nums lining-nums; letter-spacing: -0.02em;
}
.kpi-delta {
  font-size: var(--text-xs); font-weight: 600;
  display: flex; align-items: center; gap: 3px;
}
.kpi-delta.up { color: var(--color-success); }
.kpi-delta.down { color: var(--color-error); }
.kpi-platform-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* CHART CARD */
.chart-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); padding: var(--space-5);
}
.chart-card-title {
  font-size: var(--text-sm); font-weight: 600; color: var(--color-text);
  margin-bottom: var(--space-4);
  display: flex; align-items: center; justify-content: space-between;
}
.chart-container { position: relative; height: 200px; }

/* TABLE */
.table-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); overflow: hidden;
}
.table-card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
}
.table-filters { display: flex; gap: var(--space-2); align-items: center; }
.filter-select {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface-offset);
  font-size: var(--text-xs); color: var(--color-text); cursor: pointer;
}
table { border-collapse: collapse; width: 100%; }
thead tr { background: var(--color-surface-offset); border-bottom: 1px solid var(--color-divider); }
th {
  padding: var(--space-2) var(--space-4); text-align: left;
  font-size: var(--text-xs); font-weight: 700; color: var(--color-text-muted);
  letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap;
}
td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--color-divider);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--color-surface-offset); }
.row-clickable { cursor: pointer; }
.row-clickable:hover td { background: var(--color-surface-offset); }

/* BADGES */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--space-2); border-radius: var(--radius-full);
  font-size: 0.65rem; font-weight: 700; white-space: nowrap;
}
.badge-tiktok  { background: rgba(255,45,85,0.12);   color: var(--color-tiktok); }
.badge-meta    { background: rgba(8,102,255,0.12);    color: var(--color-meta); }
.badge-google  { background: rgba(52,168,83,0.12);   color: var(--color-google); }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-error   { background: var(--color-error-bg);   color: var(--color-error); }
.badge-info    { background: var(--color-info-bg);    color: var(--color-info); }
.badge-neutral { background: var(--color-surface-offset); color: var(--color-text-muted); }

/* SCORE BAR */
.score-bar-wrap { display: flex; align-items: center; gap: var(--space-2); }
.score-bar {
  height: 5px; border-radius: var(--radius-full);
  background: var(--color-surface-dynamic);
  flex: 1; min-width: 60px; overflow: hidden;
}
.score-bar-fill {
  height: 100%; border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-accent) 100%);
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* SEARCH BOX */
.search-box {
  flex: 1; min-width: 220px;
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-2) var(--space-3);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-box:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-accent-glow);
}
.search-box input { border: none; outline: none; flex: 1; font-size: var(--text-sm); background: transparent; }
.search-box svg { color: var(--color-text-faint); flex-shrink: 0; }
.media-toolbar { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }

/* TIKTOK DRILLDOWN */
.drill-breadcrumb {
  display:flex; align-items:center; gap:var(--space-2); flex-wrap:wrap;
  margin-bottom:var(--space-4); font-size:var(--text-sm);
}
.drill-crumb-btn {
  display:inline-flex; align-items:center; gap:6px;
  padding:6px 10px; border-radius:var(--radius-full);
  border:1px solid var(--color-border);
  background:var(--color-surface-offset); color:var(--color-text-muted);
  font-weight:600;
}
.drill-crumb-btn.active { background:var(--color-primary); color:#fff; border-color:var(--color-primary); }
.drill-layout { display:grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr); gap:var(--space-5); align-items:start; }
.editor-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); overflow:hidden;
}
.editor-header {
  padding: var(--space-4) var(--space-5);
  border-bottom:1px solid var(--color-divider);
  display:flex; align-items:center; justify-content:space-between; gap:var(--space-3);
}
.editor-body { padding: var(--space-5); display:flex; flex-direction:column; gap:var(--space-4); }
.editor-grid { display:grid; grid-template-columns:1fr 1fr; gap:var(--space-3); }
.editor-grid .full-width { grid-column:1 / -1; }
.preview-frame {
  width:100%; max-width:320px; aspect-ratio:9/16;
  border-radius:28px; background:#000; overflow:hidden;
  border:8px solid #111827; box-shadow:var(--shadow-lg);
  margin:0 auto;
  position:relative;
}
.preview-frame video,
.preview-frame img { width:100%; height:100%; object-fit:cover; display:block; }
.preview-overlay {
  position:absolute; inset:0; display:flex; flex-direction:column; justify-content:space-between;
  padding:var(--space-4); background:linear-gradient(180deg, rgba(0,0,0,.15) 0%, rgba(0,0,0,.0) 35%, rgba(0,0,0,.45) 100%);
  color:white;
}
.preview-meta { display:flex; align-items:center; gap:var(--space-2); font-size:var(--text-xs); font-weight:700; }
.preview-copy {
  font-size:var(--text-sm); line-height:1.45; font-weight:600;
  text-shadow:0 1px 2px rgba(0,0,0,.35);
}
.preview-cta {
  align-self:flex-start; background:#fff; color:#111827;
  padding:6px 10px; border-radius:999px; font-size:var(--text-xs); font-weight:800;
}
.preview-empty {
  height:100%; display:flex; align-items:center; justify-content:center; flex-direction:column;
  color:#d1d5db; gap:var(--space-2); font-size:var(--text-sm);
}
.metric-stack { display:flex; flex-direction:column; gap:4px; }
.metric-sub { color:var(--color-text-muted); font-size:var(--text-xs); }
.inline-actions { display:flex; gap:var(--space-2); flex-wrap:wrap; }

/* MEDIA CARD */
.media-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); overflow: hidden; cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.media-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--color-primary); }
.media-card.selected { border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-accent-glow); }
.media-thumbnail {
  aspect-ratio: 16/9; background: var(--color-surface-offset);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.media-thumb-icon { color: var(--color-primary); opacity: 0.5; }
.media-duration {
  position: absolute; bottom: var(--space-2); right: var(--space-2);
  background: rgba(0,0,0,0.7); color: white;
  font-size: 0.65rem; font-weight: 700; padding: 2px 6px;
  border-radius: var(--radius-sm); font-variant-numeric: tabular-nums;
}
.media-source-badge {
  position: absolute; top: var(--space-2); left: var(--space-2);
  font-size: 0.6rem; font-weight: 700; padding: 2px 6px;
  border-radius: var(--radius-sm); text-transform: uppercase;
}
.media-info { padding: var(--space-3); }
.media-title {
  font-size: var(--text-sm); font-weight: 600; color: var(--color-text);
  margin-bottom: var(--space-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.media-meta { font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-2); }
.media-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.media-tag {
  font-size: 0.65rem; padding: 2px 6px;
  background: var(--color-surface-offset); border-radius: var(--radius-full);
  color: var(--color-text-muted); font-weight: 500; border: 1px solid var(--color-divider);
}
.media-actions {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-divider);
  display: flex; gap: var(--space-2); justify-content: flex-end;
}

/* WIZARD */
.wizard-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); overflow: hidden;
}
.wizard-steps {
  display: flex; border-bottom: 1px solid var(--color-divider);
  padding: var(--space-4) var(--space-5); gap: var(--space-4); overflow-x: auto;
}
.wizard-step {
  display: flex; align-items: center; gap: var(--space-2);
  flex-shrink: 0; font-size: var(--text-xs); font-weight: 600;
  color: var(--color-text-faint);
}
.wizard-step.active { color: var(--color-primary); }
.wizard-step.done   { color: var(--color-success); }
.wizard-step-num {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid currentColor;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 800;
}
.wizard-step.done .wizard-step-num {
  background: var(--color-success); border-color: var(--color-success); color: white;
}
.wizard-step-sep { color: var(--color-text-faint); margin: 0 var(--space-1); }
.wizard-body { padding: var(--space-6); }
.wizard-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-divider);
  display: flex; justify-content: flex-end; gap: var(--space-3);
  background: var(--color-surface-offset);
}

/* FORM INPUTS */
.form-label {
  font-size: var(--text-xs); font-weight: 700; color: var(--color-text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.form-input {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface-offset); font-size: var(--text-sm);
  color: var(--color-text); width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-accent-glow);
}
.form-select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-surface-offset); font-size: var(--text-sm);
  color: var(--color-text); cursor: pointer; width: 100%;
  transition: border-color var(--transition);
}
.form-select:focus { outline: none; border-color: var(--color-primary); }

/* JOBS */
.jobs-list { display: flex; flex-direction: column; gap: var(--space-3); }
.job-item {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); padding: var(--space-4) var(--space-5);
  display: flex; align-items: center; gap: var(--space-4);
  transition: box-shadow var(--transition);
}
.job-item:hover { box-shadow: var(--shadow-sm); }
.job-icon {
  width: 40px; height: 40px; border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.job-icon.processing { background: var(--color-info-bg);    color: var(--color-info); }
.job-icon.done       { background: var(--color-success-bg); color: var(--color-success); }
.job-icon.queued     { background: var(--color-surface-offset); color: var(--color-text-muted); }
.job-icon.error      { background: var(--color-error-bg);   color: var(--color-error); }
.job-info { flex: 1; min-width: 0; }
.job-name { font-size: var(--text-sm); font-weight: 600; color: var(--color-text); }
.job-meta { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 2px; }
.job-progress { width: 120px; display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.job-progress-bar {
  height: 5px; background: var(--color-surface-dynamic);
  border-radius: var(--radius-full); overflow: hidden;
}
.job-progress-fill {
  height: 100%; border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-accent) 100%);
  transition: width 1s ease;
}
.job-progress-label { font-size: 0.65rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; text-align: right; }

/* CLIP CARD */
.clip-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition);
}
.clip-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.clip-thumb {
  aspect-ratio: 9/16;
  background: linear-gradient(160deg, var(--color-surface-offset) 0%, var(--color-surface-dynamic) 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-2); position: relative;
}
.clip-thumb-icon { color: var(--color-primary); opacity: 0.6; }
.clip-score {
  position: absolute; top: var(--space-2); right: var(--space-2);
  background: var(--color-primary); color: white;
  font-size: 0.65rem; font-weight: 800; padding: 3px 6px; border-radius: var(--radius-sm);
}
.clip-info { padding: var(--space-3); }
.clip-title {
  font-size: var(--text-xs); font-weight: 600; color: var(--color-text); margin-bottom: 4px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.clip-meta { font-size: 0.65rem; color: var(--color-text-muted); }
.clip-actions {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-divider);
  display: flex; gap: var(--space-2);
}

/* CREATIVE CENTER */
.request-form-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); overflow: hidden;
}
.request-form-header {
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-divider);
  display: flex; align-items: center; gap: var(--space-3);
}
.request-form-header h3 { font-size: var(--text-base); font-weight: 700; }
.request-form-body { padding: var(--space-5); }

.canva-connect-panel {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); overflow: hidden;
}
.canva-connect-header {
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-divider);
  display: flex; align-items: center; gap: var(--space-3);
}
.tool-logo {
  width: 28px; height: 28px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-sm); font-weight: 800; color: white; flex-shrink: 0;
}
.tool-logo.canva   { background: #7d2ae8; }
.tool-logo.echo    { background: #ff6b35; }
.tool-logo.opus    { background: #2563eb; }
.tool-logo.descript{ background: #1a1a2e; }

.connection-status {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface-offset);
  border-bottom: 1px solid var(--color-divider);
  font-size: var(--text-xs);
}
.connection-status svg { color: var(--color-success); }
.connection-status span { color: var(--color-text); font-weight: 600; }
.connection-status .conn-detail { color: var(--color-text-muted); margin-left: auto; }

.agent-panel { padding: var(--space-4) var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); }
.agent-log {
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-3);
  font-size: var(--text-xs); font-family: 'Courier New', monospace;
  max-height: 180px; overflow-y: auto; line-height: 1.8;
}
.log-line { display: flex; gap: var(--space-2); }
.log-time { color: var(--color-text-faint); flex-shrink: 0; }
.log-msg.ok      { color: var(--color-success); }
.log-msg.info    { color: var(--color-primary); }
.log-msg.warn    { color: var(--color-warning); }
.log-msg.pending { color: var(--color-text-muted); }

.request-queue { display: flex; flex-direction: column; gap: var(--space-2); }
.request-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3); border-radius: var(--radius-lg);
  background: var(--color-surface-offset); border: 1px solid var(--color-divider);
  transition: background var(--transition); cursor: pointer;
}
.request-item:hover { background: var(--color-surface-dynamic); }
.request-thumb {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  background: var(--color-primary-highlight);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--color-primary);
}
.request-info { flex: 1; min-width: 0; }
.request-name { font-size: var(--text-xs); font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.request-sub  { font-size: 0.65rem; color: var(--color-text-muted); }
.request-status { flex-shrink: 0; }

/* EMPTY STATE */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: var(--space-12) var(--space-8);
  color: var(--color-text-muted);
}
.empty-state-icon { margin-bottom: var(--space-4); color: var(--color-text-faint); }
.empty-state h3 { color: var(--color-text); margin-bottom: var(--space-2); font-size: var(--text-base); }
.empty-state p  { max-width: 36ch; margin-bottom: var(--space-6); font-size: var(--text-sm); }

/* SKELETON */
@keyframes shimmer { 0%{background-position:-200% 0} 100%{background-position:200% 0} }
.skeleton {
  background: linear-gradient(90deg,
    var(--color-surface-offset) 25%,
    var(--color-surface-dynamic) 50%,
    var(--color-surface-offset) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-2xl); padding: var(--space-6);
  width: min(560px, 90vw); box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-5);
}
.modal-title { font-size: var(--text-lg); font-weight: 700; }

/* TOAST */
.toast-container {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  z-index: 200; display: flex; flex-direction: column;
  gap: var(--space-2); pointer-events: none;
}
.toast {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4);
  display: flex; align-items: center; gap: var(--space-3);
  box-shadow: var(--shadow-lg); font-size: var(--text-sm); font-weight: 500;
  max-width: 320px; pointer-events: all;
  animation: slideInToast 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
@keyframes slideInToast {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.removing { opacity: 0; transform: translateX(20px); }
.toast-success { border-left: 3px solid var(--color-success); }
.toast-info    { border-left: 3px solid var(--color-info); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-icon.success { color: var(--color-success); }
.toast-icon.info    { color: var(--color-info); }
.toast-icon.warning { color: var(--color-warning); }

@keyframes spin  { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes blink { 0%, 80%, 100% { opacity: .2; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }
@media (max-width: 1100px) {
  .drill-layout { grid-template-columns: 1fr; }
}
