:root {
  --primary: #FF5A0A;
  --primary-dark: #CC4807;
  --primary-light: #FFF3EE;
  --primary-mid: #FFE0CC;
  --white: #ffffff;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-400: #9CA3AF;
  --gray-600: #4B5563;
  --gray-800: #1F2937;
  --green: #059669;
  --red: #DC2626;
  --yellow: #D97706;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: .2s ease;
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--gray-50); color: var(--gray-800); line-height: 1.5; min-height: 100vh; }

/* ── AUTH ── */
#auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 40%, var(--primary-dark) 100%);
  padding: 1rem;
}
.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}
.auth-header {
  background: var(--primary);
  padding: 2rem;
  text-align: center;
}
.auth-header .logo-text {
  font-size: 2rem;
  font-weight: 800;
  color: var(--white);
  letter-spacing: -1px;
}
.auth-header p {
  color: rgba(255,255,255,.8);
  font-size: .85rem;
  margin-top: .25rem;
}
.auth-tabs {
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  background: var(--gray-50);
}
.auth-tab {
  flex: 1;
  padding: .9rem;
  text-align: center;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  color: var(--gray-600);
  transition: var(--transition);
  border: none;
  background: none;
}
.auth-tab.active {
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  margin-bottom: -2px;
}
.auth-body { padding: 1.75rem; }
.auth-form { display: none; }
.auth-form.active { display: block; }

/* ── MAIN APP ── */
#app-view { display: none; }
#app-view.visible { display: block; }

header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header-logo { font-weight: 800; font-size: 1.3rem; color: var(--primary); letter-spacing: -0.5px; }
.header-title { font-size: .8rem; color: var(--gray-600); flex: 1; }
.header-user { font-size: .8rem; color: var(--gray-600); display: flex; align-items: center; gap: .75rem; }
.header-user strong { color: var(--gray-800); }

nav {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  gap: 0;
  overflow-x: auto;
}
.nav-tab {
  padding: .9rem 1.25rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.nav-tab:hover { color: var(--primary); background: var(--primary-light); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-badge {
  font-size: .7rem;
  background: var(--primary);
  color: white;
  border-radius: 9999px;
  padding: .1em .45em;
  font-weight: 600;
}
.nav-badge.done { background: var(--green); }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── DASHBOARD ── */
.dashboard-header h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: .25rem; }
.dashboard-header p { color: var(--gray-600); font-size: .9rem; }

.plantilla-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 1.75rem;
}
.plantilla-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition);
  cursor: pointer;
}
.plantilla-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-header {
  background: var(--primary);
  padding: 1.25rem;
  color: white;
}
.card-header .card-badge {
  display: inline-block;
  background: rgba(255,255,255,.2);
  border-radius: 9999px;
  padding: .2em .65em;
  font-size: .75rem;
  font-weight: 700;
  margin-bottom: .5rem;
}
.card-header h3 { font-size: 1rem; font-weight: 700; }
.card-header p { font-size: .75rem; opacity: .85; margin-top: .2rem; }
.card-body { padding: 1.25rem; }
.progress-bar-wrap { background: var(--gray-200); border-radius: 9999px; height: 6px; margin-bottom: .5rem; }
.progress-bar { background: var(--primary); height: 6px; border-radius: 9999px; transition: width .4s ease; }
.card-meta { font-size: .78rem; color: var(--gray-600); display: flex; justify-content: space-between; }

/* ── FORMS ── */
.form-layout { display: flex; gap: 1.5rem; align-items: flex-start; }
.form-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  position: sticky;
  top: 120px;
}
.sidebar-header {
  background: var(--primary);
  color: white;
  padding: 1rem;
  font-weight: 700;
  font-size: .85rem;
}
.sidebar-item {
  padding: .7rem 1rem;
  font-size: .8rem;
  color: var(--gray-600);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: .5rem;
  border-bottom: 1px solid var(--gray-100);
}
.sidebar-item:hover { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary-mid); }
.sidebar-item.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.sidebar-item .check { font-size: .75rem; }
.sidebar-item .check.saved { color: var(--green); }

.form-main { flex: 1; min-width: 0; }
.form-top-bar {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.form-top-bar h2 { font-size: 1.1rem; font-weight: 700; flex: 1; }
.form-top-bar .last-saved { font-size: .78rem; color: var(--gray-400); }

.section-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  margin-bottom: 1.25rem;
  overflow: hidden;
  display: none;
}
.section-card.active { display: block; }
.section-card-header {
  background: var(--primary-light);
  border-bottom: 1px solid var(--primary-mid);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.section-card-header .section-num {
  width: 28px; height: 28px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.section-card-header h3 { font-size: 1rem; font-weight: 700; color: var(--primary-dark); flex: 1; }
.section-instruction {
  padding: .9rem 1.5rem;
  background: #FFFBF5;
  border-bottom: 1px solid var(--gray-100);
  font-size: .82rem;
  color: var(--gray-600);
  font-style: italic;
  display: flex;
  gap: .5rem;
}
.section-body { padding: 1.5rem; }
.section-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .75rem;
  background: var(--gray-50);
}
.section-nav-btns { display: flex; gap: .5rem; }

/* ── FIELDS ── */
.field-group { margin-bottom: 1.25rem; }
.field-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: .35rem;
}
.field-label .req { color: var(--primary); margin-left: .1rem; }
.field-hint { font-size: .75rem; color: var(--gray-400); margin-top: .2rem; }

input[type=text], input[type=email], input[type=password], input[type=date],
select, textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: .875rem;
  font-family: inherit;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,90,10,.1);
}
textarea { resize: vertical; min-height: 80px; }

.fields-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.fields-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ── DYNAMIC TABLE ── */
.dtable-wrap { overflow-x: auto; }
.dtable {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  margin-bottom: .5rem;
}
.dtable th {
  background: var(--gray-800);
  color: white;
  padding: .55rem .6rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}
.dtable td {
  padding: .3rem .5rem;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: top;
}
.dtable tr:nth-child(even) td { background: var(--gray-50); }
.dtable td input, .dtable td select, .dtable td textarea {
  padding: .3rem .4rem;
  font-size: .8rem;
  min-width: 80px;
  border-radius: 4px;
}
.dtable td textarea { min-height: 48px; resize: vertical; }
.dtable .del-row-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 1rem;
  padding: .2rem .4rem;
  border-radius: 4px;
}
.dtable .del-row-btn:hover { background: #fee2e2; color: var(--red); }

/* ── CHECKLIST ── */
.checklist-item {
  display: grid;
  grid-template-columns: 1fr 160px 120px 1fr;
  gap: .5rem;
  align-items: start;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--gray-100);
  font-size: .82rem;
}
.checklist-item:nth-child(even) { background: var(--gray-50); }
.checklist-item:last-child { border-bottom: none; }
.checklist-item .item-label { font-weight: 500; color: var(--gray-700); padding-top: .35rem; }
.checklist-header {
  display: grid;
  grid-template-columns: 1fr 160px 120px 1fr;
  gap: .5rem;
  padding: .4rem .75rem;
  background: var(--gray-800);
  color: white;
  font-size: .75rem;
  font-weight: 600;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  font-size: .875rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }
.btn-danger { background: #FEE2E2; color: var(--red); }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-success { background: #D1FAE5; color: var(--green); }

/* ── ALERTS ── */
.alert {
  padding: .8rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid var(--primary-mid); }

/* ── ADMIN ── */
.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.admin-table th { background: var(--gray-800); color: white; padding: .75rem 1rem; text-align: left; font-weight: 600; }
.admin-table td { padding: .65rem 1rem; border-bottom: 1px solid var(--gray-200); }
.admin-table tr:hover td { background: var(--primary-light); }
.progress-pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--gray-100);
  border-radius: 9999px;
  padding: .2em .7em;
  font-size: .78rem;
  font-weight: 600;
}
.progress-pill.full { background: #D1FAE5; color: var(--green); }
.progress-pill.partial { background: var(--primary-light); color: var(--primary); }
.progress-pill.empty { background: var(--gray-100); color: var(--gray-600); }

/* ── MISC ── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; }
.page-header p { color: var(--gray-600); font-size: .875rem; margin-top: .25rem; }
.card { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid var(--gray-200); padding: 1.5rem; }
.divider { height: 1px; background: var(--gray-200); margin: 1.25rem 0; }
.text-muted { color: var(--gray-400); font-size: .8rem; }
.sheet-link { color: var(--primary); text-decoration: none; font-weight: 600; }
.sheet-link:hover { text-decoration: underline; }
.tag {
  display: inline-block;
  padding: .15em .6em;
  border-radius: 9999px;
  font-size: .72rem;
  font-weight: 700;
}
.tag-admin { background: var(--primary); color: white; }
.tag-user { background: var(--gray-200); color: var(--gray-600); }

.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.add-block-btn {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--primary);
  background: var(--primary-light);
  border: 1.5px dashed var(--primary-mid);
  border-radius: var(--radius);
  padding: .55rem 1rem;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  margin-top: .5rem;
  transition: var(--transition);
}
.add-block-btn:hover { background: var(--primary-mid); }

.dynamic-block {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: .75rem;
  background: var(--gray-50);
  position: relative;
}
.dynamic-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
  font-weight: 600;
  font-size: .85rem;
  color: var(--primary-dark);
}

.stars-options { display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; }
.stars-option {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .6rem .75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}
.stars-option:hover { border-color: var(--primary); background: var(--primary-light); }
.stars-option input[type=radio] { margin-top: .2rem; accent-color: var(--primary); }
.stars-option .stars-text strong { display: block; font-size: .85rem; }
.stars-option .stars-text span { font-size: .78rem; color: var(--gray-600); }

.list-inputs .list-input-row { display: flex; gap: .5rem; margin-bottom: .5rem; align-items: center; }
.list-inputs .list-input-row input { flex: 1; }
.list-inputs .list-input-row .list-num { font-weight: 700; color: var(--primary); min-width: 1.2rem; }

@media (max-width: 768px) {
  .form-layout { flex-direction: column; }
  .form-sidebar { width: 100%; position: static; }
  .fields-grid-2, .fields-grid-3 { grid-template-columns: 1fr; }
  .checklist-item { grid-template-columns: 1fr; }
  .checklist-header { display: none; }
  .header-inner { flex-wrap: wrap; }
  main { padding: 1rem; }
  .plantilla-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .plantilla-grid { grid-template-columns: 1fr; }
}

/* ─── ASISTENTE WIN ──────────────────────────────────────────────────────── */
.btn-assistant {
  background: var(--primary);
  color: white;
  border: none;
  font-weight: 600;
  letter-spacing: .3px;
}
.btn-assistant:hover { background: var(--primary-dark); }

.assistant-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 999;
}
.assistant-overlay.open { display: block; }

.assistant-panel {
  position: fixed;
  top: 0; right: -420px;
  width: 400px; height: 100vh;
  background: white;
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: right .3s ease;
}
.assistant-panel.open { right: 0; }

.assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--primary);
  color: white;
  flex-shrink: 0;
}
.assistant-title {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.assistant-icon { font-size: 1.5rem; }
.assistant-title strong { display: block; font-size: 1rem; }
.assistant-subtitle { font-size: .75rem; opacity: .85; }
.assistant-close {
  background: rgba(255,255,255,.2);
  border: none;
  color: white;
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
}
.assistant-close:hover { background: rgba(255,255,255,.35); }

.assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  background: var(--gray-50);
}

.assistant-msg { display: flex; }
.assistant-msg-user { justify-content: flex-end; }
.assistant-msg-bot { justify-content: flex-start; }

.msg-bubble {
  max-width: 85%;
  padding: .65rem .9rem;
  border-radius: 12px;
  font-size: .875rem;
  line-height: 1.55;
}
.assistant-msg-user .msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 3px;
}
.assistant-msg-bot .msg-bubble {
  background: white;
  color: var(--gray-800);
  border: 1px solid var(--gray-200);
  border-bottom-left-radius: 3px;
  box-shadow: var(--shadow);
}

.assistant-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: .25rem 0;
}
.assistant-typing span {
  width: 7px; height: 7px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: typing-dot .9s infinite;
}
.assistant-typing span:nth-child(2) { animation-delay: .15s; }
.assistant-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.assistant-input-area {
  padding: 1rem;
  border-top: 1px solid var(--gray-200);
  background: white;
  display: flex;
  gap: .5rem;
  align-items: flex-end;
  flex-shrink: 0;
}
.assistant-input {
  flex: 1;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .6rem .75rem;
  font-size: .875rem;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}
.assistant-input:focus { border-color: var(--primary); }
.assistant-send-btn { flex-shrink: 0; }

@media (max-width: 480px) {
  .assistant-panel { width: 100%; right: -100%; }
  .btn-assistant span { display: none; }
}
