/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fafaf9;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e5e4;
  --border-light: #f0eeec;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --highlight: #fef9c3;
  --highlight-hover: #fef08a;
  --highlight-active: #fde047;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info-bg: #dbeafe;
  --font-body: Georgia, 'Times New Roman', serif;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --max-prose: 720px;
  --sidebar-w: 300px;
}

html { font-size: 16px; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top Bar ─────────────────────────────────────────────── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.top-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  gap: 16px;
}
.logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.3px;
}
.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-info {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.user-info a { color: var(--text-muted); }
.user-info a:hover { color: var(--text); }

/* ── Login Page ──────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}
.login-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}
.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  margin-top: 16px;
  color: var(--text);
}
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: var(--font-ui);
  background: var(--bg);
  transition: border-color 0.15s;
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.login-card button {
  width: 100%;
  margin-top: 24px;
  padding: 11px;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.15s;
}
.login-card button:hover { background: #333; }

/* ── Index Page ──────────────────────────────────────────── */
.index-main {
  max-width: 640px;
  margin: 48px auto;
  padding: 0 24px;
}
.index-main h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 32px;
  letter-spacing: -0.5px;
}
.pilot-section { margin-bottom: 32px; }
.pilot-section h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}
.pilot-section ul { list-style: none; }
.pilot-section li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pilot-section li:last-child { border-bottom: none; }
.pilot-section a {
  font-size: 15px;
  font-weight: 500;
}
.comment-count {
  background: var(--info-bg);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Admin badge */
.admin-badge {
  background: var(--text);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 4px;
  vertical-align: middle;
}

/* Deliverable row (admin view) */
.deliverable-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.row-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Status badges */
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.status-badge.status-published { background: var(--success-bg); color: var(--success); }
.status-badge.status-draft { background: #f3f4f6; color: var(--text-muted); }
.status-badge.status-archived { background: var(--danger-bg); color: var(--danger); }

/* Status toggle buttons (admin) */
.status-controls {
  display: inline-flex;
  gap: 2px;
  margin-left: 4px;
}
.status-btn {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-light);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s;
  font-family: var(--font-ui);
  line-height: 1;
}
.status-btn:hover { border-color: var(--text-muted); color: var(--text); }
.status-btn.active[data-status="published"] {
  background: var(--success-bg);
  border-color: #bbf7d0;
  color: var(--success);
}
.status-btn.active[data-status="draft"] {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: var(--text-muted);
}
.status-btn.active[data-status="archived"] {
  background: var(--danger-bg);
  border-color: #fecaca;
  color: var(--danger);
}

/* ── Review Layout ───────────────────────────────────────── */
.review-layout {
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 40px 24px 80px;
  max-width: 1140px;
  margin: 0 auto;
}

/* ── Prose (article) ─────────────────────────────────────── */
.prose {
  max-width: var(--max-prose);
  width: 100%;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.75;
  color: var(--text);
}
.prose h1 {
  font-family: var(--font-ui);
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 8px;
  line-height: 1.3;
  letter-spacing: -0.5px;
}
.prose h2 {
  font-family: var(--font-ui);
  font-size: 21px;
  font-weight: 700;
  margin: 40px 0 12px;
  line-height: 1.3;
  letter-spacing: -0.3px;
  padding-top: 20px;
  border-top: 1px solid var(--border-light);
}
.prose h3 {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 600;
  margin: 28px 0 8px;
  line-height: 1.4;
}
.prose h4 {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  margin: 20px 0 6px;
}
.prose p { margin: 0 0 16px; }
.prose strong { font-weight: 700; }
.prose em { font-style: italic; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 24px; }
.prose li { margin-bottom: 6px; }
.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* Tables */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prose thead { border-bottom: 2px solid var(--border); }
.prose th {
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  background: var(--bg);
  white-space: nowrap;
}
.prose td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
.prose tbody tr:hover { background: #f9f8f6; }

/* Code */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: #f3f3f2;
  padding: 2px 5px;
  border-radius: 4px;
}
.prose pre {
  background: #f4f4f3;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px 20px;
  overflow-x: auto;
  margin: 16px 0 24px;
  line-height: 1.5;
}
.prose pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

/* ── Comment highlights ──────────────────────────────────── */
mark.commented {
  background: var(--highlight);
  border-bottom: 2px solid #facc15;
  padding: 1px 0;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.15s;
}
mark.commented:hover {
  background: var(--highlight-hover);
}
mark.commented.active {
  background: var(--highlight-active);
}

/* ── Comments Sidebar ────────────────────────────────────── */
.comments-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 68px;
  max-height: calc(100vh - 84px);
  overflow-y: auto;
  align-self: flex-start;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sidebar-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.comment-total {
  background: var(--info-bg);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}
.sidebar-empty {
  color: var(--text-light);
  font-size: 13px;
  padding: 16px 0;
}

/* Sidebar card */
.comment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-size: 13px;
}
.comment-card:hover {
  border-color: #d4d4d3;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.comment-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.12);
}
.comment-excerpt {
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.comment-text {
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.45;
}
.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-light);
}
.comment-status {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.comment-status.submitted { background: var(--info-bg); color: var(--accent); }
.comment-status.approved { background: var(--success-bg); color: var(--success); }
.comment-status.rejected { background: var(--danger-bg); color: var(--danger); }

.comment-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.comment-actions button {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.15s;
}
.comment-actions .btn-approve {
  color: var(--success);
  border-color: #bbf7d0;
}
.comment-actions .btn-approve:hover {
  background: var(--success-bg);
}
.comment-actions .btn-reject {
  color: var(--danger);
  border-color: #fecaca;
}
.comment-actions .btn-reject:hover {
  background: var(--danger-bg);
}

/* ── Comment Popover ─────────────────────────────────────── */
.comment-popover {
  position: fixed;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.04);
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 16px;
}
.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.popover-title {
  font-size: 14px;
  font-weight: 600;
}
.popover-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-light);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.popover-close:hover { color: var(--text); }
.popover-selection {
  background: var(--highlight);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font-body);
  color: var(--text);
  margin-bottom: 10px;
  max-height: 80px;
  overflow-y: auto;
  line-height: 1.45;
}
.comment-popover textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-ui);
  resize: vertical;
  min-height: 60px;
  background: var(--bg);
  transition: border-color 0.15s;
}
.comment-popover textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.popover-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}

/* Buttons */
.btn {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary {
  background: var(--text);
  color: #fff;
}
.btn-primary:hover { background: #333; }
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-ghost {
  background: none;
  color: var(--text-muted);
  padding: 8px 12px;
}
.btn-ghost:hover { color: var(--text); }

/* ── Selection tooltip (the initial "Comment" button) ────── */
.selection-tooltip {
  position: fixed;
  z-index: 150;
  background: var(--text);
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transition: opacity 0.15s, transform 0.15s;
  user-select: none;
}
.selection-tooltip:hover {
  background: #333;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1099px) {
  .comments-sidebar {
    display: none;
  }
  .review-layout {
    justify-content: center;
  }
}
@media (max-width: 767px) {
  .top-bar { padding: 0 16px; }
  .top-bar-inner { height: 46px; }
  .breadcrumb { display: none; }
  .review-layout { padding: 24px 16px 60px; }
  .prose { font-size: 16px; }
  .prose h1 { font-size: 24px; }
  .prose h2 { font-size: 19px; }
  .comment-popover { width: calc(100vw - 32px); }
}

/* ── Print ───────────────────────────────────────────────── */
@media print {
  .top-bar, .comments-sidebar, .comment-popover, .selection-tooltip { display: none !important; }
  .prose { max-width: 100%; }
  mark.commented { background: none; border: none; }
}
