/* ══════════════════════════════════════════════════════════
   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 & 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 */
    --tp-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* 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;
}

/* ── Page fade-in ── */
@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
body { animation: pageFadeIn 0.3s ease-out; }

/* ── 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);
    transform: translateY(100%); transition: transform 0.3s ease;
}
.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; transform: translateY(0); }
    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; }

/* ── Data Page Top Bar (harmonized with Newsroom) ── */
.top-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; padding: 6px 16px; border-bottom: 1px solid var(--tp-border); }
.top-bar .logo { font-size: 1.2rem; font-weight: 800; color: var(--tp-navy); text-decoration: none; }
.top-bar .logo span { color: var(--tp-gold); }
.badge-nr { background: var(--tp-navy); color: var(--tp-gold); padding: 0.15rem 0.6rem; border-radius: 20px; font-weight: 600; font-size: 0.72rem; margin-left: 0.4rem; display: inline-block; vertical-align: middle; }
.top-bar-actions { display: flex; gap: 0.4rem; align-items: center; }
.btn-nav-main { display: inline-flex; align-items: center; gap: 6px; padding: 7px 16px; border-radius: 8px; font-size: 0.82rem; font-weight: 700; font-family: var(--tp-font); text-decoration: none; transition: all 0.2s; border: none; cursor: pointer; min-height: 36px; }
.btn-nav-journal { background: var(--tp-navy); color: var(--tp-gold); }
.btn-nav-journal:hover { background: var(--tp-navy-light); color: var(--tp-gold-light); box-shadow: var(--tp-shadow-md); }
.btn-nav-newsroom { background: linear-gradient(135deg, var(--tp-gold), #b8953e); color: var(--tp-navy); }
.btn-nav-newsroom:hover { box-shadow: var(--tp-shadow-md); transform: translateY(-1px); color: var(--tp-navy); }
.tp-data-ts { font-size: 0.72rem; color: var(--tp-text-muted); }
.tp-data-ts::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--tp-success); margin-right: 5px; vertical-align: middle; }
.btn-tp-sm { padding: 5px 12px !important; min-height: 32px !important; font-size: 0.75rem !important; }
@media print { .top-bar { display: none !important; } }

/* ── Data Navigation Bar (dn-bar) ── */
.dn-bar { margin-bottom: 0.4rem; border-radius: 10px; overflow: hidden; box-shadow: var(--tp-shadow-sm); background: #220808; }
.dn-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 6px; padding: 6px 14px; }
.dn-row + .dn-row { border-top: 1px solid rgba(201,168,76,0.15); }
.dn-label { font-weight: 800; font-size: 0.6rem; text-transform: uppercase; color: var(--tp-gold); letter-spacing: 1px; margin-right: 6px; white-space: nowrap; }
.dn-label i { margin-right: 3px; }
.dn-label-link { font-weight: 800; font-size: 0.6rem; text-transform: uppercase; color: var(--tp-gold); letter-spacing: 1px; margin-right: 6px; white-space: nowrap; text-decoration: none; }
.dn-label-link:hover { text-decoration: underline; color: var(--tp-gold-light); }
.dn-group { display: inline-flex; align-items: center; gap: 2px; margin: 2px 0; }
.dn-grp { font-size: 0.52rem; font-weight: 700; color: rgba(201,168,76,0.55); text-transform: uppercase; letter-spacing: 0.5px; margin-right: 3px; white-space: nowrap; }
.dn-group-links { display: inline-flex; flex-wrap: wrap; gap: 3px; }
.dn-link { padding: 3px 8px; border-radius: 4px; font-size: 0.62rem; font-weight: 600; color: rgba(255,255,255,0.75); text-decoration: none; transition: all 0.15s; white-space: nowrap; display: inline-flex; align-items: center; gap: 3px; }
.dn-link:hover { background: rgba(201,168,76,0.2); color: #fff; }
.dn-link i { font-size: 0.55rem; }
.dn-sep { width: 1px; height: 16px; background: rgba(201,168,76,0.18); margin: 0 6px; }
.dn-cat-id { display: inline-block; width: 14px; height: 14px; border-radius: 3px; background: rgba(201,168,76,0.15); color: var(--tp-gold); font-size: 0.48rem; font-weight: 800; text-align: center; line-height: 14px; margin-right: 2px; }
/* Row 2 — Analyses: distinct cooler tones (indigo/slate) */
.dn-row.dn-row-analyses { background: rgba(100,120,160,0.12); }
.dn-row-analyses .dn-label-link { color: #a8c4e0; }
.dn-row-analyses .dn-label-link:hover { color: #d0e4f7; }
.dn-row-analyses .dn-link { color: rgba(200,215,235,0.85); background: rgba(100,140,200,0.1); }
.dn-row-analyses .dn-link:hover { background: rgba(100,140,200,0.25); color: #fff; }
.dn-row-analyses .dn-cat-id { background: rgba(100,140,200,0.25); color: #a8c4e0; }
.dn-row-analyses .dn-grp { color: rgba(160,190,220,0.6); }
.dn-row-analyses .dn-sep { background: rgba(100,140,200,0.25); }
.dn-row-analyses .dn-group { border-color: rgba(100,140,200,0.15); background: rgba(100,140,200,0.05); }
@media (max-width: 768px) { .dn-row { padding: 4px 6px; gap: 3px 4px; } .dn-grp { display: none; } .dn-sep { margin: 0 3px; height: 10px; } .dn-link { font-size: 0.56rem; padding: 2px 5px; } }
@media print { .dn-bar { display: none !important; } }

/* ── Hide Tunisien.tn logo in data page headers (legacy) ── */
.sc-header .logo img, .ca-header .logo img, .macro-header .logo img, .fin-header .logo img, .jort-header .logo img, .cmf-header .logo img { display: none; }

/* ── 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; }
}
