/* ===========================================================
   App-specific styles on top of Pico CSS
   Pico hoitaa: typography, forms, buttons, articles, container
   Tämä tiedosto: custom-komponentit joita Pico ei tarjoa
   =========================================================== */

/* -----------------------------------------------------------
   Pico CSS variable overrides — teema-riippumattomat
   -----------------------------------------------------------
   Nämä toimivat suoraan :root:ssa koska Pico ei määrittele
   niitä teemakohtaisissa selectoreissa.
   Täydellinen lista: https://picocss.com/docs/css-variables
   ----------------------------------------------------------- */
:root {
  /* Tekstin peruskoko (oletus 100% = 16px). Skaalaa kaiken muun. */
  --pico-font-size: 92%;

  /* Otsikoiden ja kappaleiden välinen tila (oletus 1.5rem) */
  /* --pico-typography-spacing-vertical: 1.25rem; */

  /* Lomake-elementtien (input, select, button) padding */
  /* --pico-form-element-spacing-vertical: 0.6rem; */
  /* --pico-form-element-spacing-horizontal: 0.9rem; */

  /* Yleinen elementtien spacing (margin/padding base) */
  /* --pico-spacing: 1rem; */

  /* Border radius (napit, kortit, inputit) */
  /* --pico-border-radius: 0.5rem; */

  /* Fonttipaino otsikoille (oletus 700) */
  /* --pico-font-weight: 600; */
}

/* -----------------------------------------------------------
   Pico-värimuuttujat — teemakohtaiset
   -----------------------------------------------------------
   TÄRKEÄÄ: värit on määritelty Picossa `[data-theme=light]`-
   ja `[data-theme=dark]`-selectoreissa jotka ovat
   SPESIFISEMPIÄ kuin pelkkä `:root`. Override pitää siis
   käyttää samaa selectoria, muuten se ei pure.

   Lisäksi napit/linkit eivät käytä pelkkää `--pico-primary`:ä,
   vaan myös `-background`, `-hover`, `-focus`, `-underline` jne.
   → kaikki pitää overrideata yhdessä että väri vaihtuu joka
   paikassa (linkit, napit, focus-ringit, underlinet).
   ----------------------------------------------------------- */
[data-theme="light"],
:root:not([data-theme="dark"]) {
  /* Oranssi primary */
  --pico-primary: #fd5a1f;
  --pico-primary-background: #fd5a1f;
  --pico-primary-border: #fd5a1f;
  --pico-primary-underline: rgba(253, 90, 31, 0.5);
  --pico-primary-hover: #d94614;
  --pico-primary-hover-background: #e04d15;
  --pico-primary-hover-border: #e04d15;
  --pico-primary-hover-underline: #d94614;
  --pico-primary-focus: rgba(253, 90, 31, 0.35);
  --pico-primary-inverse: #fff;
}

[data-theme="dark"] {
  --pico-primary: #fd7a4a;
  --pico-primary-background: #fd5a1f;
  --pico-primary-border: #fd5a1f;
  --pico-primary-underline: rgba(253, 122, 74, 0.5);
  --pico-primary-hover: #ff8e62;
  --pico-primary-hover-background: #e04d15;
  --pico-primary-hover-border: #e04d15;
  --pico-primary-hover-underline: #ff8e62;
  --pico-primary-focus: rgba(253, 90, 31, 0.35);
  --pico-primary-inverse: #fff;
}


/* ---- Card-rajoitukset ja layout ---- */

/* Auth-sivujen (login, register, forgot, reset, verify-result) keskitetty pieni kortti */
.auth-container {
  max-width: 480px;
  margin: 4rem auto;
  padding: 0 1rem;
}

.auth-container > article {
  padding: 2rem;
}


/* Dashboard ja admin: leveämpi container */
.app-container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.app-container--narrow {
  max-width: 600px;
}

/* ---- Alert-bannerit ---- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--pico-border-radius);
  margin-bottom: 1rem;
  line-height: 1.4;
  font-size: 0.95rem;
}
.alert--error {
  background: #fdecea;
  color: #c62828;
}
.alert--success {
  background: #e8f5e9;
  color: #2e7d32;
  border-left: 4px solid #2e7d32;
}
.alert--warning {
  background: #fff3e0;
  color: #5d4037;
  border-left: 4px solid #ff9800;
}
.alert--info {
  background: #f0f4f8;
  color: #455a64;
  border-left: 4px solid #607d8b;
}
.alert[hidden] { display: none; }

/* ---- Badge-komponentti (rooli- ja oikeus-näytöt) ---- */
.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.25rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.4;
}
.badge--role { background: #e3f2fd; color: #1565c0; }
.badge--perm { background: #f3e5f5; color: #7b1fa2; }
.badge--none { background: #f5f5f5; color: #999; }
.badge--pending { background: #fff3cd; color: #856404; }
.badge--accepted { background: #d4edda; color: #155724; }
.badge--expired { background: #f8d7da; color: #721c24; }

/* ---- User-cards (admin "Käyttäjät" -tabin accordion-näkymä) ---- */
.user-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.user-card {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.user-card[open] {
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.user-card__head {
  padding: 0.75rem 1rem;
  cursor: pointer;
  list-style: none; /* piilota oletus-marker Firefoxissa */
  display: flex;
  align-items: center;
  gap: 1rem;
  user-select: none;
}
.user-card__head::-webkit-details-marker { display: none; }

.user-card[open] .user-card__head::before {
  transform: rotate(90deg);
}
.user-card__primary {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 0; /* salli text overflow */
}
.user-card__primary strong {
  font-size: 1rem;
}
.user-card__meta {
  font-size: 0.85rem;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-card__badges {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.user-card__body {
  padding: 0 1rem 1rem;
  border-top: 1px solid #f0f0f0;
  margin-top: 0.5rem;
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.user-card__fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
}
.user-card__fields label {
  margin-bottom: 0;
  font-size: 0.85rem;
}
.user-card__fields input {
  margin-bottom: 0;
}
.user-card__fullspan {
  grid-column: 1 / -1;
}
/* User-card sisällä select halutaan samalle korkeudelle kuin btn-sm-napit.
   Pico:n oletus-padding on liian iso → ylikirjoita scopattuna. */
.user-card__body .inline-form select {
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  min-width: 0;
  height: auto;
  line-height: 1.4;
}
@media (max-width: 600px) {
  .user-card__fields { grid-template-columns: 1fr; }
  .user-card__meta { white-space: normal; }
}
.badge .remove {
  cursor: pointer;
  font-weight: bold;
  margin-left: 0.15rem;
  opacity: 0.6;
}
.badge .remove:hover { opacity: 1; }

/* ---- "Tarkista sähköposti" -näkymä (register success) ---- */
.check-email {
  text-align: center;
}
.check-email__icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 0.75rem;
}
.check-email__hint {
  background: #f7f7f7;
  color: var(--pico-muted-color);
  padding: 0.75rem 1rem;
  border-radius: var(--pico-border-radius);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 1rem 0;
}

/* ---- Verify-email result -sivu (success / failure) ---- */
.result-icon {
  font-size: 3rem;
  line-height: 1;
  text-align: center;
  margin-bottom: 0.75rem;
}
.result-icon--success { color: #2e7d32; }
.result-icon--error { color: #c62828; }

/* ---- Dashboard ---- */
.info-row { margin-bottom: 0.75rem; }
.info-row__label {
  font-weight: bold;
  color: var(--pico-muted-color);
  font-size: 0.85rem;
}
.info-row__value {
  font-size: 1.1rem;
  margin-top: 0.15rem;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.details-box {
  background: #f9f9f9;
  padding: 1rem;
  border-radius: var(--pico-border-radius);
  font-family: var(--pico-font-family-monospace);
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
}

/* ---- Admin: tabs ---- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--pico-muted-border-color);
  margin-bottom: 1.25rem;
}
.tab {
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--pico-muted-color);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: none;
  width: auto;
}
.tab:hover { color: var(--pico-primary); }
.tab.active {
  color: var(--pico-primary);
  border-bottom-color: var(--pico-primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- Admin: tabular data ---- */
.admin-table {
  width: 100%;
  margin-top: 0;
  font-size: 0.9rem;
}
.admin-table th {
  text-align: left;
  font-size: 0.8rem;
  color: var(--pico-muted-color);
  font-weight: 600;
}
.admin-table input {
  padding: 0.25rem 0.5rem;
  font-size: 0.9rem;
  margin: 0;
}
.admin-table .name-pair {
  display: flex;
  gap: 0.25rem;
}
.admin-table .name-pair input { flex: 1; }

/* Inline create-form yläosassa */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.inline-form input,
.inline-form select {
  margin: 0;
  width: auto;
  flex: 1 1 auto;
  min-width: 12rem;
}
.inline-form button { margin: 0; width: auto; }

/* Pieni nappi taulukoiden sisällä */
.btn-sm {
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  margin: 0;
  width: auto;
}

/* Variant: danger button */
button.danger,
[role="button"].danger {
  --pico-background-color: #c62828;
  --pico-border-color: #c62828;
  --pico-color: #fff;
}
button.danger:hover {
  --pico-background-color: #b71c1c;
  --pico-border-color: #b71c1c;
}

/* ---- Toast-style flash message (admin) ---- */
.toast-area {
  position: fixed;
  top: 1rem;
  right: 1rem;
  max-width: 320px;
  z-index: 1000;
}
