/* Custom properties for theme */
:root {
    --bg-main: #090d16;
    --bg-surface: rgba(21, 28, 46, 0.65);
    --bg-surface-solid: #151c2e;
    --bg-input: #0e1525;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(139, 92, 246, 0.3);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --primary-glow: rgba(139, 92, 246, 0.5);
    
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.1);
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Fira Code', "Courier New", Courier, monospace;
    
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Global styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.08) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.hidden {
    display: none !important;
}

/* Badge & Status Styles */
.badge {
    background: var(--primary-glow);
    border: 1px solid var(--primary);
    color: var(--text-primary);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
}
.status-dot.green { background-color: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.red { background-color: var(--danger); box-shadow: 0 0 8px var(--danger); }
.status-dot.purple { background-color: var(--primary); box-shadow: 0 0 8px var(--primary); }
.status-dot.yellow { background-color: var(--warning); box-shadow: 0 0 8px var(--warning); }

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.6; }
    100% { transform: scale(1); opacity: 1; }
}
.animate-pulse {
    animation: pulse 2s infinite ease-in-out;
}

/* Button UI Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    outline: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #6d28d9 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}
.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: #fca5a5;
}
.btn-danger:hover {
    background: var(--danger);
    color: white;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.2);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-icon {
    padding: 10px;
    line-height: 1;
}

/* App Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    background: rgba(9, 13, 22, 0.8);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 0 10px var(--primary));
}

.header-logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-logo .subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.header-status {
    display: flex;
    align-items: center;
    gap: 24px;
}

.status-item {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-item strong {
    color: var(--text-primary);
    margin-left: 4px;
}

/* Main Layout Grid */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-content {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 40px;
}

.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.controls-bar h2 {
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

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

/* Services Grid & Cards */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 24px;
}

.service-card {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: var(--transition);
    overflow: hidden;
}

.service-card:hover {
    transform: translateY(-4px);
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow: 0 8px 30px rgba(139, 92, 246, 0.15);
}

/* Glowing accent strip on top of cards based on status */
.service-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--border-color);
    transition: var(--transition);
}

.service-card.status-success::before { background: var(--success); }
.service-card.status-failed::before { background: var(--danger); }
.service-card.status-deploying::before { 
    background: linear-gradient(90deg, var(--primary) 0%, var(--info) 50%, var(--primary) 100%);
    background-size: 200% 100%;
    animation: loading-bar 1.5s infinite linear;
}
@keyframes loading-bar {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.card-title {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.card-title h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-title .provider-tag {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    color: var(--text-muted);
}
.card-title .provider-tag.gitlab { color: #fca5a5; }
.card-title .provider-tag.github { color: #93c5fd; }

.status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 6px;
}
.status-badge.success { background-color: var(--success-bg); color: #34d399; }
.status-badge.failed { background-color: var(--danger-bg); color: #f87171; }
.status-badge.deploying { background-color: var(--info-bg); color: #60a5fa; }
.status-badge.idle { background-color: rgba(255,255,255,0.05); color: var(--text-secondary); }

.card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.85rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dashed rgba(255,255,255,0.04);
}

.info-row span:first-child {
    color: var(--text-secondary);
}

.info-row span:last-child {
    font-family: var(--font-mono);
    color: var(--text-primary);
    max-width: 65%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.webhook-url-box {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    margin-top: 6px;
    overflow: hidden;
}

.webhook-url-box span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 8px;
    color: var(--text-secondary);
}

.btn-copy {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition);
}
.btn-copy:hover {
    color: var(--text-primary);
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.card-actions .btn {
    flex: 1;
}

/* Spinner / Loading States */
.loading-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
    gap: 16px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(139, 92, 246, 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal Structures */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 7, 12, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: var(--transition);
}

.modal-content {
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    overflow: hidden;
    animation: modal-enter 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modal-enter {
    from { transform: scale(0.9) translateY(20px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-lg {
    max-width: 1000px;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.highlight {
    color: var(--primary);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
}
.btn-close:hover {
    color: var(--text-primary);
}

/* Forms */
#service-form {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input, select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--border-glow);
}

.input-with-action {
    display: flex;
    gap: 8px;
}

.input-with-action input {
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 10px;
}

/* Discovery Panel */
.discovery-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    border: 1px solid var(--primary-glow);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 30px;
    animation: slide-down 0.3s ease-out;
}

@keyframes slide-down {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.panel-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.discovery-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.discovery-desc code {
    background: rgba(255,255,255,0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
}

.discovery-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.discovery-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    cursor: pointer;
    transition: var(--transition);
}

.discovery-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.1);
}

.discovery-card h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.discovery-card p {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    word-break: break-all;
    margin-bottom: 8px;
}

.discovery-card .discovered-services {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.discovered-services .svc-badge {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.discovered-services .svc-badge:hover {
    background: var(--primary-glow);
    border-color: var(--primary);
    color: var(--text-primary);
}

/* Logs and History Panel Layout */
.logs-container {
    display: flex;
    height: 550px;
}

.logs-sidebar {
    width: 250px;
    border-right: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.1);
}

.logs-sidebar h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.log-runs-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.log-run-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition);
    border: 1px solid transparent;
}

.log-run-item:hover {
    background: rgba(255,255,255,0.03);
}

.log-run-item.active {
    background: var(--primary-glow);
    border-color: rgba(139, 92, 246, 0.3);
}

.log-run-item .run-time {
    font-weight: 500;
    color: var(--text-primary);
}

.log-run-item .run-meta {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
}

.log-run-item .status-success { color: var(--success); }
.log-run-item .status-failed { color: var(--danger); }

/* Retro Terminal Styling */
.logs-terminal-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #06090f;
    overflow: hidden;
}

.terminal-header {
    background: #111827;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.terminal-dots {
    display: flex;
    gap: 6px;
}

.terminal-dots .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.terminal-dots .dot.red { background-color: var(--danger); }
.terminal-dots .dot.yellow { background-color: var(--warning); }
.terminal-dots .dot.green { background-color: var(--success); }

.terminal-title {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.terminal-output {
    flex: 1;
    padding: 20px;
    margin: 0;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: #e5e7eb;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.6;
}

/* Login Card styling */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    animation: modal-enter 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header .logo-icon {
    display: inline-block;
    margin-bottom: 16px;
}

.login-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-header p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.error-message {
    font-size: 0.8rem;
    color: #ef4444;
    margin-top: 12px;
    text-align: center;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #111827;
    border: 1px solid var(--primary);
    border-left: 4px solid var(--primary);
    color: var(--text-primary);
    padding: 14px 24px;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    z-index: 2000;
    font-size: 0.9rem;
    transform: translateY(0);
    opacity: 1;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
}

.toast.hidden {
    transform: translateY(20px);
    opacity: 0;
    display: none !important;
}

/* Responsive Queries */
@media(max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
        padding: 20px;
    }
    .header-status {
        width: 100%;
        justify-content: space-between;
    }
    .app-content {
        padding: 20px;
    }
    .controls-bar {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }
    .action-buttons {
        width: 100%;
    }
    .action-buttons .btn {
        flex: 1;
    }
    .services-grid {
        grid-template-columns: 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .logs-container {
        flex-direction: column;
        height: auto;
    }
    .logs-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 150px;
    }
    .logs-terminal-wrapper {
        height: 350px;
    }
}
