:root {
  --maroon: #6e1616;
  --maroon-dark: #551010;
  --maroon-light: #8a2222;
  --bg: #eef0f3;
  --card: #ffffff;
  --text: #26292e;
  --muted: #7a828c;
  --border: #e2e5ea;
  --accent: #b31f1f;
}

* { box-sizing: border-box; }

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

/* ------------------------------------------------------------------ */
/* Transiciones de página (login / logout)                             */
/* ------------------------------------------------------------------ */
@keyframes page-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes card-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

body { animation: page-fade 0.28s ease-out; }
body.leaving { opacity: 0; transition: opacity 0.2s ease; }
.landing-card { animation: card-rise 0.32s ease-out; }

@media (prefers-reduced-motion: reduce) {
  body, .landing-card { animation: none; }
  body.leaving { transition: none; }
}

/* ------------------------------------------------------------------ */
/* Landing                                                             */
/* ------------------------------------------------------------------ */
.landing {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #7a1a1a 0%, #4a0d0d 60%, #2c0808 100%);
  padding: 24px;
}

.landing-card {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  color: var(--maroon);
  letter-spacing: -0.5px;
}

.brand h1 span { color: var(--accent); }

.brand-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d32f2f, #6e1616);
}

.subtitle {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 15px;
}

form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

form input[type="url"],
form input[type="text"],
form input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

form input[type="url"]:focus,
form input[type="text"]:focus,
form input[type="password"]:focus { border-color: var(--accent); }

.field-gap { margin-top: 16px; }

button {
  margin-top: 16px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--maroon);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover { background: var(--maroon-light); }
button:disabled { opacity: 0.7; cursor: default; }

.alert {
  background: #fdecea;
  color: #922;
  border: 1px solid #f5c6cb;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: 14px;
}

.alert-info {
  background: #fff8e6;
  color: #7a5a00;
  border-color: #f0d78c;
}

.hidden { display: none !important; }

.loading {
  margin-top: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.history { margin-top: 32px; border-top: 1px solid var(--border); padding-top: 20px; }
.history h2 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.history ul { list-style: none; padding: 0; margin: 0; }
.history li a {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
}
.history li a:hover { background: #f5f6f8; }
.history-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ */
/* Dashboard                                                           */
/* ------------------------------------------------------------------ */
.dash-header {
  background: #fff;
  color: var(--text);
  padding: 12px 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.dash-header h1 {
  grid-column: 2;
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.back {
  grid-column: 1;
  justify-self: start;
  color: var(--muted);
  text-decoration: none;
  font-size: 20px;
  line-height: 1;
}
.back:hover { color: var(--maroon); }

.dash-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
}

.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  background: #fff;
}
.date-range .cal-icon { font-size: 13px; opacity: 0.7; }
.date-range .date-sep { color: var(--muted); }

.status-bar {
  padding: 8px 24px;
  font-size: 13px;
  color: var(--muted);
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: min-content;
  gap: 16px;
  padding: 20px 24px 48px;
}

/* Banner de título estilo MegaTime */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(135deg, var(--maroon), var(--maroon-dark));
  color: #fff;
  border-radius: 12px;
  padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.banner-title { font-size: 22px; font-weight: 800; letter-spacing: 0.2px; }
.banner-metric { text-align: right; line-height: 1.1; }
.banner-metric span { display: block; font-size: 11px; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.5px; }
.banner-metric strong { font-size: 24px; font-weight: 800; }

@media (max-width: 640px) {
  .banner { flex-direction: column; align-items: flex-start; }
  .banner-metric { text-align: left; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

/* Column spans by widget type */
.card.span-4 { grid-column: span 4; }
.card.span-6 { grid-column: span 6; }
.card.span-8 { grid-column: span 8; }
.card.span-12 { grid-column: span 12; }

@media (max-width: 900px) {
  .grid > .card { grid-column: 1 / -1 !important; }
  .dash-header h1 { max-width: 40vw; }
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--maroon);
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.chart { width: 100%; }

/* Multimedia cards */
.media-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding-bottom: 8px;
}

@media (max-width: 1100px) {
  .media-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 760px) {
  .media-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .media-grid { grid-template-columns: repeat(2, 1fr); }
}
.media-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fafafa;
  font-size: 12px;
  text-decoration: none;
  color: inherit;
}
.media-item:hover .media-name { text-decoration: none; }
.media-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #e9ebf0;
  display: block;
}

/* Placeholder con ícono para audio/video (o imagen sin miniatura) */
.media-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.media-ph-video { background: linear-gradient(135deg, #6e1616, #a12626); }
.media-ph-audio { background: linear-gradient(135deg, #2c3e50, #3f6178); }
.media-ph-image { background: linear-gradient(135deg, #7a828c, #9aa1ab); }
.media-ph svg { opacity: 0.95; }

/* Video: reproductor con preview */
.media-video {
  background: #000;
  object-fit: contain;
}

/* Audio: panel con ícono + reproductor */
.media-audio {
  aspect-ratio: auto;
  flex-direction: column;
  gap: 8px;
  padding: 14px 10px 10px;
}
.media-audio svg { width: 28px; height: 28px; }
.media-audio audio {
  width: 100%;
  height: 34px;
}
.media-body { padding: 8px 10px; }
.media-name { font-weight: 700; display: block; margin-bottom: 2px; line-height: 1.25; color: var(--maroon); text-decoration: none; }
.media-meta { color: var(--muted); }

.empty {
  grid-column: span 12;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}

.err-inline { color: #922; font-size: 12px; }

/* ------------------------------------------------------------------ */
/* Asistente IA: botón flotante + sidebar                              */
/* ------------------------------------------------------------------ */
.ai-fab-wrap {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.ai-fab-label {
  background: #fff;
  color: var(--maroon);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  position: relative;
  animation: ai-label-float 2.4s ease-in-out infinite;
}
.ai-fab-label::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #fff;
}
@keyframes ai-label-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.ai-fab {
  width: 58px;
  height: 58px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--maroon), var(--maroon-light));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(110, 22, 22, 0.45);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.ai-fab:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 10px 26px rgba(110, 22, 22, 0.55); }

.ai-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 55;
}

.ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 560px;
  max-width: 95vw;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.25s ease;
  z-index: 60;
}
.ai-panel.open { transform: translateX(0); }

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--maroon), var(--maroon-dark));
  color: #fff;
}
.ai-head-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.ai-dot { width: 9px; height: 9px; border-radius: 50%; background: #57e08a; box-shadow: 0 0 0 3px rgba(87, 224, 138, 0.25); }
.ai-close { background: transparent; border: none; color: #fff; font-size: 26px; line-height: 1; cursor: pointer; width: auto; margin: 0; padding: 0 4px; }
.ai-close:hover { opacity: 0.8; background: transparent; }

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f7f7f9;
}

.ai-msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ai-msg-user {
  align-self: flex-end;
  background: var(--maroon);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-assistant {
  align-self: flex-start;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown dentro de las burbujas del asistente */
.ai-md { max-width: 92%; white-space: normal; }
.ai-md > *:first-child { margin-top: 0; }
.ai-md > *:last-child { margin-bottom: 0; }
.ai-md p { margin: 6px 0; }
.ai-md h1, .ai-md h2, .ai-md h3, .ai-md h4 {
  margin: 10px 0 6px;
  line-height: 1.25;
  color: var(--maroon);
}
.ai-md h1 { font-size: 16px; }
.ai-md h2 { font-size: 15px; }
.ai-md h3 { font-size: 14px; }
.ai-md h4 { font-size: 13px; }
.ai-md ul, .ai-md ol { margin: 6px 0; padding-left: 20px; }
.ai-md li { margin: 2px 0; }
.ai-md strong { font-weight: 700; }
.ai-md hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.ai-md a { color: var(--accent); }
.ai-md code {
  background: #f0f0f3;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: ui-monospace, Consolas, monospace;
}
.ai-md pre {
  background: #f0f0f3;
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
}
.ai-md pre code { background: none; padding: 0; }
.ai-md table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 12px;
  display: block;
  overflow-x: auto;
}
.ai-md th, .ai-md td {
  border: 1px solid var(--border);
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
}
.ai-md thead th {
  background: #f3e9e9;
  color: var(--maroon);
  font-weight: 700;
}
.ai-md tbody tr:nth-child(even) { background: #faf7f7; }
.ai-md blockquote {
  margin: 6px 0;
  padding: 4px 10px;
  border-left: 3px solid var(--maroon-light);
  color: var(--muted);
}

.ai-typing { display: flex; gap: 4px; align-items: center; }
.ai-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: ai-blink 1.2s infinite both;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.ai-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: #fff;
}
.ai-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  max-height: 120px;
  line-height: 1.35;
}
.ai-input:focus { border-color: var(--accent); }
.ai-send {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: var(--maroon);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.ai-send:hover { background: var(--maroon-light); }

/* ------------------------------------------------------------------ */
/* Robustness UI                                                       */
/* ------------------------------------------------------------------ */
.back-link {
  display: inline-block;
  margin-top: 18px;
  color: var(--maroon);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.back-link:hover { text-decoration: underline; }

.refresh-banner {
  background: #fff8e6;
  color: #7a5a00;
  border-bottom: 1px solid #f0d78c;
  padding: 8px 24px;
  font-size: 13px;
  text-align: center;
}
.meta-bar {
  background: #f7f8fa;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 6px 24px;
  font-size: 12px;
  text-align: center;
}
.card.stale-widget {
  outline: 1px dashed #c9a227;
}

/* ------------------------------------------------------------------ */
/* Sesión: cerrar sesión                                               */
/* ------------------------------------------------------------------ */
.logout-form { margin: 0; }

.logout-btn {
  width: auto;
  margin: 0;
  padding: 7px 14px;
  border: 1px solid var(--maroon);
  border-radius: 8px;
  background: var(--maroon);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.logout-btn:hover { background: var(--maroon-light); }

.corner-logout {
  position: fixed;
  top: 16px;
  right: 16px;
  margin: 0;
  z-index: 5;
}
.corner-logout .logout-btn { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }
