/**
 * V2 Base Styles
 * Reset, typography, and global element styles
 */

/* ======================================
   Utilities
   ====================================== */
.position-relative {
    position: relative !important;
}

.w-100 {
    width: 100% !important;
}

.h-100 {
    height: 100% !important;
}

/* ======================================
   CSS Reset
   ====================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* Base font size for desktop */
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Mobile-only font scaling */
@media (max-width: 1024px) {
    html {
        font-size: var(--root-font-size, 16px);
    }
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    background-color: var(--bg-body);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ======================================
   Typography & Text Management
   ====================================== */
.text-truncate,
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    display: inline-block;
}

/* Global overflow protection for common UI elements on mobile */
@media (max-width: 1024px) {

    /* Ensure flex containers allow children to truncate */
    .nav-link,
    .dropdown-item,
    .navbar-brand,
    .card-header,
    .btn {
        min-width: 0;
    }

    /* Target text containers specifically */
    .nav-link span,
    .dropdown-item span,
    .card-title,
    .brand-text,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        max-width: 100%;
    }

    /* Required for consistency */
    .card-title,
    .brand-text {
        max-width: 100%;
    }
}

/* Special case for flex children */
.nav-link span,
.dropdown-item span {
    display: inline-block;
    vertical-align: middle;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

h1 {
    font-size: var(--font-size-3xl);
}

h2 {
    font-size: var(--font-size-2xl);
}

h3 {
    font-size: var(--font-size-xl);
}

h4 {
    font-size: var(--font-size-lg);
}

h5 {
    font-size: var(--font-size-md);
}

h6 {
    font-size: var(--font-size-base);
}

p {
    margin-bottom: var(--spacing-md);
}

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

a:hover {
    color: var(--color-primary-dark);
}

strong,
b {
    font-weight: var(--font-weight-semibold);
}

small {
    font-size: var(--font-size-sm);
}

code,
pre {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
}

code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

pre {
    background: var(--bg-secondary);
    padding: var(--spacing-md);
    border-radius: var(--radius);
    overflow-x: auto;
}

/* ======================================
   Lists
   ====================================== */
ul,
ol {
    padding-left: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
}

li {
    margin-bottom: var(--spacing-xs);
}

/* ======================================
   Images & Media
   ====================================== */
img,
video {
    max-width: 100%;
    height: auto;
}

/* ======================================
   Tables (Base)
   ====================================== */
table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: var(--font-weight-semibold);
    background: var(--table-header-bg);
}

/* ======================================
   Forms (Base)
   ====================================== */
input,
textarea,
select,
button {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

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

fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

label {
    display: block;
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--spacing-xs);
}

/* ======================================
   Utility Classes
   ====================================== */
.hidden {
    display: none !important;
}

/* Mobile/Desktop Visibility Utilities */
.mobile-only {
    display: none !important;
}

@media (max-width: 1024px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }
}

.invisible {
    visibility: hidden;
}

.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;
}

/* Text utilities */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

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

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

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

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

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

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

/* Font weights */
.font-normal {
    font-weight: var(--font-weight-normal);
}

.font-medium {
    font-weight: var(--font-weight-medium);
}

.font-semibold {
    font-weight: var(--font-weight-semibold);
}

.font-bold {
    font-weight: var(--font-weight-bold);
}

/* Text utilities */
.text-nowrap {
    white-space: nowrap !important;
}

.text-wrap {
    white-space: normal !important;
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Spacing utilities */
.m-0 {
    margin: 0;
}

.p-0 {
    padding: 0;
}

.mt-1 {
    margin-top: var(--spacing-xs);
}

.mt-2 {
    margin-top: var(--spacing-sm);
}

.mt-3 {
    margin-top: var(--spacing-md);
}

.mt-4 {
    margin-top: var(--spacing-lg);
}

.mb-1 {
    margin-bottom: var(--spacing-xs);
}

.mb-2 {
    margin-bottom: var(--spacing-sm);
}

.mb-3 {
    margin-bottom: var(--spacing-md);
}

.mb-4 {
    margin-bottom: var(--spacing-lg);
}

/* Flex utilities */
.flex {
    display: flex;
}

.flex-wrap {
    flex-wrap: wrap;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-end {
    justify-content: flex-end;
}

.gap-1 {
    gap: var(--spacing-xs);
}

.gap-2 {
    gap: var(--spacing-sm);
}

.gap-3 {
    gap: var(--spacing-md);
}

.gap-4 {
    gap: var(--spacing-lg);
}

/* Grid utilities */
.grid {
    display: grid;
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* ======================================
   Loading State
   ====================================== */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 2px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ======================================
   Scrollbar Styling
   ====================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

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

/* ======================================
   Selection
   ====================================== */
::selection {
    background: var(--color-primary);
    color: var(--text-white);
}

/* ======================================
   Focus Ring
   ====================================== */
:focus {
    outline: none;
}

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

/* ======================================
   Print Styles
   ====================================== */
@media print {
    body {
        background: white;
    }

    .no-print {
        display: none !important;
    }
}