/* Shared Material-inspired presentation. Loaded after the legacy page styles.
   Palette values still come from theme.js, including user-created presets. */
:root {
    --tc-material-font: 'Fredoka', 'Segoe UI', sans-serif;
    --tc-material-radius: 16px;
    --tc-material-shadow: 0 1px 3px rgb(0 0 0 / 10%), 0 1px 2px rgb(0 0 0 / 6%);
    --tc-material-shadow-raised: 0 6px 18px rgb(0 0 0 / 14%), 0 2px 6px rgb(0 0 0 / 8%);
    --tc-panel-shadow: var(--tc-material-shadow);
    --tc-shell-gradient: #fcf7fe;
    --tc-panel-bg: #fffbfe;
    --tc-panel-bg-solid: #fffbfe;
    --tc-panel-bg-soft: #f6f1f9;
    --tc-panel-bg-modal: #fffbfe;
    --tc-text-main: #1d1b20;
    --tc-button-bg: #6750a4;
    --tc-button-hover: #57418c;
    --tc-button-text: #fff;
}

html[data-theme='dark'] {
    --tc-panel-shadow: var(--tc-material-shadow);
    --tc-shell-gradient: #22202c;
    --tc-panel-bg: #1c1b1f;
    --tc-panel-bg-solid: #1c1b1f;
    --tc-panel-bg-soft: #27252c;
    --tc-panel-bg-modal: #1c1b1f;
    --tc-text-main: #e6e1e5;
    --tc-button-bg: #d0bcff;
    --tc-button-hover: #e2d3ff;
    --tc-button-text: #381e72;
}

html body[class] {
    font-family: var(--tc-material-font);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    --bs-body-font-family: var(--tc-material-font);
    --bs-body-color: var(--tc-text-main);
    --bs-body-bg: var(--tc-panel-bg-solid);
    --bs-border-color: var(--tc-panel-border);
}

body :is(button, input, select, textarea, .btn) { font-family: inherit; }
body :is(h1, h2, h3, h4, h5, h6) { font-family: var(--tc-material-font); }
body :is(.hero-content h1, .access-intro h1, .projects-header h1,
    .account-heading h1, .admin-heading h1, .classes-heading h1, .about-heading h1) {
    font-weight: 500;
    letter-spacing: -.025em;
    line-height: 1.15;
}
body .hero-content h1 { font-size: clamp(2.5rem, 4.8vw, 4.5rem); }
body :is(.principal-panel-title h2, .access-form-card h2) {
    font-weight: 500;
    letter-spacing: -.015em;
}
body :is(.hero-description, .access-intro p, .projects-header p) { line-height: 1.65; }

/* Surface hierarchy: quiet canvas, opaque cards, raised menus and dialogs. */
body :is(.principal-panel, .access-form-card, .projects-panel, .account-sidebar,
    .account-panel, .admin-sidebar, .admin-panel, .classes-panel, .class-card,
    .classes-summary article, .about-shell, .card, .hero-image-placeholder) {
    border: 1px solid var(--tc-panel-border);
    border-radius: var(--tc-material-radius);
    background: var(--tc-panel-bg-solid) !important;
    box-shadow: var(--tc-material-shadow);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
body :is(.trace-filter-card, .admin-config-card, .account-preference-card,
    .hero-image-card, .about-author-card, .class-code-box) {
    border: 1px solid var(--tc-panel-border);
    border-radius: 12px;
    background: var(--tc-panel-bg-soft) !important;
    box-shadow: none;
}
body :is(.modal-content, .projects-modal, .classes-modal, .principal-chatbot-panel) {
    border: 1px solid var(--tc-panel-border);
    border-radius: 24px;
    background: var(--tc-panel-bg-modal) !important;
    box-shadow: var(--tc-material-shadow-raised);
}
body :is(.modal-header, .modal-footer) { border-color: var(--tc-panel-border); }
body .modal-header { padding: 1.25rem 1.5rem; }
body .modal-title { font-weight: 500; }
body .modal-footer { gap: .5rem; }
body .dropdown-menu {
    padding: .5rem;
    border-radius: 12px;
    border-color: var(--tc-panel-border) !important;
    background: var(--tc-panel-bg-solid) !important;
    box-shadow: var(--tc-material-shadow-raised) !important;
}
body .dropdown-item { border-radius: 8px; }

/* Top app bar: preserve the existing responsive navigation and project title. */
body .header-area.traceceni-header {
    background: var(--tc-header-bg) !important;
    border-bottom: 1px solid var(--tc-panel-border);
    box-shadow: 0 1px 3px rgb(0 0 0 / 6%) !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
body .traceceni-header .main-nav.traceceni-main-nav > .traceceni-nav {
    border-radius: 24px !important;
    box-shadow: none !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
body .traceceni-header .traceceni-main-nav .traceceni-nav-link {
    border-radius: 20px;
    font-size: .875rem;
    font-weight: 500;
    letter-spacing: .01em;
}
body .traceceni-header .main-nav .menu-trigger span,
body .traceceni-header .main-nav .menu-trigger span::before,
body .traceceni-header .main-nav .menu-trigger span::after {
    background-color: var(--tc-text-main) !important;
}
body .traceceni-header .main-nav .menu-trigger.active span { background-color: transparent !important; }
/* Monochrome institutional marks stay readable on the tonal app bar. */
html[data-theme='light'] .traceceni-brand-image { filter: brightness(0); opacity: .8; }
html[data-theme='dark'] .traceceni-brand-image { filter: brightness(0) invert(1); opacity: .9; }
body .traceceni-header .traceceni-main-nav .traceceni-nav-item.dropdown > .dropdown-menu {
    border-radius: 12px !important;
    box-shadow: var(--tc-material-shadow-raised) !important;
}
body :is(.admin-nav-item, .account-nav-item) {
    border-radius: 28px;
    font-weight: 500;
}
body :is(.admin-nav-item, .account-nav-item).is-active,
body .account-nav-item.is-active:hover {
    background: var(--tc-table-head-bg) !important;
    color: var(--tc-text-main) !important;
    box-shadow: none;
}

/* Filled, outlined and text buttons keep their semantic Bootstrap colors. */
body :is(.btn, .button, .btn-hero-primary, .btn-hero-outline, .btn-projects-primary) {
    border-radius: 24px;
    font-weight: 500;
    letter-spacing: .015em;
    text-transform: none;
    transition: background-color .16s ease, border-color .16s ease, box-shadow .16s ease;
}
body :is(.btn-hero-primary, .btn-hero-outline, .btn-projects-primary, .button) {
    padding: .75rem 1.5rem;
    font-size: .9375rem;
    min-height: 44px;
    border-width: 1px;
}
body :is(.btn-primary, .btn-dark, .btn-principal-primary, .btn-principal-dark,
    .btn-projects-primary, .btn-hero-primary, .button) {
    background: var(--tc-button-bg) !important;
    color: var(--tc-button-text) !important;
    border-color: var(--tc-button-bg) !important;
    box-shadow: none;
}
body :is(.btn-primary, .btn-dark, .btn-principal-primary, .btn-principal-dark,
    .btn-projects-primary, .btn-hero-primary, .button):hover:not(:disabled) {
    background: var(--tc-button-hover) !important;
    border-color: var(--tc-button-hover) !important;
    box-shadow: var(--tc-material-shadow);
    transform: none;
}
body :is(.btn-outline-primary, .btn-outline-dark, .btn-hero-outline) {
    background: transparent !important;
    color: var(--tc-interactive-ink, var(--tc-text-main)) !important;
    border: 1px solid var(--tc-control-border) !important;
}
body :is(.btn-outline-primary, .btn-outline-dark, .btn-hero-outline):hover {
    background: var(--tc-interactive-hover) !important;
    transform: none;
}
body .btn-link { color: var(--tc-interactive-ink, var(--tc-text-main)); }
body :is(.btn, .button):disabled { box-shadow: none; }
body :is(.traceceni-floating-tool, .principal-chatbot-toggle) {
    border-radius: 16px;
    box-shadow: var(--tc-material-shadow-raised);
}

/* Outlined fields. Exclude checkbox, radio, range and color inputs. */
body :is(.form-control, .form-select, .access-form-card input:not([type='checkbox']):not([type='radio']),
    .access-form-card textarea) {
    border: 1px solid var(--tc-control-border);
    border-radius: 8px;
    background-color: var(--tc-control-bg) !important;
    color: var(--tc-control-text) !important;
    font-weight: 400;
    box-shadow: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
body :is(.form-control, .form-select, .access-form-card input, .access-form-card textarea):focus {
    border-color: var(--tc-button-bg) !important;
    box-shadow: 0 0 0 1px var(--tc-button-bg) !important;
    outline: none;
}
body :is(.form-control, .form-select):disabled {
    background-color: var(--tc-panel-bg-soft) !important;
    opacity: .65;
}
body :is(.form-control, .form-select).is-invalid {
    border-color: var(--bs-danger, #dc3545) !important;
}
body :is(.form-control, .form-select).is-invalid:focus {
    box-shadow: 0 0 0 1px var(--bs-danger, #dc3545) !important;
}
body .input-group > :not(:first-child):not(.dropdown-menu) {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
body .input-group > :not(:last-child):not(.dropdown-menu) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
body .input-group-text {
    background: var(--tc-panel-bg-soft);
    color: var(--tc-text-muted);
    border-color: var(--tc-control-border);
}
body .form-label { font-weight: 500; }
body .form-check-input { cursor: pointer; }
body .form-check-input[type='checkbox'] { border-radius: 3px; }
body .form-switch .form-check-input { border-radius: 20px; }
body .form-check-input:checked {
    background-color: var(--tc-checkbox-bg, var(--tc-button-bg)) !important;
    border-color: var(--tc-checkbox-bg, var(--tc-button-bg)) !important;
}

/* Dense working tables remain scrollable; style never changes their layout. */
body :is(.projects-table-wrapper, .trace-matrix-scroll-container) {
    border: 1px solid var(--tc-panel-border);
    border-radius: 12px;
    box-shadow: none;
}
body .table { --bs-table-color: var(--tc-text-main); --bs-table-bg: var(--tc-panel-bg-solid); }
body .table thead th {
    background-color: var(--tc-table-head-bg) !important;
    color: var(--tc-text-main) !important;
    font-weight: 500;
    letter-spacing: .01em;
}
body .table > :not(caption) > * > * { border-color: var(--tc-table-border); }
body.principal-body .accordion-imported-artifacts {
    margin: 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
}
body.principal-body .accordion-imported-artifacts .accordion-item {
    border: 1px solid var(--tc-panel-border) !important;
    border-radius: 12px;
    box-shadow: none;
}
body.principal-body .accordion-imported-artifacts .accordion-button,
body.principal-body .artifact-accordion-header {
    background: var(--tc-panel-bg-solid) !important;
    color: var(--tc-text-main) !important;
    border-radius: 12px;
    font-weight: 500;
}
body.principal-body .accordion-imported-artifacts .accordion-button:not(.collapsed),
body.principal-body .artifact-accordion-header[aria-expanded='true'] {
    background: var(--tc-panel-bg-soft) !important;
    box-shadow: inset 0 -1px var(--tc-panel-border);
    border-radius: 12px 12px 0 0;
}
body :is(.artifact-edit-row, .artifact-id-box) {
    border-color: var(--tc-panel-border);
    border-radius: 8px;
}
body .access-form-card .tab-group {
    padding: 0;
    background: transparent !important;
    border-bottom: 1px solid var(--tc-panel-border);
    border-radius: 0;
}
body .access-form-card .tab-group li a {
    border-radius: 12px 12px 0 0;
    border-bottom: 3px solid transparent;
    background: transparent !important;
    color: var(--tc-text-muted) !important;
    font-weight: 500;
    box-shadow: none;
}
body .access-form-card .tab-group .active a {
    border-bottom-color: var(--tc-button-bg);
    color: var(--tc-interactive-ink, var(--tc-text-main)) !important;
}
body .access-form-card .tab-group li a:hover { background: var(--tc-interactive-hover) !important; }

body .hero-image-wrapper::before,
body .hero-image-wrapper::after { display: none; }
body .hero-image-placeholder { border-style: solid; }
body .hero-image-card i { color: var(--tc-interactive-ink, var(--tc-text-main)); }
body :is(.hero-icon-item, .access-intro-icons span) {
    border: 0;
    border-radius: 16px;
    background: var(--tc-table-head-bg);
    color: var(--tc-interactive-ink, var(--tc-text-main));
}
body footer {
    background: var(--tc-footer-bg) !important;
    border-top: 1px solid var(--tc-panel-border);
    border-radius: 0;
}

/* Keyboard focus remains visible even where older styles remove outlines. */
html body :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--tc-button-bg) !important;
    outline-offset: 3px;
}
@media (max-width: 600px) {
    body :is(.principal-panel, .projects-panel, .account-panel, .admin-panel, .classes-panel, .about-shell) {
        border-radius: 12px;
    }
    body .modal-content { border-radius: 20px; }
    body .traceceni-header .traceceni-main-nav .dropdown-item { min-height: 44px; }
}
@media (max-width: 900px) {
    body .traceceni-header .main-nav.traceceni-main-nav > .traceceni-nav {
        display: none !important;
        position: absolute;
        top: 100%;
        right: 0;
        margin: 0;
        padding: .5rem;
        max-height: calc(100dvh - 140px);
        overflow-y: auto !important;
        background: var(--tc-panel-bg-solid) !important;
        box-shadow: var(--tc-material-shadow-raised) !important;
    }
    /* The legacy click handler toggles .active on the menu trigger. */
    body .traceceni-header .main-nav.traceceni-main-nav:has(.menu-trigger.active) > .traceceni-nav {
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
    }
    body .traceceni-header .traceceni-main-nav .traceceni-nav-item {
        display: block;
        width: 100%;
    }
    body .traceceni-header .traceceni-main-nav .traceceni-nav-link { width: 100% !important; }
    body .traceceni-header .traceceni-main-nav .traceceni-nav-item.dropdown > .dropdown-menu {
        position: static !important;
        transform: none !important;
        min-width: 0;
        width: 100%;
        box-shadow: none !important;
    }
}
@media (prefers-reduced-motion: reduce) {
    html body *, html body *::before, html body *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
