/* ============================================================
   tendencia.css — Página de Tendência Térmica K6PM-TH
   Complementa styles.css (dark theme base)
   © SetSystem Automação e Robótica — 2026
   ============================================================ */

/* Layout — body usa flex-column (definido inline no HTML) */
.tend-main {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
    padding: 16px;
    /* height calculado pelo flex do body, não fixo aqui */
    overflow: hidden;
}

@media (max-width: 900px) {
    .tend-main {
        grid-template-columns: 1fr;
        height: auto;
        overflow: auto;
    }
}

/* ── Sidebar ─────────────────────────────────────────────── */
.tend-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding-right: 4px;
}

.tend-sidebar::-webkit-scrollbar { width: 4px; }
.tend-sidebar::-webkit-scrollbar-thumb { background: var(--border-active); border-radius: 4px; }

/* ── Cards ───────────────────────────────────────────────── */
.tend-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tend-card-header {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    margin-bottom: 2px;
}

.tend-card-header svg { color: var(--text-accent); flex-shrink: 0; }

/* ── Form elements ───────────────────────────────────────── */
.tend-select,
.tend-input {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.15s;
    appearance: none;
    -webkit-appearance: none;
}
.tend-select:focus,
.tend-input:focus {
    outline: none;
    border-color: var(--text-accent);
}
.tend-select:disabled { opacity: 0.45; cursor: not-allowed; }

.tend-form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.tend-form-row label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Period buttons ──────────────────────────────────────── */
.tend-period-btns {
    display: flex;
    gap: 6px;
}
.tend-period-btn {
    flex: 1;
    padding: 5px 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.tend-period-btn:hover { border-color: var(--text-accent); color: var(--text-accent); }
.tend-period-btn.active {
    background: rgba(96,165,250,0.15);
    border-color: var(--text-accent);
    color: var(--text-accent);
    font-weight: 600;
}

/* ── Primary button ──────────────────────────────────────── */
.tend-btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 0;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border: none;
    border-radius: 7px;
    color: #fff;
    font-size: 0.875rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}
.tend-btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.tend-btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Back button ─────────────────────────────────────────── */
.tend-btn-back {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.tend-btn-back:hover { color: var(--text-primary); border-color: var(--border-active); }

/* ── Icon button ─────────────────────────────────────────── */
.tend-btn-icon {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.tend-btn-icon:hover:not(:disabled) { border-color: var(--text-accent); color: var(--text-accent); }
.tend-btn-icon:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Toggle switches ─────────────────────────────────────── */
.tend-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    user-select: none;
    padding: 2px 0;
}
.tend-toggle input { display: none; }
.tend-toggle-slider {
    position: relative;
    width: 34px;
    height: 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-active);
    border-radius: 20px;
    flex-shrink: 0;
    transition: background 0.2s;
}
.tend-toggle-slider::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--text-muted);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s, background 0.2s;
}
.tend-toggle input:checked ~ .tend-toggle-slider {
    background: rgba(96,165,250,0.15);
    border-color: var(--clr, #60a5fa);
}
.tend-toggle input:checked ~ .tend-toggle-slider::after {
    transform: translateX(16px);
    background: var(--clr, #60a5fa);
}

/* ── KPI cards ───────────────────────────────────────────── */
.tend-kpis {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.tend-kpi {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.tend-kpi-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}
.tend-kpi-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}
#kpiMax .tend-kpi-value { color: #ef4444; }
#kpiAvg .tend-kpi-value { color: #f59e0b; }
#kpiEvents .tend-kpi-value { color: #f87171; }
#kpiSamples .tend-kpi-value { color: var(--text-accent); }

/* ── Content area ────────────────────────────────────────── */
.tend-content {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding-right: 2px;
}
.tend-content::-webkit-scrollbar { width: 4px; }
.tend-content::-webkit-scrollbar-thumb { background: var(--border-active); border-radius: 4px; }

/* ── Chart cards ─────────────────────────────────────────── */
.tend-chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.tend-chart-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--border-color);
    gap: 10px;
}
.tend-chart-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.tend-chart-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.tend-chart-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}
.tend-chart-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

/* ── Chart body ──────────────────────────────────────────── */
.tend-chart-body {
    position: relative;
    padding: 12px 16px;
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tend-chart-body canvas {
    width: 100% !important;
}

/* ── Empty / loading states ──────────────────────────────── */
.tend-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
    padding: 20px;
}
.tend-empty-icon { font-size: 2.5rem; line-height: 1; }
.tend-empty p { margin: 0; max-width: 320px; }
.tend-empty strong { color: var(--text-secondary); }

.tend-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}
.tend-spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--text-accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Table ───────────────────────────────────────────────── */
.tend-table-wrap {
    overflow-x: auto;
    padding: 0 16px 14px;
}
.tend-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    color: var(--text-primary);
}
.tend-table th {
    padding: 8px 10px;
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
.tend-table td {
    padding: 7px 10px;
    border-bottom: 1px solid rgba(30,41,59,0.6);
    vertical-align: middle;
}
.tend-table tr:hover td { background: var(--bg-hover); }
.tend-td-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 20px !important;
}

/* ── Badge ───────────────────────────────────────────────── */
.tend-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-active);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── State badges ─────────────────────────────────────────── */
.state-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.state-NORMAL      { background: rgba(34,197,94,0.15);  color: #22c55e; }
.state-ATENCAO     { background: rgba(245,158,11,0.15); color: #f59e0b; }
.state-PRE_CRITICO { background: rgba(251,146,60,0.15); color: #fb923c; }
.state-ALARME      { background: rgba(239,68,68,0.15);  color: #ef4444; }
.state-CRITICO     { background: rgba(220,38,38,0.2);   color: #dc2626; }
.state-FALHA       { background: rgba(124,58,237,0.15); color: #a78bfa; }

/* ── Ack button ───────────────────────────────────────────── */
.btn-ack {
    padding: 3px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-ack:hover { border-color: #22c55e; color: #22c55e; }

/* ── Multi-select ────────────────────────────────────────── */
.tend-select[multiple] {
    appearance: auto;
    -webkit-appearance: auto;
    min-height: 80px;
    padding: 4px;
}
.tend-select[multiple] option {
    padding: 4px 6px;
    border-radius: 4px;
}
.tend-select[multiple] option:checked {
    background: rgba(96,165,250,0.25);
    color: var(--text-accent);
}

/* ── Maximize overlay ────────────────────────────────────── */
.tend-maximize-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    z-index: 999;
}
.tend-maximize-backdrop.active { display: block; }

.tend-chart-card.is-maximized {
    position: fixed;
    inset: 24px;
    z-index: 1000;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary, #1e293b);
    box-shadow: 0 24px 64px rgba(0,0,0,0.6);
    overflow: auto;
    animation: maximizeIn 0.18s ease;
}
.tend-chart-card.is-maximized .tend-chart-body {
    flex: 1;
    min-height: 0;
    padding: 16px 20px 20px;
}
.tend-chart-card.is-maximized .tend-chart-body canvas {
    max-height: calc(100vh - 200px);
}

@keyframes maximizeIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

/* Botões de ação do card maximizado */
.tend-card-action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 9px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.tend-card-action-btn:hover { border-color: var(--text-accent); color: var(--text-accent); }
.tend-card-action-btn.close-btn:hover { border-color: #ef4444; color: #ef4444; }

/* Print styles */
@media print {
    .tend-maximize-backdrop,
    .tend-sidebar,
    .app-header,
    .app-footer { display: none !important; }
    .tend-chart-card.is-maximized {
        position: static;
        box-shadow: none;
        border: none;
        inset: auto;
    }
}

/* Opção de exibição que não se aplica à seleção atual (multi-segmento) */
.tend-toggle--off { opacity: .4; cursor: not-allowed; }
.tend-toggle--off .tend-toggle-slider { filter: grayscale(1); }

/* Data + hora lado a lado (calendário nativo de date fecha no clique do dia) */
.tend-datetime { display: flex; gap: 6px; }
.tend-datetime .tend-input { flex: 1 1 auto; min-width: 0; }
.tend-time { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; color: var(--text-muted, #94a3b8); }
.tend-time .tend-input--time { flex: 0 0 auto; width: 58px; padding: 7px 4px; }
