@import url('https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@500;600;700;800&family=Source+Sans+3:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --surface-2: #eaf0f1;
  --border: #dbe4e6;
  --text: #16232a;
  --text-muted: #57666c;
  --text-faint: #8a969b;

  --ins-900: #043138;
  --ins-800: #064350;
  --ins-700: #086378;
  --ins-wash: #e6eff0;
  --ins-orange: #f49020;
  --ins-orange-wash: #fdf1e2;

  --cid-navy: #1d2944;

  --good: #2e7d46;
  --good-wash: #e6f2e9;
  --bad: #b23b3b;
  --bad-wash: #f8e8e8;

  --shadow: 0 1px 2px rgba(10,30,35,.05), 0 10px 28px rgba(10,30,35,.07);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Source Sans 3', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { font-family: 'Libre Franklin', system-ui, sans-serif; text-wrap: balance; margin: 0; }
.mono, .tabnum { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
a { color: var(--ins-700); }

/* ---------- LOGIN ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
}
@media (max-width: 860px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { min-height: 260px; }
}

.login-brand {
  position: relative;
  background: linear-gradient(160deg, var(--ins-900) 0%, var(--ins-800) 55%, var(--ins-700) 100%);
  color: #eef7f6;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 56px;
}
.brand-lockup img { height: 30px; filter: brightness(0) invert(1); opacity: .95; }
.brand-lockup .divider { width: 1px; height: 28px; background: rgba(255,255,255,.3); }
.brand-lockup .lockup-text { font-size: 13px; line-height: 1.3; }
.brand-lockup .lockup-text b { display: block; font-family: 'Libre Franklin', sans-serif; font-weight: 700; font-size: 14.5px; }
.brand-lockup .lockup-text span { opacity: .75; }

.login-brand .eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ins-orange);
  margin-bottom: 14px;
}
.login-brand h1 {
  font-size: 38px;
  font-weight: 800;
  max-width: 13ch;
  margin-bottom: 16px;
  letter-spacing: -.01em;
}
.login-brand p.lead {
  max-width: 44ch;
  color: rgba(238,247,246,.8);
  font-size: 15.5px;
  margin-bottom: auto;
}
.login-brand .foot {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: rgba(238,247,246,.55);
  padding-top: 24px;
  border-top: 1px solid rgba(255,255,255,.15);
  position: relative;
  z-index: 1;
}

.shape {
  position: absolute;
  border: 2px solid;
  border-radius: 8px;
}
.shape-1 { width: 84px; height: 84px; top: 14%; right: 10%; border-color: var(--ins-orange); transform: rotate(18deg); opacity: .55; }
.shape-2 { width: 130px; height: 130px; bottom: 8%; right: -30px; border-color: rgba(186,212,49,.6); transform: rotate(-12deg); opacity: .5; }
.shape-3 { width: 46px; height: 46px; top: 42%; right: 22%; border-color: rgba(238,247,246,.35); transform: rotate(35deg); }

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 34px;
}
.login-card img.ins-mark { height: 40px; margin-bottom: 22px; }
.login-card h2 { font-size: 23px; font-weight: 700; margin-bottom: 6px; }
.login-card .sub { color: var(--text-muted); font-size: 14px; margin-bottom: 26px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--text-faint); }
.input-wrap input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14.5px;
  background: var(--surface);
  color: var(--text);
}
.input-wrap input:focus { outline: 2px solid var(--ins-700); outline-offset: 1px; }
.input-wrap .toggle-pw {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 4px;
  display: flex;
}

.btn-primary {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 9px;
  background: var(--ins-800);
  color: #fff;
  font-weight: 700;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  transition: background .15s ease;
}
.btn-primary:hover { background: var(--ins-700); }
.btn-primary:focus-visible { outline: 2px solid var(--ins-orange); outline-offset: 2px; }

.error-banner {
  background: var(--bad-wash);
  color: var(--bad);
  border: 1px solid rgba(178,59,59,.25);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 13.5px;
  margin-bottom: 16px;
}

.protected-note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
}
.protected-note svg { flex-shrink: 0; margin-top: 2px; color: var(--ins-700); }

/* ---------- DASHBOARD ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.topbar .brand img.cid { height: 20px; }
.topbar .brand .sep { width: 1px; height: 20px; background: var(--border); }
.topbar .brand img.ins { height: 26px; }
.topbar .brand .title { font-family: 'Libre Franklin', sans-serif; font-weight: 700; font-size: 15px; color: var(--ins-800); }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13.5px; color: var(--text-muted); }
.topbar .btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}
.topbar .btn-ghost:hover { background: var(--surface-2); }

.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 70px; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 28px;
}
.stat { background: var(--surface); padding: 16px 20px; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin-bottom: 6px; }
.stat .value { font-family: 'IBM Plex Mono', monospace; font-size: 22px; font-weight: 600; color: var(--ins-800); }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-title h2 { font-size: 18px; font-weight: 700; }
.section-title .hint { font-size: 12.5px; color: var(--text-faint); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px 22px 10px;
  margin-bottom: 34px;
}
#barChart { width: 100%; display: block; overflow: visible; }
.bar-row-label {
  font-size: 12px;
  fill: var(--text);
  font-family: 'Source Sans 3', sans-serif;
}
.bar-value-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  font-weight: 600;
  fill: var(--ins-800);
}
.bar-rect { fill: var(--ins-700); }
.bar-rect:hover { fill: var(--ins-orange); }

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--ins-900);
  color: #eef7f6;
  font-size: 12.5px;
  padding: 7px 10px;
  border-radius: 7px;
  box-shadow: var(--shadow);
  z-index: 40;
  display: none;
  max-width: 260px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.survey-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.survey-card .name {
  font-family: 'Libre Franklin', sans-serif;
  font-weight: 700;
  font-size: 14.5px;
  padding: 3px 5px;
  margin: -3px -5px;
  border-radius: 5px;
  outline: none;
}
.survey-card .name:focus { background: var(--ins-wash); box-shadow: 0 0 0 1px var(--ins-700); }
.survey-card .name:hover { background: var(--surface-2); }

.survey-card .metrics { display: flex; gap: 18px; }
.metric-block .metric-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin-bottom: 3px; }
.metric-block .metric-value { font-family: 'IBM Plex Mono', monospace; font-size: 19px; font-weight: 600; }
.metric-block input.sample-input {
  width: 76px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 7px;
}
.metric-block input.sample-input:focus { outline: 2px solid var(--ins-700); }

.progress-track { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; background: var(--ins-700); border-radius: 4px; transition: width .3s ease; }
.progress-fill.over { background: var(--ins-orange); }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.card-foot .synced { font-size: 11px; color: var(--text-faint); }
.card-foot .sync-btn {
  border: none;
  background: none;
  color: var(--ins-700);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.card-foot .sync-btn:hover { background: var(--ins-wash); }
.card-foot .sync-btn svg { width: 13px; height: 13px; }
.card-foot .sync-btn.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-chip {
  font-size: 11px;
  color: var(--bad);
  background: var(--bad-wash);
  padding: 2px 7px;
  border-radius: 6px;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ins-900);
  color: #eef7f6;
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 13.5px;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .progress-fill, .toast, .sync-btn.spinning svg { transition: none; animation: none; }
}

/* ---------- ADMIN ---------- */
.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.admin-table th { background: var(--surface-2); font-size: 11px; text-transform: uppercase; color: var(--text-faint); }
.pill-admin { background: var(--ins-wash); color: var(--ins-800); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 12px; }
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 20px; max-width: 420px; box-shadow: var(--shadow); }
.form-card .field input[type=text], .form-card .field input[type=email], .form-card .field input[type=password] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 13.5px; }
