/**
 * Modern CSS Reset & Base Styles
 * Optimized for PWA with native app feel
 */

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

/* Remove default margin/padding, eliminate 300ms tap delay */
* {
    margin: 0;
    padding: 0;
    touch-action: manipulation;
}

/* Prevent font size inflation */
html {
    -moz-text-size-adjust: none;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Core body defaults */
body {
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--surface-secondary);

    /* Prevent pull-to-refresh in standalone PWA */
    overscroll-behavior-y: contain;

    /* Smooth scrolling */
    scroll-behavior: smooth;

    /* Prevent text selection highlight on tap (mobile) */
    -webkit-tap-highlight-color: transparent;
}

/* Improve media defaults */
img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}

/* Remove default button styles */
button {
    background: none;
    border: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

/* Remove default input styles */
input,
textarea {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}

/* Remove list styles */
ul,
ol {
    list-style: none;
}

/* Avoid text overflows */
p,
h1,
h2,
h3,
h4,
h5,
h6 {
    overflow-wrap: break-word;
}

/* Improve heading defaults */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-display);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
    color: var(--text-primary);
    text-wrap: balance;
}

/* Link defaults */
a {
    color: inherit;
    text-decoration: none;
    text-decoration-skip-ink: auto;
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* Remove focus outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* Table improvements */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* Address styling */
address {
    font-style: normal;
}

/* Selection styling */
::selection {
    background-color: var(--color-primary-200);
    color: var(--color-primary-900);
}

/* Placeholder styling */
::placeholder {
    color: var(--text-tertiary);
    opacity: 1;
}

/* Scrollbar styling - overlay style that doesn't affect layout */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-neutral-400) transparent;
}

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

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

::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.35);
}

/* Make scrollbar overlay content instead of taking layout space */
@supports (overflow: overlay) {
    html {
        overflow: overlay;
    }
}

/* For browsers that don't support overlay, use auto with gutter */
@supports not (overflow: overlay) {
    html {
        overflow-y: auto;
        scrollbar-gutter: stable;
    }
}

/* Hide scrollbar but keep functionality (for horizontal scrollers) */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* 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;
}

/* Safe area padding utilities for PWA */
.safe-top {
    padding-top: var(--safe-area-inset-top);
}

.safe-bottom {
    padding-bottom: var(--safe-area-inset-bottom);
}

.safe-left {
    padding-left: var(--safe-area-inset-left);
}

.safe-right {
    padding-right: var(--safe-area-inset-right);
}

.safe-x {
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

.safe-y {
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
}
