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

:root {
    --primary: #0056b3; /* Industrial Blue */
    --secondary: #343a40; /* Industrial Dark Gray */
    --accent: #ffc107; /* Industrial Yellow */
    --background: #f1f3f5; /* Light Gray */
    --surface: #ffffff;
    --border: #dee2e6;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.05);
    --radius: 8px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background);
    color: var(--secondary);
    line-height: 1.5;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1rem;
}

h1, h2 {
    color: var(--secondary);
    margin-bottom: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.5rem 1.2rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    min-height: 38px;
    line-height: normal;
    box-sizing: border-box;
    vertical-align: middle;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    border-bottom: 3px solid #004085;
}

.btn-primary:active {
    border-bottom: 1px solid #004085;
    transform: translateY(1px);
}

.btn-outline {
    border: 1px solid var(--primary);
    color: var(--primary);
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1.5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-primary {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(0,86,179,0.2);
}

.btn-outline {
    background: #fff;
    border: 1.5px solid #dee2e6;
    color: #495057;
}

.btn-outline:hover {
    border-color: #0056b3;
    color: #0056b3;
}

.btn-danger {
    background: #fff;
    border: 1.5px solid #ff7675;
    color: #d63031;
}

.btn-danger:hover {
    background: #d63031;
    color: #fff;
    border-color: #d63031;
}

/* Dashboard Layout */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    padding: 1.5rem 0;
    border-bottom: 1px solid #eee;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-divider {
    height: 24px;
    width: 1px;
    background: #dee2e6;
    margin: 0 5px;
}

.mobile-text { display: none; }
.desktop-text { display: inline-block; }

/* Share & vCard Styles */
.share-container {
    margin-bottom: 2rem;
}

.share-box {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    margin: 0 auto 2rem auto;
}

.share-title {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.share-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 1rem;
}

.share-input-group input {
    flex: 1;
    padding: 10px 12px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    background: #f8fafc;
    color: #64748b;
    outline: none;
}

.share-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-whatsapp {
    background: #25d366;
    color: white !important;
    text-decoration: none;
    padding: 10px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-whatsapp:hover {
    background: #128c7e;
}

.vcard-contact {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

.vcard-title {
    font-size: 14px;
    font-weight: 700;
    color: #475569;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vcard-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vcard-item {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #334155;
    font-size: 14px;
    text-decoration: none;
}

.vcard-item:hover {
    color: #0056b3;
}


.dashboard-title {
    font-size: 28px;
    font-weight: 800;
    color: #212529;
    letter-spacing: -1px;
}

.tabs-container {
    display: flex;
    gap: 8px;
    margin-bottom: 25px;
    background: #e9ecef;
    padding: 6px;
    border-radius: 12px;
    width: fit-content;
}

.tab-btn {
    padding: 10px 24px;
    font-weight: 700;
    color: #6c757d;
    cursor: pointer;
    border-radius: 9px;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 14px;
}

.tab-btn:hover {
    color: #212529;
    background: rgba(255,255,255,0.5);
}

.tab-btn.active {
    background: #fff;
    color: #0056b3;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 0px solid var(--border);
}

th {
    background-color: #f1f3f5;
    color: var(--secondary);
}

.responsive-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .responsive-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}


/* Invoice Editor Styles */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

input, textarea, select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
}

/* Table Style Editor */
.editor-table {
    width: 100%;
    border: 2px solid var(--secondary);
    border-collapse: collapse;
}

.editor-table th {
    background: var(--secondary);
    color: white;
    padding: 8px;
    text-align: center;
}

.editor-table td {
    border: 1px solid var(--border);
    padding: 4px;
}

.item-row-editor td {
    padding: 0px 4px !important;
}

.item-row-editor input {
    height: 24px;
    padding: 1px 5px !important;
    font-size: 13px !important;
}

.item-row-editor textarea {
    padding: 2px 5px !important;
    font-size: 13px !important;
}

.editor-table input {
    border: none;
    padding: 8px;
    width: 100%;
    background: transparent;
}

.editor-table input:focus {
    background: #fffbef;
    outline: none;
}

.item-row-editor:hover {
    background: #f8f9fa;
}

.remove-btn {
    color: #e74c3c;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 25px;
}

.btn-order {
    background: #f1f3f5;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.btn-order:hover {
    background: var(--accent);
}

/* Print Styles */
@media print {
    body {
        background: white !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .no-print {
        display: none !important;
    }
    .invoice-preview {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 10mm !important;
        width: 100% !important;
    }
    /* Preserve box shadows and backgrounds in print */
    .rounded-box, .split-header > div, .invoice-number-box {
        box-shadow: 0 4px 6px rgba(0,0,0,0.05) !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

.invoice-preview {
    background: white;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 15mm;
    box-shadow: var(--shadow);
    color: #000;
    position: relative;
    overflow: hidden;
}

.invoice-preview::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    width: 400px;
    height: 400px;
    background-image: url('../logo.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.1; /* Very subtle for text readability */
    z-index: 0;
    pointer-events: none;
}

/* Ensure content stays above watermark */
.header-invoice, .split-header, .invoice-table, .totals-area, .footer-invoice {
    position: relative;
    z-index: 1;
}

.header-invoice {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
}

.logo-tmi {
    height: 100px;
}

.invoice-meta {
    text-align: right;
}

.invoice-number-box {
    border: 1px solid #000;
    padding: 5px 15px;
    border-radius: 10px;
    display: inline-block;
    font-weight: bold;
    font-size: 1.2rem;
}

.client-info {
    margin-bottom: 30px;
}

.invoice-table {
    width: 100%;
    border: 2px solid #000;
}

.invoice-table th {
    background: #ccc !important;
    border: 1px solid #000;
    text-align: center;
    font-weight: bold;
}

.invoice-table td {
    border-right: 1px solid #000;
    padding: 8px;
}

.totals-area {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
}

.words-box {
    background: #fffbef;
    padding: 15px;
    width: 50%;
    font-weight: 600;
}

.totals-box table {
    width: 336px;
    border-collapse: collapse;
}

.totals-box td {
    border: 2px solid #000;
    font-weight: bold;
    font-family: 'Consolas', 'Monaco', monospace;
}

.num-font {
    font-family: 'Consolas', 'Monaco', monospace;
}

.rounded-box {
    border: 2px solid #000;
    border-radius: var(--radius);
}

.split-header {
    display: flex;
    gap: 0;
    border: 2px solid #000;
    border-radius: var(--radius);
    /* Removed overflow: hidden to allow -10px labels to show */
}

.split-left, .split-right {
    flex: 1;
    padding: 10px;
}

.split-left {
    border-right: 2px solid #000;
}

.footer-invoice {
    margin-top: 50px;
    display: flex;
    justify-content: space-between;
}

.share-box {
    background: #f8fafc;
    border: 1px solid #edf2f7;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

.share-title {
    font-weight: 700;
    font-size: 11px;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.9;
}

.share-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.share-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 10px;
    font-weight: 800;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
    color: white;
    text-align: center;
    line-height: 1.2;
}

.share-btn span {
    font-size: 18px;
}

.share-btn:active {
    transform: scale(0.95);
}

.bg-copy { background: #3182ce; }
.bg-whatsapp { background: #10b981; }
.bg-email { background: #4a5568; }
.bg-info { background: #0056b3; }

.btn-whatsapp:hover, .btn-email:hover {
    opacity: 0.9;
}

/* Mobile App View / Responsiveness (Dashboard + Editor only) */
@media (max-width: 768px) {
    body {
        padding: 0.5rem;
    }

    .container {
        padding: 0 0.5rem;
    }

    .card {
        border-radius: 8px;
        margin-bottom: 0.5rem;
        padding: 0.5rem;
    }

    /* Dashboard Header */
    .dashboard-header {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.75rem 0;
        margin-bottom: 1rem;
    }

    .header-actions {
        gap: 6px !important;
    }

    .header-divider {
        display: none;
    }

    .dashboard-title {
        font-size: 18px;
        margin-bottom: 0 !important;
    }

    .desktop-text { display: none; }
    .mobile-text { display: inline-block; }

    .btn {
        padding: 4px 10px !important;
        font-size: 12px !important;
        min-height: 34px !important;
    }

    /* Tabs */
    .tabs-container {
        width: 100%;
    }

    .tab-btn {
        flex: 1;
        text-align: center;
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Dashboard Table → Card Layout */
    .card table {
        display: block;
    }

    .card table thead {
        display: none;
    }

    .card table tbody {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .card table tbody tr {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        padding: 12px;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0,0,0,0.04);
        align-items: center;
    }

    .card table tbody td {
        padding: 0 !important;
        border: none !important;
        font-size: 13px;
    }

    .card table tbody td:first-child {
        font-size: 15px;
        width: 100%;
    }

    .card table tbody td:last-child {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin-top: 6px;
        padding-top: 8px !important;
        border-top: 1px solid #eee !important;
    }

    /* Editor Layout */
    form > div:first-child {
        grid-template-columns: 1fr !important;
    }

    .editor-card {
        padding: 1rem !important;
    }

    .editor-table thead {
        display: none;
    }

    .editor-table, .editor-table tbody, .editor-table tr, .editor-table td {
        display: block;
        width: 100%;
    }

    .editor-table tr {
        margin-bottom: 1.2rem;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        background: white;
        padding: 1rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    .editor-table tr:nth-child(even) {
        background-color: #f1f5f9;
    }

    .editor-table td {
        border: none;
        padding: 0.6rem 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .editor-table td[data-label="Désignation"] {
        display: block;
        width: 100%;
        border-bottom: 1.5px solid #e2e8f0;
        margin-bottom: 0.5rem;
        padding-bottom: 0.8rem;
    }

    .editor-table td[data-label="Désignation"]::before {
        display: block;
        margin-bottom: 6px;
        font-size: 11px;
    }

    .editor-table td[data-label="Désignation"] textarea {
        background: #ffffff !important;
        border: 1.5px solid #cbd5e1 !important;
        border-radius: 8px !important;
        padding: 10px !important;
        font-size: 14px !important;
        min-height: 60px !important;
    }

    .editor-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #64748b;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .editor-table td:last-child {
        border-top: 1px solid var(--border);
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }

    .items-table th, .items-table td {
        padding: 0.4rem 0.6rem;
        border-bottom: 1px solid var(--border);
    }

    .items-table input, .items-table select, .items-table textarea {
        padding: 0.3rem 0.5rem;
        font-size: 13px;
    }

    .editor-table input {
        text-align: right;
        width: auto;
        flex: 1;
        margin-left: 10px;
        border: 1px solid #eee;
        border-radius: 4px;
        padding: 4px;
    }

    .editor-table input[name="desc[]"] {
        text-align: left;
    }

    .totals-area-editor > div, .totals-grid {
        width: 100% !important;
        margin-top: 1rem;
        margin-left: 0 !important;
    }


    /* No-print toolbar on editor */
    .no-print-toolbar .container {
        flex-direction: column;
        gap: 8px;
        align-items: stretch !important;
    }

    .no-print-toolbar .container > div {
        justify-content: center;
        flex-wrap: wrap;
    }

    .editor-container {
        padding: 0 10px !important;
        margin: 15px auto !important;
    }
}

/* Remise info-bulle (popover montant en dinars) */
.remise-field {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.remise-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: #1a202c;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
    pointer-events: none;
    z-index: 50;
}
.remise-popover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    right: 14px;
    border: 5px solid transparent;
    border-bottom-color: #1a202c;
}
.remise-field:hover .remise-popover,
.remise-field:focus-within .remise-popover {
    opacity: 1;
    visibility: visible;
}

/* Modale de saisie de la désignation (mobile) */
.desc-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.desc-modal.open {
    display: flex;
}
.desc-modal__box {
    background: #fff;
    border-radius: 14px;
    padding: 1.2rem;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.desc-modal__box label {
    display: block;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #718096;
    margin-bottom: 8px;
}
.desc-modal__box textarea {
    width: 100%;
    min-height: 150px;
    border: 1.5px solid #cbd5e1;
    border-radius: 10px;
    padding: 12px;
    font-size: 16px;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
}
.desc-modal__box textarea:focus {
    border-color: #0056b3;
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.1);
}
.desc-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}
