/* ==========================================================================
   Kafando Services — Design system unifié
   Variables, mode sombre, composants partagés.
   ========================================================================== */

/* --- Tokens : palette, espacements, ombres, rayons --- */
:root {
    --primary: #1e3c72;
    --primary-light: #2a4f8c;
    --primary-soft: #eef2ff;
    --success: #10b981;
    --success-dark: #059669;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --info: #3b82f6;
    --warning: #f59e0b;

    --bg: #f8fafc;
    --card-bg: #ffffff;
    --surface: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #475569;
    --text-soft: #64748b;
    --gray: #94a3b8;

    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
    --shadow-hover: 0 20px 30px -10px rgba(0, 0, 0, 0.1);

    --radius: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --radius-pill: 999px;
}

/* --- Mode sombre : appliqué sur <html.dark> via le script bootstrap --- */
html.dark {
    --primary: #3b5e9c;
    --primary-light: #4f74b3;
    --primary-soft: #1e2a47;
    --bg: #0f172a;
    --card-bg: #1e293b;
    --surface: #334155;
    --border: #334155;
    --text: #f8fafc;
    --text-muted: #cbd5e1;
    --text-soft: #94a3b8;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 20px 30px -10px rgba(0, 0, 0, 0.5);
}

/* --- Reset minimal --- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; }

/* --- Layout --- */
.app-body { padding: 24px; padding-bottom: 90px; }
.container { max-width: 1200px; margin: 0 auto; }
.container-md { max-width: 800px; margin: 0 auto; }
.container-sm { max-width: 500px; margin: 0 auto; }

/* --- Carte de base --- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    transition: box-shadow 0.3s ease;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card-sm { padding: 20px; border-radius: var(--radius-md); }

/* --- Page « écran centré » (login / profile / import) --- */
.fullpage {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.fullpage--gradient { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.fullpage .auth-card {
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    padding: 48px 40px;
    border-radius: var(--radius);
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 440px;
    text-align: center;
    animation: fadeIn 0.5s ease-out;
}

/* --- Titres --- */
.page-title {
    color: var(--primary);
    font-size: 1.8rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}
.h-display {
    color: var(--primary);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.subtitle { color: var(--text-soft); font-weight: 500; }

/* --- Lien retour --- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-soft);
    font-weight: 500;
    margin-bottom: 24px;
    transition: color 0.2s;
}
.back-link:hover { color: var(--primary); }
.back-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 4px; border-radius: 4px; }

/* --- Formulaires : inputs, selects, labels --- */
label {
    display: block;
    text-align: left;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.input,
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="month"],
input[type="date"],
input[type="search"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    background: var(--card-bg);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
input:focus,
select:focus,
textarea:focus,
.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(30, 60, 114, 0.12);
}
html.dark input,
html.dark select,
html.dark textarea { background: var(--bg); }

input[type="file"] {
    border-style: dashed;
    background: var(--surface);
    cursor: pointer;
}

/* Variante « pill » utilisée pour login & profil */
.input-pill,
.input-pill input { border-radius: var(--radius-pill) !important; padding-left: 48px; }
.input-icon { position: relative; margin-bottom: 16px; }
.input-icon > i {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray);
    font-size: 1.05rem;
    pointer-events: none;
}

/* --- Boutons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s, color 0.2s;
    white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; }
.btn-lg { padding: 16px 28px; font-size: 1.05rem; }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; font-weight: 500; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 15px rgba(30, 60, 114, 0.18);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-light); transform: translateY(-2px); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dark); transform: translateY(-2px); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); transform: translateY(-2px); }

.btn-info { background: var(--info); color: #fff; }
.btn-info:hover:not(:disabled) { background: #2563eb; transform: translateY(-2px); }

.btn-soft {
    background: var(--surface);
    color: var(--text);
}
.btn-soft:hover:not(:disabled) { background: var(--primary); color: #fff; transform: translateY(-2px); }

.btn-ghost-danger {
    background: #fee2e2;
    color: var(--danger);
}
html.dark .btn-ghost-danger { background: #450a0a; color: #fca5a5; }
.btn-ghost-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-neutral { background: var(--surface); color: var(--text-muted); }
.badge-primary { background: var(--primary); color: #fff; }

html.dark .badge-success { background: #064e3b; color: #34d399; }
html.dark .badge-danger  { background: #7f1d1d; color: #fca5a5; }
html.dark .badge-info    { background: #1e3a8a; color: #93c5fd; }
html.dark .badge-warning { background: #78350f; color: #fcd34d; }

/* --- Messages flash --- */
.flash {
    padding: 14px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    animation: fadeInDown 0.3s ease;
}
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
html.dark .flash-success { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
html.dark .flash-danger  { background: #7f1d1d; color: #fca5a5; border-color: #991b1b; }
html.dark .flash-warning { background: #78350f; color: #fcd34d; border-color: #92400e; }

/* --- Top nav (pages connectées) --- */
.top-nav {
    background: var(--card-bg);
    padding: 16px 24px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.top-nav__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
}
.top-nav__brand i { font-size: 1.3rem; }
.top-nav__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.top-nav__actions a,
.top-nav__actions button {
    text-decoration: none;
    color: var(--text);
    font-size: 0.95rem;
    padding: 10px 18px;
    border-radius: var(--radius-pill);
    background: var(--surface);
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}
.top-nav__actions a:hover,
.top-nav__actions button:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-2px);
}
.top-nav__actions a:focus-visible,
.top-nav__actions button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}
.top-nav__actions .logout {
    background: #fee2e2;
    color: var(--danger);
    padding: 10px 14px;
}
html.dark .top-nav__actions .logout { background: #450a0a; color: #fca5a5; }
.top-nav__actions .logout:hover { background: var(--danger); color: #fff; }

/* --- Dropdown (menu Paramètres) --- */
.dropdown { position: relative; display: inline-block; }
.dropdown__menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 10px;
    min-width: 220px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    z-index: 100;
}
html.dark .dropdown__menu { box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4); }
.dropdown__menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
    background: transparent;
    border-radius: 0;
}
.dropdown__menu a:hover {
    background: var(--surface);
    color: var(--primary);
    padding-left: 24px;
}
.dropdown.is-open .dropdown__menu {
    display: block;
    animation: fadeInDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Bottom nav (mobile) --- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    box-shadow: 0 -10px 20px rgba(0, 0, 0, 0.05);
    z-index: 1000;
    padding: 12px 10px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid var(--border);
}
html.dark .bottom-nav { box-shadow: 0 -10px 20px rgba(0, 0, 0, 0.4); }
.bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--gray);
    font-size: 0.75rem;
    font-weight: 600;
    flex: 1;
    text-align: center;
    transition: color 0.2s;
}
.bottom-nav a i { font-size: 1.3rem; transition: transform 0.2s; margin-bottom: 2px; }
.bottom-nav a.is-active { color: var(--primary); }
.bottom-nav a.is-active i { transform: scale(1.1); }
.bottom-nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px; }

/* --- Tableaux --- */
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th,
.table td { padding: 14px 15px; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
    background: var(--surface);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.5px;
}
.table tr:hover td { background: var(--surface); }

/* --- Animations partagées --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Utilitaires --- */
.text-muted { color: var(--text-soft); }
.text-soft { color: var(--gray); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 12px; }
.gap-3 { gap: 16px; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-body { padding: 16px; padding-bottom: 90px; }
    .desktop-only { display: none !important; }
    .bottom-nav { display: flex; }
}
