/* ═══════════════════════════════════════════════════════════════════
   RAKJO Firma Digital — Hoja de estilos principal
   Paleta: verde bosque #2d4a22, sage #8db87c, crema #f6f9f3
   ═══════════════════════════════════════════════════════════════════ */

/* ── Variables ───────────────────────────────────────────────────── */
:root {
  --verde:        #2d4a22;
  --verde-dark:   #1e3217;
  --verde-hover:  #3a5f2c;
  --sage:         #8db87c;
  --sage-light:   #b5d4a7;
  --sage-fog:     #d4e4c8;
  --cream:        #f6f9f3;
  --cream-dark:   #edf2e8;
  --white:        #ffffff;
  --text:         #1a2a14;
  --text-muted:   #5a7050;
  --border:       #d0dfc8;
  --border-light: #e5eed e;
  --red:          #c0392b;
  --red-light:    #fde8e8;
  --shadow-sm:    0 1px 3px rgba(45,74,34,.10);
  --shadow-md:    0 4px 16px rgba(45,74,34,.14);
  --shadow-lg:    0 8px 32px rgba(45,74,34,.18);
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    16px;
  --header-h:     60px;
  --transition:   0.18s ease;
}

/* ── Reset ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--verde); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}
img { max-width: 100%; }
.hidden { display: none !important; }

/* ── Logo / Brand ────────────────────────────────────────────────── */
.logo-mark {
  width: 44px; height: 44px;
  background: var(--verde);
  color: var(--white);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 800;
  flex-shrink: 0;
}
.logo-mark.sm { width: 32px; height: 32px; font-size: 1rem; }

.logo-text { display: flex; flex-direction: column; line-height: 1.1; }
.logo-name { font-size: 1.2rem; font-weight: 800; color: var(--verde); letter-spacing: -.5px; }
.logo-sub  { font-size: .7rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }

/* ── Auth pages ──────────────────────────────────────────────────── */
.auth-page {
  background: linear-gradient(135deg, var(--verde) 0%, #4a7a3a 100%);
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.auth-container {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.auth-card {
  width: 100%;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: 2rem;
}
.auth-title    { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-bottom: .25rem; }
.auth-subtitle { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.75rem; }
.auth-footer   { color: rgba(255,255,255,.6); font-size: .8rem; text-align: center; }
.auth-form     { display: flex; flex-direction: column; gap: 1rem; }

/* ── App layout ──────────────────────────────────────────────────── */
.app-page { background: var(--cream); min-height: 100vh; }

/* Header */
.app-header {
  height: var(--header-h);
  background: linear-gradient(135deg, var(--verde) 0%, var(--verde-hover) 100%);
  border-bottom: none;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.20);
}
.header-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 1.25rem;
  height: 100%; display: flex; align-items: center; gap: 1rem;
}
.header-brand {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none;
}
.brand-name  { font-size: 1.05rem; font-weight: 700; color: #fff; }
.brand-sub   { font-size: .8rem; font-weight: 400; color: rgba(255,255,255,.7); margin-left: .25rem; }
.header-nav  { display: flex; gap: .5rem; margin-left: auto; }
.nav-link {
  padding: .35rem .85rem;
  border-radius: 20px;
  color: rgba(255,255,255,.8);
  font-size: .9rem; font-weight: 500;
  transition: var(--transition);
}
.nav-link:hover  { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(255,255,255,.20); color: #fff; }

.header-user {
  display: flex; align-items: center; gap: .5rem;
  margin-left: .5rem;
}
.user-name { font-size: .85rem; color: rgba(255,255,255,.8); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Elementos dentro del header: forzar colores claros */
.app-header .btn-icon { color: rgba(255,255,255,.85); }
.app-header .btn-icon:hover { background: rgba(255,255,255,.15); color: #fff; }
.app-header .btn-ghost { color: rgba(255,255,255,.85); }
.app-header .btn-ghost:hover { background: rgba(255,255,255,.15); color: #fff; }
.app-header button[type="submit"] { color: rgba(255,255,255,.85); border-color: rgba(255,255,255,.3); }
.app-header button[type="submit"]:hover { background: rgba(255,255,255,.15); }

/* Main content */
.app-main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem; }

/* Action bar */
.action-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.action-bar-left  { display: flex; align-items: baseline; gap: .75rem; }
.action-bar-right { display: flex; align-items: center; gap: .75rem; }
.page-title       { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.doc-counter      { font-size: .85rem; color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary {
  background: var(--verde);
  color: var(--white);
}
.btn-primary:hover:not(:disabled) { background: var(--verde-hover); }

.btn-sign {
  background: var(--sage);
  color: var(--verde-dark);
  padding: .65rem 1.5rem;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
}
.btn-sign:hover:not(:disabled) { background: var(--sage-light); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-sign:active { transform: translateY(0); }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--verde); color: var(--verde); background: var(--cream); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--cream-dark); color: var(--text); }

.btn-danger {
  background: var(--red-light);
  color: var(--red);
  border: 1.5px solid #f5c6c4;
}
.btn-danger:hover { background: #f9d0ce; }

.btn-full { width: 100%; }
.btn-sm   { padding: .35rem .75rem; font-size: .82rem; }
.btn-xs   { padding: .2rem .55rem; font-size: .78rem; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 1rem; color: var(--text-muted);
  transition: var(--transition);
}
.btn-icon:hover { background: var(--cream-dark); color: var(--text); }

/* ── Forms ───────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label {
  font-size: .85rem; font-weight: 600; color: var(--text);
}
.form-group small { font-size: .78rem; color: var(--text-muted); }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="date"],
.form-group input[type="number"],
.form-group textarea,
.form-group select,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  font-size: .9rem;
  color: var(--text);
  background: var(--white);
  transition: border-color var(--transition);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(141,184,124,.2);
}
.input-sm { padding: .4rem .65rem; font-size: .85rem; }
.select-sm { padding: .4rem .65rem; font-size: .85rem; width: 100%; }

.form-row { display: grid; gap: .75rem; }
.two-cols  { grid-template-columns: 1fr 1fr; }
.four-cols { grid-template-columns: repeat(4,1fr); }

.required { color: var(--red); }
.section-label { font-size: .85rem; font-weight: 600; color: var(--text-muted); margin-bottom: .5rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* File drop area (for cert upload) */
.file-drop-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--cream);
  transition: var(--transition);
  cursor: pointer;
}
.file-drop-area:hover { border-color: var(--sage); background: var(--sage-fog); }
.file-drop-inner {
  padding: 1.25rem;
  display: flex; align-items: center; gap: .75rem;
  color: var(--text-muted); font-size: .9rem;
}
.file-drop-icon { font-size: 1.4rem; }

/* Radio group */
.radio-group { display: flex; flex-direction: column; gap: .5rem; }
.radio-option {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .65rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.radio-option:has(input:checked) {
  border-color: var(--sage);
  background: var(--sage-fog);
}
.radio-option input[type="radio"] { margin-top: .15rem; accent-color: var(--verde); flex-shrink: 0; }
.radio-label { display: flex; flex-direction: column; gap: .1rem; }
.radio-label strong { font-size: .9rem; color: var(--text); }
.radio-label small  { font-size: .78rem; color: var(--text-muted); }
.radio-option-disabled {
  opacity: .38;
  cursor: not-allowed;
  pointer-events: none;
}

/* Checkbox */
.cert-checkboxes { display: flex; flex-direction: column; gap: .4rem; }
.cert-check-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.cert-check-item:has(input:checked) { border-color: var(--sage); background: var(--sage-fog); }
.cert-check-item input { accent-color: var(--verde); }
.cert-check-label { display: flex; flex-direction: column; gap: .05rem; }
.cert-check-alias { font-weight: 600; font-size: .88rem; color: var(--text); }
.cert-check-holder{ font-size: .78rem; color: var(--text-muted); }

/* Toggle */
.toggle-row { display: flex; align-items: center; gap: .75rem; font-size: .9rem; color: var(--text); }
.toggle { position: relative; display: inline-block; width: 42px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  inset: 0; background: var(--border);
  border-radius: 24px; transition: var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: var(--white);
  border-radius: 50%; transition: var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--sage); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Panels (inbox/outbox) ───────────────────────────────────────── */
.panels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: stretch;
}
@media (max-width: 700px) {
  .panels-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.panel-header {
  display: flex; align-items: center; gap: .6rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--cream);
  flex-wrap: wrap;
}
.panel-title {
  display: flex; align-items: center; gap: .4rem;
  font-weight: 600; font-size: .92rem; color: var(--text);
  flex: 1;
}
.panel-icon { font-size: 1rem; }

/* Drop zone */
.drop-zone {
  flex: 1;
  min-height: 280px;
  position: relative;
  padding: .5rem;
  transition: background var(--transition);
}
.drop-zone.drag-over { background: var(--sage-fog); }
.outbox-area { flex: 1; min-height: 280px; padding: .5rem; position: relative; }

.drop-hint {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: .5rem; color: var(--text-muted); text-align: center;
  padding: 2rem;
  pointer-events: none;
}
.drop-hint.hidden-hint { display: none; }
.drop-icon { font-size: 2.5rem; opacity: .5; }
.drop-hint p { font-size: .88rem; line-height: 1.55; }

/* File list */
.file-list { list-style: none; display: flex; flex-direction: column; gap: .35rem; }
.file-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--white);
  transition: var(--transition);
}
.file-item:hover { border-color: var(--sage-light); background: var(--cream); }
.file-icon  { font-size: 1.2rem; flex-shrink: 0; }
.file-info  { flex: 1; min-width: 0; }
.file-name  { font-size: .85rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta  { font-size: .75rem; color: var(--text-muted); }
.file-actions { display: flex; gap: .3rem; flex-shrink: 0; }

/* Signed file items (outbox) */
.file-item.signed { border-color: var(--sage-light); background: var(--sage-fog); }
.file-item.signed .file-name { color: var(--verde); }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  background: var(--border); border-radius: 10px;
  font-size: .72rem; font-weight: 700; color: var(--text-muted);
}
.badge-green { background: var(--sage-light); color: var(--verde-dark); }

.badge-status {
  display: inline-block; padding: .15rem .55rem;
  border-radius: 20px; font-size: .75rem; font-weight: 600;
}
.badge-status.badge-green { background: #d4edda; color: #155724; }
.badge-status.badge-red   { background: #f8d7da; color: #721c24; }

/* ── Alerts ──────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  line-height: 1.4;
}
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid #f5c6c4; }
.alert-info  { background: #e8f4fd; color: #004085; border: 1px solid #bee5eb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--white);
  padding: .75rem 1.5rem;
  border-radius: 999px;
  font-size: .88rem; font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  max-width: 90vw;
  text-align: center;
  animation: toastIn .2s ease;
}
.toast-success { background: var(--verde); }
.toast-error   { background: var(--red); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Preferences panel (slide-over) ─────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 200;
  backdrop-filter: blur(2px);
}
.prefs-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(480px, 100vw);
  background: var(--white);
  z-index: 201;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideIn .22s ease;
}
@keyframes slideIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.prefs-panel.hidden { display: none; }

.prefs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--cream);
}
.prefs-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--text); }

.prefs-body {
  flex: 1; overflow-y: auto;
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}
.prefs-section { display: flex; flex-direction: column; gap: .5rem; }
.prefs-label   { font-size: .85rem; font-weight: 700; color: var(--text); }
.prefs-hint    { font-size: .78rem; color: var(--text-muted); }
.empty-hint    { font-size: .85rem; color: var(--text-muted); }
.empty-hint a  { color: var(--verde); }

.prefs-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Perfiles de firma (presets) ─────────────────────────────────── */
.prefs-presets-section {
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  gap: .65rem !important;
}
.preset-row {
  display: flex;
  gap: .5rem;
  align-items: center;
}
.preset-row select {
  flex: 1;
  padding: .38rem .55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  background: #fff;
  min-width: 0;
}
.preset-save-row {
  display: flex;
  gap: .5rem;
  align-items: center;
}
.preset-save-row input {
  flex: 1;
  padding: .38rem .55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  min-width: 0;
}
.preset-save-row input:focus,
.preset-row select:focus {
  outline: none;
  border-color: var(--rakjo-blue-mid, #2c5282);
  box-shadow: 0 0 0 2px rgba(44,82,130,.15);
}

/* ── Cards ───────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ── Certificate table ───────────────────────────────────────────── */
.certs-table {
  width: 100%; border-collapse: collapse;
}
.certs-table th {
  background: var(--cream);
  padding: .7rem 1rem;
  text-align: left;
  font-size: .8rem; font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.certs-table td {
  padding: .85rem 1rem;
  font-size: .87rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.certs-table tr:last-child td { border-bottom: none; }
.certs-table tr:hover td { background: var(--cream); }
.cert-alias   { font-family: monospace; font-size: .9rem; }
.cert-actions { white-space: nowrap; vertical-align: middle !important; }
.cert-actions-inner { display: flex; gap: .4rem; align-items: center; flex-wrap: nowrap; }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 600px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: scale(.97); }
  to   { opacity: 1; transform: scale(1); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-body {
  flex: 1; overflow-y: auto;
  padding: 1.5rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: .75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--cream);
}

/* Signing modal */
.signing-modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 380px; width: 100%;
}
.signing-spinner {
  font-size: 3rem; margin-bottom: 1rem;
  animation: spin 1.5s linear infinite;
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.signing-modal h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: .5rem; }
.signing-modal p  { color: var(--text-muted); font-size: .9rem; }

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .75rem;
  padding: 3rem 2rem; text-align: center; color: var(--text-muted);
}
.empty-icon { font-size: 2.5rem; opacity: .5; }

/* ── Responsive tweaks ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .auth-card { padding: 2rem 1.25rem; }
  .header-inner { padding: 0 .75rem; gap: .5rem; }
  .brand-sub { display: none; }
  .header-nav { gap: .25rem; }
  .nav-link { padding: .3rem .6rem; font-size: .82rem; }
  .user-name { display: none; }
  .app-main { padding: 1rem .75rem; }
  .action-bar { gap: .5rem; }
  .btn-sign { padding: .55rem 1rem; font-size: .9rem; }
  .two-cols  { grid-template-columns: 1fr; }
  .four-cols { grid-template-columns: 1fr 1fr; }
  .prefs-panel { width: 100vw; }
  .modal-body { padding: 1rem; }
  .certs-table { font-size: .8rem; }
  .certs-table th, .certs-table td { padding: .55rem .65rem; }
}
