/* ==========================================
   CFC DASHBOARD v2.1 — IA'Optim
   Aesthetic: Refined modern · Violet anchor
   ========================================== */
*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}

:root {
    --purple: #7B3FF2;
    --purple-light: #9B6BFF;
    --purple-bg: #F5F0FF;
    --blue: #4A90E2;
    --green: #34C759;
    --orange: #FF9500;
    --red: #FF3B30;
    --text: #1A1A2E;
    --text2: #555770;
    --text3: #8E8EA9;
    --bg: #FAFAFC;
    --card: #FFFFFF;
    --border: #EEEEF2;
    --border2: #DDDDE5;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 24px;
    --shadow: 0 1px 3px rgba(26,26,46,0.04), 0 1px 2px rgba(26,26,46,0.02);
    --shadow-md: 0 4px 16px rgba(26,26,46,0.06);
    --shadow-lg: 0 8px 32px rgba(26,26,46,0.08);
    --shadow-purple: 0 4px 14px rgba(123,63,242,0.2);
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== WATERMARK ===== */
.watermark {
    position: fixed;
    bottom: 60px; right: -40px;
    opacity: 0.03;
    pointer-events: none;
    z-index: 0;
}
.watermark img { width: 400px; height: 400px; object-fit: contain; }

/* ===== HEADER ===== */
.header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}
.h-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
    height: 64px;
    display: flex; align-items: center; justify-content: space-between;
}
.logo-link {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none;
}
.logo-img { width: 42px; height: 42px; object-fit: contain; }
.logo-text-group { display: flex; flex-direction: column; }
.logo-title { font-weight: 700; font-size: 1.15rem; color: var(--purple); letter-spacing: -0.03em; line-height: 1.1; }
.logo-sub { font-size: 0.6rem; color: var(--text3); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }

.nav { display: flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: var(--r-md); }
.nav-link {
    font-weight: 600; font-size: 0.8rem;
    color: var(--text2); padding: 8px 14px;
    border-radius: var(--r-sm);
    text-decoration: none;
    transition: all 0.2s;
}
.nav-link:hover { color: var(--purple); background: var(--purple-bg); }
.nav-link.active { color: var(--purple); background: var(--card); box-shadow: var(--shadow); }

.user-zone { position: relative; }
.user-avatar {
    width: 36px; height: 36px;
    border-radius: var(--r-sm);
    background: linear-gradient(135deg, var(--purple), var(--purple-light));
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem;
    cursor: pointer; transition: transform 0.15s;
}
.user-avatar:hover { transform: scale(1.06); }

.dropdown {
    position: absolute; top: calc(100% + 8px); right: 0;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
    min-width: 260px; display: none; overflow: hidden; z-index: 200;
}
.dropdown.show { display: block; animation: ddIn 0.15s ease; }
@keyframes ddIn { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }
.dd-header { padding: 14px 16px; background: var(--bg); }
.dd-name { font-weight: 700; font-size: 0.9rem; }
.dd-email { font-size: 0.78rem; color: var(--text3); margin-top: 1px; }
.dd-role { font-size: 0.7rem; color: var(--purple); font-weight: 700; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.dd-sep { height: 1px; background: var(--border); }
.dd-item { padding: 10px 16px; font-size: 0.85rem; cursor: pointer; transition: background 0.12s; }
.dd-item:hover { background: var(--bg); }
.dd-logout { color: var(--red); }
.dd-logout:hover { background: #FFF5F5; }

/* ===== MAIN ===== */
.main {
    max-width: 1440px; margin: 0 auto;
    padding: 20px 24px;
    position: relative; z-index: 1;
    min-height: calc(100vh - 64px - 60px);
}

.pg-head { margin-bottom: 20px; }
.pg-head h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.03em; }
.pg-head p { color: var(--text3); font-size: 0.88rem; margin-top: 2px; }
.pg-date { font-size: 0.88rem; color: var(--text3); }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: 18px;
    display: flex; align-items: center; gap: 14px;
    transition: all 0.2s;
}
.stat-card:hover { border-color: var(--purple); box-shadow: var(--shadow-md); }
.stat-card.clickable { cursor: pointer; }
.stat-icon {
    width: 42px; height: 42px; border-radius: var(--r-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex-shrink: 0;
}
.stat-icon.purple { background: #F0EAFF; }
.stat-icon.blue { background: #E8F1FC; }
.stat-icon.green { background: #E6F9ED; }
.stat-icon.orange { background: #FFF3E0; }
.stat-content { min-width: 0; }
.stat-label { font-size: 0.65rem; font-weight: 700; color: var(--text3); letter-spacing: 0.08em; text-transform: uppercase; }
.stat-number { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; margin-top: 2px; }
.stat-number.ca { font-size: 1.1rem; color: var(--purple); }

/* ===== CARD ===== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px;
    margin-bottom: 20px;
}
.card-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 0.95rem; font-weight: 700; }

/* ===== FILTERS ===== */
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.f-input {
    padding: 8px 12px; border: 1.5px solid var(--border2);
    border-radius: var(--r-sm); font-family: var(--font);
    font-size: 0.85rem; color: var(--text);
    background: var(--card); outline: none;
    transition: border-color 0.2s;
}
.f-input:focus { border-color: var(--purple); }
.f-search { flex: 1; min-width: 180px; }
.f-select { min-width: 140px; }

/* ===== TABLE ===== */
.docs-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.docs-table thead th {
    text-align: left; padding: 8px 10px;
    font-size: 0.72rem; font-weight: 700; color: var(--text3);
    text-transform: uppercase; letter-spacing: 0.06em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.docs-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
}
.docs-table tbody tr:hover { background: var(--purple-bg); }
.docs-table tbody tr.row-new { background: #FAFAFF; }
.docs-table tbody td { padding: 10px 10px; vertical-align: middle; }
.docs-table.mini { font-size: 0.82rem; }
.docs-table.mini td { padding: 8px 10px; }

.type-badge {
    display: inline-block; padding: 2px 8px;
    border-radius: 4px; color: white;
    font-size: 0.7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.type-dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; margin-right: 6px; vertical-align: middle;
}
.ref-cell { font-family: var(--mono); font-size: 0.82rem; font-weight: 500; }
.amount-cell { font-weight: 700; white-space: nowrap; }
.date-cell { color: var(--text3); white-space: nowrap; }
.center { text-align: center; }
.light { color: var(--text2); }
.actions-cell { white-space: nowrap; }

.status-badge {
    display: inline-block; padding: 2px 8px;
    border-radius: 4px; font-size: 0.75rem; font-weight: 600;
    white-space: nowrap;
}
.status-sent { background: #E6F9ED; color: #1B8C3C; }
.status-pending { background: #FFF3E0; color: #CC7700; }
.status-cancelled { background: #FFE8E6; color: #CC2200; }
.status-draft { background: var(--bg); color: var(--text3); }
.status-invoiced { background: var(--purple-bg); color: var(--purple); }

.act-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 6px;
    border: none; background: var(--bg); cursor: pointer;
    font-size: 0.85rem; transition: all 0.15s;
    text-decoration: none; color: var(--text);
}
.act-btn:hover { background: var(--purple-bg); }
.act-btn.danger:hover { background: #FFE8E6; }

.empty-msg { text-align: center; padding: 24px; color: var(--text3); font-size: 0.88rem; }

/* ===== COUNTERS ===== */
.counters-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.counter-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: 20px;
    border-top: 3px solid var(--purple);
}
.counter-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.counter-icon {
    width: 36px; height: 36px; border-radius: var(--r-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
}
.counter-label { font-weight: 700; font-size: 0.9rem; }
.counter-number { font-family: var(--mono); font-size: 1.6rem; font-weight: 700; color: var(--purple); letter-spacing: -0.02em; }
.counter-sub { font-size: 0.78rem; color: var(--text3); margin-top: 4px; margin-bottom: 10px; }

/* ===== CLIENTS ===== */
.client-row {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 16px;
    border: 1px solid var(--border); border-radius: var(--r-md);
    margin-bottom: 8px;
    transition: all 0.15s;
    background: var(--card);
}
.client-row:hover { border-color: var(--purple); box-shadow: var(--shadow); }
.client-main { flex: 1; min-width: 0; }
.client-name { font-weight: 700; font-size: 0.95rem; }
.client-original { font-size: 0.78rem; color: var(--text3); }
.client-meta { display: flex; gap: 16px; font-size: 0.82rem; color: var(--text2); margin-top: 2px; flex-wrap: wrap; }
.client-counts { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.cc { font-size: 0.82rem; font-weight: 600; }
.cc-total {
    font-weight: 700; font-size: 0.82rem; color: var(--purple);
    background: var(--purple-bg); padding: 2px 8px; border-radius: 4px;
}
.client-btns { display: flex; gap: 6px; flex-shrink: 0; }

/* Suggested clients */
.modal-desc { font-size: 0.88rem; color: var(--text2); margin-bottom: 12px; }
.suggested-list { display: flex; flex-direction: column; gap: 8px; }
.suggest-card {
    padding: 12px 14px; border: 1.5px solid var(--border);
    border-radius: var(--r-md); cursor: pointer;
    transition: all 0.15s;
}
.suggest-card:hover { border-color: var(--purple); background: var(--purple-bg); }
.suggest-name { font-weight: 700; font-size: 0.92rem; margin-bottom: 2px; }
.suggest-meta { font-size: 0.78rem; color: var(--text3); }
.suggest-counts { font-size: 0.82rem; color: var(--text2); margin-top: 4px; }
.modal-sep { height: 1px; background: var(--border); margin: 16px 0; }

/* ===== BUTTONS ===== */
.btn-primary-sm {
    padding: 8px 16px; border-radius: var(--r-sm);
    background: var(--purple); color: white;
    font-family: var(--font); font-weight: 600; font-size: 0.82rem;
    border: none; cursor: pointer; transition: all 0.2s;
}
.btn-primary-sm:hover { background: #6A30D9; box-shadow: var(--shadow-purple); }
.btn-sm-fill {
    padding: 6px 12px; border-radius: var(--r-sm);
    background: var(--purple); color: white;
    font-family: var(--font); font-weight: 600; font-size: 0.78rem;
    border: none; cursor: pointer;
}
.btn-sm-fill:hover { background: #6A30D9; }
.btn-sm-outline {
    padding: 6px 12px; border-radius: var(--r-sm);
    background: none; color: var(--text);
    font-family: var(--font); font-weight: 600; font-size: 0.78rem;
    border: 1.5px solid var(--border2); cursor: pointer;
}
.btn-sm-outline:hover { border-color: var(--purple); color: var(--purple); }
.btn-sm-danger {
    padding: 6px 12px; border-radius: var(--r-sm);
    background: #FFF5F5; color: var(--red);
    font-family: var(--font); font-weight: 600; font-size: 0.78rem;
    border: none; cursor: pointer;
}
.btn-sm-danger:hover { background: var(--red); color: white; }
.btn-link { background: none; border: none; color: var(--purple); font-family: var(--font); font-weight: 600; font-size: 0.82rem; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.btn-ghost {
    padding: 8px 12px; border-radius: var(--r-sm);
    background: none; border: 1.5px solid var(--border2);
    font-family: var(--font); font-weight: 600; font-size: 0.82rem;
    color: var(--text2); cursor: pointer;
}
.btn-ghost:hover { border-color: var(--red); color: var(--red); }
.btn-accent {
    padding: 8px 16px; border-radius: var(--r-sm);
    background: var(--purple); color: white;
    font-family: var(--font); font-weight: 600; font-size: 0.82rem;
    border: none; cursor: pointer;
}
.btn-accent:hover { background: #6A30D9; }
.btn-cancel {
    padding: 8px 16px; border-radius: var(--r-sm);
    background: var(--bg); border: 1px solid var(--border2);
    font-family: var(--font); font-weight: 600; font-size: 0.82rem;
    color: var(--text2); cursor: pointer;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(26,26,46,0.3);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    z-index: 500; padding: 20px;
}
.modal {
    background: var(--card); border-radius: var(--r-xl);
    width: 100%; max-width: 460px;
    box-shadow: var(--shadow-lg);
    animation: mIn 0.2s ease;
    max-height: 90vh; overflow-y: auto;
}
.modal-lg { max-width: 600px; }
@keyframes mIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.m-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.m-head h3 { font-size: 1rem; font-weight: 700; }
.m-close {
    width: 28px; height: 28px; border-radius: 6px;
    border: none; background: var(--bg); cursor: pointer;
    font-size: 0.85rem; display: flex; align-items: center; justify-content: center;
}
.m-close:hover { background: var(--border); }
.m-body { padding: 20px; }
.m-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.m-sep { height: 1px; background: var(--border); margin: 14px 0; }
.form-g { margin-bottom: 14px; }
.form-g label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.form-g small { font-size: 0.72rem; color: var(--text3); margin-top: 3px; display: block; }
.form-g .f-input { width: 100%; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.profile-info-row { display: flex; justify-content: space-between; padding: 8px 0; }
.pi-label { font-size: 0.82rem; color: var(--text3); }
.pi-value { font-size: 0.82rem; font-weight: 600; }

/* User management */
.um-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.um-count { font-size: 0.85rem; color: var(--text3); font-weight: 600; }
.user-row {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--r-sm); margin-bottom: 6px;
}
.ur-info { flex: 1; min-width: 0; }
.ur-name { font-weight: 600; font-size: 0.85rem; }
.ur-email { font-size: 0.75rem; color: var(--text3); }
.role-sel {
    padding: 5px 8px; border-radius: 6px; border: 1.5px solid var(--border2);
    font-family: var(--font); font-size: 0.78rem; background: var(--card);
}

/* ===== FOOTER ===== */
.footer {
    display: flex; justify-content: space-between;
    max-width: 1440px; margin: 0 auto;
    padding: 20px 24px; font-size: 0.78rem; color: var(--text3);
}
.footer strong { color: var(--purple); }

/* ===== TOAST ===== */
.toast {
    position: fixed; bottom: 20px; right: 20px;
    padding: 12px 20px; border-radius: var(--r-md);
    font-size: 0.85rem; font-weight: 600; color: white;
    box-shadow: var(--shadow-lg);
    z-index: 600; opacity: 0; transform: translateY(16px);
    transition: all 0.25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.t-success { background: var(--green); }
.t-error { background: var(--red); }
.t-warning { background: var(--orange); }
.t-info { background: var(--blue); }

/* ===== LOADING ===== */
.loading {
    position: fixed; inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 400;
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--purple);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(3,1fr); } .counters-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 768px) {
    .h-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px; }
    .nav { overflow-x: auto; }
    .main { padding: 14px 16px; }
    .stats-grid { grid-template-columns: repeat(2,1fr); }
    .counters-grid { grid-template-columns: 1fr; }
    .filters { flex-direction: column; }
    .f-search { min-width: auto; width: 100%; }
    .client-row { flex-direction: column; align-items: stretch; }
    .client-counts { justify-content: flex-start; }
    .form-row { grid-template-columns: 1fr; }
    .docs-table { font-size: 0.78rem; }
    .docs-table thead th { font-size: 0.65rem; }
    .footer { flex-direction: column; gap: 4px; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}
