* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
       color: #1c2230; background: #eef1f6; }
.muted { color: #6b7488; } .small { font-size: 12px; } .hidden { display: none !important; }

/* top bar */
#topbar { display: flex; align-items: center; gap: 24px; height: 48px; padding: 0 18px; background: #14233b; color: #fff; }
#topbar .brand { font-weight: 700; font-size: 15px; }
#topbar .brand .muted { color: #9fb0cc; font-weight: 500; }
#nav { display: flex; gap: 4px; flex: 1; }
#nav a { color: #cfd8ea; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 13px; }
#nav a:hover { background: #22375a; } #nav a.active { background: #2563eb; color: #fff; }
#topbar .me { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #cfd8ea; }
#topbar .me button { background: transparent; color: #cfd8ea; border-color: #3a4a66; }
footer { padding: 6px 18px 10px; text-align: center; }
body[data-page="editor"] footer { display: none; }

/* the editor fills the window under the top bar */
main { display: grid; grid-template-columns: 372px 1fr; gap: 14px; padding: 14px; height: calc(100vh - 48px); }
#left { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.card { background: #fff; border: 1px solid #dde2ec; border-radius: 8px; padding: 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: #586; }

.filebtn { display: block; text-align: center; padding: 10px; border: 1.5px dashed #9aa7c0;
           border-radius: 6px; cursor: pointer; color: #36507e; background: #f7f9fc; }
.filebtn input { display: none; }
label { display: block; margin: 8px 0; }
select, input[type=number] { width: 100%; padding: 7px; border: 1px solid #cfd6e4; border-radius: 6px; margin-top: 3px; }
input[type=number] { width: 90px; }

button { cursor: pointer; border: 1px solid #cfd6e4; background: #fff; border-radius: 6px; padding: 7px 11px; font-size: 13px; }
button.primary { background: #2563eb; color: #fff; border-color: #2563eb; width: 100%; margin-top: 6px; font-weight: 600; }
button.primary:disabled { background: #aab4c6; border-color: #aab4c6; cursor: not-allowed; }
button.ghost { padding: 4px 9px; font-size: 12px; }
.seg { display: flex; gap: 0; margin-bottom: 10px; }
.seg .mode { flex: 1; border-radius: 0; }
.seg .mode:first-child { border-radius: 6px 0 0 6px; }
.seg .mode:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.seg .mode.active { background: #14233b; color: #fff; border-color: #14233b; }

#right { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
#canvasWrap { position: relative; flex: 1; background: #0f1726; border-radius: 8px; overflow: hidden; }
#cad { width: 100%; height: 100%; display: block; cursor: crosshair; }
#hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #5e6b85; }
#busy { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; gap: 12px;
        align-items: center; justify-content: center; background: rgba(15,23,38,.6); color: #dfe6f2; font-size: 14px; }
.spinner { width: 38px; height: 38px; border: 3px solid #2a3850; border-top-color: #34d058;
           border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

table { width: 100%; border-collapse: collapse; font-size: 11px; table-layout: fixed; }
td, th { padding: 2px 3px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td:nth-child(2), th:nth-child(2) { text-align: left; white-space: normal; }   /* item · why wraps */
td:first-child, th:first-child { text-align: left; }
tr.total td { border-top: 1.5px solid #cfd6e4; font-weight: 700; }
.big { font-size: 22px; font-weight: 700; color: #14233b; }
.kv { display: flex; justify-content: space-between; padding: 2px 0; }
.warn { color: #b4690e; }

/* assumptions panel */
.prov { font-size: 10px; background: #fbe7c6; color: #8a5a08; padding: 1px 6px; border-radius: 4px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.agrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.agrid label { margin: 0; font-size: 11px; color: #586; display: flex; flex-direction: column; }
.agrid input { width: 100%; padding: 5px; margin-top: 2px; }
.subh { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #586; margin: 10px 0 5px; }
.why { color: #8893a8; font-size: 11px; }
.rrow { display: flex; justify-content: space-between; align-items: center; font-size: 12px; padding: 3px 4px; border-bottom: 1px solid #eef1f6; border-radius: 4px; cursor: default; }
.rrow:hover { background: #eafaef; }
.rbadge { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-right: 6px;
          border-radius: 50%; background: #0b1020; color: #34d058; border: 1.5px solid #34d058; font-size: 10px; font-weight: 800; }
.brow { cursor: default; } .brow:hover { background: #eafaef; }
.rx { padding: 1px 7px; font-size: 12px; color: #b4231a; border-color: #f0c4c0; line-height: 1.2; }
.rx:hover { background: #fde2e1; }

/* anchor legend on canvas */
#legend { position: absolute; right: 10px; top: 10px; background: rgba(15,23,38,.85);
          border: 1px solid #2a3850; border-radius: 6px; padding: 8px 10px; color: #cfd8ea; font-size: 12px; }
#legend > div { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.end { background: #ff3b30; } .dot.corner { background: #ff9500; } .dot.inter { background: #ffd60a; }
.line.route { width: 14px; height: 0; border-top: 2px solid #ff8a00; display: inline-block; }
.line.routeg { width: 14px; height: 0; border-top: 2px solid #34d058; display: inline-block; }
.line.roofo { width: 14px; height: 0; border-top: 2px dashed #7aa2ff; display: inline-block; }
/* anchor chips in quote */
.achip { display:inline-block; padding:1px 7px; border-radius:10px; font-size:11px; font-weight:600; margin-right:5px; color:#fff; }
.achip.end{background:#ff3b30;} .achip.corner{background:#ff9500;} .achip.inter{background:#caa600;}
.banner{background:#fde2e1;border:1px solid #f4b8b4;border-left:4px solid #e0352b;color:#8a1c14;
        padding:8px 10px;border-radius:6px;font-size:12.5px;margin-bottom:8px;font-weight:500;}
.banner.provisional{background:#fbe7c6;border-color:#eccb90;border-left-color:#d9930d;color:#8a5a08;}
.reasoning{margin-top:10px;font-size:12px;}
.reasoning summary{cursor:pointer;color:#36507e;font-weight:600;}
.reasoning ol{margin:6px 0 0;padding-left:18px;color:#3a4458;}
.reasoning li{margin:3px 0;}

.bl { font-size: 12px; font-weight: 600; color: #2e7d32; }

/* undo / redo on the canvas */
#histBar { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; z-index: 5; }
#histBar button { background: rgba(15,23,38,.88); color: #e6edf7; border-color: #3a4a66; font-weight: 600; }
#histBar button:disabled { opacity: .4; cursor: default; }
/* legend: hollow route-point square and insert dot */
.sq { width: 9px; height: 9px; border: 2px solid #fff; display: inline-block; box-sizing: border-box; }
.dot.ins { background: #7aa2ff; opacity: .75; width: 7px; height: 7px; margin: 0 1.5px; }

/* scale calibration (PDF drawings often print no scale) */
#calibBox { margin-top: 8px; padding: 8px 10px; border: 1px solid #cfd6e4; border-radius: 6px; background: #f7f9fc; }
#calibBox .row { display: flex; gap: 6px; margin-top: 6px; }
#calibBox label { display: block; margin-top: 6px; }
#calibBox input { width: 100%; }
#calibBtn.active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* one collapsible block per lifeline (Carina: adjust one line without redoing the rest) */
.lineblock { border: 1px solid #e3e8f0; border-radius: 6px; padding: 6px 9px; margin-bottom: 6px; background: #fbfcfe; }
.lineblock > summary { cursor: pointer; font-size: 13px; }
.lineblock table { margin-top: 6px; }
.lineblock.hl { border-color: #2563eb; }
#splitBtn.active { background: #ff9500; color: #fff; border-color: #ff9500; }

/* ---------------- pages other than the editor ---------------- */
.page { max-width: 1180px; margin: 0 auto; padding: 18px; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.pagehead h2 { margin: 0; font-size: 20px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { width: 320px; max-width: 100%; }
.toolbar select { width: auto; margin: 0; }
.toolbar button.primary { width: auto; margin: 0; }
input[type=text], input[type=email], input[type=password], input[type=search], input:not([type]), textarea {
  width: 100%; padding: 7px 8px; border: 1px solid #cfd6e4; border-radius: 6px; margin-top: 3px; font: inherit; background: #fff; }
input[type=file] { margin-top: 4px; }
.tablecard { background: #fff; border: 1px solid #dde2ec; border-radius: 8px; padding: 6px 10px; overflow-x: auto; }
table.list { font-size: 13px; table-layout: auto; }
table.list th { text-align: left; color: #586; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 6px; border-bottom: 1px solid #e3e8f0; }
table.list td { text-align: left; white-space: normal; padding: 8px 6px; border-bottom: 1px solid #eef1f6; vertical-align: top; overflow: visible; }
table.list .num { text-align: right; white-space: nowrap; }
table.list tr.clickable { cursor: pointer; } table.list tr.clickable:hover td { background: #f3f7ff; }
table.list td.acts { white-space: nowrap; text-align: right; } table.list td.acts button { margin-left: 4px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: #e8ecf3; color: #3a4458; }
.pill.enviado { background: #dbe7ff; color: #1f4fbf; } .pill.ganho { background: #d8f5e1; color: #1d7a3d; }
.pill.perdido { background: #f4dede; color: #9a2a22; }
.empty { padding: 26px 10px; text-align: center; } .empty p { max-width: 560px; margin: 6px auto; }

/* login and invitation */
.authpage { display: flex; justify-content: center; padding-top: 9vh; }
.authcard { width: 400px; max-width: 100%; background: #fff; border: 1px solid #dde2ec; border-radius: 10px; padding: 22px 24px; }
.authcard h2 { margin: 0 0 4px; font-size: 19px; }
.authcard button.primary { margin-top: 12px; }
.formerr { color: #b4231a; font-size: 13px; min-height: 18px; margin-top: 6px; }
.notice { border-top: 1px solid #eef1f6; padding-top: 10px; margin-top: 14px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: #3a4458; }
label.check input { margin-top: 2px; width: auto; }

/* toasts and modals (no alert() or confirm() anywhere) */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { padding: 10px 14px; border-radius: 8px; background: #14233b; color: #fff; font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,.18); cursor: pointer; }
.toast.error { background: #9a2a22; } .toast.warn { background: #8a5a08; }
.modal-bg { position: fixed; inset: 0; z-index: 40; background: rgba(15,23,38,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 18px 20px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.modal-actions button.primary { width: auto; margin: 0; }
button.danger { background: #c0352b; color: #fff; border-color: #c0352b; font-weight: 600; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.linkbox input { font-family: ui-monospace, monospace; font-size: 12px; }

/* the job card at the top of the editor */
#jobCard .jobhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
#jobCard .back { font-size: 12px; color: #36507e; text-decoration: none; }
.title-input { font-size: 16px; font-weight: 650; border-color: transparent !important; padding: 4px 6px !important; margin: 0 0 4px -6px !important; }
.title-input:hover, .title-input:focus { border-color: #cfd6e4 !important; }
#jobCard .agrid input, #jobCard .agrid select { margin-top: 2px; }
#jobCard .notes { margin: 6px 0; } #jobCard .notes summary { cursor: pointer; color: #36507e; }
#jobCard .kv { gap: 10px; margin-top: 6px; } #jobCard #fileinfo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#conflictBox button { margin-left: 8px; }

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; height: auto; }
  #canvasWrap { height: 70vh; }
  #topbar { gap: 10px; padding: 0 10px; } #topbar .brand .muted { display: none; }
  .toolbar input[type=search] { width: 100%; }
  .form .two { grid-template-columns: 1fr; }
}

/* the price table and the quote panel (P3) */
.tablecard h3 { margin: 6px 0 8px; font-size: 14px; }
.tablecard + .tablecard, .banner + .tablecard, .savebar + .tablecard { margin-top: 12px; }
table.list tr.grp td { background: #f3f6fb; font-weight: 650; color: #36507e; font-size: 12px; }
table.list input[type=number] { width: 110px; text-align: right; margin: 0; }
.savebar { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.savebar input { flex: 1; margin: 0; } .savebar button.primary { width: auto; margin: 0; white-space: nowrap; }
.chip { display: inline-block; padding: 0 7px; border-radius: 9px; font-size: 10.5px; font-weight: 600; background: #e8ecf3; color: #3a4458; }
.chip.warn { background: #fbe7c6; color: #8a5a08; } .chip.ok { background: #d8f5e1; color: #1d7a3d; }
.lineblock .lt { float: right; font-weight: 650; }
.lineblock .chip { margin-left: 6px; }
.lineblock label { margin: 6px 0; } .lineblock select { margin-top: 2px; }
.costs { border: 1px solid #e3e8f0; border-radius: 6px; padding: 6px 9px; background: #fbfcfe; }
.costs .kv { align-items: center; padding: 3px 0; } .costs label { margin: 0; display: flex; align-items: center; gap: 6px; }
.costs input[type=number] { width: 90px; padding: 3px 5px; margin: 0; }
.banner ul { margin: 4px 0; padding-left: 18px; } .banner a { color: inherit; font-weight: 650; }

/* outputs (P4) */
#jobCard .outputs { display: flex; gap: 6px; margin-top: 8px; }
#jobCard .outputs button { flex: 1; }
#proposalText, #tplText { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
label.check.inline { display: inline-flex; margin-left: 8px; vertical-align: middle; }
code { background: #eef1f6; padding: 0 4px; border-radius: 4px; font-size: 11.5px; }
