*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f6f9;
  --surface: #fff;
  --border: #dde1e6;
  --text: #1a1f2b;
  --muted: #6b7280;
  --primary: #1a56db;
  --primary-hover: #1648c0;
  --danger: #dc2626;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
.screen.hidden { display: none !important; }
.loading {
  text-align: center;
  padding: 3rem;
  font-size: 1.125rem;
  color: var(--muted);
}
.hidden { display: none !important; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: .875rem; }

/* SSO Buttons */
.sso-buttons { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.sso-btn {
  display: flex; align-items: center; justify-content: center; gap: .625rem;
  width: 100%; padding: .6875rem .75rem;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: .875rem; font-weight: 600; cursor: pointer;
  background: var(--surface); transition: background .15s;
}
.sso-btn:hover { background: #f9fafb; }
.sso-btn:active { background: #f3f4f6; }
.sso-google { color: #1a1f2b; }
.sso-apple { color: #1a1f2b; }
.sso-ext { font-size: .625rem; color: var(--muted); margin-left: .25rem; opacity: .6; }

.sso-handoff {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .875rem;
  margin-bottom: 1rem;
}
.handoff-title {
  font-size: .8125rem;
  font-weight: 600;
  margin-bottom: .25rem;
}
.handoff-desc {
  font-size: .75rem;
  color: var(--muted);
  margin-bottom: .625rem;
}
.bookmarklet-row {
  display: flex;
  gap: .5rem;
  margin-bottom: .625rem;
}
.bookmarklet-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .4375rem .625rem;
  background: #eff6ff;
  color: var(--primary);
  border: 1px dashed var(--primary);
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
  text-align: center;
}
.bookmarklet-btn:hover { background: #dbeafe; }
.secondary-btn {
  padding: .4375rem .625rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.secondary-btn:hover { background: #f3f4f6; }
.token-form {
  display: flex;
  gap: .375rem;
}
.token-form input {
  flex: 1;
  padding: .4375rem .625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .75rem;
}
.token-form button {
  padding: .4375rem .75rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.token-form button:hover { background: var(--primary-hover); }

.divider {
  display: flex; align-items: center; text-align: center;
  margin: 1rem 0; color: var(--muted); font-size: .75rem; gap: .5rem;
}
.divider::before, .divider::after {
  content: ''; flex: 1; border-bottom: 1px solid var(--border);
}
.divider span { white-space: nowrap; }

#login-form label {
  display: block;
  margin-bottom: 1rem;
}
#login-form label span {
  display: block;
  font-size: .8125rem;
  font-weight: 600;
  margin-bottom: .25rem;
  color: var(--text);
}
#login-form input {
  width: 100%;
  padding: .625rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9375rem;
}
#login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}
#login-form button {
  width: 100%;
  padding: .75rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: .9375rem;
  font-weight: 600;
  cursor: pointer;
}
#login-form button:hover { background: var(--primary-hover); }
#login-form button:disabled { opacity: .6; cursor: not-allowed; }
.error { color: var(--danger); font-size: .8125rem; margin-top: .5rem; }
.hint { color: var(--muted); font-size: .75rem; margin-top: .75rem; text-align: center; }

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
  gap: .5rem;
}
header h1 { font-size: 1.25rem; }
.header-right {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
#unit-select {
  padding: .375rem .625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8125rem;
  min-width: 200px;
}
#logout-btn {
  padding: .375rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: .8125rem;
}
#logout-btn:hover { background: #f3f4f6; }

/* Summary */
.summary-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  padding: 1.5rem 1.5rem 0;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card-label { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.card-value { display: block; font-size: 1.75rem; font-weight: 700; margin-top: .25rem; }

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1.5rem;
}
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.panel h2 { font-size: 1rem; margin-bottom: .75rem; }
.panel.full-width { grid-column: 1 / -1; }

/* Rank chart */
.rank-col-chart-wrap { width: 100%; padding-top: .25rem; }
.rank-col-svg { width: 100%; height: auto; display: block; overflow: visible; }
.rank-grid-line { stroke: #e5e7eb; stroke-width: 1; stroke-dasharray: 3 3; }
.rank-axis-label { font-size: 10px; fill: var(--muted); font-family: var(--font); }
.rank-col-count { font-size: 11px; font-weight: 700; fill: var(--text); font-family: var(--font); }
.rank-col-label { font-size: 10.5px; font-weight: 600; fill: var(--muted); font-family: var(--font); }
.rank-col-group rect { transition: fill-opacity .2s ease; }
.rank-col-group:hover rect { fill-opacity: 1; }
.rank-curve-line { stroke: #1e3a8a; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.rank-curve-dot { fill: #ffffff; stroke: #1e3a8a; stroke-width: 2.25; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
th, td { padding: .5rem .625rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; cursor: pointer; user-select: none; }
th:hover { color: var(--text); }
tr:hover td { background: #f9fafb; }
tr.clickable { cursor: pointer; }

.badge { display: inline-block; padding: .125rem .5rem; border-radius: 999px; font-size: .6875rem; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f3f4f6; color: #4b5563; }

.choose-group-row td { background: #f8fafc; }
.choose-group-row.choose-group-start td { border-top: 2px solid #cbd5e1; border-bottom: 1px dashed #e2e8f0; }
.choose-group-row.choose-group-mid td { border-bottom: 1px dashed #e2e8f0; }
.choose-group-row.choose-group-end td { border-bottom: 2px solid #cbd5e1; }
.choose-branch { color: #64748b; font-family: monospace; font-weight: 700; margin-right: .25rem; }

.progress-bar { display: inline-flex; align-items: center; gap: .375rem; }
.progress-track { width: 64px; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; }

.table-controls {
  display: flex;
  gap: .5rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.table-controls input, .table-controls select {
  padding: .375rem .625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8125rem;
}
.table-controls input { flex: 1; min-width: 160px; }

/* Scout detail */
#scout-detail { padding: 1.5rem; }
#back-btn {
  padding: .375rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: .8125rem;
  margin-bottom: 1rem;
}
#back-btn:hover { background: #f3f4f6; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.detail-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.detail-card h3 { font-size: .9375rem; margin-bottom: .5rem; }
.detail-card ul { list-style: none; }
.detail-card li { padding: .25rem 0; font-size: .8125rem; border-bottom: 1px solid #f3f4f6; }
.detail-card li:last-child { border-bottom: none; }

.mb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .5rem;
}
.mb-chip {
  padding: .375rem .5rem;
  border-radius: 6px;
  font-size: .75rem;
  text-align: center;
  border: 1px solid var(--border);
}
.mb-chip.earned { background: #dcfce7; border-color: #86efac; color: #166534; }
.mb-chip.in-progress { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.mb-chip.needed { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.mb-chip.eagle { font-weight: 700; }

/* Roster Bulk Selection & Assign MBC Modal */
.roster-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: .75rem;
}
.roster-header-row h2 { margin-bottom: 0; }
.bulk-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: .3125rem .625rem;
}
.bulk-count {
  font-size: .8125rem;
  font-weight: 600;
  color: #1e40af;
  margin-right: .25rem;
}
.primary-btn {
  padding: .4375rem .75rem;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: 6px;
  font-size: .8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.primary-btn:hover:not(:disabled) { background: var(--primary-hover); }
.primary-btn:disabled { opacity: .55; cursor: not-allowed; }
.sm-btn { padding: .3125rem .625rem; font-size: .75rem; }
.xs-btn { padding: .1875rem .4375rem; font-size: .6875rem; }

th.col-select, td.col-select {
  width: 34px;
  text-align: center;
  padding-left: .5rem;
  padding-right: .25rem;
}
tr.selected-row td { background: #eff6ff; }
tr.selected-row:hover td { background: #dbeafe; }
.scout-checkbox {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--primary);
  vertical-align: middle;
}

.modal-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(680px, 94vw);
  max-height: 90vh;
  margin: auto;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 45px rgba(0,0,0,.22);
}
.modal-dialog::backdrop {
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(2px);
}
.modal-content {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.125rem 1.375rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.125rem; margin-bottom: .125rem; }
.modal-subtitle { font-size: .75rem; color: var(--muted); }
.icon-close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 .25rem;
}
.icon-close-btn:hover { color: var(--text); }

.modal-body {
  padding: 1.125rem 1.375rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}
.modal-section {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.field-label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text);
}
.section-header-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.badge-picker-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: .5rem;
}
.badge-picker-row input, .badge-picker-row select,
.mbc-search-grid input, .mbc-search-grid select,
.mbc-id-lookup-row input, .full-input {
  padding: .4375rem .625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8125rem;
}
.selected-scouts-list {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
  max-height: 120px;
  overflow-y: auto;
  padding: .5rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.scout-pill {
  display: inline-flex;
  align-items: center;
  gap: .3125rem;
  padding: .1875rem .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .75rem;
}
.scout-pill.already-earned {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}
.scout-pill.in-prog {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}
.scout-pill button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .875rem;
  line-height: 1;
  color: inherit;
  opacity: .7;
}
.scout-pill button:hover { opacity: 1; }

.mbc-tabs {
  display: flex;
  gap: .375rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .375rem;
}
.mbc-tab {
  padding: .3125rem .625rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.mbc-tab.active {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--primary);
}
.mbc-tab-pane {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding-top: .25rem;
}
.mbc-search-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
  gap: .375rem;
}
.mbc-id-lookup-row {
  display: flex;
  gap: .5rem;
}
.mbc-id-lookup-row input { flex: 1; }
.field-hint { font-size: .72rem; color: var(--muted); }
.mbc-results-wrap {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
}
.mbc-results-wrap:empty { display: none; }
.mbc-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .625rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: .8125rem;
}
.mbc-result-item:last-child { border-bottom: none; }
.mbc-result-meta { font-size: .72rem; color: var(--muted); }
.selected-counselor-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .625rem .875rem;
  background: #dcfce7;
  border: 1px solid #86efac;
  border-radius: 8px;
  color: #166534;
  font-size: .8125rem;
}
.assign-feedback {
  padding: .625rem .875rem;
  border-radius: 6px;
  font-size: .8125rem;
}
.assign-feedback.success {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}
.assign-feedback.error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}
.assign-feedback.warn {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
  padding: .875rem 1.375rem;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 12px 12px;
}

/* Advancement Report Modal */
.modal-dialog.report-modal {
  width: min(920px, 95vw);
}
.report-config-grid {
  display: grid;
  grid-template-columns: 160px 1fr 1fr 1fr;
  gap: .625rem;
  padding: .75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.report-field {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.report-field span {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
}
.report-field input,
.report-field select {
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8125rem;
  background: var(--surface);
}
.report-preview-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
}
.report-preview-box {
  max-height: 56vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .85rem;
  line-height: 1.55;
  color: #1e293b;
}
.report-preview-box h1 {
  font-size: 1.35rem;
  color: #003f87;
  border-bottom: 2px solid #003f87;
  padding-bottom: .3rem;
  margin: 0 0 .5rem;
}
.report-preview-box h2 {
  font-size: 1.05rem;
  color: #003f87;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: .2rem;
  margin: 1.1rem 0 .45rem;
}
.report-preview-box h3 {
  font-size: .92rem;
  color: #1e293b;
  margin: .75rem 0 .3rem;
}
.report-preview-box p {
  margin: .35rem 0;
}
.report-preview-box ul {
  margin: .35rem 0 .6rem 1.25rem;
}
.report-preview-box table {
  width: 100%;
  border-collapse: collapse;
  margin: .5rem 0 .85rem;
  font-size: .8rem;
}
.report-preview-box th {
  background: #f1f5f9;
  color: #0f172a;
  font-weight: 600;
  text-align: left;
  padding: .4rem .6rem;
  border: 1px solid #cbd5e1;
}
.report-preview-box td {
  padding: .35rem .6rem;
  border: 1px solid #cbd5e1;
  vertical-align: top;
}

@media (max-width: 768px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .summary-row { grid-template-columns: repeat(2, 1fr); }
  header { flex-direction: column; align-items: stretch; }
  .header-right { justify-content: space-between; }
  .badge-picker-row { grid-template-columns: 1fr; }
  .mbc-search-grid { grid-template-columns: 1fr 1fr; }
  .report-config-grid { grid-template-columns: 1fr; }
}
