/* =========================================
   FORECAST STRUCTURAL — NEUTRAL EDITION
   Clean, professional, timeless
   ========================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    /* Surfaces */
    --bg-app:        #f0f2f5;
    --bg-surface:    #ffffff;
    --bg-raised:     #f7f8fa;
    --bg-hover:      #eef0f3;
    --bg-active:     #e4e7ec;

    /* Borders */
    --border-subtle: #eaecf0;
    --border-soft:   #dde1e7;
    --border-mid:    #c8cdd6;
    --border-strong: #a8aebb;

    /* Purple — active/accent */
    --purple:        #5b35d5;
    --purple-light:  #7c5ce8;
    --purple-dim:    rgba(91, 53, 213, 0.10);
    --purple-glow:   rgba(91, 53, 213, 0.20);

    /* Semantic */
    --success:       #16a34a;
    --success-dim:   rgba(22, 163, 74, 0.09);
    --warning:       #d97706;
    --warning-dim:   rgba(217, 119, 6, 0.10);
    --danger:        #dc2626;
    --danger-dim:    rgba(220, 38, 38, 0.09);
    --info:          #2563eb;
    --info-dim:      rgba(37, 99, 235, 0.09);
    --orange:        #ea6c00;
    --orange-dim:    rgba(234, 108, 0, 0.09);

    /* Text */
    --text-primary:  #111827;
    --text-secondary:#374151;
    --text-muted:    #6b7280;
    --text-disabled: #d1d5db;

    /* Geometry */
    --toolbar-h:     52px;
    --toolbar-sec-h: 44px;
    --r-sm:  5px;
    --r-md:  8px;
    --r-lg:  12px;
    --r-xl:  16px;

    /* Motion */
    --t-fast: 110ms ease;
    --t-mid:  185ms ease;

    /* Shadows */
    --shadow-xs:    0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:    0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg:    0 12px 32px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);
    --shadow-xl:    0 20px 48px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.06);
}

/* =========================================
   RESET & BASE
   ========================================= */
*, *::before, *::after { box-sizing: border-box; user-select: none; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 13px;
    margin: 0; padding: 0;
    height: 100vh;
    display: flex; flex-direction: column;
    background-color: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* =========================================
   TOOLBAR
   ========================================= */
#toolbar {
    min-height: var(--toolbar-h); /* Garante a altura mínima original */
    height: auto; /* Permite crescer se quebrar a linha */
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-soft);
    display: flex; 
    align-items: center;
    flex-wrap: wrap; /* A MÁGICA: Permite que os botões desçam se faltar espaço */
    padding: 5px 14px; /* Ajustado para dar respiro quando houver 2 linhas */
    gap: 5px;
    row-gap: 8px; /* Espaço vertical entre as linhas quando quebrar */
    z-index: 100; 
    flex-shrink: 0;
    box-shadow: var(--shadow-xs);
    position: relative;
}

/* Garante que o espaçador flexível (que empurra o botão salvar pra direita) 
   não quebre o layout quando a barra virar duas linhas */
#toolbar > div[style*="flex:1"], 
#toolbar > div[style*="flex: 1"] {
    min-width: 20px; 
}

.brand {
    font-size: 14px; font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin-right: 10px;
    white-space: nowrap; flex-shrink: 0;
}

.brand span { font-weight: 300; color: var(--text-muted); }

.tool-separator {
    width: 1px; height: 22px;
    background: var(--border-soft);
    margin: 0 4px; flex-shrink: 0;
}

/* =========================================
   BUTTONS
   ========================================= */
.btn-tool {
    height: 30px; min-width: 30px;
    padding: 0 8px;
    border: 1px solid var(--border-soft);
    background: var(--bg-surface);
    border-radius: var(--r-sm);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
    position: relative;
    font-family: inherit; font-size: 12px; font-weight: 500;
    white-space: nowrap; gap: 5px; flex-shrink: 0;
}

.btn-tool .material-icons { font-size: 17px; line-height: 1; }

.btn-tool:hover {
    background: var(--bg-hover);
    border-color: var(--border-mid);
    color: var(--text-primary);
    box-shadow: var(--shadow-xs);
}

.btn-tool:active { transform: scale(0.97); }

/* Primary — run/calculate */
.btn-tool.primary {
    background: var(--purple);
    border-color: transparent;
    color: #fff; font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.btn-tool.primary:hover {
    background: var(--purple-light);
    box-shadow: var(--shadow-md);
}

/* Danger */
.btn-tool.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-tool.danger:hover { background: var(--danger-dim); border-color: rgba(220,38,38,0.25); }

/* Success */
.btn-tool.success { color: var(--success); border-color: rgba(22,163,74,0.25); }
.btn-tool.success:hover { background: var(--success-dim); }

/* Active — purple */
.btn-tool.active {
    background: var(--purple-dim);
    border-color: rgba(91,53,213,0.30);
    color: var(--purple);
    box-shadow: none;
}

.btn-tool.active::after {
    content: '';
    position: absolute;
    bottom: -7px; left: 50%;
    transform: translateX(-50%);
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--purple);
}

.btn-tool.sm { height: 26px; min-width: 26px; font-size: 11px; padding: 0 7px; }

/* =========================================
   TOOL GROUP
   ========================================= */
.tool-group-buttons {
    display: flex; gap: 2px;
    background: var(--bg-raised);
    padding: 3px; border-radius: var(--r-md);
    border: 1px solid var(--border-soft);
}

.tool-group-buttons .btn-tool { border-color: transparent; background: transparent; }
.tool-group-buttons .btn-tool:hover { background: var(--bg-surface); border-color: var(--border-soft); box-shadow: var(--shadow-xs); }
.tool-group-buttons .tool-separator { height: 18px; margin: 0 1px; }

/* =========================================
   INPUT GROUP
   ========================================= */
.input-group {
    display: flex; align-items: center;
    gap: 4px; font-size: 12px;
    color: var(--text-muted);
    border-right: none; padding-right: 0;
}

.input-group input[type="number"] {
    width: 58px; height: 30px; padding: 0 8px;
    border: 1px solid var(--border-mid);
    border-radius: var(--r-sm);
    background: var(--bg-raised);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px; text-align: center;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    outline: none;
}

.input-group input[type="number"]:focus {
    border-color: var(--purple);
    background: var(--bg-surface);
    box-shadow: 0 0 0 3px var(--purple-dim);
}

input[type="range"] {
    -webkit-appearance: none;
    height: 3px; background: var(--bg-active);
    border-radius: 2px; outline: none; cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px; height: 13px;
    background: var(--purple); border-radius: 50%;
    box-shadow: 0 1px 3px var(--purple-glow);
    transition: transform var(--t-fast);
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.25); }

/* =========================================
   WORKSPACE
   ========================================= */
#workspace {
    flex: 1; display: flex;
    position: relative;
    background: var(--bg-app);
    overflow: hidden;
}

#canvas-wrapper {
    flex: 1; width: 100%; height: 100%;
    position: relative; overflow: hidden;
    cursor: default; background-color: #ffffff;
    box-shadow: 1px 0 0 var(--border-soft), var(--shadow-sm);
}

canvas { position: absolute; top: 0; left: 0; }
#pdf-canvas          { z-index: 1; }
#structural-canvas   { z-index: 2; pointer-events: none; }
#ui-canvas           { z-index: 3; cursor: crosshair; }

/* =========================================
   PROPERTIES PANEL
   ========================================= */
#properties-panel {
    width: 300px; height: 100%;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-soft);
    display: flex; flex-direction: column;
    z-index: 20; flex-shrink: 0;
    box-shadow: -2px 0 8px rgba(0,0,0,0.04);
}

.panel-header {
    background: var(--bg-raised);
    padding: 10px 14px;
    font-weight: 600; font-size: 10px;
    letter-spacing: 0.08em; text-transform: uppercase;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text-muted);
}

.memorial-body {
    padding: 14px; 
    padding-bottom: 80px; /* <--- ADICIONADO: Garante que a rolagem passe do limite da tela e do view-switcher */
    overflow-y: auto; flex: 1;
    font-size: 12.5px; line-height: 1.6;
    scrollbar-width: thin; scrollbar-color: var(--bg-active) transparent;
    color: var(--text-secondary);
}

.memorial-body::-webkit-scrollbar { width: 4px; }
.memorial-body::-webkit-scrollbar-track { background: transparent; }
.memorial-body::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 2px; }

.mem-header { color: var(--text-primary); border-bottom: 1px solid var(--border-soft); padding-bottom: 8px; margin-bottom: 14px; font-size: 13px; font-weight: 600; }
.mem-section-title { font-weight: 600; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin-top: 18px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.mem-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 10px; }
.mem-table th, .mem-table td { border: 1px solid var(--border-subtle); padding: 5px 8px; text-align: left; vertical-align: middle; }
.mem-table th { background: var(--bg-raised); color: var(--text-muted); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.mem-table tr:nth-child(even) { background: var(--bg-raised); }

.result-box { background: var(--success-dim); border: 1px solid rgba(22,163,74,0.20); padding: 10px; border-radius: var(--r-md); text-align: center; margin-top: 14px; }
.as-value { font-size: 15px; font-weight: 700; color: var(--success); font-family: 'JetBrains Mono', monospace; }
.warning-text { color: var(--warning); font-size: 11px; font-style: italic; margin-top: 5px; }

.badge { padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 600; letter-spacing: 0.04em; color: white; display: inline-block; }
.badge-pass { background: var(--success); }
.badge-fail { background: var(--danger); }
.badge-warn { background: var(--warning); }

/* =========================================
   CONTEXT MENU
   ========================================= */
.context-menu {
    display: none; position: absolute;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    box-shadow: var(--shadow-lg);
    border-radius: var(--r-md);
    z-index: 1000; min-width: 195px;
    overflow: hidden;
    animation: menuReveal 0.12s ease-out;
}

@keyframes menuReveal {
    from { opacity: 0; transform: scale(0.96) translateY(-3px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.menu-header { background: var(--bg-raised); padding: 7px 12px; font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border-soft); }
.menu-item { padding: 9px 12px; cursor: pointer; font-size: 12.5px; transition: background var(--t-fast), color var(--t-fast); color: var(--text-secondary); }
.menu-item:hover { background: var(--bg-raised); color: var(--text-primary); }
#ctx-delete { color: var(--danger) !important; border-top: 1px solid var(--border-subtle); }
#ctx-delete:hover { background: var(--danger-dim); }

/* =========================================
   DIAGRAM LEGEND
   ========================================= */
#diagram-legend {
    position: absolute; bottom: 56px; left: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    padding: 7px 12px; border-radius: var(--r-md);
    font-size: 11px; z-index: 30;
    pointer-events: auto; cursor: default;
    box-shadow: var(--shadow-sm);
    color: var(--text-secondary);
    display: flex; align-items: center; gap: 12px;
}

.legend-btn { cursor: pointer; transition: opacity var(--t-mid); display: inline-flex; align-items: center; gap: 5px; padding: 2px 6px; border-radius: var(--r-sm); }
.legend-btn:hover { opacity: 0.8; background: var(--bg-raised); }
.legend-btn.inactive { opacity: 0.35; text-decoration: line-through; filter: grayscale(100%); }

/* =========================================
   FLOATING PROP PANEL
   ========================================= */
.prop-panel {
    display: none; position: absolute;
    top: 70px; right: 24px; width: 230px;
    background: var(--bg-surface);
    border: 1px solid var(--border-mid);
    box-shadow: var(--shadow-lg);
    border-radius: var(--r-lg);
    z-index: 2000; overflow: hidden;
}

.prop-header { background: var(--purple); color: white; padding: 9px 12px; font-size: 12px; font-weight: 600; cursor: move; display: flex; justify-content: space-between; align-items: center; }
.prop-body { padding: 12px; }
.prop-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.prop-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; margin-bottom: 4px; display: block; }

.prop-input {
    width: 100%; padding: 6px 9px;
    border: 1px solid var(--border-mid);
    border-radius: var(--r-sm);
    font-size: 12.5px; background: var(--bg-raised);
    color: var(--text-primary); font-family: inherit;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    outline: none;
}

.prop-input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-dim); background: var(--bg-surface); }
.btn-close-panel { cursor: pointer; font-size: 15px; line-height: 1; opacity: 0.7; color: white; background: none; border: none; padding: 0; }
.btn-close-panel:hover { opacity: 1; }

/* =========================================
   MODALS
   ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(17, 24, 39, 0.45);
    z-index: 2000; display: flex;
    justify-content: center; align-items: center;
    backdrop-filter: blur(4px);
}

.modal-window {
    width: 90%; height: 85%;
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
    display: flex; flex-direction: column;
    overflow: hidden; margin: auto;
    animation: modalIn 0.20s cubic-bezier(0.34, 1.15, 0.64, 1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    height: 52px; background: var(--purple);
    color: white; display: flex; align-items: center;
    justify-content: space-between; padding: 0 20px;
    font-weight: 600; font-size: 13px; flex-shrink: 0;
}

.btn-close {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.20);
    color: white; font-size: 17px; cursor: pointer;
    border-radius: 50%; width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--t-fast); padding: 0;
}
.btn-close:hover { background: rgba(255,255,255,0.28); }

.modal-toolbar { height: 42px; border-bottom: 1px solid var(--border-soft); background: var(--bg-raised); display: flex; align-items: center; padding: 0 14px; gap: 8px; flex-shrink: 0; }
.modal-content { flex: 1; position: relative; background: var(--bg-surface); overflow: hidden; }

.modal-window.mini-modal { width: 400px; height: auto; max-height: 80vh; padding: 0; border-radius: var(--r-xl); position: relative; }
.modal-close-btn { position: absolute; top: 14px; right: 18px; font-size: 20px; color: var(--text-muted); cursor: pointer; line-height: 1; z-index: 10; transition: color var(--t-fast); background: none; border: none; }
.modal-close-btn:hover { color: var(--text-primary); }

.copy-modal-header { text-align: center; padding: 28px 20px 12px; }
.copy-modal-header h3 { margin: 0; font-size: 15px; color: var(--text-primary); font-weight: 600; }
.copy-modal-header p { margin: 7px 0 0; font-size: 12px; color: var(--text-muted); }

.copy-list-container { padding: 14px 22px 28px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.copy-list-container::-webkit-scrollbar { width: 4px; }
.copy-list-container::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 2px; }

.copy-level-item { display: flex; justify-content: space-between; align-items: center; background: var(--bg-raised); border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: 11px 16px; cursor: pointer; transition: all var(--t-mid); }
.copy-level-item:hover { border-color: var(--purple); background: var(--bg-surface); box-shadow: var(--shadow-sm), 0 0 0 3px var(--purple-dim); transform: translateY(-1px); }

.copy-level-name { font-weight: 500; color: var(--text-primary); font-size: 13px; }
.element-badge { background: var(--bg-active); color: var(--text-muted); font-weight: 600; font-size: 11px; padding: 2px 9px; border-radius: 4px; min-width: 30px; text-align: center; font-family: 'JetBrains Mono', monospace; }

/* =========================================
   DETAILING / TABS
   ========================================= */
#detailing-canvas { width: 100%; height: 100%; display: block; }

.tab-btn { padding: 9px 18px; background: transparent; border: none; cursor: pointer; font-weight: 500; font-size: 12px; color: var(--text-muted); border-bottom: 2px solid transparent; transition: color var(--t-fast), border-color var(--t-fast); font-family: inherit; }
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--purple); border-bottom: 2px solid var(--purple); font-weight: 600; }

.modal-window > div[style*="background:#eee"] { background: var(--bg-raised) !important; border-bottom: 1px solid var(--border-soft) !important; }

#view-elevation { overflow: auto; height: 100%; width: 100%; background: var(--bg-raised); padding: 20px; background-image: linear-gradient(var(--border-subtle) 1px, transparent 1px), linear-gradient(90deg, var(--border-subtle) 1px, transparent 1px); background-size: 24px 24px; }
#view-forces { overflow: hidden; padding: 10px; }

/* =========================================
   GRAPH TOOLBAR
   ========================================= */
.graph-toolbar { padding: 8px 14px; border-bottom: 1px solid var(--border-soft); display: flex; gap: 10px; align-items: center; background: var(--bg-raised); height: 48px; flex-shrink: 0; }
.toolbar-label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

.toggle-group { display: flex; background: var(--bg-app); border-radius: var(--r-sm); padding: 2px; gap: 2px; border: 1px solid var(--border-mid); }
.btn-icon-toggle { width: 30px; height: 28px; border: none; background: transparent; border-radius: 4px; cursor: pointer; color: var(--text-muted); display: flex; justify-content: center; align-items: center; transition: all var(--t-fast); font-family: inherit; }
.btn-icon-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon-toggle.active { background: var(--bg-surface); color: var(--purple); box-shadow: var(--shadow-xs); }
.btn-icon-toggle i { font-size: 16px; }

/* =========================================
   WIZARD
   ========================================= */
.wizard-container {
    width: 1080px; max-width: 95vw;
    height: 680px; max-height: 92vh;
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
    display: flex; overflow: hidden;
    animation: slideUp 0.24s cubic-bezier(0.34, 1.1, 0.64, 1);
}

@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.wizard-sidebar { width: 240px; background: var(--bg-raised); border-right: 1px solid var(--border-soft); padding: 28px 16px; display: flex; flex-direction: column; flex-shrink: 0; }
.wizard-brand { font-size: 14px; font-weight: 700; color: var(--text-primary); margin-bottom: 32px; display: flex; align-items: center; gap: 10px; letter-spacing: -0.01em; }
.step-list { list-style: none; padding: 0; margin: 0; }
.step-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; margin-bottom: 3px; color: var(--text-muted); border-radius: var(--r-md); transition: all var(--t-mid); font-size: 12.5px; font-weight: 400; cursor: default; }
.step-item.active { background: var(--purple-dim); color: var(--text-primary); font-weight: 500; }

.step-num { width: 24px; height: 24px; border: 1.5px solid var(--border-mid); border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 11px; font-weight: 600; transition: all var(--t-mid); flex-shrink: 0; font-family: 'JetBrains Mono', monospace; color: var(--text-muted); }
.step-item.active .step-num { border-color: var(--purple); background: var(--purple); color: white; }

.wizard-content { flex: 1; padding: 36px 40px; display: flex; flex-direction: column; background: var(--bg-surface); position: relative; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--bg-active) transparent; }
.wizard-content::-webkit-scrollbar { width: 4px; }
.wizard-content::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 2px; }

.wizard-step { display: none; flex: 1; animation: fadeIn 0.20s ease; }
.wizard-step.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateX(6px); } to { opacity: 1; transform: translateX(0); } }

.step-title { font-size: 20px; font-weight: 700; color: var(--text-primary); margin-bottom: 24px; border-bottom: 1px solid var(--border-soft); padding-bottom: 12px; letter-spacing: -0.02em; }
.subsection-title { font-size: 10px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-muted); margin-top: 22px; margin-bottom: 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; width: 100%; }
.form-grid.three-col { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.four-col { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-group.span-2 { grid-column: span 2; }

.form-group label { font-size: 11px; font-weight: 500; color: var(--text-secondary); }

.form-group input, .form-group select {
    padding: 9px 11px;
    border: 1px solid var(--border-mid);
    border-radius: var(--r-md);
    font-size: 13px;
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
    width: 100%; background: var(--bg-raised);
    color: var(--text-primary); font-family: inherit; outline: none;
}

.form-group input:focus, .form-group select:focus {
    border-color: var(--purple);
    background: var(--bg-surface);
    box-shadow: 0 0 0 3px var(--purple-dim);
}

.form-group select {
    cursor: pointer; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px;
}

.info-box { background: var(--info-dim); border: 1px solid rgba(37,99,235,0.18); color: var(--info); padding: 11px 13px; border-radius: var(--r-md); font-size: 12px; display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.info-box .material-icons { font-size: 17px; }
.columns-2-gap { display: flex; gap: 36px; }
.columns-2-gap > div { flex: 1; }

.level-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; background: var(--bg-raised); padding: 9px 13px; border-radius: var(--r-md); border: 1px solid var(--border-soft); gap: 12px; }
.level-controls .form-group.inline { display: flex; align-items: center; flex-direction: row; gap: 8px; margin-bottom: 0; }
.level-controls .form-group.inline label { white-space: nowrap; font-size: 12px; color: var(--text-secondary); }
.level-controls .btn-tool { white-space: nowrap; flex-shrink: 0; width: auto; height: 30px; padding: 0 12px; }
.level-controls input[type="number"] { width: 75px; height: 28px; padding: 0 8px; border: 1px solid var(--border-mid); border-radius: var(--r-sm); background: var(--bg-surface); color: var(--text-primary); font-family: 'JetBrains Mono', monospace; font-size: 12px; text-align: center; outline: none; }
.level-controls input[type="number"]:focus { border-color: var(--purple); box-shadow: 0 0 0 2px var(--purple-dim); }

.table-wrapper { border: 1px solid var(--border-soft); border-radius: var(--r-md); overflow: hidden; max-height: 280px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--bg-active) transparent; }
.table-wrapper::-webkit-scrollbar { width: 4px; }
.table-wrapper::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 2px; }

.level-table { width: 100%; border-collapse: collapse; }
.level-table th { background: var(--bg-raised); padding: 9px 10px; text-align: left; font-size: 10px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; z-index: 1; }
.level-table td { padding: 0; border-bottom: 1px solid var(--border-subtle); }
.level-row:hover { background: var(--bg-raised); }
.level-row:last-child td { border-bottom: none; }

.invisible-input { width: 100%; padding: 9px 10px; border: none; background: transparent; font-family: inherit; font-size: 12.5px; color: var(--text-primary); outline: none; }
.invisible-input:focus { background: var(--purple-dim); box-shadow: inset 0 0 0 1.5px var(--purple); }
.lvl-id, .lvl-calc { padding: 9px 10px; color: var(--text-muted); font-size: 12px; font-family: 'JetBrains Mono', monospace; background: var(--bg-raised); white-space: nowrap; }

.btn-icon { cursor: pointer; color: var(--text-disabled); font-size: 17px; padding: 8px; transition: color var(--t-fast); display: block; text-align: center; }
.btn-icon:hover { color: var(--danger); }
.btn-icon.disabled { color: var(--border-soft); cursor: default; pointer-events: none; }

.wizard-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--border-soft); display: flex; gap: 10px; flex-shrink: 0; }

.btn-wizard { padding: 9px 22px; border-radius: var(--r-md); font-weight: 600; font-size: 13px; cursor: pointer; border: 1px solid transparent; transition: all var(--t-mid); font-family: inherit; }
.btn-wizard.primary { background: var(--purple); color: white; box-shadow: var(--shadow-sm); }
.btn-wizard.primary:hover { background: var(--purple-light); box-shadow: var(--shadow-md); }
.btn-wizard.secondary { background: var(--bg-raised); border-color: var(--border-mid); color: var(--text-secondary); }
.btn-wizard.secondary:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-wizard.secondary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-wizard.success { background: var(--success); color: white; }
.btn-wizard.success:hover { background: #15803d; }

.wizard-close-btn { position: absolute; top: 14px; right: 14px; background: transparent; border: none; font-size: 22px; color: var(--text-muted); cursor: pointer; line-height: 1; z-index: 100; transition: color var(--t-fast); padding: 0; }
.wizard-close-btn:hover { color: var(--danger); }

#btn-wizard-load { height: 36px; padding: 0 14px; width: 100%; justify-content: center; font-size: 12px; margin-top: 6px; }

/* =========================================
   SECONDARY TOOLBAR (Foundations)
   ========================================= */
.toolbar-secondary {
    /* 1. MUDANÇAS DE POSICIONAMENTO */
    position: relative; /* Remove o absolute para seguir o fluxo do flexbox */
    /* top e left removidos! O navegador calcula sozinho agora. */
    flex-shrink: 0; /* Impede que o Canvas amasse a barra */
    z-index: 90; 

    /* 2. RESPONSIVIDADE (Aproveitando para deixar essa barra responsiva também) */
    width: 100%; 
    min-height: var(--toolbar-sec-h); 
    height: auto; 
    flex-wrap: wrap; /* Permite quebrar botões da base se a tela for muito pequena */
    
    /* 3. ESTILOS ORIGINAIS MANTIDOS */
    background: #fffbf5;
    border-bottom: 1px solid #f0e0ca;
    border-top: 2px solid var(--orange);
    display: flex; 
    align-items: center;
    padding: 5px 14px; /* Ajustado para dar respiro se houver 2 linhas */
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    animation: slideDown 0.18s ease-out;
}

.toolbar-secondary .btn-tool { background: rgba(234,108,0,0.07); border-color: rgba(234,108,0,0.20); color: var(--orange); }
.toolbar-secondary .btn-tool:hover { background: var(--orange); border-color: var(--orange); color: white; }
.toolbar-secondary .btn-tool.primary { background: var(--orange); border-color: transparent; color: white; box-shadow: var(--shadow-sm); }
.toolbar-secondary .btn-tool.primary:hover { background: #c85e00; }
.toolbar-secondary .brand { font-size: 12px !important; color: var(--orange) !important; }
.toolbar-secondary .tool-separator { background: #f0d0b0; }
.toolbar-secondary .btn-tool span { font-size: 11px !important; font-weight: 500 !important; }

@keyframes slideDown { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* =========================================
   VIEW SWITCHER
   ========================================= */
#view-switcher {
    position: absolute; bottom: 0; left: 0;
    width: 100%; height: 38px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-soft);
    z-index: 500; display: flex;
}

.view-tab { flex: 1; max-width: 140px; border: none; background: transparent; cursor: pointer; font-weight: 500; font-size: 11.5px; color: var(--text-muted); display: flex; align-items: center; justify-content: center; gap: 6px; transition: all var(--t-mid); border-right: 1px solid var(--border-subtle); border-top: 2px solid transparent; font-family: inherit; }
.view-tab .material-icons { font-size: 15px; }
.view-tab:hover { background: var(--bg-raised); color: var(--text-secondary); }
.view-tab.active { background: var(--bg-raised); color: var(--purple); border-top-color: var(--purple); font-weight: 600; }
.view-tab.active[onclick*="foundation"] { color: var(--orange); border-top-color: var(--orange); }

/* =========================================
   SPT TABLE
   ========================================= */
.spt-row { display: flex; height: 38px; border-bottom: 1px solid var(--border-subtle); transition: background var(--t-fast); }
.spt-row:nth-child(even) { background: var(--bg-raised); }
.spt-row:hover { background: var(--bg-hover); }
.spt-cell { padding: 0 8px; height: 100%; display: flex; align-items: center; border-right: 1px solid var(--border-subtle); color: var(--text-secondary); font-size: 12px; }
.spt-cell.center { justify-content: center; }
.spt-input { width: 100%; height: 28px; border: 1px solid transparent; background: transparent; font-size: 12px; padding: 4px 6px; color: var(--text-primary); font-family: 'JetBrains Mono', monospace; outline: none; }
.spt-input:focus { border-color: var(--orange); border-radius: var(--r-sm); background: var(--bg-surface); }
.bold-input { font-weight: 700; text-align: center; }

/* =========================================
   COPY OPTIONS
   ========================================= */
.copy-options-container { 
    padding: 18px; 
    overflow-y: auto; /* Permite a rolagem vertical */
    flex: 1; /* Preenche o espaço disponível sem empurrar o modal para fora da tela */
    
    /* Estilização elegante da barra de rolagem */
    scrollbar-width: thin; 
    scrollbar-color: var(--bg-active) transparent; 
}

/* Customização da barra de rolagem para navegadores baseados em WebKit (Chrome, Edge, Safari) */
.copy-options-container::-webkit-scrollbar { 
    width: 4px; 
}
.copy-options-container::-webkit-scrollbar-thumb { 
    background: var(--bg-active); 
    border-radius: 2px; 
}
.copy-option-card { display: flex; justify-content: space-between; align-items: center; background: var(--bg-raised); border: 1px solid var(--border-soft); padding: 13px 15px; border-radius: var(--r-md); margin-bottom: 8px; transition: all var(--t-mid); }
.copy-option-card:hover { border-color: var(--purple); background: var(--bg-surface); box-shadow: var(--shadow-sm), 0 0 0 3px var(--purple-dim); }
.option-label { display: flex; align-items: center; gap: 9px; font-weight: 500; font-size: 13px; color: var(--text-primary); }
.option-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; margin-left: 34px; }

.switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--bg-active); border: 1px solid var(--border-mid); transition: .25s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px; background: white; transition: .25s; border-radius: 50%; box-shadow: var(--shadow-xs); }
input:checked + .slider { background: var(--purple); border-color: var(--purple); }
input:checked + .slider:before { transform: translateX(18px); }

.btn-confirm-copy { width: 100%; padding: 11px; background: var(--purple); color: white; border: none; border-radius: var(--r-md); font-size: 13px; font-weight: 600; cursor: pointer; margin-top: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit; box-shadow: var(--shadow-sm); transition: all var(--t-mid); }
.btn-confirm-copy:hover { background: var(--purple-light); box-shadow: var(--shadow-md); }

/* =========================================
   SLAB CARDS
   ========================================= */
.slab-option-card { flex: 1; border: 1px solid var(--border-mid); border-radius: var(--r-lg); padding: 20px; cursor: pointer; transition: all var(--t-mid); background: var(--bg-raised); text-align: center; }
.slab-option-card:hover { border-color: var(--purple); background: var(--bg-surface); transform: translateY(-2px); box-shadow: var(--shadow-md), 0 0 0 3px var(--purple-dim); }
.slab-option-card h3 { margin: 10px 0 5px; color: var(--text-primary); font-size: 14px; font-weight: 600; }
.slab-option-card p { font-size: 12px; color: var(--text-muted); margin: 0; }

.input-group-text { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.input-group-text input { flex: 1; padding: 7px; border: 1px solid var(--border-mid); border-radius: var(--r-sm); text-align: center; font-weight: 600; background: var(--bg-surface); color: var(--text-primary); font-family: 'JetBrains Mono', monospace; font-size: 13px; outline: none; }
.input-group-text input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-dim); }

/* =========================================
   STAIR WIZARD
   ========================================= */
.stair-type-selector { display: flex; gap: 14px; margin-bottom: 24px; justify-content: center; }
.stair-card { width: 80px; height: 80px; border: 1px solid var(--border-mid); border-radius: var(--r-md); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; transition: all var(--t-mid); background: var(--bg-raised); gap: 4px; }
.stair-card:hover { border-color: var(--border-strong); background: var(--bg-surface); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.stair-card.active { border-color: var(--warning); background: var(--warning-dim); box-shadow: 0 0 0 3px rgba(217,119,6,0.12); }
.stair-icon { font-size: 20px; font-weight: 900; color: var(--text-muted); line-height: 1; }
.stair-card.active .stair-icon { color: var(--warning); }

.stair-type-selector-mini { display: flex; justify-content: space-between; margin-bottom: 14px; background: var(--bg-raised); padding: 3px; border-radius: var(--r-md); border: 1px solid var(--border-soft); }
.btn-type { flex: 1; border: none; background: transparent; padding: 7px; cursor: pointer; font-weight: 500; font-size: 12px; color: var(--text-muted); border-radius: var(--r-sm); transition: all var(--t-mid); font-family: inherit; }
.btn-type:hover { background: var(--bg-hover); color: var(--text-secondary); }
.btn-type.active { background: var(--bg-surface); color: var(--purple); box-shadow: var(--shadow-xs); font-weight: 600; }

.wiz-section-title { font-size: 10px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border-soft); padding-bottom: 6px; margin: 18px 0 10px; }
.wiz-section-title:first-child { margin-top: 0; }
.form-group-compact { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.form-group-compact label { font-size: 12px; color: var(--text-secondary); }
.form-group-compact input { width: 75px; padding: 5px 7px; border: 1px solid var(--border-mid); border-radius: var(--r-sm); text-align: right; background: var(--bg-raised); color: var(--text-primary); font-family: 'JetBrains Mono', monospace; font-size: 12px; outline: none; }
.form-group-compact input:focus { border-color: var(--purple); box-shadow: 0 0 0 2px var(--purple-dim); }
.slider-group { margin-bottom: 14px; }
.slider-group label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 5px; }
.result-display { background: var(--bg-raised); border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: 10px; margin-bottom: 10px; font-size: 12px; color: var(--text-secondary); }
.mini-input { width: 50px; padding: 4px 5px; border: 1px solid var(--border-mid); border-radius: var(--r-sm); text-align: center; background: var(--bg-raised); color: var(--text-primary); font-family: 'JetBrains Mono', monospace; font-size: 12px; outline: none; }
.mini-input:focus { border-color: var(--purple); box-shadow: 0 0 0 2px var(--purple-dim); }
.wiz-divider { height: 1px; background: var(--border-soft); margin: 14px 0; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }

#preview-container { overflow: auto; background-color: var(--bg-raised); background-image: linear-gradient(var(--border-subtle) 1px, transparent 1px), linear-gradient(90deg, var(--border-subtle) 1px, transparent 1px); background-size: 22px 22px; background-position: center; display: grid; place-items: center; scrollbar-width: thin; scrollbar-color: var(--bg-active) transparent; }
#stair-preview-canvas { display: block; box-shadow: var(--shadow-md); margin: 20px; }

.btn-mirror { background: var(--bg-raised); border: 1px solid var(--border-mid); border-radius: var(--r-sm); padding: 5px 10px; cursor: pointer; color: var(--text-secondary); font-size: 12px; display: flex; align-items: center; gap: 5px; transition: all var(--t-mid); font-family: inherit; }
.btn-mirror:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }
.btn-mirror.active { background: var(--info-dim); color: var(--info); border-color: var(--info); }

.result-box-stair { background: var(--bg-raised); padding: 14px; border-radius: var(--r-md); margin-top: 18px; border: 1px solid var(--border-soft); }
.res-item { text-align: center; }
.res-item .lbl { display: block; font-size: 10px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 2px; }
.res-item .val { font-size: 14px; font-weight: 700; color: var(--text-primary); font-family: 'JetBrains Mono', monospace; }

/* =========================================
   REPORT
   ========================================= */
.report-window { width: 920px; height: 90vh; background: #e5e7eb; display: flex; flex-direction: column; border-radius: var(--r-xl); overflow: hidden; box-shadow: var(--shadow-xl); border: 1px solid var(--border-mid); }
.report-toolbar { height: 54px; background: var(--bg-surface); border-bottom: 1px solid var(--border-soft); display: flex; justify-content: space-between; align-items: center; padding: 0 20px; flex-shrink: 0; }
.report-toolbar .material-icons { color: var(--warning); }
.report-scroll-wrapper { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 28px; background-color: #e5e7eb; scrollbar-width: thin; scrollbar-color: var(--bg-active) transparent; }
.report-scroll-wrapper::-webkit-scrollbar { width: 8px; }
.report-scroll-wrapper::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 4px; }

.a4-page { width: 210mm; min-height: 297mm; background: white; margin: 0 auto; padding: 20mm; box-shadow: var(--shadow-lg); color: #000; font-family: "Times New Roman", serif; position: relative; }
.rep-header { border-bottom: 2px solid #000; padding-bottom: 10px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: flex-end; }
.rep-title { font-size: 18pt; font-weight: bold; color: #111827; }
.rep-subtitle { font-size: 10pt; color: #666; }
.rep-section { margin-bottom: 25px; }
.rep-sec-title { font-size: 12pt; font-weight: bold; border-bottom: 1px solid #ccc; margin-bottom: 10px; padding-bottom: 2px; color: #5b35d5; text-transform: uppercase; }
.rep-step { margin-bottom: 15px; padding: 10px; background: #f9fafb; border-left: 3px solid #5b35d5; page-break-inside: avoid; }
.rep-step-title { font-weight: bold; font-size: 11pt; margin-bottom: 5px; }
.rep-step-text { font-size: 10pt; margin-bottom: 8px; }
.rep-formula { font-size: 11pt; padding: 5px 0; text-align: center; }
.rep-diagram-container { width: 100%; height: 150px; border: 1px solid #eee; margin-bottom: 10px; display: flex; justify-content: center; align-items: center; }
.rep-diagram-img { max-width: 100%; max-height: 100%; }

/* =========================================
   LOADING OVERLAY
   ========================================= */
#loading-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(17,24,39,0.75); z-index: 9999; justify-content: center; align-items: center; color: white; flex-direction: column; font-family: 'Inter', sans-serif; backdrop-filter: blur(6px); }
#loading-overlay h2 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
#loading-overlay p { font-size: 12px; color: rgba(255,255,255,0.55); margin: 0; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* =========================================
   OVERRIDES
   ========================================= */
#section-data-panel { background: var(--bg-raised) !important; color: var(--text-secondary); }
#section-data-panel > div { background: var(--bg-surface) !important; border-color: var(--border-soft) !important; box-shadow: var(--shadow-sm) !important; }
#section-data-panel h4 { color: var(--text-primary) !important; border-bottom-color: var(--border-soft) !important; }
#col-res-n { color: var(--danger) !important; font-family: 'JetBrains Mono', monospace; }
#col-res-m { color: var(--info) !important; font-family: 'JetBrains Mono', monospace; }
#col-res-lam { color: var(--text-primary) !important; font-family: 'JetBrains Mono', monospace; }
#col-arm-long { color: var(--success) !important; font-family: 'JetBrains Mono', monospace; }
#col-arm-stir { color: var(--text-secondary) !important; font-family: 'JetBrains Mono', monospace; }
#ribbed-config-modal .modal-window { background: var(--bg-surface) !important; }
#rib-weight-display { color: var(--orange); font-weight: 700; font-family: 'JetBrains Mono', monospace; }
#slab-modal .modal-window { background: var(--bg-surface) !important; }
#btn-toggle-pos span { color: var(--info) !important; font-weight: 700 !important; font-size: 11px !important; }
#btn-toggle-neg span { color: var(--danger) !important; font-weight: 700 !important; font-size: 11px !important; }
#btn-toggle-loads .material-icons { color: var(--danger) !important; }
.btn-tool[onclick*="BudgetExporter"] { color: var(--success) !important; font-weight: 600 !important; width: auto !important; padding: 0 10px !important; }

/* =========================================
   PRINT
   ========================================= */
@media print {
    body * { visibility: hidden; }
    #report-modal, #report-modal * { visibility: visible; }
    #report-modal { position: absolute; left: 0; top: 0; width: 100%; height: auto; background: white; z-index: 9999; display: block !important; overflow: visible; }
    .report-window { width: 100%; height: auto; box-shadow: none; border: none; display: block; overflow: visible; }
    .report-scroll-wrapper { padding: 0; overflow: visible; height: auto; }
    .a4-page { margin: 0; padding: 0; box-shadow: none; width: 100%; min-height: auto; }
    .no-print { display: none !important; }
}

mjx-container { max-width: 100% !important; white-space: normal !important; overflow-x: auto; overflow-y: hidden; }
.rep-formula { max-width: 100%; overflow-wrap: break-word; word-wrap: break-word; }

/* =========================================
   DARK MODE (Modo Escuro)
   ========================================= */
body.dark {
    /* Surfaces (Fundos) */
    --bg-app:        #121212; /* Fundo mais profundo */
    --bg-surface:    #1e1e1e; /* Paineis e Modais */
    --bg-raised:     #252526; /* Barras e Headers */
    --bg-hover:      #2d2d30;
    --bg-active:     #333333;

    /* Borders (Bordas) */
    --border-subtle: #2d2d30;
    --border-soft:   #333333;
    --border-mid:    #3e3e42;
    --border-strong: #555555;

    /* Textos (Claros) */
    --text-primary:  #e0e0e0;
    --text-secondary:#b0b0b0;
    --text-muted:    #808080;
    --text-disabled: #555555;

    /* Ajuste de Sombras para fundo escuro */
    --shadow-xs:    0 1px 2px rgba(0,0,0,0.3);
    --shadow-sm:    0 1px 3px rgba(0,0,0,0.4);
    --shadow-md:    0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg:    0 12px 32px rgba(0,0,0,0.6);
    --shadow-xl:    0 20px 48px rgba(0,0,0,0.7);
    
    /* Cores de Destaque adaptadas */
    --purple:       #7c5ce8; /* Roxo ligeiramente mais claro para dar contraste */
    --purple-dim:   rgba(124, 92, 232, 0.15);
}

/* Ajustes Específicos para o Dark Mode */
body.dark #canvas-wrapper {
    background-color: var(--bg-app); /* O fundo do desenho fica escuro */
}

body.dark .modal-content, 
body.dark #view-elevation,
body.dark .prop-body {
    background-color: var(--bg-surface) !important;
}

body.dark #view-elevation {
    background-image: linear-gradient(var(--border-soft) 1px, transparent 1px), 
                      linear-gradient(90deg, var(--border-soft) 1px, transparent 1px);
}

/* O TRUQUE MÁGICO PARA O PDF DA ARQUITETURA */
/* Inverte as cores do PDF para que o fundo branco vire escuro e as linhas pretas virem brancas */
body.dark #pdf-canvas {
    filter: invert(1) hue-rotate(180deg) contrast(0.85);
}

/* Ajuste de inputs com hardcoded background no HTML */
body.dark input, body.dark select {
    color: var(--text-primary) !important;
}

.legend-container {
        position: absolute; bottom: 20px; left: 20px;
        background: rgba(255, 255, 255, 0.95); padding: 10px 15px;
        border-radius: 8px; border: 1px solid #ccc;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        display: flex; gap: 15px; font-family: 'Segoe UI', Arial, sans-serif;
        z-index: 1000;
    }
    .legend-item {
        display: flex; align-items: center; gap: 8px;
        font-size: 13px; color: #333; font-weight: bold;
        cursor: pointer; transition: all 0.2s ease;
        user-select: none;
    }
    .legend-item:hover { transform: scale(1.05); }
    .legend-item.inactive { opacity: 0.4; filter: grayscale(100%); text-decoration: line-through; }
    .legend-color { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }

    /* =========================================
   MEDIA QUERIES (Responsividade Global)
   ========================================= */

/* Para telas de notebooks pequenos e tablets (até 1200px) */
@media (max-width: 1200px) {
    /* Ajusta o Modal do Wizard */
    .wizard-container {
        width: 95vw;
        height: 95vh;
        flex-direction: column; /* Coloca a barra lateral no topo */
    }

    .wizard-sidebar {
        width: 100%;
        height: auto;
        padding: 15px;
        flex-direction: row; /* Passos ficam em linha horizontal */
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-soft);
    }

    .step-list {
        display: flex;
        gap: 15px;
    }

    .wizard-content {
        padding: 20px;
    }
}

/* Para telas pequenas (até 900px) */
@media (max-width: 900px) {
    /* Transforma grids de 3 ou 4 colunas do Wizard em 1 ou 2 colunas */
    .form-grid.three-col, 
    .form-grid.four-col {
        grid-template-columns: 1fr 1fr;
    }
    
    .columns-2-gap {
        flex-direction: column;
        gap: 15px;
    }

    /* Ajuste dos modais de detalhamento (Viga, Pilar, Laje) */
    .modal-window {
        width: 98% !important;
        height: 98% !important;
        max-width: none !important;
    }

    .modal-content {
        flex-direction: column !important; /* Coloca a aba de propriedades embaixo do desenho */
    }

    #properties-panel, #section-data-panel {
        width: 100% !important;
        max-width: none !important;
        height: 40% !important; /* Divide a tela */
        border-left: none;
        border-top: 1px solid var(--border-soft);
    }
}

/* Oculta textos de botões menos importantes em telas muito pequenas para economizar espaço */
@media (max-width: 768px) {
    .form-grid.three-col, 
    .form-grid.four-col,
    .form-grid {
        grid-template-columns: 1fr; /* Tudo em 1 coluna */
    }
    
    /* Esconde textos dos botões da barra secundária (Infraestrutura) mantendo só o ícone */
    .toolbar-secondary .btn-tool span {
        display: none !important;
    }
}

/* =========================================
   CORREÇÃO DE MODAIS (ANTI-ESMAGAMENTO E RESPONSIVIDADE)
   ========================================= */

/* 1. Proteção contra o esmagamento em telas normais */
.modal-content > div {
    flex-shrink: 0; /* Impede que os painéis laterais sejam esmagados */
}

/* Permite que APENAS as áreas de desenho (Canvas) encolham se necessário */
.modal-content > div[style*="flex"],
#preview-container {
    flex-shrink: 1 !important;
    min-width: 0; /* Previne que o Canvas estoure o layout flex */
}

/* 2. Empilhamento elegante em telas menores (abaixo de 1024px) */
@media (max-width: 1024px) {
    /* Transforma a linha horizontal em uma coluna com rolagem */
    .modal-content, 
    #view-section {
        flex-direction: column !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    /* Os painéis (tanto o menu quanto o desenho) passam a ocupar 100% da largura */
    .modal-content > div,
    #view-section > div {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: max-content;
        flex: none !important; /* Remove proporções como flex:2 ou flex:1 */
        border-right: none !important;
        border-bottom: 1px solid var(--border-soft);
    }

    /* Garante uma altura mínima para a área de desenho não sumir quando empilhada */
    #preview-container,
    #view-section > div:first-child,
    .modal-content > div:last-child {
        min-height: 450px !important;
        border-bottom: none !important;
    }
}