:root {
  --bg: #090b11;
  --bg-2: #0f121b;
  --panel: #131724;
  --panel-2: #1a1f2f;
  --line: #262c40;
  --line-2: #323a52;
  --text: #f2ede2;
  --text-2: #b9b3a6;
  --muted: #7f7a70;
  --gold: #d9ae55;
  --gold-2: #f3d488;
  --gold-3: #a8792a;
  --gold-grad: linear-gradient(135deg, #f6dc94 0%, #d9ae55 45%, #a8792a 100%);
  --ivi: #e8732c;
  --ok: #5fbf8a;
  --warn: #e3b341;
  --danger: #e2675d;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Cinzel', 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold-2); }
button, input, textarea, select { font: inherit; color: inherit; }
::selection { background: rgba(217, 174, 85, 0.35); }

/* ---------- Componentes ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; font-weight: 500;
  transition: border-color .15s, background .15s, transform .05s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--gold-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-gold { background: var(--gold-grad); color: #1b1407; border: none; font-weight: 600; }
.btn-gold:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.btn-danger { border-color: rgba(226, 103, 93, .5); color: #f3a59e; background: transparent; }
.btn-danger:hover { background: rgba(226, 103, 93, .12); border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-2); }
.input, .textarea, .select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 13px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--gold-3); box-shadow: 0 0 0 3px rgba(217, 174, 85, .15); }
.textarea { resize: vertical; min-height: 90px; }
.hint { font-size: 12px; color: var(--muted); }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 14px; border: 1px solid; }
.alert-error { background: rgba(226, 103, 93, .1); border-color: rgba(226, 103, 93, .4); color: #f5b3ad; }
.alert-ok { background: rgba(95, 191, 138, .1); border-color: rgba(95, 191, 138, .4); color: #a9e3c3; }
.alert-warn { background: rgba(227, 179, 65, .1); border-color: rgba(227, 179, 65, .4); color: #f0d79a; }
.hidden { display: none !important; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap; }
.badge-ok { color: #a9e3c3; border-color: rgba(95, 191, 138, .45); background: rgba(95, 191, 138, .08); }
.badge-warn { color: #f0d79a; border-color: rgba(227, 179, 65, .45); background: rgba(227, 179, 65, .08); }
.badge-danger { color: #f5b3ad; border-color: rgba(226, 103, 93, .45); background: rgba(226, 103, 93, .08); }
.badge-gold { color: var(--gold-2); border-color: rgba(217, 174, 85, .5); background: rgba(217, 174, 85, .08); }

.ivi-sign { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; text-decoration: none; letter-spacing: .02em; }
.ivi-sign img { height: 22px; width: auto; }
.ivi-sign strong { color: var(--text-2); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: 11px; }

.gold-text { background: var(--gold-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.display { font-family: var(--display); letter-spacing: .08em; }

/* ---------- Auth (login / activar) ---------- */
.auth-page {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 32px 16px;
  background:
    radial-gradient(800px 500px at 50% -10%, rgba(217, 174, 85, .14), transparent 70%),
    radial-gradient(600px 400px at 50% 110%, rgba(232, 115, 44, .06), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 410px; background: rgba(19, 23, 36, .85); border: 1px solid var(--line);
  border-radius: 22px; padding: 30px 28px 24px; box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.auth-logo { display: block; width: 190px; max-width: 60%; margin: 0 auto 10px; filter: drop-shadow(0 8px 30px rgba(217, 174, 85, .18)); }
.auth-title { text-align: center; font-family: var(--display); font-size: 15px; letter-spacing: .28em; color: var(--text-2); margin: 0 0 22px; text-transform: uppercase; }
.auth-foot { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; justify-content: center; }
.auth-help { text-align: center; font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- Chat ---------- */
.app { display: grid; grid-template-columns: 290px 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 18px 16px 12px; display: flex; align-items: center; gap: 12px; }
.side-head img { width: 42px; height: 42px; object-fit: contain; }
.side-head .name { font-family: var(--display); font-size: 15px; letter-spacing: .12em; line-height: 1.2; }
.side-head .sub { font-size: 11px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }
.side-new { padding: 4px 14px 12px; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; min-height: 0; }
.conv-group { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; padding: 14px 10px 6px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; background: none; border: 1px solid transparent;
  border-radius: 10px; padding: 9px 10px; cursor: pointer; color: var(--text-2); font-size: 14px;
}
.conv-item:hover { background: var(--panel); color: var(--text); }
.conv-item.active { background: var(--panel-2); border-color: var(--line-2); color: var(--text); }
.conv-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .x { opacity: 0; border: none; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.conv-item:hover .x { opacity: 1; }
.conv-item .x:hover { color: var(--danger); background: rgba(226, 103, 93, .12); }
.side-foot { border-top: 1px solid var(--line); padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.usage { font-size: 12px; color: var(--text-2); }
.usage .bar { height: 5px; border-radius: 99px; background: var(--panel-2); overflow: hidden; margin-top: 6px; }
.usage .bar > i { display: block; height: 100%; background: var(--gold-grad); width: 0; transition: width .3s; }
.me { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--gold-grad); color: #1b1407; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.me .who { flex: 1; min-width: 0; font-size: 13px; line-height: 1.3; }
.me .who span { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: relative; }
.menu-pop {
  position: absolute; bottom: 42px; right: 0; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
  padding: 6px; min-width: 210px; box-shadow: var(--shadow); z-index: 20;
}
.menu-pop button, .menu-pop a { display: block; width: 100%; text-align: left; background: none; border: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--text); text-decoration: none; font-size: 14px; }
.menu-pop button:hover, .menu-pop a:hover { background: var(--panel-2); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative;
  background: radial-gradient(900px 500px at 60% -20%, rgba(217, 174, 85, .07), transparent 70%), var(--bg); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); min-height: 56px; }
.topbar .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; color: var(--text-2); }
.burger { display: none; }
.scrim { display: none; }

.thread { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
.thread-inner { max-width: 780px; margin: 0 auto; padding: 26px 20px 30px; }
.msg { display: flex; gap: 14px; margin: 0 0 22px; }
.msg .ico { width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center; margin-top: 2px; }
.msg.assistant .ico { background: radial-gradient(circle at 50% 40%, #2a2416, #0d0c09); border: 1px solid rgba(217, 174, 85, .45); }
.msg.assistant .ico img { width: 22px; height: 22px; object-fit: contain; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 15px; border-radius: 18px 18px 4px 18px; max-width: 80%; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .body { flex: 1; min-width: 0; padding-top: 3px; word-wrap: break-word; }
.body p { margin: 0 0 10px; }
.body p:last-child { margin-bottom: 0; }
.body ul, .body ol { margin: 0 0 10px; padding-left: 22px; }
.body li { margin: 3px 0; }
.body strong { color: var(--gold-2); font-weight: 600; }
.body code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.body blockquote { margin: 0 0 10px; padding: 6px 14px; border-left: 3px solid var(--gold-3); color: var(--text-2); background: rgba(217, 174, 85, .05); border-radius: 0 8px 8px 0; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); opacity: .4; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.msg-error { color: #f5b3ad; font-size: 14px; }

.empty { text-align: center; padding: 6vh 10px 10px; }
.empty img { width: 150px; max-width: 45%; filter: drop-shadow(0 10px 40px rgba(217, 174, 85, .25)); }
.empty h1 { font-family: var(--display); font-weight: 600; font-size: 22px; letter-spacing: .14em; margin: 14px 0 8px; }
.empty p { color: var(--text-2); max-width: 520px; margin: 0 auto 24px; }
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 600px; margin: 0 auto; }
.chip { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer; color: var(--text-2); font-size: 14px; transition: border-color .15s, color .15s; }
.chip:hover { border-color: var(--gold-3); color: var(--text); }
.chip b { display: block; color: var(--text); font-weight: 500; margin-bottom: 2px; }

.composer-wrap { padding: 10px 20px 18px; }
.composer { max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 22px; display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 16px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: var(--gold-3); box-shadow: 0 0 0 3px rgba(217, 174, 85, .12); }
.composer textarea { flex: 1; border: none; outline: none; background: transparent; resize: none; max-height: 200px; min-height: 24px; padding: 8px 0; line-height: 1.5; }
.send { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--gold-grad); color: #1b1407; cursor: pointer; display: grid; place-items: center; flex: none; }
.send:disabled { background: var(--panel-2); color: var(--muted); cursor: not-allowed; }
.send svg { width: 18px; height: 18px; }
.disclaimer { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.banner { max-width: 780px; margin: 0 auto 10px; }

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 84%; max-width: 310px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .app.nav-open .scrim { display: block; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 30; }
  .burger { display: inline-flex; }
  .chips { grid-template-columns: 1fr; }
  .thread-inner { padding: 18px 16px 24px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .msg.user .bubble { max-width: 88%; }
}

/* ---------- Mi proceso, propuestas y valoración ---------- */
.process-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 46%; background: var(--panel); border: 1px solid var(--line-2); border-radius: 999px; padding: 6px 14px 6px 10px; cursor: pointer; color: var(--text-2); font-size: 13px; }
.process-chip:hover { border-color: var(--gold-3); color: var(--text); }
.process-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.assistant .col { flex: 1; min-width: 0; }
.proposal { margin-top: 12px; border: 1px solid rgba(217, 174, 85, .45); background: rgba(217, 174, 85, .06); border-radius: 14px; padding: 12px 14px; }
.pc-k { font-size: 12px; color: var(--gold-2); letter-spacing: .04em; margin-bottom: 4px; }
.pc-t { color: var(--text); margin-bottom: 10px; }
.pc-a { display: flex; gap: 8px; flex-wrap: wrap; }
.pc-done { font-size: 13px; color: #a9e3c3; }
.msg-actions { display: flex; gap: 4px; margin-top: 6px; opacity: .55; transition: opacity .15s; }
.msg.assistant:hover .msg-actions, .msg-actions:has(.on) { opacity: 1; }
.vote { background: none; border: 1px solid transparent; border-radius: 8px; padding: 2px 7px; cursor: pointer; font-size: 14px; filter: grayscale(1); }
.vote:hover { background: var(--panel); border-color: var(--line); filter: none; }
.vote.on { filter: none; background: rgba(217, 174, 85, .12); border-color: rgba(217, 174, 85, .45); }
.modal.modal-wide { max-width: 600px; }
.journal { max-height: 300px; overflow-y: auto; border-top: 1px solid var(--line); padding-top: 8px; }
.j-item { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.j-h { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.j-h .x { margin-left: auto; border: none; background: none; color: var(--muted); cursor: pointer; }
.j-h .x:hover { color: var(--danger); }
.j-n { margin-top: 3px; }
@media (max-width: 860px) { .process-chip { max-width: 55%; } }

/* ---------- Selector de apariencia ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.theme-opt { position: relative; display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 14px; cursor: pointer; }
.theme-opt:has(input:checked) { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.theme-opt input { position: absolute; top: 14px; right: 14px; accent-color: var(--gold); }
.theme-sw { display: flex; gap: 0; border-radius: 6px; overflow: hidden; height: 28px; width: 120px; border: 1px solid var(--line); }
.theme-sw i { flex: 1; }
.theme-n { font-weight: 600; margin-top: 4px; }
.theme-d { font-size: 13px; color: var(--text-2); }
.theme-l { font-size: 12.5px; }

/* ---------- Admin ---------- */
.admin { min-height: 100%; }
.admin-head { display: flex; align-items: center; gap: 14px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--bg-2); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.admin-head img { height: 40px; }
.admin-head .brand { font-family: var(--display); letter-spacing: .12em; font-size: 15px; line-height: 1.2; }
.admin-head .brand span { display: block; font-family: var(--font); font-size: 11px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }
.admin-head .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--bg-2); overflow-x: auto; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 12px 14px; cursor: pointer; color: var(--text-2); white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold-2); border-bottom-color: var(--gold); }
.admin-body { padding: 24px; max-width: 1280px; margin: 0 auto; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.stat .v { font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; background: var(--bg-2); position: sticky; top: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }
tbody tr.click { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.chart .b { flex: 1; max-width: 32px; background: var(--gold-grad); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.chart .b:hover { opacity: 1; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.drawer-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: var(--bg-2); border-left: 1px solid var(--line-2); z-index: 51; overflow-y: auto; box-shadow: var(--shadow); }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-2); z-index: 2; }
.drawer-head h2 { margin: 0; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.drawer-body { padding: 20px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.transcript .msg { margin-bottom: 14px; }
.transcript .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px dashed var(--gold-3); border-radius: 10px; padding: 10px 12px; margin: 8px 0 14px; }
.copybox code { flex: 1; word-break: break-all; font-size: 13px; color: var(--gold-2); }
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 18px; border-radius: 999px; z-index: 100; box-shadow: var(--shadow); font-size: 14px; }
@media (max-width: 760px) {
  .admin-body { padding: 16px; }
  .cols-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .tabs, .admin-head { padding-left: 16px; padding-right: 16px; }
}
