/* --- Global Design System --- */

:root {
    --primary-color: #3498db;
    --primary-hover-color: #2980b9;
    --secondary-color: #6c757d;
    --secondary-hover-color: #5a6268;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --error-color: #e74c3c;
    --light-bg-color: #f4f7f9;
    --white-color: #ffffff;
    --dark-text-color: #34495e;
    --light-text-color: #7f8c8d;
    --border-color: #dee2e6;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
}

/* Focus Management Styles */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 1000;
    font-weight: bold;
}

.skip-link:focus {
    top: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--light-bg-color);
    margin: 0;
    padding: 20px;
    color: var(--dark-text-color);
}

body.sidebar-layout {
    padding: 0;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    background-color: var(--white-color);
    border-right: 1px solid var(--border-color);
    padding: 24px 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 5;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand img {
    height: 40px;
    width: auto;
    border-radius: var(--border-radius);
}

.sidebar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark-text-color);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--dark-text-color);
    text-decoration: none;
    font-size: 0.95rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-link:hover {
    background-color: #eef2f7;
}

.sidebar-link.active {
    background-color: #e8f0fb;
    color: #1f4f8f;
    font-weight: 600;
}

.app-content {
    margin-left: 240px;
    padding: 24px;
    min-height: 100vh;
    box-sizing: border-box;
}

@media (max-width: 900px) {
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        padding: 12px 16px;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }

    .app-content {
        margin-left: 0;
        padding: 16px;
    }
}

/* --- Toast notifications --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background-color: var(--white-color);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
    padding: 12px 14px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    color: var(--dark-text-color);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    border-left-color: var(--success-color);
}

.toast-error {
    border-left-color: var(--error-color);
}

.toast-warning {
    border-left-color: var(--warning-color);
}

.toast-info {
    border-left-color: var(--primary-color);
}

.toast-message {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.3;
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--light-text-color);
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    line-height: 1;
}

.main-container {
    max-width: 1400px;
    margin: 0 auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: -10px 0 20px;
    font-size: 0.85rem;
    color: var(--light-text-color);
}

.breadcrumbs a {
    color: var(--primary-color);
    text-decoration: none;
}

.breadcrumbs a:hover {
    text-decoration: underline;
}

.breadcrumbs-separator {
    color: var(--light-text-color);
}

.header-right-side {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Logo specific styles */
.header-logo[src*="logo1"] {
    height: 65px;
    width: auto;
    border-radius: var(--border-radius);
}

.header-logo[src*="logo2"] {
    height: 90px;
    width: auto;
    border-radius: var(--border-radius);
}

.header-logo[src*="logo3"] {
    height: 70px;
    width: auto;
    border-radius: var(--border-radius);
}

/* Original header-logo class for fallback */
.header-logo {
    border-radius: var(--border-radius);
}

h1 {
    color: var(--dark-text-color);
    font-weight: 300;
}

/* --- Buttons --- */
.btn {
    border: none;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
    transform: translateY(0);
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--white-color);
}

.btn-primary:hover {
    background-color: var(--primary-hover-color);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--white-color);
}

.btn-secondary:hover {
    background-color: var(--secondary-hover-color);
}

.refresh-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.refresh-btn:hover {
    background-color: var(--primary-hover-color);
    transform: translateY(-1px);
}

.refresh-btn svg {
    width: 14px;
    height: 14px;
}


/* --- Card Layout --- */
.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 25px;
}

.card {
    background-color: var(--white-color);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.card h3 {
    margin-top: 0;
    font-size: 1.2rem;
    color: var(--dark-text-color);
}

.card p {
    color: var(--light-text-color);
    flex-grow: 1;
}

/* --- Steps / Pipeline --- */
.steps-container {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.step {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: #fafbfc;
}

.step-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-grow: 1;
}

.step-info p {
    margin: 0;
    font-weight: 500;
    color: var(--dark-text-color);
}

.status-indicator {
    font-size: 1.5rem;
}

.step .process-btn {
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: auto;
    white-space: nowrap;
}

.step .process-btn:hover {
    background-color: var(--primary-color);
    color: var(--white-color);
    transform: translateY(-1px);
}

.step .process-btn:disabled {
    background: transparent;
    border-color: #ccc;
    color: #ccc;
    cursor: not-allowed;
    transform: translateY(0);
}


/* --- Action Buttons --- */
.action-buttons {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
}

.action-buttons .btn {
    justify-content: center;
    font-size: 0.9rem;
    padding: 8px 12px;
}


/* --- Progress Bar --- */
.progress-bar-container {
    height: 10px;
    background-color: #ecf0f1;
    border-radius: 5px;
    overflow: hidden;
    margin-top: 8px;
    margin-bottom: 5px;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0.3s ease-in-out, opacity 0.3s ease-in-out;
    width: 100%;
    border: 1px solid #d5dbdb;
    position: relative;
    display: block;
}

.progress-bar-container.visible {
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--success-color));
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: inherit;
    position: relative;
    min-width: 0%;
    max-width: 100%;
}

.progress-bar-container.pulse .progress-bar {
    animation: progress-pulse 1.6s ease-in-out infinite;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(255, 255, 255, 0.3) 50%,
            transparent 100%);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

@keyframes progress-pulse {
    0% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.25);
    }

    100% {
        filter: brightness(1);
    }
}

.step[data-status="processing"] .progress-bar {
    background: linear-gradient(90deg, var(--warning-color), #f39c12);
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    font-weight: 600;
    color: #2c3e50;
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
    pointer-events: none;
    z-index: 1;
    display: block;
    visibility: visible;
}

.progress-meta {
    display: none;
    margin-top: 6px;
    font-size: 12px;
    color: #6c757d;
}

.progress-meta.visible {
    display: block;
}

.progress-step {
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
}

.progress-helper {
    margin: 2px 0 0;
}

/* --- Sidebar Item Wrapper --- */
.db-item-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.db-card-btn {
    flex-grow: 1;
    text-align: left;
    white-space: normal;
    word-break: break-word;
}

.db-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    color: #6b7280;
    font-size: 12px;
    text-align: center;
    border: 1px dashed #e5e7eb;
    border-radius: 10px;
    background-color: #f9fafb;
}

#build-table-btn {
    animation: pulse-border 2s infinite;
    font-weight: bold;
    border: 2px solid var(--white-color);
}

@keyframes pulse-border {
    0% {
        box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(52, 152, 219, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(52, 152, 219, 0);
    }
}

/* Skeleton Loading Styles */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.skeleton-row {
    height: 48px;
    margin-bottom: 8px;
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-card {
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--white-color);
    margin-bottom: 16px;
}

.skeleton-table-row {
    display: flex;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.skeleton-table-cell {
    flex: 1;
    height: 16px;
}

.skeleton-table-cell:nth-child(1) {
    flex: 0 0 50px;
}

.skeleton-table-cell:nth-child(2) {
    flex: 2;
}

.skeleton-table-cell:nth-child(3) {
    flex: 3;
}

.skeleton-table-cell:nth-child(4) {
    flex: 2;
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
        background: var(--light-bg-color);
    }
}

/* --- Responsive Enhancements (Task 6) --- */

:root {
    --mobile-break: 768px;
    --tablet-break: 1024px;
}

/* Hamburger menu button (hidden on desktop) */
.hamburger-menu {
    display: none;
    background: transparent;
    border: none;
    font-size: 20px;
    padding: 10px;
    cursor: pointer;
}

/* Table responsive wrapper */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Sticky first column for wider screens; degrade to normal flow on narrow screens */
table th:first-child,
table td:first-child {
    position: sticky;
    left: 0;
    background: var(--white-color);
    z-index: 2;
}

/* Touch target sizing for mobile */
@media (max-width: 768px) {
    .hamburger-menu {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide the sidebar off-canvas by default, reveal when open */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
        width: 280px;
        height: 100vh;
        top: 0;
        left: 0;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .app-content {
        margin-left: 0;
        padding: 12px;
    }

    .btn,
    .sidebar-link,
    .nav-item,
    .hamburger-menu {
        min-height: 44px;
        min-width: 44px;
    }

    /* Degrade sticky column behavior: remove sticky to avoid clipping on very small screens */
    table th:first-child,
    table td:first-child {
        position: static;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {

    /* Tablet adjustments */
    .sidebar {
        width: 220px;
        transform: translateX(0);
        position: fixed;
    }

    .app-content {
        margin-left: 220px;
    }

    .table-responsive {
        overflow-x: auto;
    }
}

/* Respect reduced motion for sidebar transitions */
@media (prefers-reduced-motion: reduce) {
    .sidebar {
        transition: none;
    }
}

/* ======================== */
/* Sidebar Context Section  */
/* ======================== */
.context-section {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    box-sizing: border-box;
}

.context-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #7f8c8d);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: block;
}

#db-selector {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary, #f4f7f9);
    font-size: 14px;
    cursor: pointer;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
}

#db-selector:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.actions-section {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border-color);
    box-sizing: border-box;
}

.actions-section.disabled button {
    opacity: 0.6;
    pointer-events: none;
    cursor: not-allowed;
}