/* Duct Calculator Plugin - Main Styles */
/* All classes prefixed with .duct- to avoid conflicts */

.duct-calculator-wrapper {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
}

/* Header */
.duct-header {
    background: linear-gradient(135deg, #1a3a5c, #2d6a9f);
    color: white;
    padding: 25px 30px;
    border-radius: 10px;
    margin-bottom: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.duct-header h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    color: #ffffff !important;
}

.duct-header .duct-subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 4px;
}

.duct-header .duct-badge {
    background: rgba(255,255,255,0.2);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    border: 1px solid rgba(255,255,255,0.3);
}

/* Navigation Tabs */
.duct-nav-tabs {
    display: flex;
    gap: 5px;
    background: #e9ecef;
    padding: 5px;
    border-radius: 10px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.duct-nav-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: #495057;
    transition: all 0.3s ease;
}

.duct-nav-tab:hover {
    background: rgba(45, 106, 159, 0.1);
}

.duct-nav-tab.active {
    background: #2d6a9f;
    color: white;
    box-shadow: 0 2px 8px rgba(45, 106, 159, 0.3);
}

/* Panels */
.duct-panel {
    display: none;
    background: white;
    border-radius: 10px;
    padding: 25px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    animation: ductFadeIn 0.3s ease;
}

.duct-panel.active {
    display: block;
}

@keyframes ductFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Form Controls */
.duct-form-group {
    margin-bottom: 18px;
}

.duct-form-group label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
    margin-bottom: 5px;
}

.duct-form-group .duct-hint {
    font-size: 12px;
    color: #718096;
    font-weight: 400;
}

.duct-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.duct-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    background: #f7fafc;
}

.duct-input:focus {
    outline: none;
    border-color: #2d6a9f;
    background: white;
    box-shadow: 0 0 0 3px rgba(45, 106, 159, 0.15);
}

.duct-input.duct-input-yellow {
    background: #fffbeb;
    border-color: #f6c23e;
}

.duct-select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    background: #f7fafc;
    transition: border-color 0.3s ease;
}

/* Buttons */
.duct-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.duct-btn-primary {
    background: #2d6a9f;
    color: white;
}

.duct-btn-primary:hover {
    background: #1a4a7a;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(45, 106, 159, 0.3);
}

.duct-btn-success {
    background: #38a169;
    color: white;
}

.duct-btn-success:hover {
    background: #2f855a;
}

.duct-btn-danger {
    background: #e53e3e;
    color: white;
}

.duct-btn-danger:hover {
    background: #c53030;
}

.duct-btn-warning {
    background: #d69e2e;
    color: white;
}

.duct-btn-warning:hover {
    background: #b7791f;
}

.duct-btn-outline {
    background: transparent;
    color: #2d6a9f;
    border: 2px solid #2d6a9f;
}

.duct-btn-outline:hover {
    background: #2d6a9f;
    color: white;
}

.duct-btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

/* Tables */
.duct-table-wrap {
    overflow-x: auto;
    margin: 15px 0;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
}

/* Dica "arraste para o lado" — só visível em telas pequenas (ver media query ≤480px) */
.duct-scroll-hint {
    display: none;
    text-align: center;
    font-size: 11px;
    color: #a0aec0;
    padding: 5px 0;
    margin-bottom: -6px;
}

.duct-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 1000px;
}

.duct-table th {
    background: #2d3748;
    color: white;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

.duct-table td {
    padding: 9px 12px;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: middle;
}

.duct-table tr:hover td {
    background: #f7fafc;
}

.duct-table .duct-status-ok {
    color: #38a169;
    font-weight: 600;
}

.duct-table .duct-status-warning {
    color: #d69e2e;
    font-weight: 600;
}

.duct-table .duct-status-danger {
    color: #e53e3e;
    font-weight: 600;
}

/* Color legend */
.duct-legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    padding: 15px;
    background: #f7fafc;
    border-radius: 8px;
    margin: 15px 0;
}

.duct-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.duct-legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.duct-legend-color.duct-yellow { background: #fffbeb; border-color: #f6c23e; }
.duct-legend-color.duct-green { background: #f0fff4; border-color: #38a169; }
.duct-legend-color.duct-orange { background: #fffbeb; border-color: #ed8936; }
.duct-legend-color.duct-red { background: #fff5f5; border-color: #e53e3e; }

/* Nota informativa acima da tabela de trechos, explicando a opção "Principal" da coluna "Vem do" */
.duct-info-note {
    background: #ebf8ff;
    border-left: 4px solid #4299e1;
    border-radius: 6px;
    padding: 12px 16px;
    margin: 15px 0;
    font-size: 13px;
    line-height: 1.6;
    color: #2c5282;
}

.duct-info-note strong {
    color: #1a365d;
}

/* Dashboard Cards */
.duct-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.duct-dash-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border-left: 4px solid #2d6a9f;
    text-align: center;
}

.duct-dash-card .duct-value {
    font-size: 32px;
    font-weight: 700;
    color: #2d3748;
    display: block;
}

.duct-dash-card .duct-label {
    font-size: 13px;
    color: #718096;
    margin-top: 4px;
}

.duct-dash-card.duct-card-warning { border-left-color: #d69e2e; }
.duct-dash-card.duct-card-danger { border-left-color: #e53e3e; }
.duct-dash-card.duct-card-success { border-left-color: #38a169; }

/* Duct Drawing Canvas */
.duct-canvas-wrap {
    background: #f7fafc;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    border: 1px solid #e2e8f0;
    overflow-x: auto;
}

.duct-drawing {
    min-height: 300px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.duct-drawing svg {
    max-width: 100%;
    height: auto;
}

/* Loading Spinner */
.duct-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: ductSpin 0.8s ease infinite;
}

@keyframes ductSpin {
    to { transform: rotate(360deg); }
}


/* Tooltips */
.duct-tooltip {
    position: relative;
    cursor: help;
}

.duct-tooltip:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #2d3748;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
}

/* Delete button row */
.duct-delete-row {
    cursor: pointer;
    color: #e53e3e;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.duct-delete-row:hover {
    background: #fff5f5;
}

/* ============================================
   FLOW PROGRESS BAR (vazão do equipamento vs. Troncos)
   ============================================ */
.duct-flow-progress {
    margin-bottom: 18px;
}

.duct-flow-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.duct-flow-progress-label {
    font-size: 13px;
    color: #4a5568;
    font-weight: 600;
}

.duct-flow-progress-value {
    font-size: 13px;
    color: #4a5568;
    white-space: nowrap;
}

.duct-flow-progress-track {
    background: #e2e8f0;
    border-radius: 8px;
    height: 14px;
    overflow: hidden;
}

.duct-flow-progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 8px;
    transition: width 0.2s ease, background 0.2s ease;
    background: #48bb78;
}

.duct-flow-progress-bar.duct-flow-ok { background: #48bb78; }
.duct-flow-progress-bar.duct-flow-warn { background: #dd6b20; }
.duct-flow-progress-bar.duct-flow-danger { background: #e53e3e; }

.duct-flow-progress-msg {
    font-size: 12px;
    margin-top: 4px;
}

.duct-flow-progress-msg.duct-flow-ok { color: #38a169; }
.duct-flow-progress-msg.duct-flow-warn { color: #dd6b20; }
.duct-flow-progress-msg.duct-flow-danger { color: #e53e3e; }

/* Mensagem de estouro de vazão em destaque — maior e mais visível que as demais mensagens */
.duct-flow-progress-msg.duct-flow-msg-big {
    font-size: 15px;
    font-weight: 700;
    margin-top: 8px;
}
/* ============================================
   TOAST NOTIFICATIONS (canto inferior direito da calculadora)
   ============================================ */
.duct-toast-container {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    max-width: 380px;
    pointer-events: none;
}

.duct-toast {
    pointer-events: auto;
    background: #2d3748;
    color: #ffffff;
    padding: 16px 20px;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    font-size: 15px;
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    opacity: 0;
    transform: translateY(12px);
    animation: duct-toast-in 0.25s ease forwards;
}

.duct-toast.duct-toast-out {
    animation: duct-toast-out 0.25s ease forwards;
}

.duct-toast-success { background: #276749; border-left: 4px solid #48bb78; }
.duct-toast-error   { background: #822727; border-left: 4px solid #e53e3e; }
.duct-toast-warning { background: #7b341e; border-left: 4px solid #dd6b20; }
.duct-toast-info    { background: #2c5282; border-left: 4px solid #4299e1; }

.duct-toast-emphasis {
    font-size: 17px;
    font-weight: 600;
    padding: 18px 22px;
    max-width: 420px;
}

.duct-toast-message { flex: 1; }

.duct-toast-close {
    cursor: pointer;
    opacity: 0.7;
    font-size: 16px;
    line-height: 1;
    padding: 2px;
    flex-shrink: 0;
}
.duct-toast-close:hover { opacity: 1; }

@keyframes duct-toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes duct-toast-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(12px); }
}

/* ============================================
   RESPONSIVO — TABLET (≤768px)
   ============================================ */
@media (max-width: 768px) {
    .duct-calculator-wrapper {
        padding: 12px;
        border-radius: 8px;
    }

    .duct-header {
        flex-direction: column;
        text-align: center;
        gap: 10px;
        padding: 18px 20px;
    }

    .duct-header h1 {
        font-size: 22px;
    }

    .duct-panel {
        padding: 16px;
    }

    .duct-form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .duct-dashboard-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .duct-nav-tab {
        font-size: 12px;
        padding: 8px 12px;
    }

    /* Botões de ação em coluna única, ocupando a largura toda — mais fácil de tocar */
    .duct-action-row {
        flex-direction: column;
        align-items: stretch;
    }

    .duct-btn {
        width: 100%;
        justify-content: center;
        padding: 12px 20px;
        font-size: 15px;
    }

    .duct-btn-sm {
        width: auto;
        padding: 6px 14px;
        font-size: 12px;
    }
}

/* ============================================
   RESPONSIVO — CELULAR (≤480px)
   ============================================ */
@media (max-width: 480px) {
    .duct-calculator-wrapper {
        padding: 8px;
    }

    .duct-header {
        padding: 14px 16px;
    }

    .duct-header h1 {
        font-size: 19px;
    }

    .duct-header .duct-subtitle {
        font-size: 12px;
    }

    .duct-panel {
        padding: 12px;
        border-radius: 8px;
    }

    .duct-panel h2 {
        font-size: 18px;
    }

    /* Abas em grade 2x3 em vez de uma fileira só, para caberem sem espremer o texto */
    .duct-nav-tabs {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .duct-nav-tab {
        font-size: 12px;
        padding: 10px 8px;
        white-space: normal;
    }

    .duct-dashboard-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .duct-dash-card {
        padding: 14px 10px;
    }

    .duct-dash-card .duct-value {
        font-size: 24px;
    }

    .duct-dash-card .duct-label {
        font-size: 11px;
    }

    .duct-table {
        font-size: 11px;
        min-width: 820px;
    }

    .duct-table th,
    .duct-table td {
        padding: 6px 8px;
    }

    /* Dica de que a tabela rola para o lado — só aparece em telas pequenas */
    .duct-scroll-hint {
        display: block;
    }

    .duct-input,
    .duct-select {
        padding: 10px 12px;
        font-size: 16px; /* 16px evita o zoom automático do Safari/iOS ao focar em campos */
    }

    /* Inputs/selects pequenos dentro das tabelas: a tabela já rola horizontalmente (largura fixa por
       design), então aqui priorizamos altura de toque confortável sobre a regra dos 16px do iOS. */
    .duct-input-sm,
    .duct-select-sm {
        padding: 10px 8px;
        font-size: 13px;
        min-height: 40px;
    }

    /* Botão de excluir linha: área de toque maior, mais fácil de acertar com o dedo */
    .duct-delete-row {
        padding: 10px 12px;
        font-size: 15px;
        display: inline-block;
    }

    .duct-form-group label {
        font-size: 13px;
    }

    .duct-legend {
        gap: 10px;
        padding: 10px;
    }

    .duct-legend-item {
        font-size: 12px;
    }

    .duct-canvas-wrap {
        padding: 10px;
        /* Em vez de encolher o SVG a ponto de o texto ficar ilegível, deixa rolar horizontalmente,
           mantendo o croqui em tamanho legível — mesmo princípio já usado nas tabelas. */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .duct-drawing {
        min-height: 220px;
        justify-content: flex-start;
    }

    .duct-drawing svg {
        max-width: none;
        width: 600px;
        min-width: 600px;
    }

    /* Barra de vazão do equipamento: rótulo e valor empilham em vez de espremer lado a lado */
    .duct-flow-progress-header {
        flex-direction: column;
        gap: 2px;
    }

    .duct-flow-progress-value {
        font-size: 12px;
    }

    /* Toast ocupa a largura útil da tela, com folga das bordas, sem cobrir tudo */
    .duct-toast-container {
        left: 10px;
        right: 10px;
        bottom: 10px;
        max-width: none;
    }

    .duct-toast {
        padding: 12px 14px;
        font-size: 14px;
        border-radius: 8px;
    }
}

/* ============================================
   RESPONSIVO — CELULAR PEQUENO (≤360px)
   ============================================ */
@media (max-width: 360px) {
    .duct-nav-tabs {
        grid-template-columns: 1fr;
    }

    .duct-dashboard-grid {
        grid-template-columns: 1fr;
    }

    .duct-header h1 {
        font-size: 17px;
    }
}

/* ============================================
   ACTION ROWS (grupos de botões no topo dos painéis)
   ============================================ */
.duct-action-row {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.duct-action-row-save {
    margin-top: 25px;
}

.duct-alerts-block {
    margin-top: 20px;
}

.duct-alerts-list {
    background: #f7fafc;
    padding: 15px;
    border-radius: 8px;
    min-height: 60px;
}
