:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e5ec;
  --text: #1c1f2a;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --radius: 10px;
}

/* El atributo `hidden` debe ganarle a cualquier `display` puesto por clase
   (ej. `.layout { display: grid }` en #view-prompts) -- si no, el navegador
   sigue renderizando el elemento "escondido" por debajo del visible. */
[hidden] {
  display: none !important;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.view-tabs { display: flex; gap: 6px; }
.view-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.view-tab:hover { border-color: var(--primary); color: var(--text); }
.view-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-title { margin-bottom: 20px; }

.logo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.topbar-title h1 { font-size: 18px; margin: 0; }
.topbar-title p { font-size: 13px; color: var(--muted); margin: 2px 0 0; }

.banner {
  margin: 16px 28px 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
}
.banner-warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid #fde68a; }
.banner-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; margin: 16px 0 0; }
.banner code { background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 4px; }

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  padding: 24px 28px 48px;
  align-items: start;
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
}

.sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 4px 0 12px;
}

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

.automation-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.automation-card:hover { border-color: var(--primary); }
.automation-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.automation-card .card-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.automation-card .card-desc { font-size: 12.5px; color: var(--muted); line-height: 1.4; }

.content { min-height: 300px; }

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.automation-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.automation-panel h2 { margin: 0 0 4px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13.5px; }

.automation-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
  margin: 20px 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 200px; }
.field label { font-size: 13px; font-weight: 600; }
.field select,
.field input[type="text"] {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  min-width: 220px;
}
.field-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field-checkbox label { font-weight: 500; }
.field-hint { font-size: 12px; color: var(--muted); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary { background: #eef0f7; color: var(--text); }
.btn-secondary:hover { background: #e2e5f2; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-block { width: 100%; margin-top: 12px; }

.prompt-form { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
.prompt-form textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  min-height: 260px;
}
.prompt-form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.prompt-card-preview {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.results { margin-top: 8px; }
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.results-header p { margin: 0; font-size: 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  background: #f9fafb;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-weight: 600;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafe; }
td.empty-cell { text-align: center; color: var(--muted); padding: 24px; }

a.row-link { color: var(--primary); text-decoration: none; font-weight: 600; }
a.row-link:hover { text-decoration: underline; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
