/* ===== CSS Variables ===== */
:root {
  --green-900: #0d3b20;
  --green-800: #1a6b3c;
  --green-700: #1f8049;
  --green-600: #2a9d5c;
  --green-500: #3cb371;
  --green-400: #5fc98a;
  --green-200: #b8e8cb;
  --green-100: #e6f7ee;
  --green-50:  #f3fbf6;

  --purple-700: #5b3b8f;
  --purple-500: #7c5cbf;
  --purple-100: #ede8f8;

  --orange-700: #b45309;
  --orange-500: #d97706;
  --orange-100: #fef3c7;

  --blue-700: #1d4ed8;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;

  --red-600: #dc2626;
  --red-100: #fee2e2;

  --gray-900: #111827;
  --gray-800: #1f2937;
  --gray-700: #374151;
  --gray-600: #4b5563;
  --gray-500: #6b7280;
  --gray-400: #9ca3af;
  --gray-300: #d1d5db;
  --gray-200: #e5e7eb;
  --gray-100: #f3f4f6;
  --gray-50:  #f9fafb;
  --white:    #ffffff;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  --font-mono: 'SF Mono', 'Consolas', 'Liberation Mono', monospace;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.14);

  --sidebar-w: 280px;
  --header-h:  64px;
  --transition: 180ms ease;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); color: var(--gray-800); background: var(--gray-100); min-height: 100vh; }
a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
select, input { font-family: var(--font); }

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--green-800);
  height: var(--header-h);
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px 0 16px;
  gap: 16px;
}
.header-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-mark { flex-shrink: 0; }
.header-text h1 {
  color: var(--white);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.3px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-subtitle {
  color: rgba(255,255,255,.65);
  font-size: .75rem;
  margin-top: 1px;
}
.header-stats { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.stat-pill {
  background: rgba(255,255,255,.15);
  color: var(--white);
  font-size: .78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.stat-pill.filtered { background: var(--green-600); }

/* ===== Layout ===== */
.app-layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  padding: 16px;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}
.sidebar-title { font-size: .85rem; font-weight: 700; color: var(--gray-700); text-transform: uppercase; letter-spacing: .5px; }
.btn-clear-all {
  font-size: .75rem;
  color: var(--green-700);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--green-200);
  background: var(--green-50);
  transition: background var(--transition);
}
.btn-clear-all:hover { background: var(--green-100); }

.filter-group { margin-bottom: 14px; }
.filter-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 5px;
}
.filter-label svg { opacity: .7; }
.filter-input, .filter-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}
.filter-input:focus, .filter-select:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(60,179,113,.15);
}
.filter-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.filter-select option { color: var(--gray-800); }

.sidebar-summary {
  margin-top: 20px;
  padding: 12px;
  background: var(--green-50);
  border: 1px solid var(--green-200);
  border-radius: var(--radius);
  font-size: .78rem;
  color: var(--gray-700);
  line-height: 1.6;
}
.sidebar-summary strong { color: var(--green-800); }

/* ===== Main content ===== */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-left { display: flex; align-items: center; gap: 4px; }
.toolbar-right { display: flex; align-items: center; gap: 10px; }

.btn-view {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 500;
  color: var(--gray-600);
  background: var(--white);
  border: 1px solid var(--gray-300);
  transition: all var(--transition);
}
.btn-view:hover { border-color: var(--green-400); color: var(--green-700); }
.btn-view.active {
  background: var(--green-800);
  color: var(--white);
  border-color: var(--green-800);
}

.results-label { font-size: .82rem; color: var(--gray-500); }

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 500;
  color: var(--green-800);
  background: var(--green-50);
  border: 1px solid var(--green-200);
  transition: background var(--transition);
}
.btn-export:hover { background: var(--green-100); }

/* ===== Filter Chips ===== */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 10px;
  background: var(--green-100);
  border: 1px solid var(--green-300, #7ecb9a);
  border-radius: 20px;
  font-size: .78rem;
  color: var(--green-800);
  font-weight: 500;
}
.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--green-200);
  color: var(--green-800);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition);
}
.chip-remove:hover { background: var(--green-400); color: var(--white); }

/* ===== View panels ===== */
.view-panel { display: none; }
.view-panel.active { display: block; }

/* ===== Table ===== */
.table-wrapper {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.data-table th {
  padding: 10px 12px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--gray-600);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
  user-select: none;
}
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: var(--green-700); }
.data-table th.sort-asc .sort-icon::after  { content: ' ↑'; }
.data-table th.sort-desc .sort-icon::after { content: ' ↓'; }

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: top;
  line-height: 1.45;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--green-50); }

.td-id {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--gray-500);
  white-space: nowrap;
}
.td-investment { max-width: 220px; font-weight: 500; }
.td-theme, .td-sector, .td-subsector { max-width: 140px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-adapting  { background: var(--orange-100); color: var(--orange-700); }
.badge-adapted   { background: var(--blue-100);   color: var(--blue-700); }
.badge-enabling-m{ background: var(--purple-100); color: var(--purple-700); }
.badge-enabling-a{ background: #e0f2fe;           color: #0369a1; }

.badge-yes { background: var(--green-100); color: var(--green-700); }
.badge-no  { background: var(--gray-100);  color: var(--gray-500); }
.badge-risk{ background: var(--red-100);   color: var(--red-600); }

.badge-hazard {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-detail {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: .75rem;
  font-weight: 500;
  background: var(--green-50);
  color: var(--green-800);
  border: 1px solid var(--green-200);
  transition: background var(--transition);
  white-space: nowrap;
}
.btn-detail:hover { background: var(--green-100); }

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 0 4px;
  flex-wrap: wrap;
}
.pg-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: var(--radius);
  font-size: .82rem;
  color: var(--gray-700);
  background: var(--white);
  border: 1px solid var(--gray-300);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.pg-btn:hover:not(:disabled) { border-color: var(--green-400); color: var(--green-700); }
.pg-btn.active {
  background: var(--green-800);
  color: var(--white);
  border-color: var(--green-800);
  font-weight: 700;
}
.pg-btn:disabled { opacity: .4; cursor: default; }
.pg-info { font-size: .78rem; color: var(--gray-500); padding: 0 6px; }

/* ===== Card view ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-id { font-family: var(--font-mono); font-size: .7rem; color: var(--gray-400); }
.card-solution-badge { flex-shrink: 0; }
.card-title { font-size: .88rem; font-weight: 600; color: var(--gray-900); line-height: 1.4; }
.card-meta { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.card-sector { font-size: .75rem; color: var(--gray-500); }
.card-divider { width: 3px; height: 3px; background: var(--gray-300); border-radius: 50%; }
.card-output {
  font-size: .78rem;
  color: var(--gray-600);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--gray-100);
}
.card-hazard-wrap { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

/* ===== Dashboard ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.dash-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.dash-card-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-500);
  margin-bottom: 14px;
}
.dash-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  font-size: .8rem;
}
.dash-bar-label {
  width: 160px;
  flex-shrink: 0;
  color: var(--gray-700);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-bar-track {
  flex: 1;
  background: var(--gray-100);
  border-radius: 3px;
  height: 8px;
  overflow: hidden;
}
.dash-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--green-500);
  transition: width .4s ease;
}
.dash-bar-count {
  width: 36px;
  text-align: right;
  color: var(--gray-500);
  font-weight: 600;
  font-size: .75rem;
}
.dash-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.dash-stat {
  background: var(--gray-50);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.dash-stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--green-700);
  line-height: 1;
}
.dash-stat-label {
  font-size: .72rem;
  color: var(--gray-500);
  margin-top: 4px;
}

/* Color accents for bar charts */
.dash-bar-fill.blue   { background: var(--blue-500); }
.dash-bar-fill.orange { background: var(--orange-500); }
.dash-bar-fill.purple { background: var(--purple-500); }
.dash-bar-fill.red    { background: var(--red-600); }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 720px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--gray-200);
}
.modal-header-content { flex: 1; min-width: 0; }
.modal-id { font-family: var(--font-mono); font-size: .75rem; color: var(--gray-400); display: block; margin-bottom: 4px; }
.modal-title { font-size: 1.05rem; font-weight: 700; color: var(--gray-900); line-height: 1.35; }
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gray-100);
  color: var(--gray-600);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--gray-200); }
.modal-body { padding: 20px; }

.modal-section { margin-bottom: 18px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-title {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--gray-400);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--gray-100);
}
.modal-row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 6px 12px;
  margin-bottom: 8px;
  font-size: .85rem;
  align-items: baseline;
}
.modal-row-label {
  font-weight: 600;
  color: var(--gray-500);
  font-size: .78rem;
}
.modal-row-value { color: var(--gray-800); line-height: 1.45; }

.modal-highlight {
  background: var(--green-50);
  border: 1px solid var(--green-200);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: .85rem;
  color: var(--gray-700);
  line-height: 1.5;
  margin-bottom: 12px;
}
.modal-highlight strong { color: var(--green-800); }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
}
.empty-state svg { margin-bottom: 16px; opacity: .4; }
.empty-state h3 { font-size: 1rem; color: var(--gray-600); margin-bottom: 6px; }
.empty-state p { font-size: .85rem; }

/* ===== Loading ===== */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--gray-400);
  font-size: .9rem;
  gap: 10px;
}
.spinner-ring {
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--green-500);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  :root { --sidebar-w: 240px; }
}
@media (max-width: 700px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
    padding: 0 16px;
  }
  .sidebar.open { max-height: 1000px; padding: 16px; }
  .header-text h1 { font-size: .88rem; }
  .modal-overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
}
