{% extends "base.html" %}

{% block title %}{{ _('Invoice') }} {{ invoice.invoice_number }} - TimeTracker{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <!-- Enhanced Header with Status Badge -->
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div class="d-flex align-items-center">
                    <h1 class="h3 mb-0 me-3">
                        <i class="fas fa-file-invoice-dollar text-primary"></i>
                        {{ _('Invoice') }} {{ invoice.invoice_number }}
                    </h1>
                    {% set status_config = {
                        'draft': {'color': 'secondary', 'icon': 'edit', 'bg': 'bg-secondary', 'label': _('Draft')},
                        'sent': {'color': 'info', 'icon': 'paper-plane', 'bg': 'bg-info', 'label': _('Sent')},
                        'paid': {'color': 'success', 'icon': 'check-circle', 'bg': 'bg-success', 'label': _('Paid')},
                        'overdue': {'color': 'danger', 'icon': 'exclamation-triangle', 'bg': 'bg-danger', 'label': _('Overdue')},
                        'cancelled': {'color': 'dark', 'icon': 'times-circle', 'bg': 'bg-dark', 'label': _('Cancelled')}
                    } %}
                    {% set config = status_config.get(invoice.status, status_config.draft) %}
                    <span class="status-badge-large {{ config.bg }} text-white">
                        <i class="fas fa-{{ config.icon }} me-2"></i>
                        {{ config.label }}
                    </span>
                </div>
                <div class="btn-group" role="group">
                    <a href="{{ url_for('invoices.edit_invoice', invoice_id=invoice.id) }}" class="btn btn-secondary">
                        <i class="fas fa-edit me-1"></i> {{ _('Edit') }}
                    </a>
                    
                    {% if invoice.payment_status != 'fully_paid' %}
                    <a href="{{ url_for('invoices.record_payment', invoice_id=invoice.id) }}" 
                       class="btn btn-success">
                        <i class="fas fa-money-bill-wave me-1"></i> {{ _('Record Payment') }}
                    </a>
                    {% endif %}
                    <div class="btn-group" role="group">
                        <button type="button" class="btn btn-info dropdown-toggle dropdown-toggle-split" 
                                data-bs-toggle="dropdown" aria-expanded="false">
                            <span class="visually-hidden">{{ _('Export options') }}</span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li>
                                <a class="dropdown-item" href="{{ url_for('invoices.export_invoice_csv', invoice_id=invoice.id) }}">
                                    <i class="fas fa-download me-2"></i> {{ _('Export CSV') }}
                                </a>
                            </li>
                            <li>
                                <a class="dropdown-item" href="{{ url_for('invoices.export_invoice_pdf', invoice_id=invoice.id) }}">
                                    <i class="fas fa-file-pdf me-2"></i> {{ _('Export PDF') }}
                                </a>
                            </li>
                        </ul>
                    </div>
                    <a href="{{ url_for('invoices.duplicate_invoice', invoice_id=invoice.id) }}" class="btn btn-outline-primary">
                        <i class="fas fa-copy me-1"></i> {{ _('Duplicate') }}
                    </a>
                    <a href="{{ url_for('invoices.list_invoices') }}" class="btn btn-outline-secondary">
                        <i class="fas fa-arrow-left me-1"></i> {{ _('Back') }}
                    </a>
                </div>
            </div>

            <!-- Invoice Overview Cards -->
            <div class="row mb-4">
                <div class="col-md-8">
                    <div class="card shadow-sm border-0">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="invoice-section">
                                        <h6 class="section-title text-primary mb-3">
                                            <i class="fas fa-user me-2"></i>{{ _('Bill To') }}
                                        </h6>
                                        <div class="client-details">
                                            <div class="client-name">{{ invoice.client_name }}</div>
                                            {% if invoice.client_email %}
                                            <div class="client-email">
                                                <i class="fas fa-envelope me-1 text-muted"></i>
                                                {{ invoice.client_email }}
                                            </div>
                                            {% endif %}
                                            {% if invoice.client_address %}
                                            <div class="client-address">
                                                <i class="fas fa-map-marker-alt me-1 text-muted"></i>
                                                {{ invoice.client_address|nl2br }}
                                            </div>
                                            {% endif %}
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="invoice-section">
                                        <h6 class="section-title text-primary mb-3">
                                            <i class="fas fa-info-circle me-2"></i>{{ _('Invoice Details') }}
                                        </h6>
                                        <div class="invoice-details">
                                            <div class="detail-row">
                                                <span class="detail-label">{{ _('Invoice #:') }}</span>
                                                <span class="detail-value">{{ invoice.invoice_number }}</span>
                                            </div>
                                            <div class="detail-row">
                                                <span class="detail-label">{{ _('Project:') }}</span>
                                                <span class="detail-value">{{ invoice.project.name }}</span>
                                            </div>
                                            <div class="detail-row">
                                                <span class="detail-label">{{ _('Issue Date:') }}</span>
                                                <span class="detail-value">{{ invoice.issue_date.strftime('%B %d, %Y') }}</span>
                                            </div>
                                            <div class="detail-row">
                                                <span class="detail-label">{{ _('Due Date:') }}</span>
                                                <span class="detail-value {% if invoice.is_overdue %}text-danger{% endif %}">
                                                    {{ invoice.due_date.strftime('%B %d, %Y') }}
                                                    {% if invoice.is_overdue %}
                                                        <span class="badge bg-danger ms-2">
                                                            <i class="fas fa-exclamation-triangle me-1"></i>
                                                            {{ invoice.days_overdue }} {{ _('days overdue') }}
                                                        </span>
                                                    {% endif %}
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="col-md-4">
                    <div class="card shadow-sm border-0">
                        <div class="card-header bg-light py-3">
                            <h6 class="m-0 font-weight-bold text-primary">
                                <i class="fas fa-cog me-2"></i>{{ _('Status & Actions') }}
                            </h6>
                        </div>
                        <div class="card-body">
                            <div class="status-actions">
                                {% if invoice.status == 'draft' %}
                                <div class="mb-3">
                                    <a href="{{ url_for('invoices.generate_from_time', invoice_id=invoice.id) }}" 
                                       class="btn btn-primary w-100">
                                        <i class="fas fa-clock me-2"></i> {{ _('Generate from Time') }}
                                    </a>
                                </div>
                                {% endif %}
                                
                                <div class="mb-3">
                                    <button type="button" class="btn btn-outline-secondary w-100" 
                                            data-bs-toggle="modal" data-bs-target="#statusModal">
                                        <i class="fas fa-edit me-2"></i> {{ _('Change Status') }}
                                    </button>
                                </div>
                                
                                <div class="info-section">
                                    <div class="info-item">
                                        <div class="info-label">{{ _('Created by') }}</div>
                                        <div class="info-value">{{ invoice.creator.display_name }}</div>
                                    </div>
                                    <div class="info-item">
                                        <div class="info-label">{{ _('Created') }}</div>
                                        <div class="info-value">{{ invoice.created_at.strftime('%B %d, %Y') }}</div>
                                    </div>
                                    <div class="info-item">
                                        <div class="info-label">{{ _('Last Modified') }}</div>
                                        <div class="info-value">{{ invoice.updated_at.strftime('%B %d, %Y') }}</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {% set tax_present = invoice.tax_rate > 0 %}
            <!-- Totals Summary -->
            <div class="row mb-4">
                <div class="{{ 'col-md-4' if tax_present else 'col-md-6' }}">
                    <div class="card summary-card border-0 shadow-sm">
                        <div class="card-body d-flex align-items-center">
                            <div class="summary-icon bg-primary text-white me-3"><i class="fas fa-coins"></i></div>
                            <div>
                                <div class="summary-label">{{ _('Subtotal') }}</div>
                                <div class="summary-value">{{ "%.2f"|format(invoice.subtotal) }} {{ currency }}</div>
                            </div>
                        </div>
                    </div>
                </div>
                {% if tax_present %}
                <div class="col-md-4">
                    <div class="card summary-card border-0 shadow-sm">
                        <div class="card-body d-flex align-items-center">
                            <div class="summary-icon bg-warning text-white me-3"><i class="fas fa-percent"></i></div>
                            <div>
                                <div class="summary-label">{{ _('Tax') }} ({{ "%.2f"|format(invoice.tax_rate) }}%)</div>
                                <div class="summary-value">{{ "%.2f"|format(invoice.tax_amount) }} {{ currency }}</div>
                            </div>
                        </div>
                    </div>
                </div>
                {% endif %}
                <div class="{{ 'col-md-4' if tax_present else 'col-md-6' }}">
                    <div class="card summary-card border-0 shadow-sm">
                        <div class="card-body d-flex align-items-center">
                            <div class="summary-icon bg-success text-white me-3"><i class="fas fa-sack-dollar"></i></div>
                            <div>
                                <div class="summary-label">{{ _('Total Amount') }}</div>
                                <div class="summary-value text-success">{{ "%.2f"|format(invoice.total_amount) }} {{ currency }}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Payment Status Summary -->
            <div class="row mb-4">
                <div class="col-md-3 col-sm-6 mb-3">
                    <div class="card summary-card border-0 shadow-sm">
                        <div class="card-body d-flex align-items-center">
                            <div class="summary-icon bg-success text-white me-3"><i class="fas fa-money-bill-wave"></i></div>
                            <div>
                                <div class="summary-label">{{ _('Amount Paid') }}</div>
                                <div class="summary-value text-success">{{ "%.2f"|format(invoice.amount_paid or 0) }} {{ currency }}</div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="col-md-3 col-sm-6 mb-3">
                    <div class="card summary-card border-0 shadow-sm">
                        <div class="card-body d-flex align-items-center">
                            <div class="summary-icon bg-warning text-white me-3"><i class="fas fa-exclamation-circle"></i></div>
                            <div>
                                <div class="summary-label">{{ _('Outstanding') }}</div>
                                <div class="summary-value text-warning">{{ "%.2f"|format(invoice.outstanding_amount) }} {{ currency }}</div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="col-md-3 col-sm-6 mb-3">
                    <div class="card summary-card border-0 shadow-sm">
                        <div class="card-body d-flex align-items-center">
                            {% if invoice.payment_status == 'unpaid' %}
                                <div class="summary-icon bg-danger text-white me-3"><i class="fas fa-times-circle"></i></div>
                            {% elif invoice.payment_status == 'partially_paid' %}
                                <div class="summary-icon bg-warning text-white me-3"><i class="fas fa-clock"></i></div>
                            {% elif invoice.payment_status == 'fully_paid' %}
                                <div class="summary-icon bg-success text-white me-3"><i class="fas fa-check-circle"></i></div>
                            {% elif invoice.payment_status == 'overpaid' %}
                                <div class="summary-icon bg-info text-white me-3"><i class="fas fa-plus-circle"></i></div>
                            {% endif %}
                            <div>
                                <div class="summary-label">{{ _('Payment Status') }}</div>
                                <div class="summary-value">
                                    {% if invoice.payment_status == 'unpaid' %}
                                        <span class="text-danger">{{ _('Unpaid') }}</span>
                                    {% elif invoice.payment_status == 'partially_paid' %}
                                        <span class="text-warning">{{ _('Partially Paid') }}</span>
                                    {% elif invoice.payment_status == 'fully_paid' %}
                                        <span class="text-success">{{ _('Fully Paid') }}</span>
                                    {% elif invoice.payment_status == 'overpaid' %}
                                        <span class="text-info">{{ _('Overpaid') }}</span>
                                    {% endif %}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="col-md-3 col-sm-6 mb-3">
                    <div class="card summary-card border-0 shadow-sm">
                        <div class="card-body">
                            <div class="summary-label mb-2">{{ _('Payment Progress') }}</div>
                            <div class="progress" style="height: 8px;">
                                <div class="progress-bar bg-success" 
                                     role="progressbar" 
                                     style="width: {{ invoice.payment_percentage }}%"
                                     aria-valuenow="{{ invoice.payment_percentage }}" 
                                     aria-valuemin="0" 
                                     aria-valuemax="100">
                                </div>
                            </div>
                            <small class="text-muted">{{ "%.1f"|format(invoice.payment_percentage) }}% {{ _('paid') }}</small>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Payment Details -->
            {% if invoice.payment_date or invoice.payment_method or invoice.payment_reference or invoice.payment_notes %}
            <div class="row mb-4">
                <div class="col-12">
                    <div class="card shadow-sm border-0">
                        <div class="card-header bg-light">
                            <h5 class="mb-0">
                                <i class="fas fa-receipt me-2"></i>
                                {{ _('Payment Details') }}
                            </h5>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                {% if invoice.payment_date %}
                                <div class="col-md-3">
                                    <div class="payment-detail">
                                        <span class="detail-label">{{ _('Payment Date:') }}</span>
                                        <span class="detail-value">{{ invoice.payment_date.strftime('%B %d, %Y') }}</span>
                                    </div>
                                </div>
                                {% endif %}
                                
                                {% if invoice.payment_method %}
                                <div class="col-md-3">
                                    <div class="payment-detail">
                                        <span class="detail-label">{{ _('Payment Method:') }}</span>
                                        <span class="detail-value">
                                            {% if invoice.payment_method == 'cash' %}{{ _('Cash') }}
                                            {% elif invoice.payment_method == 'check' %}{{ _('Check') }}
                                            {% elif invoice.payment_method == 'bank_transfer' %}{{ _('Bank Transfer') }}
                                            {% elif invoice.payment_method == 'credit_card' %}{{ _('Credit Card') }}
                                            {% elif invoice.payment_method == 'debit_card' %}{{ _('Debit Card') }}
                                            {% elif invoice.payment_method == 'paypal' %}{{ _('PayPal') }}
                                            {% elif invoice.payment_method == 'stripe' %}{{ _('Stripe') }}
                                            {% elif invoice.payment_method == 'wire_transfer' %}{{ _('Wire Transfer') }}
                                            {% else %}{{ invoice.payment_method|title }}{% endif %}
                                        </span>
                                    </div>
                                </div>
                                {% endif %}
                                
                                {% if invoice.payment_reference %}
                                <div class="col-md-3">
                                    <div class="payment-detail">
                                        <span class="detail-label">{{ _('Payment Reference:') }}</span>
                                        <span class="detail-value">{{ invoice.payment_reference }}</span>
                                    </div>
                                </div>
                                {% endif %}
                            </div>
                            
                            {% if invoice.payment_notes %}
                            <div class="row mt-3">
                                <div class="col-12">
                                    <div class="payment-detail">
                                        <span class="detail-label">{{ _('Payment Notes:') }}</span>
                                        <div class="detail-value">{{ invoice.payment_notes|nl2br }}</div>
                                    </div>
                                </div>
                            </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
            {% endif %}

            <!-- Enhanced Invoice Items -->
            <div class="row mb-4">
                <div class="col-12">
                    <div class="card shadow-sm border-0">
                        <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
                            <h6 class="m-0 font-weight-bold text-primary d-flex align-items-center">
                                <i class="fas fa-list me-2"></i>{{ _('Invoice Items') }}
                                <span class="badge badge-soft-secondary ms-2">{{ invoice.items.count() }} {{ _('items') }}</span>
                            </h6>
                            {% if invoice.status == 'draft' %}
                            <a href="{{ url_for('invoices.edit_invoice', invoice_id=invoice.id) }}" class="btn btn-sm btn-outline-primary">
                                <i class="fas fa-edit me-2"></i> {{ _('Edit Items') }}
                            </a>
                            {% endif %}
                        </div>
                        <div class="card-body p-0">
                            {% if invoice.items.count() > 0 %}
                                <div class="table-responsive">
                                    <table class="table table-hover mb-0">
                                        <thead class="table-light">
                                            <tr>
                                                <th class="border-0 ps-3">{{ _('Description') }}</th>
                                                <th class="border-0 text-center">{{ _('Quantity (Hours)') }}</th>
                                                <th class="border-0 text-end">{{ _('Unit Price') }}</th>
                                                <th class="border-0 text-end pe-3">{{ _('Total Amount') }}</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {% for item in invoice.items %}
                                            <tr class="item-row">
                                                <td class="ps-3">
                                                    <div class="item-description">
                                                        <div class="item-text">{{ item.description }}</div>
                                                        {% if item.time_entry_ids %}
                                                        <div class="item-meta">
                                                            <i class="fas fa-clock text-info me-1"></i> 
                                                            {{ _('Generated from') }} {{ item.time_entry_ids.split(',')|length }} {{ _('time entries') }}
                                                        </div>
                                                        {% endif %}
                                                    </div>
                                                </td>
                                                <td class="text-center">
                                                    <span class="quantity-badge">{{ "%.2f"|format(item.quantity) }}h</span>
                                                </td>
                                                <td class="text-end">
                                                    <span class="unit-price">{{ "%.2f"|format(item.unit_price) }} {{ currency }}</span>
                                                </td>
                                                <td class="text-end pe-3">
                                                    <span class="item-total">{{ "%.2f"|format(item.total_amount) }} {{ currency }}</span>
                                                </td>
                                            </tr>
                                            {% endfor %}
                                        </tbody>
                                        <tfoot class="table-light">
                                            <tr>
                                                <td colspan="3" class="text-end ps-3">
                                                    <strong>{{ _('Subtotal:') }}</strong>
                                                </td>
                                                <td class="text-end pe-3">
                                                    <strong>{{ "%.2f"|format(invoice.subtotal) }} {{ currency }}</strong>
                                                </td>
                                            </tr>
                                            {% if invoice.tax_rate > 0 %}
                                            <tr>
                                                <td colspan="3" class="text-end ps-3">
                                                    <strong>{{ _('Tax') }} ({{ "%.2f"|format(invoice.tax_rate) }}%):</strong>
                                                </td>
                                                <td class="text-end pe-3">
                                                    <strong>{{ "%.2f"|format(invoice.tax_amount) }} {{ currency }}</strong>
                                                </td>
                                            </tr>
                                            {% endif %}
                                            <tr class="table-primary">
                                                <td colspan="3" class="text-end ps-3">
                                                    <strong class="fs-5">{{ _('Total Amount:') }}</strong>
                                                </td>
                                                <td class="text-end pe-3">
                                                    <strong class="fs-5">{{ "%.2f"|format(invoice.total_amount) }} {{ currency }}</strong>
                                                </td>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            {% else %}
                                <div class="text-center py-5">
                                    <div class="empty-state">
                                        <i class="fas fa-list fa-3x text-muted mb-3"></i>
                                        <h5 class="text-muted">{{ _('No invoice items') }}</h5>
                                        <p class="text-muted mb-4">{{ _('Add items to this invoice to generate totals.') }}</p>
                                        {% if invoice.status == 'draft' %}
                                        <a href="{{ url_for('invoices.edit_invoice', invoice_id=invoice.id) }}" class="btn btn-primary">
                                            <i class="fas fa-plus me-2"></i> {{ _('Add Items') }}
                                        </a>
                                        {% endif %}
                                    </div>
                                </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>

            <!-- Additional Information -->
            {% if invoice.notes or invoice.terms %}
            <div class="row mb-4">
                <div class="col-12">
                    <div class="card shadow-sm border-0">
                        <div class="card-header bg-white py-3">
                            <h6 class="m-0 font-weight-bold text-primary">
                                <i class="fas fa-file-text me-2"></i>{{ _('Additional Information') }}
                            </h6>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                {% if invoice.notes %}
                                <div class="col-md-6">
                                    <h6 class="text-primary mb-3">{{ _('Notes') }}</h6>
                                    <div class="content-box">
                                        {{ invoice.notes|nl2br }}
                                    </div>
                                </div>
                                {% endif %}
                                {% if invoice.terms %}
                                <div class="col-md-6">
                                    <h6 class="text-primary mb-3">{{ _('Terms & Conditions') }}</h6>
                                    <div class="content-box">
                                        {{ invoice.terms|nl2br }}
                                    </div>
                                </div>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {% endif %}
        </div>
    </div>
</div>

<!-- Status Change Modal -->
<div class="modal fade" id="statusModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">{{ _('Change Invoice Status') }}</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <form method="POST" action="{{ url_for('invoices.update_invoice_status', invoice_id=invoice.id) }}">
                    <div class="mb-3">
                        <label for="new_status" class="form-label">{{ _('New Status') }}</label>
                        <select class="form-select" id="new_status" name="new_status" required>
                            <option value="draft" {% if invoice.status == 'draft' %}selected{% endif %}>{{ _('Draft') }}</option>
                            <option value="sent" {% if invoice.status == 'sent' %}selected{% endif %}>{{ _('Sent') }}</option>
                            <option value="paid" {% if invoice.status == 'paid' %}selected{% endif %}>{{ _('Paid') }}</option>
                            <option value="cancelled" {% if invoice.status == 'cancelled' %}selected{% endif %}>{{ _('Cancelled') }}</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label for="status_notes" class="form-label">{{ _('Notes (Optional)') }}</label>
                        <textarea class="form-control" id="status_notes" name="status_notes" rows="3" 
                                  placeholder="{{ _('Add any notes about this status change...') }}"></textarea>
                    </div>
                    <div class="d-flex justify-content-end gap-2">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ _('Cancel') }}</button>
                        <button type="submit" class="btn btn-primary">{{ _('Update Status') }}</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<style>
.payment-detail {
    margin-bottom: 1rem;
}

.payment-detail .detail-label {
    font-weight: 600;
    color: #6c757d;
    display: block;
    margin-bottom: 0.25rem;
}

.payment-detail .detail-value {
    font-weight: 500;
    color: #495057;
}
.status-badge-large {
    padding: 8px 16px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.invoice-section {
    padding: 16px 0;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
}

.client-details .client-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.client-email, .client-address {
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-size: 14px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-label {
    font-weight: 600;
    color: var(--text-secondary);
}

.detail-value {
    font-weight: 600;
    color: var(--text-primary);
}

.status-actions .btn {
    margin-bottom: 12px;
}

.info-section {
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

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

.info-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.item-row {
    transition: background-color 0.2s ease;
}

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

.item-description .item-text {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.item-description .item-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.quantity-badge {
    background: var(--primary-color);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.unit-price {
    font-weight: 600;
    color: var(--text-secondary);
}

.item-total {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 16px;
}

.content-box {
    background: var(--light-color);
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    line-height: 1.6;
}

.empty-state {
    padding: 2rem;
}

.empty-state i {
    opacity: 0.5;
}

.summary-card .summary-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 0.4px;
}

.summary-card .summary-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-primary);
}

.summary-card .summary-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}

@media (max-width: 768px) {
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        margin-bottom: 8px;
        border-radius: 6px !important;
    }
    
    .detail-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .status-badge-large {
        font-size: 12px;
        padding: 6px 12px;
    }
}
</style>
{% endblock %}

{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
    // Add hover effects to item rows
    const itemRows = document.querySelectorAll('.item-row');
    itemRows.forEach(function(row) {
        row.addEventListener('mouseenter', function() {
            this.classList.add('table-active');
        });
        row.addEventListener('mouseleave', function() {
            this.classList.remove('table-active');
        });
    });
    
    // Status change confirmation
    const statusForm = document.querySelector('#statusModal form');
    if (statusForm) {
        statusForm.addEventListener('submit', function(e) {
            const newStatusField = document.getElementById('new_status');
            const newStatus = newStatusField ? newStatusField.value : '';
            const currentStatus = '{{ invoice.status }}';
            
            if (newStatus === currentStatus) {
                e.preventDefault();
                alert('{{ _('The selected status is the same as the current status.') }}');
                return false;
            }
            
            if (newStatus === 'cancelled') {
                if (!confirm('{{ _('Are you sure you want to cancel this invoice? This action cannot be undone.') }}')) {
                    e.preventDefault();
                    return false;
                }
            }
        });
    }
});
</script>
{% endblock %}
