:root {
  color-scheme: light dark;
  --font-sans: -apple-system, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;

  --brand-50: #eef4ff;
  --brand-100: #dbe7ff;
  --brand-500: #3b5bdb;
  --brand-600: #2f4bc7;
  --brand-700: #263ea3;

  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e3e6f0;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow-sm: 0 1px 2px rgba(20, 24, 45, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 24, 45, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 24, 45, 0.14);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131a;
    --surface: #1b1d29;
    --surface-2: #21232f;
    --border: #2c2f3d;
    --text: #eef0f7;
    --text-muted: #9a9db3;
    --brand-50: #1a2340;
    --brand-100: #202b52;
  }
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.5rem; font-size: 1.05rem; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
}
.brand-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  border-left: 1px solid var(--border);
  padding-left: 0.6rem;
  margin-left: 0.1rem;
}

.header-actions { display: flex; align-items: center; gap: 1rem; }
#whoami { font-size: 0.85rem; color: var(--text-muted); }

.app-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}
.card .card-hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  text-align: center;
  color: var(--text-muted);
  transition: border-color 0.15s, background 0.15s;
}
.upload-dropzone.drag-over {
  border-color: var(--brand-500);
  background: var(--brand-50);
}

.toolbar-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
}

button svg, .btn svg { display: block; flex-shrink: 0; }

button, .btn {
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--brand-500);
  color: white;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  transition: background 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
button:hover, .btn:hover { background: var(--brand-600); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--brand-500); color: white; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.btn-danger:hover { background: rgba(220, 38, 38, 0.08); }
.btn-sm { padding: 0.32rem 0.6rem; font-size: 0.78rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--surface-2); }

.doc-name { font-weight: 500; }
.doc-version-tag {
  font-size: 0.72rem;
  color: var(--brand-600);
  background: var(--brand-50);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  margin-left: 0.4rem;
}

.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.row-actions button { padding: 0.3rem 0.55rem; font-size: 0.78rem; }

#status { min-height: 1.4rem; font-size: 0.88rem; }
.status-error { color: var(--danger); }
.status-ok { color: var(--success); }

dialog {
  border-radius: 14px;
  border: none;
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--text);
  max-width: 440px;
  width: 90vw;
}
dialog::backdrop { background: rgba(10, 12, 20, 0.5); backdrop-filter: blur(2px); }
dialog h3 { margin-top: 0; }
dialog label { display: block; margin: 0.75rem 0 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
dialog input, dialog select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  box-sizing: border-box;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
dialog .dialog-actions { margin-top: 1.3rem; display: flex; gap: 0.5rem; justify-content: flex-end; }
dialog .doc-checklist { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem; margin-top: 0.5rem; }
dialog .doc-checklist label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text); margin: 0.2rem 0; }
dialog .doc-checklist input[type="checkbox"] { width: auto; }

#sign-canvas, #sign-pad-canvas {
  display: block;
  width: 100%;
  max-width: 380px;
  height: 140px;
  border: 1px solid var(--border);
  border-radius: 8px;
  touch-action: none;
  background: white;
}

.version-list { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.version-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.version-list li:last-child { border-bottom: none; }

/* --- Login --- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand-50), var(--bg) 60%);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2.25rem;
  max-width: 380px;
  width: 90vw;
  text-align: center;
}
.login-box .brand-mark { width: 44px; height: 44px; font-size: 1.3rem; border-radius: 12px; margin: 0 auto 1rem; }
.login-box h1 { margin: 0 0 0.4rem; font-size: 1.4rem; }
.login-box p { color: var(--text-muted); margin: 0 0 1.5rem; font-size: 0.92rem; }
.login-box .btn { width: 100%; justify-content: center; padding: 0.7rem; }

/* --- Descarga app de escritorio --- */
.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.download-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  background: var(--surface-2);
}
.download-card .os-icon { display: block; margin: 0 auto 0.6rem; color: var(--brand-600); }
.download-card .btn { width: 100%; justify-content: center; margin-top: 0.75rem; }
.download-card .unavailable { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.6rem; }

/* --- Editor --- */
.editor-body { background: #2b2d3a; }
.editor-toolbar {
  position: sticky;
  top: 57px;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.25rem;
}
.tool-group { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.tool-group label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.78rem; color: var(--text-muted); }
.tool-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  font-size: 1rem;
}
.tool-btn.active { background: var(--brand-500); color: white; border-color: var(--brand-500); }
.tool-btn.danger.active { background: var(--danger); border-color: var(--danger); }
.editor-status { padding: 0.4rem 1.25rem; font-size: 0.85rem; min-height: 1.6rem; }
.pdf-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
}
.pdf-page-wrapper { position: relative; box-shadow: var(--shadow-lg); }
.pdf-render-layer, .pdf-overlay-layer { position: absolute; top: 0; left: 0; }
.pdf-overlay-layer { touch-action: none; cursor: crosshair; }

footer.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 2rem 0;
}
