/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 20px;
}

.settings-btn {
    margin-left: auto;
}

.btn-settings {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 10px 16px;
    font-size: 0.9rem;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.btn-settings:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.company-info h1 {
    font-size: 2rem;
    margin-bottom: 10px;
}

.company-info p {
    opacity: 0.9;
    margin-bottom: 5px;
}

/* Form Styles */
.form-section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.form-section h2 {
    color: #667eea;
    margin-bottom: 25px;
    font-size: 1.8rem;
}

.form-section h3 {
    color: #555;
    margin: 25px 0 15px 0;
    font-size: 1.3rem;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 5px;
}

.bill-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.customer-info {
    margin-bottom: 25px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Button Styles */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
    color: white;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(86, 171, 47, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ff416c 0%, #ff4757 100%);
    color: white;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 65, 108, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    color: white;
    font-size: 0.8rem;
    padding: 8px 16px;
}

.btn-warning:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(247, 183, 51, 0.4);
}

.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

/* Preview Styles */
.preview-section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.preview-section h2 {
    color: #667eea;
    margin-bottom: 25px;
    font-size: 1.8rem;
}

.invoice-preview {
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 30px;
    background: white;
    min-height: 400px;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 3px solid #667eea;
}

.invoice-logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.invoice-logo .logo {
    font-size: 2.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 50%;
}

.company-details h2 {
    color: #667eea;
    margin-bottom: 5px;
}

.company-details p {
    color: #666;
    margin-bottom: 3px;
    font-size: 0.9rem;
}

.invoice-meta {
    text-align: right;
}

.invoice-meta h1 {
    color: #667eea;
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.invoice-meta p {
    color: #666;
    margin-bottom: 5px;
}

.customer-details {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.customer-details h3 {
    color: #667eea;
    margin-bottom: 10px;
}

.customer-details div {
    margin-bottom: 5px;
    color: #555;
}

/* Table Styles */
.items-table {
    margin-bottom: 30px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

th, td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

th {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.9rem;
}

tbody tr:hover {
    background-color: #f8f9fa;
}

tbody tr:nth-child(even) {
    background-color: #fafafa;
}

.no-items td {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 40px;
}

/* Totals Section */
.totals-section {
    display: flex;
    justify-content: flex-end;
}

.totals {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    min-width: 300px;
    border: 1px solid #e0e0e0;
}

.total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.grand-total {
    border-top: 2px solid #667eea;
    padding-top: 15px;
    margin-top: 15px;
    font-weight: bold;
    font-size: 1.3rem !important;
    color: #667eea;
}

/* GST Selection in Totals */
.gst-selection {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
}

.gst-selection label {
    font-weight: 600;
    color: #555;
}

.gst-selection select {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
    min-width: 80px;
}

.gst-selection select:focus {
    outline: none;
    border-color: #667eea;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close-btn {
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    color: white;
    opacity: 0.8;
    transition: opacity 0.3s ease;
    line-height: 1;
    padding: 0;
    margin: 0;
}

.close-btn:hover {
    opacity: 1;
}

.modal-body {
    padding: 30px;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.4);
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: #666;
    font-size: 0.85rem;
    font-style: italic;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 5px;
    }

    .header {
        padding: 10px;
        flex-direction: column;
        gap: 10px;
    }

    .logo-section {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .logo {
        font-size: 2rem;
        padding: 10px;
        min-width: 50px;
    }

    .company-info h1 {
        font-size: 1.2rem;
    }

    .company-info p {
        font-size: 0.8rem;
    }

    .settings-btn {
        margin-left: 0;
    }

    .btn-settings {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .form-section, .preview-section {
        padding: 15px;
        margin-bottom: 15px;
    }

    .form-section h2, .preview-section h2 {
        font-size: 1.4rem;
        margin-bottom: 15px;
    }

    .form-section h3 {
        font-size: 1.1rem;
        margin: 15px 0 10px 0;
    }

    .bill-info {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .form-group {
        margin-bottom: 15px;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px;
        font-size: 0.9rem;
    }

    .action-buttons {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .btn {
        width: 100%;
        max-width: 250px;
        padding: 12px 20px;
        font-size: 0.9rem;
    }

    .invoice-preview {
        padding: 15px;
        overflow-x: auto;
    }

    .invoice-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .invoice-logo {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .invoice-logo .logo {
        font-size: 2rem;
        padding: 10px;
    }

    .company-details h2 {
        font-size: 1.3rem;
    }

    .company-details p {
        font-size: 0.8rem;
    }

    .invoice-meta {
        text-align: center;
    }

    .invoice-meta h1 {
        font-size: 1.8rem;
    }

    .customer-details {
        margin-bottom: 20px;
        padding: 15px;
    }

    .customer-details h3 {
        font-size: 1.1rem;
    }

    .items-table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 20px;
    }

    table {
        min-width: 500px;
        font-size: 0.8rem;
    }

    th, td {
        padding: 8px 4px;
        font-size: 0.75rem;
    }

    th {
        font-size: 0.7rem;
        letter-spacing: 0.3px;
    }

    .btn-warning {
        font-size: 0.6rem;
        padding: 4px 8px;
    }

    .totals-section {
        justify-content: center;
        margin-top: 15px;
    }

    .totals {
        min-width: 100%;
        max-width: 300px;
        padding: 15px;
    }

    .total-row {
        font-size: 1rem;
        margin-bottom: 8px;
    }

    .grand-total {
        font-size: 1.1rem !important;
        padding-top: 10px;
        margin-top: 10px;
    }

    .gst-selection {
        padding: 8px 0;
    }

    .gst-selection select {
        padding: 6px 10px;
        font-size: 0.9rem;
        min-width: 70px;
    }

    .modal-content {
        width: 95%;
        margin: 2% auto;
        max-height: 95vh;
    }

    .modal-header {
        padding: 15px 20px;
    }

    .modal-header h2 {
        font-size: 1.3rem;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-actions {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .modal-actions .btn {
        width: 100%;
        max-width: 200px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 3px;
    }

    .header {
        padding: 8px;
    }

    .logo {
        font-size: 1.8rem;
        padding: 8px;
    }

    .company-info h1 {
        font-size: 1rem;
    }

    .company-info p {
        font-size: 0.75rem;
    }

    .form-section, .preview-section {
        padding: 10px;
    }

    .form-section h2, .preview-section h2 {
        font-size: 1.2rem;
    }

    .form-section h3 {
        font-size: 1rem;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 8px;
        font-size: 0.85rem;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .btn-settings {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .invoice-preview {
        padding: 10px;
    }

    .invoice-logo .logo {
        font-size: 1.5rem;
        padding: 8px;
    }

    .company-details h2 {
        font-size: 1.1rem;
    }

    .company-details p {
        font-size: 0.75rem;
    }

    .invoice-meta h1 {
        font-size: 1.5rem;
    }

    .customer-details {
        padding: 10px;
    }

    table {
        min-width: 450px;
        font-size: 0.7rem;
    }

    th, td {
        padding: 6px 3px;
        font-size: 0.65rem;
    }

    .btn-warning {
        font-size: 0.55rem;
        padding: 3px 6px;
    }

    .totals {
        padding: 10px;
    }

    .total-row {
        font-size: 0.9rem;
    }

    .grand-total {
        font-size: 1rem !important;
    }

    .gst-selection select {
        padding: 5px 8px;
        font-size: 0.8rem;
        min-width: 60px;
    }

    .modal-content {
        width: 98%;
        margin: 1% auto;
    }

    .modal-header {
        padding: 10px 15px;
    }

    .modal-header h2 {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: 15px;
    }

    .close-btn {
        font-size: 1.5rem;
    }
}

@media (max-width: 320px) {
    .container {
        padding: 2px;
    }

    .form-section, .preview-section {
        padding: 8px;
    }

    .company-info h1 {
        font-size: 0.9rem;
    }

    .form-section h2, .preview-section h2 {
        font-size: 1.1rem;
    }

    table {
        min-width: 400px;
        font-size: 0.65rem;
    }

    th, td {
        padding: 5px 2px;
        font-size: 0.6rem;
    }

    .btn {
        font-size: 0.8rem;
        padding: 8px 14px;
    }

    .totals {
        padding: 8px;
    }

    .total-row {
        font-size: 0.8rem;
    }

    .grand-total {
        font-size: 0.9rem !important;
    }
}

/* Landscape orientation for small screens */
@media (max-width: 768px) and (orientation: landscape) {
    .header {
        flex-direction: row;
        padding: 8px;
    }

    .logo-section {
        flex-direction: row;
        gap: 10px;
    }

    .company-info h1 {
        font-size: 1rem;
    }

    .invoice-header {
        flex-direction: row;
        justify-content: space-between;
    }

    .invoice-logo {
        flex-direction: row;
    }

    .invoice-meta {
        text-align: right;
    }
}

/* Ensure text doesn't overflow horizontally */
* {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Prevent horizontal scrolling on main container */
body {
    overflow-x: hidden;
}

.container {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Make sure tables are scrollable on mobile */
.items-table {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Ensure modal fits on small screens */
.modal {
    padding: 10px;
    box-sizing: border-box;
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Success Message */
.success-message {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    display: none;
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    display: none;
}
