/* =====================================================
   Asistente Legal v2.1 — app.css
   Design system & layout utilities
   ===================================================== */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,300..800;1,14..32,300..800&display=swap');

/* --- Variables --- */
:root {
  --font: 'Inter', system-ui, sans-serif;

  /* Neutrals */
  --bg:        #f8fafc;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --muted:     #94a3b8;
  --text:      #0f172a;
  --text-2:    #475569;

  /* Brand — Índigo/Violeta */
  --primary:   #6366f1;
  --primary-h: #4f46e5;
  --accent:    #8b5cf6;

  /* Status */
  --green:  #10b981;
  --yellow: #f59e0b;
  --red:    #ef4444;

  /* Layout */
  --sidebar-w: 16rem;
  --header-h:  60px;
  --radius:    .875rem;
  --radius-sm: .5rem;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px -1px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 28px rgba(0,0,0,.1), 0 4px 8px -4px rgba(0,0,0,.06);

  /* Gradients */
  --grad-primary: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --grad-accent:  linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  --grad-green:   linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* =====================================================
   LAYOUT
   ===================================================== */

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

/* App shell */
.app-shell {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem .875rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

/* Main content */
.app-main {
  flex: 1;
  padding: 1.75rem 2rem;
  overflow-x: hidden;
}

/* =====================================================
   COMPONENTS
   ===================================================== */

/* Brand logo */
.brand {
  display: flex;
  align-items: center;
  gap: .625rem;
  font-weight: 700;
  font-size: .95rem;
  line-height: 1.1;
  color: var(--text);
}
.brand-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: .625rem;
  background: var(--grad-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: .85rem;
  font-weight: 800;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(99,102,241,.35);
}
.brand-sub { font-size: .7rem; font-weight: 400; color: var(--muted); }

/* Search bar */
.search-bar {
  position: relative;
  flex: 1;
  max-width: 26rem;
}
.search-bar input {
  width: 100%;
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-size: .85rem;
  color: var(--text);
  outline: none;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.search-bar input:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.search-bar kbd {
  position: absolute;
  right: .625rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: .7rem;
  color: var(--muted);
  transition: opacity .15s;
}
.search-bar input:focus ~ kbd { opacity: 0; }

/* Search dropdown */
.search-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + .375rem);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  max-height: 28rem;
  overflow-y: auto;
}
.search-dropdown.open { display: block; }
.search-dropdown-group-label {
  padding: .5rem 1rem .25rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.search-dropdown-item {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .625rem 1rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background .1s;
}
.search-dropdown-item:hover,
.search-dropdown-item.focused { background: var(--bg); }
.search-dropdown-item-icon { font-size: 1rem; flex-shrink: 0; }
.search-dropdown-item-title {
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-dropdown-item-sub {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-dropdown-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .625rem 1rem;
  font-size: .8125rem;
  color: var(--primary);
  border-top: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  transition: background .1s;
}
.search-dropdown-footer:hover { background: var(--bg); }
.search-dropdown-empty {
  padding: 1.25rem 1rem;
  text-align: center;
  font-size: .875rem;
  color: var(--muted);
}

/* Nav */
.nav-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 0 .5rem;
  margin-bottom: .25rem;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text-2);
  transition: background .15s, color .15s, transform .15s;
}
.nav-link:hover {
  background: #f5f3ff;
  color: var(--primary);
  transform: translateX(2px);
}
.nav-link.active {
  background: var(--grad-primary);
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(99,102,241,.25);
}
/* Nav icons (SVG) */
.nav-icon {
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  opacity: .8;
  display: block;
}
.nav-link:hover .nav-icon   { opacity: 1; }
.nav-link.active .nav-icon  { opacity: 1; }

/* Usage widget */
.usage-widget {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: .8rem;
}
.usage-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .875rem;
}
.usage-widget-title { font-weight: 600; font-size: .78rem; }
.usage-bar-row { margin-bottom: .625rem; }
.usage-bar-label {
  display: flex;
  justify-content: space-between;
  color: var(--text-2);
  margin-bottom: .25rem;
}
.usage-track {
  height: .375rem;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  background: var(--grad-primary);
  border-radius: 99px;
}

/* Plan badge */
.plan-badge {
  font-size: .65rem;
  padding: .15rem .5rem;
  border-radius: 99px;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  color: var(--primary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Tabs */
.tab-nav {
  display: flex;
  border-bottom: 2px solid var(--border);
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .625rem 1.125rem;
  font-size: .875rem;
  font-weight: 500;
  color: #64748b;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover  { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tab-btn .tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 .3rem;
  background: #e2e8f0;
  color: #475569;
  border-radius: 99px;
  font-size: .6875rem;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.tab-btn.active .tab-badge { background: #ede9fe; color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, opacity .15s;
}
.btn:hover  { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--grad-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(99,102,241,.4); }
.btn-outline {
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: #f5f3ff; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-danger {
  background: var(--red);
  color: white;
  box-shadow: 0 2px 8px rgba(239,68,68,.2);
}
.btn-danger:hover { box-shadow: 0 4px 14px rgba(239,68,68,.35); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, border-color .2s;
}
.card:hover {
  box-shadow: var(--shadow-md);
  border-color: #d1d5db;
}

/* Stat card */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .2s;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-label {
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}
.stat-value {
  font-size: 1.875rem;
  font-weight: 800;
  margin-top: .25rem;
  background: var(--grad-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}
.stat-sub { font-size: .75rem; color: var(--text-2); margin-top: .125rem; }
.stat-accent { border-top: 3px solid var(--primary); padding-top: 1rem; }

/* Badge / Status pill */
.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: .25rem .625rem;
  border-radius: 99px;
  background: var(--bg);
  color: var(--text-2);
}
.badge-green  { background: #ecfdf5; color: #047857; }
.badge-yellow { background: #fffbeb; color: #92400e; }
.badge-red    { background: #fef2f2; color: #991b1b; }
.badge-blue   { background: #ede9fe; color: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; }
.dtable {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.dtable th {
  text-align: left;
  padding: .625rem .75rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.dtable td {
  padding: .75rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.dtable tr:last-child td { border-bottom: none; }
.dtable tr:hover td { background: #fafafe; }
.dtable .font-medium { color: var(--text); font-weight: 500; }

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.5rem;
}
.page-title { font-size: 1.375rem; font-weight: 700; }
.page-sub { font-size: .875rem; color: var(--text-2); margin-top: .125rem; }

/* Grid helpers */
.grid-stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr 1fr; }
.grid-3 { display: grid; gap: 1rem; grid-template-columns: repeat(3, 1fr); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 500; color: var(--text-2); margin-bottom: .375rem; }
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: .875rem;
  color: var(--text);
  outline: none;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.form-textarea { min-height: 6rem; resize: vertical; }
.form-error  { font-size: .75rem; color: var(--red);   margin-top: .25rem; }
.input-error,
.input-error-v { border-color: var(--red)   !important; box-shadow: 0 0 0 3px rgba(239,68,68,.12)  !important; }
.input-ok    { border-color: var(--green) !important; box-shadow: 0 0 0 3px rgba(16,185,129,.12)  !important; }
.req         { color: var(--red); }

/* Notifications drawer */
.notif-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,.25);
}
.notif-drawer-overlay.open { display: block; }
.notif-drawer {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: min(26rem, 100%);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.notif-drawer-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.notif-drawer-body { padding: 1rem 1.5rem; flex: 1; overflow-y: auto; }
.notif-item { padding: .875rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); margin-bottom: .625rem; font-size: .85rem; transition: background .15s; }
.notif-item.unread { background: #f5f3ff; border-color: #ddd6fe; border-left: 3px solid var(--primary); }
.notif-item-head { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; margin-bottom: .2rem; }
.notif-item-icon { flex-shrink: 0; }
.notif-item-title { font-weight: 600; flex: 1; }
.notif-item-time { font-size: .75rem; color: var(--muted); margin-left: auto; white-space: nowrap; }
.notif-item-msg { color: var(--text-2); font-size: .8rem; margin-top: .2rem; line-height: 1.4; }
.notif-item-link { display: inline-block; margin-top: .35rem; font-size: .78rem; color: var(--primary); font-weight: 500; }
.notif-read-btn { margin-top: .35rem; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .72rem; padding: .15rem .5rem; color: var(--text-2); cursor: pointer; }
.notif-read-btn:hover { background: var(--border); }
.notif-empty { text-align: center; color: var(--muted); font-size: .875rem; padding: 3rem 1rem; }
.notif-loading { padding: .5rem 0; }
.notif-skel { height: 3.5rem; background: var(--border); border-radius: var(--radius-sm); margin-bottom: .625rem; animation: skelPulse 1.2s ease-in-out infinite; }
@keyframes skelPulse { 0%,100%{opacity:1} 50%{opacity:.5} }

/* Toast */
.toast {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 99;
  padding: .75rem 1.25rem;
  background: var(--grad-primary);
  color: white;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
}
.toast.show { display: block; }

/* User avatar button */
.avatar-btn {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 99px;
  background: #ede9fe;
  border: 2px solid #ddd6fe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.avatar-btn:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

/* Notification bell */
.notif-btn {
  position: relative;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 99px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.notif-btn:hover {
  background: #f5f3ff;
  border-color: var(--primary);
}
.notif-badge {
  position: absolute;
  top: -.2rem; right: -.2rem;
  width: 1.1rem; height: 1.1rem;
  border-radius: 99px;
  background: var(--red);
  color: white;
  font-size: .6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =====================================================
   AUTH PAGES
   ===================================================== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 45%, #e0e7ff 100%);
}
.auth-box {
  width: 100%;
  max-width: 26rem;
}
.auth-card {
  background: var(--surface);
  border: 1px solid rgba(99,102,241,.15);
  border-radius: 1.25rem;
  padding: 2.25rem;
  box-shadow: 0 8px 40px rgba(99,102,241,.15), 0 1px 8px rgba(0,0,0,.05);
}
.auth-title { font-size: 1.5rem; font-weight: 700; margin-top: 1.25rem; }
.auth-sub { font-size: .875rem; color: var(--text-2); margin-top: .25rem; }
.auth-footer { margin-top: 1rem; text-align: center; font-size: .875rem; color: var(--text-2); }
.auth-footer a { color: var(--primary); font-weight: 600; }
.auth-footer a:hover { text-decoration: underline; }

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 900px) {
  .app-sidebar { display: none; }
  .app-main { padding: 1.25rem 1rem; }
  .search-bar { display: none; }
}

/* =====================================================
   UTILITIES
   ===================================================== */

/* Alertas / Flash messages */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  border: 1px solid;
  margin-bottom: 1rem;
  line-height: 1.5;
}
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info    { background: #ede9fe; border-color: #ddd6fe; color: #5b21b6; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* Estado vacío */
.empty-state { text-align: center; color: var(--muted); padding: 3rem 0; }

/* Etiqueta de sección (uppercase header de tarjeta) */
.section-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: .75rem;
}

/* Tarjeta sin padding */
.card-flush { padding: 0; overflow: hidden; }

/* Texto de ayuda bajo inputs */
.form-helper { font-size: .75rem; color: var(--muted); margin-top: .25rem; }

/* Botón de acción rápida del chat */
.btn-accion-rapida {
  display: block;
  width: 100%;
  text-align: left;
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: .375rem;
  background: white;
  cursor: pointer;
  font-size: .8rem;
  color: #475569;
  line-height: 1.35;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-accion-rapida:hover {
  background: #f5f3ff;
  border-color: #ddd6fe;
  color: var(--primary);
}

/* Burbujas del chat */
.chat-msg { display: flex; gap: .625rem; }
.chat-msg--user { flex-direction: row-reverse; }
.chat-avatar {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  color: white;
}
.chat-avatar--user { background: #334155; }
.chat-avatar--ai   { background: var(--grad-primary); }
.chat-body { flex: 1; max-width: 88%; }
.chat-ts { font-size: .78rem; color: #94a3b8; margin-bottom: .2rem; }
.chat-ts--user { text-align: right; }
.chat-bubble {
  padding: .625rem .875rem;
  border-radius: .5rem;
  font-size: .875rem;
  line-height: 1.55;
}
.chat-bubble--user {
  background: #334155;
  color: white;
  border-bottom-right-radius: .15rem;
}
.chat-bubble--ai {
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: .15rem;
}
.chat-tokens { font-size: .7rem; color: #cbd5e1; margin-top: .2rem; }

/* Botón de inserción de variable en panel de plantillas */
.btn-var-insert {
  display: block;
  width: 100%;
  text-align: left;
  padding: .3rem .5rem;
  font-size: .78rem;
  font-family: monospace;
  color: #4f46e5;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: .25rem;
  margin-bottom: .2rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-var-insert:hover { background: #ede9fe; }

/* Animaciones */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================
   MATERIA COMBOBOX — búsqueda + chips removibles
   ===================================================== */
.materia-combobox { position: relative; }

.materia-chips {
    display: flex; flex-wrap: wrap; gap: .375rem;
    margin-bottom: .5rem; min-height: 0;
}
.materia-chips:empty { margin-bottom: 0; }

.materia-chip {
    display: inline-flex; align-items: center; gap: .25rem;
    padding: .2rem .625rem; border-radius: 999px;
    background: #ede9fe; border: 1px solid #ddd6fe;
    color: var(--primary); font-size: .78rem; font-weight: 500;
}
.chip-remove {
    background: none; border: none; cursor: pointer;
    color: var(--primary); font-size: .85rem; line-height: 1;
    padding: 0 0 0 .125rem; opacity: .7;
}
.chip-remove:hover { opacity: 1; }

.materia-dropdown {
    display: none; position: absolute; z-index: 50;
    left: 0; right: 0; top: 100%; margin-top: .25rem;
    max-height: 220px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}
.materia-dropdown.open { display: block; }

.materia-option {
    padding: .5rem .75rem; cursor: pointer;
    font-size: .85rem; transition: background .1s;
}
.materia-option:hover { background: #f5f3ff; }

.materia-dropdown-empty {
    padding: .75rem; text-align: center;
    color: var(--muted); font-size: .82rem;
}

/* ---- IA Confirm Modal ---- */
.ia-modal-backdrop {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(15,23,42,.5);
    backdrop-filter: blur(5px);
    display: flex; align-items: center; justify-content: center;
    padding: 1.25rem;
    opacity: 0;
    animation: iaFadeIn .18s ease forwards;
}
@keyframes iaFadeIn { to { opacity: 1; } }

.ia-modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 32px 64px -12px rgba(0,0,0,.28), 0 0 0 1px rgba(0,0,0,.06);
    width: 100%; max-width: 27rem;
    padding: 1.875rem;
    transform: scale(.95) translateY(10px);
    animation: iaSlideIn .22s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes iaSlideIn { to { transform: scale(1) translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

.ia-modal-icon {
    width: 3.25rem; height: 3.25rem;
    background: linear-gradient(135deg,#f5f3ff,#ede9fe);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1.125rem;
    box-shadow: 0 0 0 6px #f5f3ff;
}
.ia-modal-title {
    font-size: 1.05rem; font-weight: 700; color: #0f172a;
    margin-bottom: .375rem;
}
.ia-modal-body {
    font-size: .875rem; color: #475569; line-height: 1.65;
    margin-bottom: 1rem;
}
.ia-modal-meta {
    display: flex; align-items: center; gap: .4rem;
    font-size: .78rem; color: var(--primary); font-weight: 500;
    background: #f5f3ff; border-radius: var(--radius-sm);
    border: 1px solid #ddd6fe;
    padding: .5rem .75rem; margin-bottom: 1.375rem;
}
.ia-modal-actions {
    display: flex; gap: .625rem; justify-content: flex-end;
}
.ia-modal-cancel {
    padding: .5625rem 1.125rem; border-radius: var(--radius-sm);
    border: 1.5px solid var(--border); background: transparent;
    font-size: .875rem; font-weight: 500; color: var(--text-2);
    cursor: pointer; transition: background .15s, border-color .15s;
    font-family: var(--font);
}
.ia-modal-cancel:hover { background: var(--bg); border-color: #cbd5e1; }
.ia-modal-confirm {
    display: flex; align-items: center; gap: .375rem;
    padding: .5625rem 1.25rem; border-radius: var(--radius-sm);
    border: none;
    background: var(--grad-primary);
    font-size: .875rem; font-weight: 600; color: #fff;
    cursor: pointer; transition: opacity .15s, box-shadow .15s;
    font-family: var(--font);
    box-shadow: 0 2px 8px rgba(99,102,241,.35);
}
.ia-modal-confirm:hover { opacity: .92; box-shadow: 0 4px 14px rgba(99,102,241,.45); }
.ia-modal-confirm:focus-visible,
.ia-modal-cancel:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px;
}
