/* ============================================================
   CAA Content Assessment Tool — Shared Styles
   ============================================================ */

:root {
  --c-bg: #f4f5f7;
  --c-surface: #ffffff;
  --c-surface-2: #f8f9fa;
  --c-border: #d1d5db;
  --c-border-light: #e5e7eb;
  --c-text: #111827;
  --c-text-muted: #6b7280;
  --c-text-inverse: #ffffff;
  --c-primary: #1b4f8a;
  --c-primary-hover: #163f6e;
  --c-primary-light: #dbeafe;
  --c-accent: #b91c1c;
  --c-success: #15803d;
  --c-success-bg: #dcfce7;
  --c-warning: #b45309;
  --c-warning-bg: #fef3c7;
  --c-error: #dc2626;
  --c-error-bg: #fee2e2;
  --c-shadow: rgba(0, 0, 0, 0.08);
  --c-compliance: #5b67c9;
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --header-h: 60px;
  --max-w: 900px;
}

[data-theme="dark"] {
  --c-bg: #0f1117;
  --c-surface: #1a1d27;
  --c-surface-2: #22263a;
  --c-border: #30364a;
  --c-border-light: #252938;
  --c-text: #e8ecf4;
  --c-text-muted: #8a93a8;
  --c-primary: #4a90d9;
  --c-primary-hover: #5ba3eb;
  --c-primary-light: #1e3a5f;
  --c-accent: #e05252;
  --c-success: #4ade80;
  --c-success-bg: #052e16;
  --c-warning: #fbbf24;
  --c-warning-bg: #1c1103;
  --c-error: #f87171;
  --c-error-bg: #1e0505;
  --c-shadow: rgba(0, 0, 0, 0.3);
  --c-compliance: #818cf8;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

/* ── Header ─────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--c-surface);
  border-top: 3px solid var(--c-primary);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  box-shadow: 0 1px 4px var(--c-shadow);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  flex-shrink: 0;
}

.header-logo-img {
  height: 34px;
  width: auto;
  flex-shrink: 0;
  display: block;
}

[data-theme="dark"] .header-logo-img {
  filter: invert(1);
}

.header-org {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--c-text);
}

.header-title {
  flex: 1;
  text-align: center;
  font-size: 0.8rem;
  color: var(--c-text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--c-text-muted);
}

.header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--c-border);
  object-fit: cover;
}

.header-avatar-fallback {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.btn-signout {
  font-size: 0.82rem;
  color: var(--c-text-muted);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-signout:hover {
  border-color: var(--c-accent);
  color: var(--c-accent);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text-muted);
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}

.theme-toggle:hover {
  border-color: var(--c-primary);
}

/* ── Layout ─────────────────────────────────────────────── */

.page-main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: 0 1px 4px var(--c-shadow);
}

.card + .card {
  margin-top: 1.25rem;
}

/* ── Form elements ──────────────────────────────────────── */

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--c-text);
  margin-bottom: 0.35rem;
}

textarea,
input[type="text"],
input[type="url"],
input[type="email"] {
  width: 100%;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  color: var(--c-text);
  font-family: inherit;
  font-size: 0.925rem;
  padding: 0.65rem 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

textarea:focus,
input[type="text"]:focus,
input[type="url"]:focus,
input[type="email"]:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(27, 79, 138, 0.12);
}

textarea {
  min-height: 250px;
  resize: vertical;
  line-height: 1.6;
}

.field + .field {
  margin-top: 1rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--c-primary);
}

.checkbox-label {
  font-size: 0.9rem;
  color: var(--c-text);
  cursor: pointer;
  user-select: none;
}

.conditional-field {
  margin-top: 0.75rem;
  padding-left: 1.5rem;
  border-left: 2px solid var(--c-primary-light);
}

/* ── Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.925rem;
  font-weight: 500;
  padding: 0.65rem 1.25rem;
  min-height: 44px;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--c-primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--c-primary-hover);
  box-shadow: 0 2px 6px var(--c-shadow);
}

.btn-secondary {
  background: var(--c-surface-2);
  color: var(--c-text);
  border: 1px solid var(--c-border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--c-primary);
}

.btn-danger {
  background: var(--c-error-bg);
  color: var(--c-error);
  border: 1px solid var(--c-error);
}

.btn-danger:hover:not(:disabled) {
  background: var(--c-error);
  color: #fff;
}

.btn-full {
  width: 100%;
}

/* ── Drop zone & file previews ──────────────────────────── */

.drop-zone {
  border: 2px dashed var(--c-border-light);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  text-align: center;
  color: var(--c-text-muted);
  font-size: 0.875rem;
  background: var(--c-surface-2);
  transition: border-color 0.15s, background 0.15s;
  cursor: default;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.drop-zone.drag-over {
  border-color: var(--c-primary);
  background: var(--c-primary-light);
}

.drop-zone-icon {
  color: var(--c-primary);
  opacity: 0.6;
}

.preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.preview-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
}

.preview-pdf {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--c-error);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Spinner ────────────────────────────────────────────── */

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.loading-message {
  text-align: center;
  color: var(--c-text-muted);
  font-size: 0.9rem;
  padding: 1rem;
}

/* ── Intro card ─────────────────────────────────────────── */

.card-intro {
  border-left: 4px solid var(--c-primary);
  background: var(--c-primary-light);
}

[data-theme="dark"] .card-intro {
  background: var(--c-surface);
}

/* ── Output panel ───────────────────────────────────────── */

.output-panel {
  display: none;
}

.output-panel.visible {
  display: block;
}

.output-section {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border-light);
  border-left: 4px solid var(--c-primary);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}

.output-section:last-child {
  margin-bottom: 0;
}

.output-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-primary);
  margin-bottom: 0.6rem;
}

.post-url-meta {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  font-size: 0.78rem;
  color: var(--c-text-muted);
  margin-bottom: 0.6rem;
  word-break: break-all;
}

.post-url-meta a {
  color: var(--c-primary);
  text-decoration: none;
}

.post-url-meta a:hover {
  text-decoration: underline;
}

.output-section-title-post {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--c-primary);
  margin-bottom: 0;
  flex: 1;
  line-height: 1.4;
}

.output-section-body {
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  font-size: 1rem;
  line-height: 1.8;
  color: var(--c-text);
}

.output-section-body .md-h3 {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1.1rem 0 0.4rem;
  color: var(--c-primary);
}

.output-section-body .md-h3:first-child {
  margin-top: 0.2rem;
}

.output-section-body .md-h4 {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0.85rem 0 0.25rem;
  color: var(--c-text);
}

.output-section-body .md-p {
  margin: 0 0 0.6rem;
}

.output-section-body .md-p:last-child {
  margin-bottom: 0;
}

.output-section-body .md-ul,
.output-section-body .md-ol {
  margin: 0.25rem 0 0.6rem 1.35rem;
  padding: 0;
}

.output-section-body .md-ul li,
.output-section-body .md-ol li {
  margin-bottom: 0.25rem;
}

.output-section-body .md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin: 0.5rem 0 0.75rem;
}

.output-section-body .md-table th,
.output-section-body .md-table td {
  text-align: left;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--c-border-light);
  vertical-align: top;
}

.output-section-body .md-table th {
  background: var(--c-surface-2);
  font-weight: 600;
  font-size: 0.8rem;
}

.output-section.section-overall {
  border-left-color: var(--c-accent);
  background: var(--c-surface);
  padding: 1.35rem 1.5rem;
}

.output-section.section-overall .output-section-title {
  color: var(--c-accent);
}

.output-section.accordion-section {
  transition: box-shadow 0.15s ease;
}

.output-section.accordion-section:hover {
  box-shadow: 0 2px 10px var(--c-shadow);
}

.output-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

/* ── Error / notice banners ─────────────────────────────── */

.notice {
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.notice-error {
  background: var(--c-error-bg);
  color: var(--c-error);
  border: 1px solid var(--c-error);
}

.notice-success {
  background: var(--c-success-bg);
  color: var(--c-success);
  border: 1px solid var(--c-success);
}

.notice-warning {
  background: var(--c-warning-bg);
  color: var(--c-warning);
  border: 1px solid var(--c-warning);
}

/* ── Admin: document table ──────────────────────────────── */

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.doc-table th,
.doc-table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--c-border-light);
  vertical-align: middle;
}

.doc-table th {
  font-weight: 600;
  color: var(--c-text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--c-surface-2);
}

.doc-table tr:last-child td {
  border-bottom: none;
}

.doc-table .action-cell {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

/* ── Prompt viewer ──────────────────────────────────────── */

.prompt-display {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.85rem;
  font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--c-text-muted);
  max-height: 280px;
  overflow-y: auto;
}

/* ── Upload zone ────────────────────────────────────────── */

.upload-zone {
  border: 2px dashed var(--c-border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--c-primary);
  background: var(--c-primary-light);
}

.upload-zone input[type="file"] {
  display: none;
}

/* ── Section headings ───────────────────────────────────── */

.section-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--c-border-light);
}

.config-row {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.config-label {
  font-weight: 600;
  min-width: 140px;
  color: var(--c-text-muted);
  font-size: 0.8rem;
}

.config-value {
  color: var(--c-text);
  font-family: "SF Mono", Menlo, monospace;
  word-break: break-all;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-admin {
  background: var(--c-warning-bg);
  color: var(--c-warning);
  border: 1px solid var(--c-warning);
}

/* ── Login page ─────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-bg);
  padding: 2rem 1rem;
}

.login-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 24px var(--c-shadow);
  text-align: center;
}

.login-logo-img {
  height: 64px;
  width: auto;
  display: block;
  margin: 0 auto 1rem;
}

[data-theme="dark"] .login-logo-img {
  filter: invert(1);
}

.login-org {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--c-text-muted);
  margin-bottom: 2rem;
}

.google-signin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
  min-height: 48px;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.google-signin-btn:hover {
  box-shadow: 0 2px 8px var(--c-shadow);
  border-color: var(--c-primary);
}

.google-logo {
  flex-shrink: 0;
}

.login-note {
  font-size: 0.78rem;
  color: var(--c-text-muted);
  margin-top: 1.5rem;
  line-height: 1.5;
}

.login-theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  font-size: 1rem;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Accordion ──────────────────────────────────────────── */

.accordion-section .accordion-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
}

.accordion-section .accordion-header .output-section-title {
  margin-bottom: 0;
  flex: 1;
}

.accordion-arrow {
  display: inline-block;
  color: var(--c-text-muted);
  font-size: 0.7rem;
  line-height: 1;
  transition: transform 0.18s ease;
  flex-shrink: 0;
}

.accordion-section.collapsed .accordion-arrow {
  transform: rotate(-90deg);
}

.accordion-body {
  position: relative;
  padding-top: 0.65rem;
  transition: max-height 0.2s ease;
}

.accordion-section.collapsed .accordion-body {
  max-height: 7.2rem;
  overflow: hidden;
  cursor: pointer;
}

.accordion-section.collapsed .accordion-body::after {
  content: 'Show more ▾';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1.6rem;
  background: var(--c-border-light);
  display: block;
  text-align: center;
  line-height: 1.6rem;
  font-size: 0.68rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}

.accordion-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.btn-text {
  background: none;
  border: none;
  color: var(--c-text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-text:hover {
  color: var(--c-primary);
}

/* ── Results group labels ────────────────────────────────── */

.output-actions-item {
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
}

.results-group-label {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-text-muted);
  margin: 1rem 0 0.75rem;
}

.results-group-label::before,
.results-group-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--c-border-light);
}

.results-group-label-case {
  margin-top: 1.25rem;
}

/* ── Recommended Actions section ─────────────────────────── */

.output-section-actions {
  border-left-color: var(--c-success);
}

.output-section-actions .output-section-title,
.output-section-actions .accordion-header .output-section-title {
  color: var(--c-success);
}

/* ── LIA / Compliance section ───────────────────────────── */

.compliance-divider {
  height: 1px;
  background: var(--c-border-light);
  margin: 0.5rem 0 0.75rem;
}

.output-section-lia {
  border-left-color: var(--c-compliance);
  background: var(--c-surface);
}

.output-section-lia .output-section-title,
.output-section-lia .accordion-header .output-section-title {
  color: var(--c-compliance);
}

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 640px) {
  .header-title {
    display: none;
  }

  .header-user-name {
    display: none;
  }

  .page-main {
    padding: 1rem 0.75rem 2.5rem;
  }

  .card {
    padding: 1.1rem;
  }

  .output-actions {
    flex-direction: column;
  }

  .output-actions .btn {
    width: 100%;
  }

  .doc-table th:nth-child(2),
  .doc-table td:nth-child(2) {
    display: none;
  }
}

@media (max-width: 400px) {
  .login-card {
    padding: 1.75rem 1.25rem;
  }
}
