/* ===================== RESET & BASE ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --bg3: #0f3460;
  --surface: #1e2a4a;
  --surface2: #243354;
  --border: #2d4270;
  --accent: #4a90d9;
  --accent2: #5ba3f5;
  --success: #27ae60;
  --danger: #e74c3c;
  --warn: #f39c12;
  --text: #e8eaf6;
  --text2: #9bb5d6;
  --text3: #6a8ab5;
  --shadow: rgba(0,0,0,0.4);
  --topbar-h: 52px;
  --sidebar-w: 200px;
  --radius: 6px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* ===================== TOPBAR ===================== */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 6px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 100;
  position: relative;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent2);
  margin-right: 12px;
  white-space: nowrap;
}

.topbar-brand i { font-size: 20px; color: var(--danger); }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  flex-wrap: nowrap;   /* never wrap — chip is out of flow */
  overflow: hidden;    /* clip if viewport is very narrow */
  min-width: 0;
}

.sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.zoom-display {
  min-width: 44px;
  text-align: center;
  font-size: 12px;
  color: var(--text2);
}

.page-info {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
}

/* Doc chip — sits right of the spacer, left of the save buttons */
#doc-chip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 4px 3px 10px;
  font-size: 11px;
  color: var(--text2);
  max-width: 220px;
  box-shadow: 0 1px 4px var(--shadow);
  transition: opacity .18s;
}
#doc-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}
#btn-close-doc {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 15px;
  line-height: 1;
  padding: 1px 5px;
  border-radius: 50%;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
#btn-close-doc:hover { background: var(--danger); color: #fff; }

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border); }

.btn.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }

.btn.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.btn-success:hover { filter: brightness(1.1); }

.btn.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.btn-danger:hover { filter: brightness(1.1); }

.btn.btn-sm { padding: 3px 7px; font-size: 11px; }
.btn.btn-lg { padding: 10px 20px; font-size: 14px; }
.btn.icon-btn { padding: 5px 8px; }

.btn-x {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.btn-x:hover { color: var(--danger); }

.full-w { width: 100%; justify-content: center; }
.mt-4 { margin-top: 4px; }

/* ===================== MAIN LAYOUT ===================== */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===================== SIDEBAR ===================== */
/* Nav de páginas dentro del drawer: solo visible en móvil (ver media query) */
.sidebar-mobile-nav { display: none; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.tool-section {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text3);
  margin-bottom: 8px;
  padding-left: 2px;
}

/* ===================== TOOL BUTTONS ===================== */
.tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text2);
  cursor: pointer;
  font-size: 12px;
  transition: all .15s;
  margin-bottom: 2px;
}
.tool-btn:hover { background: var(--surface); color: var(--text); }
.tool-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.tool-btn i { width: 16px; text-align: center; font-size: 13px; }

/* ===================== PROPERTIES ===================== */
.prop-row {
  margin-bottom: 10px;
}
.prop-row label {
  display: block;
  font-size: 11px;
  color: var(--text3);
  margin-bottom: 4px;
}
.prop-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.prop-row select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
}

.color-row { display: flex; align-items: center; gap: 6px; }
input[type="color"] {
  width: 32px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 1px;
  background: var(--surface);
  flex-shrink: 0;
}

.color-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.color-preset {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s;
}
.color-preset:hover, .color-preset.selected { border-color: #fff; }

.style-row { display: flex; gap: 4px; }
.style-btn {
  flex: 1;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  text-align: center;
  transition: all .15s;
}
.style-btn:hover { background: var(--surface2); color: var(--text); }
.style-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Signature preview */
#sig-preview-box {
  margin-top: 8px;
}
#sig-preview-img {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  margin-bottom: 4px;
}

.hint-text {
  font-size: 10px;
  color: var(--text3);
  line-height: 1.4;
  margin-top: 6px;
}
.hint-text.center { text-align: center; }

/* ===================== WORKSPACE ===================== */
.workspace {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  position: relative;
}

.workspace::-webkit-scrollbar { width: 8px; height: 8px; }
.workspace::-webkit-scrollbar-track { background: var(--bg2); }
.workspace::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===================== DROP ZONE ===================== */
.drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-h));
}
.drop-zone.drag-over { background: rgba(74,144,217,.1); outline: 2px dashed var(--accent); }
.drop-zone-inner {
  text-align: center;
  padding: 60px 40px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  max-width: 400px;
}
.drop-zone-inner i {
  font-size: 64px;
  color: var(--danger);
  margin-bottom: 16px;
}
.drop-pdf-icon {
  width: 64px;
  height: 80px;
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 8px rgba(229,62,62,.3));
}
.drop-zone-inner h2 { font-size: 22px; margin-bottom: 8px; color: var(--text); }
.drop-zone-inner p { color: var(--text3); margin-bottom: 20px; }

/* ===================== PAGES CONTAINER ===================== */
#pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  gap: 24px;
}

/* ===================== PAGE WRAPPER ===================== */
.page-wrapper {
  position: relative;
  box-shadow: 0 4px 20px var(--shadow);
  background: white;
  cursor: crosshair;
}

.page-wrapper.tool-select { cursor: default; }
.page-wrapper.tool-text { cursor: text; }
.page-wrapper.tool-draw { cursor: crosshair; }
.page-wrapper.tool-highlight { cursor: crosshair; }
.page-wrapper.tool-signature { cursor: copy; }
.page-wrapper.tool-eraser { cursor: none; }

.pdf-canvas {
  display: block;
  position: relative;
}

.annot-canvas {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
}

.html-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

/* page number label */
.page-label {
  position: absolute;
  top: -22px;
  left: 0;
  font-size: 11px;
  color: var(--text3);
  background: var(--bg2);
  padding: 2px 8px;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* ===================== TEXT ANNOTATION ===================== */
.text-annot {
  position: absolute;
  background: transparent;
  border: 1px dashed rgba(74,144,217,.6);
  border-radius: 2px;
  cursor: move;
  min-width: 60px;
  min-height: 20px;
  user-select: none;
}
.text-annot:hover { border-color: var(--accent); }
.text-annot.selected { border: 1.5px solid var(--accent); }

.text-annot-input {
  width: 100%;
  min-width: 80px;
  background: transparent;
  border: none;
  outline: none;
  cursor: text;
  resize: none;
  font-family: inherit;
  padding: 2px 4px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
}

.annot-del-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 18px;
  height: 18px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 10;
}
.text-annot:hover .annot-del-btn,
.text-annot.selected .annot-del-btn {
  display: flex;
}

/* ===================== SIGNATURE ANNOTATION ===================== */
.sig-annot {
  position: absolute;
  cursor: move;
  border: 1px dashed rgba(74,144,217,.5);
  user-select: none;
}
.sig-annot:hover { border-color: var(--accent); }
.sig-annot.selected { border: 1.5px solid var(--accent); }

.sig-annot img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.sig-resize-handle {
  position: absolute;
  bottom: -5px;
  right: -5px;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: se-resize;
  z-index: 5;
}

/* ===================== ERASER CURSOR ===================== */
.eraser-cursor {
  position: fixed;
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  display: none;
}

/* ===================== LOADING ===================== */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(26,26,46,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay p { color: var(--text2); font-size: 14px; }

/* ===================== MODALS ===================== */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 620px;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal.modal-wide { max-width: 700px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-header h3 i { color: var(--accent); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.modal-footer > div { display: flex; gap: 8px; }

/* ===================== SIGNATURE CANVAS ===================== */
#sig-canvas {
  display: block;
  width: 100%;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: crosshair;
  touch-action: none;
}

/* ===================== MERGE ===================== */
.merge-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: var(--text3);
  margin-bottom: 12px;
  transition: all .15s;
}
.merge-drop:hover, .merge-drop.drag-over {
  border-color: var(--accent);
  background: rgba(74,144,217,.05);
  color: var(--text2);
}
.merge-drop i { margin-bottom: 8px; color: var(--accent); }
.merge-drop p { font-size: 13px; }

.merge-list { display: flex; flex-direction: column; gap: 6px; }

.merge-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.merge-item-name {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.merge-item-pages {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
}
.merge-item-btns { display: flex; gap: 3px; }
.merge-item-btn {
  width: 24px;
  height: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text2);
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.merge-item-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.merge-item-btn.del:hover { background: var(--danger); border-color: var(--danger); }

/* ===================== TOAST ===================== */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 4px 12px var(--shadow);
  animation: slideIn .2s ease;
  max-width: 280px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===================== SCROLLBAR STYLING ===================== */
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-track { background: transparent; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#pages-container::-webkit-scrollbar { width: 8px; }

/* ===================== FLOATING ZOOM ===================== */
.float-zoom {
  position: fixed;
  bottom: 20px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  z-index: 90;
  overflow: hidden;
}

.fz-btn {
  background: none;
  border: none;
  color: var(--text);
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.fz-btn:hover { background: var(--accent); color: #fff; }
.fz-btn:active { background: var(--accent2); }

.fz-level {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0 4px;
  line-height: 40px;
  user-select: none;
}

/* ===================== REQUEST SIGNATURE TOOL ===================== */
#tool-btn-reqsign.active {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff; border-color: #7c3aed;
}
.reqsign-steps {
  display: flex; gap: 4px; margin-bottom: 12px;
}
.reqsign-step {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 6px 2px; border-radius: 6px;
  background: var(--bg3); font-size: 9px; color: var(--text3);
  border: 1px solid var(--border); transition: all .2s;
}
.reqsign-step.active {
  background: rgba(124,58,237,.15); border-color: #7c3aed; color: #a78bfa;
}
.reqsign-step.done {
  background: rgba(0,200,100,.1); border-color: #00c864; color: #00c864;
}
.rs-step-num {
  font-size: 13px; font-weight: 700;
}
.rs-step-label { font-size: 9px; text-align: center; line-height: 1.2; }
.rs-hint { font-size: 11px; color: var(--text2); margin: 0 0 10px; line-height: 1.5; }
.rs-hint-small { font-size: 10px; color: var(--text3); margin: 4px 0 10px; line-height: 1.4; }
.rs-marker-count {
  font-size: 12px; font-weight: 700; color: var(--accent);
  margin-bottom: 10px; text-align: center;
}
.rs-btn-primary {
  width: 100%; padding: 9px 12px; background: #7c3aed; color: #fff;
  border: none; border-radius: var(--radius); font-size: 12px;
  font-weight: 700; cursor: pointer; margin-bottom: 6px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: filter .15s;
}
.rs-btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.rs-btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.rs-btn-secondary {
  width: 100%; padding: 7px 12px; background: var(--surface2);
  color: var(--text2); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 11px; cursor: pointer;
  margin-bottom: 6px; display: flex; align-items: center;
  justify-content: center; gap: 6px; transition: all .15s;
}
.rs-btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.rs-email-input {
  width: 100%; padding: 8px 10px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 12px; outline: none;
  margin-bottom: 10px; box-sizing: border-box;
}
.rs-email-input:focus { border-color: #7c3aed; }
.rs-saving-msg { font-size: 11px; color: var(--text3); margin-top: 8px; text-align: center; }
.rs-success-icon { font-size: 32px; text-align: center; margin: 8px 0; }

/* Signature marker overlay */
.sig-marker {
  position: absolute; border: 2px dashed #7c3aed; border-radius: 4px;
  background: rgba(124,58,237,.08); cursor: move; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 2px; user-select: none;
  min-width: 80px; min-height: 36px;
}
.sig-marker-label {
  font-size: 10px; color: #7c3aed; font-weight: 700; pointer-events: none; text-align: center;
}
.sig-marker-icon { font-size: 16px; pointer-events: none; }
.sig-marker-del {
  position: absolute; top: -8px; right: -8px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--danger); color: #fff; border: none;
  font-size: 10px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; line-height: 1; padding: 0;
}
.sig-marker-fixed {
  cursor: default; border-color: #f39c12; background: rgba(243,156,18,.08);
  pointer-events: none;
}
.sig-marker-fixed .sig-marker-label { color: #f39c12; }

/* Signing mode overlay */
.signing-mode-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff; padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; box-shadow: 0 2px 12px rgba(0,0,0,.3);
}
.signing-mode-bar strong { font-size: 15px; }
.signing-mode-bar .sign-info { display: flex; flex-direction: column; gap: 2px; }
.btn-submit-sign {
  padding: 8px 20px; background: #fff; color: #7c3aed;
  border: none; border-radius: 8px; font-weight: 800; font-size: 13px;
  cursor: pointer; transition: opacity .15s; flex-shrink: 0;
}
.btn-submit-sign:hover { opacity: .9; }
.btn-submit-sign:disabled { opacity: .5; cursor: not-allowed; }

/* Desktop: float-zoom always hidden (topbar has zoom) */
@media (min-width: 641px) {
  .float-zoom { display: none !important; }
}

/* ===================== SIDEBAR TOGGLE ===================== */
.sidebar-toggle {
  flex-shrink: 0;
  margin-right: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 149;
}
.sidebar-overlay.active { display: block; }

/* Sidebar transitions */
.sidebar {
  transition: width .22s ease, transform .22s ease;
}

/* Collapsed state (desktop) */
.sidebar.collapsed {
  width: 0;
  overflow: hidden;
  border-right: none;
}

.topbar-spacer { flex: 1; }

/* ===================== RESPONSIVE — SM (≤640px) ===================== */
@media (max-width: 640px) {
  :root {
    --topbar-h: 48px;
    --sidebar-w: 220px;
  }

  /* Topbar: compact, no overflow */
  .topbar { padding: 0 8px; gap: 4px; overflow: visible; }
  .brand-text { display: none; }
  .topbar-brand { margin-right: 4px; }
  .topbar-brand i { font-size: 18px; }
  .topbar-controls { gap: 3px; flex-wrap: nowrap; }

  /* Nav de páginas: oculto en topbar (se mueve al drawer) */
  .topbar-nav { display: none !important; }
  /* Empuja los controles a la derecha para que no se peguen al logo */
  .topbar-brand { margin-right: auto; }

  /* Navegación de páginas dentro del drawer (solo móvil) */
  .sidebar-mobile-nav {
    display: flex; flex-direction: column; gap: 2px;
    padding: 8px 8px 12px; margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
  }
  .smn-link {
    display: flex; align-items: center; gap: 11px;
    padding: 11px 12px; border-radius: 9px;
    text-decoration: none; color: var(--text2, #2b323a);
    font-size: 14px; font-weight: 500;
  }
  .smn-link i { width: 18px; text-align: center; color: var(--mute, #5b6670); font-size: 15px; }
  .smn-link.active { background: var(--accent-tint, #f1faf9); color: var(--accent-d, #087a72); font-weight: 600; }
  .smn-link.active i { color: var(--accent-d, #087a72); }
  .smn-link:active { background: var(--surface-alt, #eef2f3); }

  /* Hide labels on small buttons */
  .btn-label { display: none; }

  /* Show only icon for these in topbar */
  .btn { padding: 5px 8px; }

  /* Items hidden on xs */
  .hide-xs { display: none !important; }
  .hide-sm { display: none !important; }

  /* Sidebar: overlay slide-in on mobile */
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    height: calc(100dvh - var(--topbar-h));
    z-index: 150;
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    transition: transform .22s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  /* Disable the desktop collapsed class on mobile */
  .sidebar.collapsed {
    width: var(--sidebar-w) !important;
    overflow-y: auto;
    border-right: 1px solid var(--border);
  }

  /* Workspace takes full width */
  .main-layout { flex-direction: column; }
  .workspace { width: 100%; }

  /* Drop zone smaller */
  .drop-zone-inner {
    padding: 36px 20px;
    max-width: 100%;
  }
  .drop-zone-inner i { font-size: 48px; }
  .drop-zone-inner h2 { font-size: 18px; }

  /* Pages padding smaller */
  #pages-container { padding: 12px 8px; gap: 16px; }

  /* Modals full-screen */
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal, .modal.modal-wide {
    max-width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 90dvh;
  }

  /* Signature canvas fits screen */
  #sig-canvas { height: 180px; }

  /* Toast bottom-left on mobile */
  #toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: 100%; }

  /* ── Promo banner: single compact row ── */
  .promo-banner-inner { padding: 7px 10px; gap: 8px; flex-wrap: nowrap; }
  .promo-icon { font-size: 16px; }
  .promo-text span { display: none; }
  .promo-text strong { font-size: 12px; margin-bottom: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .promo-cta { padding: 5px 10px; font-size: 11px; width: auto; border-radius: 6px; }

  /* ── Post-its: center as modal on mobile ── */
  #seal-postit, #reqsign-postit {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: calc(100vw - 40px);
    max-width: 320px;
    z-index: 9001;
  }

  /* ── Doc chip: no room on mobile topbar ── */
  #doc-chip { display: none !important; }
}

/* ===================== RESPONSIVE — MD (641–960px) ===================== */
@media (min-width: 641px) and (max-width: 960px) {
  .hide-sm { display: none !important; }
  .btn-label { display: none; }
  .btn { padding: 5px 8px; }
  .topbar { gap: 4px; }
}

/* ===================== DESKTOP: sidebar toggle ===================== */
@media (min-width: 641px) {
  .sidebar-overlay { display: none !important; }
}

/* ===================== PROMO BANNER ===================== */
#promo-banner {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  border-bottom: 2px solid #b45309;
  flex-shrink: 0;
  z-index: 90;
}
.promo-banner-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  max-width: 1200px;
  margin: 0 auto;
}
.promo-icon {
  font-size: 22px;
  color: #fff;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
}
.promo-text {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: #1c1003;
  line-height: 1.4;
}
.promo-text strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
  margin-bottom: 2px;
}
.promo-cta {
  flex-shrink: 0;
  background: #fff;
  color: #92400e;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 8px;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  transition: background .15s, transform .1s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.promo-cta:hover { background: #fef3c7; transform: translateY(-1px); }
.promo-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.promo-close:hover { color: #fff; background: rgba(0,0,0,.15); }
@media (max-width: 640px) {
  .promo-banner-inner { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .promo-text span { display: none; }
  .promo-cta { width: 100%; justify-content: center; }
}

/* ===================== DOCUMENT INFO ===================== */
/* ===================== SIDEBAR GROUP ACCORDION ===================== */
.sidebar-group {
  padding: 0 !important;
  border-bottom: 1px solid var(--border);
}
.sidebar-group-header {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  cursor: pointer;
  color: var(--text2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  padding: 12px 10px;
  box-sizing: border-box;
  user-select: none;
  background: var(--bg2);
  transition: background .15s, color .15s;
}
.sidebar-group-header:hover { background: var(--surface); color: var(--text); }
.section-chevron {
  color: var(--text3);
  transition: transform .2s ease;
  flex-shrink: 0;
}
.section-accordion-toggle[aria-expanded="false"] .section-chevron {
  transform: rotate(-90deg);
}
.sidebar-group-body {
  background: var(--surface);
  padding: 8px 10px 10px;
  overflow: hidden;
  transition: max-height .35s ease, opacity .2s ease;
  max-height: 2000px;
  opacity: 1;
}
.sidebar-group-body.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Activate markers button */
.rs-btn-activate {
  width: 100%; padding: 8px 10px; margin-bottom: 8px;
  background: var(--surface2); border: 1px dashed #7c3aed;
  border-radius: var(--radius); color: #a78bfa;
  font-size: 11px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all .15s;
}
.rs-btn-activate:hover, .rs-btn-activate.active {
  background: rgba(124,58,237,.2); color: #c4b5fd;
}
.rs-btn-activate.active {
  border-style: solid; border-color: #7c3aed;
}

/* Accordion toggle for doc-info */
.doc-info-toggle {
  all: unset;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  cursor: pointer;
  color: var(--text3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  padding: 2px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  box-sizing: border-box;
  user-select: none;
}
.doc-info-toggle:hover { color: var(--text2); }
.doc-info-chevron {
  color: var(--text3);
  transition: transform .2s ease;
  flex-shrink: 0;
}
.doc-info-toggle[aria-expanded="false"] .doc-info-chevron {
  transform: rotate(-90deg);
}
#doc-info-grid {
  overflow: hidden;
  transition: max-height .25s ease, opacity .2s ease;
  max-height: 600px;
  opacity: 1;
}
#doc-info-grid.collapsed {
  max-height: 0;
  opacity: 0;
}

.doc-info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.doc-info-row:last-child { border-bottom: none; }
.doc-info-key {
  color: var(--text3);
  flex-shrink: 0;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.doc-info-val {
  color: var(--text2);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 118px;
  font-size: 11px;
}

/* ===================== SEAL BUTTON HIGHLIGHT ===================== */
#tool-btn-seal {
  background: linear-gradient(135deg, rgba(212,165,0,.18), rgba(212,165,0,.06));
  border-color: rgba(212,165,0,.45);
  color: #d4a017;
  position: relative;
}
#tool-btn-seal:hover {
  background: linear-gradient(135deg, rgba(212,165,0,.28), rgba(212,165,0,.12));
  border-color: #d4a017;
  color: #e8b520;
}
#tool-btn-seal.active {
  background: #d4a017;
  border-color: #d4a017;
  color: #fff;
}
#tool-btn-seal::after {
  content: '★';
  position: absolute;
  right: 8px;
  font-size: 10px;
  color: #d4a017;
  animation: seal-pulse 2s ease-in-out infinite;
}
#tool-btn-seal.active::after { color: rgba(255,255,255,.7); animation: none; }
@keyframes seal-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.8); }
}

/* Post-it list */
.postit-list {
  margin: 6px 0 0 16px;
  padding: 0;
  font-size: 12px;
  color: #713f12;
  line-height: 1.8;
}

/* ===================== SEAL TOOL ===================== */
.seal-annot {
  position: absolute;
  cursor: move;
  transform-origin: center center;
  user-select: none;
}
.seal-annot:hover .seal-rotate-handle { opacity: 1; }

.seal-svg-wrap { width: 100%; height: 100%; pointer-events: none; }
.seal-svg-wrap svg { width: 100%; height: 100%; display: block; }

.seal-rotate-handle {
  position: absolute;
  top: -28px; left: 50%;
  transform: translateX(-50%);
  width: 20px; height: 20px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: grab;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #fff;
  opacity: 0;
  transition: opacity .2s;
  z-index: 10;
}
.seal-rotate-handle::before { content: '↻'; }

.seal-resize-handle {
  position: absolute;
  bottom: -5px; right: -5px;
  width: 12px; height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: se-resize;
  z-index: 10;
}

.seal-toggle-group { display: flex; gap: 3px; }
.seal-toggle {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  padding: 4px 2px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); border-radius: var(--radius);
  cursor: pointer; font-size: 10px;
  transition: all .15s; white-space: nowrap;
}
.seal-toggle:hover { background: var(--surface2); color: var(--text); }
.seal-toggle.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.seal-colors { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.seal-color {
  width: 20px; height: 20px;
  border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s, transform .15s;
}
.seal-color:hover, .seal-color.active { border-color: #fff; transform: scale(1.15); }

#seal-postit-backdrop,
#reqsign-postit-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 9000;
}

#seal-postit,
#reqsign-postit {
  position: fixed; z-index: 9001;
  width: 220px;
  background: #fef9c3; border: 1px solid #facc15;
  border-radius: 6px; padding: 14px;
  box-shadow: 3px 3px 12px rgba(0,0,0,.3);
  color: #713f12; font-size: 12px; line-height: 1.5;
}
.postit-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none;
  font-size: 16px; color: #92400e; cursor: pointer; line-height: 1;
}
.postit-header {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 13px; color: #92400e; margin-bottom: 8px;
}
#seal-postit p, #reqsign-postit p { margin-bottom: 6px; }
.postit-link {
  display: inline-block;
  background: #d97706; color: #fff;
  padding: 5px 12px; border-radius: 4px;
  text-decoration: none; font-weight: 600; font-size: 11px; margin-top: 4px;
}
.postit-link:hover { background: #b45309; }

/* ── Seal invite popup ─────────────────────────────── */
.seal-invite {
  position: absolute;
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border: 1.5px solid #10b4a3;
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(16,180,163,.18), 0 2px 8px rgba(0,0,0,.10);
  min-width: 280px;
  max-width: 360px;
  animation: si-pop .22s cubic-bezier(.34,1.56,.64,1) both;
  pointer-events: all;
}
@keyframes si-pop {
  from { opacity:0; transform:translateY(-6px) scale(.95); }
  to   { opacity:1; transform:translateY(0)   scale(1);    }
}
.si-icon { font-size: 22px; flex-shrink: 0; line-height:1; }
.si-body { flex: 1; min-width: 0; }
.si-title { font-size: 12.5px; font-weight: 700; color: #087a72; line-height: 1.3; }
.si-desc  { font-size: 11px; color: #6b7280; margin-top: 2px; }
.si-btn-yes {
  flex-shrink: 0;
  background: #10b4a3; color: #fff;
  border: none; border-radius: 7px;
  padding: 6px 12px; font-size: 11.5px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.si-btn-yes:hover { background: #087a72; }
.si-btn-no {
  flex-shrink: 0;
  background: none; border: none;
  color: #9ca3af; font-size: 16px; cursor: pointer;
  padding: 2px 4px; border-radius: 4px; line-height: 1;
  transition: color .15s;
}
.si-btn-no:hover { color: #374151; }

/* ── PDF password modal focus ── */
#pdf-password-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16,180,163,.15);
}
#pdf-password-ok:hover { background: var(--accent2); }
