.planning-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.planning-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
}

.planning-header h1 {
    margin: 0;
    font-size: 1.2rem;
    flex: 1;
}

.planning-status {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.planning-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr) 340px;
    gap: 12px;
    padding: 0 12px 12px;
    min-height: 0;
}

.planning-sidebar,
.planning-editor,
.planning-preview {
    padding: 12px;
    overflow: auto;
}

.new-line-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
}

.line-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}

.line-attributes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px 12px;
    margin-bottom: 12px;
}

.line-attributes label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.points-table-wrap {
    overflow-x: auto;
}

.points-table input,
.points-table select {
    width: 100%;
    box-sizing: border-box;
}

/* Larguras mínimas por coluna: sem elas o km ("-3.205") e o tipo ("Estação") ficam cortados. */
.points-table td:nth-child(1) input { min-width: 80px; }
.points-table td:nth-child(2) input { min-width: 150px; }
.points-table td:nth-child(3) input { min-width: 80px; }
.points-table td:nth-child(4) select { min-width: 140px; }
.points-table td:nth-child(5) input { min-width: 64px; }
.points-table td:nth-child(6) input,
.points-table td:nth-child(8) input { min-width: 48px; }
.points-table td:nth-child(7) select { min-width: 100px; }

.point-input.invalid {
    outline: 2px solid var(--accent-alert, #ef4444);
}

.row-errors td {
    color: var(--accent-alert, #ef4444);
    font-size: 0.85em;
    padding-top: 0;
}

.planning-errors {
    color: var(--accent-alert, #ef4444);
    font-size: 0.9em;
}

.planning-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.planning-empty {
    color: var(--text-secondary);
}

#axis-preview {
    width: 100%;
    height: calc(100% - 48px);
    min-height: 480px;
}

/* ---- P1: abas, linha compartilhada, aba Marchas ---- */
.planning-tabs { display: flex; gap: 4px; }
.planning-line-picker { display: flex; align-items: center; gap: 6px; font-size: 0.9em; }
.planning-tab { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.planning-tab[hidden] { display: none; }
.marchas-layout { grid-template-columns: 280px minmax(0, 1fr); }
.new-profile-form { display: grid; gap: 6px; margin: 12px 0; }
.profile-row-error input, .profile-row-error select { outline: 1px solid var(--danger-color, #dc2626); }
.profile-derived { color: var(--text-secondary); font-family: "JetBrains Mono", monospace; }
.context-menu li.disabled { opacity: 0.45; cursor: default; }
.planning-dialog-body { margin: 12px 0 18px; display: grid; gap: 8px; }
.planning-dialog-body label { display: grid; gap: 4px; }

/* ---- P1: aba Grades ---- */
.grades-layout { grid-template-columns: 260px minmax(0, 1fr); }
.grade-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.grade-editor { display: flex; flex-direction: column; min-height: 0; }
.grade-editor #schedule-editor-container { flex: 1; min-height: 480px; overflow: auto; }
.grade-editor .grade-table-wrap { flex: 1; overflow: auto; }
.grade-editor [hidden] { display: none !important; }   /* index.css dá display:flex a .grade-table-wrap */

/* ---- P1: gráfico interativo da grade ---- */
.grade-chart-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 6px 0; }
.grade-chart-toolbar .tab-btn.active { outline: 2px solid var(--accent-interactive); }
.grade-toolbar-hint { color: var(--text-secondary); font-size: 0.85em; }
.grade-trip { fill: none; stroke-width: var(--trip-width, 2); }
.grade-trip.selected { stroke-width: calc(var(--trip-width, 2) * 1px + 1.5px); }
.grade-trip-hit { fill: none; stroke: transparent; stroke-width: 10; cursor: grab; }
.grade-node { fill: var(--chart-bg, #111); stroke: var(--accent-interactive); stroke-width: 2; cursor: ew-resize; }
.grade-trip-label { font-size: 10px; fill: var(--text-secondary); pointer-events: none; }
.grade-ghost { pointer-events: none; }   /* o fantasma é redesenhado a cada mousemove: não pode ser alvo do clique */
.grade-ghost polyline { fill: none; stroke: var(--accent-interactive); stroke-width: 2; stroke-dasharray: 5 4; }
.grade-ghost.invalid polyline { stroke: #dc2626; }
.grade-ghost circle { fill: var(--accent-interactive); }
/* Rótulos fixos à esquerda no gráfico da grade; radios/checkbox dos diálogos da página. */
.grade-axis-labels-bg { fill: var(--chart-bg, #0b1220); opacity: 0.85; pointer-events: none; }
#grade-axis-labels text { pointer-events: none; }
.planning-dialog-body label:has(> input[type="radio"]),
.planning-dialog-body label:has(> input[type="checkbox"]) { display: flex; align-items: center; gap: 6px; }
.planning-dialog-body input[type="radio"],
.planning-dialog-body input[type="checkbox"] { width: auto; margin: 0; }
.planning-dialog-body input[type="number"] { width: 5em; }
#grade-chart-svg > text.station-label { display: none; }   /* os rótulos ficam no grupo fixo #grade-axis-labels */

/* P2: bloco "Parada" do diálogo do nó */
.grade-dwell-block { border: 1px solid var(--panel-border); border-radius: 6px; padding: 8px 10px; display: grid; gap: 6px; margin-top: 6px; }
.grade-dwell-block legend { padding: 0 4px; color: var(--text-secondary); }
.grade-dwell-block input[type="number"] { width: 6em; }

/* P3: campos de estilo do traço e prévia do Prefixar */
.stroke-fields { display: grid; grid-template-columns: repeat(3, auto); gap: 6px 10px; align-items: end; }
.stroke-fields.disabled { opacity: 0.4; pointer-events: none; }
.stroke-fields .stroke-preview { grid-column: 1 / -1; }
.stroke-fields input[type="number"] { width: 5em; }
.prefix-preview { max-height: 320px; overflow: auto; }

/* Aba Acesso */
.access-hint { font-size: 12px; color: var(--text-secondary); margin: 4px 0 8px; }
.access-error { color: #dc2626; font-size: 13px; margin: 0 0 8px; }
.access-secret { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
.access-secret input { flex: 1; font-family: "JetBrains Mono", monospace; font-size: 13px; }

/* ---- P4: Validação, Homologação e Ciclo de Vida ---- */

/* Badges de status da grade */
.badge-status {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.72em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-left: 6px;
}
.badge-draft {
    background: rgba(156, 163, 175, 0.2);
    color: var(--text-secondary, #9ca3af);
}
.badge-homologated {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}
.badge-archived {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Faixa de bloqueio */
.grade-lock-banner {
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: #93c5fd;
    padding: 8px 14px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.88em;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Envoltório do gráfico e painel de validação */
.grade-content-wrap {
    display: flex;
    flex: 1;
    min-height: 480px;
    gap: 8px;
    overflow: hidden;
}
.grade-content-wrap .chart-scroll-container {
    flex: 1;
    min-height: 480px;
    overflow: auto;
}

/* Painel de validação */
.validation-panel {
    width: 330px;
    min-width: 280px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--panel-border, #333);
    background: var(--panel-bg, rgba(20, 24, 33, 0.6));
    border-radius: 6px;
    overflow: hidden;
    transition: width 0.2s ease, min-width 0.2s ease;
}
.validation-panel.collapsed {
    width: 36px;
    min-width: 36px;
}
.validation-panel.collapsed .validation-body,
.validation-panel.collapsed .validation-badges,
.validation-panel.collapsed h3 {
    display: none;
}
.validation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--panel-border, #333);
    gap: 8px;
}
.validation-header h3 {
    margin: 0;
    font-size: 0.95em;
    font-weight: 600;
}
.validation-badges {
    display: flex;
    gap: 6px;
    align-items: center;
}
.val-badge {
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 0.72em;
    font-weight: 600;
}
.val-badge-blocking {
    background: #dc2626;
    color: #fff;
}
.val-badge-accepted {
    background: #d97706;
    color: #fff;
}
.val-badge-info {
    background: #3b82f6;
    color: #fff;
}
.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1em;
    padding: 2px 6px;
    border-radius: 4px;
}
.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary, #fff);
}
.validation-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.validation-by-point {
    font-size: 0.82em;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--panel-border, #333);
}
.validation-findings-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.finding-group-title {
    font-size: 0.78em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 6px 0 2px;
}
.finding-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border, #333);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}
.finding-card:hover {
    background: rgba(255, 255, 255, 0.08);
}
.finding-card.blocking {
    border-left: 3px solid #dc2626;
}
.finding-card.accepted {
    border-left: 3px solid #d97706;
}
.finding-card.info {
    border-left: 3px solid #3b82f6;
}
.finding-desc {
    font-size: 0.85em;
    margin-bottom: 4px;
    line-height: 1.35;
}
.finding-meta {
    font-size: 0.78em;
    color: var(--text-secondary);
}
.finding-actions {
    margin-top: 6px;
    display: flex;
    gap: 6px;
}

/* Marcadores no SVG */
.overtaking-marker {
    cursor: pointer;
    transition: opacity 0.2s;
}
.overtaking-marker.open circle {
    fill: #ef4444;
}
.overtaking-marker.accepted circle {
    fill: rgba(239, 68, 68, 0.45);
}
