/* ============================================================
   Second Order — brand stylesheet
   Concept: "The Loop". A first order (the dot) and the path that
   returns to it (the arrow). Teal on cool neutrals, Manrope for
   voice, Instrument Sans for everything you read at speed.
   ============================================================ */

:root {
  /* Brand */
  --so-teal:        #0F6E63;
  --so-teal-dark:   #0A4F47;
  --so-teal-tint:   #E3F1EE;
  --so-teal-tint-2: #C6E4DE;
  --so-mint:        #5FD4C4;

  /* Cool neutrals, biased toward the teal */
  --so-ink:     #15181D;
  --so-ink-2:   #4A515C;
  --so-ink-3:   #7B8492;
  --so-line:    #D9DEE4;
  --so-line-2:  #EBEEF1;
  --so-bg:      #F4F6F7;
  --so-surface: #FFFFFF;

  /* Semantic (kept separate from the accent) */
  --so-good:     #1E8E5A;
  --so-warn:     #B7791F;
  --so-critical: #C23B3B;

  /* Type */
  --so-font-display: "Manrope", "Helvetica Neue", Arial, sans-serif;
  --so-font-body:    "Instrument Sans", "Helvetica Neue", Arial, sans-serif;

  --so-radius: 6px;
  --so-header-h: 60px;

  /* ---- Legacy variables used by page templates, remapped ---- */
  --color-primary-light:   var(--so-teal-tint-2);
  --color-primary-lighter: var(--so-teal-tint);
  --color-primary-dark:    var(--so-teal-dark);
  --color-teal-medium:     var(--so-teal);
  --color-teal-muted:      #6CA5A0;
  --color-accent-peach:    #F2B79A;   /* Female sections */
  --color-accent-blue:     #4A6FA5;   /* Male sections */
  --color-text-dark:       var(--so-ink);
  --color-text-light:      #FFFFFF;

  /* ---- Bootstrap 5.3 theme hooks ---- */
  --bs-body-font-family: var(--so-font-body);
  --bs-body-color: var(--so-ink);
  --bs-body-bg: var(--so-bg);
  --bs-primary: var(--so-teal);
  --bs-primary-rgb: 15, 110, 99;
  --bs-link-color: var(--so-teal);
  --bs-link-color-rgb: 15, 110, 99;
  --bs-link-hover-color: var(--so-teal-dark);
  --bs-link-hover-color-rgb: 10, 79, 71;
  --bs-border-color: var(--so-line);
  --bs-border-radius: var(--so-radius);
  --bs-secondary-color: var(--so-ink-2);
}

/* ---------- Base typography ---------- */
html { -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--so-font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--so-ink);
  background-color: var(--so-bg);
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
  font-family: var(--so-font-display);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--so-ink);
  text-wrap: balance;
}
h1, .h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.025em; }
h2, .h2 { font-size: 1.45rem; }
h3, .h3 { font-size: 1.2rem; }
h4, .h4 { font-size: 1.05rem; }
small, .small { color: var(--so-ink-2); }
a { color: var(--so-teal); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--so-teal-dark); text-decoration: none; }
.text-muted { color: var(--so-ink-3) !important; }

/* Eyebrow labels: uppercase, spaced, quiet */
.so-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--so-ink-3);
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1200;
  height: var(--so-header-h);
  padding: 0 20px;
  background: var(--so-surface);
  border-bottom: 1px solid var(--so-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--so-ink);
  text-decoration: none;
}
.brand:hover { color: var(--so-ink); }
.brand-mark {
  width: 28px;
  height: 28px;
  color: var(--so-teal);
  flex: none;
}
.brand-word {
  font-family: var(--so-font-display);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.03em;
  line-height: 1;
  white-space: nowrap;
}
.brand-tag {
  margin-left: 14px;
  padding-left: 14px;
  border-left: 1px solid var(--so-line);
  font-size: 12px;
  color: var(--so-ink-3);
  white-space: nowrap;
}
@media (max-width: 640px) { .brand-tag { display: none; } }

.app-header-right { display: flex; align-items: center; gap: 12px; }
.app-header-user {
  font-size: 13px;
  color: var(--so-ink-2);
  white-space: nowrap;
}
@media (max-width: 480px) { .app-header-user { display: none; } }

/* Menu toggle lives inside the header now */
.nav-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--so-line);
  border-radius: var(--so-radius);
  background: var(--so-surface);
  color: var(--so-ink);
  font-family: var(--so-font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.nav-toggle-btn:hover { background: var(--so-bg); border-color: var(--so-ink-3); }
.nav-toggle-btn:focus-visible,
.nav-close-btn:focus-visible { outline: 2px solid var(--so-teal); outline-offset: 2px; }
.nav-toggle-btn .material-icons { font-size: 20px; }

/* ---------- Sidebar / menu ---------- */
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(21, 24, 29, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 1300;
}
.nav-backdrop.show { opacity: 1; pointer-events: auto; }

.nav-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 300px;
  max-width: 88vw;
  height: 100%;
  background: var(--so-surface);
  border-left: 1px solid var(--so-line);
  box-shadow: -12px 0 32px rgba(21, 24, 29, .10);
  transform: translateX(100%);
  transition: transform .22s ease;
  z-index: 1350;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.nav-sidebar.open { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) {
  .nav-sidebar, .nav-backdrop { transition: none; }
}

.nav-sidebar-header {
  height: var(--so-header-h);
  padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--so-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
}
.nav-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--so-radius);
  background: transparent;
  color: var(--so-ink-2);
  cursor: pointer;
}
.nav-close-btn:hover { background: var(--so-bg); color: var(--so-ink); }

.nav-sidebar-body { padding: 8px 0 16px; }
.nav-group { padding: 12px 0 4px; }
.nav-group + .nav-group { border-top: 1px solid var(--so-line-2); margin-top: 4px; }
.nav-group-label {
  padding: 4px 20px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--so-ink-3);
}
.nav-sidebar-links { list-style: none; padding: 0; margin: 0; }
.nav-sidebar-links a {
  position: relative;
  display: block;
  padding: 7px 20px 7px 28px;
  font-size: 14px;
  font-weight: 500;
  color: var(--so-ink-2);
  border-left: 3px solid transparent;
  transition: background .12s ease, color .12s ease;
}
.nav-sidebar-links a:hover {
  background: var(--so-bg);
  color: var(--so-ink);
}
.nav-sidebar-links a.active {
  color: var(--so-teal-dark);
  background: var(--so-teal-tint);
  border-left-color: var(--so-teal);
  font-weight: 600;
  text-decoration: none;
}
.nav-sidebar-links a.nav-muted { color: var(--so-ink-3); font-weight: 400; }
.nav-sidebar-footer {
  margin-top: auto;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--so-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--so-ink-3);
}
.nav-sidebar-footer a { font-weight: 600; color: var(--so-ink-2); }
.nav-sidebar-footer a:hover { color: var(--so-critical); }

/* ---------- Page shell ---------- */
.full-screen {
  width: 100%;
  max-width: 100%;
  padding-left: 24px;
  padding-right: 24px;
  margin: 0;
}

/* ---------- Bootstrap component overrides ---------- */
.btn {
  font-family: var(--so-font-body);
  font-weight: 600;
  border-radius: var(--so-radius);
  white-space: nowrap;
}
.btn-primary {
  --bs-btn-bg: var(--so-teal);
  --bs-btn-border-color: var(--so-teal);
  --bs-btn-hover-bg: var(--so-teal-dark);
  --bs-btn-hover-border-color: var(--so-teal-dark);
  --bs-btn-active-bg: var(--so-teal-dark);
  --bs-btn-active-border-color: var(--so-teal-dark);
  --bs-btn-disabled-bg: var(--so-teal-tint-2);
  --bs-btn-disabled-border-color: var(--so-teal-tint-2);
  --bs-btn-focus-shadow-rgb: 15, 110, 99;
}
.btn-outline-primary {
  --bs-btn-color: var(--so-teal);
  --bs-btn-border-color: var(--so-teal-tint-2);
  --bs-btn-hover-bg: var(--so-teal-tint);
  --bs-btn-hover-color: var(--so-teal-dark);
  --bs-btn-hover-border-color: var(--so-teal);
  --bs-btn-active-bg: var(--so-teal);
  --bs-btn-active-border-color: var(--so-teal);
  --bs-btn-focus-shadow-rgb: 15, 110, 99;
}
.btn-secondary {
  --bs-btn-bg: var(--so-ink-2);
  --bs-btn-border-color: var(--so-ink-2);
  --bs-btn-hover-bg: var(--so-ink);
  --bs-btn-hover-border-color: var(--so-ink);
}
.btn-outline-secondary {
  --bs-btn-color: var(--so-ink-2);
  --bs-btn-border-color: var(--so-line);
  --bs-btn-hover-bg: var(--so-bg);
  --bs-btn-hover-color: var(--so-ink);
  --bs-btn-hover-border-color: var(--so-ink-3);
}

.card {
  --bs-card-border-color: var(--so-line);
  --bs-card-cap-bg: var(--so-surface);
  --bs-card-bg: var(--so-surface);
  border-radius: var(--so-radius);
}
.card-header {
  font-family: var(--so-font-display);
  font-weight: 700;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--so-line);
}
.card-header h1, .card-header h2, .card-header h3, .card-header h4 { margin: 0; }
.card-footer { background: var(--so-bg); border-top: 1px solid var(--so-line); }

.form-label { font-weight: 600; font-size: 13px; color: var(--so-ink-2); margin-bottom: 4px; }
.form-control, .form-select {
  border-color: var(--so-line);
  border-radius: var(--so-radius);
  color: var(--so-ink);
  background-color: var(--so-surface);
}
.form-control:focus, .form-select:focus {
  border-color: var(--so-teal);
  box-shadow: 0 0 0 3px rgba(15, 110, 99, .18);
}
.form-check-input:checked { background-color: var(--so-teal); border-color: var(--so-teal); }

.table {
  --bs-table-border-color: var(--so-line);
  --bs-table-striped-bg: #F8FAFA;
  --bs-table-hover-bg: var(--so-teal-tint);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.table thead th {
  font-family: var(--so-font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--so-ink-2);
  background: var(--so-bg);
  border-bottom: 1px solid var(--so-line);
}
.table-header-brand th,
thead.table-header-brand th {
  background: var(--so-teal) !important;
  color: #FFFFFF !important;
  border-color: var(--so-teal-dark) !important;
}
.table-light { --bs-table-bg: var(--so-bg); }

.alert { border-radius: var(--so-radius); border-width: 1px; }
.alert-success { --bs-alert-bg: #E6F4EC; --bs-alert-border-color: #BFE3CF; --bs-alert-color: #145A3A; }
.alert-danger  { --bs-alert-bg: #FBE9E9; --bs-alert-border-color: #F0C4C4; --bs-alert-color: #8A2A2A; }
.alert-warning { --bs-alert-bg: #FBF3E3; --bs-alert-border-color: #EFD9A8; --bs-alert-color: #6E4A0F; }
.alert-info    { --bs-alert-bg: var(--so-teal-tint); --bs-alert-border-color: var(--so-teal-tint-2); --bs-alert-color: var(--so-teal-dark); }

.badge { font-weight: 600; letter-spacing: .02em; }
.bg-primary { background-color: var(--so-teal) !important; }
.bg-light { background-color: var(--so-bg) !important; }
.text-primary { color: var(--so-teal) !important; }

.bg-male   { background-color: var(--color-accent-blue) !important;  color: #FFFFFF !important; }
.bg-female { background-color: var(--color-accent-peach) !important; color: var(--so-ink) !important; }

.accordion-button:not(.collapsed) { background: var(--so-teal-tint); color: var(--so-teal-dark); }
.accordion-button:focus { box-shadow: 0 0 0 3px rgba(15, 110, 99, .18); }

/* Legacy flash + date range bits kept for pages that use them */
.flash-message { padding: 10px; margin-bottom: 15px; border-radius: var(--so-radius); }
.flash-message.success { background: #E6F4EC; color: #145A3A; }
.flash-message.error   { background: #FBE9E9; color: #8A2A2A; }
.date-range-card { max-width: 600px; margin: 0 auto; padding: 20px; }
.datepicker-input {
  background-image: url('https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/images/calendar.gif');
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 20px 20px;
  padding-right: 40px;
}

/* ---------- Loader: the loop, closing ---------- */
.loader-container {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(244, 246, 247, .82);
  z-index: 1500;
  justify-content: center;
  align-items: center;
}
.loader-container.show { display: flex; }
.loader {
  width: 56px;
  height: 56px;
  color: var(--so-teal);
  animation: so-spin 1.1s linear infinite;
}
@keyframes so-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loader { animation-duration: 3s; } }

/* ---------- Auth pages (login / register) ---------- */
.auth-body { margin: 0; background: var(--so-bg); }
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
}
@media (max-width: 860px) { .auth-shell { grid-template-columns: 1fr; } }

.auth-panel {
  background: var(--so-ink);
  color: #F4F5F7;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 48px;
}
@media (max-width: 860px) { .auth-panel { padding: 28px 24px; gap: 24px; } }
.auth-panel .brand { color: #F4F5F7; }
.auth-panel .brand-mark { color: var(--so-mint); }
.auth-hero { display: flex; flex-direction: column; gap: 22px; }
.auth-hero-mark { width: 120px; height: 120px; color: var(--so-mint); }
@media (max-width: 860px) { .auth-hero-mark { width: 56px; height: 56px; } }
.auth-hero h1 {
  color: #F4F5F7;
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  max-width: 16ch;
  margin: 0;
}
@media (max-width: 860px) { .auth-hero h1 { font-size: 1.5rem; } }
.auth-hero p { color: #B4BBC6; max-width: 44ch; margin: 0; font-size: 15px; }
.auth-panel-foot { font-size: 12px; color: #7B8492; }
@media (max-width: 860px) { .auth-panel-foot { display: none; } }

.auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  background: var(--so-surface);
  border: 1px solid var(--so-line);
  border-radius: 8px;
  padding: 32px;
}
.auth-card h2 { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 4px; }
.auth-card .auth-sub { color: var(--so-ink-3); font-size: 14px; margin: 0 0 24px; }
.auth-card .form-control { height: 44px; font-size: 15px; }
.auth-card .btn-primary { height: 44px; font-size: 15px; }
.auth-foot { margin-top: 20px; font-size: 13px; color: var(--so-ink-3); text-align: center; }
.auth-foot a { font-weight: 600; }
.auth-flash { width: 100%; max-width: 400px; margin: 0 auto 16px; }
