:root {
  --brand: #0f766e;
  --brand-dark: #0b5c56;
  --brand-light: #e6f4f2;
  --ink: #1f2933;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f7fafa;
  --card: #ffffff;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --ok: #15803d;
  --radius: 12px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }

.brand-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; background: var(--brand); color: #fff;
}
.brand-header .logo { font-weight: 800; letter-spacing: 0.5px; font-size: 18px; }
.brand-header .sub { font-size: 12px; opacity: 0.9; }
.ethos {
  font-size: 12px; color: var(--brand-dark); background: var(--brand-light);
  padding: 8px 14px; text-align: center; font-style: italic;
}

.container { max-width: 720px; margin: 0 auto; padding: 20px; }
.container.wide { max-width: 1080px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}

h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; color: var(--brand-dark); }
.hint { color: var(--muted); font-size: 13px; }

.progress-track { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 12px 0 20px; }
.progress-fill { height: 100%; background: var(--brand); transition: width 0.2s ease; }
.progress-label { font-size: 12px; color: var(--muted); text-align: right; margin-top: -14px; margin-bottom: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 20px; border-radius: 8px; border: none; font-size: 15px; font-weight: 600;
  cursor: pointer; background: var(--brand); color: #fff; min-height: 44px;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; justify-content: space-between; margin-top: 20px; }

label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }

.choice-group { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; margin: 0;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 400;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.choice:hover { border-color: var(--brand); }
.choice.selected { border-color: var(--brand); background: var(--brand-light); font-weight: 600; }
.choice input { accent-color: var(--brand); pointer-events: none; }

.rating-row {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0 18px;
}
.rating-btn {
  position: relative; display: block; padding: 10px 4px; text-align: center; margin: 0;
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 600; background: #fff; line-height: 1.3;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.rating-btn small { display: block; font-weight: 400; font-size: 10px; color: var(--muted); }
.rating-btn.selected { border-color: var(--brand); background: var(--brand); color: #fff; }
.rating-btn.selected small { color: #dff5f2; }
.rating-btn.na { font-size: 12px; }

.question-block { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 14px; }
.question-block:last-child { border-bottom: none; }
.question-text { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.question-text .critical-flag { color: var(--danger); font-size: 11px; font-weight: 700; margin-left: 6px; }

.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 480px) { .check-grid { grid-template-columns: 1fr; } }
.check-item {
  display: flex; align-items: center; gap: 8px; padding: 10px; margin: 0;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-weight: 400; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.check-item input { accent-color: var(--brand); pointer-events: none; }

.callout { border-radius: 8px; padding: 12px 14px; font-size: 13px; margin: 12px 0; }
.callout.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #fde68a; }
.callout.danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.callout.ok { background: #ecfdf5; color: var(--ok); border: 1px solid #bbf7d0; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.badge.draft { background: #f1f5f9; color: #475569; }
.badge.open { background: #dcfce7; color: #166534; }
.badge.closed { background: #e2e8f0; color: #334155; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.table-scroll { overflow-x: auto; }
td.days-cell { white-space: nowrap; }
td.days-overdue { color: var(--danger); font-weight: 700; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.mywork-lead { font-size: 14px; font-weight: 600; color: var(--brand-dark); margin: 0 0 10px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-card .num { font-size: 26px; font-weight: 800; color: var(--brand-dark); }
.stat-card .label { font-size: 12px; color: var(--muted); }
.stat-card.clickable {
  cursor: pointer; font-family: inherit; text-align: left; width: 100%; -webkit-appearance: none; appearance: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.stat-card.clickable:hover { border-color: var(--brand); box-shadow: 0 2px 8px rgba(15,118,110,0.14); }

.filter-chip {
  display: flex; align-items: center; gap: 10px; background: var(--brand-light); color: var(--brand-dark);
  border-radius: 8px; padding: 8px 14px; margin-bottom: 12px; font-size: 13px; font-weight: 600;
}
.filter-chip button {
  background: none; border: 1px solid var(--brand-dark); color: var(--brand-dark); border-radius: 6px;
  padding: 2px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}

.competency-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.competency-bar-row .name { width: 200px; flex-shrink: 0; }
.competency-bar-track { flex: 1; height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; }
.competency-bar-fill { height: 100%; background: var(--brand); }
.competency-bar-fill.mixed { background: var(--warn); }
.competency-score { width: 40px; text-align: right; font-weight: 700; flex-shrink: 0; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }

.center-screen { min-height: 60vh; display: flex; align-items: center; justify-content: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); padding: 20px; max-width: 480px; width: 100%; max-height: 85vh; overflow-y: auto; }

.link-box { display: flex; gap: 8px; align-items: center; background: var(--brand-light); border-radius: 8px; padding: 10px 12px; font-size: 13px; word-break: break-all; }

footer.ethos-footer { text-align: center; padding: 20px; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------- needs-your-attention */
.attn-safeguarding {
  background: var(--danger-bg); border: 1px solid #fecaca; border-radius: 8px;
  padding: 14px 16px; margin-bottom: 16px; color: var(--danger); font-size: 14px;
}
.attn-group { border-left: 3px solid var(--warn); background: var(--bg); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.attn-group:last-child { margin-bottom: 0; }
.attn-group-title { font-weight: 700; font-size: 14px; margin-bottom: 6px; color: var(--ink); }
.attn-group-items { display: flex; flex-direction: column; }
.attn-item {
  display: block; width: 100%; text-align: left; background: none; border: none; font-family: inherit;
  font-size: 13.5px; padding: 4px 0; cursor: default; color: var(--ink);
}
button.attn-item { cursor: pointer; }
button.attn-item:hover .attn-item-name { text-decoration: underline; color: var(--brand-dark); }
.attn-item-name { font-weight: 600; }
.attn-item-sep { color: var(--muted); margin: 0 5px; }
.attn-item-detail { color: var(--muted); }

/* ------------------------------------------------------------- calendar */
.today-date { font-weight: 700; color: var(--brand-dark); font-size: 14px; margin: -4px 0 10px; }
.today-next-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin: 12px 0 4px; }
.cal-chip-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cal-chip {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  background: var(--bg); border: none; border-left: 3px solid transparent; border-radius: 6px;
  padding: 6px 8px; margin-bottom: 4px; font-size: 12.5px; font-family: inherit; cursor: pointer; color: var(--ink);
}
.cal-chip:hover { background: var(--brand-light); }
.cal-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-chip-list .cal-chip { font-size: 13.5px; padding: 8px 10px; }

.cal-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }
.cal-legend-item { display: flex; align-items: center; gap: 6px; }

.cal-mode-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 8px; padding: 3px; }
.cal-mode-btn {
  background: none; border: none; padding: 6px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
.cal-mode-btn.active { background: #fff; color: var(--brand-dark); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

.cal-grid-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; text-align: center; margin-bottom: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.cal-day { background: #fff; min-height: 92px; padding: 6px; }
.cal-day.muted { background: #fafbfb; color: var(--muted); }
.cal-day.muted .cal-day-num { color: var(--muted); }
.cal-day.today { background: var(--brand-light); }
.cal-day-num { font-size: 12.5px; font-weight: 700; margin-bottom: 4px; }
.cal-day.today .cal-day-num { color: var(--brand-dark); }
.cal-more { background: none; border: none; color: var(--brand-dark); font-size: 11px; font-weight: 600; cursor: pointer; padding: 2px 4px; }

.cal-week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-week-col { background: var(--bg); border-radius: 8px; padding: 8px; min-height: 140px; }
.cal-week-col.today { background: var(--brand-light); }
.cal-week-col-head { font-size: 11.5px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.cal-week-col.today .cal-week-col-head { color: var(--brand-dark); }

.cal-agenda-group { margin-bottom: 16px; }
.cal-agenda-date { font-size: 12.5px; font-weight: 700; color: var(--brand-dark); text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 6px; }

@media (max-width: 700px) {
  .cal-grid, .cal-grid-head { display: block; }
  .cal-grid-head { display: none; }
  .cal-day { border-bottom: 1px solid var(--border); min-height: 0; }
  .cal-day.muted { display: none; }
  .cal-week-grid { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------- admin app shell */
/* Sidebar + topbar layout for the signed-in admin app (index.html). The
   public respondent wizard (feedback.html) and reset-password.html keep
   using .brand-header/#headerActions untouched — this is a parallel set
   of classes, not a replacement. */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; background: var(--brand); color: #fff; flex-wrap: wrap;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar .logo { font-weight: 800; letter-spacing: 0.5px; font-size: 18px; }
.topbar .sub { font-size: 12px; opacity: 0.9; }
.sidebar-toggle {
  display: none; background: none; border: none; color: #fff; font-size: 20px; cursor: pointer;
  padding: 4px 10px; border-radius: 6px; line-height: 1;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.15); }
.topbar-status { display: flex; align-items: center; gap: 14px; }
.topbar-greeting { text-align: right; line-height: 1.3; }
.topbar-greeting .g-main { font-weight: 700; font-size: 14px; }
.topbar-greeting .g-sub { font-size: 11px; opacity: 0.85; }
.topbar-bell {
  position: relative; background: rgba(255,255,255,0.14); border: none; color: #fff;
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.topbar-bell:hover { background: rgba(255,255,255,0.24); }
.topbar-bell svg { width: 17px; height: 17px; }
.topbar-bell .dot {
  position: absolute; top: -2px; right: -2px; background: var(--danger); color: #fff;
  font-size: 9px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px; border: 2px solid var(--brand);
}
.topbar-profile { display: flex; align-items: center; gap: 8px; }
.avatar-circle {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.topbar-profile-text { line-height: 1.25; }
.topbar-profile-text .p-name { font-weight: 700; font-size: 13px; }
.topbar-profile-text .p-role { font-size: 11px; opacity: 0.85; }

.shell { display: flex; align-items: flex-start; }
.sidebar {
  width: 226px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--border);
  min-height: calc(100vh - 92px); position: sticky; top: 0; padding-bottom: 8px; overflow-x: hidden;
}
.sidebar.collapsed { width: 62px; }
.sidebar-section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted);
  padding: 16px 18px 6px; font-weight: 700; white-space: nowrap;
}
.sidebar.collapsed .sidebar-section-label { opacity: 0; height: 0; padding: 8px 0 0; overflow: hidden; }
.sidebar-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px; width: 100%;
  background: none; border: none; text-align: left; font-size: 14px; font-weight: 600;
  color: var(--muted); cursor: pointer; border-left: 3px solid transparent; white-space: nowrap; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-item:hover { background: var(--brand-light); color: var(--brand-dark); }
.sidebar-item.active { color: var(--brand-dark); border-left-color: var(--brand); background: var(--brand-light); }
.sidebar-item svg { flex-shrink: 0; width: 18px; height: 18px; }
.sidebar-item .item-label { overflow: hidden; text-overflow: ellipsis; }
.sidebar.collapsed .sidebar-item .item-label { display: none; }
.sidebar-item .item-badge {
  margin-left: auto; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px; flex-shrink: 0;
}
.sidebar.collapsed .sidebar-item .item-badge { display: none; }
.sidebar-collapse-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 18px; margin-top: 8px;
  background: none; border: none; border-top: 1px solid var(--border); color: var(--muted);
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; overflow: hidden;
}
.sidebar-collapse-btn:hover { color: var(--brand-dark); }
.sidebar-collapse-btn svg { flex-shrink: 0; width: 16px; height: 16px; transition: transform 0.15s ease; }
.sidebar.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-collapse-btn .item-label { display: none; }

.main-scroll { flex: 1; min-width: 0; }
.sidebar-backdrop { display: none; }
/* Before sign-in there's no sidebar/status to show — renderLogin() clears
   their content, but they'd still occupy layout space without this. */
body:not(.app-shell-active) .sidebar,
body:not(.app-shell-active) .sidebar-toggle,
body:not(.app-shell-active) .topbar-status { display: none; }

/* Auto icon-rail on medium/tablet widths, regardless of the manual toggle */
@media (max-width: 1100px) and (min-width: 701px) {
  .sidebar:not(.collapsed) { width: 62px; }
  .sidebar:not(.collapsed) .sidebar-section-label { opacity: 0; height: 0; padding: 8px 0 0; overflow: hidden; }
  .sidebar:not(.collapsed) .sidebar-item .item-label,
  .sidebar:not(.collapsed) .sidebar-item .item-badge,
  .sidebar:not(.collapsed) .sidebar-collapse-btn .item-label { display: none; }
  .sidebar.collapsed { width: 226px; } /* manual toggle still expands it back */
}

/* Phone: sidebar becomes an off-canvas hamburger drawer */
@media (max-width: 700px) {
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 60; width: 250px !important;
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 2px 0 16px rgba(0,0,0,0.2);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  /* The drawer is an overlay with room to spare, so it always shows full
     labels — override the desktop icon-only "collapsed" state, which is a
     separate concept (manual toggle / auto tablet rail) that shouldn't
     apply here even if it's carried over from a wider viewport. */
  .sidebar.collapsed .sidebar-section-label { opacity: 1; height: auto; padding: 16px 18px 6px; overflow: visible; }
  .sidebar.collapsed .sidebar-item .item-label,
  .sidebar.collapsed .sidebar-item .item-badge,
  .sidebar.collapsed .sidebar-collapse-btn .item-label { display: inline; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 55; }
  .topbar-greeting, .topbar-profile-text { display: none; }
}
