/* ══════════════════════════════════════════════════════════
   TunisienPremium — Design System v2.0
   Shared across ALL templates for 19/20 UX consistency
   ══════════════════════════════════════════════════════════ */

/* ── Brand Tokens ── */
:root {
    /* Primary palette */
    --tp-navy: #220808;
    --tp-navy-light: #3A0E0E;
    --tp-gold: #c9a84c;
    --tp-gold-dark: #8a6d1b;      /* WCAG AA on white (5.2:1) */
    --tp-gold-light: #e8d5a0;
    --tp-gold-bg: rgba(201,168,76,0.08);

    /* Surfaces */
    --tp-bg: #f5f6fa;
    --tp-bg-alt: #ecedf2;
    --tp-card: #ffffff;
    --tp-border: #e2e4ea;

    /* Text — WCAG AA compliant */
    --tp-text: #220808;
    --tp-text-secondary: #4a4a5a;  /* 7.5:1 on white */
    --tp-text-muted: #6b6b78;     /* 4.6:1 on white */

    /* Semantic */
    --tp-success: #1e7e34;
    --tp-danger: #c0392b;
    --tp-info: #2471a3;
    --tp-warning: #d68910;

    /* Spacing Scale (DS-01) — 4px base */
    --tp-space-xs: 4px;
    --tp-space-sm: 8px;
    --tp-space-md: 16px;
    --tp-space-lg: 24px;
    --tp-space-xl: 32px;
    --tp-space-2xl: 48px;
    --tp-space-3xl: 64px;

    /* Radius */
    --tp-radius-sm: 8px;
    --tp-radius-md: 12px;
    --tp-radius-lg: 16px;
    --tp-radius-pill: 9999px;

    /* Shadows */
    --tp-shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --tp-shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --tp-shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

    /* Typography Scale (DS-02) */
    --tp-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --tp-text-xs: 0.69rem;
    --tp-text-sm: 0.78rem;
    --tp-text-base: 0.95rem;
    --tp-text-lg: 1.125rem;
    --tp-text-xl: 1.25rem;
    --tp-text-2xl: 1.5rem;
    --tp-text-3xl: 2rem;

    /* Z-index Scale (DS-03) */
    --tp-z-dropdown: 100;
    --tp-z-sticky: 200;
    --tp-z-fixed: 300;
    --tp-z-modal-backdrop: 400;
    --tp-z-modal: 500;
    --tp-z-popover: 600;
    --tp-z-toast: 10000;

    /* Breakpoints (DS-19) */
    --tp-bp-sm: 576px;
    --tp-bp-md: 768px;
    --tp-bp-lg: 992px;
    --tp-bp-xl: 1200px;

    /* Transitions */
    --tp-transition: 0.2s ease;

    /* Legacy compat aliases */
    --tn-primary: var(--tp-navy);
    --tn-primary-dark: var(--tp-navy-light);
    --tn-accent: var(--tp-gold);
    --tn-accent-dark: var(--tp-gold-dark);
    --tn-bg-dark: #060303;
    --tn-bg-card: #0e0505;
    --tn-border: #1a0a0a;
    --tn-text: #e8e8ec;
    --tn-text-muted: #a0a0a8;
}

/* ── Dark mode ── */
.dark-mode {
    --tp-bg: #0a0404;
    --tp-bg-alt: #120606;
    --tp-card: #1a0808;
    --tp-text: #e8e8ec;
    --tp-text-secondary: #b0b0b8;
    --tp-text-muted: #888890;
    --tp-border: #2a1010;
}

/* ── Reduced Motion (A11Y-07) ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Page fade-in ── */
@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
body { animation: pageFadeIn 0.3s ease-out; }

/* ── iOS zoom prevention (MOB-06) ── */
@media screen and (max-width: 768px) {
    input[type="text"], input[type="email"], input[type="tel"],
    input[type="password"], input[type="url"], input[type="search"],
    input[type="number"], textarea, select {
        font-size: 16px !important;
    }
}

/* ── Skip Link (Accessibility) ── */
.skip-link {
    position: absolute; top: -40px; left: 0;
    background: var(--tp-navy); color: #fff;
    padding: 8px 16px; z-index: 10000;
    font-size: 0.85rem; font-weight: 600;
    transition: top 0.2s;
}
.skip-link:focus { top: 0; }

/* ── Focus Visible (Accessibility) ── */
:focus-visible {
    outline: 3px solid var(--tp-gold);
    outline-offset: 2px;
}
/* Remove default outline when using mouse */
:focus:not(:focus-visible) { outline: none; }

/* ── Buttons ── */
.btn-tp-primary {
    background: linear-gradient(135deg, var(--tp-navy), var(--tp-navy-light));
    color: #fff; border: none;
    border-radius: var(--tp-radius-md); padding: 11px 20px;
    font-family: var(--tp-font); font-size: 0.95rem; font-weight: 600;
    cursor: pointer; transition: all var(--tp-transition);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; /* Touch target */
}
.btn-tp-primary:hover { transform: translateY(-1px); box-shadow: var(--tp-shadow-md); color: #fff; }
.btn-tp-primary:active { transform: translateY(0); }
.btn-tp-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-tp-gold {
    background: linear-gradient(135deg, var(--tp-gold), #b8953e);
    color: var(--tp-navy); border: none;
    border-radius: var(--tp-radius-md); padding: 11px 20px;
    font-family: var(--tp-font); font-size: 0.95rem; font-weight: 700;
    cursor: pointer; transition: all var(--tp-transition);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px;
}
.btn-tp-gold:hover { transform: translateY(-1px); box-shadow: var(--tp-shadow-md); color: var(--tp-navy); }

.btn-tp-outline {
    background: transparent; color: var(--tp-text-secondary);
    border: 2px solid var(--tp-border);
    border-radius: var(--tp-radius-md); padding: 9px 18px;
    font-family: var(--tp-font); font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all var(--tp-transition);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px;
}
.btn-tp-outline:hover { border-color: var(--tp-gold); color: var(--tp-gold-dark); }

/* ── Form Controls ── */
.tp-input {
    width: 100%; border: 2px solid var(--tp-border);
    border-radius: var(--tp-radius-md); padding: 11px 14px;
    font-family: var(--tp-font); font-size: 0.95rem;
    color: var(--tp-text); background: var(--tp-card);
    transition: border-color var(--tp-transition), box-shadow var(--tp-transition);
    min-height: 44px;
}
.tp-input:focus {
    outline: none; border-color: var(--tp-gold);
    box-shadow: 0 0 0 3px rgba(201,168,76,0.15);
}
.tp-input::placeholder { color: var(--tp-text-muted); }
.tp-input[aria-invalid="true"] { border-color: var(--tp-danger); }

.tp-label {
    display: block; font-weight: 600; font-size: 0.88rem;
    color: var(--tp-text); margin-bottom: 6px;
}

/* Password field with toggle */
.tp-password-wrap {
    position: relative;
}
.tp-password-wrap .tp-input { padding-right: 44px; }
.tp-password-toggle {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--tp-text-muted);
    cursor: pointer; padding: 6px; font-size: 1.1rem;
    display: flex; align-items: center; justify-content: center;
    min-width: 36px; min-height: 36px;
}
.tp-password-toggle:hover { color: var(--tp-text); }

/* Password strength meter */
.tp-strength-meter {
    height: 4px; border-radius: 2px; background: var(--tp-border);
    margin-top: 6px; overflow: hidden;
}
.tp-strength-bar {
    height: 100%; border-radius: 2px; width: 0%;
    transition: width 0.3s, background 0.3s;
}
.tp-strength-bar[data-strength="0"] { width: 0%; }
.tp-strength-bar[data-strength="1"] { width: 25%; background: var(--tp-danger); }
.tp-strength-bar[data-strength="2"] { width: 50%; background: var(--tp-warning); }
.tp-strength-bar[data-strength="3"] { width: 75%; background: var(--tp-info); }
.tp-strength-bar[data-strength="4"] { width: 100%; background: var(--tp-success); }
.tp-strength-text {
    font-size: 0.72rem; margin-top: 3px;
    color: var(--tp-text-muted); font-weight: 500;
}

/* Field error message */
.tp-field-error {
    font-size: 0.78rem; color: var(--tp-danger);
    margin-top: 4px; display: none;
}
.tp-field-error.visible { display: block; }

/* ── Toast Notifications ── */
.tp-toast-container {
    position: fixed; bottom: 24px; right: 24px;
    z-index: 10000; display: flex; flex-direction: column;
    gap: 8px; pointer-events: none;
}
.tp-toast {
    background: var(--tp-navy); color: #fff;
    padding: 12px 20px; border-radius: var(--tp-radius-md);
    font-family: var(--tp-font); font-size: 0.88rem; font-weight: 600;
    box-shadow: var(--tp-shadow-lg);
    display: flex; align-items: center; gap: 8px;
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease-out;
    max-width: 360px;
}
.tp-toast.success { background: var(--tp-success); }
.tp-toast.error { background: var(--tp-danger); }
.tp-toast.warning { background: var(--tp-warning); }
@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastSlideOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(12px); }
}

/* ── Loading Spinner on Buttons ── */
.btn-loading {
    pointer-events: none; opacity: 0.8;
}
.btn-loading .btn-text { visibility: hidden; }
.btn-loading::after {
    content: ''; position: absolute;
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: btnSpin 0.6s linear infinite;
}
@keyframes btnSpin {
    to { transform: rotate(360deg); }
}

/* ── Card Component ── */
.tp-card {
    background: var(--tp-card); border-radius: var(--tp-radius-lg);
    padding: 2rem; box-shadow: var(--tp-shadow-md);
}

/* ── Plan Badges ── */
.tp-plan-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: var(--tp-radius-pill);
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
}
.tp-plan-free { background: #e3f2fd; color: #1565c0; }
.tp-plan-basic { background: #e8f5e9; color: #1e7e34; }
.tp-plan-pro { background: rgba(201,168,76,0.15); color: var(--tp-gold-dark); }
.tp-plan-corporate { background: #f3e5f5; color: #6a1b9a; }
.tp-plan-admin { background: var(--tp-navy); color: var(--tp-gold); }

/* ── Empty State ── */
.tp-empty-state {
    text-align: center; padding: 3rem 1rem;
    color: var(--tp-text-muted);
}
.tp-empty-state i {
    font-size: 3rem; opacity: 0.3; display: block;
    margin-bottom: 1rem;
}
.tp-empty-state p {
    font-size: 0.9rem; max-width: 400px; margin: 0 auto;
}

/* ── Alert / Banner ── */
.tp-alert {
    border-radius: var(--tp-radius-md); padding: 12px 16px;
    font-size: 0.88rem; display: flex; align-items: flex-start; gap: 10px;
    margin-bottom: 1rem;
}
.tp-alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.tp-alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.tp-alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.tp-alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ── Confirm Modal ── */
.tp-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 9998; display: none; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}
.tp-modal-overlay.open { display: flex; }
.tp-modal {
    background: var(--tp-card); border-radius: var(--tp-radius-lg);
    padding: 2rem; max-width: 420px; width: 90%;
    box-shadow: var(--tp-shadow-lg);
    animation: modalFadeIn 0.2s ease-out;
}
@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.tp-modal h4 { color: var(--tp-text); font-weight: 700; margin-bottom: 0.5rem; }
.tp-modal p { color: var(--tp-text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.tp-modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ── Mobile Bottom Nav ── */
.tp-bottom-nav {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--tp-card); border-top: 1px solid var(--tp-border);
    padding: 6px 0 max(6px, env(safe-area-inset-bottom));
    z-index: 500; box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
}
.tp-bottom-nav-inner {
    display: flex; justify-content: space-around; align-items: center;
    max-width: 500px; margin: 0 auto;
}
.tp-bottom-nav a {
    display: flex; flex-direction: column; align-items: center;
    padding: 4px 12px; color: var(--tp-text-muted);
    font-size: 0.65rem; font-weight: 600; text-decoration: none;
    transition: color var(--tp-transition);
    min-width: 56px; min-height: 44px; justify-content: center;
}
.tp-bottom-nav a i { font-size: 1.2rem; margin-bottom: 2px; }
.tp-bottom-nav a.active { color: var(--tp-gold-dark); }
.tp-bottom-nav a:hover { color: var(--tp-gold-dark); }

@media (max-width: 768px) {
    .tp-bottom-nav { display: block; }
    body { padding-bottom: 72px; }
}

/* ── Accessibility: min touch target ── */
button, a, input[type="checkbox"], input[type="radio"], select {
    min-height: 44px;
}
input[type="checkbox"], input[type="radio"] {
    min-width: 20px; min-height: 20px;
}

/* ── WCAG AA: ensure gold text contrast ── */
.text-gold-safe { color: var(--tp-gold-dark); } /* 5.2:1 on white */

/* ── Def Button (definition tooltip for data pages) ── */
.def-btn { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; font-size: 0.5rem; font-weight: 800; color: var(--tp-navy); background: rgba(26,31,54,0.08); border: 1px solid rgba(26,31,54,0.25); cursor: pointer; transition: all 0.2s; vertical-align: middle; margin-left: 4px; line-height: 1; flex-shrink: 0; }
.def-btn:hover { background: var(--tp-navy); color: #fff; border-color: var(--tp-navy); }
.def-panel { position: fixed; z-index: 9999; background: var(--tp-card); border: 2px solid var(--tp-navy); border-radius: 10px; padding: 14px 16px; max-width: 400px; box-shadow: 0 8px 30px rgba(0,0,0,0.18); font-size: 0.72rem; line-height: 1.6; color: var(--tp-text-muted); display: none; }
.def-panel.visible { display: block; }
.def-panel-title { font-weight: 800; color: var(--tp-text); margin-bottom: 8px; font-size: 0.82rem; display: flex; align-items: center; justify-content: space-between; padding-bottom: 6px; border-bottom: 2px solid rgba(26,31,54,0.15); }
.def-panel-close { cursor: pointer; font-size: 1.1rem; color: var(--tp-text-muted); padding: 0 4px; }
.def-panel-close:hover { color: var(--tp-navy); }
.def-section { margin-bottom: 8px; }
.def-section:last-of-type { margin-bottom: 4px; }
.def-section-title { font-weight: 700; color: var(--tp-text); font-size: 0.68rem; margin-bottom: 3px; text-transform: uppercase; letter-spacing: 0.3px; }
.def-panel-src { display: block; margin-top: 8px; padding-top: 6px; border-top: 1px solid rgba(0,0,0,0.06); font-size: 0.6rem; color: var(--tp-text-muted); font-style: italic; }

/* ── Dark mode: reduce image brightness ── */
.dark-mode img:not(.logo-img):not([data-no-dim]) {
    filter: brightness(0.85);
    transition: filter var(--tp-transition);
}

/* ── Tables: responsive overflow ── */
.tp-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}
table {
    border-collapse: collapse;
    min-width: 100%;
}
@media (max-width: 768px) {
    .sidebar, .data-sidebar, [class*="sidebar"] {
        overflow-x: auto;
    }
    table { font-size: 0.82rem; }
}

/* ── Title line-clamp (card titles) ── */
.tp-line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tp-line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Skeleton Loading ── */
.tp-skeleton {
    background: linear-gradient(90deg, var(--tp-bg-alt) 25%, var(--tp-bg) 50%, var(--tp-bg-alt) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
    border-radius: var(--tp-radius-sm);
}
.tp-skeleton-text { height: 14px; margin-bottom: 8px; }
.tp-skeleton-title { height: 20px; width: 70%; margin-bottom: 12px; }
.tp-skeleton-img { height: 180px; margin-bottom: 12px; }
.tp-skeleton-card {
    background: var(--tp-card);
    border-radius: var(--tp-radius-lg);
    padding: 1.5rem;
    box-shadow: var(--tp-shadow-sm);
}
@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Reading Progress Bar ── */
.tp-reading-progress {
    position: fixed; top: 0; left: 0;
    width: 0%; height: 3px;
    background: linear-gradient(90deg, var(--tp-gold), var(--tp-gold-dark));
    z-index: 10001;
    transition: width 0.1s linear;
}

/* ── Breadcrumb ── */
.tp-breadcrumb {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.78rem; color: var(--tp-text-muted);
    padding: 8px 0; flex-wrap: wrap;
}
.tp-breadcrumb a {
    color: var(--tp-text-muted); text-decoration: none;
    transition: color var(--tp-transition);
}
.tp-breadcrumb a:hover { color: var(--tp-gold-dark); }
.tp-breadcrumb .sep { color: var(--tp-border); }
.tp-breadcrumb .current { color: var(--tp-text); font-weight: 600; }

/* ── Daltonien-Safe Palette (VIZ-02) — Wong 2011 ── */
:root {
    --tp-chart-1: #0072B2; /* blue */
    --tp-chart-2: #E69F00; /* orange */
    --tp-chart-3: #009E73; /* green */
    --tp-chart-4: #CC79A7; /* pink */
    --tp-chart-5: #56B4E9; /* sky */
    --tp-chart-6: #D55E00; /* vermillion */
    --tp-chart-7: #F0E442; /* yellow */
    --tp-chart-8: #220808; /* black */
}

/* ── Enhanced Form Field (DS-16 + FORM-01) ── */
.tp-field { margin-bottom: 16px; }
.tp-field .tp-label { margin-bottom: 4px; }
.tp-field .tp-hint {
    font-size: 0.75rem; color: var(--tp-text-muted);
    margin-top: 3px;
}
.tp-field .tp-error {
    font-size: 0.75rem; color: var(--tp-danger);
    margin-top: 3px; display: none;
}
.tp-field.has-error .tp-input { border-color: var(--tp-danger); }
.tp-field.has-error .tp-error { display: block; }
.tp-field.has-success .tp-input { border-color: var(--tp-success); }

/* ── Gated Content Card (CRO-14) ── */
.tp-gated {
    position: relative; overflow: hidden;
    border-radius: var(--tp-radius-lg);
    background: var(--tp-card); border: 1px solid var(--tp-border);
}
.tp-gated-preview {
    max-height: 200px; overflow: hidden;
    mask-image: linear-gradient(to bottom, #000 40%, transparent);
    -webkit-mask-image: linear-gradient(to bottom, #000 40%, transparent);
    padding: 20px;
}
.tp-gated-overlay {
    text-align: center; padding: 24px;
    background: linear-gradient(to top, var(--tp-card) 60%, transparent);
}

/* ── Testimonial Card ── */
.tp-testimonial {
    background: var(--tp-card); border: 1px solid var(--tp-border);
    border-radius: var(--tp-radius-lg); padding: 24px;
    position: relative;
}
.tp-testimonial::before {
    content: '\201C'; position: absolute; top: 12px; left: 16px;
    font-size: 3rem; color: var(--tp-gold); opacity: 0.3;
    font-family: Georgia, serif; line-height: 1;
}
.tp-testimonial blockquote {
    font-size: 0.9rem; font-style: italic; line-height: 1.7;
    color: var(--tp-text-secondary); margin: 0 0 12px; padding-left: 8px;
}
.tp-testimonial-author {
    display: flex; align-items: center; gap: 10px;
}
.tp-testimonial-author .name { font-weight: 700; font-size: 0.85rem; }
.tp-testimonial-author .role { font-size: 0.75rem; color: var(--tp-text-muted); }

/* ── Details/Summary Styling ── */
details summary { user-select: none; }
details summary::-webkit-details-marker { display: none; }
details[open] summary .bi-chevron-down { transform: rotate(180deg); }

/* ── Smooth Scroll ── */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

/* ── Selection Color ── */
::selection { background: rgba(201,168,76,0.3); color: var(--tp-text); }

/* ── Back to Top ── */
#backToTop:hover { transform: scale(1.1); }

/* ── Hover Card Accent (DS-05) ── */
.card:hover { border-color: var(--tp-gold); }
.card[style*="border-left"]:hover { box-shadow: var(--tp-shadow-md); }

/* ── Print ── */
@media print {
    img { max-width: 100% !important; height: auto !important; }
    .no-print, .tp-bottom-nav, .tp-reading-progress { display: none !important; }
    * { break-inside: avoid-page; }
    .article-body p, .article-body li { break-inside: avoid; }
    table { break-inside: auto; }
    tr { break-inside: avoid; break-after: auto; }
}
