:root {
  --orange: #f97316;
  --orange-dark: #ea580c;
  --orange-tint: #fff1e6;
  --ink: #1a0a10;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f8f6f4;
  --surface: #ffffff;
  font-variant-numeric: tabular-nums;
  color-scheme: light dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  background: var(--border);
  color: var(--ink);
}

/* ---------- Layout: 3 paneles (brief | chat | preview) ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 6px minmax(320px, 460px) 6px minmax(320px, 1fr);
  height: 100vh;
  background: var(--border);
}

.resizer {
  background: var(--border);
  cursor: col-resize;
  position: relative;
}
.resizer::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}
.resizer:hover,
.resizer.is-dragging {
  background: var(--orange);
}

.panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--bg), #f1ede9 100%);
}

.panel--brief,
.panel--preview {
  overflow-y: auto;
}

.panel--chat {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 0 1.25rem;
}

.panel--chat::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: url("/img/growing-mark.webp");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 240px auto;
  opacity: 0.05;
}
@media (prefers-color-scheme: dark) {
  .panel--chat::before {
    background-image: url("/img/growing-mark-dark.webp");
    opacity: 0.07;
  }
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel__header h2 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0;
}

.panel__action {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--orange-dark);
  background: var(--orange-tint);
  border: none;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.panel__action:hover { background: var(--orange); color: #fff; }
.panel__actions { display: flex; gap: 0.5rem; }

.panel__body { padding: 1rem 1.25rem 1.5rem; }

/* ---------- Desplegable de búsqueda de briefs guardados ---------- */

.brief__search { position: relative; display: inline-block; }

.brief__search-dropdown {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 30;
  width: 280px;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  overflow: hidden;
}
.brief__search-dropdown[hidden] {
  display: none;
}

.brief__search-input {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.6rem 0.8rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--ink);
  outline: none;
}
.brief__search-input:focus { background: var(--orange-tint); }

.brief__search-list {
  list-style: none;
  margin: 0;
  padding: 0.3rem;
  overflow-y: auto;
}

.brief__search-item {
  padding: 0.5rem 0.6rem;
  border-radius: 0.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.brief__search-item:hover,
.brief__search-item.is-active {
  background: var(--orange-tint);
}
.brief__search-item-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}
.brief__search-item-date {
  font-size: 0.7rem;
  color: var(--muted);
}

.brief__search-empty {
  padding: 0.9rem 0.8rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.tabbar { display: none; }

/* ---------- Brief panel (formulario editable) ---------- */

.brief__progress {
  padding: 0.75rem 1.25rem 0;
  flex-shrink: 0;
}
.brief__progress-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  margin-bottom: 0.3rem;
}
.brief__progress-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.brief__progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--orange), var(--orange-dark));
  transition: width 0.3s ease;
}

.brief__meta {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.5rem 1.25rem 0;
  margin: 0;
}

.brief-form { display: flex; flex-direction: column; gap: 1.3rem; }
.brief-form[hidden] { display: none; }

/* ---------- Portón obligatorio: ¿cliente existe o es nuevo? ---------- */

.brief__gate {
  margin: 1rem 1.25rem 0;
  padding: 1rem;
  border-radius: 0.8rem;
  background: var(--orange-tint);
  border: 1px solid var(--orange);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.brief__gate[hidden] { display: none; }

.brief__gate-question {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
}
.brief__gate-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.brief__gate-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.brief__gate-btn {
  flex: 1;
  min-width: 8rem;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid var(--orange);
  background: transparent;
  color: var(--orange-dark);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.brief__gate-btn:hover { background: rgba(249, 115, 22, 0.12); }
.brief__gate-btn:active { transform: scale(0.97); }
.brief__gate-btn--primary { background: var(--orange); color: #fff; }
.brief__gate-btn--primary:hover { background: var(--orange-dark); }

.brief__gate-signup {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow: hidden;
  max-height: 0;
  padding-top: 0;
  opacity: 0;
  transform: translateY(-8px);
  border-top: 1px dashed transparent;
  transition: max-height 0.4s ease, opacity 0.35s ease, transform 0.35s ease,
    padding-top 0.35s ease, border-color 0.35s ease;
}
.brief__gate-signup[hidden] { display: none; }
.brief__gate-signup.is-revealed {
  max-height: 700px;
  padding-top: 0.6rem;
  opacity: 1;
  transform: translateY(0);
  border-top-color: var(--orange);
}

@keyframes briefGateFlash {
  0% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.55); background-color: rgba(249, 115, 22, 0.22); }
  100% { box-shadow: 0 0 0 14px rgba(249, 115, 22, 0); background-color: transparent; }
}
.brief__gate-signup.is-flash {
  animation: briefGateFlash 0.7s ease-out;
  border-radius: 0.6rem;
}

.brief__gate-signup-toggle {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--orange-dark);
  background: none;
  border: none;
  padding: 0.2rem 0;
  cursor: pointer;
  text-align: left;
}
@media (prefers-color-scheme: dark) {
  .brief__gate-signup-toggle { color: #fff; }
}
.brief__gate-signup-arrow {
  display: inline-block;
  transition: transform 0.15s ease;
}
.brief__gate-signup-toggle.is-open .brief__gate-signup-arrow {
  transform: rotate(90deg);
}

.brief__gate-signup-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.brief__gate-signup-panel[hidden] { display: none; }

.brief__gate-signup-frame {
  width: 100%;
  height: 620px;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: #fff;
}

.brief__gate-signup-done {
  align-self: stretch;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.6rem;
  border-radius: 0.6rem;
  border: none;
  background: var(--orange);
  color: #fff;
  cursor: pointer;
}
.brief__gate-signup-done:hover { background: var(--orange-dark); }

.brief__section {
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.brief__section:last-of-type { border-bottom: none; padding-bottom: 0; }

.brief__section h3 {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--orange-dark);
  margin: 0;
}
.brief__section h3 .hint {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.7rem;
}

.brief-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
}
.brief-form .req { color: #ef4444; }

.brief-form input[type="text"],
.brief-form input[type="url"],
.brief-form input[type="tel"],
.brief-form textarea,
.brief-form select {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 400;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
.brief-form input:focus,
.brief-form textarea:focus,
.brief-form select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-tint);
}
.brief-form textarea { resize: vertical; min-height: 3.5rem; }

.brief__row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.brief__row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.6rem; }

.brief__google-btn {
  align-self: flex-start;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--orange-dark);
  background: var(--orange-tint);
  border: 1px solid transparent;
  padding: 0.45rem 0.8rem;
  border-radius: 0.6rem;
  cursor: pointer;
  transition: background 0.15s;
}
.brief__google-btn:hover { background: var(--orange); color: #fff; }
.brief__google-btn:disabled { opacity: 0.6; cursor: wait; }

.brief__image-row { display: flex; gap: 0.4rem; }
.brief__image-row input { flex: 1; min-width: 0; }
.brief__upload-btn {
  flex-shrink: 0;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 1rem;
  display: grid;
  place-items: center;
  transition: border-color 0.15s, background 0.15s;
}
.brief__upload-btn:hover { border-color: var(--orange); background: var(--orange-tint); }
.brief__upload-btn:disabled { opacity: 0.6; cursor: wait; }

.brief__thumb {
  margin-top: 0.4rem;
  width: 100%;
  max-height: 6rem;
  object-fit: cover;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
}

.brief__hours {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.brief__hours label { flex-direction: row; align-items: center; gap: 0.5rem; }
.brief__hours input { flex: 1; }

.brief__colors { display: flex; gap: 0.6rem; }
.brief__color { display: flex; gap: 0.35rem; flex: 1; }
.brief__color input[type="color"] {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  flex-shrink: 0;
}
.brief__color input[type="text"] { flex: 1; min-width: 0; }

.brief__review {
  background: var(--orange-tint);
  border-radius: 0.6rem;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.brief__review-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--orange-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.brief__submit {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 0.7rem;
  padding: 0.8rem;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.brief__submit:hover { background: var(--orange-dark); }
.brief__submit:disabled { opacity: 0.6; cursor: not-allowed; }

.brief__status {
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  padding: 0.6rem;
  border-radius: 0.5rem;
  background: #dcfce7;
  color: #166534;
}
.brief__status.error { background: #fee2e2; color: #991b1b; }

/* ---------- Preview panel ---------- */

.preview-empty {
  margin: auto;
  max-width: 280px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 1.5rem;
}

#previewFrame {
  flex: 1;
  width: 100%;
  border: none;
}

/* ---------- Chat ---------- */

.app__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app__brand { display: flex; align-items: center; gap: 0.75rem; }

.app__icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0.6rem;
  border-radius: 1rem;
  background: var(--orange-tint);
  color: var(--orange-dark);
  flex-shrink: 0;
}

h1 { font-size: 1.05rem; font-weight: 700; margin: 0; }
#subtitle { font-size: 0.85rem; color: var(--muted); margin: 0.15rem 0 0; }

.app__badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--orange-dark);
  background: var(--orange-tint);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  white-space: nowrap;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.msg {
  max-width: 82%;
  padding: 0.7rem 1rem;
  border-radius: 1.1rem;
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.msg--user {
  align-self: flex-end;
  background: var(--orange);
  color: #fff;
  border-bottom-right-radius: 0.3rem;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.3rem;
}

.msg--empty {
  align-self: center;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  margin: auto;
}

.typing {
  align-self: flex-start;
  display: flex;
  gap: 0.3rem;
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.5;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 1rem 0 1.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input {
  flex: 1;
  padding: 0.75rem 1.1rem;
  border-radius: 1.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
}
#input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-tint); }

.composer button {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: none;
  background: var(--orange);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.composer button:hover { background: var(--orange-dark); }
.composer button svg { width: 1.1rem; height: 1.1rem; }

/* ---------- Responsive: pantallas angostas, un panel a la vez ---------- */

@media (max-width: 1024px) {
  .layout {
    display: block;
    height: 100vh;
    grid-template-columns: none;
  }

  .resizer { display: none; }

  .tabbar {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .tabbar button {
    flex: 1;
    padding: 0.85rem 0.5rem;
    border: none;
    background: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
  }
  .tabbar button.is-active {
    color: var(--orange-dark);
    border-bottom-color: var(--orange);
  }

  .panel {
    display: none;
    height: calc(100vh - 3rem);
  }
  .panel.is-active { display: flex; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f3ede9;
    --muted: #9b9490;
    --border: #322824;
    --bg: #17100d;
    --surface: #241a16;
    --orange-tint: #3a2013;
  }
  body { background: var(--border); }
  .panel { background: linear-gradient(180deg, var(--bg), #120c09 100%); }
}
