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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-muted: #707070;
  --accent: #c07aff;
  --accent2: #7ab4ff;
  --sidebar-w: 220px;
  --topbar-h: 52px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 10;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.nav-links {
  padding: 8px;
}

.section-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 8px 4px;
}

.accounts-list {
  padding: 0 8px 16px;
  flex: 1;
}

.nav-item {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--accent); font-weight: 500; }

.account-count {
  float: right;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* --- Main --- */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  background: rgba(10,10,10,0.85);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

/* --- Grid --- */
.grid {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

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

.post-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}

.post-thumb-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--text-muted);
}

.post-info {
  padding: 10px 12px;
}

.post-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.post-username {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

.post-date {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.post-caption {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  max-height: 3.2em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.post-media-count {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--surface2);
  border-radius: 4px;
  padding: 1px 6px;
}

.video-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.7);
  border-radius: 4px;
  font-size: 0.7rem;
  padding: 2px 6px;
  color: #fff;
}

.story-badge {
  position: absolute;
  top: 8px; left: 8px;
  background: linear-gradient(135deg, #f09433, #e6683c, #dc2743, #cc2366);
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  color: #fff;
  text-transform: uppercase;
  z-index: 1;
}

.lb-copyrow {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.lb-copyrow--top {
  margin-top: 8px;
}

.copy-btn {
  flex-shrink: 0;
  margin-top: 1px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.copy-btn:hover {
  background: var(--border);
  color: var(--text);
}

.copy-btn.copied {
  border-color: #4caf50;
  color: #4caf50;
}

.lb-url {
  font-size: 0.8rem;
  color: var(--accent2);
  word-break: break-all;
  line-height: 1.5;
  padding-top: 4px;
}

.lb-analysis {
  flex: 1;
  min-height: 24px;
}

.lb-analysis-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.lb-analysis-text {
  font-size: 0.83rem;
  color: var(--text);
  line-height: 1.65;
}

.lb-analysis-pending {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.lb-analysis-pending code {
  font-style: normal;
  background: var(--surface2);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.78rem;
  color: var(--accent2);
}

.lb-transcript-details {
  margin-top: 10px;
}

.lb-transcript-toggle {
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
}

.lb-transcript-toggle::-webkit-details-marker { display: none; }

.lb-transcript-toggle::before {
  content: '▶';
  font-size: 0.6rem;
  transition: transform 0.15s;
}

details[open] .lb-transcript-toggle::before {
  transform: rotate(90deg);
}

.lb-transcript-text {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.65;
  white-space: pre-wrap;
  border-left: 2px solid var(--border);
  padding-left: 10px;
  max-height: 200px;
  overflow-y: auto;
}

.lb-story-badge {
  display: inline-block;
  background: linear-gradient(135deg, #f09433, #e6683c, #dc2743, #cc2366);
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  color: #fff;
  text-transform: uppercase;
  vertical-align: middle;
  margin-left: 6px;
}

.post-thumb-wrap {
  position: relative;
}

/* --- Pagination --- */
.pagination {
  padding: 16px 24px 32px;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.page-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}

.page-btn:hover { background: var(--surface2); }
.page-btn.active { background: var(--surface2); color: var(--accent); border-color: var(--accent); }
.page-btn:disabled { opacity: 0.3; cursor: default; }

.page-info {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0 8px;
}

/* --- Lightbox --- */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.lightbox.open { display: flex; }

.lightbox-media {
  max-width: 80vw;
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-media img, .lightbox-media video {
  max-width: 80vw;
  max-height: 80vh;
  border-radius: 6px;
  object-fit: contain;
}

.lightbox-info {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  padding: 32px 24px 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
  max-height: 40vh;
  overflow-y: auto;
}

.lightbox-info .lb-username { color: var(--accent); font-weight: 600; font-size: 0.9rem; }
.lightbox-info .lb-date { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 6px; }
.lightbox-info .lb-caption { color: var(--text); font-size: 0.85rem; line-height: 1.6; white-space: pre-wrap; }
.lightbox-info .lb-counter { color: var(--text-muted); font-size: 0.78rem; margin-bottom: 4px; }

.lb-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.lb-copy-link-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.lb-copy-link-btn:hover {
  background: var(--border);
  color: var(--text);
}

.lightbox-close, .lightbox-prev, .lightbox-next {
  position: fixed;
  background: rgba(0,0,0,0.5);
  border: none;
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}

.lightbox-close:hover, .lightbox-prev:hover, .lightbox-next:hover {
  background: rgba(255,255,255,0.15);
}

.lightbox-close { top: 16px; right: 16px; font-size: 1rem; }
.lightbox-prev { left: 16px; top: 50%; transform: translateY(-50%); font-size: 1.5rem; }
.lightbox-next { right: 16px; top: 50%; transform: translateY(-50%); font-size: 1.5rem; }

.lightbox-prev:disabled, .lightbox-next:disabled { opacity: 0.2; cursor: default; }

/* --- Person header (name editor) --- */
.person-header {
  padding: 16px 24px 0;
}

.person-header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.person-header-name {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
}

.person-edit-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.person-edit-btn:hover {
  background: var(--border);
  color: var(--text);
}

.person-name-input {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  padding: 5px 10px;
  outline: none;
  min-width: 220px;
}

.person-save-btn {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.person-save-btn:hover { opacity: 0.85; }
.person-save-btn:disabled { opacity: 0.4; cursor: default; }

.person-cancel-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 5px 6px;
}

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

/* --- People grid --- */
.people-card .post-thumb {
  object-position: center top;
}

/* --- Lightbox bottom row (analysis + faces side by side) --- */
.lb-bottom-row {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.lb-analysis {
  flex: 1;
  min-height: 24px;
}

.lb-faces {
  width: 160px;
  flex-shrink: 0;
}

.lb-faces-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.lb-face-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
  text-align: left;
}

.lb-face-btn:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.lb-face-crop {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
}

.lb-face-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-muted);
}

.lb-face-label {
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- States --- */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 80px 0;
  font-size: 0.9rem;
}

.loading {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 80px 0;
}
