/* ==========================================
   💎 CHÈQUEFLOW V4 - MODERN FINTECH DESIGN
   ========================================== */

:root {
    --bg: #09090b; --card: #141417; --card-hover: #1c1c21;
    --border: rgba(255,255,255,0.06); --border-focus: rgba(255,255,255,0.15);
    --text: #fafafa; --muted: #71717a; --subtle: #a1a1aa;
    --indigo: #6366f1; --indigo-light: #818cf8; --indigo-glow: rgba(99,102,241,0.15);
    --emerald: #10b981; --emerald-bg: rgba(16,185,129,0.1);
    --rose: #f43f5e; --rose-bg: rgba(244,63,94,0.1);
    --amber: #f59e0b; --amber-bg: rgba(245,158,11,0.1);
    --cyan: #06b6d4; --cyan-bg: rgba(6,182,212,0.1);
    --violet: #8b5cf6; --violet-bg: rgba(139,92,246,0.1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 16px; --radius-sm: 10px; --radius-xs: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.25);
}

body[data-theme="light"] {
    --bg: #f8fafc; --card: #ffffff; --card-hover: #f1f5f9;
    --border: rgba(0,0,0,0.08); --border-focus: rgba(0,0,0,0.15);
    --text: #0f172a; --muted: #64748b; --subtle: #475569;
    --indigo-glow: rgba(99,102,241,0.08);
    --emerald-bg: rgba(16,185,129,0.06);
    --rose-bg: rgba(244,63,94,0.06);
    --amber-bg: rgba(245,158,11,0.06);
    --cyan-bg: rgba(6,182,212,0.06);
    --violet-bg: rgba(139,92,246,0.06);
    --shadow: 0 4px 20px rgba(0,0,0,0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font); background: var(--bg); color: var(--text);
    min-height: 100vh; line-height: 1.5; overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
}

/* ===== LOGIN ===== */
.login-screen {
    position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.login-bg {
    position: absolute; inset: 0;
    background: linear-gradient(-45deg, #0f0c29, #302b63, #24243e, #09090b);
    background-size: 400% 400%;
    animation: gradShift 15s ease infinite;
}
body[data-theme="light"] .login-bg {
    background: linear-gradient(-45deg, #e0e7ff, #c7d2fe, #ddd6fe, #ede9fe);
    background-size: 400% 400%;
}
@keyframes gradShift { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }

.login-card {
    position: relative; background: var(--card); border: 1px solid var(--border);
    border-radius: 20px; padding: 2.5rem 2rem; width: 90%; max-width: 400px;
    box-shadow: var(--shadow); animation: cardUp 0.5s cubic-bezier(0.16,1,0.3,1);
}
@keyframes cardUp { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }

.login-brand { text-align: center; margin-bottom: 2rem; }
.brand-icon { font-size: 2.8rem; display: block; margin-bottom: 0.5rem; }
.brand-title {
    font-size: 1.8rem; font-weight: 700; letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--indigo), var(--indigo-light));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.brand-title span { -webkit-text-fill-color: var(--emerald); }
.brand-sub { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }

.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1rem; }
.field label { font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.field input {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-xs);
    padding: 0.7rem 0.85rem; color: var(--text); font-family: var(--font); font-size: 0.9rem;
    outline: none; transition: border-color 0.2s;
}
.field input:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-glow); }
.field-pass { display: flex; align-items: stretch; position: relative; }
.field-pass input { flex: 1; border-radius: var(--radius-xs) 0 0 var(--radius-xs); border-right: none; }
.eye-btn {
    background: var(--bg); border: 1px solid var(--border); border-left: none;
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
    padding: 0 0.75rem; cursor: pointer; font-size: 0.9rem;
    transition: background 0.2s;
}
.eye-btn:hover { background: var(--card-hover); }
.field-error { color: var(--rose); font-size: 0.8rem; text-align: center; min-height: 1.1rem; margin-bottom: 0.5rem; }
.btn-connect {
    width: 100%; padding: 0.75rem; border: none; border-radius: var(--radius-xs);
    background: linear-gradient(135deg, var(--indigo), #8b5cf6);
    color: #fff; font-family: var(--font); font-size: 0.95rem; font-weight: 600;
    cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
}
.btn-connect:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--indigo-glow); }
.login-copy { text-align: center; font-size: 0.7rem; color: var(--muted); margin-top: 1.5rem; opacity: 0.5; }

/* ===== APP LAYOUT ===== */
.app { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
    width: 72px; background: var(--card); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 1.25rem 0.5rem;
    position: fixed; height: 100vh; z-index: 100;
    transition: width 0.25s cubic-bezier(0.4,0,0.2,1); overflow: hidden;
}
.sidebar:hover { width: 240px; }
.sb-brand { display: flex; align-items: center; gap: 0.65rem; padding: 0 0.5rem; margin-bottom: 2rem; white-space: nowrap; }
.sb-icon { font-size: 1.5rem; flex-shrink: 0; }
.sb-name { font-size: 1.2rem; font-weight: 700; opacity: 0; transition: opacity 0.2s; }
.sidebar:hover .sb-name { opacity: 1; }
.sb-nav { display: flex; flex-direction: column; gap: 0.35rem; flex-grow: 1; }
.sb-btn {
    display: flex; align-items: center; gap: 0.75rem;
    background: transparent; border: none; color: var(--muted);
    padding: 0.65rem 0.75rem; border-radius: var(--radius-xs);
    font-size: 0.88rem; font-family: var(--font); cursor: pointer;
    transition: all 0.2s; white-space: nowrap; width: 100%; text-align: left;
}
.sb-btn:hover { color: var(--text); background: var(--card-hover); }
.sb-btn.active { color: var(--indigo); background: var(--indigo-glow); font-weight: 600; }
.sb-emoji { font-size: 1.15rem; flex-shrink: 0; width: 24px; text-align: center; }
.sb-label { opacity: 0; transition: opacity 0.2s; }
.sidebar:hover .sb-label { opacity: 1; }
.sb-bottom { border-top: 1px solid var(--border); padding-top: 1rem; display: flex; flex-direction: column; gap: 0.65rem; }
.sb-user { display: flex; align-items: center; gap: 0.65rem; padding: 0 0.35rem; }
.sb-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, var(--indigo), #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem; color: #fff;
}
.sb-user-info { display: flex; flex-direction: column; opacity: 0; transition: opacity 0.2s; }
.sidebar:hover .sb-user-info { opacity: 1; }
.sb-username { font-weight: 600; font-size: 0.82rem; }
.sb-role { font-size: 0.7rem; color: var(--muted); }
.sb-logout {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--rose-bg); border: 1px solid rgba(244,63,94,0.15);
    color: var(--rose); padding: 0.45rem 0.65rem; border-radius: var(--radius-xs);
    font-size: 0.8rem; font-family: var(--font); cursor: pointer;
    transition: background 0.2s; white-space: nowrap;
}
.sb-logout:hover { background: rgba(244,63,94,0.15); }

/* MAIN */
.main { flex: 1; margin-left: 72px; padding: 1.5rem 2rem; min-height: 100vh; padding-bottom: 5rem; transition: margin-left 0.25s; }

/* HEADER */
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.75rem; flex-wrap: wrap; gap: 1rem; }
.header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.3px; }
.header-sub { color: var(--muted); font-size: 0.85rem; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.theme-toggle {
    width: 38px; height: 38px; border-radius: 50%; background: var(--card);
    border: 1px solid var(--border); font-size: 1rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; position: relative;
}
.theme-toggle:hover { background: var(--card-hover); transform: rotate(20deg); }

/* THEME SELECTOR */
.theme-dropdown {
    position: relative; display: inline-block;
}
.theme-options {
    position: absolute; top: 100%; right: 0; margin-top: 0.5rem;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius-xs); padding: 0.35rem;
    box-shadow: var(--shadow); z-index: 200;
    display: none; min-width: 150px;
    animation: fadeUp 0.2s ease;
}
.theme-options.show { display: block; }
.theme-opt {
    display: flex; align-items: center; gap: 0.5rem;
    width: 100%; background: transparent; border: none;
    padding: 0.5rem 0.65rem; border-radius: 6px;
    color: var(--text); font-family: var(--font);
    font-size: 0.82rem; cursor: pointer; transition: background 0.15s;
}
.theme-opt:hover { background: var(--card-hover); }
.theme-opt.active { color: var(--indigo); font-weight: 600; background: var(--indigo-glow); }

.conn-badge {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.75rem; border-radius: 20px;
    background: var(--card); border: 1px solid var(--border);
    font-size: 0.78rem; color: var(--muted);
}
.conn-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.conn-badge.online .conn-dot { background: var(--emerald); }
.conn-badge.offline .conn-dot { background: var(--rose); }
.btn-refresh {
    background: var(--indigo); color: #fff; border: none;
    padding: 0.5rem 1rem; border-radius: var(--radius-xs);
    font-family: var(--font); font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all 0.15s;
}
.btn-refresh:hover { background: var(--indigo-light); }

/* TABS */
.tab { display: none; animation: fadeUp 0.35s ease; }
.tab.active { display: block; }
@keyframes fadeUp { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.kpi {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
body[data-theme="light"] .kpi { box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.kpi-icon { font-size: 1.4rem; }
.kpi-trend { font-size: 0.75rem; font-weight: 600; padding: 0.15rem 0.45rem; border-radius: 6px; }
.kpi-trend.up { color: var(--emerald); background: var(--emerald-bg); }
.kpi-trend.down { color: var(--rose); background: var(--rose-bg); }
.kpi-val { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 0.15rem; }
.kpi[data-accent="indigo"] .kpi-val { color: var(--indigo-light); }
.kpi[data-accent="rose"] .kpi-val { color: var(--rose); }
.kpi[data-accent="emerald"] .kpi-val { color: var(--emerald); }
.kpi[data-accent="amber"] .kpi-val { color: var(--amber); }
.kpi[data-accent="cyan"] .kpi-val { color: var(--cyan); }
.kpi[data-accent="violet"] .kpi-val { color: var(--violet); }
.kpi-label { font-size: 0.78rem; color: var(--muted); }
.kpi-sub { font-size: 0.7rem; color: var(--subtle); margin-top: 0.15rem; }

/* PANELS */
.panel {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
body[data-theme="light"] .panel { box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.panel-head { margin-bottom: 1rem; }
.panel-head h2 { font-size: 1.05rem; font-weight: 600; }
.panel-head p { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1.2fr; gap: 1rem; margin-bottom: 1rem; }
.chart-wrap { height: 260px; position: relative; }
.chart-wrap-sm { height: 220px; position: relative; }

/* ACTIVITY FEED */
.activity-feed { display: flex; flex-direction: column; gap: 0.5rem; max-height: 260px; overflow-y: auto; }
.feed-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.6rem 0.5rem; border-radius: var(--radius-xs);
    cursor: pointer; transition: background 0.15s;
}
.feed-item:hover { background: var(--card-hover); }
.feed-dot { width: 3px; height: 36px; border-radius: 3px; flex-shrink: 0; }
.feed-dot.client { background: var(--emerald); }
.feed-dot.fournisseur { background: var(--rose); }
.feed-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.feed-name { font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-meta { font-size: 0.72rem; color: var(--muted); }
.feed-amt { font-weight: 700; font-size: 0.88rem; white-space: nowrap; }
.feed-amt.client { color: var(--emerald); }
.feed-amt.fournisseur { color: var(--rose); }

/* ALERT FEED */
.alert-feed { display: flex; flex-direction: column; gap: 0.5rem; max-height: 260px; overflow-y: auto; }
.alert-item {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.55rem; border-radius: var(--radius-xs); border-left: 3px solid var(--amber);
    background: var(--amber-bg); cursor: pointer; transition: transform 0.15s;
}
.alert-item:hover { transform: translateX(3px); }

/* CALENDAR */
.cal-layout { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1rem; }
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.cal-arrow {
    width: 32px; height: 32px; border-radius: 50%; background: var(--card-hover);
    border: 1px solid var(--border); color: var(--text); cursor: pointer;
    font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.cal-arrow:hover { background: var(--indigo-glow); }
.cal-weekdays { display: grid; grid-template-columns: repeat(7,1fr); text-align: center; font-size: 0.78rem; color: var(--muted); font-weight: 600; margin-bottom: 0.5rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 4px; }
.cal-day {
    aspect-ratio: 1; border-radius: var(--radius-xs); display: flex; flex-direction: column;
    align-items: center; justify-content: center; cursor: pointer;
    font-size: 0.85rem; font-weight: 500; transition: all 0.15s;
    border: 1px solid var(--border); gap: 2px;
    background: var(--card);
}
.cal-day:hover { background: var(--card-hover); }
.cal-day.empty { visibility: hidden; }
.cal-day.today { background: var(--indigo-glow); color: var(--indigo); font-weight: 700; border-color: var(--indigo); }
.cal-day.selected { background: var(--indigo) !important; color: #fff !important; font-weight: 700; border-color: var(--indigo) !important; }

/* Calendar Highlights for Active Checks */
.cal-day.has-client {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.5);
    color: #a7f3d0;
}
body[data-theme="light"] .cal-day.has-client {
    background: #e2f9f0;
    border-color: #34d399;
    color: #065f46;
}
.cal-day.has-fournisseur {
    background: rgba(244, 63, 94, 0.18);
    border-color: rgba(244, 63, 94, 0.5);
    color: #fecdd3;
}
body[data-theme="light"] .cal-day.has-fournisseur {
    background: #fff1f2;
    border-color: #fda4af;
    color: #9f1239;
}
.cal-day.has-both {
    background: rgba(99, 102, 241, 0.22);
    border-color: rgba(99, 102, 241, 0.6);
    color: #e0e7ff;
}
body[data-theme="light"] .cal-day.has-both {
    background: #eef2ff;
    border-color: #c7d2fe;
    color: #3730a3;
}

body[data-theme="light"] .cal-day {
    border-color: rgba(0, 0, 0, 0.18);
    background: #ffffff;
}
body[data-theme="light"] .cal-day:hover {
    background: #f1f5f9;
}

.cal-dot { width: 7px; height: 7px; border-radius: 50%; }
.cal-dot.c { background: var(--emerald); }
.cal-dot.f { background: var(--rose); }

/* FLOW BADGES FOR STATS TABLE */
.flow-badge {
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    display: inline-block;
}
.flow-badge.client {
    background: rgba(16, 185, 129, 0.1);
    color: var(--emerald);
}
.flow-badge.fournisseur {
    background: rgba(244, 63, 94, 0.1);
    color: var(--rose);
}

.day-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 380px; overflow-y: auto; }

/* SEGMENTED CONTROL */
.seg-control { display: flex; gap: 0.35rem; overflow-x: auto; padding-bottom: 0.5rem; }
.seg {
    padding: 0.45rem 0.85rem; border-radius: 20px; border: 1px solid var(--border);
    background: transparent; color: var(--muted); font-family: var(--font);
    font-size: 0.8rem; font-weight: 500; cursor: pointer; white-space: nowrap;
    transition: all 0.15s;
}
.seg:hover { color: var(--text); background: var(--card-hover); }
.seg.active { background: var(--indigo); color: #fff; border-color: var(--indigo); }

/* SEARCH & FILTERS */
.filter-panel { margin-bottom: 1rem; }
.search-row { margin-top: 0.75rem; }
.search-box {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-xs); padding: 0.55rem 0.85rem;
}
.search-box input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-family: var(--font); font-size: 0.88rem; }
.adv-filters { margin-top: 0.75rem; }
.adv-filters summary { font-size: 0.82rem; color: var(--muted); cursor: pointer; font-weight: 500; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 0.65rem; margin-top: 0.65rem; }
.fg { display: flex; flex-direction: column; gap: 0.25rem; }
.fg label { font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.fg select, .fg input {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-xs);
    padding: 0.5rem; color: var(--text); font-family: var(--font); font-size: 0.85rem; outline: none;
}
body[data-theme="light"] .fg select, body[data-theme="light"] .fg input,
body[data-theme="light"] .search-box, body[data-theme="light"] .field input,
body[data-theme="light"] .stats-search-box, body[data-theme="light"] .pwd-form input {
    background: #f1f5f9;
}
body[data-theme="light"] select option { background: #fff; }

/* TABLE */
.list-info { margin-bottom: 0.65rem; font-size: 0.82rem; color: var(--muted); }
.table-wrap {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow-x: auto;
}
.tbl { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.tbl th { padding: 0.75rem 1rem; font-weight: 600; color: var(--muted); text-align: left; border-bottom: 1px solid var(--border); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }
.tbl td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr { transition: background 0.15s; }
.tbl tr:hover { background: var(--card-hover); }

/* Status dot */
.st { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; font-weight: 500; }
.st-dot { width: 7px; height: 7px; border-radius: 50%; }
.st-dot.att { background: var(--amber); }
.st-dot.pay { background: var(--emerald); }
.st-dot.imp { background: var(--rose); }
.st-dot.ann { background: var(--muted); }

/* Entity pill */
.ent { padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.72rem; font-weight: 600; }
.ent.fdm { background: rgba(99,102,241,0.1); color: var(--indigo-light); }
.ent.dsg { background: rgba(6,182,212,0.1); color: #22d3ee; }
.ent.personnel { background: rgba(244,63,94,0.1); color: #fb7185; }

.btn-eye { background: transparent; border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 0.3rem 0.55rem; cursor: pointer; font-size: 0.8rem; transition: background 0.15s; }
.btn-eye:hover { background: var(--card-hover); }
.btn-outline { padding: 0.6rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-xs); background: transparent; color: var(--text); font-family: var(--font); font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: background 0.15s; }
.btn-outline:hover { background: var(--card-hover); }

/* MOBILE CARDS */
.card-list { display: none; flex-direction: column; gap: 0.65rem; }
.ck-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem; cursor: pointer;
    transition: transform 0.15s;
}
.ck-card:hover { transform: translateY(-2px); }
.ck-row { display: flex; justify-content: space-between; align-items: center; }

/* DRAWER */
.drawer-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 998;
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.drawer-overlay.active { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; right: -480px; width: 460px; max-width: 95vw;
    height: 100vh; background: var(--card); border-left: 1px solid var(--border);
    z-index: 999; padding: 1.5rem; overflow-y: auto;
    transition: right 0.3s cubic-bezier(0.4,0,0.2,1);
    box-shadow: -8px 0 30px rgba(0,0,0,0.2);
}
body[data-theme="light"] .drawer { box-shadow: -8px 0 30px rgba(0,0,0,0.08); }
.drawer.active { right: 0; }
.drawer-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.drawer-header h2 { font-size: 1.1rem; }
.drawer-close { background: transparent; border: none; color: var(--muted); font-size: 1.5rem; cursor: pointer; }
.drawer-close:hover { color: var(--text); }
.d-row { display: flex; justify-content: space-between; padding: 0.65rem 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.d-label { color: var(--muted); }
.d-val { font-weight: 600; }
.d-section { margin-top: 1.25rem; }
.d-section h3 { font-size: 0.88rem; font-weight: 600; color: var(--indigo); margin-bottom: 0.65rem; }
.d-editor { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
.d-editor select, .d-editor input { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 0.45rem 0.6rem; color: var(--text); font-family: var(--font); font-size: 0.85rem; outline: none; }
.btn-save { padding: 0.45rem 0.85rem; border: none; border-radius: var(--radius-xs); background: var(--emerald); color: #fff; font-family: var(--font); font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: background 0.15s; }
.btn-save:hover { background: #059669; }

/* TOAST */
.toasts { position: fixed; top: 1rem; right: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 9999; pointer-events: none; }
.toast {
    padding: 0.75rem 1.15rem; border-radius: var(--radius-xs);
    font-family: var(--font); font-size: 0.85rem; font-weight: 500;
    pointer-events: auto; box-shadow: var(--shadow);
    animation: tIn 0.3s ease, tOut 0.25s ease forwards; animation-delay: 0s, 3s;
}
.toast.ok { background: var(--emerald); color: #fff; }
.toast.err { background: var(--rose); color: #fff; }
.toast.nfo { background: var(--indigo); color: #fff; }
@keyframes tIn { from{opacity:0;transform:translateX(20px)} to{opacity:1;transform:translateX(0)} }
@keyframes tOut { to{opacity:0;transform:translateX(20px)} }

/* EMPTY */
.empty { text-align: center; padding: 1.5rem; color: var(--muted); font-size: 0.85rem; border: 1px dashed var(--border); border-radius: var(--radius-xs); }

/* S-FORM */
.s-form { display: flex; flex-direction: column; gap: 1rem; }
.s-actions { display: flex; gap: 0.65rem; flex-wrap: wrap; }
.info-rows { display: flex; flex-direction: column; }
.ir { display: flex; justify-content: space-between; padding: 0.55rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.ir span:first-child { color: var(--muted); }

/* STATS SECTION */
.stats-section { margin-top: 1.5rem; }
.stats-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.75rem; }
.stats-header h2 { font-size: 1.15rem; font-weight: 700; }
.stats-search-box {
    display: flex; align-items: center; gap: 0.5rem;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-xs); padding: 0.55rem 0.85rem;
    max-width: 350px; width: 100%;
}
.stats-search-box input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-family: var(--font); font-size: 0.88rem; }
.stats-sort-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stats-sort-btn {
    padding: 0.35rem 0.75rem; border-radius: 20px; border: 1px solid var(--border);
    background: transparent; color: var(--muted); font-family: var(--font);
    font-size: 0.75rem; font-weight: 500; cursor: pointer; transition: all 0.15s;
}
.stats-sort-btn:hover { color: var(--text); background: var(--card-hover); }
.stats-sort-btn.active { background: var(--indigo); color: #fff; border-color: var(--indigo); }
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
}
.stat-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
body[data-theme="light"] .stat-card { box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.stat-card-name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.stat-card-count {
    background: var(--indigo-glow); color: var(--indigo);
    padding: 0.2rem 0.6rem; border-radius: 20px;
    font-size: 0.72rem; font-weight: 600;
}
.stat-card-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.stat-item { display: flex; flex-direction: column; gap: 0.15rem; }
.stat-item-label { font-size: 0.7rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-item-val { font-size: 1rem; font-weight: 700; }
.stat-item-val.pay { color: var(--emerald); }
.stat-item-val.att { color: var(--amber); }
.stat-item-val.imp { color: var(--rose); }
.stat-item-val.total { color: var(--indigo-light); }
.stat-bar { grid-column: 1 / -1; margin-top: 0.5rem; }
.stat-bar-track {
    height: 6px; background: var(--border); border-radius: 3px;
    overflow: hidden; display: flex;
}
.stat-bar-fill-pay { background: var(--emerald); height: 100%; transition: width 0.5s ease; }
.stat-bar-fill-att { background: var(--amber); height: 100%; transition: width 0.5s ease; }
.stat-bar-fill-imp { background: var(--rose); height: 100%; transition: width 0.5s ease; }

/* PASSWORD SECTION */
.pwd-section {
    margin-top: 1rem;
}
.pwd-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.pwd-form { display: flex; flex-direction: column; gap: 0.75rem; }
.pwd-form input {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-xs);
    padding: 0.6rem 0.85rem; color: var(--text); font-family: var(--font); font-size: 0.88rem;
    outline: none; transition: border-color 0.2s; max-width: 350px;
}
.pwd-form input:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-glow); }
.pwd-form .btn-connect { max-width: 200px; }

/* BOTTOM BAR */
.bottom-bar {
    display: none; position: fixed; bottom: 0; left: 0; width: 100%;
    background: var(--card); border-top: 1px solid var(--border);
    justify-content: space-around; padding: 0.4rem 0; z-index: 100;
}
.bb-btn {
    display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
    background: transparent; border: none; color: var(--muted);
    font-family: var(--font); font-size: 0.65rem; cursor: pointer;
    padding: 0.3rem 0.5rem; transition: color 0.15s;
}
.bb-btn span:first-child { font-size: 1.1rem; }
.bb-btn.active { color: var(--indigo); }

/* RESPONSIVE */
@media(max-width:768px) {
    html, body {
        height: 100vh;
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
    .app {
        height: 100vh;
        overflow: hidden;
        flex-direction: column;
    }
    .sidebar { display: none; }
    .bottom-bar { display: flex; z-index: 1001; }
    .main {
        margin-left: 0;
        padding: 1rem;
        padding-bottom: 5.5rem;
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .header { flex-direction: column; align-items: flex-start; }
    .header-actions { width: 100%; justify-content: space-between; }
    .grid-2, .cal-layout { grid-template-columns: 1fr; }
    .kpi-row { grid-template-columns: 1fr 1fr; }
    .table-wrap { display: none; }
    .card-list { display: flex; }
    .drawer { width: 100vw; max-width: 100vw; }
    .stats-grid { grid-template-columns: 1fr; }
    .stats-search-box { max-width: 100%; }
}
@media(max-width:480px) {
    .kpi-row { grid-template-columns: 1fr; }
    .login-card { padding: 1.75rem 1.25rem; }
    .seg-control { gap: 0.25rem; }
    .seg { font-size: 0.72rem; padding: 0.35rem 0.65rem; }
    .stat-card-body { grid-template-columns: 1fr; }
}

/* ===== USER ROLES BADGES ===== */
.role-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 20px;
    padding: 0.15rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 600;
}
.role-badge.badge-admin {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}
.role-badge.badge-gérante {
    background: rgba(6, 182, 212, 0.15);
    color: #22d3ee;
}
.role-badge.badge-katiba-full {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}
.role-badge.badge-katiba-read {
    background: rgba(113, 113, 122, 0.15);
    color: #a1a1aa;
}

/* COMPANY DETAILED BREAKDOWN IN STAT CARDS */
.stat-company-breakdown {
    grid-column: 1 / -1;
    margin-top: 0.75rem;
    border-top: 1px dashed var(--border);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}
.stat-comp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
}
.stat-comp-val {
    font-weight: 600;
    font-size: 0.82rem;
}
.stat-comp-detail {
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: normal;
    margin-left: 0.25rem;
}
body[data-theme="light"] .stat-company-breakdown {
    border-color: rgba(0,0,0,0.06);
}
