:root {
  --bg: #0b0c10;
  --bg-2: #0f1015;
  --panel: #15171e;
  --panel-2: #1c1e27;
  --panel-3: #232531;
  --border: #292c38;
  --border-strong: #353846;
  --text: #eef0f5;
  --muted: #8b91a1;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-soft: rgba(139, 92, 246, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.1);
  --code: #08090d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --radius-lg: 14px;
  --gap: clamp(12px, 2vw, 22px);
  --pad: clamp(14px, 2.5vw, 22px);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #14151c 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ------- HEADER ------- */
header {
  padding: clamp(20px, 3vw, 32px) var(--pad) clamp(16px, 2vw, 22px);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(20, 21, 28, 0.9), rgba(11, 12, 16, 0));
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

header .wrap {
  max-width: 1500px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: clamp(18px, 2.4vw, 22px);
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
}

.badge {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border: 1px solid rgba(139, 92, 246, 0.3);
  padding: 4px 10px;
  border-radius: 999px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
  font-weight: 500;
}

.sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: clamp(13px, 1.6vw, 14px);
  max-width: 720px;
}

/* ------- MAIN ------- */
main {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  padding: var(--gap) var(--pad) clamp(40px, 6vw, 80px);
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

@media (min-width: 960px) {
  main {
    grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  }
}

@media (min-width: 1280px) {
  main {
    grid-template-columns: 460px minmax(0, 1fr);
  }
}

/* ------- PANELS ------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2vw, 22px);
  box-shadow: var(--shadow-md);
  animation: fade-in 0.25s ease;
}

.panel.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 960px) {
  .input-panel {
    position: sticky;
    top: 90px;
    align-self: start;
  }
}

/* ------- FORM ------- */
.lbl {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 14px 0 6px;
  font-weight: 600;
}
.lbl:first-child { margin-top: 0; }
.lbl .hint {
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 400;
  opacity: 0.8;
  margin-left: 4px;
}

input[type="text"],
textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input[type="text"]:hover,
textarea:hover {
  border-color: var(--border-strong);
}
input[type="text"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
  background: var(--panel-3);
}
textarea {
  resize: none;
  min-height: 200px;
  max-height: 60vh;
  line-height: 1.55;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: anywhere;
  tab-size: 2;
  overflow-y: auto;
}
textarea::placeholder { color: #555866; }
input[type="text"]::placeholder { color: #5a5e6c; }

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s, transform 0.06s, box-shadow 0.15s;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
button:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25);
}
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

button.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
button.secondary:hover:not(:disabled) {
  background: var(--panel-3);
  border-color: var(--border-strong);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  box-shadow: none;
}
button.ghost:hover:not(:disabled) {
  background: var(--panel-2);
  color: var(--text);
}

#analyzeBtn {
  flex: 1 1 160px;
  min-width: 140px;
}

/* ------- STATUS ------- */
.status {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  line-height: 1.4;
}
.status.loading {
  color: var(--accent-hover);
  background: var(--accent-soft);
  border-color: rgba(139, 92, 246, 0.3);
}
.status.ok {
  color: #bbf7d0;
  background: var(--ok-soft);
  border-color: rgba(34, 197, 94, 0.3);
}
.status.error {
  color: #fecaca;
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.35);
}
.status .timer {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  opacity: 0.85;
  margin-left: auto;
}
.status.hidden { display: none; }

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(167, 139, 250, 0.25);
  border-top-color: var(--accent-hover);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------- OUTPUT HEADER ------- */
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: -22px;
  background: var(--panel);
  margin-top: -22px;
  padding-top: 22px;
  z-index: 2;
  margin-left: -22px;
  margin-right: -22px;
  padding-left: 22px;
  padding-right: 22px;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}
.output-meta {
  font-size: 12.5px;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  line-height: 1.5;
}
.output-meta .ok { color: var(--ok); font-size: 16px; line-height: 1; }
.output-meta .pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.output-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.output-actions button {
  padding: 8px 14px;
  font-size: 13px;
}

/* ------- RENDERED MD ------- */
.rendered {
  font-size: 14.5px;
  line-height: 1.7;
  max-width: 100%;
  word-wrap: break-word;
}
.rendered h1 {
  font-size: clamp(22px, 2.6vw, 26px);
  margin: 0 0 14px;
  letter-spacing: -0.012em;
  font-weight: 700;
}
.rendered h2 {
  font-size: clamp(17px, 1.8vw, 19px);
  margin: 32px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: -0.005em;
}
.rendered h3 {
  font-size: clamp(15px, 1.5vw, 16.5px);
  margin: 24px 0 10px;
  color: var(--accent-hover);
  font-weight: 600;
}
.rendered p { margin: 8px 0; }
.rendered ul, .rendered ol { margin: 8px 0; padding-left: 24px; }
.rendered li { margin: 4px 0; }
.rendered hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}
.rendered table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}
@media (min-width: 760px) {
  .rendered table {
    display: table;
    white-space: normal;
  }
}
.rendered th, .rendered td {
  border: 1px solid var(--border);
  padding: 9px 12px;
  text-align: left;
  vertical-align: top;
}
.rendered th {
  background: var(--panel-2);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.rendered code {
  background: var(--code);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #c7d2fe;
  word-break: break-word;
}
.rendered pre {
  background: var(--code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12.5px;
  line-height: 1.55;
  -webkit-overflow-scrolling: touch;
}
.rendered pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text);
  white-space: pre;
  word-break: normal;
}
.rendered blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding: 6px 14px;
  color: var(--text);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
}
.rendered blockquote p { margin: 4px 0; }
.rendered strong { color: #ffffff; font-weight: 600; }
.rendered a {
  color: var(--accent-hover);
  text-decoration-color: rgba(167, 139, 250, 0.4);
  text-underline-offset: 2px;
}

/* ------- EMPTY STATE (cuando no hay output todavía) ------- */
.empty-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(40px, 8vw, 80px) 20px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}
.empty-hint .emoji {
  font-size: 28px;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ------- SELECT (modelo) ------- */
.select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 2px), calc(100% - 11px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}
.select:hover { border-color: var(--border-strong); }
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
  background-color: var(--panel-3);
}
.select:disabled { opacity: 0.45; cursor: not-allowed; }
.model-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ------- FORM ROW (modelo + nombre lado a lado en desktop) ------- */
.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 560px) {
  .form-row {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  }
}
.form-row .field { min-width: 0; }
.form-row .lbl { margin-top: 0; }

/* ------- HEADER BUTTON ------- */
.header-btn {
  margin-left: auto;
  padding: 6px 12px !important;
  font-size: 13px !important;
  border-radius: 999px !important;
  border: 1px solid var(--border) !important;
  background: var(--panel-2) !important;
  color: var(--text) !important;
}
.header-btn:hover:not(:disabled) {
  background: var(--panel-3) !important;
  border-color: var(--border-strong) !important;
  color: var(--text) !important;
}

/* ------- DRAWER HISTORIAL ------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: flex-end;
  animation: fade-in 0.2s ease;
}
.drawer.hidden { display: none; }

.drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.drawer-panel {
  position: relative;
  width: min(440px, 100%);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slide-in 0.22s ease;
}
@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font: inherit;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
  box-shadow: none;
}
.history-item:hover {
  background: var(--panel-3);
  border-color: var(--border-strong);
}
.history-item:active { transform: translateY(1px); }
.history-row1 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}
.history-title {
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.3;
}
.history-date {
  font-size: 11.5px;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
}
.history-row2 {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.history-pill {
  background: var(--panel-3);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  line-height: 1.5;
}

/* ------- SCROLLBARS (sutiles) ------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: #44485a; background-clip: padding-box; border: 2px solid transparent; }
