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

:root {
  --primary: #1a6b3c;
  --primary-light: #e8f5ee;
  --primary-dark: #0f4a29;
  --accent: #f0a500;
  --danger: #dc3545;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #dee2e6;
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 8px;
}

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

#app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  background: var(--primary-dark);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  min-height: 72px;
}

.brand-icon { font-size: 28px; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 15px; font-weight: 700; }
.brand-text span { font-size: 12px; opacity: 0.8; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  user-select: none;
}

.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,0.12);
  color: white;
  border-left-color: var(--accent);
}

.nav-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }

/* ── Main ── */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.topbar h1 { flex: 1; font-size: 18px; font-weight: 600; color: var(--text); }

.menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
}

.add-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.add-btn:hover { background: var(--primary-dark); }

.content { flex: 1; padding: 24px; overflow-y: auto; }

/* ── Dashboard ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border-left: 4px solid var(--primary);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.15); }
.stat-card:nth-child(2) { border-color: #0066cc; }
.stat-card:nth-child(3) { border-color: #cc6600; }
.stat-card:nth-child(4) { border-color: #cc0000; }
.stat-card:nth-child(5) { border-color: #6600cc; }
.stat-card:nth-child(6) { border-color: #006666; }

.stat-icon { font-size: 38px; }
.stat-info h3 { font-size: 30px; font-weight: 700; line-height: 1; }
.stat-info p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.dashboard-note {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

/* ── Table ── */
.table-container {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.search-input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  width: 260px;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,107,60,0.1); }

.table-count { color: var(--text-muted); font-size: 14px; }

.export-btns { display: flex; gap: 6px; margin-left: auto; }

.btn-export {
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-export:hover { background: var(--primary-light); border-color: var(--primary); }

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead { background: #f8f9fa; }
th {
  padding: 11px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--primary-light); }

.actions { display: flex; gap: 6px; }

.btn-edit, .btn-delete {
  border: none;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.2s;
}
.btn-edit { background: #e7f0ff; color: #0066cc; }
.btn-delete { background: #ffeded; color: var(--danger); }
.btn-edit:hover, .btn-delete:hover { opacity: 0.75; }

/* ── States ── */
.loading {
  text-align: center;
  padding: 50px;
  color: var(--text-muted);
  font-size: 15px;
}

.empty-row td {
  text-align: center;
  padding: 50px !important;
  color: var(--text-muted);
  font-size: 15px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 18px; color: var(--text); }

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }

/* ── Form ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
  color: var(--text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,107,60,0.1);
}

.form-section-title {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 6px;
  margin-top: 6px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  grid-column: 1 / -1;
}

.btn-save {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-save:hover { background: var(--primary-dark); }
.btn-save:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-cancel {
  background: none;
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}
.btn-cancel:hover { background: var(--bg); color: var(--text); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.badge-yes { background: #d4edda; color: #155724; }
.badge-no  { background: #f8d7da; color: #721c24; }

/* ── Section header ── */
.section-header { margin-bottom: 20px; }
.section-title { font-size: 20px; font-weight: 700; color: var(--text); }
.section-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  background: #333;
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 340px;
}
.toast.success { background: var(--primary); }
.toast.error   { background: var(--danger); }

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

/* ── Reports ── */
.report-toolbar {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.report-select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  outline: none;
  cursor: pointer;
  background: var(--primary-light);
  min-width: 260px;
  transition: border-color 0.2s;
}
.report-select:focus { border-color: var(--primary); }

.report-dates {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}
.report-dates label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.report-date-input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.report-date-input:focus { border-color: var(--primary); }

.btn-report-all {
  background: none;
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  white-space: nowrap;
  transition: all 0.2s;
}
.btn-report-all:hover { background: var(--bg); color: var(--text); }

/* ── Form12 filter bar ── */
.f12-filter-bar {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.f12-filter-bar .form-group {
  min-width: 150px;
  flex: 1;
}

.f12-add-btn {
  flex-shrink: 0;
  white-space: nowrap;
  padding: 9px 18px !important;
}

/* ── Form12 Excel-like table ── */
.f12-table {
  font-size: 13px;
  min-width: 100%;
}

.f12-table th {
  background: #1a6b3c;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 10px 10px;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
  border-right: 1px solid rgba(255,255,255,0.15);
  border-bottom: 2px solid #0f4a29;
  position: sticky;
  top: 0;
  z-index: 2;
}

.f12-table td {
  padding: 8px 10px;
  white-space: nowrap;
  border-right: 1px solid #e9ecef;
  border-bottom: 1px solid #e9ecef;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.f12-table tr:hover td { background: #f0f7f3; }
.f12-table tr:nth-child(even) td { background: #fafafa; }
.f12-table tr:nth-child(even):hover td { background: #f0f7f3; }

.f12-serial {
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  min-width: 44px !important;
  max-width: 44px !important;
  background: #f0f7f3 !important;
}

.f12-actions {
  min-width: 160px !important;
  max-width: 160px !important;
  white-space: nowrap;
}

.f12-dash { color: #ccc; }

/* keep old detail styles for backward compat if needed */
.geo-selector-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.detail-empty {
  padding: 30px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Bottom Nav (mobile) ── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--primary);
  z-index: 150;
  flex-direction: row;
  border-top: 2px solid var(--primary-dark);
  height: 58px;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 9px;
  font-weight: 600;
  gap: 2px;
  padding: 6px 2px 4px;
  transition: all 0.2s;
  border-top: 3px solid transparent;
  cursor: pointer;
}
.bnav-icon { font-size: 20px; line-height: 1; }
.bottom-nav-item.active {
  color: white;
  border-top-color: var(--accent);
  background: rgba(255,255,255,0.12);
}

/* ── Sidebar overlay backdrop ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
}
.sidebar-backdrop.visible { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  /* sidebar */
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.35); }
  .main { margin-left: 0; }
  .menu-btn { display: block; }

  /* bottom nav */
  .bottom-nav { display: flex; }

  /* spacing for bottom nav */
  .content { padding: 12px 12px 72px; }
  .toast-container { bottom: 68px; right: 12px; }

  /* topbar */
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar h1 { font-size: 15px; }
  .add-btn { padding: 7px 12px; font-size: 13px; }

  /* dashboard */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 12px; gap: 10px; }
  .stat-icon { font-size: 28px; }
  .stat-info h3 { font-size: 22px; }
  .stat-info p { font-size: 11px; }

  /* filter bar — 2 columns on mobile */
  .f12-filter-bar {
    padding: 12px;
    gap: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .f12-filter-bar .form-group { min-width: 0; flex: unset; }
  .f12-add-btn {
    grid-column: 1 / -1;
    width: 100%;
    text-align: center;
  }

  /* table toolbar */
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }
  .search-input { width: 100%; }
  .export-btns { margin-left: 0; justify-content: flex-end; }
  .table-count { text-align: center; }

  /* form grid */
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full,
  .form-section-title,
  .form-actions { grid-column: 1; }

  /* modal full screen */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 95vh;
    border-radius: 16px 16px 0 0;
  }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }

  /* bigger touch targets */
  .btn-edit, .btn-delete { padding: 7px 12px; font-size: 13px; }
  .btn-export { padding: 8px 14px; font-size: 13px; }
  .nav-item { padding: 14px 16px; font-size: 15px; }

  /* table font smaller on mobile */
  .f12-table { font-size: 12px; }
  .f12-table th, .f12-table td { padding: 8px 8px; }
}
