/* Sukuarkisto - design system. Rauhallinen, selkeä, hillityn futuristinen. */

:root{
  --font-sans: "Plus Jakarta Sans", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #f5f7f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-glass: rgba(255,255,255,0.72);
  --border: #e0e8e7;
  --border-strong: #c8d8d6;
  --text: #172326;
  --text-muted: #607174;
  --text-faint: #8d9da0;
  --accent: #2f8f83;
  --accent-strong: #207568;
  --accent-soft: #e4f3f0;
  --accent-warm: #c89534;
  --accent-warm-soft: #fbf1dc;
  --sidebar-bg: #ffffff;
  --sidebar-text: #181828;
  --sidebar-text-muted: rgba(24,24,40,0.55);
  --sidebar-hover: rgba(24,24,40,0.05);
  --sidebar-border: rgba(24,24,40,0.1);
  --danger: #c23838;
  --danger-soft: #fbe9e9;
  --success: #1f8a54;
  --success-soft: #e6f5ec;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20,22,30,0.06), 0 1px 1px rgba(20,22,30,0.04);
  --shadow-md: 0 8px 24px rgba(20,22,30,0.08), 0 2px 6px rgba(20,22,30,0.05);
  --shadow-lg: 0 24px 60px rgba(20,22,30,0.16), 0 6px 16px rgba(20,22,30,0.08);
  --ease: cubic-bezier(.22,.7,.32,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
  --skeleton-base: #e9ebf0;
  --skeleton-shine: #f6f7f9;
  --gender-male: #4f7fb0;
  --gender-male-soft: #eaf1f9;
  --gender-female: #b0555f;
  --gender-female-soft: #f9ecec;
  --gender-other: #4f9e6e;
  --gender-other-soft: #eaf7ee;
  color-scheme: light;
}

:root[data-theme="dark"], :root:not([data-theme="light"]):not([data-theme="dark"]) {
  /* fallback niiden ilman JS:ää - vaalea oletuksena; tumma alla media queryllä */
}

:root[data-theme="dark"]{
  --bg: #111719;
  --bg-elevated: #172023;
  --surface: #1a2427;
  --surface-glass: rgba(26,36,39,0.74);
  --border: #2a3b3f;
  --border-strong: #385055;
  --text: #edf4f2;
  --text-muted: #a5b7b7;
  --text-faint: #829799;
  --accent: #48b9a9;
  --accent-strong: #82ded2;
  --accent-soft: #173a38;
  --accent-warm: #e0b765;
  --accent-warm-soft: #3a3020;
  --danger: #e77373;
  --danger-soft: #3a2226;
  --success: #5fcf95;
  --success-soft: #16302a;
  color-scheme: dark;
  --shadow-md: 0 8px 24px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.3);
  --shadow-lg: 0 24px 60px rgba(0,0,0,0.55), 0 6px 16px rgba(0,0,0,0.35);
  --skeleton-base: #232734;
  --skeleton-shine: #2c3140;
  --gender-male: #7fa3d4;
  --gender-male-soft: #202a3d;
  --gender-female: #d18c93;
  --gender-female-soft: #3a2429;
  --gender-other: #7ecb9a;
  --gender-other-soft: #17301f;
  --sidebar-bg: #10181b;
  --sidebar-text: #ffffff;
  --sidebar-text-muted: rgba(255,255,255,0.55);
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-border: rgba(255,255,255,0.1);
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]):not([data-theme="dark"]){
    --bg: #111719;
    --bg-elevated: #172023;
    --surface: #1a2427;
    --surface-glass: rgba(26,36,39,0.74);
    --border: #2a3b3f;
    --border-strong: #385055;
    --text: #edf4f2;
    --text-muted: #a5b7b7;
    --text-faint: #829799;
    --accent: #48b9a9;
    --accent-strong: #82ded2;
    --accent-soft: #173a38;
    --accent-warm: #e0b765;
    --accent-warm-soft: #3a3020;
    --danger: #e77373;
    --danger-soft: #3a2226;
    --success: #5fcf95;
    --success-soft: #16302a;
    color-scheme: dark;
    --skeleton-base: #232734;
    --skeleton-shine: #2c3140;
    --gender-male: #7fa3d4;
    --gender-male-soft: #202a3d;
    --gender-female: #d18c93;
    --gender-female-soft: #3a2429;
    --gender-other: #7ecb9a;
    --gender-other-soft: #17301f;
    --sidebar-bg: #10181b;
    --sidebar-text: #ffffff;
    --sidebar-text-muted: rgba(255,255,255,0.55);
    --sidebar-hover: rgba(255,255,255,0.08);
    --sidebar-border: rgba(255,255,255,0.1);
  }
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:var(--font-sans);
  font-size:16px;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
a{color:var(--accent);text-underline-offset:0.15em}
img{max-width:100%;display:block}
button{font-family:inherit}
h1,h2,h3{text-wrap:balance}
p{text-wrap:pretty}

.visually-hidden{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}

/* Näppäimistöfokus näkyy aina selkeästi; hiirikäytössä ei turhaa rengasta. */
:focus{outline:none}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:4px}

/* Hienovarainen, kapea vierityspalkki - toimii sekä teemoissa. */
*{scrollbar-width:thin;scrollbar-color:var(--border-strong) transparent}
*::-webkit-scrollbar{width:10px;height:10px}
*::-webkit-scrollbar-track{background:transparent}
*::-webkit-scrollbar-thumb{background:var(--border-strong);border-radius:999px;border:2px solid var(--bg)}
*::-webkit-scrollbar-thumb:hover{background:var(--text-faint)}

@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{animation-duration:0.01ms !important;animation-iteration-count:1 !important;transition-duration:0.01ms !important;scroll-behavior:auto !important}
}

/* ---------- Layout ---------- */
.app-shell{min-height:100dvh;display:flex}

/* Sivupalkki seuraa valittua teemaa (vaalea/tumma) samoin kuin muukin
   käyttöliittymä - vain sävyt on omat, jotta se erottuu sisältöalueesta. */
.sidebar{
  width:250px;flex-shrink:0;min-height:100dvh;position:sticky;top:0;align-self:flex-start;
  background:var(--sidebar-bg);border-right:1px solid var(--sidebar-border);
  display:flex;flex-direction:column;gap:0.2rem;padding:1.4rem 1rem;
}
.sidebar__brand{
  display:flex;align-items:center;gap:0.65rem;text-decoration:none;color:var(--sidebar-text);
  font-weight:700;font-size:1rem;letter-spacing:-0.01em;padding:0 0.5rem 1.4rem;
}
.sidebar__brand img{height:30px;width:30px;border-radius:9px;object-fit:cover}
.sidebar__nav{display:flex;flex-direction:column;gap:0.2rem}
.sidebar__nav-item{
  display:flex;align-items:center;gap:0.75rem;padding:0.65rem 0.75rem;border-radius:11px;
  text-decoration:none;color:var(--sidebar-text-muted);font-weight:600;font-size:0.87rem;
  transition:background .15s ease,color .15s ease;
}
.sidebar__nav-item svg{width:18px;height:18px;flex-shrink:0}
.sidebar__nav-item:hover{color:var(--sidebar-text);background:var(--sidebar-hover)}
.sidebar__nav-item.is-active{color:#fff;background:var(--accent);box-shadow:0 4px 14px rgba(47,143,131,0.34)}
.sidebar__nav-item--muted{color:var(--sidebar-text-muted);font-size:0.84rem}
.sidebar__spacer{flex:1}
.sidebar__user{
  display:flex;align-items:center;gap:0.65rem;padding:0.9rem 0.5rem 0.2rem;
  border-top:1px solid var(--sidebar-border);margin-top:0.5rem;
}
.sidebar__account{
  display:flex;align-items:center;gap:0.65rem;flex:1;min-width:0;text-decoration:none;
  padding:0.3rem;border-radius:10px;margin:-0.3rem;transition:background .15s ease;
}
.sidebar__account:hover{background:var(--sidebar-hover)}
.sidebar__account.is-active .sidebar__username{color:var(--accent-strong)}
.sidebar__avatar{
  width:32px;height:32px;border-radius:999px;flex-shrink:0;
  background:linear-gradient(135deg,var(--accent),var(--accent-warm));
  display:flex;align-items:center;justify-content:center;color:#fff;font-weight:700;font-size:0.85rem;
}
.sidebar__username{flex:1;min-width:0;color:var(--sidebar-text);font-size:0.85rem;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.icon-btn--ghost{color:var(--sidebar-text-muted)}
.icon-btn--ghost:hover{color:var(--sidebar-text);background:var(--sidebar-hover)}

.app-main-col{flex:1;min-width:0;display:flex;flex-direction:column;min-height:100dvh}

.sidebar__search{position:relative;color:var(--sidebar-text-muted);margin-bottom:1rem}
.sidebar__search svg{position:absolute;left:0.9rem;top:50%;transform:translateY(-50%);width:16px;height:16px;pointer-events:none}
.sidebar__search .search-input{
  background:var(--sidebar-hover);border-color:transparent;color:var(--sidebar-text);box-shadow:none;
}
.sidebar__search .search-input::placeholder{color:var(--sidebar-text-muted)}
.sidebar__search .search-input:focus{border-color:var(--accent);background:var(--sidebar-hover)}
.search-input{
  width:100%;padding:0.6rem 0.9rem 0.6rem 2.35rem;border-radius:12px;border:1px solid var(--border);
  background:var(--surface);color:var(--text);font-size:0.88rem;box-shadow:var(--shadow-sm);
  transition:border-color .15s ease, box-shadow .15s ease;
}
.search-input:focus{border-color:var(--accent)}
.search-input:focus-visible{outline:2px solid var(--accent);outline-offset:1px}

/* Haku-sivun oma hakukenttä - näkyy aina, myös mobiilissa jossa
   ylätunnisteen hakukenttä on piilotettu tilan säästämiseksi. */
.search-page-form{position:relative;display:grid;gap:0.75rem;margin-bottom:1.75rem;max-width:680px}
.search-page-form__row{position:relative;display:flex;gap:0.6rem;align-items:center}
.search-page-form__row .topbar__search-icon{position:absolute;left:0.9rem;top:50%;transform:translateY(-50%);width:16px;height:16px;color:var(--text-faint);pointer-events:none;z-index:1}
.search-page-form .search-input{width:100%;font-size:0.95rem;padding-top:0.65rem;padding-bottom:0.65rem}
.search-page-form .btn{flex-shrink:0}
.search-filter-tabs{display:flex;gap:0.4rem;flex-wrap:wrap}
.search-filter-tabs__item{position:relative}
.search-filter-tabs__item input{position:absolute;opacity:0;pointer-events:none}
.search-filter-tabs__item span{
  display:inline-flex;align-items:center;min-height:34px;padding:0.35rem 0.8rem;border-radius:999px;
  border:1px solid var(--border);background:var(--surface);color:var(--text-muted);
  font-size:0.82rem;font-weight:700;cursor:pointer;transition:background .15s ease,border-color .15s ease,color .15s ease;
}
.search-filter-tabs__item:hover span{border-color:var(--accent);color:var(--accent-strong)}
.search-filter-tabs__item input:focus-visible + span{outline:2px solid var(--accent);outline-offset:2px}
.search-filter-tabs__item.is-active span{background:var(--accent);border-color:var(--accent);color:#fff}

.icon-btn{
  display:inline-flex;align-items:center;justify-content:center;
  width:40px;height:40px;border-radius:11px;border:1px solid transparent;background:transparent;color:var(--text-muted);
  cursor:pointer;transition:background .15s ease,color .15s ease;flex-shrink:0;
}
.icon-btn:hover{background:var(--accent-soft);color:var(--accent-strong)}
.icon-btn.is-active{background:var(--accent-soft);color:var(--accent-strong)}
.icon-btn svg{width:20px;height:20px}

.main{flex:1;padding:1.75rem 1.75rem 4rem}
.container{max-width:1280px;margin:0 auto}

/* ---------- Breadcrumb ---------- */
.breadcrumb{display:flex;flex-wrap:wrap;align-items:center;gap:0.25rem;margin:0 0 1.25rem;font-size:0.95rem;color:var(--text-muted)}
.breadcrumb a{color:var(--text-muted);text-decoration:none;padding:0.3rem 0.4rem;border-radius:8px}
.breadcrumb a:hover{background:var(--accent-soft);color:var(--accent-strong)}
.breadcrumb__current{color:var(--text);font-weight:600;padding:0.3rem 0.4rem}
.breadcrumb__sep{color:var(--text-faint)}

/* ---------- Page header ---------- */
.page-header{display:flex;align-items:center;justify-content:space-between;gap:1rem;margin-bottom:1.5rem;flex-wrap:wrap}
.page-header h1{font-size:1.6rem;margin:0;letter-spacing:-0.01em}
.page-header__actions{display:flex;gap:0.6rem;flex-wrap:wrap}

/* ---------- Buttons ---------- */
.btn{
  --btn-height:44px;
  --btn-pad-x:1.05rem;
  --btn-icon-size:18px;
  display:inline-flex;align-items:center;gap:0.5rem;justify-content:center;
  position:relative;padding:0.6rem var(--btn-pad-x);border-radius:999px;border:1px solid var(--border-strong);
  background:var(--surface);color:var(--text);font-weight:600;font-size:0.92rem;cursor:pointer;
  transition:transform .15s var(--ease-out), box-shadow .15s ease, background .15s ease, border-color .15s ease;
  text-decoration:none;min-height:var(--btn-height);line-height:1.1;
}
.btn > svg{width:var(--btn-icon-size);height:var(--btn-icon-size);flex:0 0 var(--btn-icon-size);display:block}
.btn:hover{box-shadow:var(--shadow-sm);transform:translateY(-1px)}
.btn:active{transform:translateY(0) scale(0.98);transition-duration:.08s}
.btn-primary{background:var(--accent);border-color:var(--accent);color:#fff}
.btn-primary:hover{filter:brightness(0.92)}
.btn-danger{background:var(--danger);border-color:var(--danger);color:#fff}
.btn-ghost{background:transparent;border-color:transparent;color:var(--text-muted)}
.btn-ghost:hover{background:var(--accent-soft);color:var(--accent-strong)}
.btn-sm{--btn-height:36px;--btn-pad-x:0.8rem;--btn-icon-size:16px;padding:0.4rem var(--btn-pad-x);font-size:0.85rem}
.btn:disabled{opacity:0.5;cursor:not-allowed}
.btn--action{
  --btn-height:56px;
  min-height:var(--btn-height);gap:0.75rem;padding:0.45rem 1.2rem 0.45rem 0.55rem;
  font-weight:750;font-size:0.95rem;letter-spacing:0;
}
.btn--action .btn__icon{
  width:42px;height:42px;border-radius:999px;display:inline-flex;align-items:center;justify-content:center;
  flex:0 0 42px;background:var(--accent-soft);color:var(--accent-strong);
}
.btn--action .btn__icon svg{width:20px;height:20px;display:block}
.btn--action .btn__label{display:inline-flex;align-items:center;white-space:nowrap}
.btn--action.btn-primary .btn__icon{background:rgba(255,255,255,0.18);color:#fff}
.btn--action.btn-danger .btn__icon{background:rgba(255,255,255,0.18);color:#fff}
.btn--action.btn-ghost .btn__icon{background:var(--accent-soft);color:var(--accent-strong)}

/* ---------- Lightweight tooltips ---------- */
[data-tooltip]{position:relative}
@media (hover: hover) and (pointer: fine){
  [data-tooltip]::before,
  [data-tooltip]::after{
    position:absolute;left:50%;bottom:calc(100% + 8px);opacity:0;pointer-events:none;
    transform:translate(-50%,4px);transition:opacity .14s ease,transform .14s ease;z-index:260;
  }
  [data-tooltip]::after{
    content:attr(data-tooltip);max-width:220px;padding:0.4rem 0.55rem;border-radius:8px;
    background:var(--text);color:var(--bg);box-shadow:var(--shadow-md);
    font-size:0.75rem;font-weight:700;line-height:1.2;white-space:nowrap;text-align:center;
  }
  [data-tooltip]::before{
    content:"";width:8px;height:8px;bottom:calc(100% + 4px);background:var(--text);
    transform:translate(-50%,4px) rotate(45deg);
  }
  [data-tooltip]:hover::before,
  [data-tooltip]:hover::after,
  [data-tooltip]:focus-visible::before,
  [data-tooltip]:focus-visible::after,
  [data-tooltip]:focus-within::before,
  [data-tooltip]:focus-within::after{opacity:1;transform:translate(-50%,0)}
  [data-tooltip]:hover::before,
  [data-tooltip]:focus-visible::before,
  [data-tooltip]:focus-within::before{transform:translate(-50%,0) rotate(45deg)}
  [data-tooltip-side="left"]::before,
  [data-tooltip-side="left"]::after{
    left:auto;right:calc(100% + 8px);top:50%;bottom:auto;transform:translate(4px,-50%);
  }
  [data-tooltip-side="left"]::before{right:calc(100% + 4px);transform:translate(4px,-50%) rotate(45deg)}
  [data-tooltip-side="left"]:hover::before,
  [data-tooltip-side="left"]:hover::after,
  [data-tooltip-side="left"]:focus-visible::before,
  [data-tooltip-side="left"]:focus-visible::after,
  [data-tooltip-side="left"]:focus-within::before,
  [data-tooltip-side="left"]:focus-within::after{transform:translate(0,-50%)}
  [data-tooltip-side="left"]:hover::before,
  [data-tooltip-side="left"]:focus-visible::before,
  [data-tooltip-side="left"]:focus-within::before{transform:translate(0,-50%) rotate(45deg)}
}

/* ---------- Grid & cards ---------- */
.grid-section{margin-bottom:2.25rem}
.grid-section h2{font-size:1rem;color:var(--text-muted);text-transform:uppercase;letter-spacing:.06em;margin:0 0 0.9rem;font-weight:700}
.grid-section__head{display:flex;align-items:center;justify-content:space-between;gap:1rem;flex-wrap:wrap}
.grid-section__head h2{margin:0 0 0.9rem}
.sort-form select{
  padding:0.45rem 2rem 0.45rem 0.85rem;border-radius:999px;border:1px solid var(--border);
  background:var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2362677a' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 0.55rem center/16px no-repeat;
  color:var(--text);font-size:0.85rem;font-weight:600;cursor:pointer;appearance:none;-webkit-appearance:none;
  margin-bottom:0.9rem;
}
.sort-form select:focus-visible{outline:2px solid var(--accent);outline-offset:1px}

.audit-filter{display:flex;gap:0.6rem;flex-wrap:wrap;align-items:center;margin-bottom:1.5rem}
.audit-filter .search-box{position:relative;max-width:320px;flex:1;min-width:200px;color:var(--text-faint)}
.audit-filter .search-box svg{position:absolute;left:0.9rem;top:50%;transform:translateY(-50%);width:16px;height:16px;pointer-events:none}
.audit-filter .search-input{max-width:none}
.audit-filter select{
  padding:0.55rem 2.1rem 0.55rem 0.85rem;border-radius:999px;border:1px solid var(--border);
  background:var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2368657f' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 0.6rem center/16px no-repeat;
  color:var(--text);font-size:0.85rem;font-weight:600;cursor:pointer;appearance:none;-webkit-appearance:none;
}
.audit-filter select:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.card-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(168px,1fr));gap:1rem}

.folder-card{
  display:flex;flex-direction:column;gap:0.6rem;padding:1rem;border-radius:var(--radius-md);
  background:var(--surface);border:1px solid var(--border);text-decoration:none;color:var(--text);
  position:relative;transition:box-shadow .2s var(--ease-out), border-color .2s ease, transform .2s var(--ease-out);
  min-height:44px;
}
.folder-card:hover{box-shadow:var(--shadow-md);border-color:var(--border-strong);transform:translateY(-2px)}
.folder-card:active{transform:translateY(0);transition-duration:.08s}
.folder-card__icon{
  width:40px;height:40px;border-radius:12px;background:var(--accent-soft);display:flex;align-items:center;justify-content:center;color:var(--accent-strong);
  transition:transform .2s var(--ease-out);
}
.folder-card:hover .folder-card__icon{transform:scale(1.06)}
.folder-card__icon svg{width:22px;height:22px}
.folder-card__name{font-weight:600;font-size:0.95rem;word-break:break-word}

.file-card{
  display:flex;flex-direction:column;border-radius:var(--radius-md);overflow:visible;
  background:var(--surface);border:1px solid var(--border);cursor:pointer;
  transition:box-shadow .2s var(--ease-out), border-color .2s ease, transform .2s var(--ease-out);
}
.file-card:hover{box-shadow:var(--shadow-md);border-color:var(--border-strong);transform:translateY(-2px)}
.file-card:active{transform:translateY(0);transition-duration:.08s}
.file-card.is-selected{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent-soft),var(--shadow-sm)}
.file-card__thumb{
  aspect-ratio:1/1;background:linear-gradient(155deg,var(--bg),var(--surface));
  display:flex;align-items:center;justify-content:center;overflow:hidden;position:relative;
  border-radius:var(--radius-md) var(--radius-md) 0 0;
}
.file-card__thumb img{width:100%;height:100%;object-fit:cover;opacity:0;transition:opacity .35s var(--ease-out)}
.file-card__thumb img.is-loaded{opacity:1}
.file-card:hover .file-card__thumb img{transform:scale(1.04);transition:opacity .35s var(--ease-out), transform .4s var(--ease-out)}
.file-card__badges{position:absolute;top:0.5rem;left:0.5rem;display:flex;gap:0.35rem}
.file-card__badge{
  background:rgba(20,22,30,0.72);color:#fff;
  padding:0.2rem 0.5rem;border-radius:8px;font-size:0.7rem;font-weight:700;letter-spacing:.03em;text-transform:uppercase;
  display:flex;align-items:center;gap:0.3rem;backdrop-filter:blur(4px);
}
.file-card__badge--new{background:var(--accent)}
.file-card__body{padding:0.7rem 0.8rem}
.file-card__title{font-size:0.88rem;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.file-card__select{
  position:absolute;right:0.5rem;bottom:0.5rem;width:34px;height:34px;border-radius:999px;
  background:rgba(255,255,255,0.9);border:1px solid rgba(20,22,30,0.16);box-shadow:var(--shadow-sm);
  display:flex;align-items:center;justify-content:center;cursor:pointer;backdrop-filter:blur(6px);
}
.file-card__select input{position:absolute;inset:0;opacity:0;cursor:pointer}
.file-card__select span{
  width:17px;height:17px;border-radius:5px;border:2px solid var(--text-muted);background:var(--surface);
  transition:background .12s ease,border-color .12s ease,box-shadow .12s ease;
}
.file-card__select input:checked + span{background:var(--accent);border-color:var(--accent);box-shadow:inset 0 0 0 3px var(--surface)}
.file-card__select:focus-within{outline:2px solid var(--accent);outline-offset:2px}

.card-menu-btn{
  position:absolute;top:0.4rem;right:0.4rem;width:32px;height:32px;border-radius:999px;
  background:rgba(255,255,255,0.9);border:none;display:flex;align-items:center;justify-content:center;cursor:pointer;
  color:var(--text);box-shadow:var(--shadow-sm);
  transition:opacity .15s ease, transform .15s ease, background .15s ease;
}
.card-menu-btn:hover{background:var(--surface);color:var(--accent-strong)}
:root[data-theme="dark"] .card-menu-btn{background:rgba(30,33,43,0.9);color:var(--text)}

/* Hiiri-/kosketinlaitteilla painike voi jäädä hienovaraisesti piiloon
   ennen hoveria - kosketusnäytöillä (ei hover-kykyä) se on aina näkyvissä. */
@media (hover: hover) and (pointer: fine){
  .card-menu-btn{opacity:0;transform:scale(0.9)}
  .folder-card:hover .card-menu-btn,.folder-card:focus-within .card-menu-btn,
  .file-card:hover .card-menu-btn,.file-card:focus-within .card-menu-btn,
  .card-menu-btn:focus-visible{opacity:1;transform:scale(1)}
}

/* ---------- Skeleton loader ---------- */
.skeleton{
  position:relative;overflow:hidden;background:var(--skeleton-base);
}
.skeleton::after{
  content:"";position:absolute;inset:0;
  background:linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  transform:translateX(-100%);animation:skeleton-shine 1.6s ease-in-out infinite;
}
@keyframes skeleton-shine{100%{transform:translateX(100%)}}

/* ---------- Empty states ---------- */
.empty-state{
  display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;
  padding:4rem 1rem;color:var(--text-muted);gap:0.5rem;
  animation:fade-in-up .4s var(--ease-out);
}
.empty-state > svg{
  width:28px;height:28px;color:var(--accent-strong);margin-bottom:0.9rem;
  padding:1rem;box-sizing:content-box;border-radius:999px;background:var(--accent-soft);
}
.empty-state h3{margin:0;color:var(--text);font-size:1.1rem}
.empty-state p{max-width:32ch}
.empty-state__actions{display:flex;gap:0.65rem;flex-wrap:wrap;justify-content:center;margin-top:0.7rem}

/* ---------- Bulk actions ---------- */
.bulk-toolbar{
  display:flex;align-items:center;justify-content:space-between;gap:0.75rem;flex-wrap:wrap;
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);
  padding:0.65rem 0.75rem;margin:0 0 0.9rem;box-shadow:var(--shadow-sm);
}
.bulk-toolbar[hidden]{display:none}
.bulk-toolbar__count{font-weight:700;font-size:0.88rem;color:var(--text)}
.bulk-toolbar__actions{display:flex;align-items:center;gap:0.45rem;flex-wrap:wrap}

/* ---------- Dropzone ---------- */
.dropzone{
  border:2px dashed var(--border-strong);border-radius:var(--radius-lg);padding:2.25rem 1rem;text-align:center;
  color:var(--text-muted);transition:border-color .2s ease, background .2s ease, transform .2s var(--ease-out);
  font-size:0.92rem;
}
.dropzone.is-dragover{border-color:var(--accent);background:var(--accent-soft);transform:scale(1.01)}

@keyframes fade-in-up{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}

/* ---------- Modal ---------- */
.modal-overlay{
  position:fixed;inset:0;background:rgba(10,11,15,0.5);backdrop-filter:blur(3px);
  display:flex;align-items:center;justify-content:center;padding:1rem;z-index:100;
  animation:overlay-in .18s ease;
}
.modal{
  background:var(--surface);border-radius:var(--radius-lg);box-shadow:var(--shadow-lg);
  width:100%;max-width:520px;max-height:90dvh;overflow:auto;padding:1.5rem;
  border:1px solid var(--border);
  animation:modal-in .22s var(--ease-out);
}
.modal--wide{max-width:820px}
@keyframes overlay-in{from{opacity:0}to{opacity:1}}
@keyframes modal-in{from{opacity:0;transform:translateY(10px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}
.modal h2{margin:0 0 0.4rem;font-size:1.25rem}
.modal p.modal__desc{color:var(--text-muted);margin:0 0 1.1rem}
.modal__actions{display:flex;justify-content:flex-end;gap:0.6rem;margin-top:1.3rem}
.modal__actions--sticky{position:sticky;bottom:-1.5rem;background:var(--surface);border-top:1px solid var(--border);padding-top:0.85rem;padding-bottom:0.2rem}

/* ---------- Forms ---------- */
.field{margin-bottom:1rem}
.field label{display:block;font-weight:600;font-size:0.88rem;margin-bottom:0.35rem}
.field input[type=text], .field input[type=password], .field input[type=search],
.field input[type=date], .field input[type=datetime-local], .field input[type=number],
.field textarea, .field select,
.upload-meta-form input[type=text]{
  width:100%;padding:0.6rem 0.8rem;border-radius:var(--radius-sm);border:1px solid var(--border-strong);
  background:var(--surface);color:var(--text);font-size:0.95rem;font-family:inherit;
  transition:border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field textarea:focus, .field select:focus,
.upload-meta-form input:focus{border-color:var(--accent)}
.field input:focus-visible, .field textarea:focus-visible, .field select:focus-visible,
.upload-meta-form input:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.field textarea{min-height:90px;resize:vertical}
.password-field{position:relative}
.password-field input{padding-right:2.6rem !important}
.password-field__toggle{
  position:absolute;right:0.4rem;top:50%;transform:translateY(-50%);
  width:32px;height:32px;border:none;background:none;border-radius:8px;
  display:flex;align-items:center;justify-content:center;color:var(--text-faint);cursor:pointer;
  transition:color .15s ease,background .15s ease;
}
.password-field__toggle:hover{color:var(--text);background:var(--accent-soft)}
.password-field__toggle.is-active{color:var(--accent-strong)}
.upload-meta-form input[type=text]::placeholder{color:var(--text-faint)}
.field small{display:block;color:var(--text-faint);margin-top:0.3rem;font-size:0.8rem}
.field-error{color:var(--danger);font-size:0.85rem;margin-top:0.3rem}
.required-mark{color:var(--danger);font-weight:700}

/* ---------- Toast ---------- */
.toast-stack{position:fixed;bottom:1.25rem;right:1.25rem;display:flex;flex-direction:column;gap:0.6rem;z-index:200}
.toast{
  background:var(--text);color:var(--bg);padding:0.75rem 1.1rem;border-radius:999px;box-shadow:var(--shadow-lg);
  font-size:0.9rem;font-weight:600;animation:toast-in .25s var(--ease-out);
}
.toast.toast--error{background:var(--danger);color:#fff}
@keyframes toast-in{from{opacity:0;transform:translateY(8px) scale(.97)}to{opacity:1;transform:translateY(0) scale(1)}}

/* ---------- Lightbox ---------- */
.lightbox{position:fixed;inset:0;background:rgba(6,7,10,0.94);z-index:150;display:flex;flex-direction:column;animation:overlay-in .2s ease}
.lightbox__stage img,.lightbox__stage video{animation:fade-in-up .3s var(--ease-out)}
.lightbox__top{display:flex;justify-content:flex-end;padding:0.75rem}
.lightbox__stage{flex:1;display:flex;align-items:center;justify-content:center;position:relative;overflow:hidden;padding:0 1rem}
.lightbox__stage img{max-height:82dvh;max-width:100%;object-fit:contain;border-radius:8px}
.lightbox__stage video{max-height:82dvh;max-width:100%;border-radius:8px}
.lightbox__nav{position:absolute;top:50%;transform:translateY(-50%);width:52px;height:52px;border-radius:999px;background:rgba(255,255,255,0.12);color:#fff;border:none;display:flex;align-items:center;justify-content:center;cursor:pointer}
.lightbox__nav:hover{background:rgba(255,255,255,0.22)}
.lightbox__nav--prev{left:1rem}
.lightbox__nav--next{right:1rem}
.lightbox__info{background:var(--surface);color:var(--text);padding:1rem 1.25rem;max-height:38dvh;overflow:auto}
.lightbox__title{font-size:1.1rem;font-weight:700;margin:0 0 0.2rem}
.lightbox__toggle{background:none;border:none;color:var(--accent);font-weight:600;cursor:pointer;padding:0.3rem 0;font-size:0.88rem}
.lightbox__details{margin-top:0.6rem;display:grid;gap:0.35rem;font-size:0.9rem}
.lightbox__details dt{color:var(--text-faint);display:inline}
.lightbox__details dd{display:inline;margin:0}
.lightbox__office{background:#fff;color:#111;max-width:900px;margin:0 auto;padding:2rem;border-radius:8px;max-height:82dvh;overflow:auto;width:100%}
.lightbox__pdf{width:100%;max-width:960px;height:82dvh;border:none;border-radius:8px;background:#fff}

/* ---------- Office preview content (rendered inside iframe/container) ---------- */
.office-preview{font-family:var(--font-sans);line-height:1.6}
.office-preview__table{border-collapse:collapse;width:100%;font-size:0.85rem}
.office-preview__table td{border:1px solid #d8dae0;padding:0.3rem 0.5rem}
.office-preview__media img{max-width:100%;border-radius:8px;margin-top:0.75rem}
.office-preview__slide{border:1px solid #e0e2e8;border-radius:12px;padding:1.25rem;margin-bottom:1rem}
.office-preview__slide-number{font-size:0.75rem;text-transform:uppercase;letter-spacing:.05em;color:#8a8fa0;margin-bottom:0.5rem}
.office-preview__tabs{display:flex;gap:0.4rem;margin-bottom:1rem;flex-wrap:wrap}
.office-preview__tab{padding:0.4rem 0.8rem;border-radius:999px;border:1px solid #d8dae0;background:#f4f5f8;cursor:pointer;font-size:0.85rem}
.office-preview__tab.is-active{background:var(--accent);color:#fff;border-color:var(--accent)}
.office-preview__scroll{overflow:auto;max-height:70dvh}

/* ---------- Menu (kolme pistettä) ---------- */
.dropdown-menu{
  position:absolute;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);
  box-shadow:var(--shadow-lg);padding:0.4rem;min-width:200px;z-index:120;
  animation:menu-in .15s var(--ease-out);transform-origin:top right;
}
@keyframes menu-in{from{opacity:0;transform:scale(.96) translateY(-4px)}to{opacity:1;transform:scale(1) translateY(0)}}
.dropdown-menu button{
  display:flex;align-items:center;gap:0.6rem;width:100%;text-align:left;padding:0.55rem 0.7rem;border:none;background:none;
  border-radius:10px;cursor:pointer;color:var(--text);font-size:0.9rem;min-height:40px;
}
.dropdown-menu button:hover{background:var(--accent-soft);color:var(--accent-strong)}
.dropdown-menu button.danger{color:var(--danger)}
.dropdown-menu button.danger:hover{background:var(--danger-soft)}
.dropdown-menu hr{border:none;border-top:1px solid var(--border);margin:0.3rem 0}

/* ---------- Tables (users/audit/settings status) ---------- */
.data-table{width:100%;border-collapse:collapse;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);overflow:hidden}
.data-table th,.data-table td{padding:0.75rem 1rem;text-align:left;border-bottom:1px solid var(--border);font-size:0.9rem}
.data-table th{color:var(--text-muted);font-weight:700;font-size:0.78rem;text-transform:uppercase;letter-spacing:.04em}
.data-table tr:last-child td{border-bottom:none}
.data-table tbody tr{transition:background .12s ease}
.data-table tbody tr:hover{background:var(--bg)}
.data-table__actions{text-align:right}
.data-table__action-buttons{display:flex;gap:0.4rem;justify-content:flex-end;flex-wrap:wrap}
.data-table select{
  padding:0.5rem 2.1rem 0.5rem 0.8rem;border-radius:10px;border:1px solid var(--border-strong);
  background:var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2368657f' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 0.6rem center/16px no-repeat;
  color:var(--text);font-size:0.88rem;font-weight:600;font-family:inherit;cursor:pointer;appearance:none;-webkit-appearance:none;
  transition:border-color .15s ease;
}
.data-table select:hover{border-color:var(--accent)}
.data-table select:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.pill{display:inline-flex;align-items:center;padding:0.2rem 0.6rem;border-radius:999px;font-size:0.75rem;font-weight:700;background:var(--accent-soft);color:var(--accent-strong)}
.pill--success{background:var(--success-soft);color:var(--success)}
.pill--danger{background:var(--danger-soft);color:var(--danger)}

.status-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:0.9rem;margin-bottom:2rem}
.status-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);padding:1rem;transition:box-shadow .2s var(--ease-out), transform .2s var(--ease-out)}
.status-card:hover{box-shadow:var(--shadow-sm);transform:translateY(-1px)}
.status-card__label{font-size:0.78rem;color:var(--text-muted);text-transform:uppercase;letter-spacing:.04em;margin-bottom:0.4rem}
.status-card__value{font-size:1.4rem;font-weight:700;letter-spacing:-0.01em;font-variant-numeric:tabular-nums}

.status-list{display:flex;flex-direction:column;gap:0.7rem}
.status-list__item{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);padding:0.9rem 1.1rem}
.status-list__head{display:flex;align-items:center;justify-content:space-between;gap:0.75rem;flex-wrap:wrap}
.status-list__label{font-weight:700;font-size:0.95rem}
.status-list__desc{margin:0.4rem 0 0;color:var(--text-muted);font-size:0.88rem;line-height:1.55;max-width:68ch}
.status-list__fallback{margin:0.4rem 0 0;color:var(--text-muted);font-size:0.85rem;line-height:1.55;max-width:68ch;padding-top:0.4rem;border-top:1px dashed var(--border)}
.status-list__fallback strong{color:var(--text)}
code{background:var(--bg);border:1px solid var(--border);border-radius:5px;padding:0.1em 0.4em;font-size:0.88em;font-family:ui-monospace,"SF Mono",Consolas,monospace}

/* ---------- Upload queue ---------- */
.upload-stepper{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:0.45rem;margin:0 0 0.9rem}
.upload-step{
  display:flex;align-items:center;justify-content:center;gap:0.35rem;min-height:36px;
  border:1px solid var(--border);border-radius:999px;background:var(--surface);color:var(--text-muted);
  font-size:0.82rem;font-weight:700;
}
.upload-step span{
  display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:999px;
  background:var(--bg);color:var(--text-muted);font-size:0.72rem;font-variant-numeric:tabular-nums;
}
.upload-step.is-active{border-color:var(--accent);color:var(--accent-strong);background:var(--accent-soft)}
.upload-step.is-active span,.upload-step.is-complete span{background:var(--accent);color:#fff}
.upload-step.is-complete{color:var(--text)}
.upload-support{
  display:grid;grid-template-columns:auto minmax(0,1fr);gap:0.65rem;align-items:flex-start;
  margin:0 0 0.95rem;padding:0.78rem 0.85rem;border:1px solid var(--border);
  border-radius:var(--radius-sm);background:var(--accent-soft);
}
.upload-support svg{width:20px;height:20px;color:var(--accent-strong);margin-top:0.1rem}
.upload-support strong{display:block;margin-bottom:0.15rem;font-size:0.86rem;color:var(--text)}
.upload-support p{margin:0;color:var(--text-muted);font-size:0.83rem;line-height:1.45}
.upload-support small{display:block;margin-top:0.25rem;color:var(--text-muted);font-size:0.78rem;line-height:1.4}
.upload-picker{width:100%;justify-content:center;cursor:pointer}
.upload-overall{
  border:1px solid var(--border);border-radius:var(--radius-md);background:var(--accent-soft);
  padding:0.75rem 0.9rem;margin-top:0.9rem;display:grid;gap:0.45rem;
}
.upload-overall[hidden]{display:none}
.upload-overall__row{display:flex;justify-content:space-between;align-items:center;gap:0.75rem;font-size:0.86rem}
.upload-overall__row strong{color:var(--text)}
.upload-overall__row span{color:var(--accent-strong);font-weight:700;white-space:nowrap}
.upload-overall__bar{height:8px;border-radius:999px;background:var(--surface);overflow:hidden;border:1px solid var(--border)}
.upload-overall__bar-fill{height:100%;width:0%;background:var(--accent);transition:width .2s ease}
.upload-overall small{color:var(--text-muted);font-size:0.78rem;line-height:1.4}
.upload-queue{display:flex;flex-direction:column;gap:0.6rem;margin-top:1rem}
.upload-queue[hidden]{display:none}
.upload-hint{margin:0.7rem 0 0;color:var(--text-muted);font-size:0.86rem;line-height:1.45;text-align:center}
.upload-item{border:1px solid var(--border);border-radius:var(--radius-md);padding:0.7rem 0.9rem}
.upload-item__row{display:flex;justify-content:space-between;align-items:center;gap:0.5rem;font-size:0.88rem}
.upload-item__name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600}
.upload-item__bar{height:6px;border-radius:999px;background:var(--border);margin-top:0.5rem;overflow:hidden}
.upload-item__bar-fill{height:100%;background:var(--accent);width:0%;transition:width .2s ease}
.upload-item--error .upload-item__bar-fill{background:var(--danger)}
.upload-item__status{font-size:0.78rem;color:var(--text-muted)}
.upload-meta-form{display:grid;gap:0.5rem;margin-top:0.6rem}

/* ---------- Auth (guest layout) ---------- */
.auth-shell{
  min-height:100dvh;display:flex;flex-direction:column;
  background:
    radial-gradient(circle at 18% 12%, var(--accent-soft), transparent 50%),
    radial-gradient(circle at 85% 88%, var(--accent-soft), transparent 45%),
    var(--bg);
}
.auth-shell__center{flex:1;display:flex;align-items:center;justify-content:center;padding:1.5rem}
.auth-card{
  width:100%;max-width:400px;background:var(--surface-glass);backdrop-filter:blur(20px) saturate(1.4);
  -webkit-backdrop-filter:blur(20px) saturate(1.4);
  border:1px solid var(--border);border-radius:var(--radius-lg);box-shadow:var(--shadow-lg);padding:2.5rem 2rem;
  animation:fade-in-up .5s var(--ease-out);
}
.auth-card__title{text-align:center;font-size:1.6rem;margin:0 0 0.3rem;letter-spacing:-0.015em}
.auth-card__subtitle{text-align:center;color:var(--text-muted);margin:0 0 1.75rem;font-size:0.92rem}
.auth-card .btn-primary{width:100%;margin-top:0.5rem}

/* ---------- Error pages ---------- */
.error-shell{
  min-height:100dvh;display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:1.25rem;padding:2rem 1rem;background:var(--bg);text-align:center;
}
.error-card{
  width:100%;max-width:520px;background:var(--surface-glass);backdrop-filter:blur(20px) saturate(1.4);
  -webkit-backdrop-filter:blur(20px) saturate(1.4);
  border:1px solid var(--border);border-radius:var(--radius-lg);box-shadow:var(--shadow-lg);
  padding:2.2rem 1.8rem;display:flex;flex-direction:column;align-items:center;gap:1rem;
  animation:fade-in-up .5s var(--ease-out);
}
.error-brand{
  display:inline-flex;align-items:center;gap:0.7rem;color:var(--text);text-decoration:none;
  font-weight:800;font-size:1rem;letter-spacing:0;
}
.error-brand img{width:38px;height:38px;border-radius:12px;object-fit:cover;box-shadow:var(--shadow-sm)}
.error-status{
  width:68px;height:68px;border-radius:22px;display:flex;align-items:center;justify-content:center;
  color:var(--accent-strong);background:var(--accent-soft);margin-top:0.25rem;
}
.error-status svg{width:31px;height:31px;display:block}
.error-code{
  margin:0;color:var(--accent-strong);font-size:0.78rem;font-weight:800;text-transform:uppercase;
  letter-spacing:0;
}
.error-card h1{margin:0;color:var(--text);font-size:2rem;line-height:1.12;letter-spacing:0}
.error-card p{margin:0;color:var(--text-muted);max-width:42ch}
.error-actions{display:flex;justify-content:center;gap:0.75rem;flex-wrap:wrap;margin-top:0.45rem}

/* ---------- Kirjautumissivun alatunniste (ei sivupalkkia siellä) ---------- */
.app-footer{
  display:flex;align-items:center;justify-content:center;gap:0.4rem 1rem;flex-wrap:wrap;
  padding:1.25rem 1.25rem;text-align:center;
  font-size:0.78rem;color:var(--text-faint);
}
.app-footer a{color:var(--text-muted);font-weight:600;text-decoration:none}
.app-footer a:hover{color:var(--accent-strong);text-decoration:underline}
.app-footer__version{opacity:0.75}

/* ---------- Sivupalkin alaosa (copyright, versio) ---------- */
.sidebar__footer{
  display:flex;flex-direction:column;gap:0.15rem;padding:0.9rem 0.6rem 0.2rem;
  font-size:0.72rem;color:var(--sidebar-text-muted);
}
.sidebar__footer a{color:var(--sidebar-text-muted);font-weight:600;text-decoration:none}
.sidebar__footer a:hover{color:var(--sidebar-text);text-decoration:underline}

/* ---------- Theme switcher ---------- */
.theme-switch{display:flex;background:var(--bg);border-radius:999px;padding:3px;border:1px solid var(--border)}
.theme-switch button{border:none;background:none;padding:0.4rem 0.6rem;border-radius:999px;cursor:pointer;color:var(--text-muted);display:flex;transition:background .15s ease, color .15s ease}
.theme-switch button:hover{color:var(--text)}
.theme-switch button.is-active{background:var(--surface);color:var(--accent-strong);box-shadow:var(--shadow-sm)}
.theme-switch svg{width:18px;height:18px}
.theme-switch--sidebar{
  background:var(--sidebar-hover);border:1px solid var(--sidebar-border);
  margin:0.7rem 0;padding:4px;justify-content:space-between;
}
.theme-switch--sidebar button{flex:1;justify-content:center;color:var(--sidebar-text-muted);padding:0.5rem 0}
.theme-switch--sidebar button:hover{color:var(--sidebar-text)}
.theme-switch--sidebar button.is-active{background:var(--accent);color:#fff;box-shadow:0 2px 8px rgba(47,143,131,0.34)}

/* ---------- Pagination ---------- */
.pagination{display:flex;gap:0.4rem;justify-content:center;margin-top:2rem}
.pagination a, .pagination span{padding:0.5rem 0.9rem;border-radius:999px;border:1px solid var(--border);text-decoration:none;color:var(--text);font-size:0.88rem}
.pagination a:hover{background:var(--accent-soft)}
.pagination .is-current{background:var(--accent);color:#fff;border-color:var(--accent)}

/* ---------- Alavalikko (mobiili) ---------- */
.bottom-nav{
  display:none;position:fixed;left:0;right:0;bottom:0;z-index:60;
  background:var(--surface-glass);
  backdrop-filter:blur(16px) saturate(1.4);-webkit-backdrop-filter:blur(16px) saturate(1.4);
  border-top:1px solid var(--border);
  padding:0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom));
  justify-content:space-around;
}
.bottom-nav__item{
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0.2rem;
  padding:0.35rem 0.5rem;border-radius:14px;color:var(--text-muted);text-decoration:none;
  font-size:0.66rem;font-weight:600;background:none;border:none;cursor:pointer;
  min-width:56px;min-height:48px;transition:color .15s ease, background .15s ease;
}
.bottom-nav__item svg{width:22px;height:22px}
.bottom-nav__item.is-active{color:var(--accent-strong);background:var(--accent-soft)}
.bottom-nav__item:active{transform:scale(.94)}

/* ---------- Alhaalta liukuva "Lisää"-arkki (mobiili) ---------- */
.sheet-overlay{
  position:fixed;inset:0;background:rgba(10,11,15,0.5);z-index:170;
  display:flex;align-items:flex-end;justify-content:center;animation:overlay-in .18s ease;
}
.sheet{
  width:100%;max-width:480px;background:var(--surface);border-radius:22px 22px 0 0;
  padding:0.5rem 0.6rem calc(1rem + env(safe-area-inset-bottom));box-shadow:var(--shadow-lg);
  animation:sheet-in .25s var(--ease-out);border:1px solid var(--border);border-bottom:none;
}
.sheet__handle{width:36px;height:4px;background:var(--border-strong);border-radius:999px;margin:0.5rem auto 0.75rem}
.sheet__item{
  display:flex;align-items:center;gap:0.8rem;padding:0.85rem 0.9rem;border-radius:14px;
  text-decoration:none;color:var(--text);font-size:0.95rem;font-weight:600;border:none;background:none;
  width:100%;text-align:left;cursor:pointer;min-height:44px;
}
.sheet__item svg{width:20px;height:20px;color:var(--text-muted);flex-shrink:0}
.sheet__item:hover{background:var(--bg)}
.sheet__item--static{cursor:default}
.sheet__item--static:hover{background:none}
.sheet__item--danger{color:var(--danger)}
.sheet__item--danger svg{color:var(--danger)}
.sheet hr{border:none;border-top:1px solid var(--border);margin:0.4rem 0.5rem}
.sheet__footer{
  display:flex;flex-direction:column;gap:0.15rem;padding:0.7rem 0.9rem 0.2rem;
  font-size:0.72rem;color:var(--text-faint);
}
.sheet__footer a{color:var(--text-muted);font-weight:600;text-decoration:none}
.sheet__footer a:hover{color:var(--accent-strong);text-decoration:underline}
@keyframes sheet-in{from{transform:translateY(100%)}to{transform:translateY(0)}}

/* ---------- Henkilön profiili ---------- */
.person-header{display:flex;gap:1.25rem;align-items:flex-start;margin-bottom:2rem;flex-wrap:wrap}
.person-header__photo-wrap{position:relative;width:112px;height:112px;flex-shrink:0}
.person-header__photo{
  width:100%;height:100%;border-radius:50%;overflow:hidden;
  background:var(--accent-soft);display:flex;align-items:center;justify-content:center;
  box-shadow:var(--shadow-sm);border:1px solid var(--border);
}
.person-header__photo img{width:100%;height:100%;object-fit:cover}
.person-header__initial{font-size:2.4rem;font-weight:700;color:var(--accent-strong)}
.person-header__photo-edit{
  position:absolute;right:-4px;bottom:-4px;width:32px;height:32px;border-radius:50%;
  background:var(--surface);border:1px solid var(--border);display:flex;align-items:center;justify-content:center;
  color:var(--text-muted);cursor:pointer;box-shadow:var(--shadow-sm);z-index:2;
}
.person-header__photo-edit:hover{color:var(--accent-strong);border-color:var(--accent)}
.person-header__info{flex:1;min-width:200px}
.person-header__info h1{margin:0 0 0.15rem;font-size:1.6rem;letter-spacing:-0.01em;display:flex;align-items:center;gap:0.4rem}
.person-header__gender{display:inline-flex;color:var(--accent-strong)}
.person-header__gender svg{width:18px;height:18px}
.person-header__gender--male{color:var(--gender-male)}
.person-header__gender--female{color:var(--gender-female)}
.person-header__gender--other{color:var(--gender-other)}
.person-header__maiden{color:var(--text-muted);font-size:0.95rem}
.person-header__lifespan{color:var(--text-muted);font-size:0.9rem;margin-top:0.15rem}
.person-header__actions{display:flex;gap:0.6rem;margin-top:0.9rem;flex-wrap:wrap}

.relationship-groups{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:1.25rem}
.relationship-group h3{margin:0 0 0.6rem;font-size:0.85rem;color:var(--text-muted);font-weight:700}
.relationship-list{list-style:none;margin:0 0 0.7rem;padding:0;display:grid;gap:0.4rem}
.relationship-list li{display:flex;align-items:center;justify-content:space-between;gap:0.5rem}
.relationship-list a{
  color:var(--text);text-decoration:none;font-weight:600;font-size:0.92rem;
  padding:0.4rem 0.7rem;border-radius:10px;background:var(--bg);flex:1;
}
.relationship-list a:hover{background:var(--accent-soft);color:var(--accent-strong)}
.relationship-remove{
  width:26px;height:26px;border-radius:50%;border:none;background:none;color:var(--text-faint);
  cursor:pointer;font-size:1.1rem;line-height:1;flex-shrink:0;
}
.relationship-remove:hover{background:var(--danger-soft);color:var(--danger)}

/* ---------- Henkilöiden tagaus-ehdotukset (kuvien lataus/muokkaus) ---------- */
.people-autocomplete{position:relative;display:block}
.people-autocomplete input{width:100%}

/* ---------- Sukupuu-haku (topbar) ---------- */
.tree-search{position:relative;min-width:220px}
.tree-search input{
  width:100%;padding:0.55rem 0.9rem;border-radius:999px;border:1px solid var(--border);
  background:var(--surface);color:var(--text);font-size:0.9rem;
}
.tree-search input:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.picker-results{
  list-style:none;margin:0.35rem 0 0;padding:0.35rem;position:absolute;left:0;right:0;z-index:20;
  background:var(--surface);border:1px solid var(--border);border-radius:14px;box-shadow:var(--shadow-md);
  max-height:280px;overflow:auto;
}
.picker-results li{display:block}
.picker-results button{
  width:100%;text-align:left;padding:0.5rem 0.7rem;border-radius:10px;border:none;background:none;
  color:var(--text);cursor:pointer;font-size:0.9rem;
}
.picker-results button:hover{background:var(--accent-soft);color:var(--accent-strong)}
.picker-results__empty{padding:0.5rem 0.7rem;color:var(--text-faint);font-size:0.85rem}
.picker-results a{
  display:flex;align-items:center;gap:0.6rem;width:100%;text-align:left;padding:0.45rem 0.6rem;border-radius:10px;
  color:var(--text);cursor:pointer;font-size:0.87rem;text-decoration:none;
}
.picker-results a:hover{background:var(--accent-soft);color:var(--accent-strong)}
.picker-results__icon{width:16px;height:16px;flex-shrink:0;color:var(--text-faint)}
.picker-results__thumb{width:28px;height:28px;border-radius:6px;overflow:hidden;flex-shrink:0;background:var(--bg)}
.picker-results__thumb img{width:100%;height:100%;object-fit:cover}
.picker-results__new{background:var(--accent);color:#fff;font-size:0.65rem;font-weight:700;padding:0.1rem 0.4rem;border-radius:5px;text-transform:uppercase}
.picker-results__all{border-top:1px solid var(--border);margin-top:0.3rem;padding-top:0.3rem}
.picker-results__all button{color:var(--accent-strong);font-weight:600}

/* ---------- Sukupuu-kaavio ---------- */
.tree-view{position:relative;border:1px solid var(--border);border-radius:var(--radius-lg);background:var(--surface);overflow:hidden}
.tree-view:fullscreen,
.tree-view.tree-view--fullscreen{
  width:100vw;height:100dvh;border:0;border-radius:0;background:var(--surface);z-index:500;
}
.tree-view.tree-view--fullscreen{position:fixed;inset:0}
.tree-view:fullscreen .tree-view__canvas,
.tree-view.tree-view--fullscreen .tree-view__canvas{height:100dvh}
.tree-view-fullscreen-active{overflow:hidden}
.tree-view__controls{
  position:absolute;top:0.75rem;right:0.75rem;z-index:10;display:flex;flex-direction:column;gap:0.2rem;
  background:var(--surface);border:1px solid var(--border);border-radius:14px;padding:0.25rem;box-shadow:var(--shadow-md);
}
.tree-view__controls button{
  width:36px;height:36px;border-radius:10px;border:none;background:none;
  color:var(--text-muted);font-size:1.15rem;cursor:pointer;transition:background .15s ease, color .15s ease;
  display:flex;align-items:center;justify-content:center;
}
.tree-view__controls button svg{width:18px;height:18px;display:block}
.tree-view__controls button:hover{color:var(--accent-strong);background:var(--accent-soft)}
.tree-view__controls button.is-active{color:#fff;background:var(--accent)}
.tree-view__canvas{
  height:70vh;overflow:hidden;cursor:grab;touch-action:none;
  background-image:radial-gradient(var(--border-strong) 1px, transparent 1px);
  background-size:22px 22px;
}
.tree-view__canvas:focus-visible{outline:2px solid var(--accent);outline-offset:-3px}
.tree-view__canvas.is-dragging{cursor:grabbing}
.tree-view__canvas svg{transform-origin:0 0;transition:none;visibility:hidden}
.tree-view__canvas.is-tree-ready svg{visibility:visible;transition:transform .05s linear}

.tree-edge{fill:none;stroke:var(--border-strong);stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}

.tree-card{
  display:flex;align-items:center;gap:0.55rem;width:100%;height:100%;padding:0.5rem 0.65rem;
  border-radius:14px;border:1px solid var(--border-strong);background:var(--surface);box-shadow:var(--shadow-sm);
  cursor:pointer;position:relative;box-sizing:border-box;font-family:var(--font-sans);
  transition:box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
/* Ei transform-siirtoa eikä tavallista (ulospäin lankeavaa) box-shadow'ta
   hoverissa: kortti elää SVG:n foreignObject-kehyksen sisällä, joka leikkaa
   kaiken sisällön tiukasti omiin rajoihinsa - siirto typistäisi yläreunan
   pyöristyksen, ja ulospäin lankeava varjo ei näkyisi lainkaan. Käytetään
   siksi sisäänpäin piirtyvää (inset) korostusrengasta. */
.tree-card:hover{box-shadow:inset 0 0 0 2px var(--accent)}
.tree-card:focus-visible{outline:2px solid var(--accent);outline-offset:-3px;box-shadow:inset 0 0 0 2px var(--accent)}
.tree-card--center{border-color:var(--accent-strong);border-width:2px;background:var(--accent-soft)}
.tree-card--male{border-left:4px solid var(--gender-male);background:var(--gender-male-soft)}
.tree-card--female{border-left:4px solid var(--gender-female);background:var(--gender-female-soft)}
.tree-card--other{border-left:4px solid var(--gender-other);background:var(--gender-other-soft)}
.tree-card--male.tree-card--center,.tree-card--female.tree-card--center,.tree-card--other.tree-card--center{border-top-color:var(--accent-strong);border-right-color:var(--accent-strong);border-bottom-color:var(--accent-strong)}
/* Poisnukkuneet himmennetään hieman, jotta elossa olevat sukulaiset erottuvat puusta nopealla vilkaisulla. */
.tree-card--deceased{opacity:0.72;filter:saturate(0.75)}
.tree-card--deceased:hover{opacity:1;filter:saturate(1)}
.tree-card__photo{
  width:38px;height:38px;border-radius:50%;overflow:hidden;flex-shrink:0;background:var(--accent-soft);
  display:flex;align-items:center;justify-content:center;box-shadow:inset 0 0 0 1px var(--border);
}
.tree-card__photo img{width:100%;height:100%;object-fit:cover}
.tree-card__initial{font-weight:800;color:var(--accent-strong);font-size:0.9rem;letter-spacing:0;line-height:1}
.tree-card--male .tree-card__photo{background:var(--gender-male-soft)}
.tree-card--male .tree-card__initial{color:var(--gender-male)}
.tree-card--female .tree-card__photo{background:var(--gender-female-soft)}
.tree-card--female .tree-card__initial{color:var(--gender-female)}
.tree-card--other .tree-card__photo{background:var(--gender-other-soft)}
.tree-card--other .tree-card__initial{color:var(--gender-other)}
.tree-card__body{min-width:0;flex:1}
.tree-card__name{
  font-size:0.8rem;font-weight:700;color:var(--text);line-height:1.25;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
.tree-card__years{font-size:0.7rem;color:var(--text-faint);margin-top:0.15rem}
.tree-card__gender{display:inline-flex;vertical-align:-2px;margin-left:0.2rem;color:var(--accent-strong)}
.tree-card__gender svg{width:11px;height:11px}
.tree-card__gender--male{color:var(--gender-male)}
.tree-card__gender--female{color:var(--gender-female)}
.tree-card__gender--other{color:var(--gender-other)}
.tree-card__profile{
  position:absolute;top:0.25rem;right:0.25rem;width:20px;height:20px;border-radius:50%;
  display:flex;align-items:center;justify-content:center;color:var(--text-faint);background:var(--surface);
  border:1px solid var(--border);
}
@media (hover: hover){
  .tree-card__profile{opacity:0;transition:opacity .15s ease}
  .tree-card:hover .tree-card__profile,.tree-card:focus-within .tree-card__profile{opacity:1}
}
.tree-card__profile:hover{color:var(--accent-strong)}
.tree-card__menu-btn{
  position:absolute;top:0.25rem;right:1.55rem;width:20px;height:20px;border-radius:50%;border:none;
  display:flex;align-items:center;justify-content:center;color:var(--text-faint);background:var(--surface);
  cursor:pointer;padding:0;
}
@media (hover: hover){
  .tree-card__menu-btn{opacity:0;transition:opacity .15s ease}
  .tree-card:hover .tree-card__menu-btn,.tree-card:focus-within .tree-card__menu-btn{opacity:1}
}
.tree-card__menu-btn:hover{color:var(--accent-strong)}
.tree-tooltip{
  position:absolute;z-index:40;max-width:240px;padding:0.42rem 0.58rem;border-radius:8px;
  background:var(--text);color:var(--bg);box-shadow:var(--shadow-md);
  font-size:0.75rem;font-weight:700;line-height:1.2;text-align:center;white-space:normal;
  pointer-events:none;opacity:0;transform:translate(-50%,calc(-100% - 10px));
  transition:opacity .12s ease,transform .12s ease;
}
.tree-tooltip::after{
  content:"";position:absolute;left:50%;bottom:-4px;width:8px;height:8px;background:var(--text);
  transform:translateX(-50%) rotate(45deg);
}
.tree-tooltip.tree-tooltip--below{transform:translate(-50%,10px)}
.tree-tooltip.tree-tooltip--below::after{top:-4px;bottom:auto}
.tree-tooltip.is-visible{opacity:1}
.tree-tooltip[hidden]{display:none}

/* ---------- Ohje-sivu (haitari) ---------- */
.help-intro{font-size:1.05rem;color:var(--text-muted);max-width:60ch;margin-bottom:1.5rem}
.help-accordion{display:flex;flex-direction:column;gap:0.7rem;max-width:70ch}
.help-item{
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);
  overflow:hidden;transition:border-color .15s ease;
}
.help-item[open]{border-color:var(--border-strong)}
.help-item summary{
  padding:1rem 1.25rem;font-weight:700;font-size:1rem;cursor:pointer;list-style:none;
  display:flex;align-items:center;justify-content:space-between;color:var(--text);
  transition:background .15s ease;
}
.help-item summary:hover{background:var(--bg)}
.help-item summary::-webkit-details-marker{display:none}
.help-item summary::after{
  content:'';width:10px;height:10px;flex-shrink:0;margin-left:1rem;
  border-right:2px solid var(--text-faint);border-bottom:2px solid var(--text-faint);
  transform:rotate(45deg);transition:transform .2s ease;
}
.help-item[open] summary::after{transform:rotate(-135deg)}
.help-item__body{padding:0 1.25rem 1.25rem}
.help-item__body h3{font-size:0.95rem;margin:1.2rem 0 0.5rem}
.help-item__body h3:first-child{margin-top:0}
.help-item__body p{line-height:1.65;margin:0 0 0.9rem}
.help-item__body ol, .help-item__body ul{line-height:1.8;padding-left:1.4rem;margin:0 0 0.9rem}
.help-diagram{
  background:var(--bg);border:1px solid var(--border);border-radius:var(--radius-md);
  padding:1rem;margin:0 0 1.25rem;max-width:420px;
}
.help-diagram svg{width:100%;height:auto;display:block}
.help-tip{
  background:var(--accent-soft);border-radius:var(--radius-sm);padding:0.7rem 0.9rem;
  font-size:0.9rem;color:var(--text);
}

/* ---------- Sivun latauspalkki ---------- */
.page-progress{
  position:fixed;top:0;left:0;height:3px;width:0;
  background:var(--accent);z-index:9999;
  opacity:0;transition:width 0.4s ease,opacity 0.25s ease;
  pointer-events:none;
}
.page-progress.is-active{opacity:1}
.page-progress.is-done{width:100% !important;opacity:0}

/* ---------- Responsive ---------- */
@media (max-width: 1080px){
  .sidebar{display:none}
  .main{padding:1rem 0.85rem calc(5.5rem + env(safe-area-inset-bottom))}
  .card-grid{grid-template-columns:repeat(auto-fill,minmax(132px,1fr))}
  .lightbox__nav{width:44px;height:44px}
  .bottom-nav{display:flex}
  .tree-search{min-width:0;width:100%}
  .tree-view__canvas{height:58vh}
}

@media (max-width: 720px){
  .page-header__actions{width:100%}
  .page-header__actions .btn--action{flex:1 1 160px}
  .empty-state__actions{width:100%}
  .empty-state__actions .btn--action{flex:1 1 160px}
  .error-shell{padding:1.25rem 0.85rem}
  .error-card{padding:1.75rem 1.2rem;border-radius:var(--radius-md)}
  .error-card h1{font-size:1.65rem}
  .error-actions{width:100%;display:grid;grid-template-columns:1fr}
  .error-actions .btn{width:100%}
  .search-page-form{max-width:none}
  .search-page-form__row{display:grid;grid-template-columns:minmax(0,1fr) auto}
  .search-filter-tabs{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}
  .search-filter-tabs__item span{width:100%;justify-content:center}
  .bulk-toolbar{position:sticky;top:0.65rem;z-index:20}
  .bulk-toolbar__actions{width:100%}
  .bulk-toolbar__actions .btn{flex:1;justify-content:center}
  .modal{padding:1.1rem;max-height:92dvh}
  .modal__actions--sticky{bottom:-1.1rem;margin-left:-1.1rem;margin-right:-1.1rem;padding-left:1.1rem;padding-right:1.1rem}
  .upload-step{font-size:0.76rem}
  .upload-overall__row{align-items:flex-start;flex-direction:column;gap:0.2rem}
  .upload-overall__row span{white-space:normal}
  .upload-item__row{align-items:flex-start;flex-direction:column}
  .data-table--responsive{display:block;background:transparent;border:none;overflow:visible}
  .data-table--responsive thead{display:none}
  .data-table--responsive tbody{display:grid;gap:0.75rem}
  .data-table--responsive tr{
    display:grid;gap:0.75rem;background:var(--surface);border:1px solid var(--border);
    border-radius:var(--radius-md);padding:0.85rem;
  }
  .data-table--responsive th,.data-table--responsive td{border-bottom:none;padding:0}
  .data-table--responsive td{
    display:grid;grid-template-columns:minmax(7.5rem,40%) minmax(0,1fr);
    align-items:center;gap:0.75rem;font-size:0.9rem;
  }
  .data-table--responsive td::before{
    content:attr(data-label);color:var(--text-muted);font-size:0.72rem;font-weight:700;
    text-transform:uppercase;letter-spacing:.04em;
  }
  .data-table--responsive .data-table__actions{text-align:left}
  .data-table--responsive .data-table__actions::before{align-self:start;padding-top:0.45rem}
  .data-table--responsive .data-table__action-buttons{justify-content:flex-start}
}
