/* Edição por blocos — mesmo padrão visual do editor do Overview Semanal (relatoriosmse). */

/* ---------- Topbar + cabeçalho do relatório (mesmas classes/CSS do app real) ----------
   Tudo prefixado com #report-view: report-app.css (cópia do app real) já tem regras
   "dormentes" para .shell/.detail-head/.topbar escopadas por .report-open (ex.:
   "body.report-open .shell{max-width:1540px}", ".report-open .detail-head{...}") que,
   por serem mais específicas que uma classe solta, venciam a cascata e espremiam o
   layout. Prefixar com o id não deixa isso acontecer, custe o que custar a ordem. */
#report-view .topbar{position:relative;isolation:isolate;overflow:hidden;display:flex;align-items:center;justify-content:space-between;min-height:64px;margin:0;padding:8px max(16px,calc((100vw - 1360px)/2));border:0;border-bottom:1px solid rgba(255,255,255,.08);border-radius:0;background:radial-gradient(640px 280px at 84% -35%,rgba(64,120,210,.5),transparent 62%),linear-gradient(118deg,#13223b,#193053 68%,#1f3a63);box-shadow:0 2px 8px rgba(19,34,59,.12);gap:14px}
#report-view .topbar .brand{display:inline-flex;align-items:center;gap:12px;min-width:0;color:#fff;text-decoration:none;white-space:nowrap}
#report-view .topbar .brand-mse{display:block;width:106px;height:auto;flex:none}
#report-view .topbar .brand-divider{height:26px;border-left:1px solid rgba(255,255,255,.26)}
#report-view .topbar .brand-reports{color:#fff;font:500 19px/1 'Lora',Georgia,serif;letter-spacing:-.025em}
#report-view .topbar .top-actions{display:flex;align-items:center;gap:10px}
#report-view .topbar .portal-back{border:1px solid rgba(255,255,255,.35);border-radius:5px;padding:7px 11px;color:#fff;text-decoration:none;font:11px 'IBM Plex Mono',Consolas,monospace;white-space:nowrap}
#report-view .topbar .portal-back:hover{background:rgba(255,255,255,.12)}

#report-view .report-shell{max-width:none;margin:0;padding:4px 12px 80px;width:auto}
#report-view .detail-head{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px 14px;margin:0 0 14px;padding:9px 16px;border:1px solid var(--ed-line);border-radius:12px;background:var(--ed-surface);box-shadow:0 2px 4px rgba(25,34,49,.025),0 8px 24px rgba(25,34,49,.04)}
#report-view .detail-identity{grid-column:1;grid-row:1;display:flex;align-items:center;gap:14px;min-width:0}
#report-view .detail-client-logo-slot{display:grid;place-items:center;width:58px;height:34px;flex:none}
#report-view .detail-client-logo{display:block;width:auto;max-width:58px;height:auto;max-height:32px;object-fit:contain;flex:none}
#report-view .detail-client-logo[hidden]{display:none}
#report-view .detail-title-block{display:grid;grid-template-columns:minmax(0,1fr);gap:3px;min-width:0}
#report-view .detail-title-block h2{margin:0;font:600 18px/1.3 'IBM Plex Sans',sans-serif;letter-spacing:-.02em;color:var(--ed-ink)}
#report-view .detail-work{margin:0;font-size:11px;line-height:1.4;color:var(--ed-body)}
#report-view .detail-status{grid-column:2;grid-row:1;display:flex;flex-direction:column;align-items:stretch;justify-content:center;gap:5px;min-width:max-content}
#report-view .detail-type{color:var(--ed-muted);font:500 10px/1.5 'IBM Plex Sans',sans-serif;text-align:left}
#report-view .detail-status-bottom{display:flex;align-items:center;justify-content:space-between;gap:14px}
#report-view .detail-meta{display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-start;gap:10px;font-size:10px;color:var(--ed-muted)}
#report-view .detail-meta strong{color:var(--ed-ink);font-weight:500;margin-left:4px}
#report-view .badge{display:inline-flex;flex:none;padding:5px 9px;border:1px solid transparent;border-radius:999px;background:#edf2ff;color:#2453b5;font:500 10px 'IBM Plex Mono',monospace;white-space:nowrap}
#report-view .status-DRAFT{background:#fff4df;color:#946000}

#report-view .open-button,#report-view .back-button{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:34px;padding:7px 10px;border-radius:8px;font:600 11px 'IBM Plex Sans',sans-serif;cursor:pointer;white-space:nowrap}
#report-view .ed-command-bar svg{width:17px;height:17px;flex:none}
#report-view .ed-command-bar .open-button{order:0;background:var(--ed-blue);color:#fff;border:1px solid var(--ed-blue);box-shadow:0 2px 4px #2563eb18}
#report-view .ed-command-bar #export-pdf{order:0}
#report-view .ed-command-bar #sheet-import-open{display:none;order:-1}
#report-view.ed-active .ed-command-bar #sheet-import-open{display:inline-flex}
#report-view .ed-command-bar .open-button:hover{background:#1d4ed8}
#report-view .ed-command-bar .open-button[aria-pressed="true"]{background:#eaf1ff;color:#194caf;border-color:#a9c2fa}
#report-view .ed-command-bar .back-button{background:#fff;color:#34465e;border:1px solid var(--ed-line)}
#report-view .ed-command-bar .back-button:hover{background:#f5f8fc;border-color:var(--ed-line-strong)}
#report-view .ed-command-bar{grid-column:1/-1;display:flex;flex-wrap:wrap;align-items:center;gap:6px;padding-top:8px;border-top:1px solid var(--ed-line)}
#report-view .ed-command-more{position:relative;margin-left:auto}
#report-view .ed-command-more>.ed-btn{min-height:34px}
#report-view .ed-command-menu{position:absolute;right:0;top:calc(100% + 8px);z-index:100;min-width:230px;max-width:calc(100vw - 48px);padding:6px;border:1px solid var(--ed-line);border-radius:10px;background:#fff;box-shadow:0 12px 40px #142b4926}
#report-view .ed-command-menu[hidden]{display:none}
#report-view .ed-menu-item{display:block;width:100%;min-height:40px;border:0;border-radius:6px;background:transparent;padding:10px 12px;text-align:left;color:#34465e;font-size:12px;cursor:pointer}
#report-view .ed-menu-item:hover,#report-view .ed-menu-item:focus-visible{background:var(--ed-blue-soft)}
#report-view .ed-menu-item.ed-menu-danger{color:#b42335}
#report-view .ed-menu-item.ed-menu-danger:hover,#report-view .ed-menu-item.ed-menu-danger:focus-visible{background:#fff0f1}
#report-view .ed-menu-separator{height:1px;margin:5px 8px;background:var(--ed-line)}
#report-view .ed-menu-item.file-button{position:relative}
#report-view .ed-menu-item.file-button input{position:absolute;inset:0;opacity:0;cursor:pointer}

/* Atalhos flutuantes (acesso rápido, sobretudo em telas estreitas) */
#report-view .ed-floating-actions{position:fixed;bottom:max(16px,env(safe-area-inset-bottom));left:50%;transform:translateX(-50%);z-index:80;display:flex;align-items:center;gap:4px;width:max-content;max-width:calc(100vw - 16px);padding:6px;background:#fff;border:1px solid var(--ed-line-strong);border-radius:12px;box-shadow:0 6px 24px #142b4924}
#report-view .ed-quick-action{display:grid;place-items:center;width:36px;height:36px;padding:8px;border:0;border-radius:8px;background:transparent;color:#34465e;cursor:pointer}
#report-view .ed-quick-action#quick-sheet-import{display:none}
#report-view.ed-active .ed-quick-action#quick-sheet-import{display:grid}
#report-view .ed-quick-action svg{width:18px;height:18px}
#report-view .ed-quick-action:hover,#report-view .ed-quick-action[aria-pressed="true"]{background:var(--ed-blue-soft);color:#194caf}

@media(max-width:700px){
  #report-view .detail-identity{align-items:flex-start;gap:8px}
  #report-view .detail-client-logo-slot{width:44px;height:28px}
  #report-view .detail-client-logo{max-width:44px;max-height:28px}
  #report-view .detail-title-block{grid-template-columns:minmax(0,1fr);gap:2px}
  #report-view .detail-status{min-width:0;gap:5px}
  #report-view .detail-status-bottom{gap:8px}
  #report-view .detail-meta{gap:4px 8px;font-size:9px}
  #report-view .ed-command-bar>button,#report-view .ed-command-bar>.ed-command-more{flex:1 1 calc(50% - 6px)}
  #report-view .ed-command-more{margin:0}
  #report-view .ed-command-more>.ed-btn{width:100%}
  #report-view .ed-command-menu{width:100%;min-width:0}
  #report-view .topbar{min-height:64px;padding:8px 16px}
  #report-view .topbar .brand-mse{width:88px}
  #report-view .report-shell{padding:12px 12px 90px}
}
@media print{.ed-floating-actions{display:none!important}}

:root {
  --ed-blue: #2563eb;
  --ed-blue-soft: #eef3ff;
  --ed-navy: #002f6c;
  --ed-ink: #192231;
  --ed-body: #4d5868;
  --ed-muted: #7a8699;
  --ed-line: #e1e5eb;
  --ed-line-strong: #cfd5dd;
  --ed-surface: #fff;
  --ed-canvas: #f5f7fa;
  --ed-red: #c93434;
  --ed-red-soft: #fff1f1;
  --ed-green: #0d8a74;
}

/* ---------- Modo edição sobre o documento ---------- */
.ed-banner {
  display: flex; align-items: center; gap: 12px;
  margin: -6px 0 18px; padding: 10px 14px;
  border: 1px solid #c9d8fb; border-radius: 10px; background: var(--ed-blue-soft);
  color: var(--ed-ink); font-size: 12.5px;
  position: sticky; top: 8px; z-index: 5; box-shadow: 0 6px 18px #2563eb14;
}
.ed-banner[hidden] { display: none; }
.ed-banner p { margin: 0; flex: 1; }
.ed-banner-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ed-blue); box-shadow: 0 0 0 4px #2563eb2b; flex: none; }

.ed-block { position: relative; }
.ed-badge {
  display: none; position: absolute; top: 8px; right: 8px; z-index: 4;
  padding: 6px 11px; border: 0; border-radius: 999px;
  background: var(--ed-blue); color: #fff; font: 600 11px/1 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif;
  letter-spacing: .02em; cursor: pointer; box-shadow: 0 6px 16px #2563eb40;
}
.ed-mode .ed-block {
  cursor: pointer; border-radius: 10px;
  outline: 2px dashed #2563eb33; outline-offset: 10px;
  transition: outline-color .15s, background-color .15s;
}
.ed-mode .ed-block:hover, .ed-mode .ed-block:focus-within { outline-color: var(--ed-blue); background-color: #2563eb06; }
.ed-mode .ed-block .ed-badge { display: inline-flex; }
.ed-saved { animation: ed-saved 1.6s ease-out; }
@keyframes ed-saved { 0% { background-color: #0d8a7426; } 100% { background-color: transparent; } }

/* ---------- Janela ---------- */
.ed-dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 0; border-radius: 16px; background: var(--ed-surface); color: var(--ed-ink);
  font: 400 13px/1.5 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif;
  box-shadow: 0 30px 90px #0b1b3366;
}
.ed-dialog.ed-wide { width: min(920px, calc(100vw - 32px)); }
.ed-dialog::backdrop { background: #0d2038a8; backdrop-filter: blur(2px); }
.ed-dialog[open] { animation: ed-pop .18s ease-out; }
@keyframes ed-pop { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
.ed-shell { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.ed-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 20px 24px 14px; border-bottom: 1px solid var(--ed-line); }
.ed-head h2 { margin: 2px 0 0; font-size: 18px; font-weight: 600; color: var(--ed-navy); }
.ed-kicker { font: 500 10.5px 'IBM Plex Mono', monospace; letter-spacing: .1em; text-transform: uppercase; color: var(--ed-blue); }
.ed-intro { margin: 6px 0 0; color: var(--ed-body); font-size: 12.5px; }
.ed-x { flex: none; width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--ed-muted); font-size: 22px; line-height: 1; cursor: pointer; }
.ed-x:hover { background: var(--ed-canvas); color: var(--ed-ink); }
.ed-body { padding: 18px 24px 8px; overflow: auto; flex: 1; background: var(--ed-surface); }
.ed-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--ed-line); background: var(--ed-canvas); border-radius: 0 0 16px 16px; }
.ed-hint { color: var(--ed-muted); font-size: 11px; }
.ed-actions { display: flex; gap: 8px; margin-left: auto; }
.ed-error { margin: 0 24px 12px; padding: 10px 12px; border-radius: 8px; background: var(--ed-red-soft); color: var(--ed-red); font-size: 12.5px; }
.ed-error[hidden] { display: none; }
.ed-discard { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 24px 12px; padding: 10px 12px; border-radius: 8px; background: #fff7e6; color: #7a5200; font-size: 12.5px; }
.ed-discard[hidden] { display: none; }
.ed-discard span { flex: 1; min-width: 180px; }

.ed-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border: 1px solid var(--ed-line-strong); border-radius: 8px;
  background: #fff; color: var(--ed-ink); font: 600 12px 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.ed-btn:hover { border-color: #aab4c2; background: #fafbfc; }
.ed-btn:disabled { opacity: .6; cursor: progress; }
.ed-primary { border-color: var(--ed-blue); background: var(--ed-blue); color: #fff; }
.ed-primary:hover { border-color: #1d4ed8; background: #1d4ed8; }
.ed-danger { border-color: var(--ed-red); background: var(--ed-red); color: #fff; }
.ed-danger:hover { border-color: #a82a2a; background: #a82a2a; }

/* ---------- Campos ---------- */
.ed-group { margin: 0 0 22px; }
.ed-group h3 { margin: 0 0 12px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ed-muted); }
.ed-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; margin-bottom: 14px; }
.ed-span { grid-column: 1 / -1; }
.ed-field { display: grid; gap: 6px; min-width: 0; margin: 0 0 2px; }
.ed-field[hidden] { display: none; }
.ed-label { font-size: 11.5px; font-weight: 600; color: var(--ed-body); }
.ed-help { color: var(--ed-muted); font-size: 11px; line-height: 1.45; }
.ed-field-error { color: var(--ed-red); font-size: 11px; }
.ed-field-error[hidden] { display: none; }
.ed-dialog input[type=text], .ed-dialog input[type=number], .ed-dialog input[type=date], .ed-dialog input[type=month], .ed-dialog textarea {
  width: 100%; min-width: 0; padding: 9px 11px; border: 1px solid var(--ed-line-strong); border-radius: 8px;
  background: #fff; color: var(--ed-ink); font: 400 13px/1.4 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif;
}
.ed-dialog input:disabled { background: var(--ed-canvas); color: var(--ed-muted); }
.ed-dialog textarea { resize: vertical; min-height: 60px; }
.ed-dialog input:focus, .ed-dialog textarea:focus { outline: 3px solid #2563eb2e; outline-offset: 0; border-color: var(--ed-blue); }
.ed-dialog input.ed-invalid { border-color: var(--ed-red); }
.ed-check { display: flex; align-items: flex-start; gap: 9px; margin: 14px 0; font-size: 12.5px; color: var(--ed-body); cursor: pointer; }

/* Listas */
.ed-list { display: grid; gap: 10px; }
.ed-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ed-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 12px; border: 1px solid var(--ed-line); border-radius: 12px; background: #fff; transition: box-shadow .15s, border-color .15s; }
.ed-row:hover { border-color: var(--ed-line-strong); box-shadow: 0 4px 14px #1922310d; }
.ed-row.ed-dragging { opacity: .45; }
.ed-row.ed-drop { border-color: var(--ed-blue); box-shadow: 0 0 0 2px #2563eb33; }
.ed-row.ed-moved { animation: ed-saved 1s ease-out; }
.ed-row-side { display: grid; justify-items: center; gap: 4px; padding-top: 4px; }
.ed-handle { color: #a7b0bd; font-size: 14px; letter-spacing: -2px; cursor: grab; user-select: none; }
.ed-handle:active { cursor: grabbing; }
.ed-row-n { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: var(--ed-canvas); color: var(--ed-muted); font: 600 10.5px 'IBM Plex Mono', monospace; }
.ed-row-tools { display: flex; flex-direction: column; gap: 4px; }
.ed-icon { width: 28px; height: 28px; padding: 0; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ed-muted); font-size: 13px; cursor: pointer; }
.ed-icon:hover:not(:disabled) { background: var(--ed-canvas); border-color: var(--ed-line); color: var(--ed-ink); }
.ed-icon:disabled { opacity: .3; cursor: default; }
.ed-icon-danger:hover:not(:disabled) { background: var(--ed-red-soft); border-color: #f3caca; color: var(--ed-red); }
.ed-add { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 11px; border: 1.5px dashed var(--ed-line-strong); border-radius: 12px; background: transparent; color: var(--ed-blue); font: 600 12.5px 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif; cursor: pointer; }
.ed-add span { font-size: 16px; line-height: 1; }
.ed-add:hover:not(:disabled) { border-color: var(--ed-blue); background: var(--ed-blue-soft); }
.ed-add:disabled { opacity: .5; cursor: default; }
.ed-empty { margin: 0; padding: 18px; border-radius: 12px; background: var(--ed-canvas); color: var(--ed-muted); text-align: center; font-size: 12.5px; }
.ed-empty[hidden] { display: none; }

/* Aviso rápido */
.ed-toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 1000; transform: translateX(-50%);
  padding: 11px 18px; border-radius: 10px; background: #13233a; color: #fff;
  font: 500 12.5px 'IBM Plex Sans', 'Segoe UI', Arial, sans-serif; box-shadow: 0 14px 40px #0b1b3355;
  animation: ed-toast-in .2s ease-out;
}
.ed-toast-ok::before { content: '✓'; margin-right: 8px; color: #5ee0c4; font-weight: 700; }
.ed-toast-out { opacity: 0; transition: opacity .4s; }
@keyframes ed-toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 700px) {
  .ed-grid { grid-template-columns: 1fr; }
  .ed-row { grid-template-columns: 26px minmax(0, 1fr) auto; padding: 10px; }
  .ed-head, .ed-body, .ed-foot { padding-left: 16px; padding-right: 16px; }
  .ed-hint { display: none; }
  .ed-banner { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .ed-dialog[open], .ed-saved, .ed-row.ed-moved, .ed-toast { animation: none; }
}
@media print {
  .ed-banner, .ed-badge, .ed-toast { display: none !important; }
  .ed-mode .ed-block { outline: none !important; background: none !important; }
}
