/* ============================================================
   assets/css/style.css – Village Household Tracking System
   Responsive: phone / tablet / laptop / desktop
   ============================================================ */

:root {
  --sidebar-width : 260px;
  --sidebar-bg    : #0f1f2e;
  --sidebar-hover : #1a3347;
  --sidebar-active: #1e90ff;
  --topbar-height : 58px;
  --primary       : #1e90ff;
  --primary-dark  : #1570cc;
  --accent        : #2ec4b6;
  --danger        : #e74c3c;
  --text-muted    : #6c757d;
  --card-radius   : 12px;
  --body-bg       : #f0f4f8;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--body-bg);
  margin: 0;
  font-size: .9rem;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: #cdd9e5;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 1040;
  transition: transform .25s ease;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.1rem 1.2rem;
  background: rgba(0,0,0,.25);
  font-size: .9rem;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-brand .fw-bold { font-size: .88rem; line-height: 1.3; }

.sidebar-nav {
  flex: 1;
  padding: .5rem 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .7rem 1.2rem;
  color: #b0c4d8;
  text-decoration: none;
  transition: background .2s, color .2s;
  font-size: .875rem;
  min-height: 44px; /* touch target */
}
.sidebar-link:hover  { background: var(--sidebar-hover); color: #fff; }
.sidebar-link.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.sidebar-icon { width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.08);
  margin: .4rem 1rem;
}

/* Sidebar search input */
.sidebar-nav .input-group { flex-wrap: nowrap; }
.sidebar-nav .form-control,
.sidebar-nav .btn { font-size: .8rem; }

/* ============================================================
   SIDEBAR OVERLAY (mobile backdrop)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1039;
}
.sidebar-overlay.active { display: block; }

/* ============================================================
   MAIN AREA
   ============================================================ */
.main-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  transition: margin-left .25s ease;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 1020;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  gap: .5rem;
}
.topbar-title {
  font-weight: 600;
  color: #2c3e50;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.page-content {
  padding: 1.5rem;
  flex: 1;
}

/* ============================================================
   ROLE BADGE
   ============================================================ */
.role-badge {
  background: var(--primary);
  font-size: .68rem;
  padding: .3em .6em;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  border: none;
  border-radius: var(--card-radius);
  box-shadow: 0 2px 12px rgba(0,0,0,.07);
}
.card-header {
  border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
  font-weight: 600;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
  border-radius: var(--card-radius);
  padding: 1rem 1.25rem;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 15px rgba(0,0,0,.12);
}
.stat-card .stat-icon  { font-size: 2.2rem; opacity: .35; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: .78rem; opacity: .85; margin-top: .2rem; }

.bg-stat-1 { background: linear-gradient(135deg,#1e90ff,#0056cc); }
.bg-stat-2 { background: linear-gradient(135deg,#2ec4b6,#1a8f87); }
.bg-stat-3 { background: linear-gradient(135deg,#f7b731,#d4960a); }
.bg-stat-4 { background: linear-gradient(135deg,#a55eea,#7b32c9); }
.bg-stat-5 { background: linear-gradient(135deg,#e74c3c,#c0392b); }
.bg-stat-6 { background: linear-gradient(135deg,#26de81,#17a85a); }

/* ============================================================
   TABLES
   ============================================================ */
.table-responsive {
  border-radius: 0 0 var(--card-radius) var(--card-radius);
  -webkit-overflow-scrolling: touch;
}
.table thead th {
  background: var(--sidebar-bg);
  color: #fff;
  font-weight: 500;
  font-size: .82rem;
  letter-spacing: .03em;
  border: none;
  padding: .65rem .75rem;
  white-space: nowrap;
}
.table tbody td { vertical-align: middle; padding: .6rem .75rem; }
.table tbody tr:hover { background: #f5f8ff; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary   { background: var(--primary);      border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-xs { font-size: .75rem; padding: .2rem .5rem; }

/* Minimum touch size for action buttons */
.btn { min-height: 36px; }
.btn-sm { min-height: 32px; }
.btn-xs { min-height: 28px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label { font-weight: 500; font-size: .85rem; }
.form-control, .form-select { font-size: .875rem; }
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 .2rem rgba(30,144,255,.2);
}

/* ============================================================
   SECTION HEADER
   ============================================================ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
  gap: .5rem;
}
.section-header h4 { margin: 0; font-weight: 700; color: #2c3e50; font-size: 1.1rem; }

/* ============================================================
   NAV TABS (Data Viewer)
   ============================================================ */
.nav-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nav-tabs .nav-link { white-space: nowrap; font-size: .83rem; padding: .5rem .75rem; }

/* ============================================================
   DEVELOPER FOOTER
   ============================================================ */
.dev-footer {
  text-align: center;
  padding: .75rem 1rem;
  font-size: .75rem;
  color: var(--text-muted);
  border-top: 1px solid #dee2e6;
  background: #fff;
  margin-top: auto;
}

/* ============================================================
   COLLAPSED SIDEBAR (desktop toggle)
   ============================================================ */
.sidebar-collapsed .sidebar    { transform: translateX(calc(var(--sidebar-width) * -1)); }
.sidebar-collapsed .main-area  { margin-left: 0; }

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .sidebar, .topbar, .sidebar-overlay,
  .no-print, .section-header .btn,
  .dataTables_filter, .dataTables_length,
  .dataTables_info, .dataTables_paginate { display: none !important; }
  .main-area { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
  table { font-size: 9pt; }
}

/* ============================================================
   RESPONSIVE — TABLET  (768px – 991px)
   ============================================================ */
@media (max-width: 991px) {
  :root { --sidebar-width: 240px; }

  .sidebar { transform: translateX(calc(var(--sidebar-width) * -1)); }
  .main-area { margin-left: 0; }
  .sidebar.open { transform: translateX(0); }

  .page-content { padding: 1.25rem; }

  .stat-card .stat-value { font-size: 1.5rem; }
  .stat-card .stat-icon  { font-size: 1.8rem; }

  /* Stack section-header vertically */
  .section-header { flex-direction: column; align-items: flex-start; }
  .section-header .d-flex { width: 100%; flex-wrap: wrap; }

  /* Topbar title shorter */
  .topbar-title { max-width: 30vw; }
}

/* ============================================================
   RESPONSIVE — LARGE PHONE  (576px – 767px)
   ============================================================ */
@media (max-width: 767px) {
  .page-content { padding: .85rem; }

  /* Stat cards: smaller font on phones */
  .stat-card { padding: .75rem 1rem; }
  .stat-card .stat-value { font-size: 1.3rem; }
  .stat-card .stat-icon  { font-size: 1.5rem; }
  .stat-card .stat-label { font-size: .72rem; }

  /* Tables: smaller text + horizontal scroll */
  .table thead th { font-size: .75rem; padding: .55rem .5rem; }
  .table tbody td { font-size: .78rem; padding: .5rem .5rem; }

  /* Cards: no radius on sides so they stretch edge-to-edge */
  .card { border-radius: 8px; }

  /* Buttons in section-header stack full-width */
  .section-header .btn { width: 100%; text-align: left; }
  .section-header .d-flex.gap-2 { flex-direction: column; }

  /* Tab overflow */
  .nav-tabs { border-bottom: 2px solid #dee2e6; }
  .nav-tabs .nav-link { font-size: .78rem; padding: .45rem .55rem; }
  .nav-tabs .badge { display: none; } /* hide counts on small phones */

  /* Forms */
  .row.g-3 > [class*="col-md"] { width: 100% !important; flex: 0 0 100% !important; max-width: 100% !important; }

  /* Quick action buttons in dashboard */
  .btn.d-flex.flex-column { padding: .75rem .5rem !important; }
  .btn.d-flex.flex-column .fs-4 { font-size: 1.25rem !important; }
  .btn.d-flex.flex-column span { font-size: .7rem; }

  /* Topbar */
  .topbar { padding: 0 .75rem; }
  .topbar-title { font-size: .82rem; max-width: 35vw; }
  .topbar .role-badge { display: none; } /* save space */
}

/* ============================================================
   RESPONSIVE — SMALL PHONE  (< 400px)
   ============================================================ */
@media (max-width: 399px) {
  .page-content { padding: .6rem; }

  .stat-card .stat-value { font-size: 1.1rem; }
  .stat-card .stat-icon  { font-size: 1.2rem; }

  .topbar-title { display: none; } /* only hamburger + icons on tiny screens */

  .table thead th,
  .table tbody td { font-size: .72rem; padding: .4rem .35rem; }
}
