@font-face {
  font-family: "Poppins";
  src: url("/fonts/poppins-300.ttf") format("truetype");
  font-style: normal;
  font-weight: 300;
  font-display: swap;
}

@font-face {
  font-family: "Poppins";
  src: url("/fonts/poppins-400.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Poppins";
  src: url("/fonts/poppins-500.ttf") format("truetype");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Poppins";
  src: url("/fonts/poppins-600.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Poppins";
  src: url("/fonts/poppins-700.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: "Poppins", Montserrat, Arial, sans-serif;
  color: #183847;
  background: #f5f9fb;
  --santus: #2170b3;
  --santus-dark: #185d98;
  --deep: #183847;
  --mid: #3387b4;
  --sky: #7ecbdf;
  --sage: #cfe5ca;
  --ink: #183847;
  --muted: #627985;
  --line: #d8e5eb;
  --surface: #ffffff;
  --soft-blue: #eef7fb;
  --soft-sage: #f0f7ee;
  --warning: #fff7df;
  --shadow: 0 20px 60px rgba(24, 56, 71, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 4% 0%, rgba(126, 203, 223, 0.22), transparent 31rem),
    radial-gradient(circle at 96% 8%, rgba(207, 229, 202, 0.34), transparent 29rem),
    #f5f9fb;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(480px, 100%);
  padding: 42px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.isotype { width: 92px; height: auto; flex-shrink: 0; }

.brand-name {
  color: var(--deep);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.brand-tagline { margin: 3px 0 0; color: var(--muted); font-size: 0.72rem; font-weight: 300; letter-spacing: 0.03em; }

.login-card h1 { margin: 7px 0 12px; font-size: clamp(2.15rem, 8vw, 3.25rem); line-height: 1.08; }
.login-card form { margin-top: 30px; display: grid; gap: 10px; }
.login-card label { margin-top: 8px; color: var(--deep); font-size: 0.8rem; font-weight: 600; }
.login-card button { margin-top: 13px; }
.form-error { margin: 8px 0 0; color: #7b2e29; background: #fbe9e7; padding: 11px 13px; border-radius: 10px; }

.app-shell { width: min(1380px, calc(100% - 40px)); margin: 32px auto; }
header { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 24px; }
header .brand-lockup { margin-bottom: 0; align-items: flex-start; }
header .isotype { margin-top: 6px; }
header h1 { font-size: clamp(1.9rem, 4vw, 2.9rem); }
h1, h2, h3 { color: var(--deep); font-family: "Poppins", Montserrat, Arial, sans-serif; }
h1 { margin: 4px 0 7px; font-size: clamp(2.2rem, 5vw, 3.65rem); font-weight: 700; line-height: 1.02; letter-spacing: -0.045em; }
h2 { margin: 4px 0; font-size: 1.35rem; font-weight: 700; }
.subtitle { max-width: 680px; color: var(--muted); font-size: 0.95rem; font-weight: 300; margin: 0; }
.eyebrow { color: var(--santus); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.17em; text-transform: uppercase; margin: 0; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.status { white-space: nowrap; border: 1px solid #b9d7df; border-radius: 999px; padding: 8px 13px; color: var(--deep); font-size: 0.75rem; font-weight: 500; background: #f2fafc; }
.status i { display: inline-block; width: 8px; height: 8px; background: var(--santus); border-radius: 50%; margin-right: 7px; box-shadow: 0 0 0 4px rgba(33, 112, 179, 0.1); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(290px, 360px); gap: 20px; align-items: start; }
.editor-column { min-width: 0; }
.conversation, #composer, .approval, .history-panel { background: rgba(255, 255, 255, 0.97); border: 1px solid var(--line); box-shadow: 0 16px 45px rgba(24, 56, 71, 0.065); }
.conversation { min-height: 470px; max-height: 62vh; overflow: auto; padding: 25px; border-radius: 22px 22px 0 0; scroll-behavior: smooth; }

.message { max-width: 91%; padding: 16px 18px; border-radius: 17px; margin: 0 0 15px; color: var(--deep); background: var(--soft-blue); border: 1px solid #dcebf1; }
.message.assistant { border-left: 4px solid var(--santus); background: #fff; box-shadow: 0 10px 28px rgba(24, 56, 71, 0.055); }
.message.user { width: fit-content; max-width: 78%; margin-left: auto; color: #fff; background: var(--deep); border-color: var(--deep); border-bottom-right-radius: 5px; }
.message.tool { width: fit-content; padding: 9px 13px; color: var(--deep); background: var(--soft-sage); border-color: #d6e8d2; font-size: 0.78rem; }
.message.error { color: #7b2e29; background: #fbe9e7; border-color: #efcbc7; }
.message > span { display: block; margin-bottom: 8px; color: var(--santus); font-size: 0.65rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }
.message.user > span, .message.error > span { color: inherit; opacity: 0.72; }
.message.tool > span { display: none; }
.message-content { min-width: 0; font-size: 0.94rem; font-weight: 400; line-height: 1.68; overflow-wrap: anywhere; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0 0 12px; }
.message-content h2 { margin: 20px 0 9px; font-size: 1.22rem; }
.message-content h3 { margin: 18px 0 8px; color: var(--santus); font-size: 1rem; font-weight: 600; }
.message-content strong { color: var(--deep); font-weight: 600; }
.message-content code { padding: 2px 7px; color: var(--santus-dark); background: #eaf4fa; border: 1px solid #d0e5f0; border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.87em; }
.message-content pre { margin: 13px 0; padding: 14px; overflow: auto; color: #eef8fb; background: var(--deep); border-radius: 12px; }
.message-content pre code { padding: 0; color: inherit; background: transparent; border: 0; }
.message-content a { color: var(--santus); font-weight: 600; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.message-content a:hover { color: var(--santus-dark); }
.message-note { padding: 10px 12px; color: var(--muted); background: var(--soft-sage); border-radius: 10px; font-size: 0.83rem; }
.message-content blockquote { margin: 13px 0; padding: 10px 14px; color: var(--muted); background: #f7fafb; border-left: 3px solid var(--sky); }

.message-content > ul { margin: 10px 0 13px; padding-left: 21px; }
.message-content > ul li { margin: 6px 0; }
.message-content > ul li::marker { color: var(--santus); }
.message-content > ol { display: grid; gap: 10px; margin: 13px 0; padding: 0; list-style: none; counter-reset: santus-item; }
.message-content > ol > li { position: relative; min-height: 48px; padding: 13px 14px 13px 51px; background: #f7fbfd; border: 1px solid #dcebf1; border-radius: 13px; counter-increment: santus-item; }
.message-content > ol > li::before { content: counter(santus-item); position: absolute; top: 12px; left: 13px; display: grid; place-items: center; width: 26px; height: 26px; color: #fff; background: var(--santus); border-radius: 8px; font-size: 0.72rem; font-weight: 600; }
.message-content li > ul { margin: 9px 0 0; padding-left: 18px; color: var(--muted); }
.message-content li > ul li { margin: 4px 0; }
.message-content li > ul li::marker { color: var(--mid); }

.table-scroll { margin: 14px 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
.message-content table { width: 100%; border-collapse: collapse; background: #fff; font-size: 0.82rem; }
.message-content th { padding: 11px 12px; color: #fff; background: var(--deep); font-weight: 600; text-align: left; white-space: nowrap; }
.message-content td { padding: 11px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.message-content tbody tr:nth-child(even) { background: #f7fbfd; }

.approval { margin: 13px 0; padding: 21px; border-radius: 17px; border-color: #ead394; background: var(--warning); }
.approval dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 15px; margin: 15px 0; }
.approval dt { color: var(--muted); font-size: 0.82rem; text-transform: capitalize; }
.approval dd { margin: 0; color: var(--deep); font-weight: 600; overflow-wrap: anywhere; }
.approval-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; }

#composer { padding: 17px; border-radius: 0 0 22px 22px; border-top: 0; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; background: #fff; color: var(--ink); outline: none; }
input:focus, textarea:focus { border-color: var(--santus); box-shadow: 0 0 0 4px rgba(33, 112, 179, 0.11); }
textarea { resize: vertical; min-height: 88px; line-height: 1.55; }
.composer-footer { display: flex; justify-content: space-between; align-items: center; gap: 13px; margin-top: 11px; }
small { color: var(--muted); font-size: 0.72rem; }

.history-panel { border-radius: 22px; padding: 18px; position: sticky; top: 18px; max-height: calc(100vh - 36px); overflow: hidden; }
.history-heading { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.history-list { max-height: calc(100vh - 150px); overflow: auto; padding-top: 11px; }
.history-entry { border-left: 3px solid var(--sky); padding: 9px 0 9px 12px; margin-bottom: 7px; }
.history-entry.user { border-color: var(--santus); }
.history-entry.approval { border-color: #d39a26; }
.history-entry.tool { border-color: var(--mid); }
.history-entry > div { display: flex; justify-content: space-between; gap: 8px; }
.history-entry strong { color: var(--deep); font-size: 0.67rem; font-weight: 600; text-transform: uppercase; }
.history-entry time { color: var(--muted); font-size: 0.62rem; white-space: nowrap; }
.history-entry p { margin: 5px 0 0; color: #58707c; font-size: 0.77rem; font-weight: 300; line-height: 1.42; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.empty { color: var(--muted); font-size: 0.84rem; }

.primary, .secondary, .danger-safe { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 500; transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease; }
.primary { color: #fff; background: var(--santus); box-shadow: 0 8px 20px rgba(33, 112, 179, 0.2); }
.primary:hover { background: var(--santus-dark); transform: translateY(-1px); }
.secondary { color: var(--deep); background: #edf3f5; }
.secondary:hover { background: #e2ecef; }
.danger-safe { color: #fff; background: var(--deep); }
.danger-safe:hover { background: #0f2a36; }
.compact { padding: 8px 11px; font-size: 0.75rem; }
button:disabled { opacity: 0.5; cursor: wait; transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* --- Acciones rápidas ------------------------------------------------- */

.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  border: 1px solid #c9e0ea;
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--deep);
  background: #f2fafc;
  font-size: 0.78rem;
  font-weight: 500;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}
.chip:hover { background: #e6f4f9; border-color: var(--sky); transform: translateY(-1px); }

/* --- Adjuntos de referencia ------------------------------------------- */

#composer.dropping { outline: 2px dashed var(--santus); outline-offset: -6px; }
.composer-footer { flex-wrap: wrap; }
.composer-tools { display: flex; gap: 7px; align-items: center; }
.composer-send { display: flex; gap: 13px; align-items: center; margin-left: auto; }

.attachment-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f7fbfd;
  max-width: 250px;
}
.attachment-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 7px; }
.attachment-chip span { font-size: 0.72rem; color: var(--deep); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { border: 0; background: transparent; color: var(--muted); font-size: 0.82rem; padding: 3px 5px; border-radius: 6px; }
.attachment-chip button:hover { color: #7b2e29; background: #fbe9e7; }

.message-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.message-attachments img { width: 92px; height: 92px; object-fit: cover; border-radius: 11px; border: 1px solid rgba(255, 255, 255, 0.35); }

/* --- Aprobación -------------------------------------------------------- */

.approval dd.wide { grid-column: 1 / -1; font-weight: 400; font-size: 0.85rem; background: rgba(255, 255, 255, 0.65); border-radius: 9px; padding: 8px 10px; }
.approval-note { margin: 10px 0 0; padding: 9px 12px; color: var(--deep); background: var(--soft-blue); border-left: 3px solid var(--sky); border-radius: 8px; font-size: 0.8rem; }

.history-author { display: inline-block; margin-top: 4px; color: var(--santus); font-size: 0.62rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }

/* --- Cupo diario de modificaciones ------------------------------------- */

.quota-pill {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #cfe4ee;
  background: var(--soft-blue);
  color: var(--deep);
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
}
.quota-pill.low { background: #fff7df; border-color: #ead394; color: #7a5b12; }
.quota-pill.empty { background: #fbe9e7; border-color: #efcbc7; color: #7b2e29; }

/* --- Panel lateral: pestañas Historial/Páginas -------------------------- */

.side-tabs { display: flex; gap: 6px; }
.side-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  color: var(--deep);
  background: #fff;
  font-size: 0.76rem;
  font-weight: 500;
}
.side-tab.active { color: #fff; background: var(--deep); border-color: var(--deep); }

.page-card {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 13px;
  margin-bottom: 9px;
  background: #f9fcfd;
}
.page-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.page-card-top strong { color: var(--deep); font-size: 0.85rem; font-weight: 600; line-height: 1.3; }
.page-card small { display: block; margin-top: 3px; color: var(--muted); font-size: 0.68rem; }
.page-card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.page-card-actions button { font-size: 0.7rem; padding: 6px 9px; }
.page-card-link { display: inline-block; margin-top: 8px; color: var(--santus); font-size: 0.72rem; font-weight: 600; text-decoration: none; }
.page-card-link:hover { text-decoration: underline; }

/* --- Administración ---------------------------------------------------- */

.admin-shell { display: grid; gap: 16px; }
.admin-tabs { display: flex; gap: 7px; flex-wrap: wrap; }
.admin-tabs .tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 17px;
  color: var(--deep);
  background: #fff;
  font-size: 0.8rem;
  font-weight: 500;
}
.admin-tabs .tab.active { color: #fff; background: var(--deep); border-color: var(--deep); }

.admin-panel {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 16px 45px rgba(24, 56, 71, 0.065);
}
.admin-panel-heading { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; }
.admin-audit-tools { display: flex; gap: 8px; align-items: center; }
.admin-audit-tools select { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: #fff; color: var(--deep); font-size: 0.78rem; }

.admin-form { margin-bottom: 18px; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: #f7fbfd; }
.admin-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.admin-form label { display: block; margin-bottom: 5px; color: var(--deep); font-size: 0.75rem; font-weight: 600; }
.admin-form select { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; background: #fff; color: var(--ink); }
.admin-form-submit { display: flex; }
.admin-form-submit button { width: 100%; }
.settings-hint { margin: 12px 0 0; color: var(--muted); font-size: 0.78rem; font-weight: 300; }
.settings-saved { margin: 10px 0 0; padding: 10px 13px; color: #2c5a35; background: var(--soft-sage); border: 1px solid #b9d8b2; border-radius: 10px; font-size: 0.82rem; }

.admin-table { margin: 0; }
.admin-table table { font-size: 0.8rem; }
.admin-table td.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-table td.empty { text-align: center; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--deep);
  border: 1px solid #cfe4ee;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge.good { background: var(--soft-sage); border-color: #b9d8b2; color: #2c5a35; }
.badge.warn { background: #fff7df; border-color: #ead394; color: #7a5b12; }
.badge.bad { background: #fbe9e7; border-color: #efcbc7; color: #7b2e29; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .history-panel { position: static; max-height: 430px; }
  .history-list { max-height: 335px; }
  .conversation { max-height: 64vh; }
}

@media (max-width: 620px) {
  .app-shell { margin: 19px auto; width: min(100% - 18px, 1380px); }
  .login-card { padding: 29px 23px; }
  header, .header-actions { align-items: stretch; flex-direction: column; }
  header { gap: 16px; }
  .brand-name { margin-bottom: 17px; }
  .conversation { padding: 13px; border-radius: 17px 17px 0 0; }
  .message { max-width: 100%; padding: 14px; }
  .message.user { max-width: 92%; }
  .message-content > ol > li { padding-right: 11px; }
  .approval-actions, .composer-footer { align-items: stretch; flex-direction: column; }
  .approval-actions button { width: 100%; }
  #composer { border-radius: 0 0 17px 17px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
