/* ============================================
   MATCHDECK DESIGN SYSTEM v4.0
   Global tokens, states, and polish.
   Load AFTER base.css, BEFORE portal.css
   ============================================ */

/* ══ TOKEN OVERRIDES ════════════════════════ */

:root {
    /* ── Primary: Tournament Orange (single source) ── */
    --color-primary:       #f97316;
    --color-primary-dark:  #ea580c;
    --color-primary-light: #fed7aa;
    --color-primary-bg:    #fff7ed;
    --color-primary-ring:  rgba(249, 115, 22, 0.18);

    /* ── Secondary: Sport Navy ── */
    --color-secondary:       #1e3a5f;
    --color-secondary-dark:  #153050;
    --color-secondary-light: #dbeafe;

    /* ── Semantic ── */
    --color-success:    #10b981;
    --color-success-bg: #ecfdf5;
    --color-warning:    #f59e0b;
    --color-warning-bg: #fffbeb;
    --color-error:      #ef4444;
    --color-error-bg:   #fef2f2;
    --color-info:       #3b82f6;
    --color-info-bg:    #eff6ff;

    /* ── Surfaces ── */
    --surface-page:    #f5f5f7;
    --surface-card:    #ffffff;
    --surface-sidebar: #0f172a;

    /* ── Typography scale (7 steps) ── */
    --text-2xs:  0.65rem;
    --text-xs:   0.75rem;
    --text-sm:   0.85rem;
    --text-base: 0.95rem;
    --text-lg:   1.05rem;
    --text-xl:   1.25rem;
    --text-2xl:  1.5rem;

    /* ── Display stats (Bebas Neue) ── */
    --stat-sm:  1.3rem;
    --stat-md:  1.8rem;
    --stat-lg:  2.5rem;

    /* ── Border radius (4 levels) ── */
    --radius-sm:  6px;
    --radius-md:  8px;
    --radius-lg:  12px;
    --radius-xl:  16px;

    /* ── Shadows (3 levels) ── */
    --shadow-card:  0 1px 3px rgba(0,0,0,0.04);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-modal: 0 20px 48px -12px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04);

    /* ── Motion ── */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 120ms;
    --duration-base: 180ms;
    --duration-slow: 280ms;

    /* ── Layout ── */
    --sidebar-width:   256px;
    --topbar-height:   52px;
    --bottom-nav-h:    56px;
    --card-padding:    1.125rem;
    --card-padding-sm: 0.875rem;
    --section-gap:     0.875rem;

    /* ── Breakpoints (for reference, used in media queries) ── */
    /* Mobile:  0–767px    */
    /* Tablet:  768–1023px */
    /* Desktop: 1024+      */
    /* Wide:    1280+      */
}


/* ══ FOCUS STATES ═══════════════════════════ */

/* Global keyboard focus ring */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove browser default only when we provide our own */
:focus:not(:focus-visible) {
    outline: none;
}

/* Input-specific focus (border + ring instead of outline) */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.p-form-input:focus-visible,
.form-input:focus-visible,
.code-input:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-ring);
}

/* Buttons — subtle ring */
button:focus-visible,
.p-btn:focus-visible,
.btn:focus-visible,
a.p-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--color-primary-ring);
}


/* ══ HOVER: DESKTOP ONLY ═══════════════════ */

/* Prevent sticky :hover on touch devices */
@media (hover: hover) and (pointer: fine) {
    .p-card:hover,
    .me-card:hover,
    .bc-card:hover,
    .tm-card:hover,
    .trk-team-card:hover,
    .club-card:hover,
    .db-reg-card:hover,
    .pd-match-card.pd-match-clickable:hover,
    .db-chip:hover,
    .db-quick-tile:hover,
    .db-team-chip:hover,
    .dash-match-row:hover {
        box-shadow: var(--shadow-hover);
        transform: translateY(-1px);
    }
}

/* Remove hover effects on touch */
@media (hover: none) {
    .p-card:hover,
    .me-card:hover,
    .bc-card:hover,
    .tm-card:hover,
    .trk-team-card:hover,
    .club-card:hover,
    .db-reg-card:hover,
    .pd-match-card.pd-match-clickable:hover,
    .db-chip:hover,
    .db-quick-tile:hover,
    .db-team-chip:hover,
    .dash-match-row:hover {
        box-shadow: none !important;
        transform: none !important;
    }
}

/* Active state for touch feedback */
@media (hover: none) {
    .p-card:active,
    .me-card:active,
    .bc-card:active,
    .tm-card:active,
    .trk-team-card:active,
    .p-btn:active,
    .btn:active {
        transform: scale(0.98);
        transition: transform 60ms ease;
    }
}


/* ══ SKELETON / LOADING ════════════════════ */

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-gray-100) 25%,
        var(--color-gray-50) 50%,
        var(--color-gray-100) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

.skeleton * {
    visibility: hidden;
}

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
    margin-bottom: var(--section-gap);
}

.skeleton-line {
    height: 14px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-line:last-child {
    margin-bottom: 0;
}

.skeleton-line-short {
    width: 60%;
}

.skeleton-line-xs {
    width: 35%;
}

.skeleton-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-stat {
    height: 80px;
    border-radius: var(--radius-lg);
}

/* Skeleton grid helper */
.skeleton-grid {
    display: grid;
    gap: 12px;
}

.skeleton-grid-2 { grid-template-columns: 1fr 1fr; }
.skeleton-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 767px) {
    .skeleton-grid-3 { grid-template-columns: 1fr 1fr; }
}


/* ══ FORM VALIDATION ══════════════════════ */

.p-form-input.invalid,
.form-input.invalid,
input.invalid,
select.invalid,
textarea.invalid {
    border-color: var(--color-error) !important;
    background: var(--color-error-bg);
}

.p-form-input.invalid:focus,
.form-input.invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.p-form-input.valid,
.form-input.valid {
    border-color: var(--color-success);
}

.p-form-error,
.form-error {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-error);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.p-form-success,
.form-success {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-success);
    margin-top: 4px;
}


/* ══ TOAST POLISH ═════════════════════════ */

.toast {
    animation: toastIn var(--duration-slow) var(--ease);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


/* ══ SCROLL SNAP FOR TABS ═════════════════ */

.p-tabs,
.pd-tabs,
.trk-tabs,
.me-filters {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.p-tabs::-webkit-scrollbar,
.pd-tabs::-webkit-scrollbar,
.trk-tabs::-webkit-scrollbar,
.me-filters::-webkit-scrollbar {
    display: none;
}


/* ══ REDUCED MOTION ═══════════════════════ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .skeleton {
        animation: none;
        background: var(--color-gray-100);
    }
}


/* ══ SMOOTH SCROLL ════════════════════════ */

html {
    scroll-behavior: smooth;
}

/* Anchor offset for sticky headers */
.portal-main {
    scroll-padding-top: calc(var(--topbar-height) + 16px);
}


/* ══ SELECTION ════════════════════════════ */

::selection {
    background: var(--color-primary-light);
    color: var(--color-gray-900);
}


/* ══ TOUCH TARGET MINIMUM ═════════════════ */

/* Ensure all clickable items meet 44px minimum */
.bottom-nav-item {
    min-height: 48px;
}

.p-btn,
.btn {
    min-height: 36px;
}

.p-btn-sm,
.btn-sm {
    min-height: 32px;
}

/* Icon buttons */
.sidebar-logout,
.sidebar-toggle,
.modal-close,
.trk-icon-btn,
.er-detail-close {
    min-width: 36px;
    min-height: 36px;
}


/* ══ UTILITY ADDITIONS ═══════════════════ */

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

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* No scrollbar utility */
.no-scrollbar {
    scrollbar-width: none;
}
.no-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Fade in animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.fade-in {
    animation: fadeIn var(--duration-base) var(--ease);
}

/* Slide up animation */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.slide-up {
    animation: slideUp var(--duration-slow) var(--ease);
}

/* Stagger children animation */
.stagger > * {
    animation: slideUp var(--duration-slow) var(--ease) both;
}
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 40ms; }
.stagger > *:nth-child(3) { animation-delay: 80ms; }
.stagger > *:nth-child(4) { animation-delay: 120ms; }
.stagger > *:nth-child(5) { animation-delay: 160ms; }
.stagger > *:nth-child(6) { animation-delay: 200ms; }


/* ══ SAFE AREA (iOS notch/home indicator) ═ */

.portal-main {
    padding-bottom: max(4rem, calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 1rem));
}

@media (min-width: 1024px) {
    .portal-main {
        padding-bottom: 3rem;
    }
}