/* Modern CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --bg-color: #f8fafc;
    --white: #ffffff;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--gray-800);
    background-color: var(--bg-color);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    padding: 20px 0;
}

header h1 {
    font-size: 2.5rem;
    color: var(--gray-900);
    font-weight: 700;
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

/* Input Section */
.input-section {
    padding: 20px;
}

.input-section h2 {
    font-size: 1.75rem;
    color: var(--gray-900);
    margin-bottom: 20px;
    text-align: center;
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--gray-700);
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: var(--transition);
    height: 38px;
}

textarea.form-control {
    height: auto;
    min-height: 80px;
}

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

input[type="file"] {
    cursor: pointer;
    text-align: center;
}

input[type="file"]::-webkit-file-upload-button {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    margin-right: 8px;
    transition: var(--transition);
}

input[type="file"]::-webkit-file-upload-button:hover {
    background: var(--gray-200);
}

/* Floating Labels */
.floating-label {
    position: relative;
}

.floating-label input:not([type="checkbox"]),
.floating-label textarea {
    padding: 18px 12px 6px 12px;
}

.floating-label label {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    margin-bottom: 0;
    transition: all 0.2s ease;
    pointer-events: none;
    background: white;
    padding: 0 4px;
    font-size: 0.95rem;
}

.floating-label input:focus ~ label,
.floating-label input:not(:placeholder-shown) ~ label {
    top: -8px;
    left: 10px;
    transform: translateY(0);
    font-size: 0.75rem;
    color: var(--primary-color);
}

.floating-label textarea ~ label {
    top: 12px;
    transform: translateY(0);
}

.floating-label textarea:focus ~ label,
.floating-label textarea:not(:placeholder-shown) ~ label {
    top: -8px;
    left: 10px;
    font-size: 0.75rem;
    color: var(--primary-color);
}

.optional {
    font-size: 0.875rem;
    color: var(--gray-500);
    font-weight: normal;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

select.form-control {
    cursor: pointer;
}

/* Section Dividers */
/* Card Styles */
.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card h3 {
    font-size: 1.125rem;
    color: var(--gray-800);
    font-weight: 600;
    margin-bottom: 15px;
}

/* Document Header */
.document-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 15px;
}

.document-header .form-group {
    flex: 1;
    margin-bottom: 0;
}

/* Toggle Switch - Hotels/Apartments Style */
.toggle-group {
    display: flex;
    align-items: center;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 180px;
    height: 44px;
}

.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    background-color: var(--primary-color);
    border-radius: 50px;
    cursor: pointer;
    border: 3px solid var(--primary-color);
    overflow: hidden;
    transition: var(--transition);
}

/* White sliding pill */
.toggle-slider::before {
    position: absolute;
    content: "";
    height: 100%;
    width: 50%;
    left: 0;
    top: 0;
    background-color: white;
    border-radius: 50px;
    transition: transform 0.3s ease;
    z-index: 1;
}

/* Text elements */
.toggle-text {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 600;
    font-size: 0.95rem;
    transition: color 0.3s ease;
    z-index: 2;
}

.toggle-text.left {
    left: 22px;
    color: var(--primary-color);
}

.toggle-text.right {
    right: 18px;
    color: white;
}

/* When checked (Invoice selected) */
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(100%);
}

.toggle-switch input:checked + .toggle-slider .toggle-text.left {
    color: white;
}

.toggle-switch input:checked + .toggle-slider .toggle-text.right {
    color: var(--primary-color);
}

/* Address Section */
.address-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.checkbox-group {
    margin-bottom: 15px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    height: auto;
    margin: 0;
}

/* File Upload */
.file-upload-wrapper {
    position: relative;
}

.file-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.file-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    transition: var(--transition);
}

.file-label:hover {
    background: var(--gray-200);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.file-label svg {
    width: 20px;
    height: 20px;
}

/* Logo Preview */
.logo-preview {
    margin-top: 10px;
    max-width: 180px;
    max-height: 80px;
}

.logo-container {
    position: relative;
    display: inline-block;
}

.logo-preview img {
    max-width: 180px;
    max-height: 80px;
    border-radius: 4px;
    border: 1px solid var(--gray-200);
    padding: 4px;
    display: block;
}

.btn-remove-logo {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.btn-remove-logo:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* Discount Section */
.discount-type {
    display: flex;
    gap: 8px;
}

.radio-label {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    background: white;
}

.radio-label:hover {
    border-color: var(--primary-color);
}

.radio-label input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.radio-label:has(input[type="radio"]:checked) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Line Items Table */
.line-items-table {
    margin-top: 15px;
}

.line-items-header {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr 1fr 40px;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 2px solid var(--gray-200);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.line-item {
    display: grid;
    grid-template-columns: 3fr 1fr 1fr 1fr 40px;
    gap: 10px;
    padding: 10px 0;
    align-items: center;
    border-bottom: 1px solid var(--gray-100);
}

.line-item:last-child {
    border-bottom: none;
}

.line-item input {
    margin: 0;
}

.btn-remove {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    margin: 0 auto;
}

.btn-remove:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* Notes Customization */
.notes-customization {
    margin-bottom: 15px;
}

.color-picker-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-picker-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0;
}

input[type="color"] {
    -webkit-appearance: none;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    width: 50px;
    height: 38px;
    cursor: pointer;
    padding: 2px;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
    margin-top: 20px;
    padding: 12px;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--gray-700);
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 0.875rem;
}

.btn-secondary:hover {
    background: var(--gray-800);
    transform: translateY(-1px);
}

.btn-print {
    background: var(--success-color);
    color: white;
}

.btn-print:hover {
    background: #16a34a;
}

/* Totals Section */
.totals-section {
    margin-bottom: 20px;
}

.totals-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr;
    gap: 15px;
    align-items: start;
}

.discount-group {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.discount-group .form-group {
    flex: 1;
    margin-bottom: 0;
}

/* Preview Section */
.preview-section {
    padding: 20px;
    position: sticky;
    top: 20px;
}

.preview-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    background: var(--white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.template-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.template-selector label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin: 0;
}

.template-select {
    width: 160px;
    height: 40px;
    padding: 0 40px 0 16px;
    font-size: 0.925rem;
    font-weight: 500;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    background-color: white;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23334155' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

.template-select:hover {
    border-color: var(--primary-color);
}

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

.preview-controls h2 {
    font-size: 1.75rem;
    color: var(--gray-900);
}

.document-preview {
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    min-height: 600px;
    background: white;
    overflow: hidden;
}

.preview-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 600px;
    color: var(--gray-400);
    font-size: 1.125rem;
}

/* Generated Document Styles */
.generated-document {
    padding: 40px;
    font-size: 14px;
    line-height: 1.5;
    color: #000;
    max-width: 800px;
    margin: 0 auto;
    background: white;
}

/* Template Styles */
/* Ensure all template colors are preserved */
.generated-document {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.generated-document * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Modern Template (Default) */
.template-modern .doc-header {
    border-bottom: 3px solid var(--primary-color);
    padding-bottom: 25px;
}

.template-modern .doc-type h1 {
    color: var(--primary-color);
    letter-spacing: -0.5px;
}

.template-modern .items-table th {
    background: linear-gradient(to right, var(--gray-100), var(--gray-50));
    color: var(--gray-800);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
    padding: 14px 12px;
}

.template-modern .totals {
    background: var(--gray-50);
    padding: 20px;
    border-radius: 8px;
    margin-left: auto;
    max-width: 350px;
}

/* Classic Template */
.template-classic {
    font-family: 'Georgia', serif;
    color: #2c2c2c;
}

.template-classic .doc-header {
    border-bottom: 4px double #1a1a1a;
    padding-bottom: 35px;
    margin-bottom: 35px;
}

.template-classic .company-info img {
    filter: grayscale(100%);
    opacity: 0.8;
}

.template-classic .doc-type h1 {
    color: #1a1a1a;
    font-family: 'Georgia', serif;
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 8px;
}

.template-classic .items-table {
    border: 2px solid #1a1a1a;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.1);
}

.template-classic .items-table th {
    background: #1a1a1a;
    color: #fff;
    font-weight: 500;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 1.5px;
    padding: 15px 12px;
}

.template-classic .items-table td {
    border: 1px solid #ccc;
    font-family: 'Georgia', serif;
}

.template-classic .billing-info h3 {
    text-decoration: underline;
    text-underline-offset: 4px;
}

/* Minimal Template */
.template-minimal {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-weight: 300;
}

.template-minimal .doc-header {
    border-bottom: 1px solid #f0f0f0;
    margin-bottom: 60px;
    padding-bottom: 20px;
}

.template-minimal .company-info h2 {
    font-weight: 200;
    font-size: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.template-minimal .company-info p {
    font-size: 12px;
    color: #999;
    margin: 1px 0;
}

.template-minimal .doc-type h1 {
    font-weight: 100;
    color: #999;
    font-size: 28px;
    letter-spacing: 4px;
}

.template-minimal .doc-type p {
    font-size: 12px;
    color: #999;
}

.template-minimal .items-table {
    margin-top: 40px;
}

.template-minimal .items-table th {
    background: none;
    border-bottom: 1px solid #f0f0f0;
    font-weight: 400;
    color: #999;
    text-align: left;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 1px;
    padding: 10px 0;
}

.template-minimal .items-table td {
    border: none;
    border-bottom: 1px solid #fafafa;
    padding: 20px 0;
    font-size: 13px;
}

.template-minimal .totals {
    margin-top: 40px;
}

.template-minimal .totals-table {
    border-top: 1px solid #f0f0f0;
    padding-top: 20px;
}

.template-minimal .notes {
    border: 1px solid #f0f0f0;
    background: #fafafa;
}

/* Bold Template */
.template-bold .doc-header {
    background: linear-gradient(135deg, var(--primary-color), #1e40af);
    color: white;
    padding: 40px 40px 40px 80px;
    margin: -40px -40px 40px -40px;
    border-bottom: none;
    position: relative;
    overflow: visible;
    width: calc(100% + 120px);
    left: -40px;
    box-sizing: border-box;
}

.template-bold .doc-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 300px;
    height: 300px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

.template-bold .company-info h2,
.template-bold .company-info p {
    color: white;
    position: relative;
    z-index: 1;
}

.template-bold .doc-type h1 {
    color: white;
    font-size: 42px;
    font-weight: 800;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.template-bold .doc-type p {
    color: rgba(255, 255, 255, 0.95);
    font-size: 14px;
}

.template-bold .items-table {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 8px;
    overflow: hidden;
}

.template-bold .items-table th {
    background: #1e293b;
    color: white;
    font-weight: 700;
    text-transform: uppercase;
    padding: 16px;
    font-size: 13px;
}

.template-bold .items-table td {
    font-weight: 500;
}

.template-bold .totals {
    background: linear-gradient(to right, #f8fafc, #e2e8f0);
    padding: 25px;
    border-radius: 12px;
    margin-left: auto;
    max-width: 400px;
}

.template-bold .total-row {
    background: var(--primary-color);
    color: white;
    font-size: 20px;
    border-radius: 8px;
}

.template-bold .total-row td {
    padding: 15px;
    font-weight: 700;
}

/* Elegant Template */
.template-elegant {
    font-family: 'Playfair Display', 'Georgia', serif;
    background: linear-gradient(to bottom, #fffbf7, white);
    padding-top: 20px;
}

.template-elegant .doc-header {
    text-align: center;
    border: none;
    padding-bottom: 50px;
    position: relative;
}

.template-elegant .doc-header::after {
    content: '❦';
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #d4af37;
    font-size: 24px;
}

.template-elegant .company-info {
    max-width: 100%;
    text-align: center;
}

.template-elegant .company-info h2 {
    color: #2c2c2c;
    font-weight: 400;
    font-size: 28px;
    margin-bottom: 15px;
}

.template-elegant .doc-type {
    text-align: center;
    margin-top: 30px;
}

.template-elegant .doc-type h1 {
    color: #d4af37;
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 400;
    font-size: 48px;
    letter-spacing: 3px;
    text-transform: uppercase;
    position: relative;
    display: inline-block;
}

.template-elegant .doc-type h1::before,
.template-elegant .doc-type h1::after {
    content: '•';
    position: absolute;
    color: #d4af37;
    font-size: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.template-elegant .doc-type h1::before {
    left: -30px;
}

.template-elegant .doc-type h1::after {
    right: -30px;
}

.template-elegant .billing-info {
    display: flex;
    justify-content: space-around;
    text-align: center;
    margin: 50px 0;
}

.template-elegant .items-table {
    margin-top: 30px;
}

.template-elegant .items-table th {
    background: none;
    border-top: 1px solid #d4af37;
    border-bottom: 3px double #d4af37;
    color: #2c2c2c;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 11px;
    padding: 15px 12px;
}

.template-elegant .items-table td {
    border-bottom: 1px dotted #e8e8e8;
    padding: 18px 12px;
    font-family: 'Georgia', serif;
}

.template-elegant .totals {
    text-align: right;
    margin-top: 40px;
}

.template-elegant .total-row {
    font-size: 18px;
    color: #d4af37;
    font-weight: 600;
    border-top: 2px solid #d4af37;
}


/* Corporate Blue Template */
.template-corporate {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #1a365d;
}

.template-corporate .doc-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 40px;
    padding-bottom: 25px;
    border-bottom: 4px solid #2c5282;
    margin-bottom: 35px;
}

.template-corporate .company-info h2 {
    color: #2c5282;
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 10px;
}

.template-corporate .company-info p {
    color: #4a5568;
    font-size: 13px;
    line-height: 1.5;
}

.template-corporate .doc-type {
    background: #2c5282;
    color: white;
    padding: 20px 30px;
    border-radius: 8px;
    text-align: center;
}

.template-corporate .doc-type h1 {
    color: white;
    font-size: 28px;
    margin-bottom: 10px;
}

.template-corporate .doc-type p {
    color: #e2e8f0;
    font-size: 13px;
}

.template-corporate .billing-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    background: #edf2f7;
    padding: 25px;
    border-left: 4px solid #2c5282;
    margin-bottom: 35px;
}

.template-corporate .billing-info h3 {
    color: #2c5282;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.template-corporate .items-table {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.template-corporate .items-table th {
    background: #2c5282;
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
    padding: 14px;
}

.template-corporate .items-table td {
    padding: 14px;
    border-bottom: 1px solid #e2e8f0;
}

.template-corporate .items-table tr:last-child td {
    border-bottom: none;
}

.template-corporate .totals {
    margin-top: 35px;
}

.template-corporate .totals-table {
    background: #f7fafc;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
}

.template-corporate .total-row {
    background: #2c5282;
    color: white;
    font-size: 18px;
    font-weight: 700;
    margin: -20px;
    margin-top: 15px;
    padding: 15px 20px;
    border-radius: 0 0 6px 6px;
}

.template-corporate .total-row td {
    color: white;
}

.template-corporate .notes {
    background: #bee3f8;
    border: 2px solid #2c5282;
    border-radius: 8px;
    padding: 25px;
    margin-top: 35px;
}

.template-corporate .notes h3 {
    color: #2c5282;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.5px;
}

.doc-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--gray-200);
    width: 100%;
}

.company-info {
    flex: 1;
}

.company-info img {
    max-height: 50px;
    margin-bottom: 10px;
}

.company-info h2 {
    font-size: 20px;
    margin-bottom: 5px;
    color: #000;
}

.company-info p {
    margin: 1px 0;
    color: #555;
    font-size: 13px;
}

.doc-type {
    text-align: right;
}

.doc-type h1 {
    font-size: 28px;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.doc-type p {
    margin: 3px 0;
    color: #555;
    font-size: 13px;
}

.billing-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-bottom: 40px;
}

.bill-to h3, .ship-to h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: #000;
}

.bill-to p, .ship-to p {
    margin: 2px 0;
    color: #555;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

.items-table th {
    background: var(--gray-100);
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--gray-300);
}

.items-table td {
    padding: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.items-table th:last-child,
.items-table td:last-child {
    text-align: right;
}

.totals {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 40px;
}

.totals-table {
    width: 300px;
}

.totals-table tr {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}

.totals-table .total-row {
    font-size: 18px;
    font-weight: 700;
    border-top: 2px solid var(--gray-300);
    padding-top: 12px;
    margin-top: 8px;
}

.notes {
    padding: 20px;
    border-radius: 6px;
    margin-top: 30px;
}

.notes h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: #000;
}

.notes p {
    color: #333;
    white-space: pre-wrap;
    margin: 0;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .preview-section {
        position: static;
    }
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .address-section {
        grid-template-columns: 1fr;
    }
    
    .totals-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .discount-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    .document-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .toggle-group {
        justify-content: flex-start;
        width: 100%;
    }
    
    .line-items-header {
        display: none;
    }
    
    .line-item {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 15px;
        background: var(--gray-50);
        border-radius: 6px;
        margin-bottom: 10px;
    }
    
    .line-item input {
        width: 100%;
    }
    
    .btn-remove {
        width: 100%;
        margin-top: 10px;
    }
    
    .doc-header {
        flex-direction: column;
    }
    
    .doc-type {
        text-align: left;
        margin-top: 20px;
    }
}

/* Ensure desktop layout in print even on small screens */
@media print and (max-width: 768px) {
    .doc-header {
        flex-direction: row !important;
    }
    
    .company-info {
        max-width: 50% !important;
    }
    
    .doc-type {
        text-align: right !important;
        margin-top: 0 !important;
    }
}

/* Print Styles */
@media print {
    @page {
        size: A4;
        margin: 0;
    }
    
    body {
        background: white;
        margin: 0;
        padding: 0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .container {
        max-width: 100%;
        padding: 0;
        margin: 0;
    }
    
    .input-section,
    header,
    .preview-controls,
    .main-content > .input-section {
        display: none !important;
    }
    
    .main-content {
        display: block !important;
        margin: 0;
        padding: 0;
        grid-template-columns: none !important;
    }
    
    .preview-section {
        padding: 0 !important;
        box-shadow: none !important;
        background: white;
        margin: 0;
        position: static !important;
        width: 100% !important;
    }
    
    .document-preview {
        border: none !important;
        min-height: auto;
        margin: 0;
        padding: 0;
        width: 100% !important;
    }
    
    .generated-document {
        padding: 40px !important;
        max-width: 100% !important;
        margin: 0 !important;
        font-size: 14px !important;
        background: white !important;
    }
    
    /* Preserve template styles in print */
    .template-bold .doc-header {
        background: linear-gradient(135deg, #2563eb, #1e40af) !important;
        color: white !important;
        padding: 40px 40px 40px 80px !important;
        margin: -40px -40px 40px -40px !important;
        box-sizing: border-box !important;
        width: calc(100% + 120px) !important;
        left: -40px !important;
        position: relative !important;
        overflow: visible !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-bold .company-info h2,
    .template-bold .company-info p,
    .template-bold .doc-type h1,
    .template-bold .doc-type p {
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-bold .items-table th {
        background: #1e293b !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-bold .totals {
        background: linear-gradient(to right, #f8fafc, #e2e8f0) !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-bold .total-row {
        background: #2563eb !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-elegant .doc-header {
        text-align: center !important;
    }
    
    .template-elegant .company-info,
    .template-elegant .doc-type {
        text-align: center !important;
        max-width: 100% !important;
    }
    
    
    /* Corporate template print styles */
    .template-corporate .doc-type {
        background: #2c5282 !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-corporate .billing-info {
        background: #edf2f7 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-corporate .items-table th {
        background: #2c5282 !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .template-corporate .total-row {
        background: #2c5282 !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    /* Fix white text preservation in all templates */
    .template-bold .doc-header,
    .template-bold .doc-header *,
    .template-corporate .doc-type,
    .template-corporate .doc-type *,
    .template-corporate .total-row,
    .template-corporate .total-row *,
    .template-bold .total-row,
    .template-bold .total-row *,
    .template-bold .items-table th,
    .template-bold .items-table th *,
    .template-corporate .items-table th,
    .template-corporate .items-table th * {
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    .doc-header {
        page-break-inside: avoid;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        margin-bottom: 30px !important;
        padding-bottom: 20px !important;
        border-bottom: 2px solid #e2e8f0 !important;
        width: 100% !important;
    }
    
    .company-info {
        flex: 1 !important;
        max-width: 50% !important;
    }
    
    .company-info img {
        max-height: 50px !important;
        margin-bottom: 10px !important;
    }
    
    .company-info h2 {
        font-size: 20px !important;
        margin-bottom: 5px !important;
        color: #000 !important;
    }
    
    .company-info p {
        margin: 1px 0 !important;
        color: #555 !important;
        font-size: 13px !important;
    }
    
    .doc-type {
        text-align: right !important;
        flex: 0 0 auto !important;
        min-width: 200px !important;
    }
    
    .doc-type h1 {
        font-size: 28px !important;
        color: #2563eb !important;
        margin-bottom: 8px !important;
    }
    
    .doc-type p {
        margin: 3px 0 !important;
        color: #555 !important;
        font-size: 13px !important;
    }
    
    .billing-info {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 40px !important;
        margin-bottom: 40px !important;
    }
    
    .items-table {
        page-break-inside: auto;
        width: 100% !important;
        margin-bottom: 30px !important;
    }
    
    .items-table tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
    
    .totals {
        page-break-inside: avoid;
        display: flex !important;
        justify-content: flex-end !important;
        margin-bottom: 40px !important;
    }
    
    .notes {
        page-break-inside: avoid;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        padding: 20px !important;
        border-radius: 6px !important;
        margin-top: 30px !important;
    }
    
    .notes h3 {
        font-size: 16px !important;
        margin-bottom: 10px !important;
        color: #000 !important;
    }
    
    .notes p {
        color: #333 !important;
        white-space: pre-wrap !important;
        margin: 0 !important;
    }
}