:root {
    --color-bg: #f8f9fb;
    --color-surface: #ffffff;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-muted: #6b7280;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --sidebar-width: 240px;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 1.5rem 1rem;
    flex-shrink: 0;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 0 0.5rem;
}

.sidebar__logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--color-primary);
    color: #fff;
    border-radius: 8px;
    font-weight: 700;
    font-size: 16px;
}

.sidebar__title {
    font-weight: 600;
    font-size: 16px;
}

.sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar__link {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    color: var(--color-text-muted);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.sidebar__link:hover {
    background: var(--color-bg);
    color: var(--color-text);
    text-decoration: none;
}

.sidebar__link--active {
    background: #eff6ff;
    color: var(--color-primary);
    font-weight: 500;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.main__header {
    padding: 1.5rem 2rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.main__header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.main__content {
    padding: 2rem;
    flex: 1;
}

.welcome {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 640px;
}

.welcome__text {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

.welcome__subtext {
    margin: 0;
    color: var(--color-text-muted);
}

.error-page {
    text-align: center;
    padding: 4rem 2rem;
}

.error-page h1 {
    font-size: 4rem;
    margin: 0 0 1rem;
    color: var(--color-text-muted);
}

.error-page p {
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
}

/* Authentification */
body.guest {
    background: linear-gradient(135deg, #eff6ff 0%, var(--color-bg) 50%, #f0fdf4 100%);
}

.guest__wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.guest__card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.guest__brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.guest__title {
    font-weight: 600;
    font-size: 1.25rem;
}

/* Formulaires */
.form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form__group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.form__label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text);
}

.form__input {
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form__input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form__hint {
    margin: 0;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.form__actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

/* Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover {
    text-decoration: none;
}

.btn--primary {
    background: var(--color-primary);
    color: #fff;
}

.btn--primary:hover {
    background: var(--color-primary-hover);
    color: #fff;
}

.btn--ghost {
    background: transparent;
    color: var(--color-text-muted);
    border-color: var(--color-border);
}

.btn--ghost:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.btn--block {
    width: 100%;
}

.btn--sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Alertes */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert--success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert--error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* En-tête utilisateur */
.main__header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-menu__name {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.user-menu__logout {
    margin: 0;
}

.auth-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 480px;
}

/* Dashboard */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1200px;
}

.dashboard__header {
    margin-bottom: 0.25rem;
}

.dashboard__secondary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.kpi-section {
    margin: 0;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.kpi-card {
    display: flex;
    gap: 0.875rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 1.25rem;
    transition: box-shadow 0.15s ease;
}

.kpi-card:hover {
    box-shadow: 0 4px 12px rgba(17, 24, 39, 0.06);
}

.kpi-card--highlight {
    border-color: #bfdbfe;
    background: linear-gradient(135deg, #ffffff 0%, #f0f7ff 100%);
}

.kpi-card__icon {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #eff6ff;
    color: var(--color-primary);
    flex-shrink: 0;
    padding: 8px;
}

.kpi-card__icon svg {
    width: 18px;
    height: 18px;
}

.kpi-card__icon--vat {
    background: #f0fdf4;
    color: #166534;
}

.kpi-card__icon--expense {
    background: #fef3c7;
    color: #b45309;
}

.kpi-card__icon--cash {
    background: #ede9fe;
    color: #6d28d9;
}

.kpi-card__icon--alert {
    background: #fee2e2;
    color: #b91c1c;
}

.kpi-card__body {
    min-width: 0;
}

.kpi-card__label {
    margin: 0 0 0.25rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.kpi-card__value {
    margin: 0 0 0.25rem;
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.kpi-card__value--count {
    font-size: 1.75rem;
}

.kpi-card__value--due {
    color: #b45309;
}

.kpi-card__value--credit {
    color: #166534;
}

.kpi-card__value--positive {
    color: #166534;
}

.kpi-card__value--negative {
    color: #b91c1c;
}

.kpi-card__hint {
    margin: 0;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.info-card {
    display: flex;
    gap: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 1.25rem;
}

.info-card__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #eff6ff;
    color: var(--color-primary);
    flex-shrink: 0;
}

.info-card__icon svg {
    width: 20px;
    height: 20px;
}

.info-card--vat .info-card__icon {
    background: #fef3c7;
    color: #b45309;
}

.info-card--sync .info-card__icon {
    background: #f0fdf4;
    color: #166534;
}

.info-card__title {
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.info-card__value {
    margin: 0 0 0.25rem;
    font-size: 1rem;
    font-weight: 600;
}

.info-card__meta {
    margin: 0;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.info-card__urgent {
    color: #b45309;
    font-weight: 600;
}

.info-card__error {
    margin: 0.75rem 0 0;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    font-size: 0.875rem;
}

.btn__icon {
    width: 16px;
    height: 16px;
    margin-right: 0.375rem;
    vertical-align: -2px;
}

.sync-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 1.5rem;
}

.sync-panel__header h2 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.sync-panel__meta {
    margin: 0 0 1rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.sync-status {
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 600;
}

.sync-status--success { color: #166534; }
.sync-status--partial { color: #b45309; }
.sync-status--failed { color: #991b1b; }
.sync-status--running { color: #1d4ed8; }

.sync-feedback {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
}

.sync-feedback--loading {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.sync-feedback--success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.sync-feedback--error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

@media (max-width: 768px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

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

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