/* ============================================================
   BASE — reset, typografia, sovelluskuori, boot-tila, utilityt
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: 1.55;
  color: var(--ink-700);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: var(--navy-600); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { list-style: none; }
strong, b { font-weight: 600; color: var(--ink-900); }
::selection { background: var(--navy-100); }

h1, .h1 { font-family: var(--font-display); font-weight: 800; font-size: var(--fs-h1); line-height: 1.33; letter-spacing: -0.02em; color: var(--ink-900); }
h2, .h2 { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-h2); line-height: 1.45; color: var(--ink-900); }
h3, .h3 { font-weight: 600; font-size: var(--fs-h3); line-height: 1.45; color: var(--ink-900); }

.micro-label {
  font-size: var(--fs-micro); font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-500);
}
.mono { font-family: var(--font-mono); font-size: var(--fs-mono); }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-500); }
.faded { color: var(--ink-400); }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-xs); }
:focus:not(:focus-visible) { outline: none; }

/* Scrollbarit */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-300); border-radius: 5px; border: 2px solid var(--bg-page); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-300); }

/* ---------- Boot-tila (ennen JS:ää) ---------- */
.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 800px at 30% 20%, var(--navy-800), var(--navy-950));
}
.boot-mark { display: flex; flex-direction: column; align-items: center; gap: 18px; animation: bootIn 600ms var(--ease-out); }
.boot-logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: linear-gradient(135deg, var(--navy-700), var(--navy-850));
  border: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}
.boot-logo::after {
  content: ""; position: absolute; inset: 14px;
  background: var(--amber-500);
  -webkit-mask: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z'/%3E%3Ccircle cx='16.5' cy='7.5' r='.5' fill='black'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z'/%3E%3Ccircle cx='16.5' cy='7.5' r='.5' fill='black'/%3E%3C/svg%3E") center / contain no-repeat;
}
.boot-name {
  font-family: var(--font-display); font-weight: 800; font-size: 20px; letter-spacing: 0.12em;
  color: #fff; text-align: center;
}
.boot-name span { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.02em; color: var(--amber-400); margin-top: 2px; }
@keyframes bootIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Sovelluskuori ---------- */
.shell { display: flex; height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 auto; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--side-bg-top), var(--side-bg-bottom));
  position: relative; z-index: 40; overflow: hidden;
  transition: width var(--t-slow) var(--ease-standard);
}
.sidebar::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--pattern-contour); background-size: 420px; opacity: 0.04;
}
.sidebar::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--pattern-grain); background-size: 140px; opacity: 0.025;
}
.sidebar > * { position: relative; z-index: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-6); background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(12px) saturate(1.4); backdrop-filter: blur(12px) saturate(1.4);
  border-bottom: 1px solid var(--line-200); position: relative; z-index: 30;
}

.view {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; position: relative;
  scroll-behavior: smooth;
}
.view-pad { max-width: var(--content-max); margin: 0 auto; padding: var(--sp-6) var(--sp-8) var(--sp-16); }

/* Näkymäsiirtymä */
.view-enter { animation: viewIn var(--t-base) var(--ease-out); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-exit { opacity: 0; transition: opacity var(--t-fast) linear; }

/* ---------- Grid-utilityt ---------- */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--sp-4); }
.col-3 { grid-column: span 3; } .col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; } .col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; } .col-12 { grid-column: span 12; }
.row { display: flex; align-items: center; gap: var(--sp-2); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

.icon { width: 18px; height: 18px; flex: 0 0 auto; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 24px; height: 24px; }

/* Porrastettu sisääntulo (motion.js lisää .reveal-go) */
.reveal { opacity: 0; transform: translateY(8px); }
.reveal-go { opacity: 1; transform: none; transition: opacity var(--t-reveal) var(--ease-out), transform var(--t-reveal) var(--ease-out); }

/* Login-tila: kromi piiloon, näkymä koko ruutuun */
.chrome-hidden .sidebar, .chrome-hidden .topbar { display: none; }
.chrome-hidden .view { height: 100vh; }

/* AI-streamauksen kursori */
.tw-cursor {
  display: inline-block; width: 2px; height: 1em; margin-left: 1px;
  background: var(--amber-500); vertical-align: text-bottom;
  animation: twBlink 1s steps(2) infinite;
}
@keyframes twBlink { 50% { opacity: 0; } }

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

/* ---------- Responsiivisuus (perustaso) ---------- */
@media (max-width: 1279px) {
  .sidebar { width: var(--sidebar-w-min); }
  .sidebar .side-label, .sidebar .side-group-title, .sidebar .side-user-info, .sidebar .brand-text, .sidebar .side-pill, .sidebar .side-count { display: none; }
  /* Kapea ikonipalkki: ryhmäotsikon tilalla ohut erotin, ei sisennystä; title-vihje kertoo "Ryhmä › Sivu". */
  .sidebar .side-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
  .sidebar .side-sublist { margin-left: 0; padding-left: 0; border-left: 0; }
  .sidebar .side-sublist .side-item { height: 40px; padding: 0 10px; }
  .sidebar .side-sublist .side-item.active::before { left: -12px; }
  .sidebar .side-list-erotin { margin-top: 6px; padding-top: 6px; border-top-color: rgba(255, 255, 255, 0.08); }
  .view-pad { padding: var(--sp-5) var(--sp-6) var(--sp-12); }
}
@media (max-width: 1023px) {
  .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9 { grid-column: span 12; }
}
