:root {
  --ink: #12203A;
  --ink-light: #2A3F63;
  --paper: #F5F6F3;
  --card: #FFFFFF;
  --line: #E1E4DD;
  --text: #1B2430;
  --text-muted: #667085;
  --gold: #D8A248;
  --teal: #2F6F62;
  --danger: #B3261E;
  --danger-bg: #FBEAE9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* ---------- auth pages (login/register) ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
}
.auth-wordmark {
  font-family: Georgia, serif;
  font-style: italic;
  font-weight: 600;
  font-size: 24px;
  margin-bottom: 4px;
}
.auth-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-foot { margin-top: 20px; font-size: 14px; color: var(--text-muted); text-align: center; }
.auth-foot a { color: var(--ink); font-weight: 600; text-decoration: none; }

/* ---------- form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--ink); outline-offset: 1px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 10px; padding: 12px 18px;
  font-size: 14.5px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-light); }
.btn-outline { background: #fff; border: 1.5px solid var(--line); color: var(--text); }
.btn-outline:hover { border-color: var(--ink); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1.5px solid var(--danger-bg); }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: 0.6; cursor: default; }

.error-msg {
  background: var(--danger-bg); color: var(--danger);
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
}
.success-msg {
  background: rgba(47,111,98,0.12); color: var(--teal);
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
}

/* ---------- app shell ---------- */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .container {
  height: 64px; display: flex; align-items: center; justify-content: space-between;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-wordmark { font-family: Georgia, serif; font-style: italic; font-weight: 600; font-size: 19px; }
.topbar-business { font-size: 13.5px; color: var(--text-muted); border-left: 1px solid var(--line); padding-left: 10px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.page { padding: 36px 0 64px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 28px; flex-wrap: wrap;
}
.page-head h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
.page-head p { color: var(--text-muted); font-size: 14.5px; margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-muted); text-decoration: none; margin-bottom: 16px; }
.back-link:hover { color: var(--ink); }

/* ---------- summary cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
@media (max-width: 800px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px;
}
.stat-card .label { font-size: 12.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.stat-card .value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- coupon table ---------- */
.table-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
thead th {
  text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-muted); padding: 14px 18px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(18,32,58,0.02); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
}
.badge-active { background: rgba(47,111,98,0.14); color: var(--teal); }
.badge-expired { background: rgba(179,38,30,0.1); color: var(--danger); }
.badge-inactive { background: #EEF0EA; color: var(--text-muted); }

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

.empty-state {
  text-align: center; padding: 60px 24px; color: var(--text-muted);
}

/* ---------- create/edit panel ---------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; margin-bottom: 28px;
}
.panel h2 { font-size: 17px; margin: 0 0 16px; }
.panel .field { margin-bottom: 14px; }

/* ---------- coupon detail ---------- */
.detail-layout { display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; align-items: start; }
@media (max-width: 860px) { .detail-layout { grid-template-columns: 1fr; } }

.share-box {
  display: flex; gap: 8px; align-items: center; background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 6px;
}
.share-box input {
  flex: 1; border: none; background: transparent; font-size: 13.5px; color: var(--text-muted);
  font-family: ui-monospace, monospace;
}
.share-box input:focus { outline: none; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: background 0.15s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.15s;
}
.switch input:checked + .slider { background: var(--teal); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.loading-text { color: var(--text-muted); padding: 40px 0; text-align: center; }

/* ---------- generador de imágenes con IA ---------- */
.ai-image-section {
  border: 1px dashed var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px;
}
.ai-image-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ai-image-head p { font-size: 13px; color: var(--text-muted); margin: 4px 0 0; }
.btn-ai {
  background: var(--ink); color: #fff; border: none; border-radius: 10px;
  padding: 10px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-ai:hover { background: var(--ink-light); }
.btn-ai:disabled { opacity: 0.6; cursor: default; }

.ai-image-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px;
}
@media (max-width: 560px) { .ai-image-grid { grid-template-columns: repeat(2, 1fr); } }
.ai-image-option {
  position: relative; border-radius: 10px; overflow: hidden; cursor: pointer;
  border: 2px solid transparent; aspect-ratio: 1; background: var(--paper);
}
.ai-image-option img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-image-option.selected { border-color: var(--gold); }
.ai-image-option.selected::after {
  content: "✓"; position: absolute; top: 6px; right: 6px; width: 22px; height: 22px;
  background: var(--gold); color: var(--ink); border-radius: 50%; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.pass-preview {
  width: 260px; border-radius: 16px; padding: 18px; margin-top: 14px;
  background: linear-gradient(165deg, var(--ink-light), var(--ink));
  background-size: cover; background-position: center;
  color: #fff; position: relative; overflow: hidden;
}
.pass-preview::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(165deg, rgba(18,32,58,0.55), rgba(18,32,58,0.85));
}
.pass-preview > * { position: relative; z-index: 1; }
.pass-preview .pp-label {
  font-family: ui-monospace, monospace; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  opacity: 0.75; margin-bottom: 6px;
}
.pass-preview .pp-discount { font-size: 26px; font-weight: 700; margin-bottom: 4px; }
.pass-preview .pp-title { font-size: 13px; opacity: 0.9; }
