@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --teif-primary: #0ea5e9;
    --teif-primary-foreground: #ffffff;
    --teif-secondary: #f1f5f9;
    --teif-secondary-foreground: #0f172a;
    --teif-accent: #f8fafc;
    --teif-accent-foreground: #0f172a;
    --teif-background: #ffffff;
    --teif-foreground: #0f172a;
    --teif-muted: #f1f5f9;
    --teif-muted-foreground: #64748b;
    --teif-border: #e2e8f0;
    --teif-input: #e2e8f0;
    --teif-ring: rgba(14, 165, 233, 0.4);
    --teif-radius: 0.75rem;
    --teif-radius-sm: 0.5rem;
    --teif-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --teif-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --teif-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --teif-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --teif-success: #10b981;
    --teif-danger: #ef4444;
    --teif-warning: #f59e0b;
    --teif-info: #3b82f6;
}

/* --- Base & Typography --- */
.teif-wrapper {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--teif-foreground);
    line-height: 1.6;
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.teif-wrapper h1,
.teif-wrapper h2,
.teif-wrapper h3 {
    color: var(--teif-foreground);
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 1rem;
}

.teif-page-title {
    font-size: 2.25rem;
}

.teif-section-title {
    font-size: 1.25rem;
    border-bottom: 1px solid var(--teif-border);
    padding-bottom: 0.75rem;
}

/* --- Components --- */
.teif-card {
    background: var(--teif-background);
    border: 1px solid var(--teif-border);
    border-radius: var(--teif-radius);
    padding: 1.5rem;
    box-shadow: var(--teif-shadow);
    transition: all 0.2s ease;
    margin-bottom: 1.5rem;
}

.teif-card:hover {
    box-shadow: var(--teif-shadow-md);
    transform: translateY(-2px);
}

/* --- Buttons --- */
.teif-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--teif-radius-sm);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    white-space: nowrap;
    text-decoration: none;
}

.teif-btn-primary {
    background: var(--teif-primary);
    color: var(--teif-primary-foreground);
}

.teif-btn-primary:hover {
    background: #0284c7;
    box-shadow: 0 10px 15px -3px rgba(14, 165, 233, 0.3);
}

.teif-btn-secondary {
    background: var(--teif-secondary);
    color: var(--teif-secondary-foreground);
    border: 1px solid var(--teif-border);
}

.teif-btn-secondary:hover {
    background: #e2e8f0;
}

.teif-btn-danger {
    background: #fff;
    color: var(--teif-danger);
    border: 1px solid #fee2e2;
}

.teif-btn-danger:hover {
    background: #fef2f2;
    border-color: #fca5a5;
}

.teif-btn-icon {
    padding: 0.5rem;
    border-radius: 0.5rem;
}

/* --- Stats Cards --- */
.teif-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.teif-stat-card {
    padding: 1.25rem;
    border-radius: var(--teif-radius);
    background: var(--teif-background);
    border: 1px solid var(--teif-border);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.teif-stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--teif-muted);
    color: var(--teif-primary);
}

.teif-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--teif-foreground);
}

.teif-stat-label {
    font-size: 0.875rem;
    color: var(--teif-muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* --- Forms --- */
.teif-form-group {
    margin-bottom: 1.25rem;
}

.teif-form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #475569;
    margin-bottom: 0.5rem;
}

.teif-input,
.teif-select,
.teif-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    background: #fff;
    border: 1px solid var(--teif-border);
    border-radius: var(--teif-radius-sm);
    color: var(--teif-foreground);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.teif-input:focus,
.teif-select:focus,
.teif-textarea:focus {
    border-color: var(--teif-primary);
    box-shadow: 0 0 0 3px var(--teif-ring);
}

.teif-select-sm {
    padding: 0.25rem 2rem 0.25rem 0.75rem;
    font-size: 0.75rem;
    min-width: 120px;
    height: 28px;
    border-radius: 9999px;
    font-weight: 600;
    cursor: pointer;
    background-position: right 0.5rem center;
    background-size: 12px;
}

/* Specific colors for inline status selects */
select.teif-status-select[data-value="terminé"],
select.teif-payment-select[data-value="payé"] {
    background-color: #dcfce7 !important;
    color: #15803d !important;
    border-color: #bbf7d0 !important;
}

select.teif-status-select[data-value="en cours de verification"] {
    background-color: #fef9c3 !important;
    color: #854d0e !important;
    border-color: #fef08a !important;
}

select.teif-status-select[data-value="créé"],
select.teif-payment-select[data-value="non payé"] {
    background-color: #fee2e2 !important;
    color: #b91c1c !important;
    border-color: #fecaca !important;
}

.teif-input-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.teif-grid-4 {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 1.5rem;
}

@media (min-width: 640px) {
    .teif-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .teif-grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

.teif-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

/* --- Tables --- */
.teif-table-container {
    background: #fff;
    border: 1px solid var(--teif-border);
    border-radius: var(--teif-radius);
    overflow: hidden;
    box-shadow: var(--teif-shadow);
}

.teif-table {
    width: 100%;
    border-collapse: collapse;
}

.teif-table th {
    background: var(--teif-muted);
    color: var(--teif-muted-foreground);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--teif-border);
}

.teif-table td {
    padding: 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--teif-border);
    vertical-align: middle;
}

.teif-table tr:last-child td {
    border-bottom: none;
}

.teif-table tr:hover td {
    background: var(--teif-accent);
}

/* --- Badges --- */
.teif-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-active,
.status-completed,
.status-paid,
.status-success {
    background: #dcfce7;
    color: #15803d;
}

.status-pending,
.status-draft {
    background: #fef9c3;
    color: #854d0e;
}

.status-expired,
.status-cancelled,
.status-failed,
.status-danger {
    background: #fee2e2;
    color: #b91c1c;
}

/* --- Navigation / Tabs --- */
.teif-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    background: var(--teif-muted);
    padding: 0.375rem;
    border-radius: 0.875rem;
    width: fit-content;
}

.teif-nav-item {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--teif-muted-foreground);
    text-decoration: none;
    transition: all 0.2s;
}

.teif-nav-item.active {
    background: #fff;
    color: var(--teif-foreground);
    box-shadow: var(--teif-shadow-sm);
}

/* --- Grid & Flex Helpers --- */
.teif-flex {
    display: flex;
}

.teif-flex-center {
    align-items: center;
}

.teif-flex-col {
    flex-direction: column;
}

.teif-justify-between {
    justify-content: space-between;
}

.teif-justify-end {
    justify-content: flex-end;
}

.teif-justify-center {
    justify-content: center;
}

.teif-grid {
    display: grid;
}

.teif-gap-2 {
    gap: 0.5rem;
}

.teif-gap-3 {
    gap: 0.75rem;
}

.teif-gap-4 {
    gap: 1rem;
}

.teif-mt-4 {
    margin-top: 1rem;
}

/* --- Colors & Backgrounds --- */
.bg-muted\/50 {
    background-color: rgba(241, 245, 249, 0.5);
}

.bg-primary\/5 {
    background-color: rgba(14, 165, 233, 0.05);
}

.bg-accent\/20 {
    background-color: rgba(248, 250, 252, 0.2);
}

.bg-accent\/50 {
    background-color: rgba(248, 250, 252, 0.5);
}

.bg-success\/5 {
    background-color: rgba(16, 185, 129, 0.05);
}

.bg-danger\/5 {
    background-color: rgba(239, 68, 68, 0.05);
}

.border-dashed {
    border-style: dashed;
}

.border-primary\/20 {
    border-color: rgba(14, 165, 233, 0.2);
}

.border-success {
    border-color: var(--teif-success);
}

.border-danger {
    border-color: var(--teif-danger);
}

/* --- Spacing --- */
.p-0 {
    padding: 0;
}

.p-4 {
    padding: 1rem;
}

.p-6 {
    padding: 1.5rem;
}

.p-8 {
    padding: 2rem;
}

.p-12 {
    padding: 3rem;
}

.pt-4 {
    padding-top: 1rem;
}

.pb-4 {
    padding-bottom: 1rem;
}

.m-0 {
    margin: 0;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mb-6 {
    margin-bottom: 1.5rem;
}

.mb-8 {
    margin-bottom: 2rem;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-6 {
    margin-top: 1.5rem;
}

.mt-8 {
    margin-top: 2rem;
}

.mx-auto {
    margin-left: auto;
    margin-right: auto;
}

/* --- Typography --- */
.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-lg {
    font-size: 1.125rem;
}

.text-xl {
    font-size: 1.25rem;
}

.text-3xl {
    font-size: 1.875rem;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.font-medium {
    font-weight: 500;
}

.font-semibold {
    font-weight: 600;
}

.font-bold {
    font-weight: 700;
}

.font-extrabold {
    font-weight: 800;
}

.text-muted-foreground {
    color: var(--teif-muted-foreground);
}

.text-primary {
    color: var(--teif-primary);
}

.text-success {
    color: var(--teif-success);
}

.text-danger {
    color: var(--teif-danger);
}

.text-white {
    color: #ffffff;
}

/* --- Sizes --- */
.w-full {
    width: 100%;
}

.w-4 {
    width: 1rem;
}

.w-5 {
    width: 1.25rem;
}

.w-6 {
    width: 1.5rem;
}

.w-12 {
    width: 3rem;
}

.w-16 {
    width: 4rem;
}

.h-4 {
    height: 1rem;
}

.h-5 {
    height: 1.25rem;
}

.h-6 {
    height: 1.5rem;
}

.h-12 {
    height: 3rem;
}

.h-16 {
    height: 4rem;
}

.space-y-2>*+* {
    margin-top: 0.5rem;
}

.space-y-4>*+* {
    margin-top: 1rem;
}

.space-y-6>*+* {
    margin-top: 1.5rem;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.max-w-xs {
    max-width: 20rem;
}

.border-t {
    border-top: 1px solid var(--teif-border);
}

.rounded-xl {
    border-radius: 0.75rem;
}

.list-none {
    list-style: none;
}

.opacity-20 {
    opacity: 0.2;
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Response */
@media (max-width: 768px) {
    .teif-form-row {
        grid-template-columns: 1fr !important;
    }

    .teif-nav {
        width: 100%;
        overflow-x: auto;
    }

    .teif-stats-grid {
        grid-template-columns: 1fr !important;
    }
}

/* --- Pricing Cards --- */
.teif-pricing-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 2rem;
    margin: 3rem 0;
}

@media (min-width: 768px) {
    .teif-pricing-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.teif-pricing-card {
    background: #fff;
    border: 1px solid var(--teif-border);
    border-radius: 1.5rem;
    padding: 2.5rem;
    text-align: center;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.teif-pricing-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    border-color: var(--teif-primary);
}

.teif-pricing-card.popular {
    border: 2px solid var(--teif-primary);
    transform: scale(1.05);
}

.teif-pricing-card.popular:hover {
    transform: scale(1.05) translateY(-5px);
}

.teif-popular-badge {
    position: absolute;
    top: 1rem;
    right: -2.5rem;
    background: var(--teif-primary);
    color: #fff;
    padding: 0.25rem 3rem;
    transform: rotate(45deg);
    font-size: 0.75rem;
    font-weight: 700;
}

.teif-price-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.teif-price-desc {
    color: var(--teif-muted-foreground);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.teif-price {
    font-size: 3rem;
    font-weight: 800;
    color: var(--teif-foreground);
    margin-bottom: 0.5rem;
}

.teif-price span {
    font-size: 1rem;
    font-weight: 500;
    color: var(--teif-muted-foreground);
}

.teif-price-features {
    list-style: none;
    padding: 0;
    margin: 2rem 0;
    text-align: left;
    flex-grow: 1;
}

.teif-price-features li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.teif-price-features li svg {
    color: var(--teif-success);
    flex-shrink: 0;
}

/* --- Account Menu --- */
.teif-user-menu-container {
    position: relative;
    display: inline-block;
}

.teif-user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: #fff;
    border: 1px solid var(--teif-border);
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.teif-user-menu-trigger:hover {
    border-color: var(--teif-primary);
    box-shadow: var(--teif-shadow-sm);
}

.teif-user-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--teif-muted);
    border: 1px solid var(--teif-border);
}

.teif-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--teif-foreground);
}

.teif-user-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 200px;
    background: #fff;
    border: 1px solid var(--teif-border);
    border-radius: 1rem;
    box-shadow: var(--teif-shadow-lg);
    padding: 0.5rem;
    display: none;
    z-index: 1000;
    animation: teif-fade-in-up 0.2s ease;
}

.teif-user-dropdown.active {
    display: block;
}

.teif-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--teif-foreground);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.5rem;
    transition: background 0.2s ease;
}

.teif-dropdown-item:hover {
    background: var(--teif-accent);
    color: var(--teif-primary);
}

.teif-dropdown-item.logout {
    color: var(--teif-danger);
    border-top: 1px solid var(--teif-border);
    margin-top: 0.25rem;
    border-radius: 0;
    padding-top: 1rem;
}

.teif-dropdown-item.logout:hover {
    background: #fff1f2;
}

@keyframes teif-fade-in-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#teif-upload-logo-btn {
    transition: all 0.2s ease;
}

#teif-upload-logo-btn:hover {
    border-color: var(--teif-primary) !important;
    background-color: rgba(14, 165, 233, 0.05) !important;
}

/* --- Global Notification System --- */
#teif-notification-container {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.teif-toast {
    pointer-events: auto;
    min-width: 280px;
    background: #ffffff;
    border-radius: 0.75rem;
    padding: 0.875rem 1.25rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateX(120%);
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.35);
}

.teif-toast.active {
    transform: translateX(0);
}

.teif-toast.success {
    background: #f0fdf4;
    color: #166534;
}

.teif-toast.error {
    background: #fef2f2;
    color: #991b1b;
}

.teif-toast-msg {
    font-size: 0.9375rem;
    font-weight: 600;
    color: inherit;
}

/* Modal Enhancements */
.teif-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.teif-modal-overlay.open {
    display: flex;
}

.teif-modal-box {
    background: #ffffff;
    border-radius: 1.5rem;
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.95) translateY(10px);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.teif-modal-overlay.open .teif-modal-box {
    transform: scale(1) translateY(0);
}

/* --- Mobile & Responsive Enhancements --- */
@media (max-width: 1024px) {
    .teif-wrapper {
        margin: 1rem auto;
    }

    .teif-page-title {
        font-size: 1.75rem;
    }
}

@media (max-width: 768px) {

    /* Layout Helpers */
    .teif-flex {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .teif-justify-between {
        justify-content: flex-start;
        flex-direction: column;
        align-items: flex-start;
    }

    /* Header optimization */
    .teif-wrapper header.teif-flex {
        margin-bottom: 2rem;
    }

    /* Tables on Mobile: Convert to cards / Scroll */
    .teif-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* For specific complex tables (like invoice items), we use a card-like layout */
    .teif-table-responsive thead {
        display: none;
        /* Hide headers on mobile */
    }

    .teif-table-responsive tr {
        display: block;
        border-bottom: 4px solid var(--teif-muted);
        padding: 1rem 0;
    }

    .teif-table-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 1rem;
        border: none !important;
        text-align: right;
    }

    .teif-table-responsive td::before {
        content: attr(data-label);
        font-weight: 700;
        text-transform: uppercase;
        font-size: 0.75rem;
        color: var(--teif-muted-foreground);
        margin-right: 1rem;
        text-align: left;
    }

    /* Modal Mobile */
    .teif-modal-box {
        padding: 1.5rem;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Nav Mobile */
    .teif-nav {
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        width: 100%;
        padding: 0.25rem;
    }

    /* Stats Grid */
    .teif-stats-grid {
        grid-template-columns: 1fr;
    }

    /* User Dropdown Alignment */
    .teif-user-dropdown {
        left: 0;
        right: auto;
        width: calc(100vw - 2rem);
    }

    /* Form Rows */
    .teif-grid-2,
    .teif-grid-3,
    .teif-grid-4 {
        grid-template-columns: 1fr;
    }

    /* Specific adjustment for invoice creation top buttons */
    .teif-wrapper header .teif-gap-2 {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .teif-wrapper header .teif-btn {
        width: 100%;
    }

    .teif-user-logo {
        height: 35px !important;
        width: 55px !important;
        border-radius: 4px !important;
        /* Less rounded for specific size */
    }
}

@media (max-width: 480px) {
    .teif-page-title {
        font-size: 1.5rem;
    }

    .teif-card {
        padding: 1rem;
    }

    .teif-btn {
        width: 100%;
        padding: 0.75rem;
    }

    .teif-toast {
        width: calc(100vw - 2rem);
        right: 1rem;
        top: 1rem;
    }
}