* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Nomads Color Palette */
    --bg-primary: #1C1917;
    --bg-secondary: #28231f;
    --bg-card: rgba(215, 192, 162, 0.05);
    --bg-hover: rgba(215, 192, 162, 0.1);

    --accent-primary: #D7C0A2;
    --accent-secondary: #C4AB8B;
    --accent-success: #D7C0A2;
    --accent-warning: #E5C797;
    --accent-danger: #C99B7A;

    /* Pops of Color */
    --pop-success: #10B981;
    /* Emerald Green */
    --pop-success-bg: rgba(16, 185, 129, 0.15);
    --pop-success-glow: rgba(16, 185, 129, 0.3);

    --pop-danger: #EF4444;
    /* Vibrant Red */
    --pop-danger-bg: rgba(239, 68, 68, 0.15);
    --pop-danger-glow: rgba(239, 68, 68, 0.3);

    --text-primary: #D7C0A2;
    --text-secondary: rgba(215, 192, 162, 0.7);
    --text-muted: rgba(215, 192, 162, 0.4);

    --border-color: rgba(215, 192, 162, 0.15);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;

    /* Border Radius - Minimal */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Layout Structure */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
}

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: var(--spacing-xl);
    max-width: calc(100vw - 260px);
    overflow-x: hidden;
}

/* Sidebar Logo */
.sidebar-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.sidebar-logo img {
    height: 28px;
    width: auto;
}

.sidebar-logo div {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.sidebar-logo h1 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    margin-bottom: 2px;
}

.sidebar-logo span {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Sidebar Navigation */
.nav-menu {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    border: 1px solid transparent;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-card);
    color: var(--accent-primary);
    border-color: var(--border-color);
    font-weight: 500;
}

.nav-icon {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

/* Page Headers */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-xl);
}

.page-title h2 {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Header Stats (moved to utility class) */
.header-actions {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

.connection-status {
    padding: 0.25rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected {
    background: var(--pop-success);
    box-shadow: 0 0 8px var(--pop-success-glow);
}

.refresh-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: rotate(180deg);
}

/* System Stats */
.system-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    transition: all 0.2s ease;
}

.stat-card:hover {
    border-color: var(--accent-primary);
    background: var(--bg-hover);
}

.stat-icon {
    font-size: 2rem;
    line-height: 1;
    filter: grayscale(30%);
}

.stat-content {
    flex: 1;
}

.stat-title {
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-bottom: 0.25rem;
}

.stat-number {
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 500;
}

/* Filters */
.filters {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-lg);
    flex-wrap: wrap;
}

.filter-btn {
    background: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-secondary);
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-weight: 500;
    transition: all 0.2s ease;
}

.filter-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
}

/* Automations Grid */
.automations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.automation-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    transition: all 0.2s ease;
}

.automation-card:hover {
    border-color: var(--accent-primary);
    background: var(--bg-hover);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.card-title-section h3 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.category-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: rgba(215, 192, 162, 0.1);
    color: var(--accent-primary);
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    border: 1px solid var(--border-color);
}

.status-badge {
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    border: 1.5px solid;
    transition: all 0.3s ease;
}

.status-badge.online {
    background: var(--pop-success-bg);
    color: var(--pop-success);
    border-color: var(--pop-success);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.1);
}

.status-badge.stopped {
    background: var(--pop-danger-bg);
    color: var(--pop-danger);
    border-color: var(--pop-danger);
}

.status-badge.errored {
    background: rgba(229, 199, 151, 0.1);
    color: var(--accent-warning);
    border-color: var(--accent-warning);
}

.card-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: var(--spacing-md);
    line-height: 1.5;
}

.card-metrics {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
}

.metric {
    background: rgba(28, 25, 23, 0.5);
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.metric-label {
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-bottom: 0.25rem;
}

.metric-value {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
}

.time-saved-badge {
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    text-align: center;
    margin-bottom: var(--spacing-md);
    font-weight: 500;
}

.time-saved-badge .label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
}

.time-saved-badge .value {
    font-size: 1.1rem;
    margin-top: 0.25rem;
    color: var(--accent-primary);
}

.card-actions {
    display: flex;
    gap: var(--spacing-xs);
}

.btn {
    flex: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    background: transparent;
    color: var(--text-primary);
}

.btn-primary {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.btn-primary:hover {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.btn-secondary {
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.btn-danger {
    border-color: var(--pop-danger);
    color: var(--pop-danger);
    opacity: 0.8;
}

.btn-danger:hover {
    background: var(--pop-danger);
    color: #fff;
    opacity: 1;
    box-shadow: 0 0 10px var(--pop-danger-glow);
}

.btn-success {
    border-color: var(--pop-success);
    color: var(--pop-success);
    opacity: 0.8;
}

.btn-success:hover {
    background: var(--pop-success);
    color: #fff;
    opacity: 1;
    box-shadow: 0 0 10px var(--pop-success-glow);
}

.btn:active {
    transform: scale(0.98);
}

/* Summary Section */
.summary-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.summary-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    text-align: center;
    transition: all 0.2s ease;
}

.summary-card:hover {
    border-color: var(--accent-primary);
    background: var(--bg-hover);
}

.summary-card h3 {
    font-size: 0.875rem;
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 11px;
    color: var(--text-muted);
}

.summary-value {
    font-size: 2.5rem;
    font-weight: 500;
    color: var(--accent-primary);
    margin-bottom: var(--spacing-xs);
}

.summary-description {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Footer */
.footer {
    text-align: center;
    color: var(--text-muted);
    padding: var(--spacing-lg) 0;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.footer p {
    margin: 0.25rem 0;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(28, 25, 23, 0.95);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

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

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 500;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--spacing-lg);
    overflow-y: auto;
    flex: 1;
}

#log-content {
    background: rgba(28, 25, 23, 0.8);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    border: 1px solid var(--border-color);
}

.modal-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
}

/* Loading State */
.loading-state {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-secondary);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    margin: 0 auto var(--spacing-md);
    animation: spin 1s linear infinite;
}

/* Animations */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: var(--spacing-sm);
    }

    h1 {
        font-size: 1.25rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .automations-grid {
        grid-template-columns: 1fr;
    }

    .system-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}