/* ==========================================================================
   FinApp v2 — Reset & Base Styles
   ========================================================================== */

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

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
  }

  body,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  figure,
  blockquote,
  dl,
  dd {
    margin: 0;
  }

  ul,
  ol {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  img,
  svg,
  video,
  canvas {
    display: block;
    max-width: 100%;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
  }

  button {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

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

@layer base {
  html,
  body {
    min-height: 100%;
    max-width: 100%;
    overflow-x: clip;
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: var(--leading-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    caret-color: var(--brand-primary);
  }

  /* Browser Surfaces: Selection, Links, Focus, Scrollbars */
  ::selection {
    background-color: var(--color-sage);
    color: var(--text-on-brand);
  }

  a:not([class]) {
    color: var(--brand-primary);
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 0.2em;
    transition: text-decoration-color var(--dur-fast) var(--ease-out);
  }

  a:not([class]):hover {
    text-decoration-color: var(--brand-primary);
  }

  :focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
  }

  :focus:not(:focus-visible) {
    outline: none;
  }

  /* Custom subtle warm scrollbars */
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--border-default) transparent;
  }

  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background-color: var(--border-default);
    border-radius: var(--radius-pill);
    border: 2px solid transparent;
    background-clip: content-box;
  }

  ::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-sage);
  }

  /* Editorial & UI Typography */
  h1,
  .heading-display {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: var(--leading-tight);
    color: var(--text-primary);
    text-wrap: balance;
  }

  h2,
  h3,
  h4 {
    font-family: var(--font-sans);
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: var(--leading-snug);
    color: var(--text-primary);
    text-wrap: balance;
  }

  /* Mandatory Tabular Numerals */
  .num,
  .tabular-nums,
  input[type="number"],
  td.num,
  th.num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
  }

  /* Skip Link for Keyboard Accessibility */
  .skip-link {
    position: fixed;
    top: -100px;
    left: var(--space-4);
    z-index: calc(var(--z-tooltip) + 10);
    padding: 0.625rem 1rem;
    background: var(--brand-primary);
    color: var(--text-on-brand);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transition: top var(--dur-fast) var(--ease-out);
  }

  .skip-link:focus {
    top: var(--space-4);
  }

  /* Screen-Reader Only Utility */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* Reduced Motion Preference */
  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
      animation-duration: 0.01ms;
      animation-iteration-count: 1;
      transition-duration: 0.01ms;
    }
  }
}

@layer utilities {
  .text-primary { color: var(--text-primary); }
  .text-secondary { color: var(--text-secondary); }
  .text-muted { color: var(--text-muted); }
  .text-positive { color: var(--positive-text); }
  .text-negative { color: var(--negative-text); }
  .text-warning { color: var(--warning-text); }
  .text-info { color: var(--info-text); }
  .text-right { text-align: right; }
  .text-center { text-align: center; }
  .font-medium { font-weight: 500; }
  .font-semibold { font-weight: 600; }
  .font-bold { font-weight: 700; }
  .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .flex { display: flex; }
  .flex-col { display: flex; flex-direction: column; }
  .items-center { align-items: center; }
  .justify-between { justify-content: space-between; }
  .gap-2 { gap: var(--space-2); }
  .gap-3 { gap: var(--space-3); }
  .gap-4 { gap: var(--space-4); }
  .w-full { width: 100%; }
  .mt-2 { margin-top: var(--space-2); }
  .mt-4 { margin-top: var(--space-4); }
  .mt-6 { margin-top: var(--space-6); }
  .mb-4 { margin-bottom: var(--space-4); }

  /* Responsive visibility & hidden MUST sit last in @layer utilities so they always win over display:flex/grid */
  @media (max-width: 768px) {
    .desktop-only {
      display: none;
    }
  }

  @media (min-width: 769px) {
    .mobile-only {
      display: none;
    }
  }

  .hidden,
  [hidden] {
    display: none;
  }
}
