:root{
  /* Light theme variables (green accents) */
  --bg: #ffffff;
  --card:   #fff6ec; ; 
  --muted: #6b766b;
  --text: #0b0b0b;
  --good: #3ccf91;
  --bad: #ff6b6b;
  --accent: #2fa84f;
  --ring: rgba(47,122,75,0.14);
  --radius:18px;
}

/* base */
*{box-sizing:border-box}
html,body{
  margin:0;
  padding:0;
  background:var(--bg);
  color:var(--text);
  font-family:Inter,system-ui,Segoe UI,Arial,sans-serif;
}

/* ===================== LOGIN (auth) ===================== */
.auth{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
}
.auth-card{
  width:100%;
  max-width:420px;
  background:var(--card);
  border:1px solid rgba(0,0,0,0.06);
  border-radius:16px;
  padding:24px 22px;
  box-shadow:0 10px 30px rgba(18,20,18,0.06);
}
.auth-card h1{
  margin:0 0 14px;
  font-size:24px;
  line-height:1.2;
  font-weight:800;
  letter-spacing:.2px;
  color:var(--text);
}
.auth-card .alert{
  background:#fff4f4;
  border:1px solid rgba(255,107,107,0.12);
  color:#7a1111;
  border-radius:12px;
  padding:10px 12px;
  margin:0 0 12px;
  font-size:14px;
}
.auth-card form{display:grid;gap:12px}
.auth-card label{
  display:grid;
  gap:6px;
  font-size:13px;
  color:var(--muted);
}
/* === Light Input Fields for Admin Login (Final Fix) === */
.auth-card input {
  padding: 12px 14px !important;
  border-radius: 12px !important;
  border: 1px solid rgba(0, 0, 0, 0.15) !important;
  background: #ffffff !important;
  color: #111 !important;
  outline: none !important;
  font-weight: 500;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04) !important;
  transition: all 0.2s ease-in-out !important;
}
.auth-card input:focus {
  border-color: #2fa84f !important;
  box-shadow: 0 0 0 3px rgba(47, 168, 79, 0.2) !important;
  background: #ffffff !important;
  color: #000 !important;
}
.auth-card button{
  margin-top:4px;
  background:linear-gradient(135deg,var(--accent),#1f7a39);
  border:none;
  color:white;
  padding:12px 16px;
  border-radius:12px;
  cursor:pointer;
  font-weight:700;
}
.auth-card button:hover{filter:brightness(1.03)}
.auth-card .help{
  margin-top:10px;
  color:var(--muted);
  font-size:12px;
  text-align:center;
}
@media (min-width:480px){
  .auth-card{padding:26px 24px}
  .auth-card h1{font-size:26px}
}

/* ===================== DASHBOARD (dash) ===================== */
.dash{min-height:100vh;display:flex;flex-direction:column}
.topbar{
  position:sticky;
  top:0;
  z-index:5;
  background:rgba(255,255,255,0.9);
  backdrop-filter:blur(4px);
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 18px;
  border-bottom:1px solid rgba(10,20,10,0.04);
  width:100%;
}
.topbar .brand{
  font-weight:800;
  letter-spacing:.2px;
  font-size:20px;
  color:var(--accent);
}
.topbar .user{
  font-size:13px;
  color:var(--muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:60%;
}
.topbar .user a{
  color:var(--accent);
  text-decoration:none;
}

/* container grid preserved */
.container{
  width:100%;
  max-width:1100px;
  margin:0 auto;
  padding:18px 16px 24px;
  display:grid;
  grid-template-columns:1fr;
  gap:16px;
}

/* panels / cards */
.panel{
  background:var(--card);
  border:1px solid var(--ring);
  border-radius:var(--radius);
  padding:16px;
  box-shadow:0 10px 30px rgba(18,20,18,0.04);
}
.panel-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}
.panel h2{
  margin:0;
  font-size:18px;
  line-height:1.2;
  color:var(--text);
}
.controls{
  display:flex;
  align-items:center;
  gap:8px;
  font-size:14px;
  color:var(--muted);
  flex-wrap:wrap;                 /* NEW: responsive wrap */
}
.controls select{
  padding:9px 12px;
  border-radius:12px;
  border:1px solid rgba(10,20,10,0.06);
  background:#fff;
  color:var(--text);
  outline:none;
  height:40px;                    /* NEW: unify height */
}
.controls select:focus{
  box-shadow:0 0 0 4px rgba(47,168,79,0.06);
}

/* small input control (used in House Report controls) */
.input-sm{
  padding:10px 12px;
  border-radius:10px;
  border:1px solid rgba(10,20,10,0.06);
  background:#fff;
  color:var(--text);
  outline:none;
  min-width:160px;
  height:40px;                    /* NEW: slightly taller */
  line-height:20px;
}

/* KPI cards */
.kpis{
  display:grid;
  grid-template-columns:1fr;
  gap:12px;
  margin:8px 0 12px;
}
.kpi{
  background:#ffffff;
  border:1px solid rgba(10,20,10,0.04);
  border-radius:14px;
  padding:12px;
  display:flex;
  justify-content:space-between;
  align-items:end;
}
.k-title{
  font-size:12px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.5px;
}
.k-title.good{color:var(--good)}
.k-title.bad{color:var(--bad)}
.k-value{
  font-size:24px;
  font-weight:800;
  margin-top:2px;
}

/* chart container */
.chart-wrap{
  width:100%;
  max-width:100%;
  border:1px dashed rgba(10,20,10,0.02);
  border-radius:12px;
  overflow:hidden;
  height:280px;
}
canvas{width:100% !important;height:100% !important}

/* tables */
.table-wrap, table{
  width:100%;
  border-collapse:collapse;
  color:var(--text);
}
table{
  color:#000000;
  background:transparent;
}
table th, table td{
  padding:10px 12px;
  border:1px solid rgba(0,0,0,0.12);
  text-align:left;
  vertical-align:middle;
  color:#000;
}
table thead th{
  font-weight:700;
  background:rgba(0,0,0,0.02);
  color:#000;
}

/* footer */
.footer{
  padding:14px 16px 24px;
  color:var(--muted);
  text-align:center;
  font-size:13px;
}

/* breakpoints */
@media (min-width:520px){
  .topbar .brand{font-size:22px}
  .kpis{grid-template-columns:repeat(3,minmax(0,1fr))}
}
@media (min-width:768px){
  .panel h2{font-size:20px}
  .chart-wrap{height:320px}
}
@media (min-width:1024px){
  .topbar .brand{font-size:24px}
  .container{grid-template-columns:1fr}
}

/* topbar small-screen fix */
@media (max-width:520px){
  .topbar{
    flex-direction:column;
    align-items:flex-start;
    gap:4px;
    padding:12px 14px;
  }
  .topbar .brand{font-size:18px}
  .topbar .user{
    font-size:12px;
    white-space:normal;
    max-width:100%;
    color:var(--muted);
  }
  .topbar .user a{
    display:inline-block;
    margin-left:6px;
    padding:4px 8px;
    border:1px solid rgba(10,20,10,0.04);
    border-radius:8px;
    background:#fff;
    text-decoration:none;
  }
}

/* headings */
h1,h2,h3,.panel h2,.title{ color:#000 !important; }

/* base controls */
input, textarea, select {
  background:#fff;
  color:var(--text);
  border:1px solid rgba(10,20,10,0.06);
}

/* buttons */
.btn, .btn-accent, .download-btn, .controls button{
  background: linear-gradient(135deg,var(--accent),#1f7a39);
  color:#fff;
  border:none;
  padding:8px 10px;
  border-radius:8px;
  cursor:pointer;
  font-weight:600;
}

/* table download button styling */
.table-download{
  background:#fff;
  border:1px solid rgba(0,0,0,0.08);
  color:#000;
  padding:6px 8px;
  border-radius:6px;
  cursor:pointer;
}

/* very small screens */
@media (max-width:420px){
  body{padding:12px;}
  .container{padding:12px;}
  .title, h1{ text-align:center; }
  .controls .input-sm, .controls select { min-width:130px; flex:1 1 140px; }
  .controls .btn{ flex:1 1 120px; }
}

/* Accessibility helper */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ========== House report combo + card ========== */
.combo-list{
  margin:0 0 10px 0;
  padding:0;
  list-style:none;
  border:1px solid rgba(0,0,0,0.12);
  border-radius:10px;
  background:#fff;
  max-height:220px;
  overflow:auto;
}
.combo-item{
  padding:10px 12px;
  border-bottom:1px solid rgba(0,0,0,0.06);
  cursor:pointer;
}
.combo-item:last-child{ border-bottom:none; }
.combo-item:hover, .combo-item:focus{
  background: rgba(47,168,79,0.06);
  outline: none;
}

.house-card{
  background:#ffffff;
  border:1px solid rgba(10,20,10,0.06);
  border-radius:12px;
  padding:12px;
}
.house-card .info-grid{
  display:grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap:10px;
}
.house-card .label{
  font-size:11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.house-card .value{
  font-size:16px;
  font-weight:700;
  color:#000;
}
@media (min-width:640px){
  .house-card .info-grid{ grid-template-columns: repeat(4,minmax(0,1fr)); }
}
/* make label sit vertically centered beside 40px-high selects */
.controls label{
  margin: 0 4px 0 0;
  line-height: 40px;      /* ⬅︎ aligns label with select height */
  display: inline-block;
}
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;                               /* was 5 */
  background:#ffffff;                        /* opaque (no overlap transparency) */
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 18px;
  border-bottom:1px solid rgba(10,20,10,0.06);
  width:100%;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);   /* gentle separation */
}

/* give the first panel a breathing room under sticky header */
.topbar + .container{
  margin-top: 8px;
}

/* also help in-page anchors not hide under sticky header */
html{ scroll-padding-top: 64px; }
/* for panels where heading should be on 1st row and controls on 2nd */
.panel-head.stack{
  flex-direction: column;         /* ⬅︎ puts controls below the h2 */
  align-items: flex-start;
  gap: 10px;
}
.panel-head.stack .controls{
  justify-content: flex-start;    /* ⬅︎ left aligned controls row */
  width: 100%;
  flex-wrap: wrap;
}

/* House Report control sizes: shorter width, taller height */
#house-search.input-sm{
  width: 180px;                   /* ⬅︎ not too long */
  height: 40px;                   /* ⬅︎ slightly taller */
}
#house-select.input-sm,
#hr-ward.input-sm{
  height: 40px;
}

/* keep buttons same height as inputs for clean row */
.controls .btn{
  height: 40px;
  display: inline-flex;
  align-items: center;
}
@media (max-width: 520px){
  .panel-head.stack .controls .input-sm,
  .panel-head.stack .controls select{
    min-width: 140px;
    flex: 1 1 160px;
  }
  .panel-head.stack .controls .btn{
    flex: 1 1 120px;
  }
}
/* House Report: push Download CSV to the right on wide screens */
@media (min-width: 900px){
  .panel-head.stack .controls{
    display: flex;         /* ensure a single row when there's space */
    align-items: center;
  }
  /* Move only the House Report CSV button to the right edge */
  .panel-head.stack .controls #house-download-csv{
    margin-left: auto;     /* 👈 pushes it to the right */
  }
}

/* ================== TOPBAR: make it fixed & prevent overlap ================== */
:root{
  --topbar-h: 64px;              /* default height */
}
@media (max-width:520px){
  :root{ --topbar-h: 60px; }     /* a bit shorter on small screens */
}

.topbar{
  position: fixed !important;    /* was sticky; fixed removes scroll-under issue */
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  z-index: 1000;
  background: #ffffff;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px 18px;            /* keep it comfy */
  border-bottom:1px solid rgba(10,20,10,0.06);
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* give content room under fixed header */
body.dash{
  padding-top: calc(var(--topbar-h) + 8px) !important;
}

/* undo any old margin we added earlier */
.topbar + .container{ margin-top: 0 !important; }

/* ================== ALIGN 'Ward:' label nicely in headers ================== */
.panel-head .controls{
  display: flex;
  align-items: center;           /* centers label with 40px inputs */
  gap: 8px;
  flex-wrap: wrap;
}
.controls label{
  margin: 0 4px 0 0;
  line-height: 1;                /* let align-items handle centering */
}

/* ================== HOUSE REPORT header stacked layout (kept) ================== */
.panel-head.stack{
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.panel-head.stack .controls{
  justify-content: flex-start;
  width: 100%;
}

/* inputs/buttons same height and tidy widths */
.input-sm,
.controls select,
.controls .btn{
  height: 40px;
}
#house-search.input-sm{ width: 180px; }

/* House Report: push its CSV button to right on wide screens */
@media (min-width: 900px){
  .panel-head.stack .controls #house-download-csv{
    margin-left: auto;
  }
}
/* ================== FIX: Show "Logged in as ..." text under heading on mobile ================== */

/* Base topbar layout */
.topbar{
  flex-wrap: wrap;                  /* allow wrapping of user text below brand */
  align-items: center;
  justify-content: space-between;
}

/* brand and user text spacing */
.topbar .brand{
  flex: 1 1 auto;
  font-weight: 800;
  font-size: 20px;
  color: var(--accent);
}

/* keep user info visible even if it wraps */
.topbar .user{
  flex: 1 1 100%;                   /* let it go to next line if needed */
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

/* slightly smaller layout for mobile screens */
@media (max-width:520px){
  .topbar{
    flex-direction: column;
    align-items: flex-start;
    height: auto !important;       /* let height grow naturally */
    padding: 10px 14px;
  }
  .topbar .brand{
    font-size: 18px;
  }
  .topbar .user{
    text-align: left;
    font-size: 12px;
    margin-top: 4px;
  }
}

/* Ensure page padding adjusts for dynamic topbar height */
body.dash{
  padding-top: calc(var(--topbar-h) + 20px) !important;
}
