@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Fira+Code:wght@400;500&display=swap');

:root {
    --bg-primary: #0b0f19;
    --bg-secondary: rgba(17, 24, 39, 0.7);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --border-glass: rgba(255, 255, 255, 0.06);
    
    --accent-blue: #3b82f6;
    --accent-blue-glow: rgba(59, 130, 246, 0.15);
    
    --status-running: #10b981;
    --status-running-glow: rgba(16, 185, 129, 0.2);
    
    --status-stopped: #ef4444;
    --status-stopped-glow: rgba(239, 68, 68, 0.2);
    
    --status-pending: #f59e0b;
    --status-pending-glow: rgba(245, 158, 11, 0.2);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --sidebar-width: 280px;
    --border-radius: 16px;
    --transition-speed: 0.3s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.03) 0%, transparent 40%);
    background-attachment: fixed;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-glass);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 10;
    overflow-y: auto;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-blue), #8b5cf6);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

.logo-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 10px;
    flex-shrink: 0;
    display: block;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #ffffff;
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    -webkit-text-fill-color: #ffffff;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    transition: all var(--transition-speed);
    border: 1px solid transparent;
}

.nav-item a:hover, .nav-item.active a {
    color: #ffffff;
    background: var(--bg-glass);
    border-color: var(--border-glass);
}

.nav-item.active a {
    border-color: rgba(59, 130, 246, 0.3);
    background: linear-gradient(to right, rgba(59, 130, 246, 0.1), transparent);
}

.sidebar-footer {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Main Content Area — avoid flex overflow clipping the right side */
.main-content {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: var(--sidebar-width);
    padding: 2.5rem;
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    box-sizing: border-box;
    overflow-x: hidden;
}

.header-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-title {
    min-width: 0;
    flex: 1 1 220px;
}

.header-title h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    overflow-wrap: anywhere;
}

.header-title p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    overflow-wrap: anywhere;
}

/* Glassmorphism Card Wrapper */
.glass-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius);
    padding: 1.75rem;
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-speed);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 4px 14px var(--accent-blue-glow);
}

.btn-primary:hover {
    background: #2563eb;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.3);
}

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

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-success {
    background: var(--status-running);
    color: #ffffff;
    box-shadow: 0 4px 14px var(--status-running-glow);
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--status-stopped);
    color: #ffffff;
    box-shadow: 0 4px 14px var(--status-stopped-glow);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* Grid Layout for Bots */
.bots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2.5rem;
}

.bot-card {
    position: relative;
    overflow: hidden;
    padding: 1.35rem 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.bot-card:hover {
    transform: none;
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.bot-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.1rem;
}

.bot-info {
    min-width: 0;
    flex: 1;
}

.bot-title-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.2rem;
}

.bot-title-row h3 {
    margin-bottom: 0;
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.bot-service {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: block;
    word-break: break-all;
    padding-left: 1.55rem;
    font-family: 'Fira Code', monospace;
}

.bot-header-badges {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
    flex-shrink: 0;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-running {
    background: rgba(16, 185, 129, 0.12);
    color: var(--status-running);
    border: 1px solid rgba(16, 185, 129, 0.28);
}

.status-stopped {
    background: rgba(239, 68, 68, 0.12);
    color: var(--status-stopped);
    border: 1px solid rgba(239, 68, 68, 0.28);
}

.status-pending {
    background: rgba(245, 158, 11, 0.12);
    color: var(--status-pending);
    border: 1px solid rgba(245, 158, 11, 0.28);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: currentColor;
    display: inline-block;
}

.status-running .status-dot {
    box-shadow: 0 0 8px var(--status-running);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.5; }
}

.bot-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
    margin-bottom: 0.85rem;
}

.metric {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border-glass);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    min-width: 0;
}

.metric-label {
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.metric-value {
    display: block;
    font-size: 0.92rem;
    font-weight: 650;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.port-value-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    max-width: 100%;
}

.port-value {
    font-weight: 650;
    color: var(--text-primary);
}

.btn-edit-port {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.1rem 0.2rem;
    line-height: 1;
    border-radius: 4px;
}

.btn-edit-port:hover {
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.12);
}

.port-badge-status {
    font-size: 0.65rem !important;
    padding: 0.1rem 0.35rem !important;
    border-radius: 4px;
    font-weight: 600;
}

.bot-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.65rem;
    margin-bottom: 1rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
}

.bot-meta span:not(:last-child)::after {
    content: '·';
    margin-left: 0.65rem;
    color: rgba(255, 255, 255, 0.15);
    font-weight: 400;
}

.bot-actions {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.bot-actions-primary {
    width: 100%;
    margin-bottom: 0.35rem;
}

.bot-actions-primary .btn {
    flex: 1 1 0;
    min-width: 0;
}

.bot-actions-primary .btn-start,
.bot-actions-primary .btn-stop {
    flex: 1.35 1 0;
}

.bot-more {
    margin-top: 0.15rem;
    border-top: 1px solid var(--border-glass);
    padding-top: 0.55rem;
}

.bot-more summary {
    list-style: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 550;
    user-select: none;
    padding: 0.2rem 0;
}

.bot-more summary::-webkit-details-marker {
    display: none;
}

.bot-more summary::after {
    content: ' ▾';
    font-size: 0.7rem;
    opacity: 0.7;
}

.bot-more[open] summary::after {
    content: ' ▴';
}

.bot-more summary:hover {
    color: var(--text-secondary);
}

.bot-actions-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.55rem;
}

.bot-link-btn {
    appearance: none;
    border: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 550;
    font-family: inherit;
    padding: 0.35rem 0.55rem;
    border-radius: 7px;
    text-decoration: none;
    cursor: pointer;
    line-height: 1.2;
}

.bot-link-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.12);
}

.bot-link-danger {
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.25);
}

.bot-link-danger:hover {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
}

.bot-last-error {
    margin-bottom: 0.85rem;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #fca5a5;
    font-size: 0.72rem;
    font-family: 'Fira Code', monospace;
    line-height: 1.45;
    word-break: break-word;
    max-height: 3.6em;
    overflow: hidden;
}

/* Compact list view */
.bots-grid.bots-view-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.bots-grid.bots-view-list .bot-card {
    padding: 1rem 1.15rem;
}

.bots-grid.bots-view-list .bot-header {
    margin-bottom: 0.75rem;
}

.bots-grid.bots-view-list .bot-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 0.65rem;
}

.bots-grid.bots-view-list .bot-meta {
    margin-bottom: 0.75rem;
}

/* List view: show secondary actions inline without needing More toggle */
.bots-grid.bots-view-list .bot-more {
    display: block;
}

.bots-grid.bots-view-list .bot-more summary {
    display: none;
}

.bots-grid.bots-view-list .bot-more .bot-actions-secondary {
    display: flex;
    margin-top: 0;
}

.bots-grid.bots-view-list .bot-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 0.65rem;
}

@media (max-width: 720px) {
    .bots-grid.bots-view-list .bot-metrics {
        grid-template-columns: 1fr 1fr;
    }
}

.detail-row {
    display: flex;
    justify-content: space-between;
}

.detail-label {
    color: var(--text-muted);
}

/* Dashboard toolbar */
.bots-toolbar {
    margin-bottom: 1.25rem;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.toolbar-actions {
    padding-top: 0.75rem;
    margin-top: 0.25rem;
    border-top: 1px solid var(--border-glass);
    width: 100%;
}

.toolbar-search {
    flex: 1 1 180px;
    min-width: 140px;
    max-width: 100%;
    padding: 0.55rem 0.85rem;
    font-size: 0.85rem;
}

.toolbar-filter {
    flex: 0 1 auto;
    width: auto;
    min-width: 140px;
    max-width: 100%;
    padding: 0.55rem 0.85rem;
    font-size: 0.85rem;
}

.filter-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

#btn-select-all {
    text-decoration: none !important;
    flex-shrink: 0;
}

.bot-select {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-blue);
    cursor: pointer;
    flex-shrink: 0;
}

.bot-card.bot-hidden {
    display: none;
}

.health-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.55rem;
    border-radius: 20px;
    font-size: 0.68rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.health-ok {
    background: rgba(16, 185, 129, 0.1);
    color: var(--status-running);
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.health-fail {
    background: rgba(239, 68, 68, 0.1);
    color: var(--status-stopped);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.view-toggle {
    display: inline-flex;
    gap: 0.25rem;
    background: rgba(0,0,0,0.2);
    padding: 0.2rem;
    border-radius: 10px;
    border: 1px solid var(--border-glass);
}

.view-toggle .view-btn.active {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.4);
    color: #fff;
}

.env-vars-list {
    max-height: 360px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.env-row {
    display: grid;
    grid-template-columns: minmax(100px, 160px) 1fr;
    gap: 0.75rem;
    align-items: center;
}

.env-key {
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.env-value-wrap {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.env-value-wrap .form-control {
    flex: 1;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
}

/* Backups table */
.backups-table {
    width: 100%;
    border-collapse: collapse;
}

.backups-table th,
.backups-table td {
    padding: 1rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border-glass);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.backups-table th {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.2);
}

.backups-table tr:last-child td {
    border-bottom: none;
}

.backups-table td:first-child {
    color: var(--text-primary);
}


/* Console Container */
.console-panel {
    display: flex;
    flex-direction: column;
    height: 480px;
    background: #05070c;
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.console-header {
    background: rgba(17, 24, 39, 0.9);
    border-bottom: 1px solid var(--border-glass);
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.console-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

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

.console-body {
    flex-grow: 1;
    padding: 1.25rem;
    overflow-y: auto;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    color: #e5e7eb;
    background-color: #030508;
}

.console-line {
    white-space: pre-wrap;
    word-break: break-all;
    margin-bottom: 0.25rem;
}

.console-line.error { color: #f87171; }
.console-line.warning { color: #fbbf24; }
.console-line.info { color: #60a5fa; }
.console-line.success { color: #34d399; }
.console-line.system { color: #a78bfa; font-style: italic; }

/* Modal / Popup Form */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed);
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: all;
}

.modal-container {
    width: 100%;
    max-width: 550px;
    transform: translateY(20px);
    transition: transform var(--transition-speed);
}

.modal-backdrop.open .modal-container {
    transform: translateY(0);
}

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

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: #ffffff;
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition-speed);
}

.form-control:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px var(--accent-blue-glow);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.75rem;
}

/* Custom Alert / Toast */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background: rgba(17, 24, 39, 0.9);
    border: 1px solid var(--border-glass);
    border-radius: 10px;
    padding: 1rem 1.5rem;
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateX(120%);
    transition: transform var(--transition-speed) cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    transform: translateX(0);
}

.toast-success { border-left: 4px solid var(--status-running); }
.toast-error { border-left: 4px solid var(--status-stopped); }
.toast-warning { border-left: 4px solid var(--status-pending); }
