/* =========================================================================
   FerSaSoft Acreditaciones — Design System (shadcn / 21st.dev aesthetic)
   Inter + paleta neutra refinada · acento gradiente indigo→violeta
   ========================================================================= */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --ink: #14151a;
  --ink-soft: #383b46;
  --muted: #6b7080;
  --muted-2: #9aa0b0;
  --line: #ebecf2;
  --line-strong: #dfe1ea;

  --brand: #6d5efc;
  --brand-2: #a855f7;
  --brand-ink: #5b4ee6;
  --brand-tint: #f1effe;
  --brand-grad: linear-gradient(135deg, #6d5efc 0%, #a855f7 100%);

  --green: #059669;
  --green-tint: #e7f7f0;
  --red: #e11d48;
  --red-tint: #fdeaef;
  --amber: #d97706;
  --amber-tint: #fdf2e3;
  --blue: #2563eb;
  --blue-tint: #e8f0fe;

  --radius: 16px;
  --radius-sm: 11px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(16,18,32,.04), 0 1px 3px rgba(16,18,32,.05);
  --shadow: 0 1px 2px rgba(16,18,32,.04), 0 6px 20px -6px rgba(16,18,32,.12);
  --shadow-lg: 0 12px 40px -12px rgba(16,18,32,.22);
  --ring: 0 0 0 3px rgba(109,94,252,.22);

  --t: 160ms cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv02","cv11","ss01";
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}
a { color: var(--brand-ink); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--brand); }
::selection { background: rgba(109,94,252,.18); }
h1, h2, h3 { letter-spacing: -0.02em; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 252px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  font-size: 1.18rem; font-weight: 800; color: var(--ink);
  margin: 4px 6px 22px; display: flex; align-items: center; gap: 9px;
  letter-spacing: -0.03em;
}
.brand small {
  display: block; font-weight: 500; font-size: .7rem; color: var(--muted-2);
  letter-spacing: 0; margin-top: 1px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .9rem; font-weight: 500;
  transition: background var(--t), color var(--t);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--brand-tint); color: var(--brand-ink); font-weight: 600; }
.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted-2); font-weight: 700; margin: 14px 12px 4px;
}
.sidebar .spacer { flex: 1; }
.sidebar .user-box {
  border-top: 1px solid var(--line); padding-top: 14px; margin-top: 8px;
  display: flex; flex-direction: column; gap: 5px;
}
.user-name { font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.logout-link { font-size: .8rem; color: var(--muted-2); }
.logout-link:hover { color: var(--red); }

.content { flex: 1; padding: 30px 38px; max-width: 1240px; width: 100%; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-head h1 { font-size: 1.6rem; margin: 0; font-weight: 700; }
.muted { color: var(--muted); }
.crumb { font-size: .82rem; color: var(--muted-2); margin-bottom: 4px; }

.flash {
  background: var(--green-tint); color: var(--green); padding: 11px 16px;
  border-radius: var(--radius-sm); font-size: .88rem; margin-bottom: 18px; font-weight: 500;
  border: 1px solid #bfe8d6;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--brand-grad); color: #fff; border: 0; cursor: pointer;
  padding: 10px 17px; border-radius: var(--radius-sm); font-size: .88rem; font-weight: 600;
  font-family: inherit; letter-spacing: -0.01em;
  box-shadow: 0 1px 2px rgba(91,78,230,.25), 0 4px 12px -4px rgba(91,78,230,.45);
  transition: transform var(--t), box-shadow var(--t), background var(--t), filter var(--t);
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.secondary {
  background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-sm);
}
.btn.secondary:hover { background: var(--surface-2); color: var(--ink); filter: none; }
.btn.danger { background: var(--red); box-shadow: 0 1px 2px rgba(225,29,72,.25), 0 4px 12px -4px rgba(225,29,72,.45); }
.btn.small { padding: 6px 11px; font-size: .8rem; border-radius: 9px; }

/* ---------- Cards / grids ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm); transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: var(--line-strong); }
.event-card { border-left: 4px solid var(--brand); display: block; }
.event-card h3 { margin: 0 0 6px; font-size: 1.1rem; }
.event-card .meta { font-size: .82rem; color: var(--muted); }
.event-card .counts { margin-top: 12px; display: flex; gap: 14px; font-size: .8rem; color: var(--muted-2); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 18px; margin-bottom: 26px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.stat .label { font-size: .76rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }

.section {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-sm); margin-bottom: 22px;
}
.section h2 { font-size: 1.02rem; margin: 0 0 16px; font-weight: 700; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); }
th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2);
  font-weight: 600; border-bottom: 1px solid var(--line-strong);
}
tbody tr { transition: background var(--t); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.tag {
  display: inline-block; padding: 3px 10px; border-radius: var(--radius-pill); font-size: .72rem; font-weight: 600;
  color: #fff;
}

/* ---------- Forms ---------- */
.form-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; box-shadow: var(--shadow-sm); max-width: 640px;
}
.field { margin-bottom: 17px; }
.field label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 7px; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: .92rem;
  background: var(--surface); color: var(--ink); font-family: inherit;
  transition: border-color var(--t), box-shadow var(--t);
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted-2); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.field input[type="color"] { padding: 4px; height: 42px; cursor: pointer; }
.field small { display: block; margin-top: 5px; font-size: .78rem; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.inline-form { display: flex; gap: 13px; align-items: end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(1100px 600px at 12% -8%, rgba(109,94,252,.22), transparent 60%),
    radial-gradient(900px 600px at 100% 110%, rgba(168,85,247,.20), transparent 55%),
    #0e1018;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 40px;
  width: 100%; max-width: 408px; box-shadow: var(--shadow-lg);
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.03em; }
.auth-card .sub { color: var(--muted); font-size: .9rem; margin-bottom: 26px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: .92rem; margin-top: 4px; }
.auth-switch { text-align: center; margin-top: 20px; font-size: .88rem; color: var(--muted); }
.error { background: var(--red-tint); color: var(--red); padding: 11px 15px; border-radius: var(--radius-sm); font-size: .86rem; margin-bottom: 18px; font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 44px 20px; font-size: .92rem; }

/* ---------- Matriz de accesos (cargos × zonas) ---------- */
.matrix { overflow-x: auto; }
.matrix table { font-size: .85rem; }
.matrix th.zone-col { text-align: center; font-size: .68rem; }
.matrix td.cell { text-align: center; }
.matrix td.role-name { font-weight: 600; white-space: nowrap; }
.matrix input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--brand); }
.role-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }

/* ---------- Avatar / fotos ---------- */
.avatar { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; }
.thumb { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; text-align: center; background: var(--surface-2); }
.thumb img { max-width: 100%; max-height: 80px; object-fit: contain; }
.thumb .tname { font-size: .75rem; margin-top: 6px; color: var(--muted); word-break: break-word; }

/* ---------- Galería de presets ---------- */
.preset-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 8px; }
.preset-card h3 { margin: 4px 0 0; font-size: 1rem; }
.preset-card .btn { margin-top: auto; justify-content: center; }
.preset-thumb { height: 120px; border-radius: var(--radius-sm); display: flex; align-items: flex-end; justify-content: center; padding: 8px; color: #fff; position: relative; overflow: hidden; }
.preset-thumb span { font-size: .7rem; background: rgba(0,0,0,.35); padding: 2px 8px; border-radius: 999px; }
.preset-blanco { background: repeating-linear-gradient(45deg, #f0f0f4, #f0f0f4 8px, #e6e6ee 8px, #e6e6ee 16px); color: #888; }
.preset-deportivo { background: linear-gradient(160deg, #a9dce3, #1d3a8a); }
.preset-congreso { background: linear-gradient(160deg, #5b4ee6, #a855f7); }
.preset-prensa { background: linear-gradient(160deg, #e11d48, #14151a); }
.preset-cr80 { background: linear-gradient(160deg, #5b4ee6, #2563eb); }
.preset-vip { background: linear-gradient(160deg, #1a1a22, #c9a227); }

/* ---------- Editor WYSIWYG ---------- */
.designer { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.designer-stage-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.designer-tabs { display: flex; gap: 6px; }
.designer-tabs button {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft);
  padding: 7px 16px; border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; font-weight: 600; font-size: .85rem;
}
.designer-tabs button.active { background: var(--brand-tint); color: var(--brand-ink); border-color: var(--brand); }
.stage {
  position: relative; background: #fff; box-shadow: var(--shadow);
  background-size: cover; background-position: center; overflow: hidden;
  border: 1px solid var(--line-strong);
}
.el {
  position: absolute; box-sizing: border-box; cursor: move; min-width: 12px; min-height: 12px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  outline: 1px dashed rgba(109,94,252,.45);
}
.el.selected { outline: 2px solid var(--brand); z-index: 50; }
.el .handle {
  position: absolute; right: -6px; bottom: -6px; width: 13px; height: 13px;
  background: var(--brand); border: 2px solid #fff; border-radius: 50%; cursor: nwse-resize;
}
.el-photo { background: rgba(109,94,252,.10); }
.el-qr { background: rgba(0,0,0,.06); }
.el-zones .zone-num {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #fff; color: #111; font-weight: 700; border: 1px solid #ccc;
}
.designer-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm); position: sticky; top: 20px;
}
.designer-panel h3 { font-size: .92rem; margin: 0 0 12px; }
.add-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.add-tools button { font-size: .78rem; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface-2); cursor: pointer; font-family: inherit; }
.add-tools button:hover { background: var(--brand-tint); border-color: var(--brand); }
.panel-field { margin-bottom: 11px; }
.panel-field label { display: block; font-size: .76rem; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.panel-field input, .panel-field select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 8px; font-size: .82rem;
  background: var(--surface); color: var(--ink); font-family: inherit;
}
.panel-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Mobile ---------- */
@media (max-width: 980px) {
  .designer { grid-template-columns: 1fr; }
  .designer-panel { position: static; }
}
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 10px 14px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); overflow: visible;
  }
  .brand { margin: 0 auto 0 0; font-size: 1.05rem; }
  .brand small { display: none; }
  .sidebar .spacer, .sidebar .user-box { display: none; }
  .nav {
    order: 2; width: 100%; flex-direction: row; flex-wrap: nowrap; gap: 4px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: 0 0 auto; white-space: nowrap; padding: 8px 12px; font-size: .85rem; }
  .nav-section { display: none; }
  .sidebar .theme-toggle { order: 1; width: auto; margin: 0; padding: 7px 11px; font-size: .8rem; }
  .content { padding: 16px; }
  .field-row { grid-template-columns: 1fr; }
  .section:has(> table), .matrix { overflow-x: auto; }
  .inline-form { flex-direction: column; align-items: stretch; gap: 12px; }
  .inline-form .field input, .inline-form .field select { width: 100%; }
  .inline-form .btn { width: 100%; justify-content: center; }
}

/* ---------- Toggle de tema ---------- */
.theme-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: .85rem; font-weight: 500;
  font-family: inherit; cursor: pointer; margin-bottom: 8px; transition: all var(--t);
}
.theme-toggle:hover { background: var(--brand-tint); color: var(--brand-ink); border-color: var(--brand-tint); }

/* ---------- Modo oscuro ---------- */
:root[data-theme="dark"] {
  --bg: #0e0f15;
  --surface: #181a23;
  --surface-2: #1f222c;
  --ink: #eceef5;
  --ink-soft: #c4c8d4;
  --muted: #9499a8;
  --muted-2: #6b7080;
  --line: #272a36;
  --line-strong: #343847;
  --brand-tint: #221f3d;
  --green: #34d399;
  --green-tint: #10271f;
  --red: #fb7185;
  --red-tint: #2c1620;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -8px rgba(0,0,0,.5);
  --shadow-lg: 0 16px 50px -12px rgba(0,0,0,.7);
}
:root[data-theme="dark"] body { background: var(--bg); }
:root[data-theme="dark"] .field input[type="color"] { background: var(--surface); }
