/* =============================================================================
   A-Trace: Main Stylesheet
   DSWD-RRCY Rehabilitation Assessment System
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@500;600;700&display=swap');

/* ─── CSS VARIABLES ──────────────────────────────────────────────────────────── */
:root {
  /* Brand Colors */
  --dswd-blue:      #4D0E13;
  --dswd-blue-dark: #2E0A0D;
  --dswd-blue-mid:  #7A1B22;
  --dswd-teal:      #0e7490;
  --dswd-gold:      #e8952c;
  --dswd-red:       #c0392b;

  /* UI Colors */
  --primary:        #4D0E13;
  --primary-hover:  #2E0A0D;
  --primary-light:  #F6E8E9;
  --accent:         #e8952c;
  --accent-light:   #fef3e2;

  /* Rating Colors */
  --very-good:      #16a34a;
  --good:           #2563eb;
  --fair:           #d97706;
  --needs-impr:     #dc2626;

  /* Rating Colors (light tints, for text-on-dark contexts) */
  --very-good-light: #86efac;
  --good-light:       #93c5fd;
  --fair-light:       #fde68a;
  --needs-impr-light: #fca5a5;

  /* Neutrals */
  --bg:             #FFFFFF;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --border:         #e2e8f0;
  --border-light:   #f1f5f9;

  /* Text */
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;

  /* Sidebar */
  --sidebar-bg:         #1F0508;
  --sidebar-hover:      #4D0E13;
  --sidebar-active:     #7A1B22;
  --sidebar-text:       #cbd5e1;
  --sidebar-text-hover: #ffffff;
  --sidebar-width:      260px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 12px rgba(0,0,0,.1),  0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 10px 30px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.08);

  /* Radius */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;

  /* Transition */
  --transition: .2s ease;
}

/* ─── RESET & BASE ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── SCROLLBAR ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ─── TYPOGRAPHY ─────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--dswd-blue);
}
.section-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.text-muted     { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }

/* ─── LOGIN PAGE ─────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Intentionally NOT vertically centered: bottom padding exceeds top padding
     by exactly 72px, which shifts the whole centered block (header/logo/card)
     72px above dead-center on any viewport tall enough to fit it with room to
     spare — a fixed, guaranteed pixel offset rather than a soft rem nudge. */
  padding: 1rem 1.5rem calc(1rem + 72px);
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, var(--sidebar-bg) 0%, var(--dswd-blue) 100%);
}
.login-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-brand-header { position: relative; z-index: 1; text-align: center; margin-bottom: 1.75rem; }
.login-brand-header .agency-name {
  color: white;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .3px;
}
.login-brand-header .login-logo-img {
  display: block;
  height: 128px;
  width: auto;
  margin: 1rem auto 0;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.25));
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,.07);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,.08);
  padding: 2.5rem;
}

.login-card-title {
  text-align: center;
  font-size: 2.1rem;
  font-weight: 800;
  color: white;
  letter-spacing: -.5px;
}
.login-card-title .accent { color: var(--dswd-gold); }
.login-card-accent-line {
  width: 48px; height: 3px;
  margin: .85rem auto 1.75rem;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--dswd-gold), var(--dswd-blue-mid));
}

.login-form { width: 100%; }
.login-card .form-label { font-weight: 600; color: rgba(255,255,255,.75); font-size: .85rem; }
.login-card .form-control {
  background: rgba(255,255,255,.05);
  border: 1.5px solid rgba(255,255,255,.18);
  color: white;
  padding: .75rem 1rem;
  font-size: .9rem;
  transition: all var(--transition);
}
.login-card .form-control::placeholder { color: rgba(255,255,255,.4); }
.login-card .form-control:focus {
  background: rgba(255,255,255,.08);
  border-color: var(--dswd-gold);
  box-shadow: 0 0 0 3px rgba(232,149,44,.18);
}
.login-card .input-group-text {
  background: rgba(255,255,255,.05);
  border: 1.5px solid rgba(255,255,255,.18);
  color: rgba(255,255,255,.6);
}
.login-card .input-group > :not(:first-child) { border-left: none; }
.login-card .input-group > :first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.login-card .input-group > :last-child  { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.login-card .input-group > :not(:first-child):not(:last-child) { border-radius: 0; }
.login-card .input-group .btn {
  background: rgba(255,255,255,.05);
  border: 1.5px solid rgba(255,255,255,.18);
  color: rgba(255,255,255,.6);
}
.login-card .input-group .btn:hover { background: rgba(255,255,255,.1); color: white; }

.login-card .alert-danger  { background: rgba(192,57,43,.18);  border-left-color: var(--dswd-red);  color: #ffc2ba; }
.login-card .alert-warning { background: rgba(232,149,44,.18); border-left-color: var(--dswd-gold); color: #ffdba8; }

.login-forgot {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: .25rem;
  background: none;
  border: none;
  padding: 0;
  font-size: .8rem;
  color: #8ab4f8;
  cursor: pointer;
}
.login-forgot:hover { text-decoration: underline; }

.btn-login {
  width: 100%;
  background: linear-gradient(135deg, var(--dswd-blue), var(--dswd-blue-mid));
  border: none;
  color: white;
  font-weight: 700;
  font-size: .95rem;
  padding: .85rem;
  border-radius: var(--radius-md);
  transition: all var(--transition);
  letter-spacing: .3px;
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(77,14,19,.35); }
.btn-login:active { transform: translateY(0); }

@media (max-width: 480px) {
  .login-card { padding: 1.75rem; }
  .login-brand-header .agency-name { font-size: .85rem; }
  .login-brand-header .login-logo-img { height: 96px; }
}

/* ─── APP LAYOUT ─────────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

/* ─── SIDEBAR ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 1000;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 3px; }

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.sidebar-brand .brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--dswd-gold), #f59e0b);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 1.1rem; font-weight: 800; flex-shrink: 0;
}
.sidebar-brand .brand-text h6 {
  color: white; font-size: .95rem; font-weight: 800; margin: 0;
  line-height: 1.2;
}
.sidebar-brand .brand-text small { color: rgba(255,255,255,.5); font-size: .68rem; display: block; }

.sidebar-section {
  padding: 1rem 0;
}
.sidebar-section-label {
  padding: .25rem 1.5rem;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.3);
  margin-bottom: .25rem;
}

.sidebar-nav { list-style: none; padding: 0; }
.sidebar-nav .nav-item { margin: 1px 0.75rem; }
.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .9rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}
.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,.08);
  color: var(--sidebar-text-hover);
}
.sidebar-nav .nav-link.active {
  background: var(--sidebar-active);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(35,105,164,.4);
}
.sidebar-nav .nav-link i { font-size: 1rem; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar-nav .nav-badge {
  margin-left: auto;
  background: var(--dswd-gold);
  color: white;
  font-size: .65rem;
  font-weight: 700;
  padding: .1rem .45rem;
  border-radius: 99px;
}

.sidebar-user {
  margin-top: auto;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.sidebar-user .user-avatar {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--dswd-blue-mid), var(--dswd-teal));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name  { color: white; font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role  { color: rgba(255,255,255,.45); font-size: .7rem; }
.sidebar-user .logout-btn {
  color: rgba(255,255,255,.4);
  background: none; border: none;
  cursor: pointer; font-size: 1rem;
  transition: color var(--transition);
  padding: .25rem;
}
.sidebar-user .logout-btn:hover { color: #fc8181; }

/* ─── MAIN CONTENT ───────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0; /* flex items default to min-width:auto, letting oversized descendants (e.g. wide tables) push this past the viewport */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden; /* safety net: page itself never scrolls horizontally, only .table-responsive does */
}

.top-bar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: .85rem 1.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.top-bar .breadcrumb { margin: 0; font-size: .82rem; }
.top-bar .breadcrumb-item a { color: var(--dswd-blue); text-decoration: none; }
.top-bar .sidebar-toggle {
  display: none;
  background: none; border: none;
  color: var(--text-secondary); font-size: 1.25rem;
  cursor: pointer; padding: .25rem;
}

.page-content { padding: 1.75rem; flex: 1; }

/* ─── CARDS ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  padding: 1.1rem 1.5rem;
  display: flex; align-items: center; gap: .75rem;
}
.card-header h5, .card-header h6 { margin: 0; font-weight: 700; }
.card-body { padding: 1.5rem; }
.card-footer { background: var(--surface-2); border-top: 1px solid var(--border-light); padding: 1rem 1.5rem; }

/* ─── STAT CARDS ─────────────────────────────────────────────────────────────── */
.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-card.blue::before   { background: var(--dswd-blue); }
.stat-card.teal::before   { background: var(--dswd-teal); }
.stat-card.gold::before   { background: var(--dswd-gold); }
.stat-card.green::before  { background: #16a34a; }
.stat-card.red::before    { background: var(--dswd-red); }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.stat-icon.blue  { background: #dbeafe; color: var(--dswd-blue); }
.stat-icon.teal  { background: #ccfbf1; color: var(--dswd-teal); }
.stat-icon.gold  { background: #fef3c7; color: #d97706; }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.red   { background: #fee2e2; color: var(--dswd-red); }

.stat-info { flex: 1; min-width: 0; }
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1; color: var(--text-primary); }
.stat-label { font-size: .78rem; color: var(--text-muted); font-weight: 500; margin-top: .25rem; text-transform: uppercase; letter-spacing: .4px; }
.stat-sub   { font-size: .75rem; color: var(--text-secondary); margin-top: .35rem; }
.stat-trend { display: flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 600; margin-top: .3rem; }
.stat-trend.up   { color: #16a34a; }
.stat-trend.down { color: var(--dswd-red); }

/* ─── TABLES ─────────────────────────────────────────────────────────────────── */
.table-container { border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { margin: 0; }
/* Wide reports table: force real overflow instead of squeezing columns unreadably,
   so .table-responsive's horizontal scrollbar kicks in on smaller screens. */
#assessments-table { min-width: 1100px; }
.table thead th {
  background: var(--surface-2);
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  padding: .9rem 1rem;
  white-space: nowrap;
}
.table tbody td { padding: .85rem 1rem; vertical-align: middle; border-bottom: 1px solid var(--border-light); font-size: .875rem; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .action-btns { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ─── BUTTONS ────────────────────────────────────────────────────────────────── */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .85rem;
  transition: all var(--transition);
  display: inline-flex; align-items: center; gap: .4rem;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary  { background: var(--dswd-blue);  border-color: var(--dswd-blue);  color: white; }
.btn-primary:hover  { background: var(--primary-hover); border-color: var(--primary-hover); box-shadow: 0 4px 12px rgba(77,14,19,.3); }

.btn-outline-primary { border-color: var(--dswd-blue); color: var(--dswd-blue); }
.btn-outline-primary:hover { background: var(--dswd-blue); color: white; }

.btn-icon { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: var(--radius-sm); }
.btn-icon:hover { transform: translateY(-1px); }

/* ─── FORMS ──────────────────────────────────────────────────────────────────── */
.form-label { font-weight: 600; color: var(--text-secondary); font-size: .82rem; margin-bottom: .4rem; }
.form-control, .form-select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  padding: .55rem .85rem;
  color: var(--text-primary);
  transition: all var(--transition);
  background-color: white;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(77,14,19,.1);
  outline: none;
}

/* ─── BADGES ─────────────────────────────────────────────────────────────────── */
.badge { font-size: .72rem; font-weight: 600; padding: .3em .65em; border-radius: 6px; }
.badge-very-good     { background: #dcfce7; color: #15803d; }
.badge-good          { background: #dbeafe; color: #1d4ed8; }
.badge-fair          { background: #fef9c3; color: #a16207; }
.badge-needs-improvement { background: #fee2e2; color: #dc2626; }

/* ML-predicted risk badges — visually distinct (indigo family + shield icon)
   from the rule-based RIHD rating badges above, so the two are never
   mistaken for one another. */
.badge-risk { border: 1px solid transparent; }
.badge-risk-low      { background: #e0e7ff; color: #4338ca; border-color: #c7d2fe; }
.badge-risk-moderate { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.badge-risk-high     { background: #ffe4e6; color: #be123c; border-color: #fecdd3; }

/* Generic on-brand badges, for counters/tags that aren't a rating or risk level */
.badge-gold { background: var(--dswd-gold); color: white; }
.badge-tag  { background: var(--primary-light); color: var(--primary); }

/* Bootstrap's stock secondary/tab styling, retinted to the app palette */
.btn-secondary, .btn-outline-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-secondary:hover, .btn-outline-secondary:hover {
  background: var(--border-light);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.alert-danger, .alert-warning {
  border: none;
  border-left: 4px solid;
  border-radius: var(--radius-md);
}
.alert-danger  { background: #fff5f5; border-left-color: var(--dswd-red);  color: #7f1d1d; }
.alert-warning { background: #fff8f0; border-left-color: var(--dswd-gold); color: #7c4a03; }

.nav-tabs { border-bottom-color: var(--border); }
.nav-tabs .nav-link {
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: .85rem;
  padding: .65rem 1.1rem;
  transition: all var(--transition);
}
.nav-tabs .nav-link:hover { color: var(--primary); border-color: var(--border); }
.nav-tabs .nav-link.active {
  color: var(--primary);
  background: transparent;
  border-color: var(--primary);
}

/* Ghost button for dark panels (e.g. the score-summary sidebar) */
.btn-ghost-light { background: rgba(255,255,255,.15); color: white; }
.btn-ghost-light:hover { background: rgba(255,255,255,.25); color: white; }

/* ─── ASSESSMENT FORM ────────────────────────────────────────────────────────── */
.assessment-header {
  background: linear-gradient(135deg, var(--dswd-blue-dark), var(--dswd-blue));
  color: white;
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  position: relative;
  overflow: hidden;
}
.assessment-header::after {
  content: 'RIHD';
  position: absolute; right: -10px; bottom: -20px;
  font-size: 6rem; font-weight: 900; color: rgba(255,255,255,.05);
  pointer-events: none;
}

.category-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.category-header {
  padding: 1rem 1.5rem;
  display: flex; align-items: center; gap: .75rem;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.category-header:hover { background: var(--surface-2); }
.category-header h6 { margin: 0; font-weight: 700; font-size: .95rem; }
.category-score-badge {
  margin-left: auto;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 99px;
  padding: .2rem .8rem;
  font-size: .78rem;
  font-weight: 700;
}

.subcategory-section { padding: 0 1.5rem 1rem; }
.subcategory-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--dswd-blue);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: .75rem 0 .5rem;
  border-bottom: 1px dashed var(--border);
  margin-bottom: .75rem;
}

.indicator-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  border-bottom: 1px solid var(--border-light);
}
.indicator-row:last-child { border-bottom: none; }
.indicator-row:hover { background: var(--surface-2); }
.indicator-row.rated { background: #f0fdf4; }

.indicator-text {
  font-size: .82rem;
  color: var(--text-primary);
  line-height: 1.5;
}
.indicator-num {
  display: inline-block;
  width: 20px;
  color: var(--text-muted);
  font-size: .75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.rating-buttons { display: flex; gap: .3rem; flex-shrink: 0; }
.rating-btn {
  width: 36px; height: 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.rating-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.rating-btn.active-1 { background: #fee2e2; color: #dc2626; border-color: #dc2626; }
.rating-btn.active-2 { background: #fef9c3; color: #a16207; border-color: #d97706; }
.rating-btn.active-3 { background: #dbeafe; color: #1d4ed8; border-color: #2563eb; }
.rating-btn.active-4 { background: #dcfce7; color: #15803d; border-color: #16a34a; }

@media (max-width: 576px) {
  .rating-btn { width: 30px; height: 30px; font-size: .72rem; }
  .indicator-row { grid-template-columns: 1fr; gap: .4rem; }
  .rating-buttons { justify-content: flex-start; }
}

/* ─── SCORE SUMMARY PANEL ────────────────────────────────────────────────────── */
.score-summary {
  background: linear-gradient(135deg, var(--dswd-blue-dark), var(--dswd-blue));
  color: white;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  position: sticky;
  top: 80px;
}
.score-summary h6 { color: rgba(255,255,255,.7); font-size: .7rem; text-transform: uppercase; letter-spacing: .5px; }
.score-summary .score-total { font-size: 3rem; font-weight: 900; line-height: 1; color: white; }
.score-summary .score-label { font-size: .8rem; color: rgba(255,255,255,.6); }
.score-summary .score-rating { font-size: 1rem; font-weight: 700; margin-top: .5rem; }
.score-cat-row { display: flex; justify-content: space-between; align-items: center; padding: .35rem 0; border-bottom: 1px solid rgba(255,255,255,.1); font-size: .8rem; }
.score-cat-row:last-child { border-bottom: none; }
.score-cat-row span:first-child { color: rgba(255,255,255,.7); }
.score-cat-row span:last-child  { font-weight: 700; color: white; }

/* ─── VIOLATION CARDS ────────────────────────────────────────────────────────── */
.violation-card {
  border-left: 4px solid;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: .85rem 1rem;
  margin-bottom: .5rem;
  background: white;
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
  display: flex; align-items: flex-start; gap: .75rem;
}
.violation-card.major    { border-left-color: #dc2626; background: #fff5f5; }
.violation-card.serious  { border-left-color: #ea580c; background: #fff7ed; }
.violation-card.moderate { border-left-color: #d97706; background: #fffbeb; }
.violation-card.minor    { border-left-color: #2563eb; background: #eff6ff; }
.violation-card.very_minor { border-left-color: #16a34a; background: #f0fdf4; }

/* ─── DASHBOARD CHARTS ───────────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 280px;
}
.alert-card {
  background: #fff8f0;
  border: 1px solid #fde68a;
  border-left: 4px solid var(--dswd-gold);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex; align-items: center; gap: .75rem;
}
.alert-card.danger { background: #fff5f5; border-color: #fca5a5; border-left-color: #dc2626; }
.alert-card.success { background: #f0fdf4; border-color: #bbf7d0; border-left-color: #16a34a; }

.chart-hint {
  text-align: center;
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: .6rem;
  margin-bottom: 0;
}

/* ─── CLICKABLE STAT CARDS ───────────────────────────────────────────────────── */
.stat-card-clickable { cursor: pointer; }
.stat-card-clickable:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); border-color: var(--primary); }
.stat-card-clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stat-card-clickable:active { transform: translateY(-1px); }

/* ─── TOP-BAR PROFILE WIDGET ─────────────────────────────────────────────────── */
.topbar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .3rem .9rem .3rem .3rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-decoration: none;
  transition: all var(--transition);
  max-width: 220px;
}
.topbar-user:hover { background: var(--primary-light); border-color: var(--primary); }
.topbar-user-avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--dswd-blue-mid), var(--dswd-teal));
  color: white;
  font-size: .75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.topbar-user-info { min-width: 0; line-height: 1.25; }
.topbar-user-name {
  font-size: .8rem; font-weight: 700; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-user-role {
  font-size: .68rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 576px) {
  .topbar-user { max-width: 46px; padding: .3rem; gap: 0; }
  .topbar-user-info { display: none; }
}

/* ─── DASHBOARD DATE-RANGE FILTER ────────────────────────────────────────────── */
.dash-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .75rem 1rem;
  box-shadow: var(--shadow-sm);
}
.dash-filter-label {
  display: flex; align-items: center; gap: .4rem;
  font-size: .78rem; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .4px;
  flex-shrink: 0;
}
.dash-range-group { flex-wrap: wrap; }
.dash-range-group .btn { font-size: .78rem; }
.dash-custom-range { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.dash-custom-range .form-control { width: auto; }
.dash-range-summary { font-size: .78rem; white-space: nowrap; }
@media (max-width: 767px) {
  .dash-filter-bar { align-items: flex-start; }
  .dash-range-summary { width: 100%; order: 99; }
}

/* ─── SKELETON LOADERS ───────────────────────────────────────────────────────── */
@keyframes skeletonPulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.skeleton {
  display: inline-block;
  background: var(--border-light);
  border-radius: var(--radius-sm);
  animation: skeletonPulse 1.4s ease-in-out infinite;
}
.skeleton-line { height: .85em; width: 60%; }
.skeleton-block { width: 100%; height: 100%; border-radius: var(--radius-md); }
.skeleton-row { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; }
.skeleton-avatar { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; }

/* ─── REPORTS ────────────────────────────────────────────────────────────────── */
.report-section { margin-bottom: 2rem; }
.report-section h6 { font-weight: 700; color: var(--dswd-blue); border-bottom: 2px solid var(--border); padding-bottom: .5rem; margin-bottom: 1rem; }

/* ─── RESIDENT PROFILE ───────────────────────────────────────────────────────── */
.resident-avatar {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--dswd-blue), var(--dswd-teal));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 2rem; font-weight: 800;
  flex-shrink: 0;
}
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .85rem; }
.info-item label { display: block; font-size: .72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.info-item span  { font-size: .9rem; font-weight: 500; color: var(--text-primary); }

/* ─── TIMELINE ───────────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before {
  content: ''; position: absolute; left: .7rem; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 1.5rem; }
.timeline-dot {
  position: absolute; left: -1.65rem; top: .25rem;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  background: var(--dswd-blue);
  box-shadow: 0 0 0 2px var(--dswd-blue);
}
.timeline-dot.success { background: #16a34a; box-shadow: 0 0 0 2px #16a34a; }
.timeline-dot.warning { background: #d97706; box-shadow: 0 0 0 2px #d97706; }
.timeline-dot.danger  { background: #dc2626; box-shadow: 0 0 0 2px #dc2626; }
.timeline-content { background: white; border: 1px solid var(--border); border-radius: var(--radius-md); padding: .85rem 1rem; box-shadow: var(--shadow-sm); }
.timeline-meta   { font-size: .75rem; color: var(--text-muted); }

/* ─── MODAL OVERRIDES ────────────────────────────────────────────────────────── */
.modal-content { border-radius: var(--radius-lg); border: none; box-shadow: var(--shadow-lg); }
.modal-header  { border-bottom: 1px solid var(--border-light); padding: 1.25rem 1.5rem; }
.modal-footer  { border-top: 1px solid var(--border-light); padding: 1rem 1.5rem; }
.modal-body    { padding: 1.5rem; }

/* ─── SEARCH BAR ─────────────────────────────────────────────────────────────── */
.search-box {
  position: relative;
  max-width: 320px;
}
.search-box .search-icon {
  position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: .9rem;
}
.search-box input { padding-left: 2.2rem; }

/* ─── PROGRESS BARS ──────────────────────────────────────────────────────────── */
.progress { border-radius: 99px; background: var(--border-light); }
.progress-bar { border-radius: 99px; transition: width .5s ease; }

/* ─── FAMILY PORTAL ──────────────────────────────────────────────────────────── */
.family-header {
  background: linear-gradient(135deg, var(--dswd-blue-dark), var(--dswd-teal));
  color: white;
  padding: 2rem;
  border-radius: var(--radius-lg);
  text-align: center;
  margin-bottom: 1.5rem;
}
.family-header h4 { color: white; font-weight: 800; }
.family-header p  { color: rgba(255,255,255,.75); }

/* ─── EMPTY STATE ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}
.empty-state i { font-size: 3.5rem; color: var(--border); display: block; margin-bottom: 1rem; }
.empty-state h6 { color: var(--text-secondary); font-weight: 600; }
.empty-state p  { font-size: .85rem; }

/* ─── ADMIN ──────────────────────────────────────────────────────────────────── */
.permission-denied {
  display: flex; align-items: center; justify-content: center;
  min-height: 60vh;
  flex-direction: column; gap: 1rem; text-align: center;
}
.permission-denied i { font-size: 4rem; color: #fca5a5; }

/* ─── MOBILE OVERLAY ─────────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
}
.sidebar-overlay.visible { display: block; }

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────────── */
@media (max-width: 991px) {
  :root { --sidebar-width: 260px; }

  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }

  .main-content { margin-left: 0; }

  .top-bar .sidebar-toggle { display: block; }

  .score-summary { position: static; }
  .page-content  { padding: 1rem; }
}

@media (max-width: 576px) {
  .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.5rem; }
  .page-content { padding: .75rem; }
  .card-body    { padding: 1rem; }
}

/* ─── PRINT / PDF STYLES ─────────────────────────────────────────────────────── */
.print-only { display: none; }

.print-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 2px solid #4D0E13;
  padding-bottom: .75rem;
  margin-bottom: 1rem;
}
.print-header img { height: 64px; width: auto; }
.print-header .print-header-text h5 { margin: 0; color: #4D0E13; font-weight: 800; }
.print-header .print-header-text p  { margin: 0; font-size: .8rem; color: #333; }
.print-meta { font-size: .78rem; color: #333; margin-bottom: 1rem; }
.print-meta strong { color: #4D0E13; }
.print-table { width: 100%; border-collapse: collapse; font-size: .75rem; }
.print-table th, .print-table td { border: 1px solid #999; padding: .35rem .5rem; text-align: left; }
.print-table th { background: #f0f0f0; color: #4D0E13; }

@media print {
  .sidebar, .top-bar, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  .print-only { display: block !important; }

  /* .app-layout/.main-content are sized with min-height:100vh for the normal
     on-screen full-height layout. They aren't hidden during print (only their
     children are, via .no-print above) — left alone, that ~100vh empty box
     sits in the flow before #print-area (which lives right before </body>,
     outside .app-layout), pushing all real print content onto page 2. */
  .app-layout, .main-content, .page-content, body { min-height: 0 !important; }
}

/* RIHD assessment print form — a single table so the letterhead/legend/quarter
   header (the thead) repeats automatically at the top of every printed page,
   matching the physical multi-page RIHD form's repeated per-page header. */
.rihd-print-table { width: 100%; border-collapse: collapse; font-size: .62rem; table-layout: fixed; }
.rihd-print-table th, .rihd-print-table td { border: 1px solid #666; padding: .2rem .3rem; text-align: center; vertical-align: middle; }
.rihd-print-table thead th { background: #f0f0f0; }
.rihd-print-table tr { break-inside: avoid; }
.rihd-letterhead-cell { border: none !important; padding: 0 0 .5rem !important; text-align: left; }
.rihd-indicator-col { width: 32%; text-align: left !important; }
.rihd-quarter-group-th { background: #e2e2e2; color: #4D0E13; font-weight: 700; }
.rihd-cat-row td { background: #4D0E13; color: #fff; font-weight: 800; text-align: left !important; padding: .3rem .5rem !important; }
.rihd-subcat-row td { background: #f0e6d2; color: #4D0E13; font-weight: 700; text-align: left !important; padding: .25rem .5rem !important; }
.rihd-mark { font-weight: 900; color: #4D0E13; }

.rihd-resident-info { display: flex; gap: 2rem; font-size: .78rem; margin: .25rem 0; }
.rihd-resident-info strong { color: #4D0E13; }
.rihd-legend-box { border: 1px solid #666; display: inline-block; padding: .3rem .6rem; font-size: .72rem; margin: .4rem 0 .6rem; }
.rihd-legend-box span { margin-right: 1rem; white-space: nowrap; }

/* RIHD official letterhead — logo + agency identification at upper-left (its
   own row), matching the physical form, followed by the centered title
   block (title / adapted-from subtitle / revision date) below it. */
.rihd-print-letterhead { display: flex; align-items: center; gap: .6rem; }
.rihd-print-letterhead img { height: 52px; width: auto; }
.rihd-print-agency-name { font-weight: 800; font-size: .82rem; color: #1a2b8f; }
.rihd-print-agency-office {
  display: inline-block; margin-top: .15rem;
  background: #1a2b8f; color: #fff;
  font-weight: 700; font-size: .68rem;
  padding: .05rem .45rem; border-radius: 2px;
}
.rihd-print-title-block { text-align: center; margin: .35rem 0 .5rem; }
.rihd-print-title-block h4 { margin: 0; font-weight: 800; font-size: 1.1rem; letter-spacing: .2px; }
.rihd-print-subtitle, .rihd-print-revision { margin: .1rem 0 0; font-style: italic; font-size: .7rem; }

/* ─── UTILITIES ──────────────────────────────────────────────────────────────── */
.gap-xs { gap: .35rem; }
.fw-semibold { font-weight: 600; }
.bg-surface { background: var(--surface) !important; }
.bg-surface-2 { background: var(--surface-2) !important; }
.border-bottom-light { border-bottom: 1px solid var(--border-light); }
.rounded-custom { border-radius: var(--radius-md) !important; }
.text-dswd-blue { color: var(--dswd-blue) !important; }
.cursor-pointer { cursor: pointer; }

/* ─── ANIMATIONS ─────────────────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .3s ease both; }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.slide-up { animation: slideUp .4s ease both; }

.stagger-1 { animation-delay: .05s; }
.stagger-2 { animation-delay: .10s; }
.stagger-3 { animation-delay: .15s; }
.stagger-4 { animation-delay: .20s; }
.stagger-5 { animation-delay: .25s; }

/* ─── PWA INSTALL BANNER ─────────────────────────────────────────────────────── */
.pwa-install-banner {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--dswd-blue);
  color: white;
  padding: .75rem 1.5rem;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: .75rem;
  z-index: 9000;
  font-size: .85rem;
  animation: slideUp .4s ease;
  max-width: 90vw;
}
.pwa-install-banner button {
  background: white; color: var(--dswd-blue);
  border: none; border-radius: 99px;
  padding: .35rem .9rem; font-size: .8rem; font-weight: 700; cursor: pointer;
  white-space: nowrap;
}
.pwa-install-banner .close-btn {
  background: none; color: rgba(255,255,255,.6);
  margin-left: .5rem; font-size: 1rem;
}
