/* ============================================================
   XPoster — Sistema de diseño inspirado en Apple HIG
   Tipografía SF (system stack), color semántico, dark mode,
   safe-area insets, toques de 44pt, materiales y transiciones.
   ============================================================ */

:root {
  /* Paleta oscura estilo iOS */
  --bg: #000000;
  --bg-elevated: #1c1c1e;      /* systemGray6 dark */
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;        /* systemGray5 dark */
  --surface-3: #3a3a3c;        /* systemGray4 dark */
  --separator: rgba(84, 84, 88, 0.6);
  --text: #ffffff;
  --text-secondary: rgba(235, 235, 245, 0.6);
  --text-tertiary: rgba(235, 235, 245, 0.3);

  /* Colores del sistema iOS */
  --blue: #0a84ff;             /* systemBlue dark */
  --blue-hover: #409cff;
  --red: #ff453a;              /* systemRed dark */
  --orange: #ff9f0a;           /* systemOrange dark */
  --green: #30d158;            /* systemGreen dark */

  /* Semánticos de la app */
  --accent: var(--blue);
  --danger: var(--red);
  --warning: var(--orange);
  --success: var(--green);

  /* Radios estilo iOS */
  --radius: 12px;
  --radius-lg: 20px;
  --radius-pill: 980px;

  /* Alturas de barras */
  --navbar-h: 48px;
  --tabbar-h: 56px;

  /* Fuente del sistema (San Francisco en Apple) */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "Segoe UI", Roboto, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;                 /* body de iOS */
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* Tarjeta “inset grouped” de iOS */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px;
}

/* ============ BOTONES (estilo iOS) ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  cursor: pointer;
  padding: 11px 18px;
  min-height: 44px;                /* objetivo táctil HIG */
  text-decoration: none;           /* para <a class="btn"> */
  box-sizing: border-box;
  transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
.btn-block { display: flex; width: 100%; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #1a1000; }
.btn-block { width: 100%; margin-top: 18px; }
.btn-sm { font-size: 15px; padding: 9px 14px; min-height: 38px; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ============ LOGIN ============ */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}
.auth-card { width: 100%; max-width: 400px; }

.brand { text-align: center; margin-bottom: 26px; }
.logo { font-size: 48px; line-height: 1; }
.brand h1 { margin: 10px 0 4px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { color: var(--text-secondary); margin: 0; font-size: 15px; }

form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 18px 0 7px;
  color: var(--text-secondary);
  text-transform: none;
}

input[type="tel"],
input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  background: var(--surface-2);
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  padding: 13px 15px;
  font-size: 17px;                 /* evita zoom en iOS */
  font-family: var(--font);
  outline: none;
  transition: box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus {
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.35);
}

.phone-row { display: flex; gap: 10px; align-items: stretch; }
#country-code,
.country-select { flex: 0 0 108px; width: 108px; }
.phone-row input[type="tel"],
.phone-row .phone-number { flex: 1 1 auto; min-width: 0; }

.pin-inputs { display: flex; gap: 12px; justify-content: center; margin-top: 4px; }
.pin-box {
  width: 60px; height: 60px;
  padding: 0;
  text-align: center;
  font-size: 26px;
  font-weight: 600;
  background: var(--surface-2);
  border-radius: var(--radius);
  color: var(--text);
}
.pin-box:focus { box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.35); }

.error-msg { color: var(--danger); font-size: 14px; min-height: 20px; margin: 14px 0 4px; text-align: center; }
.hint { color: var(--text-secondary); font-size: 13px; text-align: center; margin-top: 16px; }

/* ============ APP (layout tipo app móvil) ============ */
#app-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Nav bar superior con material translúcido */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(var(--navbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 28, 30, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.nav-title { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }

/* Contenido desplazable entre barras */
.tab-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 90px);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.tab-view { display: flex; flex-direction: column; gap: 16px; }

/* ============ EDITOR ============ */
.editor-panel h2, .posts-panel h2 { margin: 0 0 3px; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.muted { color: var(--text-secondary); font-size: 14px; margin: 0 0 14px; }
.section-note { padding: 0 4px; }

textarea { resize: vertical; line-height: 1.45; min-height: 120px; }

.editor-controls { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.editor-controls .spacer { flex: 1; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); cursor: pointer; }
.checkbox input { width: auto; }

/* ============ LISTAS DE POSTS ============ */
.posts-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.posts-header .spacer { flex: 1; }
.count-badge {
  background: var(--surface-3);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 2px 11px;
  font-size: 14px;
  font-weight: 600;
  min-width: 26px;
  text-align: center;
}
.published-count-badge { background: rgba(48, 209, 88, 0.22); color: var(--green); }

.posts-list { display: flex; flex-direction: column; gap: 10px; }

.post-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.post-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; font-size: 16px; }
.post-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.char-count { font-size: 13px; color: var(--text-tertiary); }
.char-count.over { color: var(--danger); font-weight: 700; }
.post-actions { display: flex; gap: 8px; }

.post-card.published { background: rgba(48, 209, 88, 0.08); }
.published-tag { color: var(--green); font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.icon-inline { width: 15px; height: 15px; }

.post-card.editing { box-shadow: 0 0 0 2px var(--accent) inset; }
.post-card.editing textarea { width: 100%; }

/* Duplicados */
.post-card.is-duplicate { box-shadow: 0 0 0 1.5px var(--warning) inset; }
.dup-warning { color: var(--warning); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }

/* Estados vacíos */
.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 48px 20px;
  font-size: 15px;
}
.empty-state.hidden { display: none; }

/* ============ CAMPAÑAS ============ */
.campaign-bar { display: flex; flex-direction: column; gap: 16px; }
.campaign-select-wrap label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 7px;
}
.campaign-actions { display: flex; gap: 10px; }
.campaign-actions .btn { flex: 1; }

/* ============ AJUSTES ============ */
.settings-card { display: flex; flex-direction: column; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px;
  border-bottom: 0.5px solid var(--separator);
}
.settings-label { color: var(--text); font-size: 16px; }
.settings-value { color: var(--text-secondary); font-size: 15px; }

/* ============ TAB BAR INFERIOR ============ */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(28, 28, 30, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.tab-item {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  font-family: var(--font);
  transition: color .15s ease;
  padding-top: 6px;
}
.icon { width: 24px; height: 24px; display: inline-block; color: currentColor; }
.tab-item .tab-icon { width: 26px; height: 26px; }
.tab-item .tab-text { font-size: 10px; font-weight: 500; letter-spacing: 0; }
.tab-item.active { color: var(--accent); }
.tab-item:active { opacity: .6; }

/* ============ FAB (acción: publicar en secuencia) ============ */
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-weight: 600;
  font-size: 16px;
  padding: 13px 22px;
  min-height: 50px;
  box-shadow: 0 8px 24px rgba(10, 132, 255, 0.4);
  cursor: pointer;
  transition: transform .12s ease, opacity .15s ease, box-shadow .15s ease;
}
.fab:active { transform: translateX(-50%) scale(0.96); }
.fab:disabled { opacity: 0; pointer-events: none; box-shadow: none; }
.fab-icon { width: 20px; height: 20px; }

/* ============ SHEET (bottom sheet iOS) ============ */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  transition: background .25s ease;
}
.sheet-overlay.open { background: rgba(0, 0, 0, 0.5); }
body.sheet-open { overflow: hidden; }

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}
.sheet-overlay.open .sheet { transform: translateY(0); }

.sheet-grabber {
  width: 36px; height: 5px;
  background: var(--surface-3);
  border-radius: 3px;
  margin: 6px auto 12px;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sheet-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.sheet-close {
  border: none;
  background: var(--surface-2);
  color: var(--text-secondary);
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}

.sheet-progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 14px;
}
.sheet-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s ease;
}
.sheet-status { font-size: 14px; color: var(--text-secondary); margin: 0 0 10px; font-weight: 600; }
.sheet-preview {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  max-height: 40vh;
  overflow-y: auto;
}
.sheet-actions { margin-top: 18px; }

/* ============ MODALES (centrados, estilo iOS alert) ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1100;
  transition: background .2s ease;
}
.modal-overlay.open { background: rgba(0, 0, 0, 0.5); }
.modal-dialog {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: 100%;
  max-width: 300px;
  text-align: center;
  transform: scale(1.1);
  opacity: 0;
  transition: transform .2s ease, opacity .2s ease;
}
.modal-overlay.open .modal-dialog { transform: scale(1); opacity: 1; }
.modal-title { margin: 0 0 6px; font-size: 18px; font-weight: 700; }
.modal-message { margin: 0; color: var(--text-secondary); font-size: 14px; line-height: 1.45; }
.modal-input { margin-top: 16px; text-align: left; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* ============ RESPONSIVE ============ */
@media (min-width: 768px) {
  /* En pantallas grandes, las pestañas y el sheet siguen centrados y legibles */
  .tab-content { padding-top: 24px; }
}

@media (max-width: 360px) {
  .pin-box { width: 52px; height: 52px; font-size: 22px; }
  .tab-item .tab-text { font-size: 9px; }
  .fab-label { display: none; }
  .fab { padding: 15px; }
}

/* ============ INSTALADOR ============ */
.install-body { background: var(--bg); }
.install-card { max-width: 420px; }

.install-badge {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border-radius: 20px;
  background: linear-gradient(160deg, #2c2c2e, #1c1c1e);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
}
.install-badge-icon { width: 38px; height: 38px; }

.install-card .brand h1 { font-size: 26px; margin-top: 16px; }
.install-card .subtitle { max-width: 320px; margin: 0 auto; }

/* Nota de seguridad al pie */
.install-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 20px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
}
.install-note-icon { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.install-note--ok .install-note-icon { color: var(--green); }
.install-note--err .install-note-icon { color: var(--danger); }
.install-note .install-note-icon { color: var(--text-secondary); }
.install-note code {
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
}

/* Estado de éxito */
.install-success { text-align: center; }
.install-success-icon {
  width: 64px;
  height: 64px;
  margin: 4px auto 14px;
  border-radius: 50%;
  background: rgba(48, 209, 88, 0.18);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
}
.install-success-icon .icon { width: 34px; height: 34px; }
.install-success h2 { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.install-success code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 13px;
}

/* ===== Instalador: pantalla de éxito y acciones ===== */
.install-success { text-align: center; }
.install-success .subtitle { margin-bottom: 4px; }

.install-note--ok { color: var(--text); background: rgba(48, 209, 88, 0.14); text-align: left; }
.install-note--err { color: var(--text); background: rgba(255, 69, 58, 0.16); text-align: left; }

.install-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 14px;
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.install-divider::before,
.install-divider::after {
  content: "";
  flex: 1;
  height: 0.5px;
  background: var(--separator);
}

.install-help { color: var(--text-secondary); font-size: 13px; margin: 0 0 12px; }
.install-help--done { color: var(--green); font-weight: 600; margin-top: 8px; }

.install-self-actions { display: flex; flex-direction: column; gap: 4px; }
.install-self-actions form { margin: 0; }

/* Acción de texto estilo iOS (tinta, sin fondo) */
.link-action {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--accent);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  min-height: 44px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background .15s ease;
}
.link-action:hover { background: var(--surface-2); }
.link-action:active { opacity: .6; }
.link-action--danger { color: var(--danger); }
