/* ==========================================================================
   Fijate Tools - Calculadora de Lotería de Navidad y décimo compartido
   Tema oscuro por defecto en :root / [data-theme="dark"] y claro en [data-theme="light"]
   ========================================================================== */

:root,
[data-theme="dark"] {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-page: #090d16;
  --bg-card: #111827;
  --bg-card-subtle: #182235;
  --bg-input: #0f172a;
  --border-color: #273549;
  --border-focus: #38bdf8;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-color: #38bdf8;
  --primary-light: rgba(56, 189, 248, 0.14);
  --primary-border: rgba(56, 189, 248, 0.35);

  --gold: #f59e0b;
  --gold-bg: rgba(245, 158, 11, 0.14);
  --gold-text: #fcd34d;
  --gold-border: rgba(245, 158, 11, 0.35);

  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.14);
  --success-text: #6ee7b7;

  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.14);
  --warning-text: #fcd34d;

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.14);
  --danger-text: #fca5a5;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-subtle: #f8fafc;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-focus: #0284c7;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;

  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-color: #0284c7;
  --primary-light: #e0f2fe;
  --primary-border: #7dd3fc;

  --gold: #b45309;
  --gold-bg: #fffbeb;
  --gold-text: #92400e;
  --gold-border: #fcd34d;

  --success: #059669;
  --success-bg: #ecfdf5;
  --success-text: #065f46;

  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;

  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-text: #991b1b;

  --shadow-card: 0 4px 16px -2px rgba(15, 23, 42, 0.08);
  color-scheme: light;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.55;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title,
.hero-title {
  font-family: var(--font-heading);
}

.mono,
code {
  font-family: var(--font-mono);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.uppercase {
  text-transform: uppercase;
}

/* Layout principal canónico */
.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

.card-main {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: clamp(1rem, 2.5vw, 1.75rem);
}

/* Barra rápida */
.tool-quick-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding-bottom: 1.15rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.quick-bar-text {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.quick-bar-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.quick-bar-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Botones generales */
.btn-subtle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.btn-subtle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-subtle.btn-xs {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn-danger-subtle:hover {
  border-color: var(--danger);
  color: var(--danger-text);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-md);
  border: none;
  background: var(--primary);
  color: #090d16;
  font-family: var(--font-main);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

[data-theme="light"] .btn-primary {
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-link,
.btn-link-clear {
  background: none;
  border: none;
  color: var(--primary);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.2rem 0.35rem;
}

.btn-link-clear {
  color: var(--danger-text);
}

/* Pestañas principales */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.9rem 1rem;
  min-height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-main);
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.15s ease;
}

.mode-tab:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.mode-tab.active {
  background: var(--primary-light);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary-border);
}

.mode-tab-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.mode-tab.active .mode-tab-title {
  color: var(--primary);
}

.mode-tab-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Grids de calculadora y certificado */
.calc-grid,
.cert-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 1.5rem;
  align-items: start;
}

.panel-box,
.form-section,
.preview-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: clamp(1rem, 2vw, 1.35rem);
  min-width: 0;
}

.panel-heading {
  font-family: var(--font-heading);
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border-color);
}

.sub-heading {
  font-family: var(--font-heading);
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.65rem;
}

/* Formularios responsivos */
.form-grid {
  display: grid;
  gap: 0.9rem;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  min-width: 0;
}

.form-group-center {
  justify-content: flex-end;
}

.form-group label,
.form-group > label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
}

.req {
  color: var(--danger);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0.55rem 0.78rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.92rem;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea {
  min-height: 70px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

select,
.form-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  padding-right: 40px;
  background-color: var(--bg-input);
  color: var(--text-main);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

select option,
select optgroup {
  background-color: var(--bg-card);
  color: var(--text-main);
}

[data-theme="light"] select option,
[data-theme="light"] select optgroup {
  background-color: #ffffff;
  color: #0f172a;
}

/* Inputs con sufijo o botón interno en flex */
.input-suffix-wrap,
.input-with-btn,
.stepper-wrap {
  display: flex;
  align-items: stretch;
  width: 100%;
  min-width: 0;
}

.input-suffix-wrap input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-suffix-wrap .suffix {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.78rem;
  min-width: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: none;
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.88rem;
}

.input-with-btn {
  gap: 0.4rem;
}

.input-with-btn input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
}

.stepper-wrap input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 700;
  border-radius: 0;
}

.stepper-btn {
  min-width: 42px;
  min-height: 42px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.stepper-btn:first-child {
  border-right: none;
  border-top-left-radius: var(--radius-sm);
  border-bottom-left-radius: var(--radius-sm);
}

.stepper-btn:last-child {
  border-left: none;
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
}

.stepper-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.ticket-num-input {
  font-size: 1.15rem !important;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-align: center;
}

/* Chips y segmented toggles */
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip-btn {
  min-height: 36px;
  padding: 0.35rem 0.72rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn:hover {
  border-color: var(--primary);
  color: var(--text-main);
}

.chip-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 700;
}

.segmented-toggle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.28rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.seg-btn {
  min-height: 38px;
  padding: 0.4rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--primary);
  color: #090d16;
  font-weight: 700;
}

[data-theme="light"] .seg-btn.active {
  color: #ffffff;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 42px;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  font-size: 0.84rem;
  color: var(--text-main);
  cursor: pointer;
}

.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.check-row.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.divider-line {
  height: 1px;
  background: var(--border-color);
  margin: 0.25rem 0;
}

.helper-note {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  color: var(--text-main);
  font-size: 0.84rem;
  line-height: 1.45;
}

.helper-note.is-warning {
  background: var(--warning-bg);
  border-color: var(--gold-border);
  color: var(--warning-text);
}

.mini-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.split-subbox {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-color);
  background: var(--bg-card);
}

.custom-split-toolbar,
.custom-split-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.custom-participants-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.custom-participant-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(90px, 0.85fr) auto auto;
  gap: 0.45rem;
  align-items: center;
}

.share-pct-badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.28rem 0.5rem;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-remove-row {
  min-width: 38px;
  min-height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--danger-text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-remove-row:hover {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.status-pill {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
}

.status-pill.ok {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-pill.warn {
  background: var(--warning-bg);
  color: var(--warning-text);
}

/* Resultados KPI y desglose */
.hero-kpi-box {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.05rem 1.15rem;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--gold-bg), var(--primary-light));
  border: 1px solid var(--gold-border);
  margin-bottom: 1rem;
}

.hero-kpi-main {
  min-width: 0;
  flex: 1 1 220px;
}

.hero-kpi-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.hero-kpi-val {
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 3.2vw, 2.25rem);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
  margin: 0.25rem 0;
}

.hero-kpi-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tax-status-badge {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
}

.tax-status-badge.exempt {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.tax-status-badge.has-tax {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--gold-border);
}

.metrics-lines {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.metric-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.25rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.88rem;
}

.metric-line:last-child {
  border-bottom: none;
}

.metric-line.highlight-line {
  background: var(--success-bg);
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border-bottom: none;
}

.metric-line-label {
  color: var(--text-muted);
}

.highlight-line .metric-line-label {
  color: var(--text-main);
}

.metric-line-val {
  font-weight: 700;
  color: var(--text-main);
  text-align: right;
  white-space: nowrap;
}

.metric-line-val.is-exempt {
  color: var(--primary);
}

.metric-line-val.is-tax {
  color: var(--danger-text);
}

.metric-line-val.is-positive {
  color: var(--success-text);
  font-size: 1rem;
}

/* Barra proporcional */
.breakdown-bar-wrap {
  margin-bottom: 1.15rem;
}

.breakdown-bar {
  display: flex;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
}

.seg-exempt {
  background: var(--primary);
  transition: width 0.25s ease;
}

.seg-net-taxed {
  background: var(--success);
  transition: width 0.25s ease;
}

.seg-tax {
  background: var(--danger);
  transition: width 0.25s ease;
}

.breakdown-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* Tabla de reparto */
.split-table-section {
  margin-bottom: 1.1rem;
}

.split-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  -webkit-overflow-scrolling: touch;
}

.split-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.split-table th,
.split-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border-color);
  text-align: right;
  white-space: nowrap;
}

.split-table th:first-child,
.split-table td:first-child {
  text-align: left;
}

.split-table th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.75rem;
}

.split-table tbody tr:last-child td {
  border-bottom: none;
}

.split-table tr.total-row td {
  font-weight: 800;
  background: var(--bg-card);
  color: var(--text-main);
  border-top: 1px solid var(--border-color);
}

.split-table td.net-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--success-text);
}

/* Aviso bancario */
.payout-notice-box {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--warning-bg);
  border: 1px solid var(--gold-border);
  color: var(--text-main);
  font-size: 0.83rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.payout-notice-box.is-direct {
  background: var(--success-bg);
  border-color: rgba(16, 185, 129, 0.35);
}

.payout-notice-box svg {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--gold);
}

.payout-notice-box.is-direct svg {
  color: var(--success);
}

.panel-actions-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 0.65rem;
}

/* ==========================================================================
   PESTAÑA 2: CERTIFICADO DE DÉCIMO COMPARTIDO
   ========================================================================== */
.cert-form-col {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  min-width: 0;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.section-legend {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  padding: 0 0.35rem;
}

.legend-num {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--primary-light);
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cert-participants-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.cert-members-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.cert-member-card {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.9fr) minmax(82px, 0.65fr) minmax(105px, 0.75fr) auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
}

.cert-member-pct {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 0.15rem;
}

.cert-balance-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--success-bg);
  color: var(--success-text);
  font-size: 0.82rem;
  font-weight: 700;
}

.cert-balance-bar.is-mismatch {
  background: var(--warning-bg);
  color: var(--warning-text);
}

/* Dropzone de fotografía local */
.photo-dropzone {
  border: 1.5px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  padding: 1rem;
  text-align: center;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.photo-dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.photo-drop-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.photo-drop-filled {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  text-align: left;
}

.photo-drop-filled img {
  width: 96px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.photo-drop-meta {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  flex: 1;
}

.photo-drop-meta span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.photo-drop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* Lienzo de firma */
.signature-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.signature-pad-wrap {
  position: relative;
  width: 100%;
  height: 120px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  touch-action: none;
}

.signature-pad-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.signature-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.84rem;
  pointer-events: none;
}

/* Vista previa del documento */
.cert-preview-col {
  position: sticky;
  top: 76px;
  min-width: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.preview-toolbar-title {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text-main);
}

.preview-badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--gold-bg);
  color: var(--gold-text);
  border: 1px solid var(--gold-border);
}

.paper-viewport {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

/* Hoja de certificado siempre con fondo papel claro para máxima legibilidad */
.cert-sheet {
  background: #ffffff;
  color: #0f172a;
  padding: clamp(1rem, 2.2vw, 1.5rem);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.82rem;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.cert-doc-header {
  border: 2px solid #991b1b;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, #fffbeb 0%, #fef2f2 100%);
  margin-bottom: 0.9rem;
}

.cert-doc-kicker {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #991b1b;
  margin-bottom: 0.2rem;
}

.cert-doc-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.08rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 0.6rem;
}

.cert-doc-ticket-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid #fecaca;
}

.cert-ticket-stat-label {
  display: block;
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  white-space: nowrap;
}

.cert-ticket-stat-val {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.84rem;
  font-weight: 800;
  color: #0f172a;
  white-space: nowrap;
}

.cert-ticket-stat-val.is-number {
  font-size: 1.08rem;
  color: #991b1b;
  letter-spacing: 0.06em;
}

.cert-doc-block {
  margin-bottom: 0.8rem;
}

.cert-doc-block h4 {
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #334155;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.25rem;
  margin-bottom: 0.45rem;
}

.cert-doc-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.cert-doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.77rem;
}

.cert-doc-table th,
.cert-doc-table td {
  padding: 0.42rem 0.5rem;
  border: 1px solid #cbd5e1;
  text-align: left;
}

.cert-doc-table th {
  background: #f1f5f9;
  font-weight: 700;
  color: #0f172a;
}

.cert-doc-table td.num,
.cert-doc-table th.num {
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

.cert-doc-photo-box {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.5rem;
  background: #f8fafc;
  text-align: center;
  margin-bottom: 0.8rem;
}

.cert-doc-photo-box img {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 4px;
}

.cert-doc-photo-caption {
  font-size: 0.7rem;
  color: #64748b;
  margin-top: 0.25rem;
}

.cert-doc-clause {
  font-size: 0.75rem;
  color: #334155;
  background: #f8fafc;
  border-left: 3px solid #b45309;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.85rem;
}

.cert-doc-sig-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  align-items: end;
  padding-top: 0.5rem;
  border-top: 1px dashed #cbd5e1;
}

.cert-doc-sig-box {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.5rem;
  text-align: center;
  min-height: 76px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.cert-doc-sig-box img {
  max-height: 46px;
  max-width: 100%;
  object-fit: contain;
  margin: 0.2rem auto;
}

.cert-doc-sig-empty {
  color: #94a3b8;
  font-size: 0.72rem;
  padding: 0.75rem 0;
}

.cert-doc-meta-foot {
  font-size: 0.7rem;
  color: #64748b;
  line-height: 1.45;
}

.export-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.export-secondary-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.legal-disclaimer-mini {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Modal accesible */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
}

.modal-backdrop.is-open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.95rem 1.2rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.05rem;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  min-width: 36px;
  min-height: 36px;
}

.modal-body {
  padding: 1.1rem 1.2rem;
  color: var(--text-main);
  font-size: 0.92rem;
  line-height: 1.55;
}

.modal-body ul {
  margin: 0.5rem 0 0 1.2rem;
}

.modal-footer {
  padding: 0.85rem 1.2rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Toast banner */
.toast-banner {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid var(--primary);
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 10000;
  max-width: calc(100vw - 2rem);
  text-align: center;
}

.toast-banner.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Contenedor de impresión A4 (oculto en pantalla) */
.print-only {
  display: none;
}

/* ==========================================================================
   RESPONSIVE TABLET Y MÓVIL
   ========================================================================== */
@media (max-width: 980px) {
  .calc-grid,
  .cert-workspace {
    grid-template-columns: 1fr;
  }

  .cert-preview-col {
    position: static;
  }
}

@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }

  .mode-tabs {
    grid-template-columns: 1fr;
  }

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .segmented-toggle {
    grid-template-columns: 1fr;
  }

  .custom-participant-row {
    grid-template-columns: 1fr 1fr;
  }

  .custom-participant-row input[data-field="name"] {
    grid-column: 1 / -1;
  }

  .cert-member-card {
    grid-template-columns: 1fr 1fr;
  }

  .cert-member-card input[data-field="name"] {
    grid-column: 1 / -1;
  }

  .cert-doc-ticket-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cert-doc-sig-grid {
    grid-template-columns: 1fr;
  }

  .panel-actions-row,
  .export-secondary-row {
    grid-template-columns: 1fr;
  }

  .quick-bar-btns,
  .quick-bar-btns button,
  .btn-primary,
  .btn-secondary {
    width: 100%;
  }

  .photo-drop-filled {
    flex-direction: column;
    text-align: center;
  }

  .metric-line {
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
  }

  .metric-line-val {
    white-space: normal;
    text-align: left;
  }
}

/* ==========================================================================
   IMPRESIÓN / GUARDAR COMO PDF A4 LIMPIO
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  html,
  body {
    background: #ffffff !important;
    color: #0f172a !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    min-height: 0 !important;
    display: block !important;
  }

  body > *:not(#print-certificate-mount) {
    display: none !important;
  }

  #print-certificate-mount {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #print-certificate-mount .cert-sheet {
    padding: 0;
    border: none;
    font-size: 10pt;
    line-height: 1.45;
  }

  #print-certificate-mount .cert-doc-photo-box img {
    max-height: 62mm;
  }
}
