:root {
    --primary: #0f3b73;
    --primary-dark: #09264b;
    --primary-hover: #15549f;
    --bg: #f3f6fb;
    --text: #111827;
    --muted: #64748b;
    --border: #e5e7eb;
    --white: #ffffff;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

label {
    display: block;
    margin: 14px 0 7px;
    font-weight: 700;
    color: #22304a;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 13px;
    font: inherit;
    background: var(--white);
    color: var(--text);
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 59, 115, 0.14);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 16px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.18s ease;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-light {
    background: var(--white);
    color: var(--primary);
    border-color: var(--border);
}

.btn-light:hover,
.btn-light.is-active {
    border-color: var(--primary);
    background: #eaf1fb;
}

.btn-full {
    width: 100%;
}

.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #061936 0%, #0f3b73 56%, #15569e 100%);
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    background: var(--white);
    border-radius: 16px;
    padding: 34px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
}

.login-card h1,
.login-card p {
    margin: 0 0 10px;
}

.login-card p {
    color: var(--muted);
    margin-bottom: 24px;
}

.brand-mark {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    margin-bottom: 18px;
    background: var(--primary);
    color: var(--white);
    font-weight: 800;
    letter-spacing: 0;
}

.alert-error {
    margin: 14px 0;
    border: 1px solid #f3b7b2;
    border-radius: 8px;
    padding: 12px;
    background: #fff1f0;
    color: var(--danger);
}

.app-header {
    min-height: 76px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 18px 32px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
}

.app-header h1 {
    margin: 0;
    color: var(--primary);
    font-size: 24px;
}

.app-header span {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.header-actions,
.form-actions,
.editor-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.container {
    width: min(1160px, calc(100% - 32px));
    margin: 30px auto;
}

.container.narrow {
    width: min(820px, calc(100% - 32px));
}

.section-head {
    margin-bottom: 18px;
}

.section-head h2,
.section-head p {
    margin: 0 0 6px;
}

.section-head p {
    color: var(--muted);
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.project-card,
.form-card,
.empty-state {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(15, 59, 115, 0.06);
}

.project-card {
    padding: 20px;
    transition: 0.18s ease;
}

.project-card:hover {
    transform: translateY(-2px);
    border-color: rgba(15, 59, 115, 0.35);
}

.project-card h3 {
    margin: 0 0 10px;
    color: var(--primary);
}

.project-card p {
    min-height: 44px;
    color: var(--muted);
}

.project-card span {
    display: block;
    margin-top: 16px;
    color: #506179;
    font-size: 14px;
}

.empty-state,
.form-card {
    padding: 26px;
}

.empty-state p {
    color: var(--muted);
}

.form-card h2 {
    margin-top: 0;
    color: var(--primary);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
}

.form-actions {
    justify-content: flex-end;
    margin-top: 22px;
}

.editor-page {
    height: 100vh;
    overflow: hidden;
}

.editor-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 16px;
    background: var(--primary);
    color: var(--white);
}

.editor-title {
    min-width: 0;
}

.editor-title strong,
.editor-title span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-title span {
    margin-top: 3px;
    color: #cddbf0;
    font-size: 14px;
}

.editor-shell {
    height: 100vh;
    padding-top: 64px;
    display: grid;
    grid-template-columns: 240px 1fr;
}

.tool-panel {
    background: var(--white);
    border-right: 1px solid var(--border);
    padding: 18px;
    overflow-y: auto;
}

.tool-panel h2 {
    margin: 0 0 14px;
    color: var(--primary);
    font-size: 18px;
}

.tool-btn {
    width: 100%;
    min-height: 40px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafd;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
}

.tool-btn:hover,
.tool-btn.is-active {
    background: #eaf1fb;
    border-color: var(--primary);
    color: var(--primary);
}

.control-group {
    margin-top: 20px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    font-weight: 700;
}

.check-row input {
    width: auto;
}

.save-status {
    min-height: 22px;
    margin-top: 18px;
    color: var(--muted);
    font-size: 14px;
}

.workspace {
    position: relative;
    min-width: 0;
    min-height: 0;
    background: #dce5f1;
}

#map,
#drawCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#drawCanvas {
    z-index: 500;
    pointer-events: none;
    touch-action: none;
}

@media (max-width: 820px) {
    .app-header,
    .editor-topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .editor-topbar {
        min-height: 118px;
    }

    .editor-shell {
        padding-top: 118px;
        grid-template-columns: 160px 1fr;
    }

    .tool-panel {
        padding: 12px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .container {
        width: min(100% - 20px, 1160px);
        margin: 18px auto;
    }

    .login-card {
        padding: 24px;
    }

    .editor-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .tool-panel {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        max-height: 210px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .tool-panel h2,
    .control-group,
    .check-row,
    .save-status {
        grid-column: 1 / -1;
    }

    .tool-btn {
        margin-bottom: 0;
    }
}

/* Editor Etapa 2 */
.editor-body {
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
}

.editor-body .editor-topbar {
    min-height: 64px;
    background: var(--primary);
    color: var(--white);
}

.editor-body .editor-actions {
    align-items: center;
}

.editor-body .btn-light.mode-active,
.editor-body .btn-light.mode-active:hover {
    background: var(--white);
    border-color: var(--white);
    color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.22);
}

.editor-layout {
    height: 100vh;
    padding-top: 64px;
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
}

.editor-layout .tool-panel {
    background: var(--white);
    border-right: 1px solid var(--border);
    padding: 10px;
    overflow-y: auto;
}

.editor-layout .legacy-block-section,
.editor-layout .selected-object-panel {
    display: none;
}

.tool-icons-section {
    padding-bottom: 10px;
}

.tool-icons-section h2 {
    font-size: 11px;
    text-align: center;
}

.tool-icons-section .tool-btn {
    position: relative;
    width: 56px;
    height: 52px;
    min-height: 52px;
    margin: 0 auto 8px;
    padding: 0;
    font-size: 0;
    border-radius: 12px;
}

.tool-icons-section .tool-btn::before {
    display: block;
    font-size: 22px;
    line-height: 1;
}

.tool-icons-section .tool-btn[data-tool="select"]::before {
    content: "↖";
}

.tool-icons-section .tool-btn[data-tool="pencil"]::before {
    content: "✎";
}

.tool-icons-section .tool-btn[data-tool="line"]::before {
    content: "/";
    font-weight: 900;
}

.tool-icons-section .tool-btn[data-tool="cable"]::before {
    content: "⌁";
}

.tool-icons-section .tool-btn[data-tool="measure"]::before {
    content: "↔";
}

.tool-icons-section .tool-btn[data-tool="eraser"]::before {
    content: "⌫";
}

.tool-section {
    padding: 0 0 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.tool-section h2 {
    margin: 0 0 10px;
    color: var(--primary);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0;
    cursor: pointer;
    user-select: none;
}

.tool-section h2::after {
    content: "-";
    float: right;
    font-weight: 900;
}

.tool-section.collapsed h2::after {
    content: "+";
}

.tool-section.collapsed > :not(h2) {
    display: none !important;
}

.tool-section label {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text);
}

.tool-section input[type="range"] {
    padding: 0;
}

.tool-section input[type="color"] {
    height: 42px;
    padding: 4px;
}

.editor-layout .tool-btn {
    min-height: 42px;
    margin-bottom: 8px;
    border-color: var(--border);
    background: #f8fafc;
    color: var(--text);
}

.editor-layout .tool-btn:hover,
.editor-layout .tool-btn.active {
    background: #eaf1fb;
    border-color: var(--primary);
    color: var(--primary);
}

.editor-layout .tool-btn.primary-tool {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.editor-layout .tool-btn.primary-tool:hover {
    background: var(--primary-hover);
}

.editor-layout .map-tool-btn {
    background: #eef6ff;
    border-color: #bfdbfe;
    color: var(--primary);
}

.editor-layout .tool-btn:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.editor-layout .check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.editor-layout .check-row input {
    width: auto;
}

.editor-layout .save-status {
    min-height: 22px;
    margin: 4px 0 12px;
    color: var(--muted);
    font-size: 13px;
}

.canvas-area {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #dbe4ef;
}

.canvas-area #map,
.canvas-area #drawCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.canvas-area #map {
    z-index: 1;
}

.canvas-area #drawCanvas {
    z-index: 2;
    pointer-events: none;
    touch-action: none;
}

.bottom-toolbar {
    display: none;
}

.bottom-tool-btn {
    min-width: 72px;
    min-height: 48px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--white);
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
}

.bottom-tool-btn.active {
    background: #eaf1fb;
    border-color: var(--primary);
    color: var(--primary);
}

.bottom-tool-btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.hidden {
    display: none !important;
}

.tool-hint {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.block-list {
    display: grid;
    gap: 8px;
}

.block-btn {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    background: #f8fafc;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
    text-align: left;
}

.block-btn:hover,
.block-btn.active {
    background: #eaf1fb;
    border-color: var(--primary);
    color: var(--primary);
}

.block-icon {
    position: relative;
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    display: inline-block;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.block-icon-poste {
    border-radius: 50%;
}

.block-icon-poste::before,
.block-icon-poste::after {
    content: "";
    position: absolute;
    background: var(--primary);
}

.block-icon-poste::before {
    left: 6px;
    right: 6px;
    top: 12px;
    height: 2px;
}

.block-icon-poste::after {
    top: 6px;
    bottom: 6px;
    left: 12px;
    width: 2px;
}

.block-icon-luminaria {
    border-radius: 50% 50% 8px 8px;
    border-top-color: transparent;
}

.block-icon-luminaria::before {
    content: "";
    position: absolute;
    left: -11px;
    top: 12px;
    width: 14px;
    height: 2px;
    background: var(--primary);
}

.block-icon-braco {
    border: 0;
}

.block-icon-braco::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 4px;
    width: 16px;
    height: 18px;
    border-left: 2px solid var(--primary);
    border-top: 2px solid var(--primary);
    border-radius: 8px 0 0 0;
}

.block-icon-comando,
.block-icon-medidor,
.block-icon-transformador {
    border-radius: 5px;
}

.block-icon-comando::before,
.block-icon-medidor::before,
.block-icon-transformador::before {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 800;
}

.block-icon-comando::before {
    content: "C";
}

.block-icon-medidor::before {
    content: "M";
}

.block-icon-transformador {
    border-radius: 50%;
}

.block-icon-transformador::before {
    content: "T";
}

.block-icon-transformador::after {
    content: "";
    position: absolute;
    inset: 5px;
    border: 2px solid var(--primary);
    border-radius: 50%;
}

.selected-object-panel .object-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.selected-object-panel .object-actions-grid .tool-btn {
    margin-bottom: 0;
    font-size: 12px;
}

.legend-panel {
    display: grid;
    gap: 8px;
}

.legend-item {
    display: grid;
    grid-template-columns: 26px 1fr;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--text);
    font-size: 13px;
    line-height: 1.3;
}

.legend-symbol {
    width: 24px;
    height: 24px;
}

.legend-empty {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(440px, 100%);
    background: var(--white);
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.32);
}

.modal-card-wide {
    width: min(720px, 100%);
}

.modal-card h2 {
    margin: 0 0 8px;
    color: var(--primary);
}

.modal-card p {
    margin: 0 0 14px;
    color: var(--muted);
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
}

.form-row {
    min-width: 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.selection-panel {
    margin-bottom: 10px;
}

.selection-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    background: #f8fafc;
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
}

.selection-card.muted {
    color: var(--muted);
}

.cable-legend-symbol {
    position: relative;
    display: inline-block;
    width: 24px;
    height: 18px;
}

.cable-legend-symbol::before {
    content: "";
    position: absolute;
    left: 1px;
    right: 1px;
    top: 8px;
    border-top: 3px solid var(--primary);
}

.connection-selected {
    outline: 2px solid var(--primary-hover);
}

.cable-step-hint {
    color: #b45309;
    font-weight: 700;
}

.scale-panel .tool-btn {
    margin-top: 8px;
}

.scale-status {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--primary);
    font-weight: 700;
    font-size: 13px;
}

.drawing-lock-status {
    margin-top: 6px;
    background: #eef2ff;
    color: #1e3a8a;
}

.btn.active,
.sidebar-toggle-btn.active,
.tool-btn.mode-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.hint-box {
    margin-top: 10px;
    padding: 10px;
    border-radius: 8px;
    background: #fff7ed;
    color: #9a3412;
    font-size: 12px;
    line-height: 1.35;
}

.coordinates-box {
    font-variant-numeric: tabular-nums;
}

.summary-panel .selection-card {
    font-size: 13px;
}

.ruler-info,
.measurement-label {
    color: var(--primary);
    font-weight: 700;
}

.report-page {
    background: var(--bg);
}

.report-container {
    width: min(1100px, calc(100% - 32px));
    margin: 28px auto;
}

.report-header,
.report-section {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px;
    margin-bottom: 18px;
    box-shadow: 0 10px 28px rgba(15, 59, 115, 0.06);
}

.report-header h1,
.report-section h2 {
    margin: 0 0 10px;
    color: var(--primary);
}

.report-header p {
    color: var(--muted);
}

.report-section table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.report-section th,
.report-section td {
    border-bottom: 1px solid var(--border);
    padding: 9px;
    text-align: left;
    vertical-align: top;
}

.report-section th {
    color: var(--primary);
    background: #f8fafc;
}

@media print {
    @page {
        size: A4 landscape;
        margin: 0;
    }

    .no-print {
        display: none !important;
    }

    .report-page {
        background: #fff;
    }

    .report-container {
        width: 100%;
        margin: 0;
    }

    .report-header,
    .report-section {
        box-shadow: none;
        break-inside: avoid;
    }
}

.blocks-sidebar {
    position: fixed;
    top: 64px;
    right: 0;
    bottom: 0;
    z-index: 1100;
    width: min(360px, 92vw);
    padding: 14px;
    background: var(--white);
    border-left: 1px solid var(--border);
    box-shadow: -16px 0 36px rgba(15, 23, 42, 0.16);
    transform: translateX(105%);
    transition: transform 0.2s ease;
    overflow-y: auto;
}

.blocks-sidebar.open {
    transform: translateX(0);
}

.blocks-sidebar-header,
.mobile-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.blocks-sidebar-header h3 {
    margin: 0;
    color: var(--primary);
}

.blocks-sidebar-header button,
.floating-object-toolbar button,
.multi-cable-panel button {
    border: 1px solid var(--border);
    border-radius: 8px;
    min-height: 34px;
    background: #f8fafc;
    color: var(--primary);
    font-weight: 700;
    cursor: pointer;
}

.block-groups-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 12px 0;
}

.block-group-tab {
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 8px 12px;
    background: #f8fafc;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
}

.block-group-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.blocks-list {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
}

.block-card {
    display: grid;
    grid-template-columns: 34px 1fr;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 58px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: #fff;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.block-card.active,
.block-card:hover {
    border-color: var(--primary);
    background: #eaf1fb;
}

.block-card-title,
.block-card-subtitle {
    display: block;
}

.block-card-subtitle {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.floating-object-toolbar {
    position: fixed;
    z-index: 1250;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.18);
}

.floating-object-toolbar span {
    padding: 0 8px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.floating-object-toolbar #floatDelete {
    display: none;
}

.multi-cable-panel {
    position: fixed;
    left: 50%;
    bottom: 84px;
    z-index: 1250;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100% - 24px);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
}

.multi-cable-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 14px;
}

.multi-cable-table th,
.multi-cable-table td {
    border-bottom: 1px solid var(--border);
    padding: 8px;
    text-align: left;
}

.multi-cable-table input {
    min-width: 96px;
}

.gesture-hint {
    color: var(--muted);
    font-size: 12px;
}

.sidebar-toggle-btn {
    border-color: rgba(255, 255, 255, 0.5);
}

.tool-icons-section .tool-btn[data-tool="select"]::before {
    content: "S";
}

.tool-icons-section .tool-btn[data-tool="pencil"]::before {
    content: "P";
}

.tool-icons-section .tool-btn[data-tool="cable"]::before {
    content: "~";
}

.tool-icons-section .tool-btn[data-tool="measure"]::before {
    content: "<>";
    font-size: 18px;
}

.tool-icons-section .tool-btn[data-tool="eraser"]::before {
    content: "X";
}

.smart-logo {
    width: 156px;
    height: 44px;
    object-fit: contain;
    padding: 4px 10px;
    border-radius: 10px;
    background: #fff;
}

.editor-title {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.right-workspace-panel {
    width: 360px;
}

.panel-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.panel-tab,
.layers-toolbar button,
.layer-actions button,
.layer-icon,
.properties-card button,
.block-card-actions button {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
}

.panel-tab {
    min-height: 34px;
    font-size: 12px;
}

.panel-tab.active {
    background: #eaf1fb;
    border-color: var(--primary);
    color: var(--primary);
}

.panel-pane {
    display: none;
    padding: 12px;
}

.panel-pane.active {
    display: block;
}

.panel-actions {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.layers-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.layers-toolbar button {
    min-height: 34px;
    padding: 0 10px;
}

.layers-panel {
    display: grid;
    gap: 8px;
}

.layer-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}

.layer-row.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(15, 59, 115, 0.08);
}

.layer-row.locked {
    background: #f8fafc;
}

.layer-main {
    display: grid;
    grid-template-columns: 34px 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
    padding: 8px;
}

.layer-icon {
    min-height: 30px;
    font-size: 11px;
}

.layer-name {
    border: 0;
    background: transparent;
    color: var(--text);
    font-weight: 800;
    text-align: left;
    min-width: 0;
    cursor: pointer;
}

.layer-main small {
    color: var(--muted);
    font-weight: 700;
}

.layer-actions {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    padding: 0 8px 8px;
}

.layer-actions button {
    min-height: 26px;
    padding: 0 7px;
    font-size: 11px;
}

.layer-objects {
    border-top: 1px solid var(--border);
    padding: 6px 8px 8px;
    background: #f8fafc;
}

.layer-object-item {
    padding: 4px 0;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.properties-panel {
    display: grid;
    gap: 10px;
}

.properties-card {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    font-size: 13px;
}

.properties-card label {
    display: grid;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
}

.properties-card input,
.properties-card select {
    min-height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    color: var(--text);
}

.properties-card button {
    min-height: 36px;
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.block-card {
    position: relative;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: #fff;
    text-align: left;
    cursor: pointer;
}

.block-card.active,
.block-card:hover {
    border-color: var(--primary);
    background: #f0f7ff;
}

.block-empty-state {
    display: grid;
    gap: 6px;
    padding: 16px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #475569;
    font-size: 13px;
}

.block-card-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.block-card-actions button {
    min-height: 26px;
    padding: 0 8px;
    font-size: 11px;
}

.leaflet-control-scale {
    border: 1px solid rgba(15, 59, 115, 0.25);
    border-radius: 10px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.leaflet-control-scale-line {
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 800;
    background: transparent;
}

.tool-icons-section .tool-btn[data-tool="polyline"]::before { content: "PL"; font-size: 16px; }
.tool-icons-section .tool-btn[data-tool="curve"]::before { content: "CV"; font-size: 16px; }
.tool-icons-section .tool-btn[data-tool="rect"]::before { content: "RE"; font-size: 16px; }
.tool-icons-section .tool-btn[data-tool="circle"]::before { content: "CI"; font-size: 16px; }
.tool-icons-section .tool-btn[data-tool="text"]::before { content: "T"; }
.tool-icons-section .tool-btn[data-tool="move"]::before { content: "M"; }
.tool-icons-section .tool-btn[data-tool="rotate"]::before { content: "R"; }
.tool-icons-section .tool-btn[data-tool="scale"]::before { content: "Z"; }
.tool-icons-section .tool-btn[data-tool="duplicate"]::before { content: "D"; }
.tool-icons-section .toggle-tool {
    font-size: 0 !important;
    line-height: 1;
}

.tool-icons-section .toggle-tool::before {
    content: attr(title);
    font-size: 10px;
    line-height: 1.05;
    text-align: center;
    white-space: normal;
}

.block-drawing-tools button[data-block-draw-tool="move"] {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: var(--primary);
}

.block-selected-info {
    margin-top: 8px;
    padding: 8px 10px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #eff6ff;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
}

.block-elements-panel {
    display: grid;
    gap: 6px;
    max-height: 190px;
    overflow: auto;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
}

.block-elements-panel > strong {
    color: var(--primary);
    font-size: 13px;
}

.block-elements-empty {
    color: var(--muted);
    font-size: 12px;
}

.block-element-row {
    min-height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    text-align: left;
    padding: 6px 8px;
    cursor: pointer;
}

.block-element-row.active {
    border-color: var(--primary);
    background: #e0f2fe;
    color: var(--primary);
    font-weight: 800;
}

.block-element-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}

.block-element-actions button {
    min-height: 34px;
    border: 1px solid #dbe3ef;
    border-radius: 8px;
    background: #fff;
    color: var(--primary);
    font-weight: 800;
}

.legacy-block-section,
.mobile-block-panel {
    display: none !important;
}

.pdf-stamp {
    display: none;
}

.print-frame-overlay {
    position: absolute;
    inset: 18px;
    --stamp-w: 55%;
    --stamp-h: 22%;
    z-index: 9;
    pointer-events: none;
    border: 1px solid rgba(15, 59, 115, 0.9);
    box-shadow: none;
}

.print-frame-overlay.hidden {
    display: none;
}

.print-frame-safe-area {
    position: absolute;
    inset: 16px;
    border: 1px dashed rgba(15, 59, 115, 0.7);
}

.print-frame-stamp-space {
    position: absolute;
    right: 16px;
    bottom: 16px;
    width: var(--stamp-w);
    height: var(--stamp-h);
    display: grid;
    place-items: center;
    border: 1px dashed rgba(220, 38, 38, 0.8);
    background: rgba(255, 255, 255, 0.7);
    color: #991b1b;
    font-size: 12px;
    font-weight: 800;
}

.stamp-logo-cell,
.stamp-cell,
.stamp-row-wide,
.stamp-mini {
    border: 1px solid #111;
    padding: 2px 5px;
    background: #fff;
    color: #111;
    font-family: Arial, sans-serif;
    overflow: hidden;
}

.stamp-logo-cell {
    grid-row: 1 / span 3;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.stamp-logo-mark {
    color: #0783c8;
    font-size: 34px;
    font-weight: 900;
    font-style: italic;
    line-height: 1;
}

.stamp-logo-img {
    max-width: 36mm;
    max-height: 26mm;
    object-fit: contain;
}

.stamp-cell,
.stamp-mini {
    display: grid;
    gap: 1px;
}

.stamp-cell small,
.stamp-row-wide small,
.stamp-mini small {
    display: block;
    font-size: 6px;
    line-height: 1;
    color: #0f3b73;
}

.stamp-cell strong,
.stamp-row-wide strong,
.stamp-mini strong {
    font-size: 9px;
    line-height: 1.1;
}

.stamp-client strong {
    font-size: 16px;
    line-height: 1;
}

.stamp-row-wide {
    grid-column: 2 / span 2;
    text-align: left;
}

.stamp-logo-cell.empty {
    gap: 0;
}

.stamp-logo-cell span {
    font-size: 10px;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
}

@media print {
    body.pdf-export-mode {
        background: #fff;
        overflow: hidden;
    }

    body.pdf-export-mode .editor-topbar,
    body.pdf-export-mode .tool-panel,
    body.pdf-export-mode .blocks-sidebar,
    body.pdf-export-mode .bottom-toolbar,
    body.pdf-export-mode .floating-object-toolbar,
    body.pdf-export-mode .multi-cable-panel,
    body.pdf-export-mode .map-floating-tools {
        display: none !important;
    }

    body.pdf-export-mode .pdf-stamp {
        position: fixed;
        right: 14mm;
        bottom: 14mm;
        z-index: 3000;
        display: grid !important;
        grid-template-columns: 42mm 49mm 49mm 15mm;
        grid-template-rows: 14mm 11mm 9mm 9mm;
        width: 155mm;
        height: 43mm;
        border: 1px solid #111;
        background: #fff;
        font-family: Arial, sans-serif;
        page-break-inside: avoid;
    }

    body.pdf-export-mode .pdf-stamp > div {
        border: 0;
        border-right: 1px solid #111;
        border-bottom: 1px solid #111;
    }

    body.pdf-export-mode .pdf-stamp > div:nth-child(3),
    body.pdf-export-mode .pdf-stamp > div:nth-child(4),
    body.pdf-export-mode .pdf-stamp > div:nth-child(6),
    body.pdf-export-mode .pdf-stamp > div:nth-child(10) {
        border-right: 0;
    }

    body.pdf-export-mode .pdf-stamp > div:nth-child(n+7) {
        border-bottom: 0;
    }

    body.pdf-export-mode .stamp-logo-cell {
        grid-column: 1;
        grid-row: 1 / span 3;
    }

    body.pdf-export-mode .stamp-tech {
        grid-column: 2;
        grid-row: 1;
    }

    body.pdf-export-mode .stamp-client {
        grid-column: 3 / span 2;
        grid-row: 1;
    }

    body.pdf-export-mode .stamp-row-wide {
        grid-column: 2 / span 3;
        grid-row: 2;
    }

    body.pdf-export-mode .stamp-mini:nth-of-type(5) {
        grid-column: 2;
        grid-row: 3;
    }

    body.pdf-export-mode .stamp-mini:nth-of-type(6) {
        grid-column: 3 / span 2;
        grid-row: 3;
    }

    body.pdf-export-mode .stamp-mini:nth-of-type(7) {
        grid-column: 1;
        grid-row: 4;
    }

    body.pdf-export-mode .stamp-mini:nth-of-type(8) {
        grid-column: 2;
        grid-row: 4;
    }

    body.pdf-export-mode .stamp-mini:nth-of-type(9) {
        grid-column: 3;
        grid-row: 4;
    }

    body.pdf-export-mode .stamp-sheet {
        grid-column: 4;
        grid-row: 4;
    }

    body.pdf-export-mode .editor-layout {
        display: block !important;
        height: 100vh !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    body.pdf-export-mode .canvas-area {
        position: fixed !important;
        inset: 8mm !important;
        width: auto !important;
        height: auto !important;
        overflow: hidden !important;
        border: 1.5px solid #111 !important;
    }

    body.pdf-export-mode .print-frame-overlay {
        display: block !important;
        position: fixed !important;
        inset: 8mm !important;
        z-index: 2990 !important;
        border: 1.5px solid #111 !important;
        box-shadow: none !important;
    }

    body.pdf-export-mode .print-frame-safe-area {
        inset: 6mm !important;
        border: 0.5px solid #111 !important;
    }

    body.pdf-export-mode .print-frame-stamp-space {
        right: 6mm !important;
        bottom: 6mm !important;
        width: 155mm !important;
        height: 43mm !important;
        border: 0.5px solid #111 !important;
        background: transparent !important;
        color: transparent !important;
    }
}

@media (max-width: 900px) {
    .blocks-sidebar {
        top: 104px;
        width: min(420px, 94vw);
    }

    .multi-cable-panel {
        align-items: stretch;
        flex-direction: column;
        bottom: 78px;
    }
}

.mobile-block-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 76px;
    z-index: 1300;
    max-height: min(420px, calc(100vh - 190px));
    overflow-y: auto;
    padding: 12px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.2);
}

.mobile-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    color: var(--primary);
}

.mobile-block-header button {
    min-height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--primary);
    font-weight: 700;
}

.mobile-block-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 900px) {
    .editor-body .editor-topbar {
        min-height: 104px;
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
    }

    .editor-body .editor-actions {
        width: 100%;
        gap: 8px;
    }

    .editor-body .editor-actions .btn {
        min-height: 38px;
        padding: 0 12px;
    }

    .editor-layout {
        height: 100vh;
        padding-top: 104px;
        padding-bottom: 72px;
        grid-template-columns: 88px minmax(0, 1fr);
    }

    .editor-layout .tool-panel {
        padding: 10px;
    }

    .tool-section {
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    .tool-section h2 {
        font-size: 12px;
    }

    .editor-layout .tool-btn {
        min-height: 38px;
        font-size: 13px;
    }

    .bottom-toolbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1200;
        display: flex;
        gap: 8px;
        padding: 10px;
        overflow-x: auto;
        white-space: nowrap;
        background: rgba(255, 255, 255, 0.96);
        border-top: 1px solid var(--border);
        box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.12);
    }
}

@media (max-width: 620px) {
    .editor-body .editor-topbar {
        min-height: 132px;
    }

    .editor-layout {
        padding-top: 132px;
        grid-template-columns: 1fr;
    }

    .editor-layout .tool-panel {
        display: none;
    }

    .bottom-tool-btn {
        min-width: 78px;
    }

    .modal-grid {
        grid-template-columns: 1fr;
    }
}

/* Correcoes finais: layout do editor, captura de ruas e zoom do mapa */
.editor-body {
    height: 100vh;
    overflow: hidden;
}

.editor-body .editor-topbar {
    height: 64px;
    min-height: 64px;
}

.editor-layout {
    height: calc(100vh - 64px);
    padding-top: 0;
    margin-top: 64px;
    grid-template-columns: 260px minmax(0, 1fr);
}

.editor-layout .tool-panel {
    width: 260px;
    padding: 14px;
    overflow-y: auto;
    overflow-x: hidden;
}

.tool-icons-section h2,
.tool-section h2 {
    text-align: left;
    white-space: normal;
}

.tool-icons-section .tool-btn {
    width: 100%;
    height: auto;
    min-height: 42px;
    margin: 0 0 8px;
    padding: 0 12px;
    font-size: 13px;
    justify-content: flex-start;
    gap: 10px;
}

.tool-icons-section .tool-btn::before {
    width: 24px;
    text-align: center;
    font-size: 18px;
}

.scale-status,
.hint-box,
.selection-card {
    word-break: normal;
    overflow-wrap: anywhere;
}

.canvas-area {
    background: #e5e7eb;
}

.canvas-area #map {
    background: #e5e7eb;
    z-index: 1;
}

.canvas-area #drawCanvas {
    z-index: 2;
}

.leaflet-container {
    background: #e5e7eb !important;
}

.map-floating-tools {
    position: absolute;
    top: 14px;
    left: 64px;
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 90px);
    padding: 8px;
    border: 1px solid rgba(15, 59, 115, 0.14);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
    backdrop-filter: blur(8px);
}

.map-float-btn {
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 12px;
    background: #ffffff;
    color: var(--primary);
    font-weight: 800;
    cursor: pointer;
}

.map-float-btn.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.map-float-btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.map-float-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.map-float-check input {
    width: auto;
}

.map-float-hint {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.blocks-sidebar {
    transform: translateX(105%);
    transition: transform .2s ease;
}

.blocks-sidebar.open {
    transform: translateX(0);
}

@media (max-width: 900px) {
    .editor-body .editor-topbar {
        height: 104px;
        min-height: 104px;
    }

    .editor-layout {
        height: calc(100vh - 104px - 72px);
        margin-top: 104px;
        padding-top: 0;
        padding-bottom: 0;
        grid-template-columns: 220px minmax(0, 1fr);
    }

    .editor-layout .tool-panel {
        width: 220px;
    }

    .map-floating-tools {
        left: 58px;
        right: 10px;
        max-width: none;
        flex-wrap: wrap;
    }

    .map-float-hint {
        display: none;
    }
}

@media (max-width: 620px) {
    .editor-body .editor-topbar {
        height: 132px;
        min-height: 132px;
    }

    .editor-layout {
        height: calc(100vh - 132px - 72px);
        margin-top: 132px;
        padding-top: 0;
        grid-template-columns: 1fr;
    }

    .editor-layout .tool-panel {
        display: none;
    }

    .map-floating-tools {
        top: 10px;
        left: 58px;
        right: 10px;
    }
}

/* Hotfix 2026-05-21: layout editor + ruas por borda + zoom alto */
.editor-body {
    height: 100vh !important;
    overflow: hidden !important;
}
.editor-body .editor-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 64px !important;
    min-height: 64px !important;
    z-index: 1200 !important;
}
.editor-layout {
    display: grid !important;
    grid-template-columns: 280px minmax(0, 1fr) !important;
    height: calc(100vh - 64px) !important;
    margin-top: 64px !important;
    padding-top: 0 !important;
    overflow: hidden !important;
}
.editor-layout .tool-panel {
    width: 280px !important;
    min-width: 280px !important;
    max-width: 280px !important;
    padding: 14px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}
.tool-icons-section .tool-btn {
    width: 100% !important;
    height: auto !important;
    min-height: 42px !important;
    font-size: 13px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 0 12px !important;
    margin: 0 0 8px !important;
}
.tool-icons-section .tool-btn::before {
    width: 24px !important;
    margin-right: 8px !important;
    font-size: 18px !important;
}
.canvas-area,
.canvas-area #map,
.canvas-area #drawCanvas,
.leaflet-container {
    min-width: 0 !important;
    min-height: 0 !important;
}
.canvas-area {
    position: relative !important;
    overflow: hidden !important;
    background: #e5e7eb !important;
}
.canvas-area #map,
.canvas-area #drawCanvas {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
}
.map-floating-tools {
    z-index: 1100 !important;
}
@media (max-width: 900px) {
    .editor-body .editor-topbar {
        height: 104px !important;
        min-height: 104px !important;
    }
    .editor-layout {
        grid-template-columns: 240px minmax(0, 1fr) !important;
        height: calc(100vh - 104px - 72px) !important;
        margin-top: 104px !important;
    }
    .editor-layout .tool-panel {
        width: 240px !important;
        min-width: 240px !important;
        max-width: 240px !important;
    }
}
@media (max-width: 620px) {
    .editor-body .editor-topbar {
        height: 132px !important;
        min-height: 132px !important;
    }
    .editor-layout {
        grid-template-columns: 1fr !important;
        height: calc(100vh - 132px - 72px) !important;
        margin-top: 132px !important;
    }
    .editor-layout .tool-panel {
        display: none !important;
    }
}

/* Editor avancado de blocos personalizados */
.block-creator-modal .modal-card-wide {
    width: min(980px, 96vw);
    max-height: 92vh;
    overflow-y: auto;
}

.block-drawing-editor {
    margin-top: 16px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #f8fafc;
}

.block-drawing-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.block-drawing-header strong {
    display: block;
    color: var(--primary);
    font-size: 15px;
}

.block-drawing-header small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
    max-width: 420px;
}

.block-drawing-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.block-drawing-tools button,
.block-drawing-options button {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 7px 10px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
}

.block-drawing-tools button.active,
.block-drawing-tools button:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.block-drawing-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.block-drawing-options label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.block-drawing-options input[type="text"] {
    width: 90px;
    min-height: 34px;
}

.block-element-actions,
.block-rotate-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.block-element-actions button,
.block-rotate-actions button {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 7px 10px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
}

#blockDrawCanvas {
    width: 100%;
    height: min(320px, 48vh);
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #fff;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

.block-drawing-hint {
    margin: 8px 0 0 !important;
    color: var(--muted) !important;
    font-size: 12px;
}

@media (max-width: 780px) {
    .block-drawing-header {
        display: block;
    }
    .block-drawing-tools {
        justify-content: flex-start;
        margin-top: 10px;
    }
    .modal-grid {
        grid-template-columns: 1fr;
    }
}
