/* ============================================================
   FINHUB v3 — Design system épuré
   DM Sans (UI) + JetBrains Mono (data)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:           #0A0A0A;
    --bg-card:      #111111;
    --bg-sidebar:   #0D0D0D;
    --bg-input:     #181818;
    --bg-hover:     #1A1A1A;
    --bg-elevated:  #161616;

    --text:         #D4D4D4;
    --text-muted:   #666666;
    --text-light:   #444444;
    --text-sidebar: #888888;
    --text-white:   #F5F5F5;

    --border:       #222222;
    --border-focus: #BEFF6C;
    --border-hover: #333333;

    --accent:       #BEFF6C;
    --accent-hover: #ADEF58;
    --accent-dim:   rgba(190,255,108,0.08);
    --accent-text:  #0A0A0A;

    --credit:       #4ADE80;
    --debit:        #F87171;
    --warning:      #FBBF24;
    --info:         #60A5FA;

    --radius:       6px;
    --radius-lg:    10px;
    --radius-xl:    14px;
    --shadow:       0 1px 2px rgba(0,0,0,0.4);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg:    0 12px 40px rgba(0,0,0,0.6);

    --sidebar-w:    230px;
    --header-h:     56px;
    --font-ui:      'DM Sans', -apple-system, sans-serif;
    --font-mono:    'JetBrains Mono', 'Fira Code', monospace;

    --transition:   all 0.12s ease;
}

html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
    font-family: var(--font-ui);
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── Layout ─────────────────────────────────────────── */
.sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }
.main { margin-left: var(--sidebar-w); min-height: 100vh; }
.header {
    height: var(--header-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
    background: var(--bg);
    backdrop-filter: blur(8px);
}
.header-title { font-size: 16px; font-weight: 600; color: var(--text-white); }
.page-content { padding: 24px 28px; }
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--text-white); }

/* ─── Sidebar ─────────────────────────────────────────── */
.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.logo-mark {
    width: 30px; height: 30px;
    background: var(--accent);
    color: var(--accent-text);
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius);
    font-weight: 800; font-size: 12px;
    flex-shrink: 0;
}
.logo-text { font-size: 16px; font-weight: 700; color: var(--text-white); letter-spacing: -0.02em; }

/* Space Selector */
.space-selector {
    padding: 10px 10px 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.space-selector-label {
    font-size: 9px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.1em;
    color: var(--text-light);
    margin-bottom: 6px; padding: 0 6px;
}
.space-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius);
    cursor: pointer; transition: var(--transition);
    text-decoration: none;
    color: var(--text-sidebar);
    font-size: 12px; font-weight: 500;
    margin-bottom: 1px;
}
.space-item:hover { background: var(--bg-hover); color: var(--text); }
.space-item.active { background: var(--accent-dim); color: var(--text-white); }
.space-dot {
    width: 8px; height: 8px;
    border-radius: 50%; flex-shrink: 0;
}
.space-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-item .space-balance { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); }

/* Nav */
.sidebar-nav { flex: 1; padding: 8px 8px; overflow-y: auto; scrollbar-width: none; }
.sidebar-nav::-webkit-scrollbar { display: none; }
.nav-divider { height: 1px; background: var(--border); margin: 6px 4px; }
.nav-item {
    display: flex; align-items: center; gap: 9px;
    padding: 7px 10px;
    border-radius: var(--radius);
    color: var(--text-sidebar);
    font-size: 12.5px; font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
    margin-bottom: 1px;
    position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-white); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item.active .nav-icon { opacity: 1; color: var(--accent); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.5; transition: var(--transition); stroke: currentColor; }
.nav-item:hover .nav-icon { opacity: 0.9; }

.sidebar-footer {
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-user {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 4px;
}
.user-avatar {
    width: 28px; height: 28px;
    background: var(--accent);
    color: var(--accent-text);
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-weight: 700; font-size: 11px; flex-shrink: 0;
}
.user-name { font-size: 12px; font-weight: 500; color: var(--text-white); }

/* ─── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text-white); }
.card-body { padding: 18px; }
.card-body.no-pad { padding: 0; }

/* ─── KPI Cards ──────────────────────────────────────────── */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    transition: var(--transition);
}
.kpi-card:hover { border-color: var(--border-hover); }
.kpi-label {
    font-size: 10px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--text-muted); margin-bottom: 6px;
}
.kpi-value {
    font-family: var(--font-mono);
    font-size: 24px; font-weight: 700;
    color: var(--text-white);
    letter-spacing: -0.03em;
    line-height: 1.1;
}
.kpi-value.positive { color: var(--credit); }
.kpi-value.negative { color: var(--debit); }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ─── Unified Filter Bar ─────────────────────────────────── */
.filter-bar {
    display: flex; align-items: center; gap: 8px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
}
.filter-bar .filter-group {
    display: flex; flex-direction: column; gap: 2px;
    min-width: 100px;
}
.filter-bar .filter-label {
    font-size: 10px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--text-muted);
}
.filter-bar .form-input,
.filter-bar .form-select {
    padding: 7px 10px;
    font-size: 12.5px;
    height: 34px;
    border-radius: var(--radius);
}
.filter-search-wrap {
    position: relative; flex: 2; min-width: 200px;
}
.filter-search-wrap svg {
    position: absolute; left: 10px; top: 50%;
    transform: translateY(-50%);
    pointer-events: none; opacity: 0.35;
    width: 14px; height: 14px;
}
.filter-search-wrap .form-input {
    padding-left: 32px;
    font-size: 13px;
}
.filter-divider {
    width: 1px; height: 28px;
    background: var(--border);
    flex-shrink: 0;
}
.filter-amount-row {
    display: flex; align-items: center; gap: 4px;
}
.filter-amount-row .form-input { width: 76px; }
.filter-count {
    font-size: 11px; color: var(--text-muted);
    white-space: nowrap; margin-left: auto;
}

/* ─── Data Tables ────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    padding: 9px 18px;
    font-size: 9.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted);
    text-align: left;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 18px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.08s; }
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table tr[onclick] { cursor: pointer; }

.transaction-label .primary { display: block; font-weight: 500; color: var(--text-white); font-size: 13px; }
.transaction-label .secondary { display: block; font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.amount-cell { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; font-size: 13px; }
.amount-cell.credit { color: var(--credit); }
.amount-cell.debit  { color: var(--debit); }

/* ─── Status Badges ─────────────────────────────────────── */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.status-badge.paid, .status-badge.active  { background: rgba(74,222,128,0.12); color: var(--credit); }
.status-badge.sent, .status-badge.pending { background: rgba(251,191,36,0.12); color: var(--warning); }
.status-badge.overdue   { background: rgba(248,113,113,0.12); color: var(--debit); }
.status-badge.draft     { background: rgba(255,255,255,0.05); color: var(--text-muted); }
.status-badge.signed    { background: rgba(96,165,250,0.12); color: var(--info); }
.status-badge.converted { background: rgba(190,255,108,0.10); color: var(--accent); }
.status-badge.cancelled { background: rgba(255,255,255,0.04); color: var(--text-light); }

/* ─── Tag Pills ─────────────────────────────────────────── */
.tag-pill {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px; font-weight: 600;
    white-space: nowrap;
}

/* ─── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
    display: block; margin-bottom: 5px;
    font-size: 11.5px; font-weight: 500; color: var(--text-muted);
}
.form-input, .form-select, textarea.form-input {
    width: 100%; padding: 9px 12px;
    font-family: var(--font-ui); font-size: 13px;
    color: var(--text-white);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.12s, box-shadow 0.12s;
    appearance: none;
}
.form-input:focus, .form-select:focus, textarea.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(190,255,108,0.08);
}
.form-input::placeholder { color: var(--text-light); }
.form-select option { background: #111; color: var(--text-white); }
select.form-input { cursor: pointer; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px;
    font-family: var(--font-ui); font-size: 12.5px; font-weight: 600;
    border-radius: var(--radius);
    border: none; cursor: pointer;
    transition: var(--transition);
    text-decoration: none; white-space: nowrap;
    line-height: 1;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-text); transform: translateY(-1px); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--border-hover); color: var(--text-white); }
.btn-danger  { background: transparent; color: var(--debit); border: 1px solid rgba(248,113,113,0.25); }
.btn-danger:hover  { background: rgba(248,113,113,0.08); }
.btn-sm { padding: 5px 11px; font-size: 11.5px; }
.btn-full { width: 100%; }

/* ─── Alerts ─────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px; font-weight: 500;
    margin-bottom: 14px;
}
.alert-success { background: rgba(74,222,128,0.08); color: var(--credit); border: 1px solid rgba(74,222,128,0.2); }
.alert-error   { background: rgba(248,113,113,0.08); color: var(--debit); border: 1px solid rgba(248,113,113,0.2); }
.alert-warning { background: rgba(251,191,36,0.08); color: var(--warning); border: 1px solid rgba(251,191,36,0.2); }

/* ─── Empty State ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); font-size: 13px; }
.empty-state p { margin-bottom: 14px; }

/* ─── Auth ───────────────────────────────────────────────── */
.auth-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-container { width: 100%; max-width: 400px; padding: 20px; }
.auth-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: 32px; }
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo .logo-mark { margin: 0 auto 10px; }
.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; color: var(--text-white); }
.auth-subtitle { font-size: 13px; color: var(--text-muted); }
.auth-form { margin-top: 20px; }
.auth-footer-text { text-align: center; margin-top: 18px; font-size: 12px; color: var(--text-muted); }

/* ─── Bank / Upload ──────────────────────────────────────── */
.bank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.bank-button {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer; font-family: var(--font-ui);
    text-align: left; transition: var(--transition); width: 100%; color: var(--text);
}
.bank-button:hover { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(190,255,108,0.06); }
.bank-initial {
    width: 34px; height: 34px;
    background: var(--bg-elevated); border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px; text-transform: uppercase; flex-shrink: 0;
}
.bank-name { font-size: 13px; font-weight: 500; color: var(--text-white); }

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 28px; text-align: center;
    cursor: pointer; transition: var(--transition);
    background: var(--bg-input);
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--accent); background: var(--accent-dim); }
.upload-zone input[type="file"] { display: none; }
.upload-text { font-size: 13px; color: var(--text-muted); }
.upload-text strong { color: var(--accent); }

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
    display: flex; justify-content: center; align-items: center; gap: 8px;
    margin-top: 20px;
}
.pagination-info { font-size: 12px; color: var(--text-muted); padding: 6px 10px; }

/* ─── Utilities ──────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 11.5px; }
.text-white { color: var(--text-white); }
.font-mono  { font-family: var(--font-mono); }

.btn-add-space {
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-hover); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text-muted);
    cursor: pointer; transition: var(--transition);
}
.btn-add-space:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ─── Scrollbar global ───────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main { margin-left: 0; }
    .page-content { padding: 14px; }
    .kpi-row { grid-template-columns: 1fr 1fr; }
    .header { padding: 0 16px; }
}
