/* ============================================================================
   GeoSmart Solutions — Modern theme overlay
   Loaded after style.css; extends the existing palette with a refined
   typography scale, motion, dark mode and a few component upgrades.
   ============================================================================ */

/* --- Typography ---------------------------------------------------------- */
:root {
    --gss-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
        Roboto, 'Helvetica Neue', Arial, sans-serif;
    --gss-font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    /* Typography scale (modular ratio 1.125) */
    --fs-xs: 0.75rem;
    --fs-sm: 0.875rem;
    --fs-base: 0.9375rem;
    --fs-md: 1rem;
    --fs-lg: 1.125rem;
    --fs-xl: 1.25rem;
    --fs-2xl: 1.5rem;
    --fs-3xl: 1.875rem;
    --fs-4xl: 2.25rem;

    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;

    --lh-tight: 1.25;
    --lh-snug: 1.375;
    --lh-normal: 1.5;
    --lh-relaxed: 1.625;

    /* --- Extended palette ------------------------------------------------ */
    --gss-primary-50: #eff4fc;
    --gss-primary-100: #d6e1f5;
    --gss-primary-200: #aac2eb;
    --gss-primary-300: #7196d6;
    --gss-primary-400: #426cb8;
    --gss-primary-500: #1f4694;
    --gss-primary-600: #143474;
    --gss-primary-700: #001f54;   /* original brand */
    --gss-primary-800: #001440;
    --gss-primary-900: #000a26;

    --gss-accent: #00b8d9;
    --gss-accent-soft: #e6f7fb;

    /* Surfaces (light mode default) */
    --surface-bg: #f5f7fb;
    --surface-card: #ffffff;
    --surface-muted: #f0f3f8;
    --surface-hover: #f7f9fc;
    --border-soft: #e5eaf2;
    --border-strong: #cdd5e2;
    --text-strong: #0f172a;
    --text-default: #1f2937;
    --text-muted: #5b6878;
    --text-disabled: #94a3b8;

    /* Status soft backgrounds (used by .status-badge below) */
    --status-success-bg: #e6f5ee;
    --status-success-fg: #166e3f;
    --status-warning-bg: #fff5d9;
    --status-warning-fg: #8a5a00;
    --status-danger-bg:  #fde7ea;
    --status-danger-fg:  #9b1c2c;
    --status-info-bg:    #e3f1fb;
    --status-info-fg:    #0d4f80;

    /* Motion */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --t-fast: 120ms var(--ease-out);
    --t-base: 180ms var(--ease-out);
    --t-slow: 280ms var(--ease-out);

    /* Refined shadows (more layered than Bootstrap defaults) */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 24px rgba(15, 23, 42, 0.10), 0 4px 8px rgba(15, 23, 42, 0.05);
    --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.14);

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
}

/* --- Dark mode ----------------------------------------------------------- */
[data-theme="dark"] {
    --surface-bg: #0d1426;
    --surface-card: #131c33;
    --surface-muted: #1a2440;
    --surface-hover: #1f2a48;
    --border-soft: #243154;
    --border-strong: #344164;
    --text-strong: #f1f5f9;
    --text-default: #e2e8f0;
    --text-muted: #94a3b8;
    --text-disabled: #64748b;

    --gss-primary: #4d80d6;
    --gss-primary-light: #6a96e0;
    --gss-primary-dark: #2c5db0;
    --gss-primary-rgb: 77, 128, 214;

    --status-success-bg: rgba(22, 110, 63, 0.18);
    --status-success-fg: #6ddc9d;
    --status-warning-bg: rgba(138, 90, 0, 0.20);
    --status-warning-fg: #ffd97a;
    --status-danger-bg:  rgba(155, 28, 44, 0.20);
    --status-danger-fg:  #ff8d96;
    --status-info-bg:    rgba(13, 79, 128, 0.20);
    --status-info-fg:    #6cc4f0;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.55);
}

/* --- Base typography ----------------------------------------------------- */
html { scroll-behavior: smooth; }

body {
    font-family: var(--gss-font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    color: var(--text-default);
    background-color: var(--surface-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01", "ss03";
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
    font-family: var(--gss-font-sans);
    color: var(--text-strong);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: -0.01em;
}
h1, .h1 { font-size: var(--fs-3xl); }
h2, .h2 { font-size: var(--fs-2xl); }
h3, .h3 { font-size: var(--fs-xl); }
h4, .h4 { font-size: var(--fs-lg); }
h5, .h5 { font-size: var(--fs-md); }
h6, .h6 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.04em; }

.text-muted, small.text-muted { color: var(--text-muted) !important; }

a { transition: color var(--t-fast); }

/* --- Focus ring (accessibility) ----------------------------------------- */
*:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--gss-primary-rgb), 0.30);
    border-radius: var(--radius-sm);
}
/* Leaflet manages its own focus state on tiles, controls and the map
   container itself; the global ring above caused visible flicker on every
   pan/zoom. Suppress it inside any leaflet widget. */
.leaflet-container:focus-visible,
.leaflet-container *:focus-visible {
    box-shadow: none !important;
    outline: none !important;
}

/* --- Buttons ------------------------------------------------------------- */
.btn {
    font-weight: var(--fw-medium);
    border-radius: var(--radius-md);
    transition: transform var(--t-fast), box-shadow var(--t-fast),
                background-color var(--t-fast), border-color var(--t-fast),
                color var(--t-fast);
    will-change: transform;
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(0); box-shadow: none; }

.btn-primary {
    background-color: var(--gss-primary);
    border-color: var(--gss-primary);
    color: #fff;
}
.btn-primary:hover {
    background-color: var(--gss-primary-light);
    border-color: var(--gss-primary-light);
    box-shadow: 0 6px 18px rgba(var(--gss-primary-rgb), 0.30);
}

/* --- Cards --------------------------------------------------------------- */
.card {
    background-color: var(--surface-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    transition: transform var(--t-base), box-shadow var(--t-base),
                border-color var(--t-base);
}
.card:hover {
    box-shadow: var(--shadow-md);
}
.card.is-interactive {
    cursor: pointer;
}
.card.is-interactive:hover {
    transform: translateY(-3px);
    border-color: var(--gss-primary-200);
}
.card-header {
    background-color: transparent;
    border-bottom-color: var(--border-soft);
    font-weight: var(--fw-semibold);
    color: var(--text-strong);
}

/* --- Stat cards (dashboard) --------------------------------------------- */
.stat-card {
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: "";
    position: absolute;
    top: 0; right: 0;
    width: 60%; height: 100%;
    background: linear-gradient(135deg, transparent 0%, rgba(var(--gss-primary-rgb), 0.04) 100%);
    pointer-events: none;
}
.stat-card .stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-md);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
}
.stat-card .stat-label {
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stat-card .stat-value {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-bold);
    color: var(--text-strong);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

/* --- Forms --------------------------------------------------------------- */
.form-control, .form-select {
    background-color: var(--surface-card);
    border-color: var(--border-strong);
    color: var(--text-default);
    border-radius: var(--radius-md);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.form-control:focus, .form-select:focus {
    border-color: var(--gss-primary);
    box-shadow: 0 0 0 3px rgba(var(--gss-primary-rgb), 0.18);
    background-color: var(--surface-card);
    color: var(--text-default);
}
.form-label {
    font-weight: var(--fw-medium);
    color: var(--text-strong);
    margin-bottom: var(--space-2);
}

/* --- Tables ------------------------------------------------------------- */
.table {
    color: var(--text-default);
    --bs-table-bg: transparent;
    --bs-table-hover-bg: var(--surface-hover);
    border-color: var(--border-soft);
}
.table > :not(caption) > * > * {
    background-color: transparent;
    border-bottom-color: var(--border-soft);
    color: inherit;
    padding: var(--space-3) var(--space-4);
}
.table thead {
    background-color: var(--surface-muted);
    position: sticky;
    top: 0;
    z-index: 2;
}
.table thead th {
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: var(--fs-xs);
    letter-spacing: 0.06em;
    font-weight: var(--fw-semibold);
    border-bottom: 1px solid var(--border-strong) !important;
}
.table tbody tr {
    transition: background-color var(--t-fast);
}
.table-hover > tbody > tr:hover > * {
    background-color: var(--surface-hover);
}

/* --- Status badges (uniform, soft) -------------------------------------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-3);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    border-radius: var(--radius-full);
    line-height: 1.6;
    background-color: var(--surface-muted);
    color: var(--text-muted);
}
.status-badge::before {
    content: "";
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.85;
}
/* Map domain validation states to colour intentions */
.status-badge.valide,
.status-badge.valide_n1,
.status-badge.valide_n2  { background-color: var(--status-success-bg); color: var(--status-success-fg); }
.status-badge.attente_n1,
.status-badge.attente_n2,
.status-badge.attente_n3 { background-color: var(--status-warning-bg); color: var(--status-warning-fg); }
.status-badge.brouillon  { background-color: var(--surface-muted); color: var(--text-muted); }
.status-badge.rejete     { background-color: var(--status-danger-bg);  color: var(--status-danger-fg); }
/* Alert states */
.status-badge.nouvelle   { background-color: var(--status-info-bg);    color: var(--status-info-fg); }
.status-badge.accusee    { background-color: var(--status-info-bg);    color: var(--status-info-fg); }
.status-badge.en_cours   { background-color: var(--status-warning-bg); color: var(--status-warning-fg); }
.status-badge.resolue    { background-color: var(--status-success-bg); color: var(--status-success-fg); }
.status-badge.cloturee   { background-color: var(--surface-muted);     color: var(--text-muted); }
.status-badge.annulee    { background-color: var(--status-danger-bg);  color: var(--status-danger-fg); }

/* --- Empty state -------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-6);
    color: var(--text-muted);
}
.empty-state__icon {
    width: 96px;
    height: 96px;
    margin: 0 auto var(--space-4);
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gss-primary-50), var(--surface-card));
    color: var(--gss-primary);
    font-size: 3rem;
    box-shadow: var(--shadow-xs);
}
.empty-state__title {
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
    color: var(--text-strong);
    margin-bottom: var(--space-2);
}
.empty-state__message {
    max-width: 32rem;
    margin: 0 auto var(--space-5);
    color: var(--text-muted);
}

/* --- Skeleton loading --------------------------------------------------- */
.skel {
    display: block;
    background: linear-gradient(90deg,
        var(--surface-muted) 0%,
        var(--surface-hover) 50%,
        var(--surface-muted) 100%);
    background-size: 200% 100%;
    animation: skel-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--radius-sm);
    height: 1em;
}
.skel--sm { height: 0.75em; }
.skel--lg { height: 1.5em; }
.skel--xl { height: 2em; }
.skel--circle { border-radius: 50%; aspect-ratio: 1; height: auto; }
@keyframes skel-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Sidebar polish ----------------------------------------------------- */
.sidebar {
    background-color: var(--surface-card);
    border-inline-end: 1px solid var(--border-soft);
}
.sidebar .nav-link {
    color: var(--text-muted);
    border-radius: var(--radius-md);
    margin: 2px var(--space-2);
    padding: var(--space-2) var(--space-3);
    transition: background-color var(--t-fast), color var(--t-fast);
    font-weight: var(--fw-medium);
}
.sidebar .nav-link:hover {
    background-color: var(--surface-hover);
    color: var(--text-strong);
}
.sidebar .nav-link.active {
    background-color: var(--gss-primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(var(--gss-primary-rgb), 0.30);
}
.sidebar .nav-section-title {
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: var(--fw-semibold);
    padding: var(--space-4) var(--space-4) var(--space-2);
    display: block;
}

/* --- Navbar polish ------------------------------------------------------ */
.navbar {
    background-color: var(--surface-card) !important;
    border-bottom: 1px solid var(--border-soft);
    box-shadow: var(--shadow-xs);
}
.navbar-brand {
    font-weight: var(--fw-bold);
    letter-spacing: -0.01em;
}

/* --- Theme toggle ------------------------------------------------------- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-soft);
    background-color: transparent;
    color: var(--text-default);
    transition: background-color var(--t-fast), color var(--t-fast),
                transform var(--t-fast);
}
.theme-toggle:hover {
    background-color: var(--surface-hover);
    color: var(--gss-primary);
    transform: rotate(15deg);
}
.theme-toggle .bi-moon-stars { display: inline; }
.theme-toggle .bi-sun        { display: none; }
[data-theme="dark"] .theme-toggle .bi-moon-stars { display: none; }
[data-theme="dark"] .theme-toggle .bi-sun        { display: inline; }

/* --- Scrollbar (refined) ------------------------------------------------ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
    border: 2px solid var(--surface-bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Page transitions (subtle fade-in) --------------------------------- */
@media (prefers-reduced-motion: no-preference) {
    main { animation: page-in 280ms var(--ease-out); }
    @keyframes page-in {
        from { opacity: 0; transform: translateY(6px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

/* --- Print -------------------------------------------------------------- */
@media print {
    .sidebar, .navbar, .theme-toggle, .page-actions { display: none !important; }
    main { animation: none !important; }
}
