* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --info: #06b6d4;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
  --radius: 8px;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ============ APP SIDEBAR ============ */
.has-sidebar { display: flex; }

.app-sidebar {
  width: 240px;
  min-height: 100vh;
  background: linear-gradient(180deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand-icon { font-size: 2rem; }
.sidebar-brand-title { color: white; font-size: 1.05rem; font-weight: 700; line-height: 1.2; }
.sidebar-brand-sub { color: rgba(255,255,255,0.45); font-size: 0.7rem; }

.sidebar-menu { flex: 1; padding: 0.5rem 0; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 1.2rem;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.sidebar-item:hover {
  background: rgba(255,255,255,0.07);
  color: white;
}

.sidebar-item.active {
  background: rgba(124,58,237,0.35);
  color: white;
  border-left-color: #a78bfa;
  font-weight: 700;
}

.sidebar-icon { font-size: 1.1rem; width: 24px; text-align: center; flex-shrink: 0; }

.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 0.5rem 1rem;
}

.sidebar-item-special {
  color: rgba(6,182,212,0.85);
}
.sidebar-item-special:hover { color: #22d3ee; background: rgba(6,182,212,0.1); }

.sidebar-item-admin {
  color: rgba(251,146,60,0.85);
}
.sidebar-item-admin:hover { color: #fb923c; background: rgba(251,146,60,0.1); }

.sidebar-footer {
  padding: 1rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.main-content {
  margin-left: 240px;
  flex: 1;
  min-width: 0;
  max-width: 1400px;
  padding: 1.5rem;
}

/* Mobile top bar (hidden on desktop) */
.mobile-topbar {
  display: none;
  position: sticky; top: 0; z-index: 120;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  color: white;
  padding: 0.75rem 1rem;
  align-items: center;
  gap: 0.75rem;
}
.mobile-menu-btn {
  background: none; border: none; color: white; font-size: 1.4rem; cursor: pointer; padding: 0.2rem 0.5rem;
}
.mobile-title { font-weight: 700; font-size: 1rem; }
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 140;
}

@media (max-width: 768px) {
  .has-sidebar { display: block; }
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .app-sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .mobile-topbar { display: flex; }
  .main-content { margin-left: 0; padding: 1rem; }
}

/* Old navbar (used by admin/inspector pages) */
.navbar {
  background: linear-gradient(135deg, #4c1d95 0%, #7c3aed 100%);
  color: white;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.nav-brand {
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 200px;
}

.nav-icon { font-size: 1.5rem; }

.nav-links {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-link {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.2);
  color: white;
}

.admin-link {
  background: rgba(239,68,68,0.3) !important;
  border: 1px solid rgba(239,68,68,0.5);
}

.admin-link:hover { background: rgba(239,68,68,0.5) !important; }

.nav-actions { display: flex; gap: 0.5rem; min-width: 120px; justify-content: flex-end; }

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-info { background: var(--info); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-full { width: 100%; justify-content: center; }

/* Container (admin/inspector pages) */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* Pages */
.page { display: none; }
.page.active { display: block; }

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text);
  border-bottom: 3px solid var(--primary);
  padding-bottom: 0.5rem;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  border-left: 4px solid;
}

.stat-blue { border-color: var(--primary); }
.stat-green { border-color: var(--success); }
.stat-yellow { border-color: var(--warning); }
.stat-red { border-color: var(--danger); }

.stat-number { font-size: 2rem; font-weight: 800; }
.stat-blue .stat-number { color: var(--primary); }
.stat-green .stat-number { color: var(--success); }
.stat-yellow .stat-number { color: var(--warning); }
.stat-red .stat-number { color: var(--danger); }
.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.chart-card h3 { margin-bottom: 1rem; font-size: 1rem; color: var(--text-muted); }

/* Zone Summary */
.zone-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.zone-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border-left: 4px solid;
  cursor: pointer;
  transition: transform 0.2s;
}

.zone-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.zone-card h4 { font-size: 0.95rem; margin-bottom: 0.25rem; }
.zone-card .count { font-size: 1.5rem; font-weight: 800; }
.zone-card .label { font-size: 0.75rem; color: var(--text-muted); }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card h3 { margin-bottom: 1rem; font-size: 1rem; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 1rem; }

/* Filters */
.filters {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  background: var(--card);
  padding: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  align-items: flex-end;
}

.filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-group label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }

.filter-group select, .filter-group input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  min-width: 150px;
}

/* Tables */
.tasks-table-container, .logs-table-container { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th {
  background: #f8fafc;
  padding: 0.75rem;
  text-align: left;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

tr:hover { background: #f8fafc; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 50px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-cat { color: white; }
.badge-freq { background: #ede9fe; color: #6d28d9; }
.badge-zone { color: white; font-size: 0.65rem; }

.badge-status-completed { background: #dcfce7; color: #166534; }
.badge-status-in_progress { background: #fef3c7; color: #92400e; }
.badge-status-pending { background: #e0f2fe; color: #0369a1; }
.badge-status-issue { background: #fee2e2; color: #991b1b; }

/* Frequency Tabs */
.frequency-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.freq-tab {
  padding: 0.5rem 1rem;
  border: 2px solid var(--border);
  border-radius: 50px;
  background: var(--card);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s;
}

.freq-tab:hover { border-color: var(--primary); color: var(--primary); }
.freq-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Schedule Grid */
.schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1rem;
}

.schedule-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
  transition: transform 0.2s;
  cursor: pointer;
}

.schedule-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.schedule-card h4 { font-size: 0.95rem; margin-bottom: 0.5rem; }
.schedule-card .meta { font-size: 0.8rem; color: var(--text-muted); }
.schedule-card .method { font-size: 0.8rem; color: var(--primary); margin-top: 0.25rem; }
.schedule-card .houses { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

.schedule-card .actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Task List / Log List */
.task-list, .log-list { max-height: 400px; overflow-y: auto; }

.task-item, .log-item {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.task-item:last-child, .log-item:last-child { border-bottom: none; }

.task-item-name { font-weight: 600; font-size: 0.85rem; flex: 1; }
.task-item-meta { font-size: 0.75rem; color: var(--text-muted); }

.log-item-info { flex: 1; }
.log-item-name { font-weight: 600; font-size: 0.85rem; }
.log-item-date { font-size: 0.75rem; color: var(--text-muted); }

/* Overdue */
.overdue-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--danger);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.overdue-info { flex: 1; }
.overdue-info h4 { font-size: 0.95rem; }
.overdue-info .meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.overdue-days { color: var(--danger); font-weight: 700; font-size: 0.9rem; min-width: 100px; text-align: right; }

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-lg { max-width: 800px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.1rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
}

.modal-close:hover { color: var(--danger); }

.modal-content form, #detail-body { padding: 1.5rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 0.25rem; color: var(--text-muted); }

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.form-group textarea { resize: vertical; }
.form-static { font-weight: 600; padding: 0.5rem 0; }

/* Detail sections */
.detail-section { margin-bottom: 1.5rem; }
.detail-section h4 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.detail-item label { font-size: 0.75rem; color: var(--text-muted); display: block; }
.detail-item .value { font-weight: 600; font-size: 0.9rem; }

/* Link styling */
.clickable-link {
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
}

.clickable-link:hover { color: var(--primary-dark); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
  .navbar { flex-wrap: wrap; height: auto; padding: 0.75rem; }
  .nav-links { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; padding-top: 0.5rem; }
  .charts-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .schedule-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; }
  .filter-group select, .filter-group input { min-width: 100%; }
  .zone-summary { grid-template-columns: repeat(2, 1fr); }
}

/* Admin-specific */
.admin-header {
  background: linear-gradient(135deg, #4c1d95 0%, #7c3aed 100%);
  color: white;
  padding: 1.5rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.admin-header h1 { font-size: 1.5rem; }
.admin-header p { opacity: 0.8; font-size: 0.9rem; }

.admin-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.admin-tab {
  padding: 0.6rem 1.2rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.admin-tab:hover { border-color: var(--primary); color: var(--primary); }
.admin-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

.admin-section { display: none; }
.admin-section.active { display: block; }

.admin-form {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.admin-form h3 { margin-bottom: 1rem; }

.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-row .form-group { flex: 1; min-width: 150px; }

.admin-table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.house-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.house-check {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg);
  border-radius: 4px;
  font-size: 0.8rem;
}

.house-check input { width: auto; }

/* Severity indicators */
.sev-dot { display:inline-block; width:12px; height:12px; border-radius:50%; margin-right:4px; vertical-align:middle; }
.sev-never { background:#7f1d1d; }
.sev-critical { background:#dc2626; }
.sev-moderate { background:#f59e0b; }
.sev-mild { background:#facc15; }

.sev-bar { display:flex; height:8px; border-radius:4px; overflow:hidden; }
.sev-bar > div { height:100%; }

.overdue-house-card { background:var(--card); border-radius:var(--radius); padding:1rem; margin-bottom:.75rem; box-shadow:var(--shadow); border-left:4px solid var(--border); }
.overdue-house-card.has-critical { border-left-color:#dc2626; }
.overdue-house-card.has-never { border-left-color:#7f1d1d; }
.overdue-house-card.has-moderate { border-left-color:#f59e0b; }
.overdue-house-card.has-mild { border-left-color:#facc15; }

.overdue-expand { max-height:0; overflow:hidden; transition:max-height .3s ease; }
.overdue-expand.open { max-height:2000px; }

.sev-badge { display:inline-block; padding:.1rem .45rem; border-radius:50px; font-size:.68rem; font-weight:700; color:white; }
.sev-badge-never { background:#7f1d1d; }
.sev-badge-critical { background:#dc2626; }
.sev-badge-moderate { background:#f59e0b; color:#000; }
.sev-badge-mild { background:#facc15; color:#000; }

/* Daily Task List (read-only) */
.daily-task-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.daily-task-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.daily-task-row:last-child { border-bottom: none; }
.daily-task-row:hover { background: #f8fafc; }

.daily-num {
  min-width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.daily-task-info { flex: 1; min-width: 0; }

.daily-task-name {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}

.daily-task-room {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}
