:root {
    color-scheme: dark;
    --trace-bg: #07111f;
    --trace-panel: #101f33;
    --trace-panel-2: #142842;
    --trace-border: #29415f;
    --trace-text: #e8eef7;
    --trace-muted: #91a3bb;
    --trace-orange: #ff8a1f;
    --trace-green: #24c875;
    --trace-yellow: #f2b84b;
    --trace-red: #f05252;
    --trace-blue: #3b82f6;
    --trace-grey: #607089;
}

.trace-shell { background: radial-gradient(circle at 25% 0%, #122b4a 0, var(--trace-bg) 38rem); min-height: 100vh; }
.trace-panel { background: rgba(16, 31, 51, .94); border: 1px solid var(--trace-border); border-radius: 16px; box-shadow: 0 18px 45px rgba(0, 0, 0, .2); }
.trace-eyebrow { color: var(--trace-orange); font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.trace-muted { color: var(--trace-muted); }
.trace-input { background: #0a1728; border: 1px solid var(--trace-border); border-radius: 10px; color: var(--trace-text); min-height: 42px; padding: .55rem .75rem; }
.trace-input:focus { border-color: var(--trace-orange); box-shadow: 0 0 0 3px rgba(255, 138, 31, .15); outline: none; }
.trace-button { align-items: center; background: #1b3554; border: 1px solid #36577b; border-radius: 10px; color: #fff; cursor: pointer; display: inline-flex; font-size: .82rem; font-weight: 700; gap: .35rem; justify-content: center; padding: .55rem .85rem; }
.trace-button:hover { background: #24476f; }
.trace-button.primary { background: #d9680b; border-color: #ff8a1f; }
.trace-button.danger { background: #8f2f35; border-color: #d95059; }
.trace-button:disabled { cursor: not-allowed; opacity: .45; }

.trace-summary-grid { display: grid; gap: 1rem; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.trace-stat { background: linear-gradient(145deg, rgba(29, 53, 82, .85), rgba(10, 23, 40, .9)); border: 1px solid var(--trace-border); border-radius: 14px; padding: 1rem; }
.trace-stat-value { font-size: 1.65rem; font-weight: 800; line-height: 1; margin-top: .5rem; }

.trace-run { overflow: hidden; }
.trace-run-head { align-items: flex-start; display: flex; gap: 1rem; justify-content: space-between; padding: 1.25rem 1.3rem 1rem; }
.trace-run-meta { color: var(--trace-muted); display: flex; flex-wrap: wrap; font-size: .75rem; gap: .45rem 1rem; margin-top: .5rem; }
.trace-progress { background: #07111f; border-radius: 999px; height: 6px; overflow: hidden; }
.trace-progress > span { background: linear-gradient(90deg, #2d7ff9, #26c6da); display: block; height: 100%; transition: width .3s ease; }
.trace-stages { align-items: stretch; display: grid; gap: 7px; grid-template-columns: repeat(7, minmax(88px, 1fr)); overflow-x: auto; padding: 0 1.3rem 1.15rem; }
.trace-stage { background: #192a40; border: 1px solid #344b68; border-radius: 12px; color: #eaf1fa; cursor: pointer; min-height: 92px; padding: .75rem .65rem; position: relative; text-align: left; transition: border-color .15s, transform .15s; }
.trace-stage:hover { border-color: #7c94af; transform: translateY(-2px); }
.trace-stage::before { border-radius: 12px 12px 0 0; content: ''; height: 4px; left: 0; position: absolute; right: 0; top: 0; }
.trace-stage.completed::before { background: var(--trace-green); }
.trace-stage.completed_with_warnings::before { background: var(--trace-yellow); }
.trace-stage.failed::before { background: var(--trace-red); }
.trace-stage.processing::before { animation: tracePulse 1.25s infinite; background: var(--trace-blue); }
.trace-stage.pending::before, .trace-stage.skipped::before { background: var(--trace-grey); }
.trace-stage-name { display: block; font-size: .72rem; font-weight: 800; line-height: 1.25; margin: .25rem 0 .65rem; }
.trace-stage-metrics { color: var(--trace-muted); display: grid; font-size: .66rem; gap: .2rem; grid-template-columns: 1fr 1fr; }
.trace-run-foot { align-items: center; background: rgba(8, 19, 33, .55); border-top: 1px solid var(--trace-border); display: flex; flex-wrap: wrap; gap: .75rem 1.4rem; justify-content: space-between; padding: .8rem 1.3rem; }

.trace-badge { align-items: center; border: 1px solid transparent; border-radius: 999px; display: inline-flex; font-size: .68rem; font-weight: 800; gap: .35rem; padding: .3rem .6rem; text-transform: uppercase; }
.trace-badge::before { background: currentColor; border-radius: 50%; content: ''; height: 6px; width: 6px; }
.trace-badge.success, .trace-badge.healthy, .trace-badge.completed { background: rgba(36, 200, 117, .13); border-color: rgba(36, 200, 117, .35); color: #59df99; }
.trace-badge.partial, .trace-badge.warning, .trace-badge.completed_with_warnings, .trace-badge.outdated { background: rgba(242, 184, 75, .13); border-color: rgba(242, 184, 75, .35); color: #ffd274; }
.trace-badge.failed, .trace-badge.failing, .trace-badge.error, .trace-badge.critical { background: rgba(240, 82, 82, .13); border-color: rgba(240, 82, 82, .35); color: #ff8585; }
.trace-badge.running, .trace-badge.processing, .trace-badge.changed { background: rgba(59, 130, 246, .13); border-color: rgba(59, 130, 246, .35); color: #75adff; }
.trace-badge.queued, .trace-badge.pending, .trace-badge.skipped, .trace-badge.unknown { background: rgba(96, 112, 137, .16); border-color: rgba(126, 146, 176, .35); color: #aebed2; }
.trace-badge.blocked { background: rgba(166, 91, 255, .14); border-color: rgba(166, 91, 255, .35); color: #c799ff; }

.trace-drawer-backdrop { background: rgba(1, 7, 15, .72); inset: 0; opacity: 0; pointer-events: none; position: fixed; transition: opacity .2s; z-index: 60; }
.trace-drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.trace-drawer { background: #0d1b2d; border-left: 1px solid var(--trace-border); bottom: 0; max-width: 520px; overflow-y: auto; padding: 1.35rem; position: absolute; right: 0; top: 0; transform: translateX(100%); transition: transform .25s ease; width: min(92vw, 520px); }
.trace-drawer-backdrop.open .trace-drawer { transform: translateX(0); }
.trace-log { border-left: 2px solid #38516f; margin-left: .4rem; padding: 0 0 1rem 1rem; position: relative; }
.trace-log::before { background: var(--trace-orange); border: 3px solid #0d1b2d; border-radius: 50%; content: ''; height: 12px; left: -7px; position: absolute; top: 2px; width: 12px; }
.trace-empty { color: var(--trace-muted); padding: 3rem 1rem; text-align: center; }
.trace-error-box { background: rgba(240, 82, 82, .1); border: 1px solid rgba(240, 82, 82, .35); border-radius: 10px; color: #ffaaa9; padding: .8rem; }
.trace-delta-positive { color: #5ae09b; }
.trace-delta-negative { color: #ff8585; }
.trace-delta-neutral { color: var(--trace-muted); }

@keyframes tracePulse { 50% { opacity: .4; } }
.loading-spinner { animation: traceSpin .75s linear infinite; border: 2px solid rgba(255,255,255,.3); border-radius: 50%; border-top-color: #fff; display: inline-block; height: 15px; width: 15px; }
@keyframes traceSpin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
    .trace-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .trace-stages { grid-template-columns: repeat(7, minmax(120px, 1fr)); }
}
@media (max-width: 640px) {
    .trace-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .trace-run-head { flex-direction: column; }
    .trace-run-foot { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 760px) {
    header nav { flex-wrap: nowrap !important; max-width: 100%; overflow-x: auto; padding-bottom: .2rem; }
    header nav > * { flex: 0 0 auto; }
}

/* Shared control-room shell used by every authenticated page. */
.app-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.app-sidebar { background: linear-gradient(180deg, #0b192b 0%, #081321 100%); border-right: 1px solid var(--trace-border); display: flex; flex-direction: column; height: 100vh; padding: 1.25rem 1rem; position: sticky; top: 0; z-index: 50; }
.app-brand { align-items: center; display: flex; gap: .75rem; padding: .25rem .5rem 1.25rem; }
.app-brand img { height: 38px; width: 38px; }
.app-brand > span { display: flex; flex-direction: column; line-height: 1.25; }
.app-brand strong { color: #f8fbff; font-size: 1rem; }
.app-brand small { color: #8293ab; font-size: .67rem; letter-spacing: .08em; text-transform: uppercase; }
.app-nav { display: flex; flex: 1; flex-direction: column; gap: 1.3rem; overflow-y: auto; }
.app-nav-group { display: flex; flex-direction: column; gap: .2rem; }
.app-nav-group > p { color: #64758d; font-size: .64rem; font-weight: 800; letter-spacing: .14em; margin: 0 .65rem .35rem; text-transform: uppercase; }
.app-nav-group a { align-items: center; border: 1px solid transparent; border-radius: 10px; color: #aebbd0; display: flex; font-size: .82rem; gap: .7rem; padding: .65rem .7rem; }
.app-nav-group a:hover { background: rgba(43, 70, 103, .35); color: white; }
.app-nav-group a.active { background: linear-gradient(90deg, rgba(30,104,255,.2), rgba(30,104,255,.06)); border-color: rgba(74,135,255,.25); color: #fff; }
.app-nav-icon { align-items: center; color: #7490b3; display: inline-flex; font-size: .82rem; height: 17px; justify-content: center; width: 17px; }
.app-nav-group a.active .app-nav-icon { color: #68a2ff; }
.app-sidebar-foot { border-top: 1px solid var(--trace-border); display: grid; gap: .75rem; padding: 1rem .5rem 0; }
.app-system-state { color: #90a0b7; font-size: .7rem; }
.app-system-state i { background: var(--trace-green); border-radius: 50%; box-shadow: 0 0 0 4px rgba(34,200,117,.1); display: inline-block; height: 7px; margin-right: .45rem; width: 7px; }
.app-logout { color: #9eacc0; font-size: .76rem; text-align: left; }
.app-page-main { min-width: 0; width: 100%; }
.app-page-main.container { max-width: none; padding-left: clamp(1rem,2.5vw,2.6rem); padding-right: clamp(1rem,2.5vw,2.6rem); }
.app-page-main > footer { margin-left: calc(clamp(1rem,2.5vw,2.6rem) * -1); margin-right: calc(clamp(1rem,2.5vw,2.6rem) * -1); padding-left: clamp(1rem,2.5vw,2.6rem); padding-right: clamp(1rem,2.5vw,2.6rem); }

/* Shared skeleton system: preserves layout while data is loading. */
.trace-skeleton { animation: skeletonSweep 1.35s ease-in-out infinite; background: linear-gradient(90deg, #12243a 25%, #203b5b 50%, #12243a 75%); background-size: 220% 100%; border-radius: 8px; color: transparent !important; min-height: 12px; }
.trace-skeleton-card { background: rgba(16,31,51,.94); border: 1px solid var(--trace-border); border-radius: 16px; overflow: hidden; padding: 1.15rem; }
.trace-skeleton-card span { display: block; margin-bottom: .7rem; }
.trace-skeleton-card span:nth-child(1) { height: 10px; width: 36%; }
.trace-skeleton-card span:nth-child(2) { height: 26px; width: 58%; }
.trace-skeleton-card span:nth-child(3) { height: 9px; margin-bottom: 0; width: 78%; }
.trace-skeleton-row { align-items: center; border-bottom: 1px solid rgba(41,65,95,.65); display: grid; gap: 1rem; grid-template-columns: 1.4fr .7fr 1fr .5fr; padding: 1rem; }
.trace-skeleton-row span { height: 11px; }
.trace-skeleton-row span:nth-child(2) { width: 70%; }
.trace-skeleton-row span:nth-child(4) { width: 80%; }
@keyframes skeletonSweep { 0% { background-position: 110% 0; } 100% { background-position: -110% 0; } }

@media (max-width: 900px) {
    .app-shell { display: block; }
    .app-sidebar { border-bottom: 1px solid var(--trace-border); border-right: 0; height: auto; padding: .7rem 1rem; }
    .app-brand { padding: 0; }
    .app-brand small, .app-nav-group > p, .app-sidebar-foot { display: none; }
    .app-nav { flex-direction: row; gap: .35rem; margin-top: .65rem; overflow-x: auto; }
    .app-nav-group { display: contents; }
    .app-nav-group a { flex: 0 0 auto; padding: .5rem .65rem; }
}
@media (max-width: 560px) {
    .app-brand img { height: 30px; width: 30px; }
    .app-brand strong { font-size: .9rem; }
    .app-nav-group a > span:last-child { display: none; }
    .app-nav-group a { justify-content: center; width: 39px; }
    .trace-skeleton-row { grid-template-columns: 1fr .6fr; }
    .trace-skeleton-row span:nth-child(n+3) { display: none; }
}
