@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap');

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

:root {
  --primary:        #16a34a;
  --primary-dark:   #15803d;
  --primary-light:  #dcfce7;
  --primary-subtle: #f0fdf4;
  --bg:             #f1f5f2;
  --card:           #ffffff;
  --text:           #0f172a;
  --muted:          #64748b;
  --light:          #94a3b8;
  --border:         #e2e8f0;
  --error:          #ef4444;
  --error-light:    #fee2e2;
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      16px;
  --shadow:         0 2px 8px rgba(0,0,0,0.07);
  --shadow-md:      0 4px 16px rgba(0,0,0,0.10);
}

html, body {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

a { color: inherit; text-decoration: none; }

/* ── Login Page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo-dot {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
}

.login-logo-text {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  line-height: 1.2;
}

.login-logo-text span {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-card p {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  background: #fff;
}

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--primary-dark); }

.error-msg {
  background: var(--error-light);
  color: var(--error);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}

/* ── Dashboard Layout ── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--text);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
}

.sidebar-brand {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 11px;
}

.sidebar-brand img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-brand-text { display: flex; flex-direction: column; }

.sidebar-brand-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  transition: background 0.12s, color 0.12s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.sidebar-nav a svg { opacity: 0.8; }

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

.sidebar-footer form button {
  background: none;
  border: 1.5px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  transition: background 0.12s, color 0.12s;
}

.sidebar-footer form button:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

/* Main content */
.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-weight: 700;
  font-size: 18px;
}

.topbar-meta {
  font-size: 13px;
  color: var(--muted);
}

.content {
  padding: 28px;
  flex: 1;
}

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

.stat-card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-card-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-card-value.green { color: var(--primary); }

/* ── Chart Rows ── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow);
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.bar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.bar-label {
  font-size: 13px;
  width: 130px;
  flex-shrink: 0;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.bar-fill.priority-immediate { background: #ef4444; }
.bar-fill.priority-medium    { background: #f59e0b; }
.bar-fill.priority-low       { background: var(--primary); }

.bar-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  min-width: 28px;
  text-align: right;
}

/* ── Reports Table ── */
.table-card {
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 28px;
}

.table-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.table-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.table-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-select {
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  cursor: pointer;
}

.filter-select:focus { border-color: var(--primary); }

.search-input {
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  width: 200px;
}

.search-input:focus { border-color: var(--primary); }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

table {
  width: 100%;
  min-width: 640px; /* forces horizontal scroll rather than squishing */
  border-collapse: collapse;
}

thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--primary-subtle); }

tbody td {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  vertical-align: middle;
}

.cell-muted { color: var(--muted); font-size: 13px; }
.cell-title { font-weight: 500; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-immediate { background: #fee2e2; color: #b91c1c; }
.badge-medium    { background: #fef3c7; color: #92400e; }
.badge-low       { background: var(--primary-light); color: var(--primary-dark); }

.badge-cat {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge-yes { background: var(--primary-light); color: var(--primary-dark); }
.badge-no  { background: var(--bg); color: var(--light); border: 1px solid var(--border); }

/* Desktop/mobile column visibility */
.col-mobile { display: none; text-align: center; }
.col-desktop { display: table-cell; }

/* View button (mobile only) */
.btn-view {
  padding: 6px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}
.btn-view:hover { background: var(--primary-dark); }

/* Pagination */
.pagination {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
  gap: 10px;
}

.pagination-btns {
  display: flex;
  gap: 6px;
}

.page-btn {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}

.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Detail Panel ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
}

.overlay.open { display: block; }

.detail-panel {
  position: fixed;
  top: 0;
  right: -480px;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--card);
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 201;
  display: flex;
  flex-direction: column;
  transition: right 0.25s ease;
  overflow: hidden;
}

.detail-panel.open { right: 0; }

.panel-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.panel-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--muted);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: color 0.1s;
}

.panel-close:hover { color: var(--text); }

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

.panel-section {
  margin-bottom: 20px;
}

.panel-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.panel-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 12px;
}

.panel-field-label {
  font-size: 12px;
  color: var(--light);
  font-weight: 500;
}

.panel-field-value {
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
}

.panel-field-value.empty { color: var(--light); font-style: italic; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}

.media-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-thumb .video-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3);
  color: #fff;
  font-size: 22px;
}

.voice-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--primary-subtle);
  border: 1.5px solid var(--primary-light);
  border-radius: var(--radius-sm);
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.1s;
}

.voice-link:hover { background: var(--primary-light); }

/* ── Loading / Empty ── */
.loading-state, .empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile top bar (hidden on desktop) ── */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--text);
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 150;
  gap: 12px;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-brand img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  border-radius: 50%;
}

.mobile-brand-name {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

/* Animate to × when sidebar is open */
.hamburger.is-open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger.is-open span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.hamburger.is-open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 149;
}

.sidebar-overlay.open { display: block; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  /* Show mobile topbar */
  .mobile-topbar { display: flex; }

  /* Sidebar slides in from left */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .main { margin-left: 0; width: 100%; max-width: 100vw; overflow-x: hidden; }

  /* Hide desktop topbar title on mobile (we have mobile-topbar) */
  .topbar { padding: 12px 16px; }
  .topbar-title { font-size: 16px; }

  .content { padding: 14px; }

  /* Stats grid — 2 columns on mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card-value { font-size: 24px; }

  /* Table — contain width, allow inner horizontal scroll */
  #sectionReports { width: 100%; max-width: 100%; overflow: hidden; }
  .table-card { overflow: visible; width: 100%; max-width: 100%; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; display: block; }
  .table-header { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px; }
  .table-filters { width: 100%; flex-direction: column; max-width: 100%; }
  .search-input { width: 100%; max-width: 100%; box-sizing: border-box; }
  .filter-select { width: 100%; max-width: 100%; box-sizing: border-box; }
  thead th, tbody td { padding: 10px 10px; font-size: 13px; }

  /* Detail panel full-width */
  .detail-panel { width: 100%; right: -100%; }
  .detail-panel.open { right: 0; }
  .panel-header { padding: 16px; }
  .panel-body { padding: 16px; }

  /* Pagination wrap */
  .pagination { flex-direction: column; align-items: flex-start; gap: 8px; }
}

@media (max-width: 768px) {
  /* Show View button column, hide all desktop-only columns */
  .col-mobile  { display: table-cell; }
  .col-desktop { display: none; }

  /* 3-column table that always fits the screen */
  table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }

  /* Date: fixed narrow, View button: fixed narrow, Title: fills the rest */
  thead th:nth-child(1),
  tbody td:nth-child(1) { width: 100px; padding-right: 16px; }

  thead th:nth-child(3),
  tbody td:nth-child(3) { width: 68px; text-align: center; }

  /* Title truncates instead of overflowing */
  .cell-title {
    max-width: none;
    width: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card-label { font-size: 11px; }
  .stat-card-value { font-size: 20px; }
  .login-card { padding: 28px 20px; }
}
