/* --- Audit Table Layout --- */
#audit-logs-table {
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
}

.data-table td,
.data-table th {
    vertical-align: middle;
    padding: 1rem;
    /* Match standard table padding */
    border-bottom: 1px solid var(--border-color);
    /* Match standard border color */
}

/* --- Columns --- */

/* 1. Date: 15%, Left */
#audit-logs-table th:nth-child(1),
#audit-logs-table td:nth-child(1) {
    width: 15%;
    text-align: left;
}

/* 2. User: 20%, Left */
#audit-logs-table th:nth-child(2),
#audit-logs-table td:nth-child(2) {
    width: 20%;
    text-align: left;
}

/* 3. Action: 10%, Center */
#audit-logs-table th:nth-child(3),
#audit-logs-table td:nth-child(3) {
    width: 10%;
    text-align: center;
}

/* 4. Target: 25%, Left, Truncate */
#audit-logs-table th:nth-child(4),
#audit-logs-table td:nth-child(4) {
    width: 25%;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 5. Details: 30%, Left (more space for changes) */
#audit-logs-table th:nth-child(5),
#audit-logs-table td:nth-child(5) {
    width: 30%;
    text-align: left;
}

/* --- User Column --- */
.user-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    background-color: #f0f0f0;
    color: var(--color-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.user-name {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.875rem;
    /* Slightly smaller than cell base for density */
}

/* --- Target Column --- */
.text-muted {
    color: var(--text-muted) !important;
}

.target-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    /* Match standard cell size */
    color: var(--text-main);
}

/* --- Date Column --- */
.date-cell {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.date-date {
    font-size: 0.875rem;
    color: var(--text-main);
    font-weight: 500;
}

.date-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Action Pills --- */
.pill {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.5;
}

.pill-create {
    background-color: #d1fae5;
    color: #047857;
}

.pill-update {
    background-color: #e0f2fe;
    color: #0369a1;
}

.pill-delete {
    background-color: #fee2e2;
    color: #b91c1c;
}

.pill-login {
    background-color: #f3f4f6;
    color: #4b5563;
}

/* --- Details Button --- */
.btn-ghost {
    background: transparent;
    border: none;
    color: var(--color-accent);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
}

.btn-ghost:hover {
    background-color: #eef2ff;
}

/* --- Modal & Diffs (Retained) --- */
.audit-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.audit-modal-content {
    background: var(--bg-card);
    width: 90%;
    max-width: 600px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    animation: slideIn 0.2s ease-out;
}

.audit-modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9fafb;
}

.audit-modal-header h3 {
    font-size: 1.25rem;
    margin: 0;
    color: var(--text-main);
}

.audit-modal-body {
    padding: 1.5rem;
    max-height: 70vh;
    overflow-y: auto;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.audit-diff {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.field-name {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.badge-old {
    color: #dc2626;
    text-decoration: line-through;
    background-color: #fef2f2;
}

.badge-new {
    color: #059669;
    font-weight: 600;
    background-color: #ecfdf5;
}

.icon-arrow {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.audit-list {
    margin: 0;
    padding-left: 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.audit-list li {
    margin-bottom: 0.25rem;
}

.payload-value {
    color: var(--text-main);
    font-weight: 500;
}

@keyframes slideIn {
    from {
        transform: translateY(10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* --- Mobile Responsiveness (Overrides `.data-table` defaults) --- */
@media (max-width: 768px) {
    #audit-logs-table td {
        font-size: 16px;
        /* WCAG readability minimum */
    }

    /* Reset specific widths to allow card layout */
    #audit-logs-table td:nth-child(1),
    #audit-logs-table td:nth-child(2),
    #audit-logs-table td:nth-child(3),
    #audit-logs-table td:nth-child(4),
    #audit-logs-table td:nth-child(5) {
        width: 100%;
        text-align: right;
        display: block;
        box-sizing: border-box;
    }

    #audit-logs-table td::before {
        display: block !important;
        width: 100%;
        margin-bottom: 0.5rem;
        white-space: nowrap;
        text-align: left;
    }

    /* Prevent truncation on Target and Details columns */
    #audit-logs-table td[data-label="Details"],
    #audit-logs-table td[data-label="Details"]>span,
    #audit-logs-table td[data-label="Details"] .text-muted,
    #audit-logs-table td[data-label="Target"],
    #audit-logs-table td[data-label="Target"]>span,
    #audit-logs-table td[data-label="Target"] .target-cell {
        white-space: pre-wrap !important;
        word-break: break-word;
        overflow: visible;
        text-overflow: clip;
    }

    #audit-logs-table td[data-label="Details"] {
        background-color: var(--bg-body, #f8fafc);
        border-radius: var(--radius-sm);
        padding: 0.75rem;
        margin-top: 0.5rem;
        border: 1px dashed var(--border-color);
        text-align: left;
    }

    .audit-diff {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        width: 100%;
        background: var(--bg-surface-light, #f9fafb);
        padding: 0.5rem;
        border-radius: 6px;
    }

    .badge {
        white-space: pre-wrap;
        word-break: break-word;
        width: 100%;
        box-sizing: border-box;
    }

    .icon-arrow {
        transform: rotate(90deg);
        margin: 0.25rem 0 0.25rem 1rem;
        align-self: flex-start;
    }
}