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

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font-sans);
    color: var(--foreground);
    background: var(--background);
    line-height: var(--lh-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, p { margin: 0; }
h1 { font-size: var(--fs-3xl); line-height: var(--lh-tight); }
h2 { font-size: var(--fs-2xl); line-height: var(--lh-tight); }
h3 { font-size: var(--fs-xl);  line-height: var(--lh-tight); }
p  { font-size: var(--fs-base); }

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

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

/* --- 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;
}
.hidden,
[hidden] { display: none !important; }
.stack   { display: flex; flex-direction: column; gap: var(--space-4); }
.row     { display: flex; align-items: center; gap: var(--space-3); }
.spacer  { flex: 1; }

/* --- Button --- */
.btn {
    --btn-bg: var(--primary);
    --btn-fg: var(--primary-foreground);
    --btn-border: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--btn-border);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font-weight: 600;
    font-size: var(--fs-base);
    line-height: 1;
    cursor: pointer;
    transition: filter var(--dur) var(--ease), transform 60ms var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover  { filter: brightness(1.04); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }

.btn-primary   { --btn-bg: var(--primary);    --btn-fg: var(--primary-foreground); }
.btn-secondary { --btn-bg: var(--secondary);  --btn-fg: var(--secondary-foreground); }
.btn-accent    { --btn-bg: var(--accent);     --btn-fg: var(--accent-foreground); }
.btn-ghost     { --btn-bg: transparent;       --btn-fg: var(--foreground); }
.btn-outline   { --btn-bg: transparent;       --btn-fg: var(--foreground); --btn-border: var(--border); }
.btn-destructive { --btn-bg: var(--destructive); --btn-fg: var(--destructive-foreground); }

.btn-lg { padding: 14px 22px; font-size: var(--fs-lg); border-radius: var(--radius-md); }
.btn-sm { padding: 6px 10px;  font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-block { width: 100%; }

/* --- Input / Select / Textarea --- */
.field { display: flex; flex-direction: column; gap: var(--space-2); text-align: left; }
.field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--foreground); }
.field-hint  { font-size: var(--fs-xs); color: var(--muted-foreground); }
.field-error { font-size: var(--fs-xs); color: var(--destructive); }

.input, .select, .textarea {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--input);
    color: var(--foreground);
    padding: 10px 12px;
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
    font-size: var(--fs-base);
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 25%, transparent);
}
.textarea { min-height: 96px; resize: vertical; }

/* --- Checkbox --- */
.check {
    display: flex; align-items: flex-start; gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
}
.check input[type=checkbox] {
    accent-color: var(--primary);
    transform: translateY(2px);
    width: 16px; height: 16px;
}

/* --- Card --- */
.card {
    background: var(--card);
    color: var(--card-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.card-title  { font-size: var(--fs-lg); font-weight: 700; }
.card-desc   { font-size: var(--fs-sm); color: var(--muted-foreground); margin-top: var(--space-1); }

/* --- Badge --- */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: var(--secondary);
    color: var(--secondary-foreground);
    font-size: var(--fs-xs);
    font-weight: 600;
    border: 1px solid var(--border);
}

/* --- Spinner --- */
.spinner {
    width: 44px; height: 44px;
    border: 4px solid rgba(255,255,255,.25);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 900ms linear infinite;
}
.spinner-sm { width: 18px; height: 18px; border-width: 3px; }

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

/* --- Loading overlay --- */
.loading-overlay {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: var(--wow-blue-900);
    color: #fff;
    z-index: 9999;
    padding: var(--space-6);
    text-align: center;
}
.loading-overlay h2 { margin-top: var(--space-5); font-size: var(--fs-xl); font-weight: 600; }

/* --- Toast --- */
.toast-host {
    position: fixed; bottom: var(--space-6); right: var(--space-6);
    display: flex; flex-direction: column; gap: var(--space-2);
    z-index: 9999; pointer-events: none;
}
.toast {
    background: var(--neutral-900); color: #fff;
    border: 1px solid var(--neutral-700);
    padding: 10px 14px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: var(--fs-sm);
    min-width: 240px;
    pointer-events: auto;
    animation: toast-in 220ms var(--ease);
}
.toast.error   { background: var(--destructive); border-color: transparent; }
.toast.success { background: #16a34a; border-color: transparent; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Dropdown (langue selector) --- */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    background: var(--popover);
    color: var(--popover-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-1);
    min-width: 220px;
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
    display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: var(--space-3);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: inherit;
    font-weight: 500;
    width: 100%;
    flex-direction: row;
}
.dropdown-item:hover, .dropdown-item[aria-selected="true"] { background: var(--secondary); }
.dropdown-search { padding: var(--space-2); position: sticky; top: 0; background: var(--popover); border-bottom: 1px solid var(--border); }
.dropdown-search input {
    width: 100%; padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    background: var(--card);
}
.dropdown-search input:focus { border-color: var(--ring); }

/* --- Dialog (native <dialog>) --- */
.dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 480px;
    width: 90vw;
    max-height: min(640px, calc(100vh - 2 * var(--space-8)));
    background: var(--card);
    color: var(--card-foreground);
    box-shadow: var(--shadow-lg);
}
.dialog::backdrop {
    background: rgba(0, 0, 0, .35);
    backdrop-filter: blur(2px);
}
.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-5) var(--space-3);
    border-bottom: 1px solid var(--border);
}
.dialog-header h3 { font-size: var(--fs-lg); font-weight: 800; color: var(--wow-red-500); }
.dialog-close {
    flex-shrink: 0;
    width: 32px; height: 32px;
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    background: var(--secondary);
    color: var(--foreground);
    font-size: var(--fs-base);
    line-height: 1;
}
.dialog-close:hover { filter: brightness(.95); }
.dialog-body {
    padding: var(--space-5);
    overflow-y: auto;
    font-size: var(--fs-sm);
    line-height: var(--lh-normal);
    white-space: pre-line;
}
.dialog-footer { padding: var(--space-4) var(--space-5) var(--space-5); }

/* RTL support */
[dir="rtl"] { text-align: right; }