:root {
    /* MagicWand 2.0 - Copilot Light Semantic Palette */
    --brand-bg: #f8fafc; /* Very light slate */
    --brand-surface: #ffffff;
    --brand-border: rgba(0, 0, 0, 0.08);
    --brand-text: #0f172a;
    --brand-muted: #64748b;
    
    /* Semantic Colors */
    --accent-blue: #2563eb;
    --accent-green: #10b981;
    --accent-amber: #d97706;
    --accent-red: #dc2626;
    
    /* Avigiri logo colours */
    --avi-indigo: #24148c;
    --avi-indigo-soft: #efedfa;
    --avi-lime: #a9bf2b;

    /* Gradients */
    --grad-blue: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --grad-surface: linear-gradient(180deg, rgba(0, 0, 0, 0.02) 0%, rgba(0, 0, 0, 0) 100%);
}

body.theme-copilot {
    background-color: var(--brand-bg);
    color: var(--brand-text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    letter-spacing: -0.01em;
    overflow-x: hidden;
}

/* Sidebar Navigation */
.copilot-sidebar {
    width: 260px;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: var(--brand-surface);
    border-right: 1px solid var(--brand-border);
    padding: 1.5rem 1rem;
    z-index: 1000;
    min-height: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--brand-border);
    margin-bottom: 1.5rem;
    text-decoration: none;
    color: var(--brand-text);
    flex: 0 0 auto;
}

.sidebar-logo img {
    height: 32px;
    border-radius: 6px;
}

.sidebar-footer {
    color: var(--brand-text);
    flex: 0 0 auto;
}

.copilot-sidebar-nav,
.copilot-mobile-nav {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.25rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.35) transparent;
}

.copilot-sidebar-nav::-webkit-scrollbar,
.copilot-mobile-nav::-webkit-scrollbar {
    width: 6px;
}

.copilot-sidebar-nav::-webkit-scrollbar-track,
.copilot-mobile-nav::-webkit-scrollbar-track {
    background: transparent;
}

.copilot-sidebar-nav::-webkit-scrollbar-thumb,
.copilot-mobile-nav::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.28);
    border-radius: 999px;
}

.sidebar-section {
    margin-bottom: 0.55rem;
}

.sidebar-section-title,
.copilot-mobile-section-title {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.sidebar-section-title::-webkit-details-marker,
.copilot-mobile-section-title::-webkit-details-marker {
    display: none;
}

.sidebar-section-title::after,
.copilot-mobile-section-title::after {
    content: "\F282";
    font-family: "bootstrap-icons";
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--brand-muted);
    transition: transform 0.18s ease;
}

.sidebar-section[open] > .sidebar-section-title::after,
.sidebar-section[open] > .copilot-mobile-section-title::after {
    transform: rotate(180deg);
}

.sidebar-section-title {
    padding: 0.35rem 0.5rem;
    margin: 0.75rem 0 0.4rem;
    color: var(--brand-muted);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-radius: 8px;
}

.sidebar-section-title:hover,
.copilot-mobile-section-title:hover {
    background: rgba(0, 0, 0, 0.035);
    color: var(--brand-text);
}

.sidebar-section-links {
    padding-bottom: 0.15rem;
}

.sidebar-signout-form {
    margin-top: 0.2rem;
}

.sidebar-signout-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--brand-muted);
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
}

.sidebar-signout-btn:hover {
    color: var(--accent-red);
}

.nav-pill-custom {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    color: var(--brand-muted);
    text-decoration: none;
    transition: all 0.2s ease;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.nav-pill-custom:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--brand-text);
}

.nav-pill-custom.active {
    background: rgba(37, 99, 235, 0.08);
    color: var(--accent-blue);
}

/* Main Content Area */
.copilot-main {
    margin-left: 260px;
    padding: 2rem 3rem;
    min-height: 100vh;
    width: calc(100% - 260px);
    max-width: 100%;
    overflow-x: hidden;
}

.copilot-mobile-header {
    position: sticky;
    top: 0;
    z-index: 1035;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--brand-border);
    backdrop-filter: blur(14px);
}

.copilot-mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--brand-text);
    text-decoration: none;
    font-weight: 700;
    overflow: hidden;
}

.copilot-mobile-brand img {
    height: 28px;
    border-radius: 6px;
    flex: 0 0 auto;
}

.copilot-mobile-brand span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.copilot-mobile-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.copilot-mobile-menu .offcanvas-body {
    padding: 1rem;
    min-height: 0;
}

.copilot-mobile-section-title {
    padding: 0 0.5rem;
    margin: 1rem 0 0.5rem;
    color: var(--brand-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-radius: 8px;
}

.copilot-mobile-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--brand-border);
}

/* Hero Section / Welcome */
.welcome-header h1 {
    font-weight: 800;
    color: var(--brand-text);
}

/* Action Cards */
.copilot-card {
    background: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 12px;
    padding: 1.5rem;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    height: 100%;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.copilot-card:hover {
    border-color: rgba(37, 99, 235, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.icon-box {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
    font-size: 1.25rem;
}

.icon-blue { background: rgba(37, 99, 235, 0.1); color: #2563eb; }
.icon-green { background: rgba(16, 185, 129, 0.1); color: #059669; }
.icon-amber { background: rgba(217, 119, 6, 0.1); color: #d97706; }
.icon-red { background: rgba(220, 38, 38, 0.1); color: #dc2626; }

/* Status Badges */
.status-pill {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    letter-spacing: 0.05em;
}

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

/* Modern Compact Tables for Manufacturing */
.table-copilot {
    background: var(--brand-surface);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--brand-border);
    font-size: 0.875rem;
}

.table-copilot thead th {
    background: #f1f5f9;
    color: var(--brand-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 1rem;
    border-bottom: 1px solid var(--brand-border);
}

.table-copilot tbody td {
    padding: 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--brand-border);
    color: var(--brand-text);
}

.table-copilot tbody tr:hover {
    background: rgba(37, 99, 235, 0.02);
}

/* Badge System */
.badge-copilot {
    padding: 0.4em 0.8em;
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.75rem;
}

.badge-success-soft { background: #ecfdf5; color: #059669; }
.badge-warning-soft { background: #fffbeb; color: #d97706; }
.badge-danger-soft { background: #fef2f2; color: #dc2626; }
.badge-primary-soft { background: #eff6ff; color: #2563eb; }

/* Page Header Utility */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
}

.page-title {
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--brand-text);
}

.page-subtitle {
    color: var(--brand-muted);
    font-size: 0.95rem;
}

/* Module start pages (#ai-enquiries, #ai-design, ...) */
.ai-portal-overlay {
    position: fixed;
    inset: 0;
    background: var(--brand-bg);
    z-index: 2000;
    display: none;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding: 2rem 3rem 3rem;
}

/* Keep the sidebar in view where it is shown. */
@media (min-width: 1200px) {
    .ai-portal-overlay {
        left: 260px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .ai-portal-overlay {
        left: 0;
    }
}

body.ai-portal-open {
    overflow: hidden;
}

body.ai-portal-open .copilot-sidebar .nav-pill-custom.active:not(.is-portal) {
    background: transparent;
    color: var(--brand-muted);
}

.nav-pill-custom.is-portal {
    background: var(--avi-indigo-soft);
    color: var(--avi-indigo);
}

.ai-portal-content {
    max-width: 880px;
    width: 100%;
}

.ai-close-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0 0 1.5rem -0.6rem;
    padding: 0.4rem 0.6rem;
    border: 0;
    border-radius: 8px;
    background: none;
    color: #475569;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}

.ai-close-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--brand-text);
}

.ai-portal-head {
    display: flex;
    align-items: center;
    gap: 1.1rem;
    margin-bottom: 1.75rem;
}

.ai-portal-avatar {
    flex: 0 0 auto;
    width: 60px;
    height: 60px;
    border-radius: 12px;
    border-bottom: 4px solid var(--avi-lime);
    background: var(--avi-indigo);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
}

.ai-portal-title {
    margin: 0 0 0.2rem;
    font-size: 1.9rem;
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--brand-text);
    outline: none;
}

.ai-portal-subtitle {
    margin: 0;
    font-size: 1rem;
    color: #475569;
}

.ai-suggestion-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.75rem;
}

.ai-suggestion-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1.1rem 1.2rem;
    border: 1px solid #dfe3ea;
    border-radius: 12px;
    background: #fff;
    color: var(--brand-text);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.ai-suggestion-card:hover {
    border-color: var(--avi-indigo);
    background: #fbfaff;
}

.ai-suggestion-card:focus-visible,
.ai-close-btn:focus-visible,
.ai-ask-send:focus-visible,
.ai-ask-attach:focus-visible {
    outline: 2px solid var(--avi-indigo);
    outline-offset: 2px;
}

.ai-suggestion-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--avi-indigo-soft);
    color: var(--avi-indigo);
    font-size: 1.15rem;
}

.ai-suggestion-title {
    display: block;
    font-size: 1.02rem;
    font-weight: 600;
}

.ai-suggestion-note {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.88rem;
    line-height: 1.4;
    color: #56647a;
}

.ai-suggestion-go {
    color: #94a3b8;
}

.ai-suggestion-card:hover .ai-suggestion-go {
    color: var(--avi-indigo);
}

.ai-ask {
    padding-top: 1.5rem;
    border-top: 1px solid #dfe3ea;
}

.ai-ask-label {
    display: block;
    margin-bottom: 0.6rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--brand-text);
}

.ai-portal-input-container {
    display: flex;
    gap: 0.4rem;
    padding: 0.35rem;
    margin-bottom: 1rem;
    border: 1px solid #b9c2d0;
    border-radius: 12px;
    background: #fff;
}

.ai-portal-input-container:focus-within {
    border-color: var(--avi-indigo);
    box-shadow: 0 0 0 3px rgba(36, 20, 140, 0.12);
}

.ai-portal-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.6rem 0.4rem;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1rem;
    color: var(--brand-text);
}

.ai-ask-attach {
    flex: 0 0 auto;
    width: 44px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: #475569;
    font-size: 1.15rem;
}

.ai-ask-attach:hover {
    background: #f1f5f9;
}

.ai-ask-send {
    flex: 0 0 auto;
    padding: 0.6rem 1.4rem;
    border: 0;
    border-radius: 8px;
    background: var(--avi-indigo);
    color: #fff;
    font-weight: 600;
}

.ai-ask-send:hover {
    background: #1a0e6b;
}

.ai-ask-send:disabled {
    opacity: 0.6;
}

.ai-portal-meta {
    min-height: 1.5rem;
    margin: 0 0 1rem;
}

.ai-portal-meta .form-select {
    max-width: 260px;
}

.ai-match-count-select {
    max-width: 140px;
}

.ai-gasket-id-input {
    max-width: 260px;
}

.ai-share-password-input {
    max-width: 320px;
}

.ai-share-link-box {
    max-width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.ai-category-row {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.ai-design-match-link {
    white-space: nowrap;
}

.ai-portal-status {
    min-height: 1.25rem;
    margin-top: 0.6rem;
}

.ai-portal-status.text-warning {
    color: #9a5b00 !important;
}

.ai-conversation-panel {
    width: 100%;
    max-height: 240px;
    overflow-y: auto;
    margin: 0 0 1.5rem;
    padding: 1rem;
    border: 1px solid #dfe3ea;
    border-radius: 12px;
    background: #fff;
    text-align: left;
}

.ai-conversation-message + .ai-conversation-message {
    margin-top: 0.85rem;
}

.ai-conversation-message--user {
    margin-left: auto;
    max-width: 80%;
}

.ai-conversation-message--assistant {
    max-width: 88%;
}

.ai-conversation-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--brand-muted);
    margin-bottom: 0.25rem;
}

.ai-conversation-body {
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    line-height: 1.5;
    color: var(--brand-text);
}

.ai-conversation-message--assistant .ai-conversation-body {
    background: #f5f7fa;
}

.ai-conversation-message--user .ai-conversation-body {
    background: var(--avi-indigo-soft);
}

.ai-result-panel {
    width: 100%;
}

.ai-result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.ai-result-panel .card {
    border-radius: 16px;
}

.ai-result-panel .table th,
.ai-result-panel .table td {
    padding: 0.9rem 1rem;
}

.app-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(248, 250, 252, 0.78);
    backdrop-filter: blur(4px);
}

.app-loading-card {
    min-width: 260px;
    max-width: 360px;
    padding: 1.25rem 1.5rem;
    border-radius: 18px;
    border: 1px solid var(--brand-border);
    background: rgba(255, 255, 255, 0.96);
    text-align: center;
}

.app-loading-spinner {
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.9rem;
}

.app-loading-title {
    color: var(--brand-text);
    margin-bottom: 0.35rem;
}

body.app-loading-active {
    overflow: hidden;
}

@media (max-width: 991.98px) {
    .copilot-main {
        margin-left: 0;
        width: 100%;
        padding: 1.25rem 1rem 2rem;
        min-height: auto;
    }

    .copilot-main > .container-fluid {
        max-width: 100%;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        margin-bottom: 1.5rem;
    }

    .page-header > div:last-child {
        width: 100%;
    }

    .page-header .btn,
    .page-header .badge {
        width: 100%;
        justify-content: center;
    }

    .copilot-card {
        padding: 1.1rem;
    }

    .table-copilot thead th,
    .table-copilot tbody td {
        padding: 0.75rem;
    }

    .ai-portal-overlay {
        padding: 1rem 1rem 2rem;
    }

    .ai-portal-content {
        max-width: 100%;
    }

    .ai-conversation-message--user,
    .ai-conversation-message--assistant {
        max-width: 100%;
    }

    .ai-suggestion-grid {
        grid-template-columns: 1fr;
    }

    .ai-category-row > * {
        width: 100%;
        max-width: none !important;
    }
}

@media (hover: none) and (pointer: coarse), (max-width: 1199.98px) {
    body.theme-copilot {
        overflow-x: hidden;
    }

    .copilot-sidebar {
        display: none !important;
    }

    /* Bootstrap's d-lg-none hides this from 992px; show it wherever the sidebar is hidden. */
    body .copilot-mobile-header {
        display: flex !important;
    }

    .copilot-main {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 1rem 0.75rem 1.75rem !important;
        overflow-x: hidden;
    }

    .copilot-main > .container-fluid,
    .hub-shell,
    .hub-card-grid {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .hub-title,
    .hub-subtitle,
    .welcome-header {
        max-width: 100% !important;
    }

    .hub-card-grid > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

@media (max-width: 767.98px) {
    .copilot-main {
        padding: 1rem 0.75rem 1.75rem;
    }

    .copilot-mobile-header {
        padding: 0.7rem 0.75rem;
        gap: 0.65rem;
    }

    .copilot-mobile-brand {
        gap: 0.5rem;
    }

    .copilot-mobile-brand img {
        height: 24px;
    }

    .copilot-mobile-actions .btn,
    .copilot-mobile-header > .btn {
        padding: 0.45rem 0.6rem;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .page-subtitle {
        font-size: 0.9rem;
    }

    .ai-close-btn {
        margin-bottom: 1rem;
    }

    .ai-portal-head {
        gap: 0.85rem;
        margin-bottom: 1.25rem;
    }

    .ai-portal-avatar {
        width: 48px;
        height: 48px;
        font-size: 1.3rem;
    }

    .ai-portal-title {
        font-size: 1.5rem;
    }

    .ai-portal-subtitle {
        font-size: 0.92rem;
    }

    .ai-suggestion-card {
        padding: 0.9rem;
        gap: 0.8rem;
    }

    .ai-ask-send {
        padding: 0.6rem 1rem;
    }

    .app-loading-card {
        min-width: 0;
        width: min(100%, 320px);
        margin: 0 0.75rem;
    }
}
