@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --black: #000000;
    --panel: #0c0c0c;
    --panel-raised: #131313;
    --line: #232323;
    --line-bright: #3a3a3a;
    --white: #f2f2f0;
    --dim: #8a8a86;
    --dimmer: #55554f;

    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--black);
    color: var(--white);
    min-height: 100vh;
    line-height: 1.6;
    background-image:
        linear-gradient(var(--line) 1px, transparent 1px),
        linear-gradient(90deg, var(--line) 1px, transparent 1px);
    background-size: 64px 64px;
    background-position: -1px -1px;
    background-attachment: fixed;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--black); }
::-webkit-scrollbar-thumb { background: var(--line-bright); border-radius: 0; border: 2px solid var(--black); }
::-webkit-scrollbar-thumb:hover { background: var(--dim); }

:focus-visible {
    outline: 1px solid var(--white);
    outline-offset: 3px;
}

/* ============ SHELL ============ */

.app-shell {
    max-width: 1360px;
    margin: 0 auto;
    padding: 0 40px 100px;
}

/* Top instrument rail */
.instrument-rail {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 28px 0;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
    position: sticky;
    top: 0;
    background: rgba(0,0,0,0.86);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 200;
}

.rail-mark {
    display: flex;
    align-items: center;
    gap: 14px;
}

.rail-mark-glyph {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line-bright);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    color: var(--white);
}

.rail-mark-glyph::before {
    display: none;
}

.rail-mark-glyph svg {
    width: 16px;
    height: 16px;
    stroke: var(--white);
}

.rail-name {
    font-family: var(--font-display);
    font-size: 1.05em;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.rail-sub {
    font-family: var(--font-mono);
    font-size: 0.68em;
    color: var(--dimmer);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 2px;
}

.rail-nav {
    display: flex;
    gap: 4px;
    align-items: center;
}

.rail-link {
    font-family: var(--font-mono);
    font-size: 0.78em;
    letter-spacing: 0.04em;
    color: var(--dim);
    text-decoration: none;
    padding: 9px 18px;
    border: 1px solid transparent;
    transition: color 0.25s var(--ease-soft), border-color 0.25s var(--ease-soft), background 0.25s var(--ease-soft);
    display: flex;
    align-items: center;
    gap: 8px;
}

.rail-link .tick {
    width: 4px;
    height: 4px;
    background: var(--dimmer);
    transition: background 0.25s var(--ease-soft);
}

.rail-link:hover {
    color: var(--white);
    border-color: var(--line);
}

.rail-link.is-active {
    color: var(--white);
    border-color: var(--line-bright);
    background: var(--panel);
}

.rail-link.is-active .tick {
    background: var(--white);
    box-shadow: 0 0 8px rgba(242,242,240,0.6);
}

/* ============ PAGE HEAD ============ */

.page-head {
    padding: 56px 0 44px;
    animation: riseIn 0.7s var(--ease) backwards;
}

@keyframes riseIn {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-eyebrow {
    font-family: var(--font-mono);
    font-size: 0.72em;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--dimmer);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.page-eyebrow::before {
    content: '';
    width: 22px;
    height: 1px;
    background: var(--line-bright);
}

.page-title {
    font-family: var(--font-display);
    font-size: clamp(2.4em, 5vw, 4.2em);
    font-weight: 600;
    letter-spacing: -0.035em;
    line-height: 1;
    margin-bottom: 18px;
    text-transform: uppercase;
}

.page-desc {
    font-size: 1.05em;
    color: var(--dim);
    max-width: 560px;
    font-weight: 400;
}

/* ============ SIGNATURE: LOAD TRACE ============ */

.trace-panel {
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 0;
    margin-bottom: 40px;
    position: relative;
    overflow: hidden;
    animation: riseIn 0.7s var(--ease) 0.1s backwards;
}

.trace-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 22px 28px 0;
}

.trace-label {
    font-family: var(--font-mono);
    font-size: 0.7em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--dimmer);
}

.trace-readout {
    font-family: var(--font-mono);
    font-size: 1.4em;
    font-weight: 500;
    color: var(--white);
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.trace-readout .unit {
    font-size: 0.5em;
    color: var(--dim);
    letter-spacing: 0.04em;
}

.trace-svg-wrap {
    width: 100%;
    height: 132px;
    position: relative;
}

.trace-svg-wrap svg {
    width: 100%;
    height: 100%;
    display: block;
}

.trace-line {
    fill: none;
    stroke: var(--white);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 6px rgba(242,242,240,0.35));
}

.trace-fill {
    fill: url(#traceGradient);
    opacity: 0.5;
}

.trace-grid line {
    stroke: var(--line);
    stroke-width: 1;
}

.trace-scan {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, transparent, rgba(242,242,240,0.5), transparent);
    animation: scanSweep 6s linear infinite;
    opacity: 0.6;
}

@keyframes scanSweep {
    0% { left: 0%; }
    100% { left: 100%; }
}

.trace-foot {
    display: flex;
    justify-content: space-between;
    padding: 0 28px 18px;
    font-family: var(--font-mono);
    font-size: 0.65em;
    color: var(--dimmer);
    letter-spacing: 0.06em;
}

/* ============ METRIC GRID ============ */

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border: 1px solid var(--line);
    margin-bottom: 40px;
    animation: riseIn 0.7s var(--ease) 0.15s backwards;
}

.metric {
    padding: 26px 28px;
    border-right: 1px solid var(--line);
    position: relative;
    transition: background 0.3s var(--ease-soft);
}

.metric:last-child { border-right: none; }

.metric:hover {
    background: var(--panel);
}

.metric-index {
    position: absolute;
    top: 14px;
    right: 16px;
    font-family: var(--font-mono);
    font-size: 0.62em;
    color: var(--dimmer);
}

.metric-label {
    font-family: var(--font-mono);
    font-size: 0.68em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--dimmer);
    margin-bottom: 14px;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 2.1em;
    font-weight: 500;
    letter-spacing: -0.02em;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.metric-value .unit {
    font-size: 0.42em;
    color: var(--dim);
    font-weight: 400;
}

/* ============ PANELS ============ */

.panel {
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 36px;
    margin-bottom: 28px;
    animation: riseIn 0.7s var(--ease) 0.2s backwards;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
}

.panel-title {
    font-family: var(--font-display);
    font-size: 1.25em;
    font-weight: 600;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 12px;
}

.panel-title::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--white);
}

.panel-actions {
    display: flex;
    gap: 10px;
}

/* ============ BUTTONS ============ */

.btn {
    position: relative;
    font-family: var(--font-mono);
    font-size: 0.76em;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--white);
    background: transparent;
    border: 1px solid var(--line-bright);
    padding: 11px 22px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    transition: border-color 0.3s var(--ease-soft), color 0.3s var(--ease-soft);
    isolation: isolate;
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--white);
    transform: translateY(101%);
    transition: transform 0.35s var(--ease);
    z-index: -1;
}

.btn:hover {
    color: var(--black);
    border-color: var(--white);
}

.btn:hover::before {
    transform: translateY(0%);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--white);
    color: var(--black);
    border-color: var(--white);
}

.btn-primary::before {
    background: var(--black);
}

.btn-primary:hover {
    color: var(--white);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    transition: transform 0.3s var(--ease-soft);
}

.btn-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.btn:hover .btn-icon {
    transform: translateX(2px);
}

.submit-btn .btn-icon {
    transform: translateX(0);
}

.submit-btn:hover .btn-icon {
    transform: translateX(3px);
}

/* ============ CONTROLS / FORM FIELDS ============ */

.controls-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
}

.control-group {
    background: var(--panel);
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-label,
.form-label {
    font-family: var(--font-mono);
    font-size: 0.66em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--dimmer);
}

.control-input,
.form-input,
.form-textarea {
    width: 100%;
    padding: 12px 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line-bright);
    color: var(--white);
    font-family: var(--font-body);
    font-size: 0.95em;
    transition: border-color 0.3s var(--ease-soft);
    border-radius: 0;
}

.control-input { font-family: var(--font-mono); font-size: 0.88em; }

.control-input:focus,
.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-bottom-color: var(--white);
}

.control-input::placeholder,
.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--dimmer);
}

/* ============ CUSTOM DROPDOWN SYSTEM ============ */

.control-select,
.form-select {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

.custom-dropdown {
    position: relative;
    width: 100%;
    user-select: none;
}

.dropdown-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    background: transparent;
    border-bottom: 1px solid var(--line-bright);
    color: var(--white);
    font-family: var(--font-body);
    font-size: 0.95em;
    cursor: pointer;
    transition: border-color 0.3s var(--ease-soft);
}

.dropdown-trigger:hover,
.dropdown-trigger.is-open {
    border-bottom-color: var(--white);
}

.dropdown-trigger .placeholder {
    color: var(--dimmer);
}

.dropdown-arrow {
    width: 10px;
    height: 10px;
    border-right: 1px solid var(--dim);
    border-bottom: 1px solid var(--dim);
    transform: rotate(45deg);
    margin-top: -4px;
    transition: transform 0.3s var(--ease-soft), border-color 0.3s;
}

.dropdown-trigger.is-open .dropdown-arrow {
    transform: rotate(-135deg);
    border-color: var(--white);
}

.dropdown-menu {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    pointer-events: none;
}

.dropdown-menu.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.dropdown-option {
    padding: 14px 20px;
    color: var(--dim);
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 1px solid transparent;
}

.dropdown-option:hover {
    background: var(--line);
    color: var(--white);
}

.dropdown-option.is-selected {
    color: var(--white);
    background: rgba(255,255,255,0.05);
    border-bottom: 1px solid var(--line-bright);
}

.dropdown-menu::-webkit-scrollbar { width: 6px; }
.dropdown-menu::-webkit-scrollbar-track { background: var(--panel-raised); }
.dropdown-menu::-webkit-scrollbar-thumb { background: var(--line-bright); }

/* ============ CHART ============ */

.chart-wrapper {
    position: relative;
    height: 380px;
}

/* ============ TABLE ============ */

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--line);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    font-family: var(--font-mono);
    font-size: 0.68em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--dimmer);
    text-align: left;
    padding: 16px 22px;
    background: var(--panel-raised);
    border-bottom: 1px solid var(--line);
    font-weight: 500;
    white-space: nowrap;
}

td {
    padding: 17px 22px;
    color: var(--dim);
    font-size: 0.92em;
    border-bottom: 1px solid var(--line);
    transition: color 0.2s var(--ease-soft);
}

td .num {
    font-family: var(--font-mono);
    color: var(--white);
}

tr { transition: background 0.2s var(--ease-soft); }
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--panel-raised); }
tr:hover td { color: var(--white); }

.type-tag {
    font-family: var(--font-mono);
    font-size: 0.78em;
    letter-spacing: 0.03em;
    color: var(--white);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.type-tag::before {
    content: '';
    width: 5px;
    height: 5px;
    background: var(--white);
    flex-shrink: 0;
}

.th-remove,
.td-remove {
    width: 1%;
    text-align: center;
    white-space: nowrap;
}

.row-remove {
    position: relative;
    font-family: var(--font-mono);
    font-size: 0.7em;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--line-bright);
    color: var(--dim);
    cursor: pointer;
    overflow: hidden;
    isolation: isolate;
    transition: color 0.3s var(--ease-soft), border-color 0.3s var(--ease-soft);
}

.row-remove::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--white);
    transform: translateY(101%);
    transition: transform 0.3s var(--ease);
    z-index: -1;
}

.row-remove:hover {
    color: var(--black);
    border-color: var(--white);
}

.row-remove:hover::before {
    transform: translateY(0%);
}

.row-remove:active {
    transform: scale(0.96);
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--dimmer);
    font-family: var(--font-mono);
    font-size: 0.85em;
    letter-spacing: 0.04em;
}

.empty-state-mark {
    font-family: var(--font-mono);
    font-size: 2em;
    color: var(--line-bright);
    margin-bottom: 18px;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 70px;
    color: var(--dimmer);
    font-family: var(--font-mono);
    font-size: 0.78em;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.loading-bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 16px;
}

.loading-bars span {
    width: 3px;
    background: var(--white);
    animation: loadBar 1s ease-in-out infinite;
}
.loading-bars span:nth-child(1) { height: 40%; animation-delay: 0s; }
.loading-bars span:nth-child(2) { height: 100%; animation-delay: 0.12s; }
.loading-bars span:nth-child(3) { height: 65%; animation-delay: 0.24s; }
.loading-bars span:nth-child(4) { height: 85%; animation-delay: 0.36s; }

@keyframes loadBar {
    0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
    50% { transform: scaleY(1); opacity: 1; }
}

/* ============ FORM PAGE ============ */

.form-panel {
    max-width: 640px;
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 44px;
    animation: riseIn 0.7s var(--ease) backwards;
}

.form-field {
    margin-bottom: 30px;
}

.form-hint {
    display: block;
    margin-top: 10px;
    font-size: 0.78em;
    color: var(--dimmer);
    font-family: var(--font-mono);
}

.submit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 17px;
    background: var(--white);
    color: var(--black);
    border: 1px solid var(--white);
    font-family: var(--font-mono);
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    margin-top: 8px;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    transition: color 0.35s var(--ease-soft);
}

.submit-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--black);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s var(--ease);
    z-index: -1;
}

.submit-btn:hover {
    color: var(--white);
}

.submit-btn:hover::before {
    transform: scaleX(1);
}

.submit-btn:active {
    transform: scale(0.99);
}

.success-message {
    text-align: center;
    padding: 90px 40px;
    animation: riseIn 0.6s var(--ease);
}

.success-mark {
    width: 56px;
    height: 56px;
    border: 1px solid var(--white);
    margin: 0 auto 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1.4em;
    animation: markSpin 0.6s var(--ease);
}

@keyframes markSpin {
    from { transform: rotate(-90deg) scale(0.5); opacity: 0; }
    to { transform: rotate(0) scale(1); opacity: 1; }
}

.success-title {
    font-family: var(--font-display);
    font-size: 1.6em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    margin-bottom: 12px;
}

.success-text {
    color: var(--dim);
    font-size: 1em;
    max-width: 380px;
    margin: 0 auto;
}

/* ============ RESPONSIVE ============ */

@media (max-width: 980px) {
    .app-shell { padding: 0 24px 80px; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .metric:nth-child(2) { border-right: none; }
    .metric:nth-child(1), .metric:nth-child(2) { border-bottom: 1px solid var(--line); }
    .controls-grid { grid-template-columns: 1fr; }
    .rail-nav .rail-link span.label-text { display: none; }
    .panel { padding: 26px; }
    .form-panel { padding: 30px; }
}

@media (max-width: 600px) {
    .metric-grid { grid-template-columns: 1fr; }
    .metric { border-right: none !important; border-bottom: 1px solid var(--line); }
    .metric:last-child { border-bottom: none; }
    .instrument-rail { flex-direction: column; gap: 16px; align-items: flex-start; padding: 20px 0; }
    .page-title { font-size: 2.1em; }
    .panel-head { flex-direction: column; align-items: flex-start; gap: 14px; }
    .panel-actions { width: 100%; }
    .btn { flex: 1; justify-content: center; }
}
