/* ==========================================================================
   Barbara — Design System
   Basado en barbara.html: editorial, calido, tipografia serif+sans.
   Sin dependencias externas. Todo local.
   ========================================================================== */

/* --- Design tokens --- */
:root {
  --paper: #F4EEE3;
  --paper-2: #EDE5D6;
  --paper-3: #FBF7EF;
  --ink: #1C1813;
  --ink-soft: #52493D;
  --ink-muted: #8A7F72;
  --ember: #E4572E;
  --ember-deep: #C3431F;
  --pine: #13453A;
  --pine-2: #0C2E27;
  --butter: #EEBC4E;
  --line: rgba(28,24,19,.14);
  --line-soft: rgba(28,24,19,.08);
  --ok: #3CAE6B;
  --danger: #DC4A3A;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'IBM Plex Sans', -apple-system, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 14px;
  --radius-lg: 22px;
  --radius-full: 100px;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* grain texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: .03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--ember); color: var(--paper); }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; background: none; border: none; padding: 0; color: inherit; }
input, textarea, select { font-family: inherit; border-color: var(--line); }

/* --- Typography --- */
.font-sans { font-family: var(--sans); }
.font-serif { font-family: var(--serif); }
.font-mono { font-family: var(--mono); }
.font-display { font-family: var(--serif); }

h1, h2, h3 {
  font-family: var(--serif);
  letter-spacing: -.02em;
  line-height: 1.08;
}
h1 { font-weight: 340; font-size: clamp(32px, 5vw, 56px); }
h2 { font-weight: 360; font-size: clamp(24px, 3.5vw, 40px); }
h3 { font-weight: 500; font-size: 21px; }
h1 em, h2 em { font-style: italic; color: var(--ember); font-weight: 420; }

/* --- Buttons (barbara style) --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5em;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 20px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--ink);
  cursor: pointer;
  transition: transform .25s cubic-bezier(.2,.8,.2,1), background .25s, color .25s, box-shadow .25s;
  white-space: nowrap;
  background: transparent;
  color: var(--ink);
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn-fill {
  background: var(--ink);
  color: var(--paper);
  box-shadow: 3px 3px 0 rgba(28,24,19,.18);
}
.btn-fill:hover { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--ember); }
.btn-ember {
  background: var(--ember);
  border-color: var(--ember);
  color: #fff;
  box-shadow: 3px 3px 0 rgba(196,67,31,.35);
}
.btn-ember:hover { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--pine); }
.btn-pine {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--paper);
}
.btn-pine:hover { background: var(--pine-2); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }

/* --- HTMX loading states --- */
.btn.htmx-request,
button.htmx-request,
form.htmx-request button[type="submit"] {
  pointer-events: none;
  opacity: .65;
  position: relative;
}
.btn.htmx-request::after,
button.htmx-request::after,
form.htmx-request button[type="submit"]::after {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: htmx-spin .6s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}
@keyframes htmx-spin { to { transform: rotate(360deg); } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }

/* --- Cards (barbara style) --- */
.card {
  background: var(--paper-3);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 6px 8px 0 rgba(28,24,19,.08);
  overflow: hidden;
}
.card-soft {
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* --- Forms (barbara style) --- */
.input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--paper-3);
  color: var(--ink);
  font-size: 15px;
  transition: border-color .2s, box-shadow .2s;
}
.input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(28,24,19,.08);
}
.input::placeholder { color: var(--ink-muted); }
.label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

/* --- Sidebar (app layout) --- */
.sidebar {
  background: var(--ink);
  color: var(--paper);
  width: 260px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  transition: transform .25s cubic-bezier(.2,.8,.2,1);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 22px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 21px;
}
.sidebar-logo .mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--ember);
  color: var(--paper);
  display: grid;
  place-items: center;
  font-size: 18px;
  transform: rotate(-4deg);
  transition: transform .3s;
}
.sidebar-logo:hover .mark { transform: rotate(4deg) scale(1.05); }
.sidebar-logo .org {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 400;
  color: rgba(244,238,227,.5);
  display: block;
  margin-top: 1px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 12px; }
.sidebar-nav .new-chat {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px dashed rgba(244,238,227,.25);
  border-radius: 12px;
  color: rgba(244,238,227,.7);
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  margin-bottom: 12px;
  transition: background .2s, border-color .2s, color .2s;
}
.sidebar-nav .new-chat:hover {
  background: rgba(244,238,227,.08);
  border-color: rgba(244,238,227,.4);
  color: var(--paper);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(244,238,227,.6);
  transition: background .2s, color .2s;
  margin-bottom: 2px;
}
.nav-link:hover {
  background: rgba(244,238,227,.08);
  color: var(--paper);
}
.nav-link.active {
  background: rgba(244,238,227,.12);
  color: var(--paper);
  font-weight: 600;
}
.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .7;
}
.nav-link.active svg { opacity: 1; }
.nav-link .badge-count {
  margin-left: auto;
  background: var(--ember);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.conv-link {
  display: block;
  padding: 5px 14px 5px 42px;
  font-size: 12px;
  color: rgba(244,238,227,.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 6px;
  transition: background .2s, color .2s;
}
.conv-link:hover { background: rgba(244,238,227,.06); color: rgba(244,238,227,.7); }
.conv-link.active { background: rgba(244,238,227,.1); color: var(--paper); font-weight: 500; }

.sidebar-user {
  border-top: 1px solid rgba(244,238,227,.1);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-user .name { font-size: 14px; font-weight: 500; color: rgba(244,238,227,.9); }
.sidebar-user .email { font-size: 11px; color: rgba(244,238,227,.4); }
.sidebar-user .logout {
  padding: 6px;
  border-radius: 8px;
  color: rgba(244,238,227,.4);
  transition: background .2s, color .2s;
}
.sidebar-user .logout:hover { background: rgba(244,238,227,.1); color: var(--paper); }

/* --- Main content area --- */
.app-main {
  margin-left: 260px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.app-content {
  flex: 1;
  overflow-y: auto;
}

/* Mobile */
.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--paper);
}
.mobile-header .hamburger {
  background: none;
  border: none;
  padding: 6px;
  border-radius: 8px;
  color: var(--ink);
}
.mobile-header .hamburger:hover { background: var(--paper-2); }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(28,24,19,.5);
  backdrop-filter: blur(4px);
  z-index: 40;
}

@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .app-main { margin-left: 0; }
  .mobile-header { display: flex; }
}

/* --- Page sections --- */
.page-header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.page-header h1 { font-size: 28px; }
.page-body { padding: 24px 32px; }
.page-body-narrow { max-width: 1200px; margin: 0 auto; padding: 24px 32px; }

/* --- Chat --- */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}
.chat-msg {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  max-width: 85%;
}
.chat-msg.user { margin-left: auto; flex-direction: row-reverse; }
.chat-msg .avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}
.chat-msg.bot .avatar { background: var(--pine); color: var(--paper); }
.chat-msg.user .avatar { background: var(--ink); color: var(--paper); }
.chat-msg .bubble {
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
}
.chat-msg.bot .bubble {
  background: var(--paper-2);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 6px;
  color: var(--ink);
}
.chat-msg.user .bubble {
  background: var(--ink);
  color: var(--paper);
  border-bottom-right-radius: 6px;
}
.chat-msg .bubble b { color: var(--ember-deep); }
.chat-msg.user .bubble b { color: var(--butter); }

.chat-input-area {
  border-top: 1px solid var(--line-soft);
  background: var(--paper);
  padding: 16px;
}
.chat-input-box {
  position: relative;
}
.chat-input-box textarea {
  width: 100%;
  padding: 14px 54px 14px 18px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--paper-3);
  color: var(--ink);
  font-size: 15px;
  font-family: var(--sans);
  resize: none;
  min-height: 52px;
  max-height: 200px;
  transition: border-color .2s;
}
.chat-input-box textarea:focus {
  outline: none;
  border-color: var(--ink);
}
.chat-input-box .send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  display: grid;
  place-items: center;
  transition: background .2s, transform .2s;
}
.chat-input-box .send-btn:hover { background: var(--ember); transform: scale(1.05); }

/* --- Approval card (inline in chat) --- */
.approval-card {
  margin-top: 12px;
  background: var(--paper-3);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.approval-card .action-type {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--pine);
  background: rgba(19,69,58,.1);
  padding: 3px 10px;
  border-radius: 6px;
  letter-spacing: .02em;
}
.approval-card .actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(244,238,227,.4); }

/* --- Alerts --- */
.alert {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  border: 1px solid;
}
.alert-ok { background: rgba(60,174,107,.1); border-color: rgba(60,174,107,.2); color: #1a6b3a; }
.alert-error { background: rgba(220,74,58,.1); border-color: rgba(220,74,58,.2); color: #9a2c22; }
.alert-warn { background: rgba(238,188,78,.15); border-color: rgba(238,188,78,.3); color: #7a5c14; }
.alert-info { background: rgba(19,69,58,.08); border-color: rgba(19,69,58,.15); color: var(--pine); }

/* --- Eyebrow / section labels (from barbara.html) --- */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ember-deep);
}
.eyebrow::before {
  content: "";
  width: 24px;
  height: 1.5px;
  background: var(--ember);
}

/* --- Badge --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: var(--paper-2);
  border: 1px solid var(--line);
}
.badge-ember { background: rgba(228,87,46,.1); color: var(--ember-deep); border-color: rgba(228,87,46,.2); }
.badge-pine { background: rgba(19,69,58,.1); color: var(--pine); border-color: rgba(19,69,58,.2); }
.badge-ok { background: rgba(60,174,107,.1); color: #1a6b3a; border-color: rgba(60,174,107,.2); }

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
.tab {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  transition: color .2s, border-color .2s;
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ember-deep); border-bottom-color: var(--ember); font-weight: 600; }

/* --- Settings / form sections --- */
.settings-section {
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 20px;
}
.settings-section h3 {
  font-size: 19px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

/* --- Utility overrides for Tailwind compat --- */
.h-full { height: 100%; }
.min-h-full { min-height: 100%; }
.w-full { width: 100%; }
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.hidden { display: none; }
.block { display: block; }
.inline-flex { display: inline-flex; }
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-center { text-align: center; }
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }

/* Text sizes */
.text-xs { font-size: 12px; line-height: 1.4; }
.text-sm { font-size: 14px; line-height: 1.4; }
.text-lg { font-size: 18px; line-height: 1.5; }
.text-xl { font-size: 20px; }
.text-2xl { font-size: 24px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* Spacing */
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }
.p-6 { padding: 24px; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.px-6 { padding-left: 24px; padding-right: 24px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.mr-3 { margin-right: 12px; }
.space-y-4 > * + * { margin-top: 16px; }
.space-y-6 > * + * { margin-top: 24px; }

/* Alpine.js */
[x-cloak] { display: none !important; }

/* Scrollbar */
.scrollbar-thin::-webkit-scrollbar { width: 4px; }
.scrollbar-thin::-webkit-scrollbar-track { background: transparent; }
.scrollbar-thin::-webkit-scrollbar-thumb { background: rgba(244,238,227,.2); border-radius: 4px; }

/* --- Auth pages (login/signup) --- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--paper);
}
@media (max-width: 768px) { .auth-wrap { grid-template-columns: 1fr; } }
.auth-brand {
  background: var(--ink);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px;
  position: relative;
  overflow: hidden;
}
@media (max-width: 768px) { .auth-brand { display: none; } }
.auth-brand::after {
  content: "";
  position: absolute;
  right: -100px;
  top: -100px;
  width: 350px;
  height: 350px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(228,87,46,.25), transparent 65%);
}
.auth-brand h1 { color: var(--paper); font-size: 42px; max-width: 10ch; position: relative; z-index: 1; }
.auth-brand h1 em { color: var(--butter); }
.auth-brand .tagline { color: rgba(244,238,227,.6); font-size: 17px; margin-top: 18px; max-width: 28ch; position: relative; z-index: 1; }
.auth-form {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
}
.auth-form-inner {
  width: 100%;
  max-width: 380px;
}
.auth-form-inner .logo-mobile {
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
}
@media (max-width: 768px) { .auth-form-inner .logo-mobile { display: flex; } }
.auth-form-inner h2 {
  font-size: 28px;
  margin-bottom: 6px;
}
.auth-form-inner .sub {
  color: var(--ink-soft);
  font-size: 15px;
  margin-bottom: 28px;
}
.auth-form-inner .field { margin-bottom: 18px; }
.auth-form-inner .divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
  font-size: 13px;
  color: var(--ink-muted);
}
.auth-form-inner .divider::before,
.auth-form-inner .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.auth-form-inner .google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  background: var(--paper-3);
  transition: border-color .2s, background .2s;
}
.auth-form-inner .google-btn:hover { border-color: var(--ink); background: var(--paper-2); }
.auth-form-inner .footer-link {
  text-align: center;
  margin-top: 24px;
  font-size: 14px;
  color: var(--ink-soft);
}
.auth-form-inner .footer-link a { color: var(--ember); font-weight: 600; }
.auth-form-inner .footer-link a:hover { text-decoration: underline; }

/* --- Reveal animation (from barbara.html) --- */
.rv { opacity: 0; transform: translateY(18px); transition: opacity .6s ease, transform .6s cubic-bezier(.2,.8,.2,1); }
.rv.in { opacity: 1; transform: none; }
.d1 { transition-delay: .08s; }
.d2 { transition-delay: .16s; }
.d3 { transition-delay: .24s; }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-soft);
}
.empty-state .ico {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  color: var(--ink-muted);
}
.empty-state h3 { color: var(--ink); margin-bottom: 6px; }
.empty-state p { font-size: 14px; max-width: 320px; margin: 0 auto; }
