/* ==========================================================================
   Kontiolahti Yhdistys – Dashboard
   Design-tokenit: DESIGN.md (Kontiolahden Työttömät ry & Kontiotupa)
   ========================================================================== */

:root {
  --primary: #2E5B4D;
  --primary-dark: #24493D;
  --primary-light: #3A6E5D;
  --secondary: #6B7280;
  --tertiary: #F59E0B;
  --neutral: #F8FAFC;
  --surface: #FFFFFF;
  --ink: #1F2937;
  --ink-soft: #4B5563;
  --line: #E5E7EB;
  --on-primary: #FFFFFF;
  --success: #10B981;
  --error: #EF4444;

  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 12px 34px rgba(0, 0, 0, 0.18);

  --header-h: 68px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body.drawer-open { overflow: hidden; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--neutral);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0 0 0.75rem; }
a { color: var(--primary); }
button { font-family: var(--font); cursor: pointer; }
code { background: #EEF2F0; padding: 0.1rem 0.35rem; border-radius: 4px; }

:focus-visible { outline: 3px solid var(--tertiary); outline-offset: 2px; border-radius: 4px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  border: 0; clip: rect(0 0 0 0); overflow: hidden;
}

/* --------------------------------------------------------------------------
   Yläpalkki
   -------------------------------------------------------------------------- */
#header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--spacing, 24px);
  padding: 0.65rem 1.5rem;
  min-height: var(--header-h);
  background: rgba(248, 250, 252, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }

.brand-mark {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  color: var(--on-primary);
  background: var(--primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.brand-text { min-width: 0; }
#title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#tagline { font-size: 0.8rem; color: var(--secondary); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#nav {
  display: flex;
  gap: 0.35rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  margin-left: auto;
}
#nav::-webkit-scrollbar { display: none; }

.nav-btn {
  flex: 0 0 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.nav-btn:hover { color: var(--primary); background: rgba(46, 91, 77, 0.08); }
.nav-btn:active { background: rgba(46, 91, 77, 0.16); }

.header-meta { flex: 0 0 auto; margin-left: 0.75rem; }

/* --------------------------------------------------------------------------
   Merkit & painikkeet
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-neutral { background: #EDF1F5; color: var(--secondary); }
.badge-primary { background: var(--primary); color: var(--on-primary); }
.badge-tertiary { background: #FEF3C7; color: #92600A; }
.badge-success { background: #D1FAE5; color: #065F46; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  transition: background-color 0.15s, color 0.15s, transform 0.05s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-secondary:hover { background: rgba(46, 91, 77, 0.08); }
.btn-tertiary { background: var(--tertiary); color: #7C4A03; }
.btn-tertiary:hover { filter: brightness(1.05); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.82rem; }
.btn-icon {
  width: 40px; height: 40px;
  padding: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
}
.btn-icon:hover { color: var(--primary); border-color: var(--primary); }

/* --------------------------------------------------------------------------
   Skenenäkymä (hero)
   -------------------------------------------------------------------------- */
#hero {
  position: relative;
  height: clamp(420px, 58vh, 660px);
  overflow: hidden;
  background: linear-gradient(180deg, #F1F5F2 0%, #E7EEE9 55%, #DDE7E0 100%);
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
#scene:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--tertiary); }

#labels-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.scene-label {
  position: absolute;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  background: var(--surface);
  color: var(--primary-dark);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.2s;
}
.scene-label small { display: block; font-size: 0.7rem; font-weight: 500; color: var(--secondary); text-align: center; }
.scene-label.active { background: var(--primary); color: var(--on-primary); }
.scene-label[data-key="kontiotupa"].active { background: #B0713A; color: var(--on-primary); }
.scene-label[data-key="tori"].active { background: var(--tertiary); color: #7C4A03; }
.scene-label.active small { color: rgba(255,255,255,0.8); }
.scene-label[data-key="tori"].active small { color: rgba(124,74,3,0.8); }

.tooltip {
  position: absolute;
  z-index: 20;
  max-width: 260px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.8rem 1rem;
  font-size: 0.85rem;
  color: var(--ink);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
}
.tooltip strong { display: block; color: var(--primary-dark); font-size: 0.9rem; margin-bottom: 0.25rem; }
.tooltip small { color: var(--secondary); }

#scene-ui {
  position: absolute;
  left: 1.5rem; bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  pointer-events: none;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  align-items: center;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.65rem 1.4rem;
  width: fit-content;
}
.legend-item { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.78rem; font-weight: 600; color: var(--ink-soft); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--primary); }
.dot-brown { background: #C0824D; }
.dot-orange { background: var(--tertiary); }
.hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  width: fit-content;
}

#loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  border: none;
  background: var(--surface);
  color: var(--secondary);
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  z-index: 10;
}

.error-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.5rem;
  background: rgba(248, 250, 252, 0.92);
  padding: 2rem;
  color: var(--ink);
}
.error-overlay p { font-weight: 600; font-size: 1.05rem; margin: 0; }
.error-overlay .error-sub { font-weight: 400; font-size: 0.85rem; color: var(--secondary); max-width: 520px; }

/* --------------------------------------------------------------------------
   Kortit
   -------------------------------------------------------------------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: var(--spacing, 24px);
  max-width: 1240px;
  margin: -1.5rem auto 0;
  padding: 0 1.5rem 1rem;
  position: relative;
  z-index: 5;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.4rem;
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.card-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.card-icon {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: rgba(46, 91, 77, 0.1);
  color: var(--primary);
  border-radius: var(--radius-md);
}
.card-head h2 { font-size: 1.05rem; font-weight: 700; color: var(--primary-dark); margin-right: auto; }

.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.card-list li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.card-list li:last-child { border-bottom: none; }
.card-list .list-dot {
  flex: 0 0 auto;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--tertiary);
  align-self: center;
}
.card-list strong { color: var(--ink); font-weight: 600; }
.card-list .muted { color: var(--secondary); font-size: 0.82rem; }

/* --------------------------------------------------------------------------
   Digibanneri
   -------------------------------------------------------------------------- */
.digibanner {
  max-width: 1240px;
  margin: 1.75rem auto;
  padding: 1.1rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  background: linear-gradient(120deg, #FEF3C7, #FDE9B8);
  border: 1px solid #F3D47E;
  border-radius: var(--radius-lg);
}
.digibanner .digi-icon {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--radius-md);
  background: var(--tertiary);
  color: #7C4A03;
}
.digibanner .digi-text { flex: 1 1 260px; }
.digibanner h2 { font-size: 1rem; color: #7C4A03; }
.digibanner p { margin: 0; font-size: 0.88rem; color: #6B5208; }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.footer {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  color: var(--secondary);
  font-size: 0.85rem;
}
.footer .f-links { display: flex; gap: 0.9rem; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   Drawer
   -------------------------------------------------------------------------- */
#drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(31, 41, 55, 0.35);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s;
}
#drawer-backdrop.show { opacity: 1; }

#drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 70;
  width: min(540px, 100vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  overflow-y: auto;
  padding: 1.5rem;
  color: var(--ink);
}
#drawer.open { transform: translateX(0); }

#drawer-close { position: sticky; top: 0; float: right; margin-bottom: 1rem; z-index: 5; }

.drawer-hero {
  border-radius: var(--radius-lg);
  padding: 1.2rem 1.4rem;
  color: var(--on-primary);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.drawer-hero.orange { background: linear-gradient(135deg, #B45309, #D97706); }
.drawer-hero.tertiary { background: linear-gradient(135deg, #B45309, #D97706); }
.drawer-hero h2 { font-size: 1.35rem; margin-bottom: 0.3rem; }
.drawer-hero .role { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.85; margin: 0; }
.drawer-hero .chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.drawer-hero .chip { background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.25); padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; }

.drawer-section { margin-bottom: 1.4rem; }
.drawer-section h3 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--secondary);
  margin-bottom: 0.5rem;
}
.drawer-section p { font-size: 0.94rem; color: var(--ink-soft); margin-bottom: 0.5rem; }

.drawer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.drawer-list li {
  background: var(--neutral);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.9rem;
  font-size: 0.88rem;
}
.drawer-list li strong { color: var(--primary-dark); display: block; margin-bottom: 0.1rem; }
.drawer-list li .sub { color: var(--tertiary); font-weight: 600; font-size: 0.8rem; display: block; margin-top: 0.15rem; }

.drawer-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }
.meta-line { display: flex; gap: 0.4rem; flex-direction: column; font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 0.35rem; }
.meta-line strong { color: var(--ink); }

/* --------------------------------------------------------------------------
   Responsiivisuus
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .header-meta { display: none; }
}

@media (max-width: 720px) {
  #header { flex-wrap: wrap; gap: 0.5rem; padding: 0.6rem 1rem; }
  #nav { order: 3; width: 100%; margin-left: 0; padding-bottom: 0.25rem; }
  .nav-btn { font-size: 0.8rem; padding: 0.4rem 0.7rem; }
  #hero { height: 420px; }
  #scene-ui { left: 1rem; bottom: 1rem; }
  .legend { gap: 0.9rem; padding: 0.5rem 0.9rem; }
  .scene-label { font-size: 0.68rem; padding: 0.25rem 0.6rem; }
  .scene-label small { font-size: 0.6rem; }
  .hint { display: none; }
  .cards { margin-top: -1rem; padding: 0 1rem 1rem; }
  .card { padding: 1.1rem; }
  .footer { padding: 1.2rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  #drawer, #drawer-backdrop { transition: none; }
  .card { transition: none; }
}
