/* Flyeapp — Estilos limpios, livianos y de alto contraste */

:root {
  color-scheme: dark;
  --bg-app: #0d0f14;
  --bg-panel: #14171f;
  --bg-card: #1b1f2a;
  --bg-card-hover: #222736;
  --bg-input: #10131a;
  --border: #272c3a;
  --border-strong: #373f52;
  --text: #f1f3f8;
  --text-muted: #98a1b5;
  --text-dim: #6e778c;
  --accent: #e13b6d;
  --accent-hover: #f04a7c;
  --accent-soft: rgba(225, 59, 109, 0.16);
  --danger: #ef4444;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --topbar-h: 56px;
  --sidebar-w: 390px;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.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;
}

/* Layout general */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* Barra superior */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 10;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 15.5px;
  user-select: none;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: block;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(200, 30, 90, 0.35);
}

.select-compact {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  outline: none;
}

.select-compact:hover, .select-compact:focus-visible {
  border-color: var(--border-strong);
}

/* Segmented controls */
.segmented {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.segmented-full {
  display: flex;
  width: 100%;
}

.segmented-full .seg-btn {
  flex: 1;
}

.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.seg-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.seg-btn.active {
  background: var(--bg-card-hover);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.seg-sub {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 11px;
}

.seg-btn.active .seg-sub {
  color: var(--text-muted);
}

/* Botones */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-ghost {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  padding: 4px 7px;
}

.btn-danger-ghost:hover {
  color: #fda4af;
  background: rgba(239, 68, 68, 0.12);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-link {
  appearance: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
}

.btn-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.icon-btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}

.icon-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Workspace 2 columnas */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 10px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 6px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.tab-panel.active {
  display: flex;
}

/* Tarjetas de grupo en sidebar */
.group-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.group-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0;
}

/* Campos y formularios */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label, .field-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.value-badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
}

.input, .textarea, .select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
}

.textarea {
  resize: vertical;
  min-height: 58px;
  line-height: 1.4;
}

.hint {
  font-size: 11.5px;
  color: var(--text-dim);
  margin: 0;
}

/* Range sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 99px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--accent);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--accent);
  cursor: pointer;
}

/* Switch toggle */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  color: var(--text);
}

.toggle input {
  appearance: none;
  width: 32px;
  height: 18px;
  border-radius: 99px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.toggle input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s, background 0.15s;
}

.toggle input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input:checked::after {
  transform: translateX(14px);
  background: #fff;
}

/* Image slots */
.image-slot-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.image-slot-card.active-slot {
  border-color: var(--accent);
}

.image-slot-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  cursor: pointer;
}

.image-slot-head:hover {
  background: rgba(255, 255, 255, 0.025);
}

.slot-thumb {
  width: 42px;
  height: 42px;
  border-radius: 5px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-dim);
}

.slot-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.slot-thumb-demo {
  background: linear-gradient(135deg, #4b122b, #1d0914 65%, #b84a39);
  color: rgba(255, 255, 255, 0.85);
  font-weight: 700;
  font-size: 10px;
}

.slot-info {
  flex: 1;
  min-width: 0;
}

.slot-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-sub {
  font-size: 11px;
  color: var(--text-dim);
}

.slot-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.image-slot-body {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: rgba(255, 255, 255, 0.015);
}

.upload-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

/* Acordeón de secciones */
.section-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}

.section-item.is-open {
  border-color: var(--border-strong);
}

.section-item.is-disabled {
  opacity: 0.62;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  user-select: none;
}

.section-title-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.section-preview {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-dim);
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-body {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(0, 0, 0, 0.14);
}

/* Paletas de colores */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.palette-chip {
  appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s;
}

.palette-chip:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.palette-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.swatch-stack {
  display: flex;
  flex-shrink: 0;
}

.swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  margin-left: -4px;
}

.swatch-dot:first-child {
  margin-left: 0;
}

.color-pickers-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
}

.color-field input[type="color"] {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
}

.color-field-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.color-field-meta span {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.2;
}

.color-field-meta code {
  font-size: 11px;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Logos en footer */
.logo-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.logo-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11.5px;
}

.logo-chip img {
  height: 22px;
  max-width: 60px;
  object-fit: contain;
}

/* Stage / Canvas preview */
.stage {
  flex: 1;
  background:
    radial-gradient(circle at 50% 25%, rgba(255, 255, 255, 0.03), transparent 60%),
    repeating-linear-gradient(45deg, #0b0d12 0 12px, #0d1016 12px 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 24px;
  min-width: 0;
  overflow: hidden;
}

.stage-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.canvas-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: calc(100% - 36px);
  border-radius: 6px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

#flyer-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 130px);
  width: auto;
  height: auto;
  cursor: grab;
  touch-action: none;
}

#flyer-canvas.is-dragging {
  cursor: grabbing;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 15, 20, 0.82);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none;
}

.canvas-frame.drag-over .drop-overlay {
  display: flex;
}

.drop-overlay-box {
  border: 2px dashed var(--accent);
  background: var(--accent-soft);
  color: #fff;
  padding: 18px 24px;
  border-radius: var(--radius);
  font-weight: 600;
  text-align: center;
}

.stage-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
}

.stage-meta {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 500;
}

.stage-tip {
  color: var(--text-dim);
}

.btn-report {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11.5px;
  padding: 5px 9px;
}

.btn-report:hover {
  color: var(--text);
}

.qr-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qr-preview-thumb {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: #ffffff;
  padding: 4px;
  border: 1px solid var(--border);
  object-fit: contain;
  flex-shrink: 0;
}

/* Modales nativos <dialog> */
.modal {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  color: var(--text);
  width: min(460px, calc(100vw - 32px));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7);
}

.modal::backdrop {
  background: rgba(6, 8, 12, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
}

.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form .input {
  flex: 1;
}

.saved-styles-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.saved-style-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.saved-style-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.saved-style-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-row {
  display: flex;
  gap: 6px;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1f2432;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 999;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive (pantallas medianas y chicas) */
@media (max-width: 960px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
  }
  .topbar-center {
    order: 3;
    width: 100%;
    display: flex;
    justify-content: center;
  }
  .app-shell {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }
  .workspace {
    flex-direction: column-reverse;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .stage {
    padding: 16px;
  }
  #flyer-canvas {
    max-height: 62vh;
  }
}
