/* ==========================================================================
   PayVoice Base Styles, Scoped Reset, Typography & Accessibility Primitives
   ========================================================================== */

@layer reset, tokens, base, layout, components, pages, utilities;

@layer reset {
  html,
  body,
  div,
  span,
  main,
  aside,
  header,
  nav,
  section,
  article,
  footer,
  dialog,
  form,
  fieldset,
  label,
  input,
  select,
  textarea,
  button,
  table,
  thead,
  tbody,
  tfoot,
  tr,
  th,
  td,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  p,
  ul,
  ol,
  li,
  dl,
  dt,
  dd,
  pre,
  code,
  figure,
  blockquote,
  a {
    box-sizing: border-box;
  }

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

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

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

@layer base {
  html {
    font-size: 100%;
    accent-color: var(--color-brand-btn-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-strong) transparent;
  }

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

  body {
    margin: 0;
    min-block-size: 100dvh;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.55;
    color: var(--color-text-primary);
    background-color: var(--color-bg-canvas);
    overflow-x: clip;
  }

  h1,
  h2,
  h3,
  h4 {
    color: var(--color-text-primary);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.22;
    text-wrap: balance;
  }

  h1 {
    font-size: var(--text-2xl);
    font-weight: 800;
  }

  h2 {
    font-size: var(--text-lg);
  }

  h3 {
    font-size: var(--text-md);
    font-weight: 600;
  }

  p {
    text-wrap: pretty;
  }

  a {
    color: var(--color-brand-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
  }

  a:hover {
    color: var(--color-brand-hover);
  }

  button,
  input,
  select,
  textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
  }

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

  button:disabled,
  [aria-disabled="true"] {
    cursor: not-allowed;
  }

  input,
  select,
  textarea {
    background-color: var(--color-bg-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.5625rem 0.75rem;
    font-size: var(--text-sm);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast),
      background-color var(--transition-fast);
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--color-text-muted);
  }

  input:hover:not(:disabled),
  select:hover:not(:disabled),
  textarea:hover:not(:disabled) {
    border-color: var(--color-border-strong);
  }

  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: none;
    border-color: var(--color-brand-primary);
    box-shadow: var(--shadow-glow-brand);
  }

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

  code,
  pre,
  .mono {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
  }

  /* Institutional Fintech Table Styling */
  table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--text-sm);
  }

  th {
    position: sticky;
    inset-block-start: 0;
    z-index: 1;
    text-align: start;
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.055em;
    padding: 0.75rem 1rem;
    background-color: var(--color-bg-subtle);
    border-block-end: 1px solid var(--color-border);
    white-space: nowrap;
    text-wrap: balance;
  }

  td {
    padding: 0.875rem 1rem;
    border-block-end: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
    vertical-align: middle;
  }

  tbody tr {
    transition: background-color var(--transition-fast);
  }

  tbody tr:hover {
    background-color: var(--color-bg-surface-hover);
  }

  tbody tr:last-child td {
    border-block-end: none;
  }

  /* Legacy WebKit Scrollbar Fallback for older engines */
  @supports not (scrollbar-color: auto) {
    ::-webkit-scrollbar {
      inline-size: 8px;
      block-size: 8px;
    }

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

    ::-webkit-scrollbar-thumb {
      background: var(--color-border-strong);
      border-radius: var(--radius-full);
    }

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

  @media (prefers-reduced-motion: reduce) {
    html,
    body,
    dialog,
    dialog::backdrop,
    button,
    a,
    input,
    select,
    textarea,
    tr {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer utilities {
  .tabular-nums {
    font-variant-numeric: tabular-nums;
  }

  .text-muted {
    color: var(--color-text-muted);
  }

  .text-secondary {
    color: var(--color-text-secondary);
  }

  .text-success {
    color: var(--color-success);
  }

  .text-danger {
    color: var(--color-danger);
  }

  .text-warning {
    color: var(--color-warning);
  }

  .visually-hidden,
  .sr-only {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .skip-link:focus-visible {
    position: fixed;
    inset-block-start: var(--space-3);
    inset-inline-start: var(--space-3);
    z-index: 100;
    inline-size: auto;
    block-size: auto;
    margin: 0;
    clip-path: none;
    padding: 0.625rem 1rem;
    border-radius: var(--radius-md);
    background-color: var(--color-brand-btn-bg);
    color: var(--color-text-inverse);
    font-weight: 600;
    font-size: var(--text-sm);
    box-shadow: var(--shadow-lg);
  }

  .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-inline-size: 0;
  }
}
