/* Invoice Designer — Canva-style document builder */

.id-designer {
    --id-form-width: 420px;
    --id-primary: #0071e3;
    --id-accent: #5e5ce6;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Toolbar */
.id-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--tb-bg-primary);
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius-lg);
}

.id-type-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.id-type-btn {
    padding: 8px 14px;
    border: 1px solid var(--tb-border);
    background: var(--tb-bg-secondary);
    color: var(--tb-text-secondary);
    border-radius: var(--tb-radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.id-type-btn:hover,
.id-type-btn.active {
    background: var(--id-primary);
    border-color: var(--id-primary);
    color: #fff;
}

.id-more-select {
    padding: 8px 12px;
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius);
    background: var(--tb-bg-secondary);
    color: var(--tb-text-primary);
    font-size: 13px;
    cursor: pointer;
}

.id-template-picker {
    display: flex;
    gap: 8px;
}

.id-brand-btn,
.id-template-btn {
    padding: 8px 14px;
    border: 1px solid var(--tb-border);
    background: var(--tb-bg-secondary);
    color: var(--tb-text-secondary);
    border-radius: var(--tb-radius);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.id-brand-btn:hover,
.id-template-btn:hover {
    border-color: var(--id-primary);
    color: var(--id-primary);
}

/* Workspace */
.id-workspace {
    display: grid;
    grid-template-columns: var(--id-form-width) 1fr;
    gap: 20px;
    align-items: start;
}

/* Form */
.id-form {
    background: var(--tb-bg-primary);
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius-lg);
    overflow: hidden;
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}

.id-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--tb-border);
    position: sticky;
    top: 0;
    background: var(--tb-bg-primary);
    z-index: 5;
}

.id-form-header h4 {
    margin: 0;
    font-size: 15px;
    color: var(--tb-text-primary);
}

.id-collapse-all {
    background: none;
    border: none;
    color: var(--tb-text-tertiary);
    cursor: pointer;
    font-size: 14px;
}

.id-section {
    border-bottom: 1px solid var(--tb-border);
}

.id-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--tb-text-secondary);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

.id-section-title:hover {
    background: var(--tb-bg-secondary);
}

.id-toggle {
    margin-left: auto;
    font-size: 11px;
    transition: transform 0.2s ease;
}

.id-section.collapsed .id-section-body {
    display: none;
}

.id-section.collapsed .id-toggle {
    transform: rotate(-90deg);
}

.id-section-body {
    padding: 0 16px 16px;
}

.id-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.id-row .form-group,
.id-section-body .form-group {
    margin-bottom: 12px;
}

.id-section-body .form-group label {
    font-size: 11px;
    color: var(--tb-text-tertiary);
    margin-bottom: 4px;
}

.id-section-body input,
.id-section-body select,
.id-section-body textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius);
    background: var(--tb-bg-secondary);
    color: var(--tb-text-primary);
    font-size: 13px;
}

.id-section-body input[type="color"] {
    padding: 4px;
    height: 38px;
    cursor: pointer;
}

/* Preview Panel */
.id-preview-panel {
    background: #f5f7fa;
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius-lg);
    display: flex;
    flex-direction: column;
    min-height: 700px;
    position: sticky;
    top: 80px;
}

.id-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--tb-bg-primary);
    border-bottom: 1px solid var(--tb-border);
    border-radius: var(--tb-radius-lg) var(--tb-radius-lg) 0 0;
}

.id-preview-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--tb-text-secondary);
}

.id-preview-actions {
    display: flex;
    gap: 8px;
}

.id-preview-scroll {
    flex: 1;
    overflow: auto;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.id-preview-canvas {
    width: 100%;
    max-width: 800px;
    transform-origin: top center;
}

/* Document Preview Styles */
.id-document {
    font-family: var(--id-font);
    max-width: 800px;
    margin: 0 auto;
    padding: 30px;
    background: #fff;
    color: #1d1d1f;
    line-height: 1.6;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.id-logo-img {
    max-height: 60px;
    max-width: 160px;
    object-fit: contain;
    margin-bottom: 8px;
}

.id-sig-img {
    max-height: 50px;
    max-width: 140px;
    object-fit: contain;
    margin-bottom: 4px;
}

.id-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--id-primary);
}

.id-company h2 {
    margin: 8px 0 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--tb-text-primary);
}

.id-company p {
    margin: 4px 0;
    font-size: 12px;
    color: #666;
}

.id-title-block {
    text-align: right;
}

.id-title-block h1 {
    margin: 0;
    color: var(--id-primary);
    font-size: 24px;
    font-weight: 700;
}

.id-title-block p {
    margin: 5px 0;
    font-size: 13px;
}

.id-notice {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.id-notice-amber {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    color: #92400e;
    text-align: left;
}

.id-notice-red {
    background: #fee2e2;
    border: 1px solid #ef4444;
    color: #991b1b;
}

.id-parties {
    display: flex;
    gap: 16px;
    margin-bottom: 25px;
}

.id-party-box {
    flex: 1;
    padding: 16px;
    background: linear-gradient(135deg, var(--id-soft), var(--id-light));
    border-radius: 12px;
    border: 1px solid color-mix(in srgb, var(--id-primary) 10%, transparent);
}

.id-party-label {
    display: block;
    color: var(--id-primary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.id-party-name {
    display: block;
    font-size: 15px;
    margin-bottom: 4px;
}

.id-party-box p {
    margin: 0;
    font-size: 12px;
    color: #666;
}

.id-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 20px;
}

.id-table thead tr {
    background: var(--id-primary);
    color: #fff;
}

.id-table th,
.id-table td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

.id-table th:first-child {
    border-radius: 8px 0 0 0;
}

.id-table th:last-child {
    border-radius: 0 8px 0 0;
}

.id-num,
.id-table td.id-num {
    text-align: center;
}

.id-hsn-cell {
    font-size: 12px;
}

.id-unit {
    color: #999;
    font-size: 11px;
}

.id-discount {
    color: #e74c3c;
}

.id-totals {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.id-totals-inner {
    width: 320px;
    font-size: 13px;
}

.id-total-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
}

.id-grand-total {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 17px;
    font-weight: 700;
    border-top: 2px solid var(--id-primary);
    margin-top: 6px;
    color: var(--id-primary);
}

.id-words {
    margin-top: 8px;
    font-size: 12px;
    color: #666;
}

.id-hsn {
    margin-top: 24px;
}

.id-hsn h4 {
    font-size: 13px;
    margin: 0 0 8px;
    color: var(--id-primary);
}

.id-bank,
.id-notes {
    margin-top: 20px;
    padding: 14px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.7;
}

.id-terms {
    margin-top: 16px;
    font-size: 11px;
    color: #666;
}

.id-footer {
    margin-top: 40px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.id-signature {
    text-align: center;
    font-size: 12px;
}

.id-signature span {
    display: block;
    border-top: 1px solid #333;
    padding-top: 5px;
    min-width: 150px;
}

.id-generated {
    font-size: 11px;
    color: #999;
    text-align: right;
}

/* Item rows */
.id-item-row {
    display: grid;
    grid-template-columns: 2fr 80px 80px 100px 90px 80px 90px 40px;
    gap: 10px;
    align-items: end;
    padding: 12px;
    background: var(--tb-bg-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
}

.id-item-row .form-group {
    margin-bottom: 0 !important;
}

.id-item-row .remove-item {
    height: 38px;
    padding: 0 10px;
}

/* Modal */
.id-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.id-modal {
    background: var(--tb-bg-primary);
    border-radius: var(--tb-radius-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.id-modal-wide {
    max-width: 720px;
}

.id-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--tb-border);
}

.id-modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.id-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--tb-text-tertiary);
    cursor: pointer;
}

.id-modal-body {
    padding: 20px;
}

.id-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--tb-border);
}

.id-help-text {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--tb-text-tertiary);
}

.id-template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
}

.id-template-card {
    border: 2px solid var(--tb-border);
    border-radius: var(--tb-radius-lg);
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.id-template-card:hover,
.id-template-card.selected {
    border-color: var(--id-primary);
    background: var(--tb-bg-secondary);
}

.id-template-thumb {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f7fa;
    border-radius: var(--tb-radius);
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 600;
}

.id-template-name {
    font-size: 12px;
    font-weight: 500;
}

/* Mobile */
@media (max-width: 1024px) {
    .id-workspace {
        grid-template-columns: 1fr;
    }

    .id-preview-panel {
        min-height: 500px;
        position: static;
    }

    .id-form {
        max-height: none;
    }
}

@media (max-width: 768px) {
    .id-designer {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
        box-sizing: border-box;
    }

    .id-workspace {
        gap: 12px;
        width: 100%;
    }

    .id-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    .id-type-tabs {
        flex-wrap: wrap;
        gap: 5px;
        width: 100%;
        box-sizing: border-box;
    }

    .id-type-btn {
        white-space: normal;
        padding: 6px 10px;
        font-size: 12px;
        flex: 1 1 auto;
        min-width: 70px;
        text-align: center;
    }

    .id-template-picker {
        justify-content: space-between;
    }

    .id-form,
    .id-preview-panel {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        border-radius: var(--tb-radius);
    }

    .id-form-header {
        padding: 10px 12px;
    }

    .id-section-body {
        padding: 0 12px 12px;
    }

    .id-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .id-section-body .form-group {
        margin-bottom: 10px;
    }

    .id-item-row {
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }

    .id-item-row .form-group {
        width: 100%;
    }

    .id-item-row .remove-item {
        align-self: flex-end;
        width: auto;
    }

    .id-document {
        padding: 12px;
    }

    .id-header {
        flex-direction: column;
        gap: 16px;
    }

    .id-title-block {
        text-align: left;
    }

    .id-title-block h1 {
        font-size: 18px;
    }

    .id-company h2 {
        font-size: 16px;
    }

    .id-parties {
        flex-direction: column;
    }

    .id-table {
        font-size: 10px;
    }

    .id-table th,
    .id-table td {
        padding: 4px;
    }

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

    .id-totals-inner {
        width: 100%;
    }

    .id-grand-total {
        font-size: 15px;
    }

    .id-preview-panel {
        min-height: 400px;
        overflow: hidden;
    }

    .id-preview-scroll {
        padding: 10px;
        overflow: hidden;
        width: 100%;
        box-sizing: border-box;
    }

    .id-preview-canvas {
        transform-origin: top left;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }

    .id-document {
        transform: scale(0.45);
        transform-origin: top left;
        width: 222%;
        max-width: 222%;
        padding: 16px;
        box-sizing: border-box;
    }

    .id-preview-toolbar {
        padding: 8px 10px;
    }

    .id-preview-actions .btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}
