:root {
  --bg: #0e1116;
  --surface: #161b23;
  --surface-2: #1d242f;
  --border: #2a3342;
  --text: #dce3ec;
  --text-dim: #94a3b8;
  --accent: #4da3ff;
  --accent-2: #37d0a0;
  --warn: #e8b34b;
  --danger: #ff7676; /* Improved contrast to satisfy WCAG AA (>4.5:1) on dark surfaces */
  --mono: "SF Mono", "JetBrains Mono", Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
}

.accent { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h1 { font-size: 1.1rem; margin: 0; letter-spacing: -0.01em; white-space: nowrap; }

/* ---- project switcher ---- */
.project-switcher { display: flex; align-items: center; gap: 8px; }
.project-switcher .proj-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim);
  white-space: nowrap;
}
#project-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 36px 5px 12px;
  font: inherit;
  font-size: 0.86rem;
  max-width: 260px;
  height: 36px;
  vertical-align: middle;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%238a97a8'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z' clip-rule='evenodd' /%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
}
#project-select:hover { border-color: rgba(77, 163, 255, 0.4); }
#project-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.15); }
#tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}
.tab:focus-visible {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.03);
  box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.15);
}
.tab.active {
  color: var(--accent);
  background: rgba(77, 163, 255, 0.14);
  font-weight: 600;
  border-color: rgba(77, 163, 255, 0.25);
  box-shadow: 0 0 12px rgba(77, 163, 255, 0.15);
}

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--accent);
  margin: 28px 0 16px;
  letter-spacing: -0.01em;
}
.view { display: none; }
.view.active { display: block; }
[hidden] { display: none !important; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 24px 0 12px; }
.section-head h2 { margin: 0; }

button { font: inherit; cursor: pointer; }

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  transition: all 0.15s ease;
}
.btn:hover:not(:disabled) { border-color: rgba(77, 163, 255, 0.4); }
.btn:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.15); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.approve { color: var(--accent-2); border-color: #1e5c45; }
.btn.approve:hover { border-color: var(--accent-2); }
.btn.reject { color: var(--danger); border-color: #5c2a2a; }
.btn.reject:hover { border-color: var(--danger); }
.btn.primary { background: var(--accent); color: #08121f; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #6bb4ff; border-color: #6bb4ff; }
.btn.primary:disabled { background: rgba(255, 255, 255, 0.04); border-color: var(--border); color: rgba(255, 255, 255, 0.25); opacity: 1; }
.btn.ghost { background: transparent; }

#new-project {
  height: 36px;
  padding: 0 14px;
  border-radius: 8px;
}

/* ---- empty state ---- */
.empty-state { display: flex; justify-content: center; padding: 80px 16px; }
.empty-card {
  max-width: 460px; width: 100%; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 40px 32px;
}
.empty-card h2 { color: var(--text); margin: 0 0 8px; }
.empty-form { display: flex; gap: 8px; margin-top: 20px; }
.empty-form input {
  flex: 1; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font: inherit;
}
.empty-form input:focus { outline: none; border-color: var(--accent); }

/* ---- search bar ---- */
.search-bar { display: flex; gap: 10px; margin: 16px 0 24px; }
.search-bar input {
  flex: 1; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; font: inherit; font-size: 0.9rem;
  height: 40px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-bar input::placeholder { color: var(--text-dim); opacity: 0.85; }
.search-bar input:hover { border-color: rgba(77, 163, 255, 0.4); }
.search-bar input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.15); }
.search-bar .btn.primary { height: 40px; padding: 0 24px; }

/* ---- job status / spinner ---- */
.job-status {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; margin: 10px 0; font-size: 0.85rem; color: var(--text-dim);
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.job-status.done { color: var(--accent-2); border-color: #1e5c45; }
.job-status.error { color: var(--danger); border-color: #5c2a2a; }

/* ---- banners ---- */
.banner {
  border-radius: 8px; padding: 10px 14px; margin: 10px 0; font-size: 0.85rem;
  border: 1px solid var(--border); background: var(--surface);
}
.banner.warn { color: var(--warn); border-color: #5c4a1e; background: #241d0f; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap::-webkit-scrollbar {
  height: 6px;
}
.table-wrap::-webkit-scrollbar-track {
  background: var(--bg);
}
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 6px; }
tr.selectable td { transition: background-color 0.15s ease; }
tr.selectable:hover td { background: rgba(77, 163, 255, 0.03); }
td.chk, th.chk {
  width: 44px;
  padding-left: 8px;
  padding-right: 8px;
  text-align: center;
}
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  border-radius: 4px;
  background: var(--surface-2);
  position: relative;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}
input[type="checkbox"]:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.05);
}
input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #08121f;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="checkbox"]:active { transform: scale(0.9); }
input[type="checkbox"]:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.25);
}

.app-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.app-cell > div { display: flex; flex-direction: column; justify-content: center; }
.app-cell > div > div:first-child { font-weight: 600; color: var(--text); line-height: 1.3; }
.app-cell .dim { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 0.75rem; margin-top: 2px; }
.app-cell .dim .chip { margin: 0; padding: 0 6px; height: 18px; font-size: 0.64rem; line-height: 1; }

.app-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
  background: var(--surface-2);
  flex-shrink: 0;
}
.app-icon.fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
}

.chip {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 0 8px;
  height: 22px;
  line-height: 1;
  margin: 1px 4px 1px 0;
  white-space: nowrap;
  vertical-align: middle;
  box-sizing: border-box;
}
.chip b { color: var(--accent); font-weight: 600; }
.chip.lever { color: var(--accent-2); border-color: rgba(55, 208, 160, 0.25); background: rgba(55, 208, 160, 0.08); }
.chip.signal { color: var(--accent); border-color: rgba(77, 163, 255, 0.25); background: rgba(77, 163, 255, 0.08); }
.chip.verified { color: var(--accent-2); border-color: rgba(55, 208, 160, 0.3); background: rgba(55, 208, 160, 0.12); }
.chip.unverified { color: var(--warn); border-color: rgba(232, 179, 75, 0.3); background: rgba(232, 179, 75, 0.08); }
.chip.status-approved { color: var(--accent-2); border-color: rgba(55, 208, 160, 0.3); background: rgba(55, 208, 160, 0.06); }
.chip.status-candidate { color: var(--text-dim); border-color: var(--border); background: rgba(138, 151, 168, 0.06); }
td.revenue { font-family: var(--mono); white-space: nowrap; text-align: right; font-weight: 600; }
td.num { font-family: var(--mono); white-space: nowrap; text-align: right; }
th.right { text-align: right !important; }
/* Keep keyword-rank chips on one line so rows stay a uniform height. */
.ranks-cell {
  max-width: 380px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
  mask-image: linear-gradient(to right, black 85%, transparent 100%);
}
.ranks-cell::-webkit-scrollbar {
  display: none;
}
.star { color: var(--warn); margin-right: 2px; font-size: 0.9em; }

#competitors td:last-child {
  white-space: nowrap;
}

.btn.verify {
  background: var(--surface-2);
  color: var(--accent);
  border-color: rgba(77, 163, 255, 0.3);
  padding: 0 10px;
  height: 22px;
  line-height: 1;
  font-size: 0.78rem;
  border-radius: 6px;
  margin-left: 8px;
  vertical-align: middle;
  transition: all 0.15s ease;
  box-sizing: border-box;
}
.btn.verify:hover {
  background: rgba(77, 163, 255, 0.15);
  border-color: var(--accent);
  color: var(--text);
}

.dim { color: var(--text-dim); }
.empty {
  color: var(--text-dim);
  padding: 48px 24px;
  font-size: 0.95rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
  margin: 20px 0;
  width: 100%;
}
.folders .empty,
.grid .empty,
.cards .empty {
  grid-column: 1 / -1;
}

/* ---- stats cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
  container-type: inline-size; /* Enable container query context on the card */
}
.card:hover {
  border-color: rgba(77, 163, 255, 0.6);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(77, 163, 255, 0.15);
  transform: translateY(-2px);
}
.card .head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.card .head .app-icon { width: 44px; height: 44px; }
.card .head .name { font-weight: 600; font-size: 1rem; color: var(--text); line-height: 1.3; }
.card .head .sub { color: var(--text-dim); font-size: 0.78rem; margin-top: 2px; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 4px;
  margin-bottom: 16px;
}
@media (max-width: 1024px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
/* Container query: switch to 2 columns if the card container is too narrow (e.g. tablet viewports or narrow desktop screens) */
@container (max-width: 340px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}
.stat:hover {
  border-color: rgba(77, 163, 255, 0.35);
  background: rgba(29, 36, 47, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.stat .v { font-size: 1.15rem; font-weight: 700; font-family: var(--mono); color: var(--text); letter-spacing: -0.02em; }
.stat .v.money { color: var(--accent-2); }
.stat .k { font-size: 0.65rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500; margin-top: 4px; line-height: 1.2; }
.card .foot {
  margin-top: auto;
  padding-top: 16px; /* balanced symmetry with grid's margin-bottom: 16px */
  border-top: 1px solid var(--border);
  font-size: 0.74rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card .foot > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 500;
  white-space: normal; /* Allow text wrapping for long page names / warnings */
  word-break: break-word;
  line-height: 1.3;
}
.card .foot > .f-verified {
  background: rgba(55, 208, 160, 0.08);
  border: 1px solid rgba(55, 208, 160, 0.2);
}
.card .foot > span:first-child:not(.f-verified) {
  background: rgba(232, 179, 75, 0.06);
  border: 1px solid rgba(232, 179, 75, 0.15);
}
.card .foot > span:last-child {
  background: rgba(138, 151, 168, 0.08);
  border: 1px solid rgba(138, 151, 168, 0.2);
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.7rem;
  white-space: nowrap;
}

/* ---- gallery folders ---- */
.folders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 32px 20px;
  margin-top: 24px;
}
.folder-tile {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.folder-tile:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.folder-tile .tab-notch {
  position: absolute;
  top: -10px;
  left: 16px;
  width: 52px;
  height: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  z-index: 2;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.folder-tile .tab-notch::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 5px;
  background: var(--surface);
  z-index: 3;
}
.folder-tile:hover .tab-notch {
  border-color: var(--accent);
}
.folder-cover {
  height: 120px;
  aspect-ratio: 1.6;
  border-radius: 8px;
  background: #000 center/cover no-repeat;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 12px;
}
@supports (aspect-ratio: 1) {
  .folder-cover {
    height: auto;
  }
}
.folder-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.folder-cover .app-icon { width: 52px; height: 52px; }
.folder-tile .f-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  height: 2.6em;
  line-height: 1.3;
  color: var(--text);
}
.folder-tile .f-meta {
  font-size: 0.74rem;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 4px;
}
.folder-tile .f-verified {
  color: var(--accent-2);
  background: rgba(55, 208, 160, 0.08);
  border: 1px solid rgba(55, 208, 160, 0.25);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.68rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
}
.folder-tile .f-unverified {
  color: var(--warn);
  background: rgba(232, 179, 75, 0.06);
  border: 1px solid rgba(232, 179, 75, 0.25);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.68rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
}

/* ---- gallery folder view ---- */
.folder-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.folder-title { font-weight: 600; font-size: 1rem; }
.folder-title .dim { font-weight: 400; }
.folder-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.foreign-toggle { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--warn); cursor: pointer; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.creative {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.creative:hover {
  border-color: rgba(77, 163, 255, 0.5);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(77, 163, 255, 0.1);
}
.creative.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 24px rgba(0, 0, 0, 0.3);
}
.creative.selected:hover {
  border-color: #6bb4ff;
  box-shadow: 0 0 0 1px #6bb4ff, 0 8px 24px rgba(0, 0, 0, 0.35);
}
.creative:has(input:focus-visible) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 24px rgba(0, 0, 0, 0.2);
}
.creative:has(video) .thumb::before {
  content: "▶";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(14, 17, 22, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 3px;
  z-index: 1;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.creative:has(video):hover .thumb::before {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.8);
}
.creative .thumb { position: relative; background: #000; }
.creative video, .creative img.thumb-img {
  width: 100%;
  height: 260px;
  object-fit: cover;
  background: #000;
  display: block;
}
.creative .pick {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  width: 26px; height: 26px; border-radius: 6px;
  background: rgba(22, 27, 35, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease;
}
.creative .pick input { margin: 0; }
.creative.selected .pick {
  border-color: var(--accent);
  background: rgba(77, 163, 255, 0.25);
}
.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.82rem;
  background: rgba(14, 17, 22, 0.7);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  padding: 2px 8px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: all 0.15s ease;
}
.badge.hi { border-color: var(--accent-2); color: var(--accent-2); }
.badge.unrated { border-color: var(--border); color: var(--text-dim); }
.star-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 0.85rem;
  background: rgba(14, 17, 22, 0.75);
  border: 1px solid var(--warn);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  line-height: 1;
  padding-bottom: 1px;
}
.creative .meta { padding: 8px 10px; }
.creative .hook { font-size: 0.78rem; font-weight: 600; color: var(--accent-2); min-height: 1.2em; }
.creative .hook:empty::after { content: "Unanalyzed"; color: var(--text-dim); font-style: italic; font-weight: 400; }
.creative .who { font-size: 0.74rem; color: var(--text-dim); margin-top: 2px; }

/* ---- drawer ---- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(620px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 50;
  overflow-y: auto;
}
.drawer.hidden, .drawer-backdrop.hidden { display: none; }
.drawer-inner { padding: 20px 22px 40px; }
.drawer-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.6rem;
  z-index: 2;
  cursor: pointer;
  border-radius: 50%;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.drawer-close:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text);
}
.drawer-close:focus-visible {
  outline: none;
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text);
}
.drawer h3 { margin: 0 0 4px; font-size: 1rem; padding-right: 30px; }
.drawer .sub { color: var(--text-dim); font-size: 0.8rem; margin-bottom: 14px; }
.drawer video, .drawer img.full { width: 100%; border-radius: 8px; background: #000; }
.drawer h4, .insp-item h4 { color: var(--accent); font-size: 0.85rem; margin: 20px 0 8px; text-transform: uppercase; letter-spacing: 0.05em; }

.scorebar { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 0.8rem; }
.scorebar .lbl { flex: 0 0 200px; color: var(--text-dim); }
.scorebar .track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.scorebar .fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.scorebar .fill.hi { background: var(--accent-2); }
.scorebar .fill.lo { background: var(--danger); }
.scorebar .num { font-family: var(--mono); width: 3.5ch; text-align: right; }

.kv {
  font-size: 0.84rem;
  margin-bottom: 14px;
}
.kv .k {
  display: block;
  margin-bottom: 4px;
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* structure map beats + transcript */
.beats { list-style: none; margin: 6px 0; padding: 0; }
.beats li { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
.beats .ts { font-family: var(--mono); color: var(--accent); flex: 0 0 52px; }
.beats .bt b { color: var(--text); }
details.block {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; margin: 8px 0; font-size: 0.84rem;
}
details.block summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.transcript-line { display: flex; gap: 10px; padding: 3px 0; font-size: 0.82rem; }
.transcript-line .ts { font-family: var(--mono); color: var(--text-dim); flex: 0 0 52px; }

details.variant {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 0.84rem;
}
details.variant summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.variant summary .angle { color: var(--text-dim); font-weight: 400; font-size: 0.78rem; }
details.block summary:focus-visible,
details.variant summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.2);
  border-radius: 4px;
}
details.variant .lines { margin: 8px 0; }
details.variant .line { padding: 4px 0; border-bottom: 1px dashed var(--border); }
details.variant .line .type { font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase; color: var(--accent-2); margin-right: 6px; }
details.variant .line .vnote { color: var(--text-dim); font-size: 0.76rem; font-style: italic; }
details.variant pre {
  white-space: pre-wrap;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--text);
  margin: 8px 0 4px;
}

.star-btn {
  width: 100%;
  margin-top: 18px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
}
.star-btn.starred { border-color: var(--warn); color: var(--warn); }
.star-btn:hover { border-color: var(--warn); }

/* ---- inspiration ---- */
.insp-folder { margin-bottom: 20px; }
.insp-folder > summary {
  display: flex; align-items: center; gap: 12px; cursor: pointer; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  font-size: 0.95rem;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.insp-folder > summary:hover {
  border-color: var(--accent);
  background-color: var(--surface-2);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(77, 163, 255, 0.1);
}
.insp-folder > summary:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.15);
}
.insp-folder > summary::-webkit-details-marker { display: none; }
.insp-folder > summary .app-icon { width: 34px; height: 34px; }
.insp-folder > summary .f-name { font-weight: 600; }
.insp-folder > summary .f-count { color: var(--text-dim); font-size: 0.8rem; }
.insp-folder > summary .caret { display: inline-block; margin-left: auto; color: var(--text-dim); transition: transform 0.2s ease; }
.insp-folder[open] > summary .caret { transform: rotate(90deg); }
.insp-folder .insp-body { padding-top: 14px; }
.insp-item {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  position: relative;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.insp-item:hover {
  border-color: rgba(77, 163, 255, 0.35);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(77, 163, 255, 0.05);
}
@media (min-width: 641px) {
  .insp-item > div:first-child {
    position: sticky;
    top: 80px;
    align-self: start;
  }
}
.insp-item .sub {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-top: 4px;
  margin-bottom: 16px;
}
.insp-item video, .insp-item img {
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  display: block;
}
.insp-item textarea {
  width: 100%;
  min-height: 80px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.86rem;
  line-height: 1.4;
  resize: vertical;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
.insp-item textarea::placeholder {
  color: var(--text-dim);
  opacity: 0.7;
}
.insp-item textarea:hover {
  border-color: rgba(77, 163, 255, 0.45);
  background-color: rgba(29, 36, 47, 0.6);
}
.insp-item textarea:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--surface-2);
  box-shadow: 0 0 0 3px rgba(77, 163, 255, 0.2);
}
.insp-item .note-row { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 10px; }
.note-status { font-size: 0.76rem; color: var(--accent-2); align-self: center; }

/* Separator and spacing for analysis headings */
.insp-item h4 {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin: 22px 0 10px !important;
}
.insp-item h4:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 8px !important;
}

/* Scorecard bar & gradient enhancements */
.scorebar {
  margin-bottom: 10px;
}
.scorebar .track {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.03);
}
.scorebar .fill {
  background: linear-gradient(90deg, #1e3a5c, var(--accent));
}
.scorebar .fill.hi {
  background: linear-gradient(90deg, #1e5c45, var(--accent-2));
}
.scorebar .fill.lo {
  background: linear-gradient(90deg, #5c2a2a, var(--danger));
}

/* Highlighted blockquote-like styling for Analyst Note */
.scorebar ~ .kv {
  background: rgba(77, 163, 255, 0.03);
  border-left: 3px solid var(--accent);
  padding: 14px 18px;
  border-radius: 0 8px 8px 0;
  margin-top: 18px;
  margin-bottom: 22px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(77, 163, 255, 0.05);
  border-right: 1px solid rgba(77, 163, 255, 0.05);
  border-bottom: 1px solid rgba(77, 163, 255, 0.05);
}
.scorebar ~ .kv .k {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.scorebar ~ h4 ~ .kv {
  background: none;
  border-left: none;
  border: none;
  box-shadow: none;
  padding: 0;
  border-radius: 0;
  margin-top: 0;
  margin-bottom: 14px;
}
.scorebar ~ h4 ~ .kv .k {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

/* Interactive transitions for details blocks */
details.block, details.variant {
  transition: border-color 0.15s ease;
}
details.block:hover, details.variant:hover {
  border-color: rgba(77, 163, 255, 0.4);
}

/* ---- confirm-page modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 60; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 32px)); max-height: 86vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; z-index: 70;
}
.modal.hidden, .modal-backdrop.hidden { display: none; }
.modal-inner { padding: 22px 24px; }
.modal h3 { margin: 0 0 4px; font-size: 1.05rem; }
.modal .sub { color: var(--text-dim); font-size: 0.82rem; margin-bottom: 16px; }
.candidate {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 10px; color: var(--text);
}
.candidate:hover { border-color: var(--accent); }
.candidate .c-main { flex: 1; }
.candidate .c-name { font-weight: 600; font-size: 0.9rem; }
.candidate .c-id { font-family: var(--mono); font-size: 0.72rem; color: var(--text-dim); }
.candidate .c-score { font-family: var(--mono); font-size: 0.72rem; color: var(--accent-2); white-space: nowrap; }
.candidate.best { border-color: #1e5c45; }
.candidate .c-badge { font-size: 0.66rem; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.05em; }
.modal-skip { width: 100%; margin-top: 6px; }
.modal-progress { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 0.85rem; padding: 8px 0; }

/* ---- login overlay (injected by the live data layer) ---- */
.login-backdrop { position: fixed; inset: 0; background: var(--bg); z-index: 100; display: flex; align-items: center; justify-content: center; }
.login-card { width: min(360px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; text-align: center; }
.login-card h2 { color: var(--text); margin: 0 0 6px; font-size: 1.1rem; }
.login-card input { width: 100%; margin: 18px 0 12px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font: inherit; }
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card .err { color: var(--danger); font-size: 0.8rem; min-height: 1.2em; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px; }
  #tabs {
    width: calc(100% + 24px);
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 10px 16px;
    border: 1px solid transparent;
    white-space: nowrap;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .project-switcher { margin-left: 0; width: 100%; display: flex; gap: 8px; }
  .project-switcher .proj-label { display: none; }
  #project-select { max-width: none; flex: 1; }
}

@media (max-width: 640px) {
  main { padding: 16px 12px; }
  h2 { margin-top: 16px; margin-bottom: 12px; font-size: 1.15rem; }

  /* Competitor table: drop the least-essential columns so essentials fit. */
  .table-wrap th.opt, .table-wrap td.opt { display: none; }
  .table-wrap table { min-width: 550px; width: 100%; }
  
  th, td { padding: 12px 10px; }
  
  .app-icon { width: 28px; height: 28px; border-radius: 6px; }
  .app-cell { gap: 8px; }
  .app-cell > div > div:first-child { font-size: 0.82rem; }
  .app-cell .dim { font-size: 0.7rem !important; gap: 4px; }
  
  input[type="checkbox"] {
    width: 20px;
    height: 20px;
    position: relative;
  }
  input[type="checkbox"]::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
  }
  input[type="checkbox"]:checked::after {
    left: 7px;
    top: 2px;
    width: 5px;
    height: 11px;
    border-width: 0 2px 2px 0;
  }
  
  /* Verification column cell alignment and sizing on mobile */
  #competitors td:last-child {
    white-space: nowrap;
  }
  td:last-child .chip {
    display: inline-flex;
    align-items: center;
    margin-bottom: 0;
    margin-right: 8px;
  }
  td:last-child .btn.verify {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 0;
    margin-top: 0;
    padding: 0 16px;
    height: 44px; /* Accessible tap target */
    font-size: 0.8rem;
    text-align: center;
    width: auto;
    box-sizing: border-box;
    vertical-align: middle;
  }

  .project-switcher .proj-label { display: none; }
  #project-select {
    height: 44px;
    font-size: 0.9rem;
    padding: 0 36px 0 12px;
    background-position: right 12px center;
    background-size: 20px;
    border-radius: 8px;
    max-width: none;
    flex: 1;
  }
  #new-project {
    height: 44px;
    font-size: 0.9rem;
    padding: 0 16px;
    border-radius: 8px;
  }

  .search-bar { flex-direction: column; }
  .search-bar input { height: 44px; font-size: 0.95rem; }
  .search-bar .btn.primary { height: 44px; padding: 10px; font-size: 0.95rem; }
  #approve-selected {
    height: 44px;
    font-size: 0.9rem;
    padding: 0 16px;
  }

  /* Mobile layout overrides for .insp-item to improve visual hierarchy and tap target size */
  .insp-item {
    display: flex;
    flex-direction: column;
    padding: 16px;
  }
  .insp-item > div {
    display: contents; /* unwrap wrappers to allow flex-reordering of descendants */
  }
  /* Prevent height collapse browser bugs for display: contents children in flex container */
  .insp-item > div > * {
    flex: 0 0 auto;
    width: 100%;
  }
  .insp-item > div > h3 {
    order: -5;
    margin-top: 4px !important;
    margin-bottom: 4px !important;
    font-size: 1.15rem;
  }
  .insp-item > div > .sub {
    order: -4;
    margin-bottom: 12px;
    font-size: 0.78rem;
  }
  .insp-item > div > img,
  .insp-item > div > video {
    order: -3;
    height: 200px;
    object-fit: cover;
    margin-bottom: 12px;
  }
  .insp-item > div > .note-row {
    order: -2;
    margin: 8px 0 10px !important;
  }
  .insp-item > div > div[style*="display:flex"] {
    order: -1;
    margin-bottom: 20px !important;
    display: flex !important;
    gap: 8px;
    width: 100%;
    position: relative;
  }
  .insp-item > div > div[style*="display:flex"] .btn {
    flex: 1;
    height: 44px; /* Mobile tap target compliance >= 44px */
    font-size: 0.9rem;
  }
  .insp-item > div > div[style*="display:flex"] .note-status {
    position: absolute;
    right: 12px;
    top: -22px;
  }
  .scorebar { flex-wrap: wrap; gap: 4px 10px; margin-bottom: 12px; }
  .scorebar .lbl { flex: 0 0 100%; margin-bottom: 2px; }

  .insp-folder > summary {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 12px;
    align-items: center;
  }
  .insp-folder > summary .app-icon {
    grid-column: 1;
    grid-row: 1 / 3;
  }
  .insp-folder > summary .f-name {
    grid-column: 2;
    grid-row: 1;
    line-height: 1.25;
  }
  .insp-folder > summary .f-count {
    grid-column: 2;
    grid-row: 2;
    white-space: nowrap;
    font-size: 0.76rem;
  }
  .insp-folder > summary .caret {
    grid-column: 3;
    grid-row: 1 / 3;
    margin-left: auto;
  }

  .card { padding: 16px; }
  .card .head .app-icon { width: 36px; height: 36px; }

  /* Gallery Folder view mobile enhancements */
  .folder-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  #gallery-back {
    height: 44px;
    padding: 0 16px;
    font-size: 0.9rem;
    margin-bottom: 0;
  }
  #gallery-title {
    margin: 0;
  }
  .folder-actions {
    width: 100%;
    margin-left: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }
  #analyze-selected {
    flex: 1;
    margin-left: 0;
    height: 44px;
    min-width: 140px;
  }
  .foreign-toggle {
    padding: 10px 0;
    min-height: 44px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .creative .pick {
    width: 44px;
    height: 44px;
    top: 0;
    left: 0;
    border-radius: 10px 0 10px 0;
    border-top: none;
    border-left: none;
  }
  .creative .badge {
    top: 0;
    right: 0;
    height: 44px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 10px 0 10px;
    border-top: none;
    border-right: none;
  }
  .creative.selected .pick {
    border-color: var(--accent);
  }
  .creative .pick input {
    width: 20px;
    height: 20px;
  }
}
