/* public/css/customers.css – Kundenverwaltung */

/* ============================================================
   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(--info);
}
.stat-card:nth-child(3) {
    border-top-color: var(--warning);
}
.stat-card:nth-child(4) {
    border-top-color: var(--danger);
}

.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;
}

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

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

.customers-table {
    width: 100%;
    min-width: 960px; /* verhindert gequetschte Spalten – horizontales Scrollen stattdessen */
    border-collapse: collapse;
    font-size: 0.875rem;
}
.customers-table td, .customers-table th {
    white-space: nowrap;
}

.customers-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;
}

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

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

.sort-indicator {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: var(--gray-500);
    opacity: 0;
    transition: opacity 0.15s;
}

.customers-table th.sorted .sort-indicator {
    opacity: 1;
    color: var(--primary);
}

.customers-table th.sorted-asc .sort-indicator::before {
    content: "↑";
}
.customers-table th.sorted-desc .sort-indicator::before {
    content: "↓";
}

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

/* ============================================================
   STATUS BADGES
   ============================================================ */
.status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-block;
}

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

.status-inactive {
    background: rgba(108, 117, 125, 0.1);
    color: var(--gray);
}

/* ============================================================
   PORTAL ACTION BADGES
   ============================================================ */
.portal-action-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
}

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

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

.portal-action-badge.none {
    color: var(--gray);
}

/* ============================================================
   ACTION BUTTONS
   ============================================================ */
.customer-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.action-btn {
    padding: 6px 10px;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
}

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

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

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

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

/* ============================================================
   PAGINATION (wie Invoices)
   ============================================================ */
.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-divider {
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(0, 0, 0, 0.08),
        transparent
    );
    margin: 5px 16px;
}

/* ============================================================
   MODALS
   ============================================================ */
.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: 800px;
    width: 90vw;
}

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

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-600);
    line-height: 1;
    padding: 4px;
    float: right;
}

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

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

.modal-footer .btn {
    padding: 10px 20px;
    border-radius: var(--border-radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}

.modal-footer .btn-secondary {
    background: var(--gray-100);
    color: var(--gray-800);
    border: 1px solid var(--gray-300);
}

.modal-footer .btn-secondary:hover {
    background: var(--gray-200);
}

.modal-footer .btn-primary {
    background: var(--primary);
    color: #fff;
}

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

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

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

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

#customerForm .form-control,
#customerForm input,
#customerForm select,
#customerForm 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;
}

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

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

/* ============================================================
   DETAIL MODAL (cdm)
   ============================================================ */
.cdm-data-label {
    font-weight: 500;
    color: var(--gray-600);
    font-size: 0.8rem;
}
.cdm-data-value {
    font-weight: 500;
    color: var(--gray-900);
    word-break: break-word;
}

.cdm-kpi-card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    border-left: 4px solid var(--primary);
}

.cdm-kpi-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: var(--gray-800);
}

.cdm-kpi-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--gray-100);
}

.cdm-kpi-row:last-child {
    border-bottom: none;
}

.cdm-kpi-value {
    font-weight: 600;
}
.cdm-kpi-value.cdm-risk-low {
    color: var(--success);
}
.cdm-kpi-value.cdm-risk-medium {
    color: var(--warning);
}
.cdm-kpi-value.cdm-risk-high {
    color: var(--danger);
}

.seg-btns {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.seg-btn {
    padding: 8px 16px;
    border: 2px solid transparent;
    border-radius: 24px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--gray-100);
    color: var(--gray-800);
    transition: all 0.15s;
}

.seg-btn:hover:not(:disabled) {
    background: var(--gray-200);
}

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

.seg-btn.seg-active.loyal {
    background: #2e7d32;
    border-color: #2e7d32;
}

.seg-btn.seg-active.normal {
    background: #1565c0;
    border-color: #1565c0;
}

.seg-btn.seg-active.problem {
    background: #c62828;
    border-color: #c62828;
}

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

.cdm-action-item {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 12px;
}

.cdm-action-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cdm-action-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

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

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

/* ============================================================
   EMPTY STATE
   ============================================================ */
.no-data-container {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray);
}

.no-data-icon {
    font-size: 48px;
    margin-bottom: 16px;
    color: #ddd;
}

.no-data-title {
    font-size: 18px;
    margin-bottom: 8px;
    font-weight: 600;
}

.no-data-description {
    font-size: 14px;
    margin-bottom: 20px;
}

/* ============================================================
   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;
    }
    .customers-table th,
    .customers-table td {
        white-space: normal;
    }
    .modal.wide {
        max-width: 100%;
        margin: 10px;
    }
    #cdm-content > div:first-child {
        grid-template-columns: 1fr;
    }
    #customerForm .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }
    .pagination {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .pagination-controls {
        justify-content: center;
    }
}

/* ============================================================
   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);
    }
}
