/* styles.css — one stylesheet for the whole app.
   Colors and spacing live in "CSS variables" (the --names below), so changing
   the brand color later means editing one line instead of fifty. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #101828;
  --muted: #667085;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --error-bg: #fef3f2;
  --error-text: #b42318;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* The HTML "hidden" attribute must always win, even over classes that set display. */
[hidden] { display: none !important; }

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

h1, h2, h3 { margin: 0; line-height: 1.25; }
code { background: #eef0f4; padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--muted); margin: 8px 0 0; }

/* ---------- Logo ---------- */
.logo {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none;
}
.logo-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--brand); color: #fff; font-size: 16px;
}

/* ---------- Buttons ---------- */
.button {
  display: inline-block; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; font: 600 14px var(--font);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.button:hover { background: var(--brand-dark); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-ghost { background: transparent; color: var(--brand); }
.button-ghost:hover { background: #eef2ff; }

/* ---------- Login / sign-up / home ---------- */
.auth-layout {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 32px 16px; text-align: center;
}
.auth-tagline { color: var(--muted); margin: 0 0 12px; max-width: 420px; }
.auth-box { min-height: 200px; display: flex; justify-content: center; align-items: flex-start; }
.loading-text { color: var(--muted); }
.home-title { font-size: clamp(28px, 5vw, 44px); max-width: 680px; margin-top: 16px; }
.home-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.notice { padding: 14px 16px; border-radius: 8px; max-width: 460px; text-align: left; }
.notice-error { background: var(--error-bg); color: var(--error-text); }

/* ---------- Dashboard shell ---------- */
/* Hide the dashboard until dashboard.js confirms someone is signed in. */
.is-loading .app-shell { visibility: hidden; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0; padding: 20px 16px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 28px; }
.nav-link {
  padding: 8px 12px; border-radius: 8px; color: var(--text);
  text-decoration: none; font-size: 14px; font-weight: 500;
}
.nav-link:hover { background: var(--bg); }
.nav-link.is-active { background: #eef2ff; color: var(--brand); }
.nav-link.is-disabled { color: var(--muted); cursor: default; }
.nav-link.is-disabled:hover { background: none; }
.nav-link em { font-style: normal; font-size: 11px; margin-left: 6px; padding: 1px 6px; border-radius: 99px; background: var(--bg); }

.app-main { flex: 1; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* "Create your workspace" screen (shown until the user has an organization) */
.workspace-setup { max-width: 640px; }
.workspace-setup h2 { font-size: 18px; }
.workspace-setup-box { margin-top: 16px; }

.content { padding: 28px 32px; display: flex; flex-direction: column; gap: 20px; max-width: 1200px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card h3 { font-size: 15px; }

.empty-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  background: linear-gradient(135deg, #eef2ff, #ffffff);
}
.empty-banner h2 { font-size: 17px; }
.empty-banner p { margin: 6px 0 0; color: var(--muted); max-width: 560px; }

/* "Grid" lays the 4 number cards out in a row, wrapping on small screens. */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 28px; font-weight: 700; }

.chart-placeholder {
  margin-top: 16px; height: 260px; display: grid; place-items: center; text-align: center;
  border: 1px dashed var(--border); border-radius: 8px; color: var(--muted); padding: 16px;
}

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

/* ---------- Forms (Milestone 3) ---------- */
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 220px; font-size: 13px; font-weight: 500; }
.field input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font: 14px var(--font); color: var(--text); background: var(--surface);
}
.field input:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
.form-error { color: var(--error-text); background: var(--error-bg); padding: 10px 12px; border-radius: 8px; margin: 12px 0 0; font-size: 14px; }

.button-small { padding: 6px 12px; font-size: 13px; }
.button-danger { background: transparent; border-color: #fecdca; color: var(--error-text); }
.button-danger:hover { background: var(--error-bg); }

/* ---------- Site cards ---------- */
.section-title { font-size: 15px; margin-bottom: 12px; }
.sites-list { display: flex; flex-direction: column; gap: 12px; }
.site-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.site-domain { margin-top: 2px; }
.key-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 16px; padding: 10px 12px; background: var(--bg); border-radius: 8px;
}
.key-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.key-value { flex: 1 1 200px; background: none; padding: 0; font-size: 13px; overflow-wrap: anywhere; }
.site-note { font-size: 13px; }

/* ---------- Site status + setup (Milestone 4) ---------- */
.site-status { font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.site-status.is-live { color: #067647; font-weight: 600; }
.setup { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.setup summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--brand); }
.setup-steps { padding-left: 20px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.notice-warning { background: #fffaeb; color: #93370d; font-size: 13px; max-width: none; margin: 12px 0 0; }
.code-block {
  background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 14px 16px;
  font-size: 12px; line-height: 1.55; overflow-x: auto; max-height: 320px; margin: 12px 0;
}
.code-block code { background: none; padding: 0; font-size: inherit; }

/* ---------- Dashboard lists + table ---------- */
/* Top bots / Top pages: show about 4½ rows and scroll for the rest. The half row peeking
   out at the bottom hints that there's more (Mac hides scrollbars until you scroll). */
.rank-list {
  list-style: none; padding: 0 8px 0 0; margin: 12px 0 0; display: flex; flex-direction: column;
  max-height: 270px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #d0d5dd transparent; /* slim, light scrollbar */
}
.rank-list::-webkit-scrollbar { width: 6px; }
.rank-list::-webkit-scrollbar-thumb { background: #d0d5dd; border-radius: 99px; }
.rank-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.rank-list li:last-child { border-bottom: 0; }
.rank-list li > div { display: flex; flex-direction: column; min-width: 0; }
.rank-title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.rank-sub { font-size: 12px; color: var(--muted); }
.rank-count { font-weight: 700; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; margin-top: 12px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }

/* ---------- Filters, chart, verification (Milestone 5) ---------- */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; }
.toolbar-field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
/* The browser's own dropdown arrow sits right at the edge and ignores padding, so we
   hide it (appearance: none) and draw our own chevron as a small SVG background image,
   placed 12px in from the right. padding-right leaves room so text never overlaps it. */
.toolbar-field select {
  appearance: none; -webkit-appearance: none;
  padding: 8px 40px 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font: 14px var(--font); color: var(--text); cursor: pointer;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23667085' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
}
.toolbar-field select:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
/* Page filter box, styled like the dropdowns, with a × button to clear it */
.page-input-wrap { position: relative; display: inline-flex; }
.page-input-wrap input {
  width: 260px; padding: 8px 32px 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font: 14px var(--font); color: var(--text); background: var(--surface);
}
.page-input-wrap input:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
.page-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border: 0; border-radius: 99px; background: var(--bg);
  color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer;
}
.page-clear:hover { background: var(--border); color: var(--text); }
.rank-list li.is-clickable { cursor: pointer; border-radius: 6px; }
.rank-list li.is-clickable:hover .rank-title { color: var(--brand); }
.toolbar-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.toolbar-toggle input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.chart-caption { font-size: 13px; margin-top: 4px; }
.chart-box { position: relative; height: 280px; margin-top: 12px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; }
.chart-table { margin-top: 12px; }
.chart-table summary { cursor: pointer; font-size: 13px; color: var(--brand); font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge-good { background: #ecfdf3; color: #067647; }
.badge-bad { background: var(--error-bg); color: var(--error-text); }
.data-table tr.is-fake td { color: var(--muted); }

/* ---------- Settings (MCP) ---------- */
#mcp-regenerate-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.example-prompts { margin: 12px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text); }
.card .notice { max-width: none; }

/* ---------- Phones and small screens ---------- */
@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 14px 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; margin-top: 12px; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .empty-banner { flex-direction: column; align-items: flex-start; }
}
