/* ============================================================
   App Layout & Page-Specific Styles
   ============================================================ */

/* ---- App Shell ---- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    position: relative;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition-slow);
}

.sidebar-brand {
    padding: var(--space-6);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand h2 {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    color: var(--color-sidebar-text-active);
    margin: 0;
}

.sidebar-brand small {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    display: block;
    margin-top: var(--space-1);
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4) 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-6);
    color: var(--color-sidebar-text);
    text-decoration: none;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    transition: background var(--transition-fast), color var(--transition-fast);
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--color-sidebar-hover-bg);
    color: var(--color-sidebar-text-active);
}

.sidebar-nav a.active {
    background: var(--color-sidebar-active-bg);
    color: var(--color-sidebar-text-active);
    border-left-color: var(--color-primary);
}

.sidebar-nav a .nav-icon {
    width: 20px;
    text-align: center;
    font-size: var(--font-size-md);
}

/* ---- Main Content ---- */
.main-content {
    flex: 1;
    padding: var(--space-8);
    max-width: 1200px;
    margin: 0 auto;
}

/* ---- Page Sections ---- */
.page {
    display: none;
}

.page.active {
    display: block;
}

.page-header {
    margin-bottom: var(--space-6);
}

.page-header h1 {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-1);
}

.page-header p {
    color: var(--color-text-secondary);
    font-size: var(--font-size-base);
}

/* ---- Home Page: Run Controls ---- */
.run-controls {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.last-ran {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.run-status {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    display: none;
}

.run-status.visible { display: block; }

/* ---- Log Container ---- */
.log-container {
    background: var(--color-log-bg);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    max-height: 420px;
    overflow-y: auto;
    font-family: var(--font-family-mono);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    display: none;
}

.log-container.visible { display: block; }

.log-line {
    color: var(--color-log-text);
    white-space: pre-wrap;
    word-break: break-word;
}

.log-line.debug {
    color: var(--color-log-debug);
    display: none;
}

.log-line.debug.visible { display: block; }
.log-line.error { color: var(--color-log-error); }
.log-line.success { color: var(--color-log-success); }

/* ---- Run History Page ---- */
.run-history-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
}

.upload-btn-wrapper {
    position: relative;
    overflow: hidden;
}

.upload-btn-wrapper input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* ---- Run Detail Modal ---- */
.run-detail-meta {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.run-detail-logs-header {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    margin-top: var(--space-6);
    margin-bottom: var(--space-2);
}

.collection-group {
    margin-bottom: var(--space-6);
}

.collection-group-header {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-3);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.collection-group-header .chevron {
    transition: transform var(--transition-normal);
    font-size: var(--font-size-sm);
}

.collection-group-header.collapsed .chevron {
    transform: rotate(-90deg);
}

.collection-group-body {
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

.collection-group-body.collapsed {
    max-height: 0 !important;
    overflow: hidden;
}

/* ---- Settings Page ---- */
.settings-section {
    margin-bottom: var(--space-8);
}

.settings-section h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-0);
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--color-border-light);
}

.settings-row:last-child { border-bottom: none; }

.settings-label {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
}

.settings-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-top: var(--space-1);
}

.settings-control {
    flex-shrink: 0;
    margin-left: var(--space-6);
}

/* Delay slider */
.delay-slider {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.delay-slider input[type="range"] {
    width: 160px;
    accent-color: var(--color-primary);
}

.delay-slider .delay-value {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    min-width: 40px;
    text-align: center;
    font-family: var(--font-family-mono);
}

/* Theme color editor */
.theme-color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
}

.theme-color-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.theme-color-item label {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    flex: 1;
}

.theme-color-item input[type="color"] {
    width: 36px;
    height: 28px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 2px;
    cursor: pointer;
    background: var(--color-surface);
}

/* Theme share */
.theme-share {
    margin-top: var(--space-4);
}

.theme-share textarea {
    width: 100%;
    min-height: 80px;
    font-family: var(--font-family-mono);
    font-size: var(--font-size-sm);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    resize: vertical;
}

.theme-share-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

/* ---- Mobile Menu Button ---- */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--font-size-lg);
}

.mobile-topbar {
    display: none;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.mobile-topbar-title {
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--color-overlay);
    z-index: 99;
}

.sidebar-overlay.visible {
    display: block;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        padding: var(--space-4);
    }

    .mobile-topbar {
        display: flex;
    }

    .mobile-menu-btn {
        display: flex;
        position: absolute;
        top: var(--space-4);
        right: var(--space-4);
    }

    .page-header h1 {
        font-size: var(--font-size-xl);
    }

    .card {
        padding: var(--space-4);
    }

    /* Settings rows stack vertically */
    .settings-row {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .settings-control {
        margin-left: 0;
        width: 100%;
    }

    .delay-slider {
        width: 100%;
    }

    .delay-slider input[type="range"] {
        flex: 1;
        min-width: 0;
    }

    /* Theme color grid single column */
    .theme-color-grid {
        grid-template-columns: 1fr;
    }

    /* Tables scroll horizontally */
    .table-wrapper {
        margin-left: calc(-1 * var(--space-4));
        margin-right: calc(-1 * var(--space-4));
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    /* Run history action buttons wrap */
    tbody td:last-child {
        white-space: normal;
    }

    tbody td:last-child .btn {
        margin-bottom: var(--space-1);
    }

    /* Modals take full width */
    .modal {
        width: 100%;
        max-width: none;
        max-height: 100vh;
        border-radius: 0;
        height: 100vh;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }

    /* Log container shorter on mobile */
    .log-container {
        max-height: 280px;
    }

    /* Run controls stack */
    .run-controls {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: var(--space-3);
    }

    .card {
        padding: var(--space-3);
    }

    .theme-share textarea {
        min-height: 60px;
        font-size: var(--font-size-xs);
    }
}
