:root {
  --bg: #0b1120;
  --bg-soft: #111a2e;
  --card: #16223c;
  --card-2: #1c2b4a;
  --border: #24365c;
  --text: #e8eefc;
  --muted: #93a3c4;
  --brand: #3b82f6;
  --brand-2: #6366f1;
  --accent: #22d3ee;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 80% -10%, #1b2a4d 0%, transparent 60%),
              radial-gradient(1000px 500px at -10% 10%, #16204a 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font-family: inherit; cursor: pointer; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 34px 30px; box-shadow: var(--shadow);
}
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.auth-logo img { width: 46px; height: 46px; border-radius: 10px; }
.auth-logo b { font-size: 1.05rem; }
.auth-card h1 { font-size: 1.5rem; margin: 18px 0 4px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: .92rem; }
.auth-tabs { display: flex; gap: 6px; background: var(--bg-soft); padding: 5px; border-radius: 12px; margin-bottom: 20px; }
.auth-tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px; border-radius: 9px; font-weight: 600; }
.auth-tabs button.active { background: var(--brand); color: #fff; }

/* ---------- Forms ---------- */
label { display: block; font-size: .82rem; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
input, select, textarea {
  width: 100%; background: var(--bg-soft); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 13px; font-size: .95rem; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(59,130,246,.18); }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0;
  border-radius: 10px; padding: 12px 18px; font-weight: 700; font-size: .95rem; width: 100%;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--card-2); border: 1px solid var(--border); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.btn.sm { width: auto; padding: 8px 14px; font-size: .85rem; }
.btn.wauto { width: auto; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.err { color: var(--red); font-size: .85rem; margin-top: 12px; min-height: 1em; }

/* ---------- Botón de Google ---------- */
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #1f2328; border: 1px solid #dadce0; border-radius: 10px;
  padding: 12px 18px; font-weight: 600; font-size: .95rem; width: 100%;
  text-decoration: none; margin-bottom: 4px;
}
.btn-google:hover { background: #f7f8f8; }
.auth-sep { display: flex; align-items: center; gap: 12px; margin: 16px 0 4px; color: var(--muted); font-size: .8rem; }
.auth-sep::before, .auth-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---------- Portal del cliente (3 pasos) ---------- */
.portal { max-width: 860px; margin: 0 auto; padding: 20px 18px 60px; }
.portal-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 22px; }
.portal-h1 { font-size: 1.6rem; margin: 0 0 6px; }
.portal-sub { color: var(--muted); margin: 0 0 20px; font-size: .95rem; }

.pasos { display: flex; gap: 8px; margin-bottom: 28px; flex-wrap: wrap; }
.paso {
  flex: 1; min-width: 130px; display: flex; align-items: center; gap: 8px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: .88rem; font-weight: 600; color: var(--muted);
}
.paso .n {
  width: 24px; height: 24px; border-radius: 50%; background: var(--card-2);
  display: grid; place-items: center; font-size: .8rem; flex: none;
}
.paso.activo { border-color: var(--brand); color: var(--text); }
.paso.activo .n { background: var(--brand); color: #fff; }
.paso.ok { border-color: var(--green); color: var(--text); }
.paso.ok .n { background: var(--green); color: #06281c; }

.doc-card { text-align: center; }
.doc-card .doc-ico { font-size: 2.4rem; line-height: 1; margin-bottom: 8px; }
.doc-card.listo { border-color: var(--green); }
.doc-card.subiendo { opacity: .55; pointer-events: none; }

/* Firma */
.firma-wrap { position: relative; background: #fff; border-radius: 12px; overflow: hidden; }
.firma-wrap canvas { width: 100%; height: auto; display: block; touch-action: none; cursor: crosshair; }
.firma-linea { position: absolute; left: 8%; right: 8%; bottom: 22%; border-bottom: 2px dashed #c9ccd1; pointer-events: none; }
.firma-hint {
  position: absolute; left: 0; right: 0; bottom: 24%; text-align: center;
  color: #b9bec5; font-size: 1rem; pointer-events: none; font-family: var(--font);
}

.listo { text-align: center; padding: 30px 0; }
.listo-ico { font-size: 3.4rem; margin-bottom: 10px; }

@media (max-width: 700px) {
  .pasos .paso { min-width: 0; font-size: .78rem; padding: 10px; }
  .portal { padding: 14px 14px 50px; }
}

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-soft); border-right: 1px solid var(--border); padding: 22px 16px;
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.sidebar .brand img { width: 38px; height: 38px; border-radius: 9px; }
.sidebar .brand b { font-size: .98rem; line-height: 1.1; }
.sidebar .brand span { font-size: .72rem; color: var(--muted); }
.navbtn {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--muted); padding: 11px 13px; border-radius: 10px;
  font-weight: 600; font-size: .92rem;
}
.navbtn:hover { background: var(--card); color: var(--text); }
.navbtn.active { background: var(--brand); color: #fff; }
.navbtn .ic { width: 18px; text-align: center; }
.sidebar .spacer { flex: 1; }
.userbox { padding: 12px; background: var(--card); border-radius: 12px; font-size: .82rem; }
.userbox .em { color: var(--muted); word-break: break-all; }

.content { padding: 30px 34px; max-width: 1150px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-head h1 { margin: 0; font-size: 1.6rem; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 4px 20px rgba(0,0,0,.2);
}
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.card .lead { color: var(--muted); font-size: .86rem; margin: 0 0 14px; }
.stat .n { font-size: 2rem; font-weight: 800; }
.stat .l { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.stat.alta .n { color: var(--red); }
.stat.media .n { color: var(--amber); }
.stat.ok .n { color: var(--green); }

/* ---------- Table / list ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; font-size: .95rem; }
.item .meta { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.badge { font-size: .72rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.badge.alta { background: rgba(248,113,113,.15); color: var(--red); }
.badge.media { background: rgba(251,191,36,.15); color: var(--amber); }
.badge.ok { background: rgba(52,211,153,.15); color: var(--green); }
.badge.info { background: rgba(59,130,246,.15); color: #93c5fd; }
.badge.gray { background: var(--card-2); color: var(--muted); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }

/* ---------- Dropzone ---------- */
.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 34px; text-align: center;
  color: var(--muted); background: var(--bg-soft); transition: .15s;
}
.drop.hover { border-color: var(--brand); background: rgba(59,130,246,.08); color: var(--text); }
.drop .big { font-size: 2rem; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5,10,20,.72); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 18px; width: 100%;
  max-width: 760px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow);
}
.modal .m-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
.modal .m-head h2 { margin: 0; font-size: 1.2rem; }
.modal .m-body { padding: 22px 24px; }
.modal .m-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: var(--card); }
.close-x { background: transparent; border: 0; color: var(--muted); font-size: 1.5rem; line-height: 1; }
.letter-preview {
  background: #fff; color: #111; border-radius: 8px; padding: 30px 34px; font-family: "Times New Roman", Georgia, serif;
  font-size: .9rem; white-space: pre-wrap; line-height: 1.5; max-height: 55vh; overflow: auto;
}

/* ---------- Misc ---------- */
.chk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.chk-grid .chk-h { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.chk { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); font-weight: 500; cursor: pointer; }
.chk input { width: auto; }
@media (max-width: 600px) { .chk-grid { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--card-2); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: .82rem; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.notice { background: rgba(251,191,36,.1); border: 1px solid rgba(251,191,36,.3); color: #fde68a; padding: 12px 15px; border-radius: 10px; font-size: .84rem; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--card);
  border: 1px solid var(--border); color: var(--text); padding: 12px 20px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 100; font-size: .9rem; font-weight: 600;
}
.toast.ok { border-color: var(--green); }
.toast.bad { border-color: var(--red); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.flex { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar .spacer { display: none; }
  .grid.cols-3, .grid.cols-4, .grid.cols-2 { grid-template-columns: 1fr; }
  .content { padding: 20px; }
  .row { grid-template-columns: 1fr; }
}
