/* ── Theme tokens ───────────────────────────────────────────── */
:root {
  --bg: #f1f5f9;            /* page background */
  --surface: #ffffff;       /* cards, sidebar */
  --surface-2: #f8fafc;     /* subtle fills */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --brand: #6366f1;
  --brand-hover: #4f46e5;
  --brand-tint: #eef2ff;    /* active nav / soft accents */
  --code-bg: #0f172a;       /* code blocks stay dark for readability */
  --code-text: #e2e8f0;
  --danger: #dc2626;
  --ok: #059669;
}

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

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

/* ── Login ──────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo h1 { font-size: 1.8rem; margin: 0.4rem 0 0.2rem; }
.login-logo p  { color: var(--text-muted); font-size: 0.9rem; }

.logo-icon { display: inline-flex; }
.logo-icon svg { display: block; }

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.35rem; }

input, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--brand);
  border-color: transparent;
}

button {
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  width: 100%;
}

button:hover { background: var(--brand-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-bottom: 0.75rem; padding: 0.5rem; background: #fef2f2; border-radius: 6px; }
.hidden { display: none; }

.btn-primary {
  background-color: var(--brand);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
}
.btn-primary:hover { background-color: var(--brand-hover); }

.btn-secondary {
  background-color: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
}
.btn-secondary:hover { background-color: var(--surface-2); color: var(--text); }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.form-group input, .form-group select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tab-btn {
  padding: 0.75rem 1.5rem;
  background: none; border: none;
  color: var(--text-muted); cursor: pointer; font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── App shell ──────────────────────────────────────── */
.app-layout { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.app-layout.hidden { display: none; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 1rem 1.2rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.nav-links { list-style: none; flex: 1; }
.nav-links a {
  display: block;
  padding: 0.65rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  margin: 0 0.5rem;
  font-size: 0.9rem;
}
.nav-links a:hover { background: var(--surface-2); color: var(--text); }
.nav-links a.active { background: var(--brand-tint); color: var(--brand-hover); font-weight: 600; }

.sidebar-user { border-top: 1px solid var(--border); padding: 1rem; font-size: 0.85rem; }
.user-name { font-weight: 600; }
.user-email { color: var(--text-muted); margin-bottom: 0.6rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-user button {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  width: auto;
}
.sidebar-user button:hover { background: var(--surface-2); color: var(--text); }

.main-content { overflow-y: auto; padding: 2rem; }
.page { display: none; }
.page.active { display: block; }
.page h2 { margin-bottom: 1.25rem; font-size: 1.4rem; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; gap: 1rem; }
.page-header button { width: auto; padding: 0.5rem 1rem; font-size: 0.85rem; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card h3 { margin-bottom: 1rem; font-size: 1rem; }

/* Stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th { text-align: left; padding: 0.6rem; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 600; }
.data-table td { padding: 0.6rem; border-bottom: 1px solid var(--border); }

/* Badges */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
.badge-owner  { background: #e0e7ff; color: #3730a3; }
.badge-admin  { background: #cffafe; color: #155e75; }
.badge-editor { background: #d1fae5; color: #065f46; }
.badge-viewer { background: #e2e8f0; color: #334155; }
.badge-queued { background: #e2e8f0; color: #475569; }
.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-low { background: #e2e8f0; color: #475569; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fee2e2; color: #991b1b; }

.form-inline { display: flex; gap: 1rem; align-items: center; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }
.muted { color: var(--text-muted); font-size: 0.9rem; }

/* ── Modal ─────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 2rem;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); color: var(--text);
  border-radius: 12px;
  width: 100%; max-width: 760px; max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; }
.modal-close {
  background: none; border: none; font-size: 1.6rem; line-height: 1;
  cursor: pointer; color: var(--text-muted); padding: 0 0.25rem; width: auto;
}
.modal-close:hover { color: var(--text); background: none; }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-body h4 { margin: 1.5rem 0 0.5rem; }

.score-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.score-pill {
  border-radius: 10px; padding: 0.6rem 1rem; min-width: 90px;
  display: flex; flex-direction: column; align-items: center;
}
.score-pill .score-value { font-size: 1.4rem; font-weight: 700; }
.score-pill .score-label { font-size: 0.75rem; opacity: 0.85; }
.score-good { background: #d1fae5; color: #065f46; }
.score-mid  { background: #fef3c7; color: #92400e; }
.score-bad  { background: #fee2e2; color: #991b1b; }

.report-summary { font-size: 1rem; line-height: 1.5; color: var(--text); }
.report-error { color: #991b1b; background: #fee2e2; padding: 0.75rem 1rem; border-radius: 8px; }

.check-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.check-list li { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.45rem 0.25rem; border-bottom: 1px solid var(--border); }
.check-list small { color: var(--text-muted); }
.check-list strong { color: var(--text); }
.check-icon { flex-shrink: 0; }

.rec-list { padding-left: 1.25rem; color: var(--text); }
.rec-list li { margin-bottom: 0.75rem; line-height: 1.45; }
.rec-list small { color: #475569; }
.badge-effort { background: #e0e7ff; color: #3730a3; margin-left: 0.5rem; }

.mention-yes { color: var(--ok); font-weight: 700; }
.mention-no  { color: var(--danger); font-weight: 700; }
.detail-cell { max-width: 380px; }
.detail-cell details summary { cursor: pointer; }

/* Fixes & code blocks */
.fixes-section { margin: 1rem 0; }
.fix-card { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem; margin-bottom: 0.75rem; background: var(--surface); }
.fix-head { display: flex; justify-content: space-between; align-items: center; color: var(--text); }
.fix-code { background: var(--code-bg); color: var(--code-text); padding: 0.75rem; border-radius: 6px; font-size: 0.8rem; overflow-x: auto; white-space: pre; }

.schedule-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; cursor: pointer; color: var(--text-muted); }

.badge-engine { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.rank-pos { font-weight: 700; }
.rank-top { color: var(--ok); }
.rank-mid { color: #b45309; }
.rank-none { color: var(--danger); font-size: 0.85rem; }

.bar-wrap { display: flex; align-items: center; gap: 0.5rem; }
.bar { height: 14px; background: var(--brand); border-radius: 3px; min-width: 2px; }
.bar-wrap span { font-size: 0.8rem; color: var(--text-muted); }

/* ── Trends & report ────────────────────────────────────────── */
.trend-chart { width: 100%; max-width: 480px; height: auto; margin: 0.5rem 0 1rem; }
.report-doc { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem; }
.report-letterhead { border-bottom: 2px solid var(--brand); margin-bottom: 1rem; padding-bottom: 0.5rem; }
.report-letterhead h2 { margin: 0; }

@media print {
  body { background: #fff !important; }
  .sidebar, .no-print, .page-header .header-actions { display: none !important; }
  .app-layout { display: block !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .page { display: none !important; }
  .page#page-reports { display: block !important; }
  .report-doc { background: #fff !important; box-shadow: none; border: none; }
  .trend-chart text { fill: #475569 !important; }
  .score-pill { border: 1px solid var(--border-strong); }
}

/* ── Legal pages (privacy / terms) ──────────────────────────── */
.legal-page { max-width: 820px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.legal-header { display: flex; align-items: center; gap: 0.6rem; padding: 1rem 0 1.5rem; border-bottom: 1px solid var(--border); margin-bottom: 2rem; }
.legal-header .logo-icon svg { display: block; }
.legal-header h1 { font-size: 1.4rem; margin: 0; }
.legal-content h2 { font-size: 1.1rem; margin: 1.8rem 0 0.6rem; }
.legal-content p, .legal-content li { line-height: 1.6; color: #1e293b; }
.legal-content ul { padding-left: 1.4rem; margin: 0.5rem 0; }
.legal-content a { color: var(--brand-hover); }
.legal-meta { color: var(--text-muted); font-size: 0.9rem; }
.legal-back { display: inline-block; margin-bottom: 1.5rem; color: var(--brand-hover); text-decoration: none; }
.legal-placeholder { background: #fef3c7; color: #92400e; padding: 0 0.25rem; border-radius: 3px; font-style: italic; }
