* { box-sizing: border-box; }
.hidden { display: none !important; }
body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background: #f4f6f8;
    color: #14181f;
    line-height: 1.5;
}
a { color: #1c6dd0; }

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #dfe3e8;
}
.logo-text { font-weight: 600; font-size: 1.1rem; color: #14181f; text-decoration: none; }
.header-nav a { margin-left: 1.25rem; text-decoration: none; font-size: 0.95rem; color: #5b6472; }
.header-nav a:hover { color: #14181f; }

.main-content { width: 95%; margin: 0 auto; padding: 2rem 0; }

.card {
    background: #fff;
    border: 1px solid #dfe3e8;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid #edf0f2; }
th { color: #5b6472; font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.badge-buy { background: #e3f5ea; color: #1a8754; }
.badge-sell { background: #fbe9e7; color: #c0362c; }
.badge-hold { background: #eef1f4; color: #5b6472; }
.badge-on { background: #e3f5ea; color: #1a8754; }
.badge-off { background: #fdf1de; color: #b3690a; }

.btn {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    border-radius: 6px;
    border: none;
    background: #1c6dd0;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.95rem;
    text-decoration: none;
}
.btn:hover { background: #1758a8; }
.btn-secondary { background: #eef1f4; color: #14181f; }
.btn-secondary:hover { background: #e2e6ea; }

.form-group { margin-bottom: 1rem; }
label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; color: #5b6472; }
input, select {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 6px;
    border: 1px solid #dfe3e8;
    background: #fff;
    color: #14181f;
    font-size: 0.95rem;
}
input:focus, select:focus { outline: 2px solid #1c6dd0; outline-offset: -1px; }

.auth-container { display: flex; justify-content: center; padding-top: 3rem; }
.auth-card { width: 100%; max-width: 340px; background: #fff; border: 1px solid #dfe3e8; border-radius: 8px; padding: 2rem; }
.auth-error { background: #fbe9e7; color: #c0362c; padding: 0.6rem 0.8rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }

.stat-row { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.stat { flex: 1; min-width: 140px; }
.stat-label { color: #5b6472; font-size: 0.85rem; }
.stat-value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-value.positive { color: #1a8754; }
.stat-value.negative { color: #c0362c; }

.picker-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.5rem; }
.picker-row .form-group { margin-bottom: 0; min-width: 200px; flex: 1; }

/* Dashboard: chart + Lines/Triggers sidebar side by side, matching the
   reference layout where triggers are built next to the chart they apply
   to rather than on a separate page. */
.dashboard-layout { display: flex; gap: 1.5rem; align-items: flex-start; }
.dashboard-main { flex: 1; min-width: 0; }
.dashboard-sidebar { width: 300px; flex-shrink: 0; }
.dashboard-sidebar .card { margin-bottom: 1.5rem; }
.dashboard-sidebar .card:last-child { margin-bottom: 0; }
@media (max-width: 860px) {
    .dashboard-layout { flex-direction: column; }
    .dashboard-sidebar { width: 100%; }
}

.notice { padding: 0.6rem 0.8rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.notice-ok { background: #e3f5ea; color: #1a8754; }
.notice-error { background: #fbe9e7; color: #c0362c; }
.notice-info { background: #e7f0fb; color: #1c6dd0; }

/* Popup config panel — modelled on a "Trigger Configuration" style builder:
   a floating card with a title + close button, a chained set of fields
   ("X when A [operator] B"), and a two-button footer. */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 24, 31, 0.4);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 4rem 1.5rem 1.5rem;
    z-index: 100;
}
.modal-panel {
    background: #fff;
    border: 1px solid #dfe3e8;
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(20, 24, 31, 0.22);
    width: 100%;
    max-width: 420px;
    padding: 1.5rem;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.modal-header h2 { font-size: 1.1rem; margin: 0; }
.modal-close {
    background: none;
    border: none;
    color: #98a1ad;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
}
.modal-close:hover { background: #eef1f4; color: #14181f; }
.modal-footer { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.modal-footer .btn, .modal-footer .btn-secondary { flex: 1; text-align: center; }
.field-chain-label { font-size: 0.8rem; color: #5b6472; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.5rem; }
.field-chain { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }

.chart-wrap { position: relative; }
.chart-wrap canvas { width: 100%; height: 340px; display: block; }
.chart-wrap.secondary-chart { margin-top: 1rem; }
.chart-wrap.secondary-chart canvas { height: 140px; }
.chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: #14181f;
    color: #fff;
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    line-height: 1.4;
    transform: translate(-50%, -100%);
    white-space: pre-line;
    opacity: 0;
    transition: opacity 0.1s;
}
.chart-legend { display: flex; gap: 1.25rem; margin-top: 0.75rem; font-size: 0.85rem; color: #5b6472; }
.chart-legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; display: inline-block; }
.legend-line { width: 1rem; height: 2px; display: inline-block; }
.legend-remove { cursor: pointer; color: #98a1ad; font-weight: 600; }
.legend-remove:hover { color: #c0362c; }

/* Draggable Line chips in the sidebar — dragged onto any chart panel
   (the main chart or an added blank one) to plot that line there. */
.line-chip {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.6rem;
    border: 1px solid #dfe3e8;
    border-radius: 6px;
    background: #fff;
    font-size: 0.9rem;
    cursor: grab;
}
.line-chip:active { cursor: grabbing; }
.line-chip.dragging { opacity: 0.4; }
.line-chip .drag-handle { color: #98a1ad; }

.blank-panel {
    border: 2px dashed #dfe3e8;
    border-radius: 8px;
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.blank-panel.drag-over { border-color: #1c6dd0; background: #f4f8fd; }
.blank-panel-placeholder { color: #98a1ad; font-size: 0.9rem; text-align: center; padding: 1.5rem; }
.chart-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.chart-panel-header h3 { margin: 0; font-size: 1rem; }
