/* ------------------------------------------------------------------ *
 * Energy Sector CI Interdependency Survey — Carleton / NC-CIPSeR
 * Plain CSS, no framework. Carleton red (#C8102E) on a neutral base.
 * ------------------------------------------------------------------ */

:root {
  --red: #c8102e;
  --red-dark: #9c0c24;
  --red-tint: #fdf1f3;
  --ink: #14161a;
  --ink-2: #3d434c;
  --muted: #5b6067;
  --line: #d9dbe0;
  --line-soft: #ebedf0;
  --bg: #f6f7f9;
  --card: #ffffff;
  --ok: #1c7c4a;
  --err: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.06), 0 4px 14px rgba(20, 22, 26, 0.05);
  --maxw: 780px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--red-dark); }
a:hover { color: var(--red); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.nowrap { white-space: nowrap; }

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

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--red); color: #fff; padding: .6rem 1rem;
}
.skip-link:focus { left: 0; }

/* --- Focus: always visible, never removed ------------------------- */
:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 2px;
  border-radius: 3px;
}

/* --- Top bar ------------------------------------------------------ */
.topbar {
  background: #fff;
  border-bottom: 3px solid var(--red);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { display: inline-flex; align-items: center; gap: .55rem; min-width: 0; }
/* CIPSER logo shared with the CII applications (167x66 source PNG). */
.brand-logo { height: 32px; width: auto; display: block; flex: none; }
.identity { display: flex; align-items: center; gap: .75rem; font-size: .88rem; color: var(--muted); }
.identity .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }

/* --- Page shell --------------------------------------------------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page-wide { max-width: 1180px; }
.page-foot {
  max-width: var(--maxw); margin: 0 auto; padding: 0 1rem 3rem;
  color: var(--muted); font-size: .85rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

/* --- Sign-in ------------------------------------------------------ */
.login-card { max-width: 420px; margin: 3rem auto; }
.login-title { font-size: 1.25rem; }
.login-form { margin-top: 1rem; display: grid; gap: .85rem; }
.login-foot { margin-top: 1rem; font-size: .88rem; color: var(--muted); }
.login-foot .sep { margin: 0 .4rem; }
.login-foot .signup-note { display: block; margin-top: .35rem; color: var(--muted); }
.login-foot .signup-note { display: block; margin-top: .25rem; font-size: .82rem; }
.divider {
  text-align: center; color: var(--muted); font-size: .8rem;
  margin: 1rem 0 .75rem; position: relative;
}
.divider::before, .divider::after {
  content: ""; position: absolute; top: 50%; width: calc(50% - 1.25rem);
  border-top: 1px solid var(--line-soft);
}
.divider::before { left: 0; }
.divider::after { right: 0; }
.federated { display: grid; gap: .5rem; }

/* --- Forms -------------------------------------------------------- */
.field { display: grid; gap: .3rem; }
.sub-field { margin-top: .75rem; max-width: 420px; }
label { font-weight: 600; font-size: .92rem; color: var(--ink-2); }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fff;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}
textarea { resize: vertical; min-height: 5.5rem; }
input:focus, textarea:focus { border-color: var(--red); }

.btn {
  font: inherit; font-weight: 600;
  padding: .6rem 1.1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--muted); }
.btn-lg { padding: .75rem 1.6rem; font-size: 1.02rem; }
.btn-danger { background: #fff; color: var(--err); border-color: var(--err); }
.btn-danger:hover:not(:disabled) { background: var(--err); color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }
td.actions { text-align: right; }

.linkish {
  background: none; border: 0; padding: 0;
  color: var(--red-dark); font: inherit; text-decoration: underline; cursor: pointer;
}

.form-error { color: var(--err); font-size: .9rem; margin: .5rem 0 0; }
.form-note { color: var(--ok); font-size: .9rem; margin: .5rem 0 0; }
.form-error:empty, .form-note:empty { margin: 0; }

/* --- Survey structure --------------------------------------------- */
.survey-head { margin-bottom: 1.25rem; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .08em; font-size: .72rem;
  font-weight: 700; color: var(--red); margin-bottom: .35rem;
}
.survey-head .intro { color: var(--ink-2); }

.banner {
  background: var(--red-tint);
  border: 1px solid #f3ccd3;
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin-bottom: 1.25rem;
  font-size: .92rem;
}

.survey-section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.survey-section > h2 {
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--red);
  display: inline-block;
}
.section-desc { color: var(--ink-2); }

.question {
  border: 0; padding: 0; margin: 1.5rem 0 0;
  min-width: 0; /* let fieldsets shrink inside flex/grid */
}
.question:first-of-type { margin-top: 1rem; }
.question + .question { border-top: 1px solid var(--line-soft); padding-top: 1.25rem; }
.q-title, .question > legend { display: block; padding: 0; margin: 0 0 .35rem; }
.q-num { font-weight: 700; color: var(--red); margin-right: .35rem; }
.q-label { font-weight: 600; }
.req { color: var(--red); }
.q-help { color: var(--muted); font-size: .88rem; margin: .1rem 0 .5rem; }
.counter { text-align: right; font-size: .78rem; }
.field-error { color: var(--err); font-size: .88rem; margin: .4rem 0 0; }
.field-error:empty { margin: 0; }
.question.has-error { border-left: 3px solid var(--err); padding-left: .75rem; margin-left: -.75rem; }

/* --- Option lists -------------------------------------------------- */
.opt-list { display: grid; gap: .35rem; margin-top: .4rem; }
/* `columns` in survey.json -> a responsive multi-column option list. */
.opt-list.cols-2 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.opt-list.cols-3 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.opt-list.inline { grid-auto-flow: column; justify-content: start; gap: 1.5rem; }
.opt { display: flex; align-items: flex-start; gap: .5rem; }
.opt input { margin-top: .28rem; flex: none; width: 1.05rem; height: 1.05rem; accent-color: var(--red); }
.opt label { font-weight: 400; color: var(--ink); cursor: pointer; }
.other-input { margin-top: .5rem; max-width: 420px; }

/* --- Scale legend -------------------------------------------------- */
.scale-legend {
  background: var(--red-tint);
  border: 1px solid #f3ccd3;
  border-radius: 8px;
  padding: .6rem .85rem;
  margin: .75rem 0 0;
  font-size: .9rem;
}
.scale-legend summary { cursor: pointer; font-weight: 600; color: var(--red-dark); }
.scale-defs { margin: .75rem 0 .25rem; padding-left: 1.4rem; }
.scale-defs li { margin-bottom: .3rem; color: var(--ink-2); }

/* --- Slider -------------------------------------------------------- */
.slider-wrap { margin-top: .6rem; }
.slider { width: 100%; accent-color: var(--red); height: 1.6rem; }
.slider.unset { filter: grayscale(1); opacity: .8; }
.slider-anchors {
  display: flex; justify-content: space-between;
  font-size: .75rem; color: var(--muted); margin-top: -.2rem;
}
.slider-anchors span:nth-child(2) { text-align: center; }
.slider-anchors span:last-child { text-align: right; }
.slider-out {
  display: block; margin-top: .5rem; font-size: .92rem;
  background: var(--line-soft); border-radius: 8px; padding: .5rem .7rem;
}
.slider-out.unset { color: var(--muted); font-style: italic; }
.slider-out .def { color: var(--ink-2); }

/* --- Matrix -------------------------------------------------------- */
.matrix-scroll { overflow-x: auto; margin-top: .6rem; border: 1px solid var(--line); border-radius: 8px; }
table.matrix { border-collapse: collapse; width: 100%; min-width: 600px; font-size: .82rem; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--line-soft); padding: .45rem .15rem; text-align: center; }
table.matrix thead th {
  vertical-align: bottom; background: #fafbfc; position: sticky; top: 0;
  font-weight: 600; color: var(--ink-2);
}
table.matrix .col-num { display: block; font-weight: 700; color: var(--red); }
table.matrix .col-lab { display: block; font-weight: 400; font-size: .66rem; color: var(--muted); line-height: 1.2; max-width: 5.2rem; margin: 0 auto; }
table.matrix th.row-head {
  text-align: left; position: sticky; left: 0; background: #fff; z-index: 1;
  font-weight: 600; min-width: 124px; max-width: 124px; padding-left: .6rem; padding-right: .5rem;
}
table.matrix thead th.row-head { z-index: 2; background: #fafbfc; }
table.matrix tbody tr:hover td, table.matrix tbody tr:hover th.row-head { background: var(--red-tint); }
table.matrix input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--red); }
table.matrix tr.row-missing th.row-head { color: var(--err); }
table.matrix tr.row-missing td { background: #fff5f4; }

/* --- Submit / thanks / privacy ------------------------------------- */
.submit-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.summary { flex: 1 1 240px; }
.privacy-text { font-size: .86rem; color: var(--ink-2); }
.thanks-card { border-left: 4px solid var(--ok); }
.error-card { border-left: 4px solid var(--err); }

/* --- Dashboard ------------------------------------------------------ */
.tiles {
  display: grid; gap: 1rem; margin-bottom: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem;
}
.tile-value { font-size: 1.9rem; font-weight: 700; color: var(--red); line-height: 1.1; }
.tile-label { color: var(--muted); font-size: .85rem; }

.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.25rem; }

.grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.chart-card { min-width: 0; }
.chart-holder { position: relative; height: 260px; }
.heatmap-card .chart-holder { height: auto; }
.wide-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-top: 1.25rem;
}

table.heatmap { border-collapse: collapse; width: 100%; font-size: .9rem; margin-top: .5rem; }
table.heatmap th, table.heatmap td { padding: .4rem .6rem; border-bottom: 1px solid var(--line-soft); }
table.heatmap thead th { text-align: left; color: var(--muted); font-size: .8rem; }
table.heatmap tbody th { text-align: left; font-weight: 500; }
table.heatmap td.heat-cell { text-align: center; font-weight: 700; width: 5.5rem; }
table.heatmap td.num { text-align: right; color: var(--muted); width: 3rem; }
.heat-legend { display: flex; align-items: center; gap: 2px; margin-top: .75rem; }
.legend-step { display: block; width: 18px; height: 10px; border: 1px solid rgba(0,0,0,.06); }
.heat-legend .muted { margin: 0 .35rem; }

.table-scroll { overflow-x: auto; max-height: 520px; overflow-y: auto; border: 1px solid var(--line-soft); border-radius: 8px; }
table.data-table { border-collapse: collapse; width: 100%; font-size: .86rem; }
table.data-table th, table.data-table td { padding: .5rem .6rem; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
table.data-table thead th { position: sticky; top: 0; background: #fafbfc; z-index: 1; }
table.data-table td.prose { min-width: 240px; max-width: 460px; white-space: pre-wrap; }

/* --- Small screens --------------------------------------------------- */
@media (max-width: 560px) {
  .page { padding: 1rem .75rem 2.5rem; }
  .survey-section { padding: 1rem; border-radius: 8px; }
  .opt-list.cols-2, .opt-list.cols-3 { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
}

/* --- Print ----------------------------------------------------------- */
@media print {
  .topbar, .identity, .toolbar, .skip-link, .submit-row { display: none !important; }
  body { background: #fff; }
  .card, .survey-section, .wide-card { box-shadow: none; border-color: #bbb; page-break-inside: avoid; }
}

/* --- Reduced motion --------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
