/* ── Variables ─────────────────────────────────────────────────── */
:root {
  --primary:    #52A79B;
  --primary-dk: #3d8a7f;
  --navy:       #152F37;
  --teal-light: #C6E3DF;
  --sand:       #F3F0EC;
  --coral:      #E25563;
  --purple:     #7F77DD;
  --cyan:       #1DACEA;
  --text:       #152F37;
  --text-muted: #6b7c80;
  --border:     #d8e8e6;
  --bg:         #F3F0EC;
  --white:      #ffffff;
  --radius:     8px;
  --shadow:     0 1px 4px rgba(21,47,55,.08);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Montserrat', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Layout ────────────────────────────────────────────────────── */
#dashboard { max-width: 1200px; margin: 0 auto; padding: 16px 20px 40px; }

/* ── Header ────────────────────────────────────────────────────── */
.dash-header {
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.dash-header svg { flex-shrink: 0; }
.dash-header h1 { font-family: 'Sora', sans-serif; font-size: 18px; font-weight: 700; }
.dash-header .sub { font-size: 11px; opacity: .7; margin-top: 3px; }
.dash-header .spacer { flex: 1; }
.dash-header .meta { font-size: 11px; opacity: .6; text-align: right; }

/* ── Controls bar ──────────────────────────────────────────────── */
.controls {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
}
.controls label { font-size: 11px; font-weight: 500; color: var(--text-muted); }
.controls select, .controls input[type=text] {
  font-family: 'Montserrat', sans-serif;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  background: var(--white);
  color: var(--text);
}
.ctrl-sep { width: 1px; height: 18px; background: var(--border); }
.cat-chips { display: flex; gap: 4px; align-items: center; }
.cat-chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 12px;
  border: 1.5px solid transparent; cursor: pointer; transition: .15s;
  user-select: none;
}
.cat-chip.national  { background: #e8f5f3; color: #0F5F53; border-color: var(--primary); }
.cat-chip.ogsl      { background: #e5f4fd; color: #084a6e; border-color: var(--cyan); }
.cat-chip.atlantic  { background: #fdecea; color: #7a1a24; border-color: var(--coral); }
.cat-chip.pacific   { background: #ddeef5; color: #084a6e; border-color: #0F6D8E; }
.cat-chip.amundsen  { background: #f3eafa; color: #5b2e82; border-color: #9B59B6; }
.cat-chip.off { opacity: .38; border-color: transparent; }

.ctrl-spacer { flex: 1; }
.ctrl-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 5px; }

/* ── Export dropdown ───────────────────────────────────────────── */
.export-dropdown { position: relative; }
.export-menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--white); border: 1px solid var(--border);
  border-radius: 7px; box-shadow: 0 4px 16px rgba(21,47,55,.13);
  z-index: 200; min-width: 160px; overflow: hidden;
}
.export-item {
  display: flex; align-items: baseline; gap: 6px;
  width: 100%; padding: 8px 14px; text-align: left;
  background: none; border: none; cursor: pointer;
  font-family: 'Montserrat', sans-serif; font-size: 11px; font-weight: 600;
  color: var(--navy);
}
.export-item:hover { background: var(--sand); }
.export-item-sub { font-size: 10px; font-weight: 400; color: var(--text-muted); }
.btn {
  font-family: 'Montserrat', sans-serif;
  font-size: 11px; font-weight: 600;
  padding: 5px 10px; border-radius: 6px; border: none;
  cursor: pointer; display: flex; align-items: center; gap: 5px; transition: .15s;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover   { background: var(--primary-dk); }
.btn-outline   { background: transparent; color: var(--navy); border: 1.5px solid var(--border); }
.btn-outline:hover   { background: var(--sand); }
.btn-settings  { background: var(--sand); color: var(--navy); border: 1.5px solid var(--border); }
.btn-settings:hover  { background: #e8e4dd; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── KPI tiles ─────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 8px; }
.kpi {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 11px; color: var(--primary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-family: 'Sora', sans-serif; font-size: 28px; font-weight: 700; color: var(--navy); margin-top: 4px; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.kpi-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.kpi-delta  { font-size: 11px; font-weight: 600; margin-top: 3px; min-height: 15px; }
.kpi-delta.up   { color: #1a7f4b; }
.kpi-delta.down { color: #c0392b; }
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 10px; font-size: 10px; font-weight: 600; white-space: nowrap;
}
.badge-doi   { background: var(--teal-light); color: #0F5F53; }
.badge-orcid { background: #e8f7f0; color: #1a6640; }
.badge-ror   { background: #e8e4f7; color: #4a3aaa; }
.badge-national  { background: #e8f5f3; color: #0F5F53; }
.badge-ogsl      { background: #e5f4fd; color: #084a6e; }
.badge-atlantic  { background: #fdecea; color: #7a1a24; }
.badge-pacific   { background: #f0ebe0; color: #6b4c1e; }
.badge-amundsen  { background: #f3eafa; color: #5b2e82; }

/* ── UpSet plot ────────────────────────────────────────────── */
.upset-wrap { overflow-x: auto; }
.upset-svg text { font-family: 'Montserrat', sans-serif; }

/* ── Panels ────────────────────────────────────────────────────── */
.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel h3 {
  font-family: 'Sora', sans-serif; font-size: 13px; font-weight: 600;
  color: var(--navy); margin-bottom: 12px;
  border-bottom: 2px solid var(--teal-light); padding-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.panel h3 .panel-actions { display: flex; gap: 6px; }
.panel-note { font-size: 10px; color: var(--text-muted); margin-top: 8px; }

/* ── Grid layouts ──────────────────────────────────────────────── */
.grid-1   { margin-bottom: 14px; }
.grid-2   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid-3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid-3-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-bottom: 14px; }

/* ── Charts ────────────────────────────────────────────────────── */
.chart-wrap { position: relative; }
.chart-h240 { height: 240px; }
.chart-h280 { height: 280px; }
.chart-h320 { height: 320px; }

/* ── PID section ───────────────────────────────────────────────── */
.pid-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.pid-kpi  { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.pid-kpi-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.pid-kpi-value { font-size: 20px; font-weight: 600; color: var(--navy); }
.pid-kpi-pct   { font-size: 12px; color: var(--text-muted); margin-left: 4px; font-weight: 400; }
.pid-kpi-sub   { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.pid-charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.pid-kpi-btn { cursor: pointer; transition: border-color .15s, box-shadow .15s; user-select: none; }
.pid-kpi-btn:hover { border-color: var(--primary); }
.pid-kpi-btn.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(82,167,155,.18); }
#pid-detail-table th, #pid-detail-table td { padding: 5px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
#pid-detail-table th { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--bg); position: sticky; top: 0; z-index: 1; }
#pid-detail-table td:first-child { white-space: normal; max-width: 260px; }
#pid-detail-table tbody tr:hover { background: var(--bg); }
#pid-detail-table a { color: var(--primary); text-decoration: none; }
#pid-detail-table a:hover { text-decoration: underline; }

/* ── Map ───────────────────────────────────────────────────────── */
#map { height: 360px; border-radius: 6px; }
.map-controls { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; align-items: center; }
.map-toggle {
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 10px;
  border: 1.5px solid var(--border); cursor: pointer; background: var(--white);
  color: var(--text-muted); transition: .15s;
}
.map-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Table ─────────────────────────────────────────────────────── */
.table-controls { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.table-controls input {
  font-family: 'Montserrat', sans-serif; font-size: 12px;
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px;
  background: var(--white); color: var(--text); flex: 1; min-width: 200px;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  background: var(--sand); color: var(--navy); font-weight: 600;
  padding: 8px 10px; text-align: left; position: sticky; top: 0;
  white-space: nowrap; cursor: pointer; user-select: none;
}
th:hover { background: var(--teal-light); }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #e8f5f3; }
.cell-title { max-width: 240px; font-size: 11.5px; }
.cell-title a { color: var(--navy); text-decoration: none; }
.cell-title a:hover { color: var(--primary); text-decoration: underline; }
.eov-list { display: flex; flex-wrap: wrap; gap: 3px; }
.badge-eov { background: #eef7f6; color: #1a5a52; font-size: 9.5px; padding: 1px 6px; border-radius: 8px; font-weight: 500; }
.bar-cell { display: flex; align-items: center; gap: 6px; }
.bar-bg { flex: 1; background: #eee; border-radius: 3px; height: 6px; min-width: 40px; }
.bar-fill { height: 6px; border-radius: 3px; background: var(--primary); }
.num { font-weight: 600; font-size: 12px; color: var(--navy); min-width: 28px; text-align: right; }
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 12px; align-items: center; font-size: 12px; color: var(--text-muted); }
.page-btn { padding: 4px 10px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; background: var(--white); font-size: 12px; }
.page-btn:hover { background: var(--sand); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Settings drawer ───────────────────────────────────────────── */
#settings-drawer {
  display: none; background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
#settings-drawer.open { display: block; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.setting-group h4 { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.setting-item { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; cursor: pointer; }
.setting-item input[type=checkbox] { accent-color: var(--primary); width: 14px; height: 14px; }

/* ── Loading overlay ───────────────────────────────────────────── */
#loading {
  position: fixed; inset: 0; background: rgba(21,47,55,.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 9999; color: #fff; gap: 16px;
}
#loading.hidden { display: none; }
.spinner {
  width: 40px; height: 40px; border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-msg { font-size: 14px; font-weight: 500; }

/* ── Section visibility ────────────────────────────────────────── */
.section-hidden { display: none !important; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #dashboard { padding: 12px 12px 30px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3, .grid-3-1 { grid-template-columns: 1fr; }
  .pid-kpis { grid-template-columns: 1fr 1fr; }
  .pid-charts-grid { grid-template-columns: 1fr; }
  #map { height: 260px; }
  .settings-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
@media (max-width: 480px) {
  #dashboard { padding: 8px 8px 20px; }
  .panel h3 { flex-wrap: wrap; }
  .panel h3 > span { flex: 0 0 100%; margin-top: 2px; }
  .kpis { grid-template-columns: 1fr; }
  .pid-kpis { grid-template-columns: 1fr; }
  .dash-header { padding: 12px 16px; gap: 10px; }
  .dash-header h1 { font-size: 15px; }
  .dash-header .meta { display: none; }
  .ctrl-sep { display: none; }
  .table-controls input { min-width: 0; width: 100%; }
  .table-controls { flex-direction: column; align-items: stretch; }
  #map { height: 220px; }
  th { font-size: 10px; padding: 6px 6px; }
  td { font-size: 10px; padding: 5px 6px; }
  .cell-title { max-width: 140px; font-size: 10px; }
  .badge-eov { font-size: 8px; padding: 1px 4px; }
  .pagination { gap: 4px; }
  .page-btn { padding: 3px 8px; font-size: 10px; }
}

/* ── Source breakdown mini-badges ──────────────────────────────── */
.src-breakdown { display: flex; gap: 4px; flex-wrap: wrap; }
.src-badge { font-size: 9px; padding: 1px 5px; border-radius: 6px; font-weight: 600; }
.src-badge.crossref    { background: #e8e4f7; color: #4a3aaa; }
.src-badge.datacite    { background: var(--teal-light); color: #0F5F53; }
.src-badge.opencitations { background: #fdecea; color: #7a1a24; }

/* ── Focus visible (keyboard nav) ─────────────────────────────── */
[role="button"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Panel header select ──────────────────────────────────────── */
.panel-select {
  font-size: 11px; padding: 2px 6px;
  border: 1px solid var(--border); border-radius: 4px;
  font-family: inherit; background: var(--white); color: var(--text);
}

/* ── EOV filter indicator ──────────────────────────────────────── */
#eov-filter-label, #org-filter-label {
  display: none; font-size: 11px; background: var(--teal-light); color: var(--navy);
  padding: 3px 10px; border-radius: 10px; align-items: center; gap: 6px;
}
#eov-filter-label.show, #org-filter-label.show { display: inline-flex; }
#eov-filter-label button, #org-filter-label button { background: none; border: none; cursor: pointer; font-size: 13px; line-height: 1; padding: 0; color: var(--navy); }
.org-link { background: none; border: none; cursor: pointer; font-size: inherit; color: var(--primary); padding: 0; text-align: left; }
.org-link:hover { text-decoration: underline; }

/* ── Print / PDF ───────────────────────────────────────────────── */
@media print {
  .controls, #settings-drawer, .btn, .pagination, .table-controls { display: none !important; }
  body { background: #fff; }
}

/* ── Info modal ─────────────────────────────────────────────────── */
#info-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(21,47,55,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000; padding: 20px;
}
#info-modal-overlay.hidden { display: none; }
.info-modal-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px 28px;
  max-width: 480px; width: 100%;
  box-shadow: 0 8px 32px rgba(21,47,55,.22);
  max-height: 80vh; overflow-y: auto;
}
.info-modal-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--teal-light); padding-bottom: 8px;
}
.info-modal-header h2 {
  font-family: 'Sora', sans-serif; font-size: 14px; font-weight: 600;
  color: var(--navy); margin: 0;
}
#info-modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 16px; padding: 0 0 0 12px;
  line-height: 1; flex-shrink: 0;
}
#info-modal-close:hover { color: var(--navy); }
#info-modal-body { font-size: 12px; color: var(--text); line-height: 1.6; }
#info-modal-body p { margin-bottom: 8px; }
#info-modal-body h4 {
  font-size: 11px; font-weight: 600; color: var(--navy);
  margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .04em;
}
#info-modal-body ul { padding-left: 16px; margin: 0 0 8px; }
#info-modal-body li { margin-bottom: 4px; }

/* ── Info & expand buttons ──────────────────────────────────────── */
.info-btn, .expand-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 13px; padding: 0 2px;
  line-height: 1; display: inline-flex; align-items: center;
}
.info-btn:hover, .expand-btn:hover { color: var(--primary); }
.info-btn:focus-visible, .expand-btn:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 2px;
}

/* ── Map fullscreen ─────────────────────────────────────────────── */
#section-map.map-fullscreen {
  position: fixed; inset: 0; z-index: 8000;
  border-radius: 0; margin: 0; padding: 12px;
  display: flex; flex-direction: column;
}
#section-map.map-fullscreen h3 { margin-bottom: 8px; }
#section-map.map-fullscreen #map { flex: 1; height: auto !important; min-height: 0; }

/* ── Password overlay ──────────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0;
  background: rgba(21,47,55,.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000; padding: 20px;
}
#auth-overlay.hidden { display: none; }
.auth-card {
  background: var(--white); border-radius: 12px; padding: 36px 40px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: 0 8px 32px rgba(21,47,55,.28);
}
.auth-title { font-family:'Sora',sans-serif; font-size:18px; font-weight:700; color:var(--navy); text-align:center; margin-top:4px; }
.auth-sub   { font-size:12px; color:var(--text-muted); text-align:center; margin-bottom:8px; }
.auth-field { width:100%; display:flex; flex-direction:column; gap:6px; margin-bottom:4px; }
.auth-label { font-size:12px; font-weight:600; color:var(--text-muted); text-transform:uppercase; letter-spacing:.04em; }
.auth-input {
  font-family:'Montserrat',sans-serif; font-size:14px;
  border:1.5px solid var(--border); border-radius:var(--radius);
  padding:10px 14px; background:var(--white); color:var(--text); width:100%;
  transition: border-color .15s;
}
.auth-input:focus  { outline:none; border-color:var(--primary); box-shadow:0 0 0 3px rgba(82,167,155,.18); }
.auth-input--error { border-color:var(--coral); }
.auth-error        { font-size:12px; color:var(--coral); text-align:center; width:100%; margin:0; }
.auth-btn          { width:100%; justify-content:center; padding:10px 16px; font-size:14px; margin-top:8px; }
@media (max-width:480px) { .auth-card { padding:28px 20px; } }
