/* ================= RESET ================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: #f1f5f9;
    color: #1e293b;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* ================= SPLIT LAYOUT ================= */
.split-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

/* LEFT PANEL */
.left-panel {
    width: 50%;
    padding: 40px;
    background: #f8fafc;
}

/* RIGHT PANEL */
.right-panel {
    width: 50%;
    padding: 40px;
    background: #e2e8f0;
    display: flex;
    justify-content: center;
}

/* ================= HEADER ================= */
.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: #2563eb;
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-header p {
    margin-top: 5px;
    font-size: 14px;
    color: #64748b;
    margin-bottom: 30px;
}

/* ================= FORM SECTION ================= */
.form-section {
    background: #ffffff;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.05);
}

.section-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
}

.section-icon {
    width: 36px;
    height: 36px;
    background: #e0e7ff;
    color: #4f46e5;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
}

/* ================= FORM GRID ================= */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.form-grid.cols-1 {
    grid-template-columns: 1fr;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-label {
    font-size: 13px;
    margin-bottom: 6px;
    color: #475569;
}

.form-input,
.form-select,
.form-textarea {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    font-size: 14px;
    transition: 0.3s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: #6366f1;
    background: #ffffff;
}

.form-textarea {
    resize: none;
    min-height: 80px;
}

/* ================= LOGO UPLOAD ================= */
.logo-upload-section {
    margin-bottom: 20px;
}

.logo-upload-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.logo-upload-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.logo-upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.3);
}

.logo-upload-btn input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    left: 0;
    top: 0;
}

.logo-preview-container {
    display: none;
    align-items: center;
    gap: 15px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 10px;
    border: 2px solid #e0e7ff;
}

.logo-preview-container.active {
    display: flex;
}

.logo-preview-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 10px;
    background: white;
    padding: 8px;
    border: 2px solid #e2e8f0;
}

.logo-preview-info {
    flex: 1;
}

.logo-preview-name {
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
}

.logo-preview-size {
    font-size: 12px;
    color: #64748b;
}

.logo-remove-btn {
    padding: 8px 12px;
    background: #fee2e2;
    color: #dc2626;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
}

.logo-remove-btn:hover {
    background: #dc2626;
    color: white;
}

/* Logo in Invoice Preview */
.invoice-logo {
    max-width: 140px;
    max-height: 70px;
    object-fit: contain;
    margin-bottom: 15px;
    padding: 10px;
    background: white;
    border-radius: 12px;
    border: 2px solid #e0e7ff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}

/* ================= ITEM CARD ================= */
.item-card {
    background: #f8fafc;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    border: 1px solid #e2e8f0;
}

.item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.item-number {
    font-weight: 600;
}

.delete-btn {
    background: #fee2e2;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    color: #dc2626;
    cursor: pointer;
    transition: 0.2s;
}

.delete-btn:hover {
    background: #dc2626;
    color: white;
}

.item-grid,
.item-grid-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.item-grid-row {
    margin-top: 15px;
}

/* ================= BUTTONS ================= */
.add-item-btn {
    margin-top: 10px;
    background: #e0e7ff;
    color: #4338ca;
    border: none;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.add-item-btn:hover {
    background: #4338ca;
    color: white;
}

.btn-group {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.btn {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    font-size: 14px;
}

.btn-primary {
    background: #6366f1;
    color: white;
}

.btn-primary:hover {
    background: #4f46e5;
}

.btn-success {
    background: #22c55e;
    color: white;
}

.btn-success:hover {
    background: #16a34a;
}

/* PWA Install Button */
.install-pwa-btn {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    font-size: 14px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    transition: all 0.3s ease;
}

.install-pwa-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

/* Floating Install Button */
.floating-install-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 25px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.4);
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    animation: slideInUp 0.5s ease;
    transition: all 0.3s ease;
}

.floating-install-btn.show {
    display: flex;
}

.floating-install-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 32px rgba(16, 185, 129, 0.5);
}

.floating-install-btn:active {
    transform: translateY(-1px);
}

@keyframes slideInUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@media (max-width: 480px) {
    .floating-install-btn {
        bottom: 15px;
        right: 15px;
        padding: 12px 20px;
        font-size: 14px;
    }
}

/* ================= PREVIEW ================= */
.preview-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
}

.preview-card {
    width: 100%;
    max-width: 750px;
    background: #ffffff;
    padding: 30px;
    border-radius: 12px;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
}

.invoice-type {
    font-size: 18px;
    font-weight: 700;
    color: #2563eb;
}

.invoice-details {
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
}

.detail-card h4 {
    margin-bottom: 6px;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    table-layout: auto;
}

.invoice-table th,
.invoice-table td {
    padding: 10px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.invoice-table th {
    background: #f1f5f9;
    font-weight: 600;
}

.invoice-table th:nth-child(2),
.invoice-table td:nth-child(2) {
    text-align: center;
}

.invoice-table th:nth-child(3),
.invoice-table td:nth-child(3),
.invoice-table th:nth-child(4),
.invoice-table td:nth-child(4) {
    text-align: right;
}

.invoice-totals {
    width: 300px;
    margin-left: auto;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.totals-row.total {
    font-weight: 700;
    font-size: 16px;
    border-top: 2px solid #cbd5e1;
    padding-top: 8px;
}

/* ================= RESPONSIVE ================= */

/* Tablets and landscape phones - split view */
@media (min-width: 768px) and (max-width: 1024px) {
    .split-container {
        display: flex;
        flex-direction: row;
    }

    .left-panel,
    .right-panel {
        width: 50%;
        padding: 15px;
        overflow-y: auto;
        height: 100vh;
    }

    .preview-card {
        padding: 20px;
        font-size: 12px;
    }

    .form-section {
        padding: 15px;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 8px 5px;
        font-size: 11px;
    }
}

/* Mobile portrait - stacked view */
@media (max-width: 767px) {

    .split-container {
        flex-direction: column;
    }

    .left-panel,
    .right-panel {
        width: 100%;
        padding: 20px;
    }

    .right-panel {
        background: #f8fafc;
        padding: 10px;
    }

    .preview-wrapper {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
    }

    .preview-card {
        min-width: 100%;
        max-width: 100%;
        padding: 20px;
        font-size: 12px;
    }

    .invoice-header {
        flex-direction: column;
        gap: 15px;
    }

    .invoice-details {
        flex-direction: column;
        gap: 15px;
    }

    .invoice-table {
        font-size: 11px;
        width: 100%;
        display: table;
        table-layout: fixed;
    }

    .invoice-table thead {
        display: table-header-group;
    }

    .invoice-table tbody {
        display: table-row-group;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 6px 4px;
        font-size: 11px;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Adjust column widths for mobile */
    .invoice-table th:first-child,
    .invoice-table td:first-child {
        width: 40%;
    }

    .invoice-table th:nth-child(2),
    .invoice-table td:nth-child(2) {
        width: 15%;
        text-align: center;
    }

    .invoice-table th:nth-child(3),
    .invoice-table td:nth-child(3) {
        width: 20%;
        text-align: right;
    }

    .invoice-table th:nth-child(4),
    .invoice-table td:nth-child(4) {
        width: 25%;
        text-align: right;
    }

    .invoice-totals {
        width: 100%;
        font-size: 13px;
    }

    .form-grid,
    .item-grid,
    .item-grid-row {
        grid-template-columns: 1fr;
    }

    .btn-group {
        flex-direction: column;
    }
    
    .logo-preview-img {
        width: 60px;
        height: 60px;
    }
    
    .invoice-logo {
        max-width: 120px;
        max-height: 60px;
    }

    .company-info,
    .detail-card {
        font-size: 13px;
    }

    .invoice-type {
        font-size: 16px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .left-panel,
    .right-panel {
        padding: 10px;
    }

    .preview-card {
        padding: 12px;
        font-size: 11px;
    }

    .app-header h1 {
        font-size: 22px;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 5px 3px;
        font-size: 10px;
    }

    .invoice-table th:first-child,
    .invoice-table td:first-child {
        width: 35%;
    }

    .invoice-table th:nth-child(2),
    .invoice-table td:nth-child(2) {
        width: 12%;
    }

    .invoice-table th:nth-child(3),
    .invoice-table td:nth-child(3) {
        width: 23%;
    }

    .invoice-table th:nth-child(4),
    .invoice-table td:nth-child(4) {
        width: 30%;
    }

    .form-section {
        padding: 15px;
    }

    .btn {
        font-size: 13px;
        padding: 10px;
    }

    .invoice-totals {
        font-size: 12px;
    }

    .totals-row {
        margin-bottom: 6px;
    }
}