.modal::backdrop {
    background: rgba(0,0,0,0.4);

    animation: animatetop 0.8s;
}

.modal {
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    padding: 0.5rem;

    animation: animatetop 0.8s;
}

/* Garantir que dialog não aberto não aparece */
dialog:not([open]) {
    display: none !important;
    visibility: hidden !important;
}

.modal-header {
    display: flex;
    align-items: center;
    padding: 0.25rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header .modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
    margin-right: 0;
    pointer-events: auto;
    flex-shrink: 0;
}

.modal-header .modal-actions .btn {
    padding: 4px 10px;
    font-size: 10pt;
    border-radius: 14px;
    cursor: pointer;
    pointer-events: auto;
}

.modal-header .modal-actions .btn-primary {
    background: var(--color-primary);
}

.modal-header .modal-actions .btn-secondary {
    background: var(--color-secondary);
}

.modal-header h2 {
    font-size: 16pt;
    margin: 0;
    margin-right: auto;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-close {
    font-size: 20pt;
    font-weight: bold;
    flex-shrink: 0;
    margin-left: 0;
}

.modal-close:hover,
.modal-close:focus {
    text-decoration: none;
    cursor: pointer;
}

.modal-footer {
    display: flex;
    justify-content: right;
    padding: 0.25rem;
    margin-top: 0.75rem ;
    border-top: 1px solid var(--color-border);
}

.modal-footer .btn {
    margin-left: 0.5rem;
}

@keyframes animatetop {
    from {opacity: 0}
    to {opacity: 1}
}

.modal-matrix{
    height: 45rem;
    width: 80rem;
}

/* Tab styling for info modal */
.info-tab-btn {
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent !important;
}

.info-tab-btn:hover {
    background-color: var(--color-bg-secondary, #f5f5f5) !important;
    text-decoration: underline;
}

.info-tab-active {
    border-bottom: 3px solid var(--color-primary, #007bff) !important;
    color: var(--color-primary, #007bff);
}

.info-tab-content {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Info modal styling */
#info-modal {
    max-width: 90vw;
    max-height: 95vh;
}

#info-modal .modal-body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

#info-modal pre {
    background-color: var(--color-bg-secondary, #f5f5f5);
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
}

/* Draggable and Resizable Modal */
.draggable-modal {
    position: fixed !important;
    overflow: hidden !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    min-width: 300px;
    min-height: 200px;
    width: 800px;
    height: 600px;
    /* Valores padrão - JavaScript sobrescreve estes */
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0 !important;
    display: none !important;
    flex-direction: column !important;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    z-index: 1000;
}

/* Show modal quando open - JavaScript controla posição */
.draggable-modal[open] {
    display: flex !important;
    /* left, top e transform são controlados pelo JavaScript */
}

.draggable-modal::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

.draggable-handle {
    cursor: move;
    user-select: none;
    flex-shrink: 0;
    background: linear-gradient(to right, var(--color-primary, #007bff), var(--color-primary-dark, #0056b3));
    color: white;
    padding: 12px !important;
    border-radius: 8px 8px 0 0;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
}

.draggable-handle h2 {
    margin: 0 !important;
    font-size: 16px;
    color: white;
}

.draggable-handle .modal-close {
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s ease;
    float: none !important;
    margin-left: auto !important;
}

.draggable-handle .modal-close:hover {
    transform: scale(1.2);
}

/* Body scrollable */
.draggable-modal .modal-body {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    /* Default: allow scrolling unless a specific modal overrides */
    overflow: auto !important;
    padding: 0 !important;
    max-height: none !important;
}

/* Reachability tree keeps internal pan handling, so hide scrollbars there */
#gentree-modal .modal-body {
    overflow: hidden !important;
}

/* Info modal: restore vertical scrolling (was blocked by generic hidden overflow) */
#info-modal .modal-body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 20px !important;
    max-height: 80vh !important; /* maintain viewport cap */
    min-height: 0; /* flex child shrink to enable scroll */
    box-sizing: border-box;
}

/* Info modal header: keep buttons on the right */
#info-modal .draggable-handle {
    justify-content: flex-start !important;
}

#info-modal .draggable-handle h2 {
    flex: 0 1 auto;
    margin-right: auto !important;
}

#info-modal .modal-actions {
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 0.5rem;
}

#info-modal .modal-close {
    flex-shrink: 0;
    margin-left: 0 !important;
}

/* Property modal header: keep buttons on the right */
#property-modal .draggable-handle {
    justify-content: flex-start !important;
}

#property-modal .draggable-handle h2 {
    flex: 0 1 auto;
    margin-right: auto !important;
}

#property-modal .modal-actions {
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 0.5rem;
}

#property-modal .modal-close {
    flex-shrink: 0;
    margin-left: 0 !important;
}

#property-modal .modal-body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 20px !important;
    max-height: 80vh !important;
    min-height: 0;
    box-sizing: border-box;
}

/* Physical I/O Mapping modal */
.output-mapping-modal {
    width: min(92vw, 920px);
    max-width: none;
    max-height: 88vh;
    height: min(88vh, 760px);
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--color-border, #333);
    border-radius: 14px;
    background: var(--color-bg-primary, #1e1e2e);
    color: var(--color-text-primary, #e0e0e0);
    box-shadow: 0 22px 64px rgba(0, 0, 0, 0.46);
    flex-direction: column;
}

.output-mapping-modal[open] {
    display: flex;
}

.output-mapping-header {
    background: linear-gradient(135deg, #0f766e 0%, #2563eb 100%);
    color: #fff;
    cursor: move;
    user-select: none;
    gap: 16px;
}

.output-mapping-header h2 {
    margin: 0;
    color: #fff;
    font-size: 19px;
    font-weight: 750;
}

.output-mapping-header p {
    margin: 4px 0 0;
    color: rgba(255,255,255,0.82);
    font-size: 12px;
    line-height: 1.35;
}

.output-mapping-body {
    padding: 18px 22px 20px;
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    background: var(--color-bg-primary, #1e1e2e);
    color: var(--color-text-primary, #e0e0e0);
}

.output-mapping-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.output-mapping-summary-card {
    border: 1px solid rgba(74, 144, 226, 0.25);
    border-radius: 8px;
    background: rgba(74, 144, 226, 0.08);
    padding: 11px 12px;
}

.output-mapping-summary-card strong {
    display: block;
    color: var(--color-primary, #4A90E2);
    font-size: 12px;
    margin-bottom: 4px;
}

.output-mapping-summary-card span {
    display: block;
    color: var(--color-text-secondary, #aaa);
    font-size: 11px;
    line-height: 1.35;
}

.output-mapping-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.output-mapping-table-wrap {
    border: 1px solid var(--color-border, #333);
    border-radius: 10px;
    overflow: auto;
    max-height: none;
    min-height: 180px;
    height: min(46vh, 420px);
    background: var(--color-bg-secondary, #2a2a3a);
}

#output-mapping-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

#output-mapping-table thead tr {
    background: rgba(15, 118, 110, 0.18);
}

#output-mapping-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 10px 12px;
    border-bottom: 2px solid #0f766e;
    color: #67e8f9;
    background: #202837;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-align: left;
    text-transform: uppercase;
}

#output-mapping-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border, #333);
    color: var(--color-text-primary, #e0e0e0);
}

#output-mapping-table tbody tr:hover {
    background: rgba(74, 144, 226, 0.08);
}

#output-mapping-table select,
#output-mapping-table input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--color-border, #444);
    border-radius: 7px;
    background: var(--color-bg-primary, #1e1e2e);
    color: var(--color-text-primary, #e0e0e0);
    padding: 8px 10px;
    font-size: 13px;
}

#output-mapping-table option,
#output-mapping-table input[type="text"]::placeholder {
    color: var(--color-text-primary, #e0e0e0);
}

.output-mapping-modal p,
.output-mapping-modal span,
.output-mapping-modal label,
.output-mapping-modal td {
    color: var(--color-text-primary, #e0e0e0);
}

.output-mapping-header p,
.output-mapping-header span,
.output-mapping-header .modal-close {
    color: #fff;
}

.output-mapping-summary-card span,
.output-mapping-empty span {
    color: var(--color-text-secondary, #aaa);
}

#output-mapping-table select:focus,
#output-mapping-table input[type="text"]:focus {
    outline: none;
    border-color: #14b8a6;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.14);
}

.output-mapping-select-col {
    width: 38px;
}

.output-mapping-type-col {
    width: 100px;
}

.output-mapping-empty {
    display: none;
    padding: 28px 18px;
    text-align: center;
    color: var(--color-text-secondary);
    border: 1px dashed var(--color-border);
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
}

.output-mapping-empty strong,
.output-mapping-empty span {
    display: block;
}

.output-mapping-empty strong {
    color: var(--color-text-primary);
    margin-bottom: 4px;
}

.output-mapping-footer {
    background: var(--color-bg-primary, #1e1e2e);
}

@media (max-width: 720px) {
    .output-mapping-summary {
        grid-template-columns: 1fr;
    }

    .output-mapping-modal {
        width: 96vw;
    }
}

/* Footer stays at bottom */
.draggable-modal .modal-footer {
    flex-shrink: 0 !important;
    background-color: var(--color-bg-secondary, #f5f5f5);
    border-top: 1px solid var(--color-border);
    padding: 12px !important;
    margin-top: 0 !important;
}

/* Tree modal specific layout to avoid bottom cut */
#gentree-modal .plottree {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0; /* allow flex child to shrink */
}

#gentree-modal #tree-container {
    flex: 1 1 auto;
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden; /* svg handles its own internal pan */
}

/* Auto-build modal animations */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}
