:root {
  --construction-border: #cbd9ea;
  --construction-surface: #ffffff;
  --construction-muted: #5f7089;
  --construction-blue: #2155d9;
  --construction-green: #087d4b;
  --construction-red: #b42318;
  --construction-amber: #a15c00;
}

.construction-page { min-height: 100dvh; background: #eef4fb; color: #142139; }
.construction-page .v15-topbar { grid-template-columns: minmax(190px, 240px) minmax(180px, 1fr) auto !important; column-gap: 14px !important; }
.construction-page .v15-brand-center { min-width: 0; }
.construction-page .v15-title { font-size: clamp(18px, 1.55vw, 24px) !important; white-space: nowrap !important; }
.construction-page .main-nav { min-width: 0; gap: 6px !important; }
.construction-page .main-nav a,
.construction-page .nav-action-btn,
.construction-page .user-menu-toggle { padding: 11px 15px !important; font-size: 14px !important; }
.construction-content { width: min(1500px, calc(100% - 32px)); margin: 22px auto; display: grid; gap: 18px; }
.tool-panel { background: var(--construction-surface); border: 1px solid var(--construction-border); border-radius: 8px; padding: 20px; box-shadow: none; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-heading h2 { margin: 4px 0 0; font-size: 1.25rem; letter-spacing: 0; }
.eyebrow, .updated-chip { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 10px; border: 1px solid #a9c7fb; border-radius: 6px; color: #1644a8; background: #edf5ff; font-size: .74rem; font-weight: 800; }
.safety-note, .warning-box { border: 1px solid #f2c66d; background: #fff9e9; color: #704400; border-radius: 6px; padding: 12px 14px; margin-bottom: 14px; }
.source-modes { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--construction-border); border-radius: 6px; padding: 4px; background: #f1f5fa; }
.source-mode { min-height: 42px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: #263852; font-weight: 800; box-shadow: none; }
.source-mode.active { border-color: #75a6fb; background: #eaf2ff; color: #1649bd; }
.works-write-mode { margin: 14px 0 0; padding: 12px; border: 1px solid var(--construction-border); border-radius: 6px; }
body.embedded-works { min-height: 0; background: transparent; }
body.embedded-works > .topbar,
body.embedded-works > .site-footer,
body.embedded-works > #login-modal,
body.embedded-works .preview-panel { display: none !important; }
body.embedded-works .construction-content { width: 100%; max-width: none; margin: 0; padding: 0; }
body.embedded-works .results-section { margin: 0; }
.works-write-mode legend { padding: 0 6px; color: #17233a; font-weight: 800; }
.works-mode-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.works-mode-option { display: flex; align-items: center; gap: 10px; min-height: 68px; padding: 10px 12px; border: 1px solid #c8d6e9; border-radius: 6px; background: #fff; cursor: pointer; }
.works-mode-option input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: #1f55dd; }
.works-mode-option span { display: grid; gap: 3px; }
.works-mode-option.is-selected { border-color: #3f7cf0; background: #edf4ff; }
.works-mode-option.works-mode-replace.is-selected { border-color: #dc6b5e; background: #fff2f0; }
.source-panel { margin-top: 14px; border: 1px solid var(--construction-border); border-radius: 6px; padding: 12px; background: #f7faff; }
.source-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.source-item { display: grid; grid-template-columns: 22px 1fr; align-items: center; min-height: 64px; border: 1px solid var(--construction-border); border-radius: 6px; padding: 9px 12px; background: #fff; cursor: pointer; }
.source-item:has(input:checked) { border-color: #2c65e6; background: #eef5ff; }
.source-item input { width: 17px; height: 17px; }
.source-item strong, .source-item small { display: block; }
.source-item small { margin-top: 3px; color: var(--construction-muted); }
.file-drop { display: grid; min-height: 92px; place-items: center; border: 1px dashed #6f97d4; border-radius: 6px; color: #174c9b; cursor: pointer; }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.operation-selector { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin: 14px 0 0; padding: 12px; border: 1px solid var(--construction-border); border-radius: 6px; background: #f7faff; }
.operation-selector legend { padding: 0 6px; color: #203a5d; font-size: .88rem; font-weight: 800; }
.operation-option { display: grid; grid-template-columns: 22px 1fr; align-items: center; min-height: 76px; gap: 8px; padding: 10px 12px; border: 1px solid var(--construction-border); border-radius: 6px; background: #fff; cursor: pointer; }
.operation-option:has(input:checked) { border-color: #4d82ee; background: #edf4ff; }
.operation-option input { width: 18px; height: 18px; }
.operation-option strong, .operation-option small { display: block; }
.operation-option small { margin-top: 4px; color: var(--construction-muted); line-height: 1.3; }
.operation-terrain:has(input:checked) { border-color: #69bf94; background: #effaf4; }
.operation-title:has(input:checked) { border-color: #b38be3; background: #f8f2ff; }
.operation-order:has(input:checked) { border-color: #e0ae4d; background: #fff9eb; }
.rentas-reference { transition: opacity .15s ease; }
.rentas-reference.operation-muted { opacity: .62; }
.rentas-reference { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--construction-border); }
.reference-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reference-heading h3 { margin: 0 0 4px; font-size: 1rem; }
.reference-badge { padding: 4px 9px; border: 1px solid #75cba2; border-radius: 5px; background: #eaf9f1; color: #087343; font-size: .72rem; font-weight: 800; }
.reference-actions { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; gap: 8px; margin-top: 10px; }
.reference-file { display: flex; align-items: center; min-height: 40px; padding: 8px 12px; overflow: hidden; border: 1px dashed #6f97d4; border-radius: 6px; color: #174c9b; cursor: pointer; }
.reference-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reference-file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.danger-outline-action { min-height: 40px; padding: 8px 15px; border: 1px solid var(--construction-red); border-radius: 6px; background: #fff; color: var(--construction-red); box-shadow: none; font-weight: 800; }
.query-actions, .table-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.query-actions button, .table-actions button, .confirmation-modal button, .audit-panel button { min-height: 40px; padding: 8px 15px; border-radius: 6px; box-shadow: none; font-weight: 800; }
.primary-action { border: 1px solid var(--construction-blue); background: var(--construction-blue); color: #fff; }
.secondary-action { border: 1px solid #9eb1c9; background: #fff; color: #28415f; }
.danger-action { border: 1px solid var(--construction-red); background: var(--construction-red); color: #fff; }
.apply-action { border: 1px solid var(--construction-green); background: var(--construction-green); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
.status-message { margin-top: 14px; border: 1px solid #b9cbe2; border-radius: 6px; padding: 12px 14px; color: #37506e; background: #f5f8fc; }
.status-message.success { border-color: #8bd3ae; background: #edfbf4; color: #086b41; }
.status-message.error { border-color: #f1a8a2; background: #fff0ef; color: #9f2017; }
.status-message.warning { border-color: #c18a24; background: #fff4d9; color: #644409; box-shadow: none; }
.progress-wrap[data-state="waiting_token"] .progress-fill { background: #e2b456; }
body.dark-theme .status-message.warning { border-color: #957331; background: #302816; color: #ffe1a0; }
.progress-wrap { margin-top: 14px; }
.progress-track { position: relative; height: 24px; overflow: hidden; border-radius: 6px; background: #dce6f2; }
.progress-fill { width: 0; height: 100%; background: #179a59; transition: width .25s ease; }
.progress-track strong { position: absolute; inset: 0; display: grid; place-items: center; color: #11243b; }
.progress-wrap p { margin: 7px 0 0; color: var(--construction-muted); }
.results-section { display: grid; gap: 18px; }
.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.summary-grid article { min-height: 88px; display: grid; place-items: center; align-content: center; border: 1px solid var(--construction-border); border-radius: 6px; background: #fff; }
.summary-grid span { color: var(--construction-muted); font-size: .82rem; text-align: center; }
.summary-grid strong { margin-top: 5px; font-size: 1.65rem; }
.summary-ready { background: #edf9f3 !important; border-color: #8bd3ae !important; }
.summary-ok { background: #edf5ff !important; border-color: #a9c7fb !important; }
.summary-warn { background: #fff9e9 !important; border-color: #f2c66d !important; }
.summary-empty { background: #fff0ef !important; border-color: #f1a8a2 !important; }
.summary-applied { background: #e8faf0 !important; border-color: #64c693 !important; }
.summary-error { background: #fff0ef !important; border-color: #f1a8a2 !important; }
.table-heading { align-items: flex-end; }
.table-heading > div:first-child { display: grid; gap: 5px; }
.row-count { color: var(--construction-muted); }
.filters-grid { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.filters-grid label, .confirmation-modal label { display: grid; gap: 6px; font-weight: 700; }
.filters-grid input, .filters-grid select, .confirmation-modal input { width: 100%; min-height: 42px; border: 1px solid var(--construction-border); border-radius: 6px; padding: 8px 10px; background: #fff; color: #142139; }
.table-scroll { overflow: auto; border: 1px solid var(--construction-border); border-radius: 6px; }
.construction-table { width: 100%; min-width: 1580px; border-collapse: collapse; table-layout: fixed; }
.construction-table th, .construction-table td { border-right: 1px solid #d7e2ef; border-bottom: 1px solid #d7e2ef; padding: 9px 8px; vertical-align: top; font-size: .82rem; }
.construction-table th { position: sticky; top: 0; z-index: 1; background: #edf3fa; color: #203a5d; text-align: left; }
.construction-table th:nth-child(1) { width: 68px; text-align: center; }
.construction-table th:nth-child(n+2):nth-child(-n+6) { width: 64px; text-align: center; }
.construction-table th:nth-child(7) { width: 270px; }
.construction-table th:nth-child(8) { width: 290px; }
.construction-table th:nth-child(9) { width: 170px; }
.construction-table th:nth-child(10) { width: 285px; }
.construction-table th:nth-child(11) { width: 280px; }
.construction-table td:nth-child(n+1):nth-child(-n+6) { text-align: center; vertical-align: middle; }
.construction-table input[type="checkbox"] { width: 18px; height: 18px; }
.manual-cell { display: inline-flex; min-height: 24px; align-items: center; padding: 3px 7px; border: 1px solid #e5b849; border-radius: 5px; background: #fff5d6; color: #795000; font-size: .7rem; font-weight: 800; }
.construction-lines { display: grid; gap: 4px; }
.construction-lines span { display: block; min-width: 0; line-height: 1.35; overflow-wrap: anywhere; white-space: normal; }
.construction-lines span + span { padding-top: 4px; border-top: 1px solid #e2eaf4; }
.area-change { display: grid; gap: 3px; }
.area-change small { color: var(--construction-muted); font-weight: 700; }
.area-change strong { display: block; }
.area-arrow { color: var(--construction-muted); }
.title-lines { display: grid; gap: 7px; }
.title-lines > span { display: grid; gap: 3px; line-height: 1.3; }
.title-lines > span + span { padding-top: 7px; border-top: 1px solid #e2eaf4; }
.title-lines small { color: var(--construction-muted); }
.title-lines .title-review { color: #8a4e00; }
.title-lines .title-review small { color: #8a4e00; }
.state-badge { display: inline-flex; padding: 3px 7px; border-radius: 5px; font-size: .72rem; font-weight: 800; }
.state-ready { background: #dcf7e9; color: #07663d; }
.state-review { background: #fff0c7; color: #825000; }
.state-excluded { background: #ffe1de; color: #97231b; }
.state-unchanged { background: #e5efff; color: #17489e; }
.state-applied { background: #cdefdd; color: #075e37; }
.state-error { background: #ffe1de; color: #97231b; }
.apply-observations { border-color: #e7958e; }
.apply-observations .section-heading { margin-bottom: 12px; }
.apply-observations .section-heading > div { display: grid; gap: 5px; }
.observation-table-scroll { overflow: auto; border: 1px solid #edb2ad; border-radius: 6px; }
.application-observation-table { width: 100%; min-width: 760px; border-collapse: collapse; table-layout: fixed; }
.application-observation-table th,
.application-observation-table td { padding: 10px 12px; border-right: 1px solid #efd5d2; border-bottom: 1px solid #efd5d2; text-align: left; vertical-align: top; font-size: .84rem; }
.application-observation-table th { background: #fff0ef; color: #7e211a; }
.application-observation-table th:nth-child(-n+3) { width: 84px; text-align: center; }
.application-observation-table td:nth-child(-n+3) { text-align: center; }
.application-observation-table th:nth-child(4) { width: 260px; }
.application-observation-table th:last-child,
.application-observation-table td:last-child { border-right: 0; }
.application-observation-table tbody tr:last-child td { border-bottom: 0; }
.observation-detail { color: #8d251d; font-weight: 700; overflow-wrap: anywhere; }
.detail-text { margin-top: 6px; color: #4c5e75; line-height: 1.35; }
.change-list { display: grid; gap: 6px; margin: 7px 0 0; padding: 0; list-style: none; color: #334b69; line-height: 1.35; }
.change-list li { padding-left: 8px; border-left: 3px solid #e69a13; }
.audit-list { display: grid; gap: 8px; }
.audit-item { display: grid; grid-template-columns: 145px 120px 1fr; gap: 12px; border: 1px solid var(--construction-border); border-radius: 6px; padding: 10px 12px; }
.audit-ok { border-left: 4px solid #16965a; }
.audit-error { border-left: 4px solid #c72d22; }
.confirmation-modal { width: min(560px, calc(100vw - 24px)); background: #fff; color: #142139; border: 1px solid var(--construction-border); border-radius: 8px; padding: 22px; position: relative; }
.confirmation-modal h2 { margin: 0 36px 10px 0; }
.confirmation-modal .apply-action { width: 100%; margin-top: 16px; }
.muted { color: var(--construction-muted); }
.pagination-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; font-size: .78rem; }
.pagination-bar label, .pagination-bar div { display: flex; align-items: center; gap: 9px; }
.pagination-bar select { width: 78px; min-height: 36px; border: 1px solid var(--construction-border); border-radius: 5px; padding: 6px 9px; background: #fff; color: #142139; }
.pagination-bar button { min-height: 36px; border: 1px solid var(--construction-border); border-radius: 5px; padding: 7px 12px; background: #fff; color: #28415f; box-shadow: none; font-weight: 700; }

body.dark-theme.construction-page { --construction-border: #33455f; --construction-surface: #111c2e; --construction-muted: #aebbd0; background: #091323; color: #edf4ff; }
body.dark-theme .tool-panel, body.dark-theme .summary-grid article, body.dark-theme .source-item, body.dark-theme .confirmation-modal { background: #111c2e; color: #edf4ff; }
body.dark-theme .source-panel, body.dark-theme .source-modes { background: #0c1727; }
body.dark-theme .operation-selector { background: #0c1727; }
body.dark-theme .operation-selector legend { color: #edf4ff; }
body.dark-theme .operation-option { background: #111c2e; }
body.dark-theme .operation-option:has(input:checked) { background: #17345f; }
body.dark-theme .operation-terrain:has(input:checked) { background: #123426; }
body.dark-theme .operation-title:has(input:checked) { background: #302144; }
body.dark-theme .operation-order:has(input:checked) { background: #3b2c10; }
body.dark-theme .source-mode { color: #dce8f8; }
body.dark-theme .source-mode.active { background: #17345f; color: #fff; }
body.dark-theme .works-write-mode { border-color: #31445f; }
body.dark-theme .works-write-mode legend { color: #e8f0fb; }
body.dark-theme .works-mode-option { border-color: #344862; background: #0c1727; }
body.dark-theme .works-mode-option small { color: #9db0c8; }
body.dark-theme .works-mode-option.is-selected { border-color: #5a91ef; background: #122b4c; }
body.dark-theme .works-mode-option.works-mode-replace.is-selected { border-color: #d9766b; background: #3a2024; }

@media (max-width: 720px) {
  .works-mode-options { grid-template-columns: 1fr; }
}
body.dark-theme .source-item:has(input:checked) { background: #17345f; }
body.dark-theme .reference-file, body.dark-theme .danger-outline-action { background: #0c1727; }
body.dark-theme .reference-badge { background: #123426; color: #8be0b6; }
body.dark-theme .filters-grid input, body.dark-theme .filters-grid select, body.dark-theme .confirmation-modal input, body.dark-theme .secondary-action { background: #0c1727; color: #edf4ff; }
body.dark-theme .construction-table th { background: #17253a; color: #edf4ff; }
body.dark-theme .construction-table td, body.dark-theme .construction-table th { border-color: #33455f; }
body.dark-theme .construction-lines span + span { border-color: #33455f; }
body.dark-theme .title-lines > span + span { border-color: #33455f; }
body.dark-theme .title-lines .title-review, body.dark-theme .title-lines .title-review small { color: #ffd27a; }
body.dark-theme .manual-cell { border-color: #9d7728; background: #3b2c10; color: #ffd27a; }
body.dark-theme .change-list { color: #d7e4f5; }
body.dark-theme .change-list li { border-left-color: #f3b43f; }
body.dark-theme .pagination-bar select, body.dark-theme .pagination-bar button { background: #0c1727; color: #edf4ff; }
body.dark-theme .summary-ready, body.dark-theme .summary-applied { background: #123426 !important; }
body.dark-theme .summary-ok { background: #142c50 !important; }
body.dark-theme .summary-warn { background: #3b2c10 !important; }
body.dark-theme .summary-empty { background: #3a1d20 !important; }
body.dark-theme .summary-error { background: #3a1d20 !important; }
body.dark-theme .safety-note, body.dark-theme .warning-box { background: #352a13; color: #ffe7a7; }
body.dark-theme .apply-observations { border-color: #7d3c3d; }
body.dark-theme .observation-table-scroll { border-color: #663638; }
body.dark-theme .application-observation-table th { background: #3a1d20; color: #ffc1bb; }
body.dark-theme .application-observation-table td,
body.dark-theme .application-observation-table th { border-color: #563238; }
body.dark-theme .observation-detail { color: #ffb8b0; }

@media (min-width: 861px) and (max-width: 1280px) {
  .construction-page .v15-topbar {
    grid-template-columns: minmax(170px, 220px) minmax(0, 1fr) !important;
    grid-template-areas: "logo title" "nav nav";
    row-gap: 8px !important;
    min-height: 118px !important;
    padding: 10px 18px !important;
  }
  .construction-page .header-logo-wrap { grid-area: logo; justify-self: start !important; }
  .construction-page .v15-brand-center { grid-area: title; justify-self: center !important; }
  .construction-page .main-nav { grid-area: nav; width: 100%; justify-content: center !important; flex-wrap: nowrap !important; }
  .construction-page .header-logo-banner { height: 54px !important; }
  .construction-page .v15-title { font-size: 20px !important; }
}

@media (max-width: 900px) {
  .construction-content { width: min(100% - 16px, 1500px); margin: 12px auto; }
  .tool-panel { padding: 14px; }
  .source-list, .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .operation-selector { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-heading, .table-heading { align-items: stretch; flex-direction: column; }
  .table-actions { margin-top: 0; }
  .table-actions button { flex: 1; }
  .audit-item { grid-template-columns: 1fr; gap: 4px; }
  .reference-actions { grid-template-columns: 1fr 1fr; }
  .reference-file { grid-column: 1 / -1; }
  .pagination-bar { align-items: stretch; flex-direction: column; }
  .pagination-bar div { justify-content: space-between; }
}

@media (max-width: 860px) {
  .construction-page .v15-topbar {
    grid-template-columns: 1fr !important;
    grid-template-areas: "logo" "title" "nav";
  }
  .construction-page .header-logo-wrap { grid-area: logo; }
  .construction-page .v15-brand-center { grid-area: title; }
  .construction-page .main-nav { grid-area: nav; flex-wrap: wrap !important; justify-content: center !important; }
  .construction-page .v15-title { white-space: normal !important; text-align: center; }
}

@media (max-width: 520px) {
  .source-list { grid-template-columns: 1fr; }
  .operation-selector { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters-grid { grid-template-columns: 1fr 1fr; }
  .query-actions button { flex: 1 1 100%; }
  .reference-heading { align-items: flex-start; }
}

.compact-note { margin: 14px 0 0; }
.works-summary { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.works-table { min-width: 1460px; }
.works-table th:nth-child(1) { width: 70px; text-align: center; }
.works-table th:nth-child(2),
.works-table th:nth-child(3),
.works-table th:nth-child(4),
.works-table th:nth-child(6) { width: 68px; text-align: center; }
.works-table th:nth-child(5) { width: 210px; }
.works-table th:nth-child(7) { width: 300px; }
.works-table th:nth-child(8) { width: 370px; }
.works-table th:nth-child(9) { width: 280px; }
.works-table td:nth-child(1),
.works-table td:nth-child(2),
.works-table td:nth-child(3),
.works-table td:nth-child(4),
.works-table td:nth-child(6) { text-align: center; vertical-align: middle; }
.works-lines small, .unit-code { display: block; margin-top: 3px; color: var(--construction-muted); line-height: 1.3; }
.works-lines .calculated-label { color: #8a4e00; font-weight: 800; }
.file-drop.is-dragging { border-color: #1f57d6; background: #eaf2ff; }
body.dark-theme .works-lines .calculated-label { color: #ffd27a; }

@media (max-width: 900px) {
  .works-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
