/*
 * CursorPilot admin console.
 *
 * Hand-written CSS with no build step, deliberately. The dashboard is a few
 * hundred lines of markup that changes rarely; a toolchain here would mean a
 * node_modules, a lockfile and a build stage in the deploy for no gain, and
 * nginx can serve these three files exactly as they are.
 *
 * The palette is taken from the extension so the two surfaces read as one
 * product — the same terracotta accent, the same neutral greys.
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --text: #1a1c1e;
  --muted: #6b7280;
  --accent: #c9633f;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --ok: #1e7f43;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --sidebar: 248px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #16181b;
    --surface: #1d2024;
    --surface-2: #22262b;
    --border: #2f343a;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }

/*
 * `[hidden]` is only a UA rule of `display: none`, which any class that sets
 * `display` outranks — and nearly every layout container here sets one. The
 * result is worse than a cosmetic slip: the boot overlay is `position: fixed;
 * inset: 0`, so while "hidden" it still covered the page and swallowed every
 * click on the sign-in button, with nothing on screen to explain why.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.cp-sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ boot */

.cp-boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.cp-boot__spinner {
  width: 26px; height: 26px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .cp-boot__spinner { animation-duration: 2s; }
}

/* --------------------------------------------------------------- controls */

.cp-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.cp-btn:hover { background: var(--surface-2); }
.cp-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cp-btn:disabled { opacity: .55; cursor: default; }

.cp-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.cp-btn--primary:hover { filter: brightness(1.06); background: var(--accent); }

.cp-btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.cp-btn--danger:hover { filter: brightness(1.08); background: var(--danger); }

.cp-btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.cp-btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.cp-field { display: block; margin-bottom: 14px; }
.cp-field__label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.cp-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.cp-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(201 99 63 / 18%);
}

.cp-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 14px;
}

.cp-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0; }
.cp-error:empty { min-height: 0; margin: 0; }

/* ---------------------------------------------------------------- sign in */

.cp-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.cp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.cp-login__card { width: 100%; max-width: 400px; }
.cp-login__logo { display: block; margin: 0 auto 24px; max-width: 180px; height: auto; }
.cp-login__title { font-size: 19px; margin: 0 0 6px; text-align: center; }
.cp-login__body {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin: 0 0 24px;
}

.cp-turnstile { margin: 4px 0 12px; min-height: 68px; }
.cp-turnstile iframe { display: block; width: 100%; height: 68px; border: 0; }

.cp-login__card .cp-btn { width: 100%; }

/* ----------------------------------------------------------------- shell */

.cp-shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.cp-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

/* The wordmark is 7:1; forcing it into a square box renders it as a smear.
   The sidebar uses the square icon and the login screen uses the wordmark. */
.cp-sidebar__brand img { border-radius: 6px; flex: 0 0 auto; }

.cp-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  padding: 0 8px;
}

.cp-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.cp-nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
}
.cp-nav__item:hover { background: var(--surface-2); color: var(--text); }
.cp-nav__item[aria-current='page'] { background: var(--surface-2); color: var(--text); }
.cp-nav__item[aria-current='page'] .cp-nav__dot { background: var(--accent); }

.cp-nav__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex: 0 0 auto;
}

.cp-sidebar__foot { border-top: 1px solid var(--border); padding-top: 14px; }
.cp-who { padding: 0 8px 10px; }
.cp-who__name { font-size: 13px; font-weight: 600; }
.cp-who__email { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.cp-sidebar__foot .cp-btn { width: 100%; }

.cp-main { padding: 32px; min-width: 0; }

.cp-page__head { margin-bottom: 24px; }
.cp-page__head h1 { font-size: 22px; margin: 0 0 4px; }
.cp-page__head p { margin: 0; color: var(--muted); font-size: 14px; }

/* ----------------------------------------------------------------- stats */

.cp-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--gap);
}

.cp-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.cp-stat__value { font-size: 27px; font-weight: 650; line-height: 1.1; }
.cp-stat__label { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ----------------------------------------------------------------- table */

.cp-toolbar { display: flex; gap: 10px; margin-bottom: var(--gap); }

.cp-search {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.cp-search:focus { outline: none; border-color: var(--accent); }

.cp-tablewrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Narrow screens scroll the table, never the page. */
  overflow-x: auto;
}

.cp-table { width: 100%; border-collapse: collapse; font-size: 14px; }

.cp-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.cp-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cp-table tr:last-child td { border-bottom: 0; }
.cp-table tbody tr:hover { background: var(--surface-2); }

.cp-user__name { font-weight: 550; }
.cp-user__email { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }

.cp-tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.cp-tag--ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.cp-tag--warn { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.cp-tag--admin { color: var(--text); border-color: var(--text); }
.cp-tag--off { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

.cp-rowactions { display: flex; gap: 4px; justify-content: flex-end; }

.cp-empty { padding: 32px; text-align: center; color: var(--muted); }

.cp-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: var(--gap);
  font-size: 13px;
  color: var(--muted);
}

/* --------------------------------------------------------------- dialogs */

.cp-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 28px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.cp-dialog::backdrop { background: rgb(16 24 40 / 45%); }
.cp-dialog h2 { margin: 0 0 6px; font-size: 18px; }
.cp-dialog__body { margin: 0 0 20px; font-size: 13.5px; color: var(--muted); }
.cp-dialog__warn {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.cp-dialog__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* ---------------------------------------------------------------- toasts */

.cp-toasts {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.cp-toast {
  background: #16181b;
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: rise 160ms ease-out;
}
.cp-toast--error { background: var(--danger); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ----------------------------------------------------------- small screens */

@media (max-width: 720px) {
  .cp-shell { grid-template-columns: 1fr; }
  .cp-sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px;
  }
  .cp-nav { flex-direction: row; flex: 1; }
  .cp-sidebar__foot { border-top: 0; padding-top: 0; }
  .cp-who { display: none; }
  .cp-main { padding: 20px 16px; }
}
