/* ============================================
   Loom Dashboard — Industrial Control Theme
   ============================================ */

:root {
  /* noboxAI dark palette — derived from brand tokens */
  --bg: #0a0c12;
  --surface: #11141d;
  --surface-2: #181c28;
  --surface-3: #1f2435;
  --border: #262c40;
  --border-hover: #374060;
  --text: #e4e8f1;
  --text-muted: #7b86a3;
  --text-dim: #4a5270;
  --accent: #03a9f4;
  --accent-dim: #0693e3;
  --accent-glow: rgba(3, 169, 244, 0.12);
  --gold: #ffba49;
  --gold-dim: rgba(255, 186, 73, 0.12);
  --green: #8bc34a;
  --green-dim: rgba(139, 195, 74, 0.12);
  --red: #eb5e55;
  --red-dim: rgba(235, 94, 85, 0.12);
  --yellow: #ffba49;
  --yellow-dim: rgba(255, 186, 73, 0.12);
  --blue: #03a9f4;
  --cyan: #03a9f4;
  --purple: #8b5cf6;
  --radius: 8px;
  --radius-lg: 12px;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'DM Mono', 'Fira Code', monospace;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 0 0 1px var(--border);
  --shadow-hover: 0 8px 24px rgba(0,0,0,0.45), 0 0 0 1px var(--border-hover);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Ambient grain */
.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px;
}

/* ===== Top Navigation ===== */

.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topnav-left, .topnav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

.brand-logo { width: 78px; height: 78px; }
.brand-text { letter-spacing: -0.02em; }

.nav-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.nav-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  transition: all var(--transition);
}

.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active { color: var(--accent); background: var(--accent-glow); }
.nav-link.nav-record { color: var(--red); }
.nav-link.nav-record:hover { background: var(--red-dim); color: var(--red); }

.agent-status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.expired { background: var(--yellow); }
.status-dot.offline { background: var(--red); }

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover { color: var(--text); border-color: var(--border-hover); background: var(--surface-3); }

.video-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

/* ===== Toolbar ===== */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.add-url-form {
  display: flex;
  gap: 0;
}

.add-url-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-right: none;
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius) 0 0 var(--radius);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  width: 280px;
  outline: none;
  transition: border-color var(--transition);
}

.add-url-input:focus { border-color: var(--accent); }
.add-url-input::placeholder { color: var(--text-dim); }

.btn-add {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  padding: 7px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-display);
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.btn-add:hover { background: var(--accent-dim); }

.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px 7px 32px;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-family: var(--font-display);
  width: 200px;
  outline: none;
  transition: border-color var(--transition);
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }

.filter-chips {
  display: flex;
  gap: 4px;
}

.chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-family: var(--font-display);
  font-weight: 400;
  cursor: pointer;
  transition: all var(--transition);
}

.chip:hover { border-color: var(--border-hover); color: var(--text); }
.chip.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); font-weight: 500; }

.sort-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 0.7rem;
  font-family: var(--font-display);
  cursor: pointer;
  outline: none;
}

.sort-select option { background: var(--surface); }

/* ===== Dashboard Layout ===== */

.dashboard-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: calc(100vh - 104px);
}

/* ===== Side Panel ===== */

.side-panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  max-height: calc(100vh - 104px);
  position: sticky;
  top: 104px;
}

.panel-section { padding: 0 12px; margin-bottom: 24px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0 4px;
}

.panel-header h4 {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.btn-icon-sm {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon-sm:hover { color: var(--text); border-color: var(--border-hover); }

.folder-list { display: flex; flex-direction: column; gap: 2px; }

.folder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: var(--font-display);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  width: 100%;
}

.folder-item:hover { color: var(--text); background: var(--surface-2); }
.folder-item.active { color: var(--accent); background: var(--accent-glow); }

.folder-item .folder-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-dim);
}

.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }

.tag-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all var(--transition);
}

.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }

.empty-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-style: italic;
}

/* ===== Grid Area ===== */

.grid-area {
  padding: 20px 24px;
  overflow-y: auto;
  max-height: calc(100vh - 104px);
}

/* ===== Bulk Action Bar ===== */

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin-bottom: 16px;
  background: var(--accent-glow);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius);
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.bulk-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  margin-right: 8px;
}

.btn-bulk {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-family: var(--font-display);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-bulk:hover { background: var(--surface-3); border-color: var(--border-hover); }
.btn-bulk-danger { color: var(--red); }
.btn-bulk-danger:hover { background: var(--red-dim); border-color: var(--red); }

.btn-bulk-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-family: var(--font-display);
  cursor: pointer;
  margin-left: auto;
}

.btn-bulk-cancel:hover { color: var(--text); }

/* ===== Video Grid ===== */

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ===== Video Card ===== */

.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

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

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

.card-thumb {
  position: relative;
  aspect-ratio: 16/10;
  background: var(--bg);
  overflow: hidden;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.video-card:hover .card-thumb img {
  transform: scale(1.03);
}

.card-thumb .thumb-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(10, 12, 18, 0.85) 100%);
  opacity: 0;
  transition: opacity 0.3s;
}

.video-card:hover .thumb-overlay { opacity: 1; }

.card-duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(10, 12, 18, 0.85);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 400;
  letter-spacing: 0.03em;
}

.card-select {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(10, 12, 18, 0.5);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-card:hover .card-select,
.video-card.selected .card-select { opacity: 1; }

.card-select.checked {
  background: var(--accent);
  border-color: var(--accent);
}

.card-select.checked::after {
  content: '';
  width: 10px;
  height: 6px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg) translateY(-1px);
}

.card-source {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.55rem;
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.source-sdk { background: var(--green-dim); color: var(--green); }
.source-url { background: var(--accent-glow); color: var(--accent); }
.source-agent_import { background: var(--yellow-dim); color: var(--yellow); }
.source-embed { background: rgba(139, 92, 246, 0.12); color: var(--purple); }

.card-body {
  padding: 12px 14px;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text);
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-meta-item {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
}

.card-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.card-tag {
  font-size: 0.55rem;
  font-family: var(--font-mono);
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.card-agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.55rem;
  font-family: var(--font-mono);
  padding: 1px 5px;
  border-radius: 3px;
}

.agent-complete { background: var(--green-dim); color: var(--green); }
.agent-queued { background: var(--yellow-dim); color: var(--yellow); }

.card-actions {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.video-card:hover .card-actions { opacity: 1; }

.card-action-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.card-action-btn:hover { color: var(--text); border-color: var(--border-hover); }
.card-action-btn.danger:hover { color: var(--red); border-color: var(--red); }

/* ===== Empty State ===== */

.empty-state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 20px;
  color: var(--text-dim);
}

.empty-state-box p { font-size: 1rem; font-weight: 500; color: var(--text-muted); }
.empty-state-box span { font-size: 0.8rem; }
.empty-state-box a { color: var(--accent); text-decoration: none; }
.empty-state-box a:hover { text-decoration: underline; }

/* ===== Loading ===== */

.loading-spinner {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== Pagination ===== */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 20px 0;
}

.page-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all var(--transition);
}

.page-btn:hover { border-color: var(--border-hover); color: var(--text); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

/* ===== Modal ===== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h3 { font-size: 0.9rem; font-weight: 600; }

.modal-close {
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-muted);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

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

.modal-footer button {
  font-family: var(--font-display);
}

/* Modal form inputs */
.modal-body input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-family: var(--font-display);
  width: 100%;
  outline: none;
}

.modal-body input[type="text"]:focus { border-color: var(--accent); }

.modal-body label {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-body .checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.modal-body .checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 0;
}

.modal-body .checkbox-list input[type="checkbox"] {
  accent-color: var(--accent);
}

/* Agent import list */
.agent-import-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.agent-import-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.75rem;
}

.agent-import-item.imported { opacity: 0.5; }
.agent-import-item .item-name { flex: 1; }
.agent-import-item .item-status {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-dim);
}

/* ===== Toast ===== */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.8rem;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 360px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

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

/* ===== Responsive ===== */

@media (max-width: 768px) {
  .dashboard-layout { grid-template-columns: 1fr; }
  .side-panel { display: none; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left, .toolbar-right { flex-wrap: wrap; }
  .add-url-input { width: 100%; }
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

.hidden { display: none !important; }
