/* public/css/invoices.css – Rechnungsverwaltung
 * Vollständige, korrigierte Version
 * Modal-Close-Button wie bei Reminder (schmal, 1.25rem, mit Hover)
 * Modal-Header mit Flexbox für konsistente Ausrichtung
 * 3‑Punkte‑Button jetzt genauso groß wie die anderen Aktionen
 */

/* ============================================================
   STATS CARDS
   ============================================================ */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    border-top: 4px solid var(--primary);
}

.stat-card:nth-child(1) {
    border-top-color: var(--success);
}
.stat-card:nth-child(2) {
    border-top-color: var(--warning);
}
.stat-card:nth-child(3) {
    border-top-color: var(--danger);
}
.stat-card:nth-child(4) {
    border-top-color: var(--info);
}

.stat-title {
    font-size: 0.8125rem;
    color: var(--gray-600);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ============================================================
   PAGE ACTIONS
   ============================================================ */
.page-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.search-filter {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    min-width: 250px;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius-md);
    font-size: 0.875rem;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-500);
}

.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius-md);
    background: #fff;
    font-size: 0.875rem;
    min-width: 140px;
}

.action-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ============================================================
   INVOICES TABLE
   ============================================================ */
.invoices-container {
    background: #fff;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border-top: 4px solid var(--purple);
}

.table-responsive {
    overflow-x: auto;
}

.invoices-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.invoices-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    white-space: nowrap;
    position: relative;
    cursor: pointer;
    user-select: none;
}

.invoices-table th:hover {
    background: rgba(67, 97, 238, 0.05);
}

.invoices-table th.sortable {
    padding-right: 30px;
}

.invoices-table th .sort-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    opacity: 0;
    transition: opacity 0.15s;
    font-size: 0.7rem;
}

.invoices-table th.active-sort .sort-arrow {
    opacity: 1;
}

.invoices-table th.sort-asc .sort-arrow::before {
    content: "↑";
}
.invoices-table th.sort-desc .sort-arrow::before {
    content: "↓";
}

.invoices-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}

.invoices-table tr:hover {
    background: rgba(67, 97, 238, 0.02);
}

.invoice-status {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    min-width: 80px;
}

.status-paid {
    background: rgba(76, 201, 240, 0.1);
    color: var(--success);
}

.status-pending {
    background: rgba(248, 150, 30, 0.1);
    color: var(--warning);
}

.status-overdue {
    background: rgba(247, 37, 133, 0.1);
    color: var(--danger);
}

/* ============================================================
   ACTION BUTTONS IN TABLE – alle gleich groß
   ============================================================ */
.action-buttons-cell {
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.75rem;
    border-radius: var(--border-radius-sm);
    min-height: 34px;
    min-width: 34px;
}

.btn-view {
    background: #f0f4ff;
    color: var(--primary);
    border: 1px solid #c7d2fe;
}
.btn-view:hover {
    background: #dde5ff;
}

.btn-edit {
    background: #fff7ed;
    color: var(--warning);
    border: 1px solid #fed7aa;
}
.btn-edit:hover {
    background: #ffedd5;
}

.btn-delete {
    background: #fff0f6;
    color: var(--danger);
    border: 1px solid #fbcfe8;
}
.btn-delete:hover {
    background: #fce7f3;
}

/* ─── 3‑Punkte‑Button – genauso groß wie die anderen ─── */
.more-actions-btn {
    background: none;
    border: 1px solid var(--gray-200);
    color: var(--gray-600);
    cursor: pointer;
    padding: 6px 14px;
    border-radius: var(--border-radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: all 0.15s;
    min-height: 34px;
    min-width: 34px;
}

.more-actions-btn:hover {
    background: var(--gray-200);
    color: var(--gray-900);
    border-color: var(--gray-300);
}

/* ============================================================
   PORTAL ACTION BADGES
   ============================================================ */
.portal-action-cell {
    white-space: nowrap;
}

.portal-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 0.7rem;
    cursor: default;
    margin-right: 3px;
    transition: transform 0.1s;
}

.portal-badge:hover {
    transform: scale(1.2);
}

.portal-badge-promise {
    background: #fef3c7;
    color: #d97706;
}

.portal-badge-dispute {
    background: #fdecea;
    color: #e03e3e;
}

/* ============================================================
   MODALS (Rechnung) – mit Flexbox-Header und korrigiertem Close-Button
   ============================================================ */
.modal-bg {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.2s,
        visibility 0.2s;
}

.modal-bg.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: #fff;
    border-radius: var(--border-radius-xl);
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    padding: 24px;
    transform: scale(0.96);
    transition: transform 0.2s;
}

.modal-bg.open .modal {
    transform: scale(1);
}

.modal.wide {
    max-width: 960px;
}

.modal.narrow {
    max-width: 600px;
}

/* ─── Modal Header (Flexbox) ─── */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e9ecef;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

/* ─── Close-Button (wie bei Reminder) ─── */
.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: #565656;
    padding: 4px 6px;
    line-height: 1;
    transition:
        color 0.2s,
        background 0.2s;
    border-radius: var(--border-radius-sm);
    flex-shrink: 0;
}

.modal-close:hover {
    color: #212529;
    background: var(--gray-100);
}

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}

/* ─── Formular im Modal ── */
#invoiceForm .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 4px;
}

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

#invoiceForm label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--gray-800);
}

#invoiceForm .form-control,
#invoiceForm input,
#invoiceForm select,
#invoiceForm textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius-md);
    font-size: 0.875rem;
    font-family: var(--font-family);
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
    background: #fff;
}

#invoiceForm .form-control:focus,
#invoiceForm input:focus,
#invoiceForm select:focus,
#invoiceForm textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

#invoiceForm textarea {
    resize: vertical;
    min-height: 60px;
}

.preview-row {
    display: flex;
    gap: 20px;
    background: var(--gray-50);
    padding: 12px;
    border-radius: var(--border-radius-md);
    margin-bottom: 16px;
    font-weight: 500;
    flex-wrap: wrap;
}

.preview-row span {
    flex: 1;
}

.char-counter {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-align: right;
    margin-top: 4px;
}

/* ============================================================
   DETAIL MODAL
   ============================================================ */
.idm-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    padding: 24px;
}

.idm-section-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 12px;
    color: var(--gray-800);
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 6px;
}

.idm-field-grid {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 8px 12px;
    margin-bottom: 16px;
}

.idm-label {
    font-size: 0.75rem;
    color: var(--gray-600);
    font-weight: 500;
}

.idm-value {
    font-size: 0.875rem;
    color: var(--gray-900);
    word-break: break-word;
}

.idm-value.idm-multiline {
    white-space: pre-wrap;
}

.idm-amount-box {
    background: var(--gray-50);
    border-radius: var(--border-radius-md);
    padding: 12px;
    margin: 16px 0;
}

.idm-amount-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    padding: 6px 0;
}

.idm-amount-total {
    font-weight: 700;
    border-top: 1px solid var(--gray-200);
    margin-top: 6px;
    padding-top: 8px;
    color: var(--primary);
}

.idm-client-box {
    background: var(--gray-50);
    border-radius: var(--border-radius-md);
    padding: 12px;
    margin-bottom: 20px;
}

.idm-action-entry {
    border-left: 3px solid var(--primary);
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--gray-50);
    border-radius: var(--border-radius-sm);
}

.idm-action-header {
    font-weight: 600;
    font-size: 0.8rem;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}

.idm-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.idm-badge-promise {
    background: var(--warning-bg);
    color: var(--warning);
}

.idm-badge-dispute {
    background: var(--danger-bg);
    color: var(--danger);
}

.idm-empty {
    text-align: center;
    color: var(--gray-500);
    padding: 20px 0;
}

/* ============================================================
   DROPDOWN MENU (3‑Punkte)
   ============================================================ */
.dropdown-menu-overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 2000;
    display: none;
}

.dropdown-menu-overlay.show {
    display: block;
}

.dropdown-menu {
    position: fixed;
    background: #fff;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 2001;
    min-width: 220px;
    display: none;
    overflow: hidden;
    border: 1px solid var(--gray-200);
    animation: slideIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.dropdown-menu.show {
    display: block;
}

.dropdown-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.dropdown-body {
    padding: 8px 0;
}

.dropdown-item {
    padding: 12px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    color: var(--gray-800);
    text-decoration: none;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: all 0.15s;
}

.dropdown-item:hover:not(:disabled) {
    background: var(--gray-50);
    padding-left: 26px;
}

.dropdown-item:disabled {
    color: var(--gray-400);
    cursor: not-allowed;
}

.dropdown-item .item-text {
    flex: 1;
}

.dropdown-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 8px 20px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-top: 1px solid var(--gray-200);
    flex-wrap: wrap;
    gap: 12px;
}

.pagination-info {
    font-size: 0.8rem;
    color: var(--gray-600);
}

.pagination-controls {
    display: flex;
    gap: 5px;
    align-items: center;
}

.pagination-btn {
    padding: 6px 12px;
    border: 1px solid var(--gray-300);
    background: #fff;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--gray-100);
    border-color: var(--gray-400);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ============================================================
   EXPORT DROPDOWN
   ============================================================ */
.export-dropdown {
    position: relative;
    display: inline-block;
}

.export-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
    min-width: 220px;
    z-index: 100;
    display: none;
    margin-top: 4px;
    overflow: hidden;
}

.export-menu.show {
    display: block;
}

.export-option {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    transition: all 0.15s;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-800);
    text-decoration: none;
}

.export-option:last-child {
    border-bottom: none;
}

.export-option:hover {
    background: var(--gray-50);
    padding-left: 20px;
}

.export-option.disabled {
    color: #ccc;
    cursor: not-allowed;
    background: #f9f9f9;
}

.export-option.disabled:hover {
    background: #f9f9f9;
    padding-left: 16px;
}

.export-divider {
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(0, 0, 0, 0.08),
        transparent
    );
    margin: 5px 16px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .page-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .search-filter {
        width: 100%;
    }
    .search-box {
        min-width: auto;
        flex: 1;
    }
    .action-buttons {
        justify-content: flex-end;
    }
    .invoices-table th,
    .invoices-table td {
        white-space: normal;
    }
    .modal.wide {
        max-width: 100%;
        margin: 10px;
    }
    .idm-layout {
        grid-template-columns: 1fr;
    }
    #invoiceForm .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }
    .pagination {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .pagination-controls {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .action-buttons-cell {
        flex-wrap: wrap;
        gap: 4px;
    }
    .btn-sm,
    .more-actions-btn {
        padding: 4px 8px;
        font-size: 0.7rem;
        min-height: 30px;
        min-width: 30px;
    }
}
