/* ==========================================================================
   Plansquare Questionnaire — design tokens
   ========================================================================== */
:root {
  /* Brand (sampled from logo: diamond gradient #B21818→#E1232E, wordmark #4D4D4D) */
  --brand-50:  #FDECEC;
  --brand-100: #F9D2D3;
  --brand-500: #D8262E;
  --brand-600: #C41E25;
  --brand-700: #A3161C;
  --brand-800: #7F1015;
  --brand-grad: linear-gradient(135deg, #B21818 0%, #E1232E 100%);

  /* Neutrals */
  --n-0:   #FFFFFF;
  --n-50:  #F7F8FA;
  --n-100: #EFF1F4;
  --n-200: #E2E5EA;
  --n-300: #CBD0D8;
  --n-500: #7A828E;
  --n-700: #4D4D4D;
  --n-900: #1E2227;

  /* Semantic */
  --ok-bg: #ECFDF3;  --ok-fg: #12703E;  --ok-line: #A6E9C3;
  --err-bg: #FEF2F2; --err-fg: #B42318; --err-line: #F5B5B0;
  --warn-bg: #FFF8E6; --warn-fg: #8A5A00; --warn-line: #F7DC9A;

  /* Type */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs: .78rem; --fs-sm: .875rem; --fs-md: 1rem; --fs-lg: 1.125rem; --fs-xl: 1.375rem; --fs-2xl: 1.75rem;

  /* Spacing */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;

  /* Shape & elevation */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;
  --sh-sm: 0 1px 2px rgba(30,34,39,.06);
  --sh-md: 0 4px 16px rgba(30,34,39,.08);
  --ring: 0 0 0 3px rgba(216,38,46,.22);

  --ease: 160ms cubic-bezier(.2,.7,.3,1);
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--fs-md); line-height: 1.55;
  color: var(--n-900); background: var(--n-50);
  display: flex; flex-direction: column; min-height: 100vh;
}
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.01em; margin: 0 0 var(--s-2); }
h2 { font-size: var(--fs-lg); font-weight: 600; margin: 0 0 var(--s-4); }
p { margin: 0 0 var(--s-3); }
.muted { color: var(--n-500); }
.small { font-size: var(--fs-sm); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

/* ==========================================================================
   Layout
   ========================================================================== */
.topbar {
  background: var(--n-0); border-bottom: 1px solid var(--n-200);
  position: sticky; top: 0; z-index: 10;
}
.topbar::before { content: ""; display: block; height: 4px; background: var(--brand-grad); }
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: var(--s-2) var(--s-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
}
.brand { display: flex; align-items: center; gap: var(--s-3); color: var(--n-700); }
.brand:hover { text-decoration: none; }
.brand img { height: 52px; width: auto; display: block; }
.brand-title { font-weight: 600; font-size: var(--fs-sm); color: var(--n-500); border-left: 1px solid var(--n-200); padding-left: var(--s-3); }
.topbar nav { display: flex; gap: var(--s-4); align-items: center; font-size: var(--fs-sm); }
.topbar nav a { color: var(--n-700); font-weight: 500; }

.container { width: 100%; max-width: 860px; margin: 0 auto; padding: var(--s-8) var(--s-4) var(--s-10); flex: 1; }
.container.wide { max-width: 1040px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-6); }
.page-head .crumb { font-size: var(--fs-sm); color: var(--n-500); margin-bottom: var(--s-1); }
.page-head .crumb a { color: var(--n-500); }

.footer { background: var(--n-900); color: var(--n-300); font-size: var(--fs-xs); }
.footer-inner { max-width: 1040px; margin: 0 auto; padding: var(--s-6) var(--s-4); display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.footer img { height: 44px; width: auto; opacity: .9; }
.footer a { color: var(--n-300); }

/* ==========================================================================
   Components
   ========================================================================== */
/* Card */
.card { background: var(--n-0); border: 1px solid var(--n-200); border-radius: var(--r-lg); padding: var(--s-6); margin-bottom: var(--s-4); box-shadow: var(--sh-sm); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s-4); }
.card-grid .card { margin: 0; display: flex; flex-direction: column; }
.card-grid .card .actions { margin-top: auto; padding-top: var(--s-4); }

/* Buttons: variants primary | secondary | ghost | danger; sizes sm | md */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 10px 18px; min-height: 40px; border-radius: var(--r-md);
  font: inherit; font-weight: 600; font-size: var(--fs-sm); line-height: 1; cursor: pointer;
  border: 1px solid transparent; transition: background var(--ease), box-shadow var(--ease), transform var(--ease);
  text-decoration: none !important; white-space: nowrap;
  background: var(--brand-600); color: var(--n-0); box-shadow: var(--sh-sm);
}
.btn:hover { background: var(--brand-700); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--n-0); color: var(--n-700); border-color: var(--n-300); }
.btn.secondary:hover { background: var(--n-100); border-color: var(--n-500); }
.btn.ghost { background: transparent; color: var(--brand-600); box-shadow: none; }
.btn.ghost:hover { background: var(--brand-50); }
.btn.danger { background: var(--n-0); color: var(--err-fg); border-color: var(--err-line); box-shadow: none; }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 6px 12px; min-height: 32px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: none; color: var(--n-700); cursor: pointer; font: inherit; font-weight: 500; padding: 0; }
button.link:hover { color: var(--brand-600); }
form.inline { display: inline; }
.actions { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; margin-top: var(--s-5); }

/* Inputs */
label { display: block; font-weight: 600; font-size: var(--fs-sm); margin: var(--s-4) 0 var(--s-2); color: var(--n-900); }
label:first-child { margin-top: 0; }
label .hint { font-weight: 400; color: var(--n-500); }
input[type=text], input[type=number], input[type=password], input[type=file], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--n-300); border-radius: var(--r-md);
  font: inherit; color: var(--n-900); background: var(--n-0); transition: border-color var(--ease), box-shadow var(--ease);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
textarea { min-height: 6.5rem; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%237A828E' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
input[type=file] { padding: 8px; }
input[type=file]::file-selector-button { font: inherit; font-size: var(--fs-xs); font-weight: 600; padding: 6px 10px; border: 1px solid var(--n-300); border-radius: var(--r-sm); background: var(--n-0); color: var(--n-700); margin-right: var(--s-3); cursor: pointer; }
.is-invalid input, .is-invalid textarea, .is-invalid .choice { border-color: var(--err-fg); }
.field-error { color: var(--err-fg); font-size: var(--fs-sm); margin-top: var(--s-2); display: flex; gap: 6px; align-items: center; }
.field-error::before { content: "!"; display: inline-flex; width: 16px; height: 16px; border-radius: 50%; background: var(--err-fg); color: #fff; font-size: 11px; font-weight: 700; align-items: center; justify-content: center; flex: none; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }

/* Choice tiles (radio / checkbox rendered as selectable rows) */
.choices { display: flex; flex-direction: column; gap: var(--s-2); }
.choice {
  display: flex; align-items: center; gap: var(--s-3); font-weight: 500; font-size: var(--fs-md);
  padding: 10px 14px; border: 1px solid var(--n-200); border-radius: var(--r-md); background: var(--n-0);
  margin: 0; cursor: pointer; transition: border-color var(--ease), background var(--ease);
}
.choice:hover { border-color: var(--n-300); background: var(--n-50); }
.choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand-600); flex: none; }
.choice:has(input:checked) { border-color: var(--brand-500); background: var(--brand-50); }
.choice.plain { border: none; padding: 0; background: none; font-weight: 500; }

/* Rating pills */
.rating { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.rating label { position: relative; margin: 0; }
.rating input { position: absolute; opacity: 0; inset: 0; }
.rating span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 44px; padding: 0 12px;
  border: 1px solid var(--n-300); border-radius: var(--r-md); background: var(--n-0); font-weight: 600; cursor: pointer;
  transition: all var(--ease);
}
.rating label:hover span { border-color: var(--brand-500); color: var(--brand-600); }
.rating input:checked + span { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.rating input:focus-visible + span { box-shadow: var(--ring); }
.rating-scale { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--n-500); margin-top: var(--s-2); }

/* Question block */
.question .q-num { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brand-600); margin-bottom: var(--s-1); }
.question .q-text { font-size: var(--fs-lg); font-weight: 600; margin: 0 0 var(--s-2); }
.q-desc { white-space: pre-line; color: var(--n-500); font-size: var(--fs-sm); margin: 0 0 var(--s-4); }
.q-image { max-width: 100%; max-height: 420px; border-radius: var(--r-md); border: 1px solid var(--n-200); margin: 0 0 var(--s-4); display: block; }
.req { color: var(--brand-600); }

/* Progress */
.progress { height: 6px; background: var(--n-200); border-radius: var(--r-pill); overflow: hidden; margin: var(--s-2) 0 var(--s-6); }
.progress > span { display: block; height: 100%; background: var(--brand-grad); width: 0; transition: width 300ms ease; }
.progress-label { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--n-500); }

/* Alerts */
.alert { padding: var(--s-3) var(--s-4); border-radius: var(--r-md); margin-bottom: var(--s-4); font-size: var(--fs-sm); border: 1px solid; }
.alert.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-line); }
.alert.err { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-line); }
.alert.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 600; padding: 2px 10px; border-radius: var(--r-pill); background: var(--ok-bg); color: var(--ok-fg); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.off { background: var(--n-100); color: var(--n-500); }
.badge.type { background: var(--n-100); color: var(--n-700); }
.badge.type::before { display: none; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--n-0); font-size: var(--fs-sm); }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--n-200); vertical-align: middle; }
th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--n-500); font-weight: 600; background: var(--n-50); white-space: nowrap; }
tbody tr:hover { background: var(--n-50); }
tbody tr:last-child td { border-bottom: none; }
td .ops { display: flex; gap: var(--s-2); justify-content: flex-end; }
.card.flush { padding: 0; overflow: hidden; }

/* Question list (admin) */
.q-item { display: flex; gap: var(--s-4); align-items: center; padding: var(--s-4) 0; border-bottom: 1px solid var(--n-200); }
.q-item:last-of-type { border-bottom: none; }
.q-item .num { width: 32px; height: 32px; border-radius: 50%; background: var(--n-100); color: var(--n-700); font-weight: 700; font-size: var(--fs-xs); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.q-item .body { flex: 1; min-width: 0; }
.q-item .body .title { font-weight: 600; }
.q-item .meta { display: flex; gap: var(--s-3); align-items: center; font-size: var(--fs-xs); color: var(--n-500); margin-top: 2px; flex-wrap: wrap; }
.q-item .ops { display: flex; gap: var(--s-1); flex: none; }
.empty { text-align: center; color: var(--n-500); padding: var(--s-8) var(--s-4); }
.empty strong { display: block; color: var(--n-700); margin-bottom: var(--s-1); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s-4); margin-bottom: var(--s-6); }
.stat { background: var(--n-0); border: 1px solid var(--n-200); border-radius: var(--r-md); padding: var(--s-4); }
.stat .v { font-size: var(--fs-xl); font-weight: 700; }
.stat .l { font-size: var(--fs-xs); color: var(--n-500); text-transform: uppercase; letter-spacing: .05em; }

/* Auth */
.auth { max-width: 420px; margin: var(--s-10) auto; }
.auth .logo { display: block; margin: 0 auto var(--s-6); height: 64px; width: auto; }
.auth h1 { text-align: center; font-size: var(--fs-xl); }
.auth .muted { text-align: center; margin-bottom: var(--s-6); }

/* Hero (public quiz intro / thank you) */
.hero { background: var(--n-0); border: 1px solid var(--n-200); border-radius: var(--r-lg); padding: var(--s-8) var(--s-6); margin-bottom: var(--s-6); position: relative; overflow: hidden; }
.hero::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--brand-grad); }
.hero .eyebrow { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-600); margin-bottom: var(--s-2); }
.hero h1 { margin-bottom: var(--s-2); }
.hero .q-desc { font-size: var(--fs-md); margin-bottom: 0; }
.done { text-align: center; padding: var(--s-10) var(--s-6); }
.done .check { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-bg); color: var(--ok-fg); display: inline-flex; align-items: center; justify-content: center; font-size: 30px; margin-bottom: var(--s-4); }

@media (max-width: 640px) {
  .container { padding: var(--s-5) var(--s-4) var(--s-8); }
  .card { padding: var(--s-4); }
  .brand-title { display: none; }
  .q-item { flex-wrap: wrap; }
  .q-item .ops { width: 100%; justify-content: flex-end; }
}
