/* HFTAlert Bar Data — Dark Theme */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0d0d1a;
    color: #e0e0e0;
    min-height: 100vh;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    background: #1a1a2e;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    padding: 40px;
    width: 360px;
    text-align: center;
}

.login-container h1 {
    color: #4CAFC8;
    margin-bottom: 24px;
    font-size: 24px;
}

.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: #aaa;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    background: #0d0d1a;
    border: 1px solid #3a3a4e;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 14px;
}

.form-group input:focus {
    outline: none;
    border-color: #4CAFC8;
}

button {
    width: 100%;
    padding: 10px;
    background: #4CAFC8;
    color: #0d0d1a;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}

button:hover {
    background: #5dc0d9;
}

.error-message {
    color: #e74c3c;
    font-size: 13px;
    margin-bottom: 12px;
}

/* Chart Page */
.chart-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a3e;
    flex-shrink: 0;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toolbar h1 {
    color: #4CAFC8;
    font-size: 18px;
    font-weight: 700;
}

.symbol-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.symbol-controls input[type="text"] {
    width: 80px;
    padding: 6px 8px;
    background: #0d0d1a;
    border: 1px solid #3a3a4e;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 13px;
    text-transform: uppercase;
}

.symbol-controls select {
    padding: 5px 8px;
    background: #0d0d1a;
    border: 1px solid #3a3a4e;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 12px;
    cursor: pointer;
}

.symbol-controls select:focus {
    outline: none;
    border-color: #4CAFC8;
}

.symbol-controls input[type="number"] {
    width: 70px;
    padding: 5px 8px;
    background: #0d0d1a;
    border: 1px solid #3a3a4e;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 12px;
    text-align: center;
}

.symbol-controls input[type="number"]:focus {
    outline: none;
    border-color: #4CAFC8;
}

.symbol-controls button {
    width: auto;
    padding: 6px 12px;
    font-size: 12px;
    margin-top: 0;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-link {
    color: #4CAFC8;
    font-size: 12px;
    text-decoration: none;
    white-space: nowrap;
}

.nav-link:hover {
    text-decoration: underline;
}

.overlays {
    display: flex;
    gap: 20px;
    font-size: 11px;
}

.overlay-set {
    display: flex;
    align-items: center;
    gap: 2px;
}

.overlay-set span {
    color: #888;
    margin-right: 6px;
    font-weight: 600;
}

.overlay-toggle {
    display: flex;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
}

.overlay-toggle:hover {
    background: #2a2a3e;
}

.overlay-toggle input[type="radio"] {
    margin: 0;
}

#chart-container {
    flex: 1;
    width: 100%;
    min-height: 0;
    position: relative;
}

/* Chart host built by ChartCell inside its container (fills #chart-container on
   the realtime page; per-cell chart area on the grid). */
.cell-chart {
    position: relative;
    width: 100%;
    height: 100%;
}

.chart-legend {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 10;
    pointer-events: none;
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: #e0e0e0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: rgba(13, 13, 26, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #2a2a3e;
    border-top-color: #4CAFC8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    padding: 4px 16px;
    background: #1a1a2e;
    border-top: 1px solid #2a2a3e;
    font-size: 11px;
    color: #888;
    flex-shrink: 0;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

#status-symbol {
    color: #4CAFC8;
}

#status-updated {
    color: #666;
}

/* ---- Multichart grid (multichart.php) --------------------------------- */
.toolbar-subtitle {
    color: #888;
    font-size: 13px;
    font-weight: 600;
}

#settings-btn {
    width: auto;
    margin-top: 0;
    padding: 4px 9px;
    background: transparent;
    color: #4CAFC8;
    border: 1px solid #3a3a4e;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

#settings-btn:hover {
    background: #2a2a3e;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 2), 1fr);
    gap: 4px;
    padding: 4px;
    flex: 1;
    min-height: 0;
}

.chart-grid.fit {
    grid-auto-rows: 1fr;
    overflow: hidden;
}

.chart-grid.scroll {
    grid-auto-rows: var(--row-h, 420px);
    overflow-y: auto;
}

.chart-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: #1a1a2e;
    border: 1px solid #2a2a3e;
    border-radius: 4px;
    overflow: hidden;
}

/* Compact per-cell header built by ChartCell (showTitle:true): symbol · period ·
   metric/source label, instrument description, and a mini loading spinner. */
.cell-title {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 24px;
    padding: 0 8px;
    flex-shrink: 0;
    border-bottom: 1px solid #2a2a3e;
    font-size: 11px;
    overflow: hidden;
}

.cell-title-label {
    color: #4CAFC8;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.cell-title-desc {
    flex: 1;
    min-width: 0;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Per-cell "last updated" clock (HH:MM:SS ET). Muted and pushed to the right;
   flex-shrink:0 + nowrap keep it fully visible while .cell-title-desc (flex:1,
   min-width:0) absorbs the slack and ellipsis-truncates first. tabular-nums stops
   the clock from jittering as digits change. */
.cell-title-updated {
    flex-shrink: 0;
    color: #888;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.cell-title-spinner {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border: 2px solid #2a2a3e;
    border-top-color: #4CAFC8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Delineator cell title extras: the last-bar stats line (muted, flexes to absorb
   slack and ellipsis-truncates before the clock) and the primary "Confirmed"
   badge (green, shown only when the daily series confirms direction). */
.cell-title-stats {
    flex: 1;
    min-width: 0;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}

.cell-title-confirmed {
    flex-shrink: 0;
    color: #26a65b;
    font-weight: 600;
}

/* In a grid cell the chart host flexes to fill below the title (overriding the
   width/height:100% base used on the realtime page's #chart-container). */
.chart-cell > .cell-chart {
    flex: 1;
    min-height: 0;
    height: auto;
}

/* ---- Settings modal --------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(13, 13, 26, 0.7);
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    width: 720px;
    max-width: 94vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    background: #1a1a2e;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #2a2a3e;
    flex-shrink: 0;
}

.modal-header h2 {
    color: #4CAFC8;
    font-size: 16px;
    font-weight: 700;
}

.modal-close {
    width: auto;
    margin-top: 0;
    padding: 2px 8px;
    background: transparent;
    color: #aaa;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    color: #e0e0e0;
    background: transparent;
}

/* Layout controls row (columns / mode / row height). */
.settings-layout-row {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-bottom: 1px solid #2a2a3e;
    font-size: 12px;
    color: #aaa;
    flex-shrink: 0;
}

.settings-layout-row label {
    display: flex;
    align-items: center;
    gap: 6px;
}

.settings-layout-row select,
.settings-layout-row input[type="number"] {
    padding: 5px 8px;
    background: #0d0d1a;
    border: 1px solid #3a3a4e;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 12px;
    width: 70px;
}

.settings-layout-row select:focus,
.settings-layout-row input[type="number"]:focus {
    outline: none;
    border-color: #4CAFC8;
}

.settings-layout-row input[type="number"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.settings-mode {
    display: flex;
    gap: 10px;
}

.settings-mode label {
    cursor: pointer;
}

/* Body: mini-grid preview | per-cell editor. */
.settings-body {
    display: flex;
    gap: 16px;
    padding: 16px;
    min-height: 0;
    overflow: auto;
    flex: 1;
}

.settings-preview-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-preview {
    display: grid;
    grid-template-columns: repeat(var(--cols, 2), 1fr);
    gap: 6px;
    align-content: start;
}

.preview-tile {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    height: 44px;
    padding: 0 8px;
    background: #0d0d1a;
    border: 1px solid #2a2a3e;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
}

/* The only drag origin (see multichart.js). Tile body is click-to-select. */
.tile-handle {
    flex-shrink: 0;
    width: 14px;
    text-align: center;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6a6a7e;
    cursor: grab;
    user-select: none;
}

.tile-handle:active {
    cursor: grabbing;
}

.tile-handle:hover {
    color: #9a9ab0;
}

.preview-tile:hover {
    border-color: #3a3a4e;
}

.preview-tile.selected {
    border-color: #4CAFC8;
    background: #16213a;
}

/* Insertion marker while a tile is dragged over this one. */
.preview-tile.drag-over {
    border-color: #4CAFC8;
    border-style: dashed;
}

.preview-tile-label {
    flex: 1 1 auto;
    min-width: 0;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-tile-remove {
    width: auto;
    margin-top: 0;
    padding: 0 4px;
    background: transparent;
    color: #888;
    border: none;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.preview-tile-remove:hover:not(:disabled) {
    color: #e74c3c;
    background: transparent;
}

.preview-tile-remove:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.settings-add {
    width: auto;
    margin-top: 0;
    align-self: flex-start;
    padding: 6px 12px;
    background: transparent;
    color: #4CAFC8;
    border: 1px solid #3a3a4e;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.settings-add:hover:not(:disabled) {
    background: #2a2a3e;
}

.settings-add:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Per-cell editor form (reuses .symbol-controls / .overlay-set input styling). */
.cell-editor {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-left: 16px;
    border-left: 1px solid #2a2a3e;
    font-size: 12px;
}

.cell-editor .editor-label {
    width: 56px;
    flex-shrink: 0;
    color: #888;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.cell-editor .symbol-controls input[type="text"],
.cell-editor .symbol-controls select,
.cell-editor .symbol-controls input[type="number"] {
    flex: 1;
    text-align: left;
    width: auto;
}

.cell-editor .overlay-set {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 4px 8px;
}

/* Metric (Overlay) and Source groups: the group label sits on its OWN row with
   the radio options wrapping onto the row below it (flex-basis:100% forces the
   break), matching the uppercase label look of the Symbol/Period/Bars rows so the
   whole editor reads consistently. Scoped to .cell-editor so the realtime toolbar
   overlays (inline label + radios) are unaffected. */
.cell-editor .overlay-set span {
    flex-basis: 100%;
    margin-right: 0;
    margin-bottom: 2px;
    text-transform: uppercase;
    font-size: 11px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid #2a2a3e;
    flex-shrink: 0;
}

.modal-footer button {
    width: auto;
    margin-top: 0;
    padding: 8px 18px;
    font-size: 13px;
}

.btn-muted {
    background: #2a2a3e;
    color: #e0e0e0;
}

.btn-muted:hover {
    background: #3a3a4e;
}

.btn-accent {
    background: #4CAFC8;
    color: #0d0d1a;
}

.btn-accent:hover {
    background: #5dc0d9;
}

/* Instrument description — horizontally centered in the status bar, truncating
   with an ellipsis on narrow widths without pushing the edge status elements. */
#status-desc {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    max-width: 50%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #aaa;
    pointer-events: none;
}
