/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* Container */
.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background-color: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 500;
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #e74c3c;
}

.status-indicator.connected {
    background-color: #27ae60;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 1200px) {
    .main-content {
        grid-template-columns: 2fr 1fr;
    }
}

/* Section Headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.25rem;
    color: #2c3e50;
}

/* Scripts Grid */
.scripts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

/* Script Card */
.script-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.script-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.script-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 1rem;
}

.script-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.script-status {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.script-status.running {
    background-color: #d4edda;
    color: #155724;
}

.script-status.stopped {
    background-color: #f8d7da;
    color: #721c24;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
}

/* Script Info */
.script-info {
    margin-bottom: 1rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.9rem;
}

.info-label {
    color: #666;
}

.info-value {
    font-weight: 500;
}

/* Script Actions */
.script-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s;
    font-weight: 500;
}

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

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #2980b9;
}

.btn-success {
    background-color: #27ae60;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: #229954;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: #c0392b;
}

.btn-warning {
    background-color: #f39c12;
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background-color: #d68910;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #7f8c8d;
}

/* Log Controls */
.log-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#log-selector {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

/* Log Viewer */
.log-viewer {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 8px;
    padding: 1rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.log-entry {
    padding: 0.25rem 0;
    border-bottom: 1px solid #333;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-empty {
    color: #666;
    text-align: center;
    padding: 2rem;
}

/* Footer */
.footer {
    background-color: #34495e;
    color: #ecf0f1;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow-y: auto;
    padding: 2rem 0;
}

/* Ensure confirmation modal appears above script manager modal */
#modal {
    z-index: 2000;
}

.modal-content {
    background-color: white;
    margin: 2rem auto;
    padding: 0;
    border-radius: 8px;
    width: 80%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-close {
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
}

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

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
}

.toast {
    background: white;
    border-radius: 4px;
    padding: 1rem 1.5rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 250px;
    animation: slideIn 0.3s ease-out;
}

.toast.success {
    border-left: 4px solid #27ae60;
}

.toast.error {
    border-left: 4px solid #e74c3c;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Bulk Actions */
.bulk-actions {
    display: flex;
    gap: 0.5rem;
}

/* Statistics Bar */
.stats-bar {
    background: white;
    padding: 1rem 2rem;
    display: flex;
    gap: 2rem;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-label {
    color: #666;
    font-size: 0.9rem;
}

.stat-value {
    font-weight: 600;
    font-size: 1.1rem;
}

.stat-running {
    color: #27ae60;
}

.stat-stopped {
    color: #e74c3c;
}

/* Improve script card hover */
.script-card {
    position: relative;
    overflow: hidden;
}

.script-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: transparent;
    transition: background 0.3s;
}

.script-card:has(.script-status.running)::before {
    background: #27ae60;
}

.script-card:has(.script-status.stopped)::before {
    background: #e74c3c;
}

/* Add icons to buttons */
.btn-success::before {
    content: '▶ ';
}

.btn-danger::before {
    content: '■ ';
}

.btn-warning::before {
    content: '↻ ';
}

.btn-secondary::before {
    content: '📄 ';
}

.btn-primary::before {
    content: '↻ ';
}

/* Pulse animation for running status */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(39, 174, 96, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0);
    }
}

.script-status.running .status-dot {
    animation: pulse 2s infinite;
}

/* Smooth transitions */
.script-card,
.btn,
.stat-value {
    transition: all 0.3s ease;
}

/* Loading overlay */
.loading-overlay {
    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: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Confirmation dialog improvements */
.modal-content {
    animation: modalFadeIn 0.3s ease;
}

/* Standard modal should center properly */
.modal-content {
    margin: 2rem auto;
    position: relative;
    max-height: 90vh;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Better log viewer */
.log-viewer {
    position: relative;
}

.log-viewer::before {
    content: 'LOGS';
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 0.7rem;
    color: #666;
    letter-spacing: 1px;
}

/* Auto-scroll indicator */
.auto-scroll-indicator {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    background: #3498db;
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 3px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Script Manager Modal Styles */
.modal-large {
    max-width: 800px;
    max-height: 85vh;
}

.modal-medium {
    max-width: 600px;
    max-height: 80vh;
}

/* Fix for Script Manager Modal scrolling */
#script-manager-modal .modal-content {
    height: 85vh;
}

#script-manager-modal .modal-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Ensure sections don't overflow */
.script-manager-section {
    margin-bottom: 1rem;
    padding: 1rem;
    background-color: #f5f5f5;
    border-radius: 4px;
    flex-shrink: 0;
}

.script-manager-section h4 {
    margin-top: 0;
    margin-bottom: 1rem;
    color: #2c3e50;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.form-group input[type="text"] {
    width: calc(100% - 100px);
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    color: #333;
    margin-right: 0.5rem;
}

.form-group input[type="checkbox"] {
    margin-right: 0.5rem;
}

.form-group small {
    font-size: 0.85rem;
    color: #666;
    display: block;
    margin-top: 0.25rem;
}

.script-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0.5rem;
}

.script-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.script-item-info {
    flex: 1;
}

.script-item-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.script-item-path {
    font-size: 0.875rem;
    color: #666;
    font-family: monospace;
}

.script-item-actions {
    display: flex;
    gap: 0.5rem;
}

.browse-results {
    max-height: 250px;
    overflow-y: auto;
    margin-top: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0.5rem;
}

.browse-item {
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.browse-item:hover {
    background-color: #f5f5f5;
}

.directory-browser {
    border-top: 1px solid #ddd;
    margin-top: 2rem;
    padding-top: 2rem;
    flex-shrink: 0;
    background-color: #f9f9f9;
    border-radius: 4px;
    padding: 1rem;
}

.directory-browser h4 {
    margin-top: 0;
    color: #2c3e50;
}

.btn-info {
    background-color: #17a2b8;
    color: white;
}

.btn-info:hover:not(:disabled) {
    background-color: #138496;
}

/* Small button variant */
.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
}

/* Dark mode styles */
body.dark-mode {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode .header {
    background-color: #1e1e1e;
}

body.dark-mode .stats-bar,
body.dark-mode .script-card,
body.dark-mode .modal-content {
    background-color: #2a2a2a;
    color: #e0e0e0;
}

body.dark-mode .script-manager-section,
body.dark-mode .directory-browser {
    background-color: #333;
}

body.dark-mode .browse-item,
body.dark-mode .script-item {
    background-color: #2a2a2a;
    border-color: #444;
}

body.dark-mode .browse-item:hover {
    background-color: #3a3a3a;
}

body.dark-mode input[type="text"],
body.dark-mode select {
    background-color: #333;
    color: #e0e0e0;
    border-color: #444;
}

/* Directory Browser Styles */
.directory-browser {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.browser-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.browser-controls input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
}

.directory-contents {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    overflow-y: auto;
    min-height: 300px;
    max-height: 400px;
}

.browser-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
}

.browser-item:hover {
    background-color: #f5f5f5;
}

.browser-item.selected {
    background-color: #e3f2fd;
}

.browser-item.selected:hover {
    background-color: #bbdefb;
}

.browser-item-icon {
    margin-right: 0.75rem;
    font-size: 1.2rem;
}

.browser-item-name {
    flex: 1;
    font-family: monospace;
    font-size: 0.9rem;
}

.browser-item-type {
    color: #666;
    font-size: 0.85rem;
}

.browser-status {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #f5f5f5;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #666;
}

/* Directory browser dark mode */
body.dark-mode .directory-contents {
    background-color: #2a2a2a;
    border-color: #444;
}

body.dark-mode .browser-item {
    border-bottom-color: #333;
}

body.dark-mode .browser-item:hover {
    background-color: #333;
}

body.dark-mode .browser-item.selected {
    background-color: #1e3a5f;
}

body.dark-mode .browser-status {
    background-color: #333;
    color: #999;
}

body.dark-mode .form-group small {
    color: #999;
}

/* Responsive modal adjustments */
@media (max-height: 768px) {
    .modal {
        padding: 1rem 0;
    }
    
    .modal-content {
        margin: 1rem auto;
        max-height: 95vh;
    }
    
    #script-manager-modal .modal-content {
        height: 90vh;
    }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 1rem auto;
    }
    
    .modal-large {
        max-width: 95%;
    }
    
    .form-group input[type="text"] {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .form-group button {
        width: 100%;
    }
}

/* Ensure empty state messages are visible */
.browse-item:only-child {
    text-align: center;
    color: #666;
    font-style: italic;
    cursor: default;
}

.browse-item:only-child:hover {
    background-color: white;
}

/* Scrollbar styling for better visibility */
.script-list::-webkit-scrollbar,
.browse-results::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.script-list::-webkit-scrollbar-track,
.browse-results::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.script-list::-webkit-scrollbar-thumb,
.browse-results::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.script-list::-webkit-scrollbar-thumb:hover,
.browse-results::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: #555;
}