/* ============================================================================
   base.css — reset, typography, element defaults
   Depends on tokens.css. Load order: tokens -> base -> components -> layout
   ========================================================================== */

/* ---------- 1. RESET ------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -moz-tab-size: 2;
  tab-size: 2;
}

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd, ol, ul, pre, fieldset, legend {
  margin: 0;
  padding: 0;
}

ol, ul { list-style: none; }

img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
  max-width: 100%;
}
img, video { height: auto; }

button, input, select, textarea, optgroup {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  margin: 0;
}
button { background: none; border: 0; }
textarea { resize: vertical; }

table { border-collapse: collapse; border-spacing: 0; }

fieldset { border: 0; min-width: 0; }

hr {
  border: 0;
  border-top: 1px solid var(--divider);
  height: 0;
  margin: var(--space-6) 0;
}

[hidden] { display: none !important; }

/* ---------- 2. DOCUMENT --------------------------------------------------- */

html, body { height: 100%; }

body {
  background-color: var(--surface);
  background-image: var(--texture-grid);
  background-size: var(--texture-size);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-tight);
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;

  /* Never allow the page itself to scroll sideways. */
  overflow-x: hidden;
  max-width: 100%;
}

::selection {
  background: var(--brand-soft-hover);
  color: var(--text-primary);
}

/* ---------- 3. TYPOGRAPHY ------------------------------------------------- */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  font-optical-sizing: auto;
  text-wrap: balance;
}
h5, h6 {
  font-family: var(--font-ui);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--text-primary);
}

h1 { font-size: var(--text-3xl); letter-spacing: var(--tracking-tighter); }
h2 { font-size: var(--text-2xl); letter-spacing: var(--tracking-tighter); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--text-muted);
  font-weight: var(--weight-semibold);
}

p { max-width: 72ch; text-wrap: pretty; }
p + p { margin-top: var(--space-3); }

small { font-size: var(--text-xs); color: var(--text-muted); }

strong, b { font-weight: var(--weight-semibold); color: var(--text-primary); }
em, i { font-style: italic; }

a {
  color: var(--text-link);
  text-decoration: none;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
  transition: color var(--dur-1) var(--ease-out);
}
a:hover { color: var(--text-link-hover); text-decoration: underline; }

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-feature-settings: "zero" 1;
}
code {
  background: var(--surface-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 0.1em 0.36em;
  color: var(--text-secondary);
}
pre {
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  line-height: var(--leading-normal);
}
pre code { background: none; border: 0; padding: 0; }

kbd {
  font-size: var(--text-2xs);
  font-family: var(--font-mono);
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  padding: 0.14em 0.42em;
  color: var(--text-secondary);
  white-space: nowrap;
}

blockquote {
  border-left: 2px solid var(--accent);
  padding-left: var(--space-4);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-style: italic;
}

abbr[title] { text-decoration: underline dotted; cursor: help; }

/* Numerals — all data-bearing figures line up in columns. */
.num,
td.num, th.num,
time, output, meter, progress {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.94em;
  letter-spacing: var(--tracking-normal);
}

/* ---------- 4. TYPE UTILITIES -------------------------------------------- */

.display {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tighter);
  line-height: var(--leading-tight);
}
.eyebrow {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--text-muted);
}
.lede {
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
}

.t-2xs  { font-size: var(--text-2xs); }
.t-xs   { font-size: var(--text-xs); }
.t-sm   { font-size: var(--text-sm); }
.t-base { font-size: var(--text-base); }
.t-md   { font-size: var(--text-md); }
.t-lg   { font-size: var(--text-lg); }
.t-xl   { font-size: var(--text-xl); }
.t-2xl  { font-size: var(--text-2xl); }
.t-3xl  { font-size: var(--text-3xl); }

.fg-primary   { color: var(--text-primary); }
.fg-secondary { color: var(--text-secondary); }
.fg-muted     { color: var(--text-muted); }
.fg-brand     { color: var(--brand); }
.fg-accent    { color: var(--accent-ink); }
.fg-success   { color: var(--success-ink); }
.fg-warning   { color: var(--warning-ink); }
.fg-danger    { color: var(--danger-ink); }
.fg-info      { color: var(--info-ink); }

.w-regular  { font-weight: var(--weight-regular); }
.w-medium   { font-weight: var(--weight-medium); }
.w-semibold { font-weight: var(--weight-semibold); }
.w-bold     { font-weight: var(--weight-bold); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* A gold hairline that sits under a section title — the signature detail. */
.rule-accent {
  height: 2px;
  width: 44px;
  border-radius: var(--radius-full);
  background: var(--accent-rule);
  margin-top: var(--space-2);
}

/* ---------- 5. FOCUS ------------------------------------------------------ */

:focus { outline: none; }

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

a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
[role="menuitem"]:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 0;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

/* Forced-colors: keep the ring visible when the OS repaints everything. */
@media (forced-colors: active) {
  :focus-visible { outline: 2px solid Highlight; }
}

/* ---------- 6. FORM ELEMENT DEFAULTS -------------------------------------- */

button, [role="button"], summary, label[for], select {
  cursor: pointer;
}
button:disabled, [aria-disabled="true"] {
  cursor: not-allowed;
}

::placeholder { color: var(--text-muted); opacity: 1; }

input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Autofill should not paint Chrome's yellow over the paper ground. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-primary);
  -webkit-box-shadow: 0 0 0 1000px var(--surface-elevated) inset;
  caret-color: var(--text-primary);
  transition: background-color 100000s ease 0s;
}

/* ---------- 7. ACCESSIBILITY HELPERS -------------------------------------- */

.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-tooltip);
  padding: var(--space-3) var(--space-4);
  background: var(--brand);
  color: var(--on-brand);
  border-radius: var(--radius-sm);
  font-weight: var(--weight-semibold);
  box-shadow: var(--shadow-lg);
  transform: translateY(calc(-100% - var(--space-4)));
  transition: transform var(--dur-2) var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(0); text-decoration: none; }

/* ---------- 8. ICONS ------------------------------------------------------ */
/* Every icon is <svg class="ic"><use href="#ic-name"></use></svg> from the
   inline sprite. Icons inherit currentColor and never carry meaning alone. */

.ic {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
  pointer-events: none;
}
.ic-sm { width: 1em;    height: 1em;    stroke-width: 1.7; }
.ic-lg { width: 1.4em;  height: 1.4em;  stroke-width: 1.5; }
.ic-xl { width: 2rem;   height: 2rem;   stroke-width: 1.3; }
.ic-solid { fill: currentColor; stroke: none; }

/* ---------- 9. SCROLLBARS ------------------------------------------------- */

* {
  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: var(--radius-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- 10. MOTION ---------------------------------------------------- */

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

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* Shared keyframes used across components */
@keyframes fade-in      { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in      { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rise-in-lg   { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes slide-in-right { from { transform: translateX(100%); } to { transform: none; } }
@keyframes scale-in     { from { opacity: 0; transform: translateY(6px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes spin         { to { transform: rotate(360deg); } }
@keyframes shimmer      { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pulse-ring   {
  0%   { box-shadow: 0 0 0 0 currentColor; opacity: 0.55; }
  70%  { box-shadow: 0 0 0 7px currentColor; opacity: 0; }
  100% { box-shadow: 0 0 0 0 currentColor; opacity: 0; }
}
@keyframes grow-x       { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- 11. PRINT ----------------------------------------------------- */

@media print {
  body { background: #fff; color: #000; }
  .app-sidebar, .app-topbar, .app-bottomnav, .toast-region, .no-print { display: none !important; }
  .app-main { padding: 0 !important; }
  .card, .panel { box-shadow: none !important; border: 1px solid #ccc !important; }
}
