/* ============================================================
   CV Online — App chrome
   Direccion: "mesa de trabajo editorial". Papel cálido, tinta
   azul profunda, acento verde pino y detalle latón. Display
   serif (Fraunces) con restricción, UI en Inter.
   ============================================================ */

:root {
  --paper:      #F4F2EC;
  --paper-2:    #EDEAE1;
  --surface:    #FFFFFF;
  --ink:        #16233F;   /* azul tinta */
  --ink-soft:   #3B4A66;
  --muted:      #7A8399;
  --line:       #DEDACE;
  --line-2:     #E9E6DC;
  --pine:       #2F6F5E;   /* acento */
  --pine-dark:  #235244;
  --brass:      #B58A3C;   /* detalle */
  --danger:     #B23A34;
  --danger-bg:  #FBEDEC;
  --ok:         #2F6F5E;

  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 2px rgba(22,35,63,.05), 0 8px 30px rgba(22,35,63,.08);
  --shadow-sm:  0 1px 2px rgba(22,35,63,.06);

  --sans: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

[data-theme="dark"] {
  --paper:      #151b27;
  --paper-2:    #1c2436;
  --surface:    #212d42;
  --ink:        #e8edf5;
  --ink-soft:   #a8b4cc;
  --muted:      #6a7a96;
  --line:       #2a3650;
  --line-2:     #243048;
  --pine:       #3d9b84;
  --pine-dark:  #2e7a67;
  --brass:      #c9a555;
  --danger:     #e05555;
  --danger-bg:  #2e1e1e;
  --ok:         #3d9b84;
  --shadow:     0 1px 2px rgba(0,0,0,.3), 0 8px 30px rgba(0,0,0,.4);
  --shadow-sm:  0 1px 2px rgba(0,0,0,.2);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  transition: background .2s, color .2s;
}
a { color: var(--pine); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
h1,h2,h3 { margin: 0; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .62em 1.05em; font-size: .93rem; font-weight: 600;
  transition: transform .04s ease, background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #101c34; }
.btn-accent { background: var(--pine); color: #fff; }
.btn-accent:hover { background: var(--pine-dark); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #EED2CF; }
.btn-danger:hover { background: #F6DEDC; }
.btn-sm { padding: .42em .7em; font-size: .82rem; }
.btn-block { width: 100%; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: .32rem; margin-bottom: .8rem; }
.field label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.field .hint { font-size: .74rem; color: var(--muted); font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=url], input[type=date], input[type=month], textarea, select {
  width: 100%; font-family: inherit; font-size: .92rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .58em .7em; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--pine);
  box-shadow: 0 0 0 3px rgba(47,111,94,.14);
}
textarea { resize: vertical; min-height: 74px; line-height: 1.45; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .8rem; }
@media (max-width: 560px){ .row-2,.row-3 { grid-template-columns: 1fr; } }

/* Campo de fecha: texto libre + botón calendario */
.date-combo { position: relative; display: flex; align-items: stretch; }
.date-combo input[type=text] { flex: 1; padding-right: 2.4em; }
.date-hidden {
  position: absolute; right: .3em; top: 50%; transform: translateY(-50%);
  width: 1px; height: 1px; opacity: 0; pointer-events: none; padding: 0; border: 0;
}
.date-cal-btn {
  position: absolute; right: .28em; top: 50%; transform: translateY(-50%);
  width: 1.9em; height: 1.9em; display: grid; place-items: center;
  background: transparent; border: 0; cursor: pointer; font-size: 1rem; line-height: 1;
  border-radius: 6px; opacity: .75;
}
.date-cal-btn:hover { opacity: 1; background: var(--paper-2, rgba(0,0,0,.05)); }
.date-current-note {
  display: inline-flex; align-items: center; gap: .4em; font-size: .9rem;
  color: var(--pine); font-weight: 600; padding: .58em .1em;
}
.check-inline {
  display: flex !important; flex-direction: row !important; align-items: center; gap: .5rem;
  font-size: .82rem; font-weight: 500; color: var(--ink-soft); cursor: pointer; margin-bottom: .2rem;
}
.check-inline input[type=checkbox] { width: auto; margin: 0; accent-color: var(--pine); }

.checkbox { flex-direction: row; align-items: center; gap: .5rem; }
.checkbox input { width: auto; }
.checkbox label { font-weight: 500; color: var(--ink); }

/* ============================================================
   AUTH
   ============================================================ */
.auth-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr;
}
@media (max-width: 900px){ .auth-wrap { grid-template-columns: 1fr; } }

.auth-aside {
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(47,111,94,.20), transparent 60%),
    linear-gradient(160deg, #16233F 0%, #1D2F52 60%, #21395F 100%);
  color: #EDEFF5; padding: 3.2rem 3rem; display: flex; flex-direction: column;
  justify-content: space-between; position: relative; overflow: hidden;
}
@media (max-width: 900px){ .auth-aside { display: none; } }
.auth-brand { display: flex; align-items: center; gap: .7rem; font-family: var(--display);
  font-weight: 600; font-size: 1.25rem; letter-spacing: .2px; }
.auth-mark { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center;
  background: var(--brass); color: #16233F; font-weight: 700; font-family: var(--display); }
.auth-hero h1 { font-family: var(--display); font-weight: 600; font-size: 2.7rem; line-height: 1.05;
  letter-spacing: -.5px; margin-bottom: 1rem; }
.auth-hero h1 em { font-style: italic; color: #E7C889; }
.auth-hero p { color: #B9C2D6; font-size: 1.02rem; max-width: 30ch; }
.auth-foot { font-size: .8rem; color: #8794AE; display: flex; gap: 1.2rem; }
.auth-sheet {
  position: absolute; right: -60px; bottom: -40px; width: 260px; height: 340px; background: #fff;
  border-radius: 8px; transform: rotate(8deg); opacity: .10;
  box-shadow: 0 30px 80px rgba(0,0,0,.4);
}

.auth-main { display: grid; place-items: center; padding: 2rem; background: var(--paper); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card-title { font-family: var(--display); font-size: 1.65rem; font-weight: 600; margin-bottom: .3rem; }
.auth-card .card-sub { color: var(--muted); font-size: .92rem; margin-bottom: 1.6rem; }
.auth-tabs { display: inline-flex; background: var(--paper-2); border-radius: 10px; padding: 4px; margin-bottom: 1.4rem; }
.auth-tabs button { border: none; background: transparent; color: var(--ink-soft); font-weight: 600;
  font-size: .88rem; padding: .5em 1em; border-radius: 7px; }
.auth-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.auth-alt { text-align: center; font-size: .86rem; color: var(--muted); margin-top: 1.1rem; }
.auth-title { font-family: var(--display); font-size: 1.4rem; font-weight: 600; margin-bottom: .3rem; }
.auth-sub { font-size: .88rem; color: var(--muted); margin-bottom: 1.1rem; }
.code-input input { text-align: center; letter-spacing: .6em; font-size: 1.5rem; font-weight: 600;
  font-variant-numeric: tabular-nums; }

/* ============================================================
   APP SHELL
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 60px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 1.4rem; background: rgba(244,242,236,.85);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; font-family: var(--display);
  font-weight: 600; font-size: 1.12rem; }
.topbar .brand .auth-mark { width: 26px; height: 26px; font-size: .9rem; }
.topbar .nav { display: flex; align-items: center; gap: .5rem; }
.topbar .who { font-size: .82rem; color: var(--muted); margin-right: .3rem; max-width: 22ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-admin { font-size: .68rem; font-weight: 700; color: var(--brass); border: 1px solid #E4CF9E;
  background: #FBF3DF; padding: .12em .5em; border-radius: 999px; text-transform: uppercase; letter-spacing: .5px; }
.btn-theme { background: transparent; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .38em .55em; font-size: 1rem; line-height: 1; cursor: pointer; color: var(--ink-soft);
  transition: background .15s, color .15s; display: flex; align-items: center; }
.btn-theme:hover { background: var(--paper-2); color: var(--ink); }

/* ============================================================
   EDITOR
   ============================================================ */
.editor {
  display: grid; grid-template-columns: 480px 1fr; gap: 0;
  align-items: start; min-height: calc(100vh - 60px);
}
@media (max-width: 1100px){ .editor { grid-template-columns: 1fr; } }

.form-pane { padding: 0 1.4rem 5rem; border-right: 1px solid var(--line); }
.preview-pane {
  padding: 1.4rem;
  position: sticky; top: 60px;
  display: flex; flex-direction: column;
  height: calc(100vh - 60px);
  min-width: 0; overflow-x: hidden;
}

/* Controles de hoja y plantilla en el panel izquierdo */
.form-controls { padding: 1.2rem 0 1rem; border-bottom: 1px solid var(--line); margin-bottom: 1.4rem; }
.form-controls-row { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; margin-bottom: .9rem; }
.form-pane h2 { font-family: var(--display); font-size: 1.4rem; font-weight: 600; margin-bottom: .2rem; margin-top: 0; }
.form-pane .lead { color: var(--muted); font-size: .9rem; margin-bottom: 1.3rem; }

.section-block { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 1rem 1.05rem; margin-bottom: 1rem; box-shadow: var(--shadow-sm); }
.section-block > h3 { font-size: .78rem; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--pine); margin-bottom: 0; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.section-hint { font-size: .75rem; color: var(--ink-soft); margin: -.4rem 0 .75rem; font-style: italic; }

.repeat-item { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: .85rem;
  margin-bottom: .75rem; background: #FCFBF8; position: relative; }
.repeat-item .item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.repeat-item .item-head strong { font-size: .82rem; color: var(--ink-soft); }
.item-head-actions { display: flex; align-items: center; gap: .25rem; }
.reorder-btn { background: none; border: 1px solid var(--border); border-radius: 4px; padding: 0 .3rem; font-size: .7rem; line-height: 1.6; cursor: pointer; color: var(--ink-soft); transition: background .15s, color .15s; }
.reorder-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.link-remove { background: none; border: none; color: var(--danger); font-size: .78rem; font-weight: 600; padding: .2em .3em; }
.link-remove:hover { text-decoration: underline; }
.bullets-list { display: flex; flex-direction: column; gap: .4rem; }
.bullet-row { display: flex; gap: .4rem; align-items: flex-start; }
.bullet-row textarea { min-height: 40px; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--paper-2);
  border: 1px solid var(--line); border-radius: 999px; padding: .28em .7em; font-size: .82rem; }
.chip button { border: none; background: none; color: var(--muted); font-size: 1rem; line-height: 1; padding: 0; }
.chip button:hover { color: var(--danger); }

.photo-row { display: flex; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.photo-prev { width: 66px; height: 66px; border-radius: 50%; object-fit: cover; border: 2px solid var(--line);
  background: var(--paper-2); flex: none; }

/* ---- Preview pane ---- */
.preview-toolbar { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; margin-bottom: 1rem; } /* legacy */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: none; background: transparent; padding: .4em .7em; border-radius: 7px; font-size: .82rem;
  font-weight: 600; color: var(--ink-soft); }
.seg button.active { background: var(--ink); color: #fff; }
.seg .label { font-size: .7rem; color: var(--muted); font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; align-self: center; padding: 0 .5em 0 .3em; }

.template-picker { display: flex; flex-wrap: wrap; gap: .5rem; padding-bottom: .2rem; margin-bottom: 0; }
.tpl-card { flex: none; width: 92px; cursor: pointer; text-align: center; }
.tpl-thumb { width: 92px; height: 122px; border-radius: 8px; border: 2px solid var(--line);
  background: #fff; overflow: hidden; box-shadow: var(--shadow-sm); transition: border-color .15s, transform .1s; }
.tpl-card.active .tpl-thumb { border-color: var(--pine); }
.tpl-card:hover .tpl-thumb { transform: translateY(-2px); }
.tpl-card span { display: block; font-size: .74rem; margin-top: .35rem; color: var(--ink-soft); font-weight: 600; }
.tpl-thumb svg { width: 100%; height: 100%; display: block; }

.fit-badge { display: inline-flex; align-items: center; gap: .45em; font-size: .82rem; font-weight: 600;
  padding: .4em .75em; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.fit-badge.ok { color: var(--ok); border-color: #BBD8CE; background: #EDF6F2; }
.fit-badge.warn { color: var(--brass); border-color: #E7D2A2; background: #FBF4E2; }
.fit-badge.tight { color: var(--danger); border-color: #EED2CF; background: var(--danger-bg); }
.fit-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.preview-stage { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; display: grid; place-items: start center;
  overflow-x: hidden; overflow-y: visible; flex: 1; min-height: 0; }

/* Contenedor de la hoja del CV (tamaño fijo por formato) */
.cv-page {
  background: #fff; box-shadow: 0 10px 40px rgba(22,35,63,.16); position: relative;
  overflow: hidden; transform-origin: top center;
}
.cv-page.fmt-a4     { width: 794px;  height: 1123px; }
.cv-page.fmt-carta  { width: 816px;  height: 1056px; }
.cv-page.fmt-oficio { width: 816px;  height: 1344px; }

.download-row { display: flex; flex-wrap: wrap; gap: .6rem; padding-top: .9rem; border-top: 1px solid var(--line); margin-top: 0; flex-shrink: 0; }

/* ============================================================
   ADMIN
   ============================================================ */
.admin { max-width: 1100px; margin: 0 auto; padding: 2rem 1.4rem 4rem; }
.admin h2 { font-family: var(--display); font-size: 1.7rem; font-weight: 600; margin-bottom: .2rem; }
.admin .lead { color: var(--muted); margin-bottom: 1.6rem; }
.stats { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.6rem; }
.stat { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: .9rem 1.2rem; box-shadow: var(--shadow-sm); min-width: 130px; }
.stat .n { font-family: var(--display); font-size: 1.7rem; font-weight: 600; }
.stat .l { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.table-wrap { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm); }
table.users { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.users th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); padding: .8rem 1rem; border-bottom: 1px solid var(--line); background: #FBFAF6; }
table.users td { padding: .75rem 1rem; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.users tr:last-child td { border-bottom: none; }
table.users tr:hover td { background: #FCFBF7; }
.badge { font-size: .72rem; font-weight: 700; padding: .18em .55em; border-radius: 999px; }
.badge.on { color: var(--ok); background: #EAF4EF; }
.badge.off { color: var(--danger); background: var(--danger-bg); }
.badge.pend { color: var(--brass); background: #FBF4E2; }
.actions-cell { display: flex; gap: .4rem; justify-content: flex-end; }
@media (max-width: 720px){ table.users .hide-sm { display: none; } }

/* ============================================================
   TOAST + utils
   ============================================================ */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: .7em 1.1em; border-radius: 10px; font-size: .88rem;
  font-weight: 500; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--pine-dark); }

.err-text { color: var(--danger); font-size: .82rem; margin-top: .3rem; min-height: 1em; }
.ok-text { color: var(--ok); font-size: .82rem; margin-top: .3rem; min-height: 1em; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }
.muted { color: var(--muted); }
.mt-1 { margin-top: .6rem; } .mt-2 { margin-top: 1.2rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.divider { height: 1px; background: var(--line); margin: 1.2rem 0; border: none; }

/* ============================================================
   CV MODAL (admin)
   ============================================================ */
.cv-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.cv-modal { background: var(--paper); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.3);
  width: min(860px, 100%); max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; }
.cv-modal-header { display: flex; justify-content: space-between; align-items: center;
  padding: .9rem 1.2rem; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.cv-modal-close { background: none; border: none; font-size: 1.1rem; color: var(--muted);
  cursor: pointer; padding: .2em .4em; border-radius: 4px; }
.cv-modal-close:hover { background: var(--surface); color: var(--ink); }
.cv-modal-stage { background: var(--paper-2); padding: 24px; overflow-y: auto; overflow-x: hidden;
  flex: 1; min-height: 0; display: grid; place-items: start center; }

/* Dark mode: topbar usa variable para que el backdrop sea correcto */
[data-theme="dark"] .topbar { background: rgba(21,27,39,.88); }
[data-theme="dark"] .auth-aside { background: #1c2436; }
[data-theme="dark"] .auth-card { background: var(--surface); }
[data-theme="dark"] input, [data-theme="dark"] textarea, [data-theme="dark"] select { background: var(--paper-2); color: var(--ink); border-color: var(--line); }
[data-theme="dark"] .tag-admin { background: #2e2510; border-color: #5a4010; }
[data-theme="dark"] .section-block { background: var(--surface); }
[data-theme="dark"] .repeat-item { background: var(--paper-2); }
[data-theme="dark"] .tpl-card .tpl-thumb { background: var(--surface); }
[data-theme="dark"] .preview-stage { background: var(--paper-2); }
[data-theme="dark"] .stat { background: var(--surface); }
[data-theme="dark"] .users td, [data-theme="dark"] .users th { border-color: var(--line); }