/* CSS Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --success-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --background-color: #f3f4f6;
    --card-background: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Container */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.logo {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Main Content */
main {
    flex: 1;
}

/* Template Actions */
.template-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* Form Sections */
.form-section {
    background: var(--card-background);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
}

.form-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

/* Form Elements */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--card-background);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn .icon {
    font-size: 1rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
}

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

.btn-secondary:hover {
    background: #5b6370;
}

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

.btn-success:hover {
    background: var(--success-hover);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    padding: 8px 12px;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--background-color);
    border-color: var(--secondary-color);
}

.btn-large {
    padding: 14px 28px;
    font-size: 1.1rem;
}

/* Line Items */
.line-items-container {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.line-items-header {
    display: grid;
    grid-template-columns: 2fr 80px 100px 100px 50px;
    gap: 10px;
    padding: 12px 16px;
    background: var(--background-color);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.line-item {
    display: grid;
    grid-template-columns: 2fr 80px 100px 100px 50px;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

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

.line-item input {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
}

.line-item input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.line-item .amount {
    font-weight: 500;
    color: var(--text-primary);
    text-align: right;
}

.btn-add-item {
    width: 100%;
    border-radius: 0;
    padding: 14px;
}

/* Totals */
.totals-container {
    max-width: 400px;
    margin-left: auto;
}

.totals-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.totals-row label {
    font-weight: 500;
}

.totals-row input {
    width: 100px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    text-align: right;
}

.discount-input {
    display: flex;
    gap: 8px;
}

.discount-input input {
    width: 80px;
}

.discount-input select {
    width: 60px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.totals-summary {
    border-top: 2px solid var(--border-color);
    padding-top: 16px;
    margin-top: 16px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 1rem;
}

.summary-row.total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    border-top: 2px solid var(--border-color);
    padding-top: 12px;
    margin-top: 8px;
}

/* Generate Section */
.generate-section {
    display: flex;
    gap: 16px;
    justify-content: center;
    padding: 30px 0;
    flex-wrap: wrap;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 0;
    margin-top: 40px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

footer a:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow-y: auto;
    padding: 20px;
}

.modal.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.modal-content {
    background: var(--card-background);
    border-radius: var(--radius-lg);
    max-width: 800px;
    width: 100%;
    margin: 40px auto;
    position: relative;
    box-shadow: var(--shadow-lg);
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.modal-small {
    max-width: 400px;
    padding: 24px;
}

.modal-small h2 {
    margin-bottom: 20px;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    z-index: 10;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--background-color);
}

.modal-actions {
    display: flex;
    justify-content: center;
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

/* Invoice Preview */
.invoice-preview {
    padding: 40px;
    background: white;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
    flex-wrap: wrap;
    gap: 20px;
}

.invoice-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.invoice-company-info h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
}

.invoice-company-info p {
    color: var(--text-secondary);
    margin-bottom: 4px;
    white-space: pre-line;
}

.invoice-details {
    text-align: right;
}

.invoice-details p {
    margin-bottom: 6px;
}

.invoice-details strong {
    color: var(--text-primary);
}

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

.invoice-party h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.invoice-party h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.invoice-party p {
    color: var(--text-secondary);
    margin-bottom: 4px;
    white-space: pre-line;
}

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

.invoice-items-table th {
    background: var(--background-color);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

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

.invoice-items-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}

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

.invoice-totals {
    margin-left: auto;
    width: 300px;
}

.invoice-total-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
}

.invoice-total-row.final {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    border-top: 2px solid var(--border-color);
    padding-top: 15px;
    margin-top: 10px;
}

.invoice-notes {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.invoice-notes h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.invoice-notes p {
    color: var(--text-secondary);
    white-space: pre-line;
    margin-bottom: 16px;
}

/* Template List */
.template-list {
    max-height: 400px;
    overflow-y: auto;
}

.template-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.template-item:hover {
    background: var(--background-color);
}

.template-item-name {
    font-weight: 500;
}

.template-item-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.template-item-actions {
    display: flex;
    gap: 8px;
}

.template-item-actions button {
    padding: 6px 10px;
    font-size: 0.85rem;
}

.no-templates {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .header-content {
        flex-direction: column;
        gap: 10px;
    }

    .logo {
        width: 40px;
        height: 40px;
    }

    .tagline {
        font-size: 0.95rem;
    }

    .form-section {
        padding: 16px;
    }

    .form-section h2 {
        font-size: 1.1rem;
    }

    .line-items-header {
        display: none;
    }

    .line-item {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 16px;
    }

    .line-item input {
        width: 100%;
    }

    .line-item input::placeholder {
        font-size: 0.85rem;
    }

    .line-item .amount {
        text-align: left;
        font-size: 1.1rem;
        padding-top: 8px;
    }

    .line-item .btn-danger {
        justify-self: start;
    }

    .totals-container {
        max-width: 100%;
    }

    .totals-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .generate-section {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-large {
        width: 100%;
    }

    .template-actions {
        flex-direction: column;
    }

    .template-actions .btn {
        width: 100%;
    }

    /* Modal Responsive */
    .modal {
        padding: 10px;
    }

    .modal-content {
        margin: 20px auto;
    }

    .invoice-preview {
        padding: 20px;
    }

    .invoice-header {
        flex-direction: column;
    }

    .invoice-details {
        text-align: left;
    }

    .invoice-parties {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .invoice-items-table {
        font-size: 0.85rem;
    }

    .invoice-items-table th,
    .invoice-items-table td {
        padding: 10px 8px;
    }

    .invoice-totals {
        width: 100%;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.25rem;
    }

    .form-section {
        padding: 12px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .invoice-title {
        font-size: 1.5rem;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    header,
    .template-actions,
    .generate-section,
    footer,
    .modal-close,
    .modal-actions {
        display: none !important;
    }

    .modal {
        position: static;
        background: none;
        padding: 0;
    }

    .modal-content {
        box-shadow: none;
        margin: 0;
        max-height: none;
    }

    .invoice-preview {
        padding: 0;
    }
}
