/* ── Layer 0: New Primitives CSS (v0.37.2) ───────────
   Preact component styles. Uses variables.css tokens.
   Prefixed sw- to avoid clash with old primitives.css.
   ──────────────────────────────────────────────────── */

/* ── Button ────────────────────────────────── */

.sw-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5em; border: 1px solid transparent; border-radius: var(--radius);
    font-family: var(--font); font-weight: 500; cursor: pointer;
    transition: background var(--transition), border-color var(--transition), opacity var(--transition);
    white-space: nowrap; position: relative;
}
.sw-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sw-btn--sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.sw-btn--md { padding: 0.45rem 0.9rem; font-size: 0.875rem; }
.sw-btn--lg { padding: 0.6rem 1.2rem; font-size: 1rem; }

.sw-btn--primary { background: var(--accent); color: var(--text-on-color); }
.sw-btn--primary:hover:not(:disabled) { background: var(--accent-hover); }
.sw-btn--secondary { background: var(--bg-raised); color: var(--text); border-color: var(--border); }
.sw-btn--secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-light); }
.sw-btn--danger { background: var(--danger); color: var(--text-on-color); }
.sw-btn--danger:hover:not(:disabled) { opacity: 0.9; }
.sw-btn--ghost { background: transparent; color: var(--text-2); }
.sw-btn--ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }

.sw-btn--loading .sw-btn__content--hidden { visibility: hidden; }
.sw-btn__spinner {
    position: absolute; width: 1em; height: 1em;
    border: 2px solid transparent; border-top-color: currentColor;
    border-radius: 50%; animation: sw-spin 0.6s linear infinite;
}

/* ── Spinner ───────────────────────────────── */

.sw-spinner {
    display: inline-block; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: sw-spin 0.6s linear infinite;
}
.sw-spinner--sm { width: 16px; height: 16px; }
.sw-spinner--md { width: 24px; height: 24px; }
.sw-spinner--lg { width: 40px; height: 40px; }

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

/* ── Avatar ────────────────────────────────── */

.sw-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%; object-fit: cover; flex-shrink: 0;
    font-weight: 600; color: var(--text-on-color); background: var(--accent);
}
.sw-avatar--sm { width: 24px; height: 24px; font-size: 0.65rem; }
.sw-avatar--md { width: 32px; height: 32px; font-size: 0.75rem; }
.sw-avatar--lg { width: 48px; height: 48px; font-size: 1rem; }
.sw-avatar--fallback { user-select: none; }

/* ── FormField ─────────────────────────────── */

.sw-field { display: flex; flex-direction: column; gap: 0.3rem; }
.sw-field__label { font-size: 0.8rem; font-weight: 500; color: var(--text-2); }
.sw-field__required { color: var(--danger); margin-left: 2px; }
.sw-field__error { font-size: 0.75rem; color: var(--danger); }
.sw-field__hint { font-size: 0.75rem; color: var(--text-3); }
.sw-field--error .sw-input { border-color: var(--danger); }

/* ── Shared input ──────────────────────────── */

.sw-input {
    width: 100%; padding: 0.45rem 0.7rem; background: var(--input-bg);
    color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
    font-family: var(--font); font-size: 0.875rem; outline: none;
    transition: border-color var(--transition);
}
.sw-input:focus { border-color: var(--accent); }
.sw-input::placeholder { color: var(--text-3); }

/* ── Tooltip ───────────────────────────────── */

.sw-tooltip-wrap { position: relative; display: inline-flex; }
.sw-tooltip {
    position: absolute; z-index: 1000; padding: 0.3rem 0.6rem;
    background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 0.75rem; white-space: nowrap;
    pointer-events: none; animation: sw-fade-in 0.15s ease;
}
.sw-tooltip--top { bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); }
.sw-tooltip--bottom { top: calc(100% + 6px); left: 50%; transform: translateX(-50%); }
.sw-tooltip--left { right: calc(100% + 6px); top: 50%; transform: translateY(-50%); }
.sw-tooltip--right { left: calc(100% + 6px); top: 50%; transform: translateY(-50%); }

@keyframes sw-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── Banner ────────────────────────────────── */

.sw-banner {
    display: flex; align-items: center; justify-content: center;
    gap: 0.5rem; padding: 0.5rem 1rem; font-size: 0.85rem; font-weight: 500;
    width: 100%; flex-shrink: 0;
}
.sw-banner--info { background: var(--accent-dim); color: var(--accent-light); }
.sw-banner--warn { background: var(--warning-dim); color: var(--warning-light); }
.sw-banner--error { background: var(--danger-dim); color: var(--danger-light); }
.sw-banner--success { background: var(--success-dim); color: var(--success-light); }
.sw-banner__close {
    background: none; border: none; color: inherit; cursor: pointer;
    font-size: 1.1rem; padding: 0 0.3rem; opacity: 0.7;
}
.sw-banner__close:hover { opacity: 1; }

/* ── Toast ─────────────────────────────────── */

.sw-toast-container {
    position: fixed; bottom: 1rem; right: 1rem; z-index: 10000;
    display: flex; flex-direction: column-reverse; gap: 0.5rem;
    max-width: 380px; pointer-events: none;
}
.sw-toast {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.75rem 1rem; border-radius: var(--radius-lg);
    background: var(--bg-raised); border: 1px solid var(--border);
    box-shadow: var(--shadow-lg); pointer-events: auto;
    font-size: 0.875rem;
}
.sw-toast--enter { animation: sw-slide-in 0.25s ease; }
.sw-toast--exit { animation: sw-fade-out 0.2s ease forwards; }
.sw-toast--success { border-left: 3px solid var(--success); }
.sw-toast--error { border-left: 3px solid var(--danger); }
.sw-toast--warn { border-left: 3px solid var(--warning); }
.sw-toast--info { border-left: 3px solid var(--accent); }
.sw-toast__msg { flex: 1; color: var(--text); }
.sw-toast__close {
    background: none; border: none; color: var(--text-3); cursor: pointer;
    font-size: 1.1rem; padding: 0; line-height: 1;
}
.sw-toast__close:hover { color: var(--text); }

@keyframes sw-slide-in { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes sw-fade-out { to { opacity: 0; transform: translateX(50%); } }

/* ── Dialog ────────────────────────────────── */

.sw-dialog-overlay {
    position: fixed; inset: 0; z-index: 5000;
    background: var(--overlay); display: flex; align-items: center; justify-content: center;
    animation: sw-fade-in 0.15s ease;
}
.sw-dialog {
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    min-width: 360px; max-width: min(520px, 90vw); max-height: 85vh;
    display: flex; flex-direction: column; animation: sw-scale-in 0.2s ease;
}
.sw-dialog__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem; border-bottom: 1px solid var(--border);
}
.sw-dialog__title { font-size: 1rem; font-weight: 600; color: var(--text); margin: 0; }
.sw-dialog__close {
    background: none; border: none; color: var(--text-3); cursor: pointer;
    font-size: 1.3rem; padding: 0; line-height: 1;
}
.sw-dialog__close:hover { color: var(--text); }
.sw-dialog__body { padding: 1rem 1.25rem; overflow-y: auto; color: var(--text); font-size: 0.9rem; line-height: 1.5; }
.sw-dialog__actions {
    display: flex; gap: 0.5rem; justify-content: flex-end;
    padding: 0.75rem 1.25rem; border-top: 1px solid var(--border);
}

@keyframes sw-scale-in { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Menu ──────────────────────────────────── */

.sw-menu {
    z-index: 6000; min-width: 160px; max-width: 300px;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    padding: 4px 0; outline: none; animation: sw-fade-in 0.1s ease;
}
.sw-menu__item {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.75rem; cursor: pointer; font-size: 0.85rem;
    color: var(--text); transition: background var(--transition);
}
.sw-menu__item:hover, .sw-menu__item--focused { background: var(--bg-hover); }
.sw-menu__item--disabled { opacity: 0.4; cursor: not-allowed; }
.sw-menu__item--disabled:hover { background: transparent; }
.sw-menu__icon { flex-shrink: 0; width: 1.1em; text-align: center; color: var(--text-2); }
.sw-menu__label { flex: 1; }
.sw-menu__arrow { font-size: 0.6em; color: var(--text-3); }
.sw-menu__divider { height: 1px; background: var(--border); margin: 4px 0; }

@media (max-width: 768px) {
    .sw-menu { max-width: calc(100vw - 16px); }
    .sw-menu__item { min-height: 44px; padding: 0.5rem 0.75rem; }
}

/* ── Drawer ────────────────────────────────── */

.sw-drawer-overlay {
    position: fixed; inset: 0; z-index: 4000;
    background: transparent; transition: background 0.25s ease;
    pointer-events: none;
}
.sw-drawer-overlay--open { background: var(--overlay); pointer-events: auto; }
.sw-drawer {
    position: fixed; top: 0; bottom: 0; z-index: 4001;
    background: var(--bg-surface); border: 1px solid var(--border);
    display: flex; flex-direction: column;
    transition: transform 0.25s ease;
    overflow: hidden;
}
.sw-drawer--right { right: 0; transform: translateX(100%); }
.sw-drawer--right.sw-drawer--open { transform: translateX(0); }
.sw-drawer--left { left: 0; transform: translateX(-100%); }
.sw-drawer--left.sw-drawer--open { transform: translateX(0); }
.sw-drawer__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sw-drawer__title { font-size: 1rem; font-weight: 600; color: var(--text); margin: 0; }
.sw-drawer__close {
    background: none; border: none; color: var(--text-3); cursor: pointer;
    font-size: 1.3rem; padding: 0; line-height: 1;
}
.sw-drawer__close:hover { color: var(--text); }
.sw-drawer__body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; }

/* ── Tabs ──────────────────────────────────── */

.sw-tabs {
    display: flex; align-items: center; gap: 0;
    border-bottom: 1px solid var(--border); position: relative;
}
.sw-tabs__scroll {
    display: flex; overflow-x: auto; scrollbar-width: none;
    -ms-overflow-style: none; flex: 1;
}
.sw-tabs__scroll::-webkit-scrollbar { display: none; }
.sw-tabs__tab {
    padding: 0.5rem 0.9rem; background: none; border: none;
    border-bottom: 2px solid transparent; color: var(--text-2);
    font-family: var(--font); font-size: 0.85rem; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
}
.sw-tabs__tab:hover { color: var(--text); }
.sw-tabs__tab--active { color: var(--accent); border-bottom-color: var(--accent); }
.sw-tabs__tab--disabled { opacity: 0.4; cursor: not-allowed; }
.sw-tabs__icon { margin-right: 0.35rem; }
.sw-tabs__arrow {
    background: none; border: none; color: var(--text-3);
    cursor: pointer; padding: 0.3rem 0.5rem; font-size: 1.2rem; flex-shrink: 0;
}
.sw-tabs__arrow:hover { color: var(--text); }

/* ── Dropdown ──────────────────────────────── */

.sw-dropdown { position: relative; display: inline-block; }
.sw-dropdown__trigger {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; width: 100%; padding: 0.45rem 0.7rem;
    background: var(--input-bg); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius);
    font-family: var(--font); font-size: 0.875rem; cursor: pointer;
    transition: border-color var(--transition);
}
.sw-dropdown--open .sw-dropdown__trigger { border-color: var(--accent); }
.sw-dropdown__value { flex: 1; text-align: left; }
.sw-dropdown__chevron { color: var(--text-3); font-size: 0.7em; }
.sw-dropdown__list {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    z-index: 6000; max-height: 240px; overflow-y: auto;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    animation: sw-fade-in 0.1s ease;
}
.sw-dropdown__search { margin: 4px; width: calc(100% - 8px); }
.sw-dropdown__option {
    padding: 0.4rem 0.75rem; cursor: pointer; font-size: 0.85rem;
    color: var(--text); transition: background var(--transition);
}
.sw-dropdown__option:hover, .sw-dropdown__option--focused { background: var(--bg-hover); }
.sw-dropdown__option--selected { color: var(--accent); font-weight: 500; }
.sw-dropdown__option--disabled { opacity: 0.4; cursor: not-allowed; }
.sw-dropdown__option--disabled:hover { background: transparent; }
.sw-dropdown__empty { padding: 0.75rem; text-align: center; color: var(--text-3); font-size: 0.85rem; }
