/* C21 CAM Grupo — estilos compartidos de la calculadora pública y el panel directivo. */

@font-face {
  font-family: 'Typold';
  src: url('../fonts/Typold-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Typold';
  src: url('../fonts/Typold-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --gold: #beaf87;
  --gold-strong: #8f7f55;
  --gold-soft: rgba(190, 175, 135, 0.14);
  --ink: #1d1d1f;
  --ink-2: #2a2a2c;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #a1a1a6;
  --line: #e8e6e1;
  --surface: #ffffff;
  --surface-2: #f7f6f3;
  --bg: #f3f2ee;
  --danger: #c4453c;
  --ok: #2f7d4f;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 32px -12px rgba(0, 0, 0, 0.12);
  --font: 'Typold', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* Colores del reparto */
  --c-royalty: #9a9a9f;
  --c-agent: #beaf87;
  --c-partners: #7c6a43;
  --c-group: #2a2a2c;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

::selection {
  background: var(--gold);
  color: #fff;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.gold {
  color: var(--gold-strong);
}

.muted {
  color: var(--muted);
}

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

.stack > * + * {
  margin-top: 16px;
}

/* ---------- Layout ---------- */

.page-center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand-header {
  text-align: center;
  padding: 32px 24px 8px;
}

.brand-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-header p {
  font-size: 14px;
  margin-top: 4px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 14px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--gold);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.45);
  text-decoration: none;
}

.brand-mark.sm {
  width: 36px;
  height: 36px;
  margin: 0;
  border-radius: 10px;
  font-size: 15px;
}

/* ---------- Formularios ---------- */

.field label,
.label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.15s;
}

.field:focus-within > label {
  color: var(--gold-strong);
}

.input,
.field input,
.field select {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  font-size: 17px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  appearance: none;
}

.field select {
  font-size: 15px;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236e6e73' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.field input:focus,
.field select:focus {
  border-color: var(--gold);
  background-color: var(--surface);
  box-shadow: 0 0 0 4px var(--gold-soft);
}

.field input::placeholder {
  color: var(--faint);
  font-weight: 400;
}

.affix {
  position: relative;
}

.affix > span {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  color: var(--faint);
  font-weight: 700;
  pointer-events: none;
}

.affix .prefix {
  left: 14px;
}

.affix .suffix {
  right: 14px;
}

.affix input.has-prefix {
  padding-left: 30px;
}

.affix input.has-suffix {
  padding-right: 34px;
}

.hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.hint.warn {
  color: var(--danger);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Control segmentado (radio buttons) */
.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.segmented legend {
  padding: 0;
}

.segmented label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 6px 8px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.segmented label small {
  display: block;
  font-weight: 400;
  font-size: 12px;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--gold);
}

fieldset.field-set {
  border: 0;
  margin-inline: 0;
  margin-bottom: 0;
  padding: 0;
  min-width: 0;
}

fieldset.field-set > legend {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.chip:hover {
  border-color: var(--gold);
  color: var(--text);
}

.chip[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--gold);
}

/* Slider */
input[type='range'] {
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--gold) var(--fill, 50%), var(--line) var(--fill, 50%));
}

input[type='range']::-moz-range-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--gold) var(--fill, 50%), var(--line) var(--fill, 50%));
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--gold);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

input[type='range']::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--gold);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary {
  width: 100%;
  background: var(--ink);
  color: #fff;
}

.btn-primary:hover {
  background: var(--ink-2);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--gold);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(196, 69, 60, 0.08);
  color: var(--danger);
  font-size: 14px;
}

/* Panel oscuro de resultados */
.result-panel {
  position: relative;
  overflow: hidden;
  padding: 22px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--ink) 0%, #34343a 100%);
  color: #fff;
}

.result-panel::after {
  content: '';
  position: absolute;
  top: -48px;
  right: -48px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.12;
  filter: blur(36px);
  pointer-events: none;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.72);
}

.result-row + .result-row {
  margin-top: 8px;
}

.result-row .neg {
  color: #f0a39c;
}

.result-divider {
  height: 1px;
  margin: 16px 0;
  background: rgba(255, 255, 255, 0.1);
}

.result-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.result-big {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 4px;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.result-big small {
  font-size: 14px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
}

.result-note {
  margin-top: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
}

details.explainer {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  font-size: 14px;
}

details.explainer summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--muted);
  list-style: none;
}

details.explainer summary::-webkit-details-marker {
  display: none;
}

details.explainer summary::before {
  content: '+';
  display: inline-block;
  width: 18px;
  color: var(--gold-strong);
}

details.explainer[open] summary::before {
  content: '−';
}

details.explainer ol {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
}

details.explainer li + li {
  margin-top: 4px;
}

.fine-print {
  font-size: 12px;
  line-height: 1.55;
  color: var(--faint);
  text-align: center;
}

.back-link {
  display: block;
  margin-top: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--gold-strong);
}

/* ---------- Calculadora pública ---------- */

.public {
  max-width: 440px;
  overflow: hidden;
}

.public .body {
  padding: 16px 24px 24px;
}

.public footer {
  padding: 14px;
  text-align: center;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
}

.public footer a {
  color: var(--muted);
  text-decoration: none;
}

.public footer a:hover {
  color: var(--gold-strong);
}

.public footer strong {
  color: var(--text);
}

.promo {
  display: block;
  width: 100%;
  max-width: 440px;
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: 14px;
  text-align: center;
  text-decoration: none;
  color: var(--faint);
  font-size: 13px;
  transition: background 0.15s;
}

.promo:hover {
  background: rgba(255, 255, 255, 0.6);
}

.promo strong {
  color: var(--muted);
}

.promo:hover strong {
  color: var(--gold-strong);
}

.promo p {
  margin-top: 4px;
  font-size: 12px;
}

.login {
  max-width: 400px;
  padding-bottom: 28px;
}

.login form {
  padding: 16px 28px 0;
}

/* ---------- Panel directivo ---------- */

.admin {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(243, 242, 238, 0.86);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 16px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.15;
}

.topbar-title small {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.05);
}

.tabs button {
  white-space: nowrap;
  min-height: 34px;
  padding: 4px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

.tabs button[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.tab-badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 99px;
  font-size: 11px;
  line-height: 18px;
  background: var(--ok);
  color: #fff;
}

.tab-badge.fail {
  background: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.controls {
  position: sticky;
  top: 80px;
  padding: 22px;
}

.controls h2,
.section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.controls details {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.controls details summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.controls details[open] summary {
  margin-bottom: 14px;
}

.split-readout {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 14px;
  color: var(--muted);
}

.split-readout strong {
  color: var(--text);
}

.results > * + * {
  margin-top: 20px;
}

.section {
  padding: 22px;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 16px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 20px;
  align-items: end;
}

.hero-meta {
  display: grid;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Barra de reparto */
.fill-royalty {
  background: var(--c-royalty);
}

.fill-agent {
  background: var(--c-agent);
}

.fill-partners {
  background: var(--c-partners);
}

.fill-group {
  background: var(--c-group);
}

.dist-bar {
  display: flex;
  height: 14px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--line);
  gap: 2px;
}

.dist-bar span {
  display: block;
  min-width: 2px;
  transition: flex-grow 0.3s ease;
}

.recipients {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.recipient {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.recipient-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.recipient-amount {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.recipient-sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

/* Tabla */
.table-wrap {
  overflow-x: auto;
  margin: 0 -22px;
  padding: 0 22px;
}

table.ledger {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 14px;
}

.ledger th,
.ledger td {
  padding: 10px 8px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.ledger th:first-child,
.ledger td:first-child {
  text-align: left;
  padding-left: 0;
  white-space: normal;
}

.ledger th:last-child,
.ledger td:last-child {
  padding-right: 0;
}

.ledger thead th {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.ledger .group-row td {
  font-weight: 700;
}

.ledger .sub-row td {
  color: var(--muted);
}

.ledger .sub-row td:first-child {
  padding-left: 22px;
}

.ledger .total-row td {
  font-weight: 700;
  border-bottom: 0;
  border-top: 2px solid var(--text);
}

.ledger .pct {
  color: var(--muted);
}

.ledger .name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.print-toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: -6px 0 12px;
}

.footnote {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

/* Flujo de IVA */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.flow {
  margin: 0;
  font-size: 14px;
}

.flow div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.flow dt {
  color: var(--muted);
}

.flow dd {
  margin: 0;
  font-weight: 700;
  white-space: nowrap;
}

.flow .flow-total {
  border-bottom: 0;
  border-top: 2px solid var(--text);
}

.flow .flow-total dt {
  color: var(--text);
  font-weight: 700;
}

.steps {
  margin: 14px 0 0;
  padding-left: 20px;
  font-size: 14px;
  color: var(--muted);
}

.steps li + li {
  margin-top: 8px;
}

.steps strong {
  color: var(--text);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.status.ok {
  color: var(--ok);
}

.status.fail {
  color: var(--danger);
}

.status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

/* Pruebas */
.tests-view {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.test-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.test-summary h2 {
  font-size: 22px;
}

.test-group {
  margin-top: 20px;
}

.test-group h3 {
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.test-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}

.test-list li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  font-size: 14px;
}

.test-list li + li {
  border-top: 1px solid var(--line);
}

.test-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--ok);
}

.test-list li.fail .test-icon {
  background: var(--danger);
}

.test-error {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: var(--danger);
  word-break: break-word;
}

.test-ms {
  font-size: 12px;
  color: var(--faint);
}

.print-only {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .recipients {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .controls {
    position: static;
  }

  .hero,
  .two-col {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 560px) {
  .topbar-title > div {
    display: none;
  }

  .tabs button {
    padding: 4px 10px;
  }

  .topbar-inner {
    gap: 10px;
  }

  .logout-label {
    display: none;
  }

  .section,
  .controls {
    padding: 18px;
  }

  .table-wrap {
    margin: 0 -18px;
    padding: 0 18px;
  }

  .recipient-amount {
    font-size: 19px;
  }

  .result-big {
    font-size: 30px;
  }

  .public .body {
    padding: 12px 18px 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- Impresión (PDF del desglose) ---------- */

@media print {
  @page {
    margin: 14mm;
  }

  body {
    background: #fff;
    font-size: 12px;
  }

  .topbar,
  .controls,
  .actions,
  .no-print {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .card {
    box-shadow: none;
    border-color: #ddd;
    break-inside: avoid;
  }

  .result-panel {
    background: #fff;
    color: var(--text);
    border: 1px solid #ddd;
  }

  .result-panel::after {
    display: none;
  }

  .result-row,
  .result-big small,
  .result-note {
    color: var(--muted);
  }

  .result-kicker {
    color: var(--gold-strong);
  }

  .dist-bar,
  .swatch {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

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

  .two-col {
    grid-template-columns: 1fr 1fr;
  }

  table.ledger {
    min-width: 0;
  }

  body.hide-partners .partners-detail {
    display: none !important;
  }
}
