/**
 * Consolidated styles for the generic entity module
 * Optimized for compact buttons without line breaks
 * With permanent scrollbar for table displays
 * CSS Variables sind in styles_variables.css definiert
 */

/* ===== SCROLLBAR FIX ===== */
/* View containers - allow natural expansion and scrolling */
#prompts-view, #files-view, #mandates-view, #users-view, #workflows-view, #automations-view, .module-wrapper {
    display: flex;
    flex-direction: column;
    /* Removed height: 100% to allow natural expansion and scrolling */
    overflow: visible;
}

/* Card containers for list views */
.card {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: visible;
    padding: 1rem;
    max-height: calc(100vh - 150px); /* Ensure card doesn't exceed viewport */
}

/* List containers - direct parent of the entity table */
#prompts-list, #mandates-list-container, #users-list-container, .files-list-container, #workflows-list, #automations-list {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: visible;
    min-height: 200px;
    max-height: calc(100vh - 200px); /* Ensure it doesn't exceed viewport */
}

/* Module content - allow natural expansion, scrolling handled by parent .module-container */
.module-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    /* No height restrictions - allow natural expansion */
    overflow: visible;
    /* Remove max-height to allow scrolling via parent container */
}

/* Entity table wrapper - ensure it fills available space */
.entity-table-wrapper {
    background: var(--color-bg);
    border-radius: 25px;
    box-shadow: inset 0 0 0 1px rgba(199,197,178,.15), 0 0 10px rgba(0, 0, 0, 0.1);
    padding: 16px;
    margin: 16px 0;
    border: 1px solid rgba(199,197,178,.15);
}

/* Entity actions - ensure they don't grow or shrink */
.entity-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
}

/* THE KEY FIX: Entity table container - ALWAYS show vertical scrollbar */
.entity-table-container {
    flex: 1;
    overflow-x: auto !important;
    overflow-y: auto !important;
    scrollbar-width: thin;
    border: none;
    border-radius: 15px;
    margin-bottom: 8px;
    min-height: 200px;
    max-height: calc(100vh - 300px); /* Prevent table from exceeding viewport */
    position: relative;
}

/* Custom scrollbar styling for WebKit browsers */
.entity-table-container::-webkit-scrollbar {
    width: 10px;
}

.entity-table-container::-webkit-scrollbar-track {
    background: var(--color-surface);
    border-radius: 0 0.25rem 0.25rem 0;
}

.entity-table-container::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 5px;
}

.entity-table-container::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary-hover);
}

/* ===== ENTITY TABLE STYLES ===== */
.entity-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    table-layout: fixed;
    min-width: 600px; /* Ensure table has minimum width for proper scrolling */
}

.entity-table th {
    background: var(--color-primary);
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--color-bg);
    border-bottom: 2px solid var(--color-primary-hover);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--font-family);
}

.entity-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-medium-gray);
    color: var(--color-text);
    transition: background-color 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px; /* Prevent cells from becoming too wide */
    font-family: var(--font-family);
}

.entity-table tr:hover td {
    background-color: var(--color-highlight-gray);
}

.entity-table .entity-actions-cell {
    white-space: nowrap;
    /* Width is set dynamically via inline styles based on action count */
}

/* ===== ENTITY ACTIONS ===== */
.entity-bulk-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.entity-selection-count {
    color: #757575;
    font-size: 14px;
}

.entity-filter {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.entity-search {
    width: 100%;
    padding: 12px 16px;
    padding-left: 40px;
    border: 1px solid var(--color-gray-disabled);
    border-radius: 25px;
    font-size: 14px;
    transition: all 0.2s ease;
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-family);
}

.entity-search:focus {
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 2px rgba(242, 88, 67, 0.1);
    outline: none;
}

.entity-filter i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-gray);
}

/* Action buttons - using base .btn-icon styles from styles_base.css */
/* All entity-*-btn classes are now defined in styles_base.css alongside .btn-icon */
/* Only specific overrides are defined below if needed */

/* ===== ENTITY MODAL STYLES ===== */
.entity-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1002;
}

.entity-modal-content {
    background: var(--color-bg);
    border-radius: 25px;
    box-shadow: inset 0 0 0 1px rgba(199,197,178,.15), 0 0 10px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(199,197,178,.15);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.entity-modal-header {
    padding: 12px 16px;
    background: var(--color-primary);
    border-bottom: 2px solid var(--color-primary-hover);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 25px 25px 0 0;
}

.entity-modal-header h3 {
    margin: 0;
    color: var(--color-bg);
    font-size: 18px;
    font-weight: 600;
    font-family: var(--font-family);
}

.entity-modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--color-bg);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 15px;
}

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

.entity-modal-body {
    padding: 16px;
}

.entity-modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--color-medium-gray);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Modal buttons */
.entity-modal-save,
.entity-modal-cancel {
    padding: 8px 16px;
    border-radius: 25px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-family);
}

.entity-modal-save {
    background: var(--color-secondary);
    color: var(--color-bg);
    border: none;
}

.entity-modal-save:hover {
    background: var(--color-secondary-hover);
}

.entity-modal-cancel {
    background: var(--color-primary);
    color: var(--color-bg);
    border: 1px solid var(--color-primary-hover);
}

.entity-modal-cancel:hover {
    background: var(--color-primary-hover);
}

/* ===== ENTITY FORM STYLES ===== */
.entity-form {
    width: 100%;
}

.entity-form-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.entity-form-group {
    margin-bottom: 0;
}

.entity-form-group label {
    display: block;
    margin-bottom: 4px;
    color: var(--color-secondary);
    font-weight: 500;
    font-size: 14px;
    font-family: var(--font-family);
}

.entity-form-group input[type="text"],
.entity-form-group input[type="number"],
.entity-form-group input[type="datetime-local"],
.entity-form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--color-gray-disabled);
    border-radius: 25px;
    font-size: 14px;
    transition: all 0.2s ease;
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-family);
}

.entity-form-group input:focus,
.entity-form-group textarea:focus {
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 2px rgba(242, 88, 67, 0.1);
    outline: none;
}

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

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--color-secondary);
    font-weight: 500;
    font-size: 14px;
    font-family: var(--font-family);
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-gray-disabled);
    border-radius: 3px;
    cursor: pointer;
}

.field-disabled-notice {
    display: block;
    margin-top: 4px;
    color: var(--color-gray);
    font-size: 12px;
    font-style: italic;
    font-family: var(--font-family);
}

/* ===== ENTITY DETAILS STYLES ===== */
.entity-details {
    padding: 20px;
}

.entity-detail-row {
    display: flex;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--color-medium-gray);
    padding-bottom: 10px;
}

.entity-detail-label {
    font-weight: bold;
    width: 200px;
    color: var(--color-gray);
    font-family: var(--font-family);
}

.entity-detail-value {
    flex: 1;
    word-break: break-word;
}

/* ===== PAGINATION STYLES ===== */
.entity-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
}

.entity-page-prev,
.entity-page-next {
    background: none;
    border: 1px solid var(--color-gray-disabled);
    padding: 8px 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-family);
    color: var(--color-text);
}

.entity-page-prev:hover:not(:disabled),
.entity-page-next:hover:not(:disabled) {
    background: var(--color-highlight-gray);
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

.entity-page-prev:disabled,
.entity-page-next:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.entity-items-per-page {
    padding: 8px;
    border: 1px solid var(--color-gray-disabled);
    border-radius: 25px;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-family);
}

/* ===== EMPTY AND LOADING STATES ===== */
.entity-empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--color-gray);
    font-family: var(--font-family);
}

.entity-add-btn-empty {
    margin-top: 16px;
    padding: 10px 20px;
    background: var(--color-secondary);
    color: var(--color-bg);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-family);
    font-weight: 500;
}

.entity-add-btn-empty:hover {
    background: var(--color-secondary-hover);
}

.entity-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--color-gray);
    font-family: var(--font-family);
}

.entity-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-surface);
    border-top: 3px solid var(--color-secondary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== ERROR STATES ===== */
.entity-error {
    background-color: var(--color-red-disabled);
    color: var(--color-red);
    padding: 0.75rem;
    border-radius: 25px;
    margin-bottom: 1rem;
    border: 1px solid var(--color-red);
    font-family: var(--font-family);
}

.entity-retry-btn {
    background-color: var(--color-red);
    color: var(--color-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 25px;
    margin-top: 0.5rem;
    border: none;
    cursor: pointer;
    font-family: var(--font-family);
}

.entity-retry-btn:hover {
    background-color: var(--color-red-hover);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .entity-detail-row {
        flex-direction: column;
    }
    
    .entity-detail-label {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .entity-modal-content {
        width: 95%;
        margin: 1rem;
    }
}

/* Entity table actions */
.entity-actions-cell {
    white-space: nowrap;
    text-align: center;
    min-width: 80px; /* Minimum width, will be dynamically expanded based on action count */
    /* Width will be set dynamically via inline styles based on action count */
    overflow: visible; /* Ensure buttons are not clipped */
}

.entity-actions-cell button {
    background: none;
    border: none;
    padding: 4px 8px;
    cursor: pointer;
    transition: color 0.2s;
    border-radius: var(--radius-sm);
}

.entity-actions-cell button:hover {
    opacity: 0.8;
}

/* Add new styles for split delete button */
.entity-delete-btn-container {
    display: inline-flex;
    align-items: center;
    position: relative;
}

.entity-delete-confirm-container {
    display: none;
    gap: 4px;
    align-items: center;
}

.entity-delete-confirm-btn,
.entity-delete-cancel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    padding: 0;
    margin: 0 1px;
    min-width: 1.25rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
}

.entity-delete-confirm-btn {
    color: var(--color-secondary) !important;
}

.entity-delete-confirm-btn:hover {
    color: var(--color-secondary-hover) !important;
}

.entity-delete-cancel-btn {
    color: var(--color-red) !important;
}

.entity-delete-cancel-btn:hover {
    color: var(--color-red-hover) !important;
}

/* Sortable Headers */
th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    background: var(--color-highlight-gray);
}

th.sortable i {
    margin-left: 4px;
    font-size: 12px;
    opacity: 0.5;
}

th.sortable:hover i {
    opacity: 1;
}

/* ===== FILE TABLE STYLES ===== */
.entity-file-name {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-secondary);
    font-family: var(--font-family);
}

.entity-file-name i {
    font-size: 16px;
    color: var(--color-secondary);
}

.entity-file-size {
    color: var(--color-gray);
    font-size: 14px;
    font-family: var(--font-family);
}

.entity-file-date {
    color: var(--color-gray);
    font-size: 14px;
    font-family: var(--font-family);
}

/* File upload button */
.entity-upload-btn {
    background: var(--color-secondary);
    color: var(--color-bg);
    border: none;
    padding: 8px 16px;
    border-radius: 25px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-family: var(--font-family);
    font-weight: 500;
}

.entity-upload-btn:hover {
    background: var(--color-secondary-hover);
}

.entity-upload-btn i {
    font-size: 16px;
}

/* File preview is now handled by modal in styles_workflow_files.css */

/* Automation Execution Modal */
.automation-execution-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.automation-execution-modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.automation-execution-modal-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.automation-execution-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.automation-execution-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.automation-execution-modal-close:hover {
    color: #333;
}

.automation-execution-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.execution-status {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 16px;
    font-weight: 500;
}

.execution-status.status-info {
    background: #e3f2fd;
    color: #1976d2;
}

.execution-status.status-success {
    background: #e8f5e9;
    color: #388e3c;
}

.execution-status.status-danger {
    background: #ffebee;
    color: #d32f2f;
}

.execution-log {
    background: #f5f5f5;
    border-radius: 4px;
    padding: 12px;
    max-height: 400px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 13px;
}

.log-entry {
    margin-bottom: 8px;
    padding: 4px 0;
}

.log-time {
    color: #666;
    margin-right: 8px;
}

.log-message {
    color: #333;
}

.automation-execution-modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
}

/* Automation Logs Modal */
.automation-logs-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.automation-logs-modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.automation-logs-modal-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.automation-logs-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.automation-logs-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.automation-logs-modal-close:hover {
    color: #333;
}

.automation-logs-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.logs-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.log-item {
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 16px;
    background: #fafafa;
}

.log-item.completed {
    border-left: 4px solid #4caf50;
}

.log-item.error {
    border-left: 4px solid #f44336;
}

.log-item.running {
    border-left: 4px solid #2196f3;
}

.log-item-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.log-item-date {
    font-weight: 500;
    color: #333;
}

.log-item-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.log-item-workflow {
    color: #666;
    font-size: 13px;
}

.log-item-workflow code {
    background: #e0e0e0;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
}

.log-item-messages {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.log-message-item {
    padding: 8px;
    background: white;
    border-radius: 3px;
    font-size: 13px;
    color: #333;
}

.automation-logs-modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
}