:root[data-theme="dark"] {
    --bg-base: #07090e;
    --panel-bg: rgba(18, 24, 38, 0.95);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --input-bg: rgba(15, 23, 42, 0.7);
}

:root[data-theme="light"] {
    --bg-base: #f1f5f9;
    --panel-bg: rgba(255, 255, 255, 0.98);
    --border-color: rgba(0, 0, 0, 0.08);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent: #0284c7;
    --accent-hover: #0369a1;
    --input-bg: #f8fafc;
}

* {
    box-sizing: border-box;
    font-family: 'Vazirmatn', sans-serif;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

/* هدر ابزارهای شناور در بالا */
.top-floating-tools {
    position: fixed;
    top: 1.25rem;
    left: 1.25rem;
    display: flex;
    gap: 0.75rem;
    z-index: 1000;
}

.tool-btn {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--accent);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.tool-btn:hover {
    border-color: var(--accent);
    transform: scale(1.1) rotate(15deg);
}

.tool-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.n1n-quick-menu {
    position: relative;
}

.n1n-fab-dropdown {
    position: absolute;
    top: 54px;
    left: 0;
    right: auto;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    width: 180px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.25);
    backdrop-filter: blur(16px);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1100;
}

.n1n-fab-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.n1n-fab-dropdown a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-main);
    font-size: 0.8rem;
    font-weight: 700;
    transition: background 0.2s, color 0.2s;
}

.n1n-fab-dropdown a svg {
    width: 16px;
    height: 16px;
    stroke: var(--accent);
}

.n1n-fab-dropdown a:hover, .n1n-fab-dropdown a.active {
    background: rgba(14, 165, 233, 0.1);
    color: var(--accent);
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* پنل کنترل سمت راست */
.control-panel {
    width: 48%;
    background: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    padding: 2rem 1.25rem;
    overflow-y: auto;
    max-height: 100vh;
    backdrop-filter: blur(16px);
}

.panel-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.panel-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

.form-section {
    margin-bottom: 1.5rem;
    background: rgba(0,0,0,0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
}

.form-section h3 {
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
    color: var(--accent);
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    grid-column: span 1;
}

.form-group.full-width {
    grid-column: span 2;
}

label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 700;
}

input, select, textarea {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    color: var(--text-main);
    font-size: 0.85rem;
    outline: none;
    width: 100%;
    transition: border-color 0.3s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.78rem;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-weight: 700;
}

.items-table-ctrl {
    width: 100%;
    border-collapse: collapse;
}

.items-table-ctrl th, .items-table-ctrl td {
    padding: 0.25rem;
    font-size: 0.78rem;
}

.items-table-ctrl input {
    width: 100%;
    font-size: 0.8rem;
    padding: 0.4rem;
}

/* استایل آپلود فایل */
.file-upload-container-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.file-upload-wrapper {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--input-bg);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    transition: border-color 0.3s;
}

.file-upload-wrapper:hover {
    border-color: var(--accent);
}

.file-upload-wrapper input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-upload-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.35rem 0.7rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    pointer-events: none;
}

.file-upload-name {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-remove-file {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    padding: 0 0.9rem;
    height: 38px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-remove-file:hover {
    background: #ef4444;
    color: #ffffff;
}

/* پنل پیش‌نمایش فاکتور A4 */
.invoice-preview-container {
    width: 52%;
    padding: 2rem 1rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    max-height: 100vh;
}

.invoice-sheet {
    background: #ffffff;
    color: #0f172a;
    width: 210mm;
    min-height: 297mm;
    padding: 12mm 15mm;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    box-sizing: border-box;
    font-size: 0.85rem;
}

.invoice-sheet-inner {
    display: flex;
    flex-direction: column;
}

/* هدر سه ستونه استاندارد */
.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 1rem;
    margin-bottom: 1.2rem;
    gap: 1rem;
}

.inv-logo-area {
    width: 140px;
    text-align: right;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-shrink: 0;
    min-height: 50px;
}

.inv-logo-area img {
    max-height: 55px;
    max-width: 130px;
    object-fit: contain;
    display: block;
}

.inv-title-area {
    text-align: center;
    flex-grow: 1;
}

.inv-title-area h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.2rem;
}

.invoice-main-title-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: #475569;
}

.inv-meta-box {
    border: 1.5px solid #0f172a;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    text-align: left;
    width: 200px;
    background: #f8fafc;
    flex-shrink: 0;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    margin-bottom: 0.15rem;
    color: #1e293b;
}

/* مشخصات فروشنده (راست) و خریدار (چپ) */
.inv-parties-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.2rem;
    direction: rtl;
}

.party-box {
    background: #ffffff;
    border: 1.5px solid #0f172a;
    border-radius: 6px;
    padding: 0.8rem 1rem;
    font-size: 0.8rem;
    line-height: 1.7;
    text-align: right;
}

.seller-box {
    order: 1;
}

.buyer-box {
    order: 2;
}

.party-box-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: #0f172a;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 0.3rem;
    margin-bottom: 0.4rem;
    text-align: center;
    background: #f1f5f9;
    margin: -0.8rem -1rem 0.5rem -1rem;
    padding: 0.4rem;
    border-radius: 4px 4px 0 0;
}

.party-row {
    margin-bottom: 0.15rem;
    color: #334155;
}

/* جدول اقلام */
.inv-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.2rem;
}

.inv-items-table th, .inv-items-table td {
    border: 1px solid #0f172a;
    padding: 0.55rem;
    font-size: 0.82rem;
    text-align: center;
    vertical-align: middle;
}

.inv-items-table th {
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 700;
}

.inv-items-table td:nth-child(2) {
    text-align: right;
    padding-right: 0.8rem;
}

/* باکس محاسبات */
.inv-totals-box {
    width: 100%;
    border: 1.5px solid #0f172a;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 1.2rem;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    border-bottom: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e293b;
}

.total-row:last-child {
    border-bottom: none;
}

.total-row.final-payable {
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 700;
    font-size: 0.95rem;
}

.inv-notes-area {
    font-size: 0.78rem;
    color: #334155;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    margin-bottom: 1.2rem;
}

/* مهر و امضا */
.inv-signatures {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.sig-box {
    width: 48%;
    border: 1px dashed #64748b;
    height: 80px;
    border-radius: 6px;
    text-align: center;
    padding-top: 0.4rem;
    font-size: 0.75rem;
    color: #475569;
    position: relative;
    background: #fafafa;
}

.seller-sig-box img {
    position: absolute;
    max-height: 55px;
    max-width: 120px;
    object-fit: contain;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

.invoice-footer-wrap {
    margin-top: auto;
}

.action-bar-preview {
    margin-bottom: 0.8rem;
}

.btn-print-large {
    width: 100%;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: white;
    border: none;
    padding: 0.85rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 25px -5px rgba(14, 165, 233, 0.4);
    transition: transform 0.2s;
}

.btn-print-large:hover {
    transform: translateY(-2px);
}

.inv-brand-footer {
    text-align: center;
    font-size: 0.72rem;
    color: #64748b;
    border-top: 1px solid #cbd5e1;
    padding-top: 0.5rem;
}

.inv-brand-footer a {
    color: #0284c7;
    text-decoration: none;
    font-weight: 700;
}

/* ریسپانسیو پیش‌نمایش فاکتور در موبایل و تبلت */
@media (max-width: 992px) {
    .app-wrapper {
        flex-direction: column;
    }
    .control-panel {
        width: 100%;
        max-height: none;
        border-left: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1.5rem 1rem;
    }
    .invoice-preview-container {
        width: 100%;
        padding: 1rem 0.5rem;
        background: rgba(0,0,0,0.1);
        max-height: none;
    }
    .invoice-sheet {
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        padding: 8mm !important;
    }
    .inv-parties-grid {
        grid-template-columns: 1fr !important;
    }
    .invoice-sheet .inv-items-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }
    .inv-header {
        flex-direction: column;
        gap: 0.8rem;
        text-align: center;
    }
    .inv-meta-box, .inv-logo-area {
        width: 100% !important;
        justify-content: center !important;
        text-align: center !important;
    }
}

/* Print CSS استاندارد و تخصصی خروجی پرینت و PDF */
@media print {
    .no-print, 
    .control-panel, 
    .top-floating-tools,
    .action-bar-preview,
    .app-wrapper > *:not(.invoice-preview-container) {
        display: none !important;
    }

    @page {
        size: A4 portrait;
        margin: 8mm 10mm;
    }

    body, html {
        background: #ffffff !important;
        color: #0f172a !important;
        width: 100% !important;
        height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .app-wrapper {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .invoice-preview-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
        overflow: visible !important;
        max-height: none !important;
        background: transparent !important;
    }

    .invoice-sheet {
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
        border: none !important;
        background: #ffffff !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        page-break-after: avoid;
    }

    .invoice-sheet-inner {
        width: 100% !important;
    }

    .inv-header {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        border-bottom: 2px solid #0f172a !important;
        padding-bottom: 6mm !important;
        margin-bottom: 6mm !important;
    }

    .inv-logo-area {
        width: 120px !important;
        text-align: right !important;
        display: flex !important;
        justify-content: flex-start !important;
    }

    .inv-logo-area img {
        max-height: 50px !important;
        max-width: 110px !important;
    }

    .inv-title-area {
        text-align: center !important;
        flex-grow: 1 !important;
    }

    .inv-title-area h1 {
        font-size: 1.3rem !important;
        color: #0f172a !important;
    }

    .invoice-main-title-text {
        font-size: 0.85rem !important;
        color: #475569 !important;
    }

    .inv-meta-box {
        border: 1.5px solid #0f172a !important;
        padding: 4mm 6mm !important;
        width: 180px !important;
        background: #f8fafc !important;
    }

    .meta-row {
        font-size: 0.75rem !important;
        color: #1e293b !important;
    }

    .inv-parties-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 6mm !important;
        margin-bottom: 6mm !important;
        direction: rtl !important;
    }

    .party-box {
        background: #ffffff !important;
        border: 1.5px solid #0f172a !important;
        border-radius: 6px !important;
        padding: 5mm !important;
        font-size: 0.78rem !important;
        line-height: 1.6 !important;
    }

    .party-box-title {
        background: #f1f5f9 !important;
        color: #0f172a !important;
        font-size: 0.85rem !important;
        padding: 2mm !important;
        margin: -5mm -5mm 4mm -5mm !important;
        border-bottom: 1px solid #cbd5e1 !important;
    }

    .inv-items-table {
        width: 100% !important;
        border-collapse: collapse !important;
        margin-bottom: 6mm !important;
    }

    .inv-items-table th, .inv-items-table td {
        border: 1px solid #0f172a !important;
        padding: 4mm 3mm !important;
        font-size: 0.78rem !important;
    }

    .inv-items-table th {
        background: #f1f5f9 !important;
        color: #0f172a !important;
    }

    .inv-totals-box {
        width: 100% !important;
        border: 1.5px solid #0f172a !important;
        border-radius: 6px !important;
        overflow: hidden !important;
        margin-bottom: 6mm !important;
    }

    .total-row {
        padding: 3mm 5mm !important;
        font-size: 0.8rem !important;
        background: #ffffff !important;
        border-bottom: 1px solid #cbd5e1 !important;
        color: #1e293b !important;
    }

    .total-row.final-payable {
        background: #f1f5f9 !important;
        color: #0f172a !important;
        font-weight: bold !important;
    }

    .inv-notes-area {
        font-size: 0.75rem !important;
        background: #f8fafc !important;
        border: 1px solid #cbd5e1 !important;
        padding: 4mm !important;
        margin-bottom: 6mm !important;
    }

    .inv-signatures {
        display: flex !important;
        justify-content: space-between !important;
        margin-top: 4mm !important;
        margin-bottom: 6mm !important;
    }

    .sig-box {
        width: 48% !important;
        height: 75px !important;
        border: 1px dashed #64748b !important;
        background: #fafafa !important;
        font-size: 0.72rem !important;
        padding-top: 3mm !important;
    }

    .seller-sig-box img {
        max-height: 48px !important;
        max-width: 110px !important;
        bottom: 3px !important;
    }

    .invoice-footer-wrap {
        margin-top: auto !important;
    }

    .inv-brand-footer {
        border-top: 1px solid #cbd5e1 !important;
        padding-top: 3mm !important;
        font-size: 0.68rem !important;
        color: #64748b !important;
        text-align: center !important;
    }
}