/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Qonto-inspired palette */
    --purple: #5c2d91;
    --purple-light: #7b4fad;
    --purple-dark: #3d1a66;
    --purple-subtle: #f3eef8;
    --mint: #1fd1a8;
    --mint-light: #e6faf4;
    --mint-dark: #15a584;
    --peach: #ff8c69;
    --peach-light: #fff0eb;
    --mustard: #f5b731;
    --mustard-light: #fef6e0;

    --black: #1a1a2e;
    --gray-50: #f8f9fc;
    --gray-100: #f1f3f7;
    --gray-200: #e4e7ed;
    --gray-300: #d0d4dc;
    --gray-400: #a0a5b2;
    --gray-500: #6e7382;
    --gray-600: #4a4f5c;
    --gray-700: #33374a;
    --gray-900: #1a1a2e;

    --success: #1fd1a8;
    --warning: #f5b731;
    --danger: #e74c5e;
    --info: #5c9df5;

    --white: #ffffff;
    --shadow-xs: 0 1px 2px rgba(26,26,46,0.04);
    --shadow: 0 1px 3px rgba(26,26,46,0.08), 0 1px 2px rgba(26,26,46,0.04);
    --shadow-md: 0 4px 12px rgba(26,26,46,0.08), 0 2px 4px rgba(26,26,46,0.04);
    --shadow-lg: 0 8px 24px rgba(26,26,46,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    --sidebar-width: 260px;
    --topbar-height: 0px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--purple);
    text-decoration: none;
    transition: color 0.15s;
}

a:hover {
    color: var(--purple-dark);
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--black);
    color: var(--white);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 1.75rem 1.5rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand a {
    color: var(--white);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sidebar-brand a:hover {
    color: var(--white);
    text-decoration: none;
}

.sidebar-brand-icon {
    width: 32px;
    height: 32px;
    background: var(--purple);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

.sidebar-section {
    padding: 0 0.75rem;
    margin-bottom: 0.25rem;
}

.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.35);
    padding: 1rem 0.75rem 0.5rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    color: rgba(255,255,255,0.6);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    margin-bottom: 2px;
}

.sidebar-nav a:hover {
    color: var(--white);
    background: rgba(255,255,255,0.06);
    text-decoration: none;
}

.sidebar-nav a.active {
    color: var(--white);
    background: var(--purple);
}

.sidebar-nav a .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    opacity: 0.8;
    flex-shrink: 0;
}

.sidebar-nav a.active .nav-icon {
    opacity: 1;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.7rem;
    color: rgba(255,255,255,0.3);
    line-height: 1.6;
}

/* ─── Mobile Hamburger ───────────────────────────────────────────────────── */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--black);
    z-index: 110;
    align-items: center;
    padding: 0 1rem;
    gap: 0.75rem;
}

.mobile-topbar .brand-name {
    color: var(--white);
    font-weight: 700;
    font-size: 1rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--white);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}
.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}
.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: -1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    /* Only visible in mobile via media query below */
    display: none;
}

/* ─── Main Content ────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1100px;
    padding: 2rem 2.5rem;
    flex: 1;
    width: 100%;
}

/* ─── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert-success { background: var(--mint-light); color: #0a6e55; border-left: 3px solid var(--mint); }
.alert-error { background: #fef0f1; color: #9b2c3b; border-left: 3px solid var(--danger); }
.alert-warning { background: var(--mustard-light); color: #7a5a0b; border-left: 3px solid var(--mustard); }
.alert-info { background: #eef4fe; color: #2a5fb0; border-left: 3px solid var(--info); }

/* ─── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1 {
    font-size: 1.625rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
}

/* ─── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--gray-200);
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--gray-700);
    letter-spacing: -0.01em;
}

/* ─── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--gray-200);
    padding: 1.25rem 1.5rem;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.15s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--purple);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.35rem;
    font-weight: 500;
}

.stat-card.success::before { background: var(--mint); }
.stat-card.success .stat-value { color: var(--mint-dark); }
.stat-card.warning::before { background: var(--mustard); }
.stat-card.warning .stat-value { color: #9a6e08; }
.stat-card.danger::before { background: var(--danger); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.info::before { background: var(--info); }
.stat-card.info .stat-value { color: var(--info); }

/* ─── Tables ──────────────────────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

thead th {
    background: var(--gray-50);
    padding: 0.7rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
    color: var(--gray-700);
}

tbody tr {
    transition: background 0.1s;
}

tbody tr:hover {
    background: var(--purple-subtle);
}

tbody tr:last-child td {
    border-bottom: none;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }
.text-danger { color: var(--danger) !important; }

/* ─── Mobile Card View for Tables ────────────────────────────────────────── */
.mobile-cards {
    display: none;
}

.mobile-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    font-size: 0.85rem;
}

.mobile-card-row .label {
    color: var(--gray-500);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.mobile-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-100);
    flex-wrap: wrap;
}

/* ─── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-draft { background: var(--gray-100); color: var(--gray-600); }
.badge-finalized { background: #eef0ff; color: #4a3fa0; }
.badge-paid { background: var(--mint-light); color: #0a6e55; }
.badge-cancelled { background: #fef0f1; color: #b53347; }
.badge-overdue { background: var(--mustard-light); color: #7a5a0b; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.5;
    font-family: inherit;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); text-decoration: none; box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); box-shadow: none; }

.btn-primary { background: var(--purple); color: var(--white); }
.btn-primary:hover { background: var(--purple-dark); color: var(--white); }
.btn-success { background: var(--mint); color: var(--white); }
.btn-success:hover { background: var(--mint-dark); color: var(--white); }
.btn-warning { background: var(--mustard); color: var(--white); }
.btn-warning:hover { background: #d9a028; color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #c73d4f; color: var(--white); }
.btn-outline {
    background: var(--white);
    color: var(--gray-700);
    border: 1.5px solid var(--gray-300);
}
.btn-outline:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
    color: var(--gray-900);
}

.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; border-radius: var(--radius-xs); }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ─── Forms ───────────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 0.4rem;
    letter-spacing: -0.01em;
}

.form-group label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--white);
    color: var(--gray-900);
}

.form-control:focus {
    outline: none;
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(92, 45, 145, 0.1);
}

.form-control::placeholder {
    color: var(--gray-400);
}

select.form-control {
    appearance: auto;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-inline {
    display: flex;
    gap: 1rem;
    align-items: end;
}

/* ─── Invoice Lines Table ─────────────────────────────────────────────────── */
.invoice-lines-table {
    width: 100%;
    margin-top: 1rem;
}

.invoice-lines-table th {
    font-size: 0.7rem;
    padding: 0.5rem;
}

.invoice-lines-table td {
    padding: 0.35rem 0.5rem;
    vertical-align: top;
}

.invoice-lines-table .form-control {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.invoice-lines-table input[type="number"] {
    width: 100px;
}

.line-description { min-width: 200px; }

/* ─── Invoice View ────────────────────────────────────────────────────────── */
.invoice-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.invoice-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 1rem;
    font-size: 0.875rem;
}

.invoice-meta dt {
    font-weight: 600;
    color: var(--gray-500);
}

.invoice-meta dd {
    color: var(--gray-900);
}

.invoice-totals {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
}

.invoice-totals table {
    width: auto;
    min-width: 300px;
}

.invoice-totals td {
    padding: 0.5rem 1rem;
}

.invoice-totals .total-ttc {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--purple);
    border-top: 2px solid var(--gray-900);
}

.legal-mentions {
    margin-top: 2rem;
    padding: 1.25rem;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--gray-500);
    line-height: 1.8;
    border: 1px solid var(--gray-200);
}

.hash-info {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--gray-500);
    word-break: break-all;
    border: 1px solid var(--gray-200);
}

/* ─── Verification ────────────────────────────────────────────────────────── */
.verify-valid {
    color: var(--mint-dark);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.verify-invalid {
    color: var(--danger);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

/* ─── Filter Tabs ─────────────────────────────────────────────────────────── */
.filter-tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1.5rem;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    padding: 0.3rem;
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
}

.filter-tabs a {
    padding: 0.45rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-xs);
    color: var(--gray-500);
    transition: all 0.15s;
    white-space: nowrap;
}

.filter-tabs a:hover {
    color: var(--gray-700);
    text-decoration: none;
}

.filter-tabs a.active {
    background: var(--white);
    color: var(--purple);
    box-shadow: var(--shadow-xs);
}

/* ─── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-400);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.empty-state a {
    font-weight: 600;
}

/* ─── Charts Grid ─────────────────────────────────────────────────────────── */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.chart-full {
    grid-column: 1 / -1;
}

/* ─── Footer ──────────────────────────────────────────────────────────────── */
.footer {
    padding: 1.25rem 2.5rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--gray-400);
    border-top: 1px solid var(--gray-200);
}

/* ─── Responsive: Tablet ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }
    .main-content {
        margin-left: 220px;
    }
    .container {
        padding: 1.5rem;
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

/* ─── Responsive: Mobile ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root {
        --topbar-height: 56px;
    }

    .mobile-topbar {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        top: 56px;
        padding-top: 0;
        min-height: calc(100vh - 56px);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
        z-index: 95;
        pointer-events: auto;
        opacity: 1;
    }

    .main-content {
        margin-left: 0;
        padding-top: var(--topbar-height);
    }

    .container {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .page-header h1 {
        font-size: 1.35rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    .invoice-header {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .invoice-totals {
        justify-content: stretch;
    }

    .invoice-totals table {
        width: 100%;
        min-width: auto;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .btn-group {
        width: 100%;
    }

    .btn-group .btn {
        flex: 1;
        min-width: 0;
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
    }

    .card {
        padding: 1rem;
        border-radius: var(--radius-sm);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .filter-tabs {
        width: 100%;
    }

    .footer {
        padding: 1rem;
        font-size: 0.7rem;
    }

    .legal-mentions {
        font-size: 0.75rem;
        padding: 1rem;
    }

    /* Responsive grids in forms */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Flex items in forms */
    [style*="display: flex"][style*="gap: 2rem"] {
        flex-direction: column;
        gap: 0.75rem !important;
    }
}

/* ─── Responsive: Small Mobile ───────────────────────────────────────────── */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .page-header h1 {
        font-size: 1.15rem;
    }

    .btn {
        font-size: 0.8rem;
        padding: 0.5rem 1rem;
    }

    .badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.5rem;
    }

    thead th {
        font-size: 0.65rem;
        padding: 0.5rem 0.5rem;
    }

    tbody td {
        padding: 0.65rem 0.5rem;
        font-size: 0.8rem;
    }
}

/* ─── PWA standalone mode ────────────────────────────────────────────────── */
@media (display-mode: standalone) {
    .mobile-topbar {
        padding-top: env(safe-area-inset-top);
        height: calc(56px + env(safe-area-inset-top));
    }

    .main-content {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
