:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2530;
  --muted: #6b7785;
  --line: #e2e6ec;
  --accent: #1f4ea1;
  --accent-soft: #e8eefb;
  --ro-red: #ce1126;
  --ro-yellow: #fcd116;
  --ro-blue: #002b7f;
  --shadow: 0 1px 3px rgba(20, 30, 45, .08), 0 4px 14px rgba(20, 30, 45, .05);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
h1 { font-size: 1.35rem; margin: 0 0 .15rem; }
h2 { font-size: 1rem; margin: 0; }
a { color: var(--accent); }

.site-header {
  background: var(--panel);
  border-bottom: 3px solid var(--ro-yellow);
  border-image: linear-gradient(90deg, var(--ro-blue) 0 33%, var(--ro-yellow) 33% 66%, var(--ro-red) 66% 100%) 1;
  padding: 1rem 1.5rem;
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-start;
}
.subtitle { margin: 0; color: var(--muted); max-width: 60ch; }
.provenance { font-size: .8rem; color: var(--muted); text-align: right; line-height: 1.5; }
.provenance strong { color: var(--ink); }
.provenance a { white-space: nowrap; }

main { padding: 1.25rem 1.5rem 3rem; max-width: 1600px; margin: 0 auto; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.notice {
  background: var(--accent-soft); border: 1px solid #c9d8f5; border-left: 4px solid var(--accent);
  border-radius: 8px; padding: .6rem .85rem; margin: 0 0 1.25rem; font-size: .85rem; color: var(--ink);
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem .9rem; box-shadow: var(--shadow);
}
.card .value { font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em; }
.card .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.controls {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.control { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.control.search { grid-column: 1 / -1; }
.control label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.control input[type=search], .control select {
  padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; font: inherit; color: inherit; width: 100%;
}
.control.checks { flex-direction: column; justify-content: center; gap: .4rem; }
.chk { display: flex; align-items: center; gap: .4rem; font-size: .85rem; text-transform: none; letter-spacing: 0; color: var(--ink); }
.control.reset { flex-direction: column; justify-content: flex-end; gap: .4rem; }
button {
  font: inherit; padding: .45rem .7rem; border-radius: 7px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer;
}
button:hover { background: var(--accent-soft); border-color: var(--accent); }
#export { background: var(--accent); color: #fff; border-color: var(--accent); }
#export:hover { filter: brightness(1.08); }

.stack { display: flex; flex-direction: column; gap: 1.25rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .9rem 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

.metric-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.metric-toggle button { border: 0; border-radius: 0; padding: .35rem .6rem; font-size: .8rem; }
.metric-toggle button.active { background: var(--accent); color: #fff; }

#map { width: 100%; }
/* Map is now on its own full-width row — keep the SVG a sensible size, centered. */
#map svg { width: 100%; max-width: 720px; height: auto; display: block; margin: 0 auto; }
.county { stroke: #fff; stroke-width: .5; cursor: pointer; transition: opacity .1s; }
.county:hover { opacity: .8; }
.county.selected { stroke: var(--ro-red); stroke-width: 1.8; }
.map-legend { display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }
.legend-scale { display: inline-flex; height: 12px; border-radius: 3px; overflow: hidden; }
.legend-scale span { width: 26px; height: 12px; }
.map-note { padding: 0 1rem 1rem; margin: 0; font-size: .78rem; color: var(--muted); }

.table-wrap { overflow-x: auto; max-height: 70vh; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
thead th {
  position: sticky; top: 0; background: #f0f2f6; text-align: left; padding: .5rem .6rem;
  border-bottom: 2px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none;
}
thead th.no-sort { cursor: default; }
thead th .arrow { color: var(--accent); font-size: .7rem; }
tbody td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: var(--accent-soft); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entity { font-weight: 600; }
button.entity-link {
  border: 0; background: none; padding: 0; margin: 0; font: inherit; font-weight: 600;
  color: var(--accent); text-align: left; cursor: pointer; line-height: 1.3;
}
button.entity-link:hover { text-decoration: underline; background: none; }
.tag.multi { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tag.gdpr { background: #ede7f6; color: #5b3a9b; font-weight: 600; }
.tag.neocupat { background: #e0f2f1; color: #00695c; font-weight: 600; }
.tag.pstatus { background: #eef2ff; color: #3949ab; font-weight: 600; white-space: normal; }
.entity-anon { font-style: italic; color: var(--muted); }
.addr { color: var(--muted); font-size: .8rem; }
.addr-link { color: inherit; text-decoration: none; }
.addr-link:hover { text-decoration: underline; color: var(--accent); }
.addr-link .ext { opacity: .55; }
.tag { display: inline-block; font-size: .68rem; padding: .08rem .4rem; border-radius: 999px; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.tag.lit { background: #fde8e8; color: #9b1c1c; }
.tag.titlu { background: #fef3cd; color: #8a6d00; }
.tag.src-unknown { background: #fde8e8; color: #9b1c1c; }
.tag.src-branch { background: #fff4e5; color: #92510a; }
.tag.src-address, .tag.src-city, .tag.src-bucuresti, .tag.src-override { background: #e6f4ea; color: #1e6b35; }
.status-active { color: #1e6b35; font-weight: 600; }
.status-expired { color: #9b1c1c; }
.status-indef { color: var(--muted); }
.src-pdf a { font-size: .8rem; }

.count-badge { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: .1rem .55rem; font-size: .8rem; font-weight: 700; }
.pager { display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--muted); flex-wrap: wrap; }
.pager button { padding: .25rem .55rem; }
.pager button:disabled { opacity: .4; cursor: default; }

.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: .85rem;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.site-footer a { font-weight: 600; }

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 30, 45, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 3vh 1rem; overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-box {
  position: relative; background: var(--panel); border-radius: 12px;
  box-shadow: 0 12px 48px rgba(20, 30, 45, .3);
  width: min(1100px, 100%); padding: 1.5rem 1.5rem 1.75rem;
  border-top: 4px solid var(--accent);
}
.modal-close {
  position: absolute; top: .6rem; right: .8rem; border: 0; background: none;
  font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; padding: .2rem .5rem;
}
.modal-close:hover { color: var(--ink); background: none; }
.modal-box h2 { font-size: 1.2rem; padding-right: 2rem; }
.modal-sub { color: var(--muted); font-size: .85rem; margin: .35rem 0 1rem; }
.modal-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; margin-bottom: 1.25rem;
}
.m-stat { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; }
.m-val { font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; }
.m-lab { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.modal-body { overflow-x: auto; }
.m-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.m-table th { text-align: left; padding: .4rem .55rem; background: #f0f2f6; border-bottom: 2px solid var(--line); white-space: nowrap; }
.m-table td { padding: .4rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.m-table tr:hover { background: var(--accent-soft); }

.tooltip {
  position: fixed; pointer-events: none; background: #1c2530; color: #fff;
  padding: .4rem .6rem; border-radius: 6px; font-size: .8rem; box-shadow: var(--shadow); z-index: 50; max-width: 240px;
}
.tooltip b { color: var(--ro-yellow); }

/* ---------------------------------------------------------------- phones */
@media (max-width: 640px) {
  main { padding: 1rem .85rem 2rem; }
  .site-header { padding: .9rem 1rem; }
  .provenance { text-align: left; }
  .provenance a { white-space: normal; }

  /* The choropleth doesn't fit a phone — hide it (still built in JS). */
  .map-panel { display: none; }

  /* Stacked-card layout: every field stays visible with its label. */
  .table-wrap { overflow: visible; max-height: none; }
  #table thead, .m-table thead { display: none; }
  #table tbody, #table tr, #table td,
  .m-table tbody, .m-table tr, .m-table td { display: block; }
  #table tr, .m-table tr {
    border: 1px solid var(--line); border-radius: 10px;
    margin-bottom: .6rem; padding: .25rem .75rem; background: #fff;
  }
  #table tr:hover, .m-table tr:hover { background: #fff; }
  #table td, .m-table td {
    display: flex; justify-content: space-between; gap: 1rem; text-align: right;
    padding: .35rem 0; border-bottom: 1px dashed var(--line); white-space: normal;
  }
  #table tr td:last-child, .m-table tr td:last-child { border-bottom: 0; }
  #table td::before, .m-table td::before {
    content: attr(data-label); font-weight: 600; color: var(--muted);
    text-align: left; flex: 0 0 auto;
  }
  /* Long free-text fields read better left-aligned under their label. */
  #table td.addr, .m-table td.addr { flex-direction: column; text-align: left; gap: .15rem; }
  td.num { text-align: right; white-space: normal; }
  button.entity-link { text-align: right; }

  /* Roomier tap targets / less cramped modal. */
  .modal { padding: 2vh .5rem; }
  .modal-box { padding: 1.25rem 1rem; }
  .pager button { padding: .4rem .7rem; }
}
