/* Site-wide styles for the veleprojekti viewer. Mobile-first: base styles are sized for a
   ~320-360px screen. `min-width` media queries layer on enhancements for tablet/desktop. */

:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --accent: #2563eb;
  --warn: #b45309;
  --warn-bg: #fef3c7;
}

* { box-sizing: border-box; }

/* Screen-reader-only utility for accessible captions/labels that shouldn't render visually. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* --- Header --- */
header {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
header .header-row {
  display: flex;
  align-items: center;
  gap: .5rem;
}
header h1 { margin: 0 0 .2rem; font-size: 1.15rem; line-height: 1.2; flex: 1; min-width: 0; }
header .lede { margin: 0; color: var(--muted); font-size: .85rem; }
header .backlink { margin: .4rem 0 0; font-size: .85rem; }
header .backlink a { color: var(--accent); text-decoration: none; }
header .subnav { margin-top: .5rem; font-size: .9rem; }
header .subnav a { color: var(--accent); text-decoration: none; }
header .subnav a:hover { text-decoration: underline; }

/* Info (ⓘ) button — opens the info modal. Large touch target on mobile. */
.info-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.info-btn:hover { background: #eef2ff; }

/* Info modal — shares the project-modal frame but goes full-screen on mobile. */
dialog.info-modal {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  margin: 0;
  background: #fff;
}
dialog.info-modal::backdrop { background: rgba(0,0,0,.4); }
dialog.info-modal .info-body {
  padding: 3rem 1.25rem 1.5rem;
  max-width: 36rem;
  margin: 0 auto;
}
dialog.info-modal h2 { margin: 0 0 .75rem; font-size: 1.2rem; }
dialog.info-modal h3 { margin: 1.25rem 0 .5rem; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
dialog.info-modal p { margin: 0 0 .75rem; font-size: .95rem; }
dialog.info-modal .info-links { margin: 0; padding-left: 1.1rem; }
dialog.info-modal .info-links li { margin-bottom: .5rem; font-size: .95rem; }
dialog.info-modal a { color: var(--accent); }

/* --- Map --- */
#map-section { padding: 0; }
#map {
  width: 100%;
  height: 260px;
  border-bottom: 1px solid var(--border);
}

/* --- Table --- */
#table-section { padding: .75rem .5rem; overflow-x: auto; }
#projects-table {
  width: 100%;
  min-width: 34rem;
  border-collapse: collapse;
  font-size: .85rem;
  background: #fff;
}
#projects-table th, #projects-table td {
  padding: .45rem .5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
#projects-table th {
  font-weight: 600;
  font-size: .78rem;
  color: var(--muted);
  background: #f3f3f3;
  position: sticky;
  top: 0;
  white-space: nowrap;
}
#projects-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}
#projects-table th[data-sort]:hover { color: var(--accent); }
#projects-table th .sort-arrow { margin-left: .3rem; opacity: .5; }
#projects-table th.sorted .sort-arrow { opacity: 1; color: var(--accent); }
#projects-table tbody tr { cursor: pointer; }
#projects-table tbody tr:hover { background: #f6f8ff; }
#projects-table .empty { text-align: center; color: var(--muted); padding: 1rem; }
#projects-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#projects-table .eu-funds-link { color: var(--accent); text-decoration: none; }
#projects-table .eu-funds-link:hover { text-decoration: underline; }
#projects-table .proj-desc { color: var(--muted); font-size: .82rem; max-width: 24rem; }

.status-pill {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  background: #eef;
  color: #224;
}

/* --- Phase chips (main page Status column) --- */
.phase-chip {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
}
.phase-ideja        { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
.phase-pred-eojn    { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.phase-u-tijeku     { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.phase-izvedba      { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.phase-zavrseno     { background: #e5e7eb; color: #374151; border-color: #d1d5db; }
.phase-obustavljeno { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.phase-unknown      { background: #f3f4f6; color: var(--muted); border-color: var(--border); }

/* --- Modal --- */
dialog#project-modal {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  max-width: 680px;
  width: calc(100% - 1rem);
  max-height: calc(100dvh - 2rem);
  background: #fff;
  overflow-y: auto;
}
dialog#project-modal::backdrop { background: rgba(0,0,0,.4); }

#modal-body { padding: 1rem 1rem 1.25rem; }
#modal-body h2 { margin: 0 0 .5rem; font-size: 1.05rem; line-height: 1.25; padding-right: 1.5rem; }
#modal-body p { margin: .25rem 0 .5rem; font-size: .9rem; }
#modal-body .hero {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #eee center/cover no-repeat;
  border-radius: 4px;
  margin-bottom: .75rem;
}
/* On narrow screens, dl becomes single-column (term above definition) to avoid overflow. */
#modal-body dl {
  display: grid;
  grid-template-columns: 1fr;
  gap: .15rem 0;
  margin: .5rem 0;
  font-size: .9rem;
}
#modal-body dt { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; margin-top: .35rem; }
#modal-body dd { margin: 0; }
#modal-body .conflict-badge {
  display: inline-block;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: .7rem;
  padding: .05rem .4rem;
  border-radius: 3px;
  margin-left: .35rem;
}
#modal-body .source-label {
  display: inline-block;
  font-size: .7rem;
  color: var(--muted);
  margin-left: .35rem;
}
#modal-body .obs-notes {
  font-size: .75rem;
  color: var(--muted);
  margin-top: .15rem;
  word-break: break-word;
}

.modal-close {
  position: absolute;
  top: .25rem;
  right: .35rem;
  background: transparent;
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: .25rem .5rem;
  min-width: 44px;
  min-height: 44px;
}

/* --- Footer (shared across index + project pages) --- */
.site-footer {
  padding: 1rem 1rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .8rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  margin-top: 2rem;
}
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* === Tablet (≥640px) === */
@media (min-width: 640px) {
  header { padding: 1rem; }
  header h1 { font-size: 1.3rem; }
  header .lede { font-size: .95rem; }

  /* Bounded card dialog on wider screens, not full-viewport. */
  dialog.info-modal {
    width: calc(100% - 2rem);
    height: auto;
    max-width: 40rem;
    max-height: calc(100dvh - 2rem);
    border-radius: 8px;
    overflow-y: auto;
  }
  dialog.info-modal .info-body { padding: 2.5rem 2rem 2rem; }

  #map { height: 340px; }

  #table-section { padding: 1rem; }
  #projects-table { font-size: .95rem; min-width: 0; }
  #projects-table th, #projects-table td { padding: .55rem .7rem; }
  #projects-table th { font-size: .85rem; }

  #modal-body { padding: 1rem 1.25rem 1.5rem; }
  #modal-body h2 { font-size: 1.15rem; padding-right: 2rem; }
  #modal-body dl {
    grid-template-columns: max-content 1fr;
    gap: .25rem .75rem;
  }
  #modal-body dt { text-transform: none; letter-spacing: 0; font-size: .9rem; margin-top: 0; }
}

/* === Desktop (≥1024px) === */
@media (min-width: 1024px) {
  header h1 { font-size: 1.4rem; }
  #map { height: 380px; }
}
