:root {
  --ink: #1b2330;
  --muted: #63707f;
  --paper: #ffffff;
  --canvas: #eef2f7;
  --line: #d6dde6;
  --primary: #1f5fbf;
  --primary-dark: #16478f;
  --green: #1f7a4d;
  --green-soft: #e4f4ea;
  --red: #b3261e;
  --red-soft: #fbeae9;
  --yellow: #8a5a06;
  --yellow-soft: #fff2d6;
  --gray-soft: #e7ecf2;
  --shadow: 0 12px 36px rgba(20, 40, 70, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(31, 95, 191, 0.10), transparent 30rem),
    var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--primary-dark); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0.4rem; font-size: clamp(1.6rem, 5vw, 2.3rem); line-height: 1.1; }
h2 { margin-bottom: 0; font-size: 1.1rem; }
small { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 1rem; }

.topbar {
  min-height: 64px;
  padding: 0.7rem max(1rem, calc((100vw - 1180px) / 2));
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  color: white; background: #16233a;
}
.brand { display: flex; align-items: center; gap: 0.65rem; color: white; text-decoration: none; font-weight: 800; }
.brand-logo { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: #fff; }
.user-menu { display: flex; align-items: center; gap: 0.75rem; }
.user-menu form { margin: 0; }
.user-name { font-size: 0.85rem; color: #c9d6ea; }
.user-menu .link-button { color: #a9c6f5; }

.nav-tabs {
  display: flex; gap: 0.35rem;
  padding: 0.6rem max(1rem, calc((100vw - 1180px) / 2));
  overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs a { flex: 0 0 auto; padding: 0.5rem 0.8rem; border-radius: 999px; color: #40506a; text-decoration: none; font-size: 0.9rem; font-weight: 700; }
.nav-tabs a:hover { background: #e8eef6; }

.container { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.footer { display: flex; justify-content: space-between; gap: 1rem; width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 1.5rem 0 2.5rem; color: var(--muted); border-top: 1px solid var(--line); font-size: 0.8rem; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.4rem; }
.eyebrow { margin-bottom: 0.4rem; color: var(--primary); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.72rem; font-weight: 900; }

.panel, .auth-card, .metric-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel { padding: 1.25rem; margin-bottom: 1.25rem; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.panel-danger { border-color: #e7b6b0; }
.auth-card { width: min(460px, 100%); margin: 5vh auto; padding: clamp(1.4rem, 5vw, 2.4rem); }
.auth-card p { color: var(--muted); }
.error-card { text-align: center; }
.error-symbol { display: grid; width: 64px; height: 64px; place-items: center; margin: 0 auto 1rem; border-radius: 50%; color: white; background: var(--red); font-size: 2rem; font-weight: 900; }

.form-stack { display: grid; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: grid; gap: 0.4rem; color: #40506a; font-size: 0.86rem; font-weight: 700; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 0.7rem 0.8rem;
  color: var(--ink); background: white; border: 1px solid #c3cedb; border-radius: 11px; outline: none;
}
textarea { resize: vertical; min-height: auto; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.14); }
.check-label { display: flex; align-items: center; gap: 0.6rem; min-height: 46px; }
.check-label input { width: 20px; min-height: 20px; }

.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; padding: 0.65rem 1.05rem; border: 1px solid transparent; border-radius: 11px;
  text-decoration: none; font-weight: 800; cursor: pointer;
}
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button-primary { color: white; background: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: #33455f; background: #e8eef6; border-color: #cdd9e7; }
.button-danger { color: white; background: var(--red); }
.button-large { min-height: 52px; }
.link-button { padding: 0; border: 0; color: var(--primary-dark); background: transparent; font-weight: 800; cursor: pointer; }
.icon-button { width: 42px; height: 46px; border: 0; border-radius: 11px; color: var(--red); background: var(--red-soft); font-size: 1.4rem; line-height: 1; cursor: pointer; }

.alert { margin-bottom: 1rem; padding: 0.9rem 1rem; border-radius: 12px; font-weight: 700; }
.alert-success { color: var(--green); background: var(--green-soft); border: 1px solid #b7dbc4; }
.alert-error { color: var(--red); background: var(--red-soft); border: 1px solid #e8baba; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.metric-card { display: grid; gap: 0.25rem; padding: 1.2rem; }
.metric-card span { color: var(--muted); font-size: 0.86rem; font-weight: 700; }
.metric-card strong { font-size: clamp(1.4rem, 4vw, 2.1rem); }
.metric-main { color: white; background: linear-gradient(135deg, #1f5fbf, #3d86e0); border-color: transparent; }
.metric-main span, .metric-main small { color: #dbe8fb; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.two-columns > .panel { min-width: 0; }
.date-filter { display: flex; gap: 0.5rem; align-items: end; }
.date-filter input { min-height: 44px; }

.badge { display: inline-flex; width: fit-content; padding: 0.25rem 0.55rem; border-radius: 999px; color: #4a5a6e; background: var(--gray-soft); font-size: 0.72rem; font-weight: 850; }
.badge-success { color: var(--green); background: var(--green-soft); }
.badge-warning { color: var(--yellow); background: var(--yellow-soft); }
.badge-danger { color: var(--red); background: var(--red-soft); }
.empty { margin: 0; padding: 1.2rem 0; color: var(--muted); text-align: center; }

.list { display: grid; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.8rem 0; border-bottom: 1px solid #eef2f7; }
.list-row:last-child { border-bottom: 0; }
.list-row > div:first-child { display: grid; }
.row-muted { opacity: 0.6; }
.row-actions { display: flex; align-items: center; gap: 0.75rem; }
.row-actions form { margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { color: var(--muted); text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
th, td { padding: 0.7rem; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
.audit-detail { font-size: 0.82rem; color: #556; max-width: 340px; word-break: break-word; }

/* ---- Filtros ---- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.25rem; }
.chip-link { padding: 0.45rem 0.85rem; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: #40506a; text-decoration: none; font-size: 0.85rem; font-weight: 700; }
.chip-link.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---- Tarjetas de pedido ---- */
.order-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.order-card { display: grid; gap: 0.6rem; padding: 1.1rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.order-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.order-card.is-void { opacity: 0.6; }
.order-card-top { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.order-card-top strong { font-size: 1rem; }
.order-card-meta { display: grid; gap: 0.15rem; color: var(--muted); font-size: 0.83rem; }

/* ---- Chips de etapa ---- */
.stage-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip { display: inline-flex; padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 800; background: var(--gray-soft); color: #5a6b7d; }
.chip-pendiente { background: var(--gray-soft); color: #5a6b7d; }
.chip-en_proceso { background: var(--yellow-soft); color: var(--yellow); }
.chip-terminado { background: var(--green-soft); color: var(--green); }

/* ---- Tablero de etapas (dashboard) ---- */
.stage-board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
.stage-tile { display: grid; gap: 0.15rem; padding: 0.9rem; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfe; }
.stage-tile .stage-name { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.stage-tile strong { font-size: 1.6rem; }

/* ---- Detalle: datos ---- */
.data-list { display: grid; gap: 0.55rem; }
.data-list > div { display: grid; grid-template-columns: 150px 1fr; gap: 0.6rem; align-items: baseline; }
.data-list span { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.money-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.money-row > div { display: grid; gap: 0.1rem; }
.money-row span { color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.money-row strong { font-size: 1.15rem; }
.saldo-pendiente strong { color: var(--red); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.25rem; }

/* ---- Flujo de etapas (detalle) ---- */
.stage-flow { display: grid; gap: 0.7rem; }
.stage-step { padding: 0.85rem; border: 1px solid var(--line); border-left: 4px solid #c3cedb; border-radius: 12px; background: #fbfcfe; }
.stage-step.stage-en_proceso { border-left-color: var(--yellow); }
.stage-step.stage-terminado { border-left-color: var(--green); }
.stage-step-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.stage-step small { display: block; margin-top: 0.3rem; color: var(--muted); }
.stage-action { margin: 0.6rem 0 0; }
.stage-action .button { width: 100%; }

/* ---- Roster ---- */
.roster-head { display: grid; grid-template-columns: 1.6fr 0.6fr 0.6fr 1.2fr 44px; gap: 0.5rem; padding: 0 0.1rem 0.4rem; color: var(--muted); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.roster-line { display: grid; grid-template-columns: 1.6fr 0.6fr 0.6fr 1.2fr 44px; gap: 0.5rem; margin-bottom: 0.5rem; align-items: center; }
.roster-line input { min-height: 44px; }
.order-form .panel { margin-bottom: 1.25rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.7rem; }

@media (max-width: 850px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-columns { grid-template-columns: 1fr; }
  .form-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .container { width: min(100% - 1rem, 1180px); padding-top: 1.2rem; }
  .topbar { padding-inline: 0.75rem; }
  .brand > span:last-child, .user-name { display: none; }
  .nav-tabs { padding-inline: 0.5rem; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .data-list > div { grid-template-columns: 1fr; gap: 0.1rem; }
  .roster-head { display: none; }
  .roster-line { grid-template-columns: 1fr 1fr; gap: 0.4rem; padding: 0.7rem; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfe; }
  .roster-line input[name="player_name"] { grid-column: 1 / -1; }
  .roster-line input[name="advertising"] { grid-column: 1 / -1; }
  .roster-line .icon-button { grid-column: 2; justify-self: end; }
  .money-row { grid-template-columns: 1fr; }
  .footer { flex-direction: column; }
}
