/* =============================================================================
 * shared/base.css — reset, document defaults, utilities and primitives.
 *
 * PURPOSE   Everything that is not a composite component: the box-model reset,
 *           body typography, low-level utility classes and the single-element
 *           primitives every page composes with.
 * PROVIDES  reset + body · utilities (.container .truncate .tnum .scroll-thin
 *           .reveal + stagger) · primitives (.eyebrow .section-label .icon-badge
 *           .avatar .btn .icon-btn .input .tag .swatch .dot .kv .bar .stat-num
 *           .add-tile, colour helpers .c-*).
 * REQUIRES  tokens.css (all values are var(--…)). Load AFTER tokens.css.
 * USED BY   every page.
 * ============================================================================= */

/* ── Reset & document defaults ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-base);
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv01";
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.container { width: 100%; max-width: var(--content-max); margin-inline: auto; padding-inline: var(--pad-x); }
.tnum { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Thin, unobtrusive scrollbar for any scroll container */
.scroll-thin { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.scroll-thin::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }
.scroll-thin::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: var(--r-pill); border: 2px solid transparent; background-clip: content-box; }
.scroll-thin::-webkit-scrollbar-thumb:hover { background: #c8c8c8; background-clip: content-box; }

/* Entrance: fade-in up + blur. `.reveal` alone fires immediately; pages add
   .d1…d12 (or nth-child rules in their own styles.css) to stagger top→bottom. */
/* Ends on `filter: none` (not blur(0)) so finished elements don't keep a
   stacking context — which would otherwise trap popovers above them. */
@keyframes enter { from { opacity: 0; transform: translateY(10px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
.reveal { opacity: 0; animation: enter .5s var(--ease) forwards; }
.reveal.d1{animation-delay:.05s}.reveal.d2{animation-delay:.10s}.reveal.d3{animation-delay:.15s}
.reveal.d4{animation-delay:.20s}.reveal.d5{animation-delay:.25s}.reveal.d6{animation-delay:.30s}
.reveal.d7{animation-delay:.35s}.reveal.d8{animation-delay:.40s}.reveal.d9{animation-delay:.45s}
.reveal.d10{animation-delay:.50s}.reveal.d11{animation-delay:.55s}.reveal.d12{animation-delay:.60s}

/* ── Primitives ───────────────────────────────────────────────────────────── */
.eyebrow { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .025em; text-transform: uppercase; color: var(--muted); }
.section-label { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .025em; text-transform: uppercase; color: var(--faint); margin-bottom: .625rem; }

.icon-badge { display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: var(--r-lg); background: var(--ink); color: #fff; }
.icon-badge--sm { border-radius: var(--r-sm); }
.icon-badge--muted { background: var(--surface-2); color: var(--faint); }

.avatar { display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; border-radius: var(--r-pill); background: #e5e5e5; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; flex: none; }
.avatar--icon .ti { font-size: 15px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; height: 2rem; padding-inline: .75rem; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--ink); font-family: inherit; font-size: var(--fs-base); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background var(--t-fast) ease-out, border-color var(--t-fast) ease-out, color var(--t-fast) ease-out; }
.btn:hover { background: var(--surface-1); border-color: var(--border-strong); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn--danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn--danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn--muted { color: var(--muted); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn .ti { font-size: 15px; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); cursor: pointer; transition: background var(--t-fast) ease-out, color var(--t-fast) ease-out; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn .ti { font-size: 16px; }

.input { width: 100%; height: 2.25rem; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); padding: 0 .7rem; font-family: inherit; font-size: var(--fs-base); color: var(--ink); transition: border-color var(--t-fast) ease-out, box-shadow var(--t-fast) ease-out; }
.input::placeholder { color: var(--faint); }
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* Native select, styled (chevron supplied by a sibling .ti inside .select-wrap) */
.select-wrap { position: relative; display: flex; }
.select { appearance: none; -webkit-appearance: none; width: 100%; height: 2.25rem; padding: 0 2rem 0 .7rem; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); font-family: inherit; font-size: var(--fs-base); color: var(--ink); cursor: pointer; transition: border-color var(--t-fast) ease-out, box-shadow var(--t-fast) ease-out; }
.select:hover { border-color: var(--border-strong); }
.select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.select-wrap > .ti { position: absolute; right: .55rem; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--faint); font-size: 15px; }

/* Folder / category badge — white pill, light border, leading muted icon */
.tag { display: inline-flex; align-items: center; gap: .3rem; flex: none; max-width: 40vw; font-size: var(--fs-xs); font-weight: 500; color: var(--tag-ink, var(--ink-2)); background: var(--tag-bg, var(--surface)); border: 1px solid var(--tag-border, var(--border)); border-radius: var(--r-pill); padding: 2px 9px 2px 7px; }
.tag .ti { font-size: 12px; color: var(--tag-ink, var(--faint)); flex: none; }
.tag span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Categorical identity marks */
.swatch { display: inline-block; width: .625rem; height: .625rem; border-radius: var(--r-pill); flex: none; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent); }
.dot { display: inline-block; width: .5rem; height: .5rem; border-radius: var(--r-pill); flex: none; }

/* Key/value list (document properties, login meta) */
.kv { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; align-items: center; }
.kv dt { font-size: var(--fs-sm); color: var(--muted); }
.kv dd { margin: 0; font-size: var(--fs-base); color: var(--ink); justify-self: end; text-align: right; font-variant-numeric: tabular-nums; }

/* Stats: big count + share bar */
.stat-num { font-size: 1.75rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.bar { height: 4px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: var(--r-pill); background: var(--ink); }

/* "Add new" dashed affordance */
.add-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; min-height: 100%; padding: 1.5rem; border: 1px dashed var(--border-strong); border-radius: var(--r-lg); color: var(--muted); background: transparent; cursor: pointer; transition: border-color var(--t-fast) ease-out, color var(--t-fast) ease-out, background var(--t-fast) ease-out; }
.add-tile:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Colour helpers — set currentColor to a categorical palette value */
.c-work{color:var(--c-work)}.c-personal{color:var(--c-personal)}.c-recipes{color:var(--c-recipes)}
.c-research{color:var(--c-research)}.c-travel{color:var(--c-travel)}.c-ideas{color:var(--c-ideas)}
.c-drafts{color:var(--c-drafts)}.c-system{color:var(--c-system)}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; opacity: 1; }
  *, *::before, *::after { transition: none !important; }
}
