/* ====================================================================
   Reportamelox · Design System
   Naval engineering reports — light/dark, cobalt blue (#1f87c2)
   ==================================================================== */

:root {
  --primary: #1f87c2;
  --primary-strong: #13598a;
  --primary-soft: #e8f3fa;
  --navy: #0a2540;
  --accent: #0891b2;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --danger-soft: #fee2e2;

  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --bg-soft: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow: 0 4px 14px rgba(15, 23, 42, .08);
  --shadow-lg: 0 18px 50px rgba(10, 37, 64, .22);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;

  --sidebar-w: 256px;
  --topbar-h: 64px;

  --font: 'Inter', system-ui, 'Segoe UI', sans-serif;
  --font-display: 'Sora', 'Inter', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

[data-theme="dark"] {
  --primary: #38a3dd;
  --primary-strong: #1f87c2;
  --primary-soft: #11324b;
  --navy: #061522;
  --accent: #22d3ee;
  --danger-soft: #3b1517;

  --bg: #07131f;
  --surface: #0e1f33;
  --surface-2: #122843;
  --bg-soft: #0c1d30;
  --border: #1d3a55;
  --border-strong: #28527a;
  --text: #e8eef5;
  --text-muted: #93a8c0;
  --text-faint: #5e7794;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 6px 20px rgba(0,0,0,.4);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -.01em; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; }

.visually-hidden, .skip-link {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; top: 10px; left: 10px; width: auto; height: auto;
  clip: auto; padding: 10px 16px; background: var(--primary); color: #fff;
  border-radius: var(--r-sm); z-index: 9999;
}

/* ===================== Layout ===================== */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

#sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--navy), #0c2c4d 60%, var(--primary-strong));
  color: #dbe9f5;
  padding: 18px 14px;
  z-index: 40;
}
[data-theme="dark"] #sidebar {
  background: linear-gradient(180deg, #061522, #0a2238 70%, #0d3050);
  border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 20px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 19px; color: #fff; line-height: 1; }
.brand-sub { font-size: 12px; color: #9fc2dd; margin-top: 3px; }
#sidebar-close { margin-left: auto; color: #cfe2f2; }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: 10px;
  color: #c4dbef; font-weight: 500; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 19px; height: 19px; flex: none; opacity: .9; }
.nav-item:hover { background: rgba(255,255,255,.09); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,.16); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14);
}
.nav-item.nav-accent svg { color: #7ee0f5; opacity: 1; }
.nav-item.active.nav-accent { background: rgba(34,211,238,.2); }

.sidebar-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 6px 4px; border-top: 1px solid rgba(255,255,255,.1); margin-top: 8px; }
.sidebar-version { font-size: 11px; color: #7fa3c2; font-family: var(--mono); }
.sidebar-footer .ghost-btn { color: #cfe2f2; }
.sidebar-footer .ghost-btn:hover { background: rgba(255,255,255,.12); }

#sidebar-scrim { position: fixed; inset: 0; background: rgba(4,15,26,.55); z-index: 39; backdrop-filter: blur(2px); }

#main { min-width: 0; display: flex; flex-direction: column; }

#topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
#breadcrumb { font-weight: 600; font-size: 15px; color: var(--text); display: flex; align-items: center; gap: 8px; }
#breadcrumb .crumb-faint { color: var(--text-faint); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
#global-search {
  width: 210px; max-width: 38vw; padding: 9px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 14px;
}
#global-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

#view { padding: 26px 26px 80px; outline: none; }
#view:focus-visible { outline: none; }

/* ===================== Buttons ===================== */
.primary-btn, .secondary-btn, .ghost-btn, .danger-btn {
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 10px; font-weight: 600; font-size: 14px;
  padding: 10px 16px; cursor: pointer; border: 1px solid transparent;
  transition: transform .05s, background .15s, box-shadow .15s, border-color .15s;
  white-space: nowrap;
}
.primary-btn:active, .secondary-btn:active, .ghost-btn:active { transform: translateY(1px); }
.primary-btn {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: #fff; box-shadow: var(--shadow-sm);
}
.primary-btn:hover { box-shadow: 0 4px 14px rgba(31,135,194,.4); }
.primary-btn svg { width: 17px; height: 17px; }
.secondary-btn {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.secondary-btn:hover { background: var(--surface-2); border-color: var(--primary); }
.secondary-btn svg { width: 17px; height: 17px; }
.ghost-btn {
  background: transparent; color: var(--text-muted); padding: 8px;
  border-radius: 9px;
}
.ghost-btn:hover { background: var(--bg-soft); color: var(--text); }
.ghost-btn svg { width: 19px; height: 19px; }
.icon-btn { width: 40px; height: 40px; justify-content: center; padding: 0; }
.danger-btn { background: var(--danger); color: #fff; }
.danger-btn:hover { filter: brightness(1.07); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--bg-soft); color: var(--text-muted);
}
.chip.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip.primary { background: var(--primary-soft); color: var(--primary-strong); }

/* ===================== Cards ===================== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow-sm);
}
.card-grid { display: grid; gap: 16px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--text-muted); font-size: 14px; max-width: 60ch; }
.page-head .spacer { flex: 1; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 20px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi::after { content: ""; position: absolute; right: -20px; top: -20px; width: 70px; height: 70px; border-radius: 50%; background: var(--primary-soft); opacity: .6; }
.kpi .k-val { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--primary-strong); position: relative; }
.kpi .k-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; position: relative; }

.empty {
  text-align: center; padding: 56px 24px; color: var(--text-muted);
  border: 2px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface-2);
}
.empty svg { width: 46px; height: 46px; color: var(--text-faint); margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 17px; }
.empty p { margin: 0 auto 18px; max-width: 46ch; font-size: 14px; }

/* lists of reports/templates */
.list { display: grid; gap: 12px; }
.list-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .05s;
}
.list-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.list-item .li-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-strong); flex: none; }
.list-item .li-icon svg { width: 21px; height: 21px; }
.li-main { min-width: 0; flex: 1; }
.li-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.li-actions { display: flex; gap: 6px; }

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tpl-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; cursor: pointer; transition: transform .08s, box-shadow .15s, border-color .15s;
  display: flex; flex-direction: column; gap: 8px;
}
.tpl-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }
.tpl-card .tpl-cat { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); }
.tpl-card h3 { margin: 0; font-size: 16px; }
.tpl-card p { margin: 0; font-size: 13px; color: var(--text-muted); flex: 1; }
.tpl-card .tpl-foot { display: flex; gap: 8px; margin-top: 8px; }

/* ===================== Forms ===================== */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=search], .field input[type=date],
.field input[type=number], .field input[type=password], .field textarea, .field select,
input.cell-like, textarea.cell-like {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 92px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }

/* ===================== Modal ===================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,18,30,.5); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 18px; z-index: 200; animation: fade .15s ease;
}
.modal {
  width: min(640px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); animation: pop .18s cubic-bezier(.2,.9,.3,1.2);
}
.modal.wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head .ghost-btn { margin-left: auto; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98) } }

/* ===================== Toast ===================== */
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 10px; z-index: 300; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: 12px; background: var(--navy); color: #fff;
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; animation: pop .18s ease;
  max-width: 92vw;
}
.toast.success { background: var(--ok); }
.toast.danger { background: var(--danger); }
.toast.warn { background: var(--warn); }
.toast.info { background: var(--primary-strong); }

/* ===================== Spinner ===================== */
.spinner, .ai-spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor;
  border-right-color: transparent; display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px;
}
.spinner.big { width: 30px; height: 30px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg) } }

/* ===================== Scan view ===================== */
.scan-wrap { max-width: 760px; margin: 0 auto; }
.scan-hero {
  text-align: center; padding: 30px 24px; border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--primary-soft), var(--surface));
  border: 1px solid var(--border);
}
.scan-hero .scan-badge { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 14px; display: grid; place-items: center; background: linear-gradient(180deg, var(--primary), var(--primary-strong)); color: #fff; box-shadow: var(--shadow); }
.scan-hero .scan-badge svg { width: 32px; height: 32px; }
.scan-hero h1 { margin: 0 0 6px; font-size: 22px; }
.scan-hero p { margin: 0 auto; max-width: 52ch; color: var(--text-muted); font-size: 14px; }

.scan-drop {
  margin-top: 20px; border: 2px dashed var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface); padding: 30px 20px; text-align: center; transition: border-color .15s, background .15s;
}
.scan-drop.drag { border-color: var(--primary); background: var(--primary-soft); }
.scan-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.scan-previews { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }
.scan-thumb { position: relative; width: 110px; height: 140px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--bg-soft); }
.scan-thumb img { width: 100%; height: 100%; object-fit: cover; }
.scan-thumb button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: none; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 15px; line-height: 1; }

.scan-step { display: flex; align-items: center; gap: 10px; justify-content: center; color: var(--text-muted); font-size: 14px; margin-top: 18px; }
.scan-result-card { margin-top: 18px; }

#camera-stage { position: relative; background: #000; border-radius: var(--r); overflow: hidden; }
#camera-stage video { width: 100%; display: block; max-height: 60vh; object-fit: contain; }
.camera-frame { position: absolute; inset: 8%; border: 2px dashed rgba(255,255,255,.6); border-radius: 12px; pointer-events: none; }

/* ===================== Editor ===================== */
.editor-shell { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.editor-canvas-wrap { min-width: 0; }
.editor-toolbar {
  position: sticky; top: var(--topbar-h); z-index: 20;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--r);
}
.editor-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.editor-toolbar .doc-title { font-weight: 700; font-size: 15px; border: none; background: transparent; color: var(--text); min-width: 140px; flex: 1; }
.editor-toolbar .doc-title:focus { outline: none; }

.report-paper {
  /* The document always looks like white paper (Word/Docs style), even in dark UI.
     Scope a light palette here so the editable spreadsheet/widgets inside render light too. */
  background: #ffffff; color: #0f172a;
  --text: #0f172a; --text-muted: #64748b; --text-faint: #94a3b8;
  --surface: #ffffff; --surface-2: #f8fafc; --bg-soft: #f1f5f9;
  --border: #e2e8f0; --border-strong: #cbd5e1; --primary-soft: #e8f3fa;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  box-shadow: var(--shadow-lg); margin: 0 auto; max-width: 820px; padding: 0; overflow: hidden;
}

.side-panel { position: sticky; top: calc(var(--topbar-h) + 12px); display: flex; flex-direction: column; gap: 16px; }
.panel-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.panel-card h3 { margin: 0; padding: 13px 16px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.panel-body { padding: 14px 16px; }
.tabs { display: flex; gap: 4px; padding: 8px 8px 0; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; border-radius: 8px 8px 0 0; }
.tab.active { color: var(--primary); background: var(--primary-soft); }

.block-palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.palette-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-muted); text-align: center;
  transition: border-color .15s, color .15s, background .15s;
}
.palette-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.palette-btn svg { width: 20px; height: 20px; }
.palette-btn.tool { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.palette-btn.tool:hover { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.palette-cat { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); margin: 16px 0 8px; }
.palette-subcat { font-size: 11px; font-weight: 600; color: var(--accent); margin: 12px 0 6px; padding-left: 2px; }

/* ===================== Report blocks (render) ===================== */
.report-doc { font-family: 'Calibri', var(--font), sans-serif; color: #0f172a; }
.report-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 28px; border-bottom: 3px solid var(--primary); background: #f8fafc;
}
.report-header img { height: 40px; object-fit: contain; }
.report-header .rh-right { display: flex; align-items: center; gap: 10px; }
.page-content { padding: 26px 30px 36px; }

.report-block { position: relative; margin: 4px 0; border-radius: 8px; }
.editable .report-block { padding: 6px; border: 1px solid transparent; transition: border-color .12s, background .12s; }
.editable .report-block:hover { border-color: var(--border); background: var(--surface-2); }
.editable .report-block.selected { border-color: var(--primary); background: var(--primary-soft); }
.block-tools {
  position: absolute; top: -13px; right: 8px; display: none; gap: 2px; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-sm); padding: 2px;
}
.editable .report-block.selected .block-tools, .editable .report-block:hover .block-tools { display: flex; }
.block-tools button { width: 26px; height: 26px; border: none; background: transparent; border-radius: 6px; cursor: pointer; color: var(--text-muted); display: grid; place-items: center; }
.block-tools button:hover { background: var(--bg-soft); color: var(--text); }
.block-tools button svg { width: 15px; height: 15px; }
.block-tools button.del:hover { color: var(--danger); }

.rb-cover { text-align: center; padding: 40px 20px; background: linear-gradient(160deg, #eaf4fb, #fff); border-radius: 10px; }
.rb-cover .cover-photo img { max-height: 230px; border-radius: 8px; margin-bottom: 18px; box-shadow: var(--shadow); }
.rb-cover .cover-title { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--primary-strong); }
.rb-cover .cover-sub { font-size: 15px; color: #475569; margin-top: 6px; }
.rb-cover .cover-vessel { font-size: 21px; font-weight: 700; margin-top: 18px; }
.rb-cover .cover-meta { font-size: 13px; color: #64748b; margin-top: 10px; line-height: 1.7; }

.rb-heading h1, .rb-heading h2, .rb-heading h3 { color: var(--primary-strong); border-bottom: 1px solid #d6e2ee; padding-bottom: 4px; margin: 14px 0 8px; }
.rb-heading h1 { font-size: 23px; } .rb-heading h2 { font-size: 18px; } .rb-heading h3 { font-size: 15px; border-bottom: none; }
.rb-paragraph { font-size: 14px; line-height: 1.65; }
.rb-notes { background: #f1f7fc; border-left: 3px solid var(--primary); padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 13.5px; color: #334155; }

.rb-keyvalue { display: grid; grid-template-columns: max-content 1fr; gap: 4px 18px; font-size: 13.5px; }
.rb-keyvalue dt { font-weight: 600; color: #64748b; }
.rb-keyvalue dd { margin: 0; }

table.data-table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 13px; }
table.data-table th, table.data-table td { border: 1px solid #cbd5e1; padding: 7px 9px; text-align: center; }
table.data-table th { background: #dcebf6; font-weight: 700; color: #0f3a5a; }
table.data-table caption { caption-side: top; text-align: left; font-weight: 700; font-size: 13.5px; margin-bottom: 4px; color: #0f172a; }
table.data-table tr.out-tol td { background: #fff3e0; color: #9a3412; font-weight: 600; }
table.data-table td.out-tol { background: #ffe0b2 !important; color: #9a3412; font-weight: 700; }
.tol-legend { font-size: 12px; color: #64748b; margin-top: 4px; }

.rb-image, .img-fig { text-align: center; }
.rb-image img, .img-fig img { max-width: 100%; height: auto; max-height: 340px; width: auto; border-radius: 8px; }
.rb-image figcaption, .img-fig figcaption { font-size: 12px; color: #64748b; font-style: italic; margin-top: 4px; }
.img-empty { background: #f1f5f9; border: 2px dashed #cbd5e1; padding: 36px 24px; text-align: center; color: #64748b; font-size: 13px; border-radius: 8px; }

/* TOC */
.rb-toc h2 { color: #13598a; border-bottom: 1px solid #d6e2ee; padding-bottom: 4px; }
.toc-list { list-style: none; padding: 0; margin: 8px 0; counter-reset: toc; }
.toc-list li { padding: 3px 0; font-size: 13.5px; border-bottom: 1px dotted #e2e8f0; }
.toc-list .toc-l1 { font-weight: 700; }
.toc-list .toc-l3 { padding-left: 18px; color: #475569; font-size: 13px; }

/* Divider */
.rb-divider-inner { display: flex; align-items: center; gap: 12px; margin: 10px 0; color: #94a3b8; }
.rb-divider-inner::before, .rb-divider-inner::after { content: ""; flex: 1; height: 1px; background: #cbd5e1; }
.rb-divider-inner span { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }

/* Formula */
.rb-formula-inner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #f8fafc; border-left: 3px solid #1f87c2; padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 14px; }
.rb-formula-inner .f-label { font-weight: 700; color: #0f3a5a; }
.rb-formula-inner .f-expr { font-family: var(--mono); background: #eef2f7; padding: 2px 8px; border-radius: 6px; color: #334155; }
.rb-formula-inner .f-res { color: #13598a; }

/* Checklist */
.rb-checklist h3 { color: #13598a; font-size: 15px; }
.chk-list { list-style: none; padding: 0; margin: 6px 0; }
.chk-list li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid #eef2f7; font-size: 13.5px; }
.chk-badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.chk-ok .chk-badge { background: #dcfce7; color: #166534; }
.chk-danger .chk-badge { background: #fee2e2; color: #991b1b; }
.chk-na .chk-badge { background: #e2e8f0; color: #475569; }

/* Summary cards */
.rb-summary h3 { color: #13598a; font-size: 15px; }
.sum-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 6px; }
.sum-card { background: #f1f7fc; border: 1px solid #d6e2ee; border-radius: 10px; padding: 14px; text-align: center; }
.sum-card.good { background: #dcfce7; border-color: #86efac; }
.sum-card.bad { background: #fee2e2; border-color: #fca5a5; }
.sum-card .sc-v { font-family: var(--font-display); font-size: 24px; font-weight: 800; color: #0f3a5a; }
.sum-card.good .sc-v { color: #166534; } .sum-card.bad .sc-v { color: #991b1b; }
.sum-card .sc-l { font-size: 11.5px; color: #64748b; margin-top: 2px; }

/* Gallery */
.rb-gallery h3 { color: #13598a; font-size: 15px; }
.gal-grid { display: grid; gap: 10px; margin-top: 6px; }
.gal-grid figure { margin: 0; }
.gal-grid img { width: 100%; height: auto; border-radius: 8px; display: block; }
.gal-grid figcaption { font-size: 11.5px; color: #64748b; font-style: italic; margin-top: 3px; text-align: center; }

/* Annotated photo */
.rb-annotated-inner { margin: 0; text-align: center; }
.ann-stage { position: relative; display: inline-block; max-width: 100%; }
.ann-stage img { max-width: 100%; height: auto; border-radius: 8px; display: block; }
.ann-stage[data-annotated] { cursor: crosshair; }
.ann-dot { position: absolute; transform: translate(-50%, -50%); width: 24px; height: 24px; border-radius: 50%; background: #1f87c2; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0,0,0,.4); }
.ann-legend { text-align: left; margin: 8px 0 0; padding-left: 4px; list-style: none; font-size: 13px; }
.ann-legend li { padding: 2px 0; }
.rb-signature { display: flex; gap: 30px; margin-top: 30px; }
.rb-signature .sig-box { flex: 1; border-top: 1px solid #94a3b8; padding-top: 8px; text-align: center; font-size: 12px; color: #475569; }
.rb-pagebreak { border: none; border-top: 2px dashed var(--border-strong); margin: 16px 0; }
.editable .rb-pagebreak::after { content: "Salto de página"; display: block; text-align: center; font-size: 11px; color: var(--text-faint); margin-top: -10px; background: var(--surface); width: max-content; margin-inline: auto; padding: 0 8px; }

/* contenteditable fields in editor */
[contenteditable="true"] { outline: none; }
[contenteditable="true"]:focus { box-shadow: 0 0 0 2px var(--primary-soft); border-radius: 4px; }
[contenteditable="true"][data-placeholder]:empty::before { content: attr(data-placeholder); color: var(--text-faint); }

/* ===================== Spreadsheet ===================== */
.ss-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table.ss { border-collapse: collapse; width: 100%; font-size: 13px; }
table.ss th, table.ss td { border: 1px solid var(--border); padding: 0; min-width: 70px; }
table.ss th { background: var(--bg-soft); font-weight: 700; padding: 6px 8px; color: var(--text); position: relative; }
table.ss td input { width: 100%; border: none; background: transparent; padding: 7px 8px; font-size: 13px; color: var(--text); text-align: center; font-family: var(--mono); }
table.ss td input:focus { outline: 2px solid var(--primary); outline-offset: -2px; background: var(--primary-soft); }
table.ss td.out-tol { background: #fff3e0; }
table.ss td.out-tol input { color: #9a3412; font-weight: 700; }
.ss-toolbar { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.ss-col-head { display: flex; align-items: center; gap: 4px; justify-content: center; }
.ss-col-head input { background: transparent; border: none; text-align: center; font-weight: 700; width: 100%; color: var(--text); font-size: 12.5px; }

/* ===================== Responsive ===================== */
.only-mobile { display: none; }
@media (max-width: 1080px) {
  .editor-shell { grid-template-columns: 1fr; }
  .side-panel { position: static; order: -1; }
}
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  #app.sidebar-open #sidebar { transform: translateX(0); }
  .only-mobile { display: inline-flex; }
  .btn-label { display: none; }
  #global-search { display: none; }
  #view { padding: 18px 16px 80px; }
  .field-row { grid-template-columns: 1fr; }
  .rb-signature { flex-direction: column; gap: 16px; }
}
@media (min-width: 821px) { #sidebar-scrim { display: none !important; } }

/* print */
@media print {
  #sidebar, #topbar, .editor-toolbar, .side-panel, .block-tools { display: none !important; }
  #app { display: block; } #view { padding: 0; }
  .report-paper { box-shadow: none; border: none; max-width: 100%; }
}
