/* =====================================================================
   AI Companion · tema oscuro con acentos violeta
   ===================================================================== */
:root {
    --bg: #07070b;
    --bg-2: #0c0c12;
    --surface: #111118;
    --surface-2: #171720;
    --surface-3: #1e1e29;
    --border: #262633;
    --border-strong: #34344a;
    --text: #ebe9f5;
    --text-2: #c4c1d6;
    --muted: #8a87a0;
    --primary: #8b5cf6;
    --primary-2: #7c3aed;
    --violet: #a855f7;
    --lilac: #c4b5fd;
    --glow: rgba(139, 92, 246, .35);
    --ok: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --info: #60a5fa;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --sidebar-w: 248px;
    --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
    --ease: cubic-bezier(.22, .8, .3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(139, 92, 246, .12), transparent 60%),
        radial-gradient(700px 400px at -10% 110%, rgba(168, 85, 247, .08), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
small { font-size: .8rem; }
[hidden] { display: none !important; }
::selection { background: var(--primary); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--muted); }
.small { font-size: .86rem; }
.mono { font-family: var(--mono); font-size: .85em; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.link { color: var(--lilac); font-weight: 500; transition: color .2s; }
.link:hover { color: #fff; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon-xs { width: 13px; height: 13px; }
.icon-xl { width: 46px; height: 46px; color: var(--primary); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
    display: flex; flex-direction: column; gap: 1.25rem; padding: 1.25rem 1rem;
    background: linear-gradient(180deg, rgba(17, 17, 24, .97), rgba(10, 10, 15, .97));
    border-right: 1px solid var(--border);
    transition: transform .35s var(--ease);
}
.brand { display: flex; align-items: center; gap: .65rem; font-weight: 700; font-size: 1.08rem; padding: .25rem .5rem; letter-spacing: -.01em; }
.brand-center { justify-content: center; margin-bottom: 1rem; }
.brand-orb {
    width: 30px; height: 30px; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #e9d5ff, var(--violet) 40%, var(--primary-2) 75%);
    box-shadow: 0 0 18px var(--glow), inset 0 0 6px rgba(255, 255, 255, .4);
    animation: orb-breathe 4s ease-in-out infinite;
}
@keyframes orb-breathe { 50% { box-shadow: 0 0 28px rgba(168, 85, 247, .6), inset 0 0 8px rgba(255, 255, 255, .5); transform: scale(1.05); } }

.nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: .75rem; padding: .65rem .8rem; border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 500; transition: background .2s, color .2s, transform .2s;
    position: relative;
}
.nav-link:hover { background: var(--surface-2); color: #fff; transform: translateX(2px); }
.nav-link.active { background: linear-gradient(90deg, rgba(139, 92, 246, .22), rgba(139, 92, 246, .04)); color: #fff; }
.nav-link.active::before { content: ""; position: absolute; left: -1rem; top: 20%; bottom: 20%; width: 3px; border-radius: 0 3px 3px 0; background: var(--violet); box-shadow: 0 0 12px var(--violet); }
.nav-link.active .icon { color: var(--lilac); }
.nav-button { width: 100%; background: none; border: 0; cursor: pointer; font: inherit; text-align: left; }
.sidebar-footer { display: flex; flex-direction: column; gap: .5rem; }
.ai-card { display: flex; align-items: center; gap: .7rem; padding: .75rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.ai-card strong { display: block; font-size: .92rem; }
.ai-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; background: linear-gradient(135deg, var(--primary), var(--violet)); color: #fff; box-shadow: 0 0 14px var(--glow); }
.ai-status-text { display: flex; align-items: center; gap: .35rem; }
.ai-status-text::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.ai-status-text.on { color: var(--ok); }
.ai-status-text.off { color: var(--warn); }
.sidebar-backdrop { display: none; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 1rem;
    padding: .85rem 1.75rem; background: rgba(7, 7, 11, .75); backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 1.05rem; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.topbar .menu-toggle { display: none; }
.user-chip { display: flex; align-items: center; gap: .5rem; padding: .25rem .65rem .25rem .25rem; border: 1px solid var(--border); border-radius: 99px; background: var(--surface); font-size: .88rem; }
.content { padding: 1.75rem; max-width: 1440px; width: 100%; margin: 0 auto; animation: fade-up .45s var(--ease); }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Status pill ---------- */
.status-pill {
    display: inline-flex; align-items: center; gap: .5rem; padding: .4rem .85rem; border-radius: 99px; cursor: pointer;
    font: 600 .82rem var(--font); border: 1px solid; transition: all .25s var(--ease);
}
.status-pill.on { color: #86efac; background: rgba(34, 197, 94, .1); border-color: rgba(34, 197, 94, .35); }
.status-pill.off { color: #fcd34d; background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .35); }
.status-pill:hover { transform: translateY(-1px); filter: brightness(1.15); }
.status-pill:disabled { opacity: .6; cursor: wait; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: currentColor; position: relative; }
.status-pill.on .pulse::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid currentColor; animation: ping 1.8s infinite; }
@keyframes ping { from { transform: scale(.6); opacity: .9; } to { transform: scale(1.8); opacity: 0; } }

/* ---------- Cards & grids ---------- */
.card {
    background: linear-gradient(180deg, var(--surface), rgba(17, 17, 24, .85));
    border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem;
    box-shadow: var(--shadow); transition: border-color .25s;
}
.card:hover { border-color: var(--border-strong); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.card-head h3, .section-title { display: flex; align-items: center; gap: .5rem; }
.card-head h3 .icon, .section-title .icon { color: var(--violet); }
.section-title { font-size: 1rem; margin: 0 0 1rem; }
.form-card .section-title:not(:first-of-type) { margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.form-card [data-provider-section] > .section-title { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.layout-aside { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.main-stack, .aside-stack { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.aside-stack { position: sticky; top: 84px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-head p { margin: .35rem 0 0; }
.head-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: .5rem; font-size: .88rem; }
.empty { color: var(--muted); font-size: .9rem; margin: .5rem 0; }
.empty-state { text-align: center; padding: 3rem 1.5rem; display: flex; flex-direction: column; align-items: center; gap: .6rem; }

/* ---------- Hero ---------- */
.hero-card {
    position: relative; overflow: hidden; display: flex; align-items: center; justify-content: space-between; gap: 2rem;
    padding: 2rem; margin-bottom: 1.5rem; border-radius: calc(var(--radius) + 4px); border: 1px solid rgba(139, 92, 246, .3);
    background: radial-gradient(600px 300px at 90% 50%, rgba(139, 92, 246, .25), transparent 70%), linear-gradient(135deg, #14121f, #0d0c14);
}
.hero-text { max-width: 640px; position: relative; z-index: 1; }
.hero-text h2 { font-size: 1.6rem; margin: .35rem 0 .6rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 700; color: var(--lilac); }
.hero-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.1rem; }
.hero-orb { position: relative; width: 150px; height: 150px; flex-shrink: 0; }
.hero-orb span { position: absolute; inset: 0; border-radius: 50%; border: 1px solid rgba(196, 181, 253, .35); animation: spin 14s linear infinite; }
.hero-orb span:nth-child(1) { background: radial-gradient(circle at 35% 30%, #f3e8ff, var(--violet) 35%, var(--primary-2) 65%, transparent 72%); border: 0; filter: drop-shadow(0 0 30px var(--glow)); animation: orb-breathe 5s ease-in-out infinite; inset: 25px; }
.hero-orb span:nth-child(2) { inset: 8px; border-style: dashed; animation-duration: 18s; }
.hero-orb span:nth-child(3) { inset: -6px; border-color: rgba(139, 92, 246, .25); animation-direction: reverse; animation-duration: 24s; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Stats ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.stat-card {
    position: relative; display: flex; flex-direction: column; gap: .3rem; padding: 1.25rem; border-radius: var(--radius);
    border: 1px solid var(--border); background: linear-gradient(160deg, var(--surface-2), var(--surface));
    transition: transform .3s var(--ease), border-color .3s, box-shadow .3s; overflow: hidden;
}
.stat-card::after { content: ""; position: absolute; width: 120px; height: 120px; right: -40px; top: -40px; border-radius: 50%; background: radial-gradient(circle, rgba(139, 92, 246, .18), transparent 70%); }
a.stat-card:hover { transform: translateY(-3px); border-color: rgba(139, 92, 246, .45); box-shadow: 0 12px 30px rgba(139, 92, 246, .12); }
.stat-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: rgba(139, 92, 246, .14); color: var(--lilac); margin-bottom: .35rem; }
.stat-label { color: var(--muted); font-size: .84rem; font-weight: 500; }
.stat-value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; }
.stat-meta { color: var(--muted); font-size: .78rem; }
.stat-ai .stat-value { font-size: 1.3rem; }
.stat-ai .btn { margin-top: .5rem; align-self: flex-start; position: relative; z-index: 1; }
.stats-compact .stat-card { padding: 1rem 1.15rem; }
.stats-compact .stat-value { font-size: 1.5rem; }

/* ---------- Chart ---------- */
.legend { display: flex; align-items: center; gap: .45rem; font-size: .78rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot-in, .bar-in { background: linear-gradient(180deg, var(--violet), var(--primary-2)); }
.dot-out, .bar-out { background: linear-gradient(180deg, #4b4b63, #2c2c3c); }
.dot-out { margin-left: .5rem; }
.bar-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: .75rem; height: 210px; align-items: end; padding-top: .5rem; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: .45rem; height: 100%; }
.bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 4px; border-bottom: 1px solid var(--border); }
.bar { width: 40%; max-width: 22px; min-height: 3px; height: var(--h); border-radius: 6px 6px 2px 2px; transform-origin: bottom; animation: grow .9s var(--ease) both; }
.bar-in { box-shadow: 0 0 14px rgba(139, 92, 246, .35); }
.bar-col small { color: var(--muted); font-size: .75rem; }
@keyframes grow { from { transform: scaleY(0); } }

/* ---------- Lists ---------- */
.rank-list, .feed, .timeline, .conv-list, .memory-list, .mini-log, .memory-mini, .topic-bars, .chat-list-items { list-style: none; margin: 0; padding: 0; }
.rank-item, .feed-item, .conv-item { display: flex; align-items: center; gap: .8rem; padding: .65rem .6rem; border-radius: var(--radius-sm); transition: background .2s; }
.rank-item:hover, .feed-item:hover, .conv-item:hover { background: var(--surface-2); }
.rank-name { flex: 1; display: flex; flex-direction: column; font-weight: 550; }
.rank-name small { color: var(--muted); font-weight: 400; }
.feed-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.feed-body strong { font-size: .86rem; }
.feed-body span { color: var(--text-2); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.feed-dot.contact { background: var(--info); }
.feed-dot.ai { background: var(--violet); box-shadow: 0 0 8px var(--violet); }
.feed-dot.admin { background: var(--warn); }
.timeline li { display: flex; gap: .85rem; padding: .5rem 0; position: relative; }
.timeline li:not(:last-child)::before { content: ""; position: absolute; left: 4px; top: 1.3rem; bottom: -.5rem; width: 1px; background: var(--border); }
.timeline-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: .4rem; flex-shrink: 0; background: var(--primary); box-shadow: 0 0 0 3px rgba(139, 92, 246, .18); }
.timeline div { display: flex; flex-direction: column; font-size: .9rem; }
.conv-item { justify-content: space-between; }
.conv-item > span:first-child { display: flex; flex-direction: column; min-width: 0; }
.conv-summary { color: var(--text-2); margin-top: .2rem; }

/* ---------- Avatars, badges, chips ---------- */
.avatar {
    --hue: 265; width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; display: grid; place-items: center;
    font-weight: 700; font-size: .85rem; color: #fff;
    background: linear-gradient(135deg, hsl(var(--hue) 70% 55%), hsl(calc(var(--hue) + 30) 65% 38%));
}
.avatar-sm { width: 30px; height: 30px; border-radius: 9px; font-size: .72rem; }
.avatar-xs { width: 22px; height: 22px; border-radius: 7px; font-size: .6rem; }
.avatar-lg { width: 64px; height: 64px; border-radius: 18px; font-size: 1.3rem; box-shadow: 0 0 25px rgba(139, 92, 246, .25); }
.badge {
    display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .55rem; border-radius: 99px; white-space: nowrap;
    font-size: .74rem; font-weight: 600; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border);
}
.badge-ok { background: rgba(34, 197, 94, .12); color: #86efac; border-color: rgba(34, 197, 94, .3); }
.badge-warn { background: rgba(245, 158, 11, .12); color: #fcd34d; border-color: rgba(245, 158, 11, .3); }
.badge-danger { background: rgba(239, 68, 68, .12); color: #fca5a5; border-color: rgba(239, 68, 68, .3); }
.badge-soft { background: rgba(139, 92, 246, .1); color: var(--lilac); border-color: rgba(139, 92, 246, .25); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.chip { padding: .22rem .65rem; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--border); font-size: .78rem; color: var(--text-2); }

/* Categorías de memoria */
.cat-dato { --cat: #60a5fa; }
.cat-preferencia { --cat: #c084fc; }
.cat-tema { --cat: #22d3ee; }
.cat-importante { --cat: #f59e0b; }
.cat-resumen { --cat: #a1a1aa; }
.badge-cat { color: var(--cat, var(--lilac)); background: color-mix(in srgb, var(--cat, #8b5cf6) 14%, transparent); border-color: color-mix(in srgb, var(--cat, #8b5cf6) 35%, transparent); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .62rem 1.1rem;
    border-radius: var(--radius-sm); border: 1px solid transparent; font: 600 .9rem var(--font); cursor: pointer;
    transition: transform .2s var(--ease), box-shadow .2s, background .2s, border-color .2s, opacity .2s; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--violet)); color: #fff; box-shadow: 0 4px 18px rgba(139, 92, 246, .35); }
.btn-primary:hover { box-shadow: 0 6px 26px rgba(139, 92, 246, .55); transform: translateY(-1px); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { border-color: var(--primary); background: var(--surface-3); }
.btn-warn { background: rgba(245, 158, 11, .1); color: #fcd34d; border-color: rgba(245, 158, 11, .35); }
.btn-warn:hover { background: rgba(245, 158, 11, .2); }
.btn-danger { background: rgba(239, 68, 68, .12); color: #fca5a5; border-color: rgba(239, 68, 68, .4); }
.btn-danger:hover { background: rgba(239, 68, 68, .25); color: #fff; }
.btn-sm { padding: .45rem .8rem; font-size: .82rem; }
.btn-block { width: 100%; }
.icon-btn {
    display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
    background: transparent; border: 1px solid var(--border); color: var(--text-2); transition: all .2s;
}
.icon-btn:hover { background: var(--surface-3); color: #fff; border-color: var(--primary); }
.icon-btn.danger:hover { border-color: var(--danger); color: #fca5a5; background: rgba(239, 68, 68, .1); }
.icon-btn-sm { width: 28px; height: 28px; }
.icon-btn-sm .icon { width: 15px; height: 15px; }
.row-actions { display: flex; gap: .35rem; align-items: center; justify-content: flex-end; }
.row-actions form { margin: 0; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.field > span { font-size: .84rem; font-weight: 550; color: var(--text-2); }
.field small { color: var(--muted); font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=url], select, textarea {
    width: 100%; padding: .65rem .85rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--bg-2); color: var(--text); font: inherit; font-size: .92rem; transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 44px; line-height: 1.5; }
select { appearance: none; padding-right: 2.2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a99fd0' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .8rem center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139, 92, 246, .22); }
input:disabled { opacity: .6; }
input[type=range] { width: 100%; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.25rem; }
.inline-form { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.inline-form input[type=text] { flex: 1; min-width: 180px; }
.inline-form select { width: auto; }
.stack-form { display: flex; flex-direction: column; gap: .6rem; }
.danger-zone form { margin-bottom: .6rem; }
.danger-zone { border-color: rgba(239, 68, 68, .2); }
.card form > input[type=text] { margin-bottom: .6rem; }

.switch { display: flex; align-items: center; gap: .8rem; margin: .75rem 0; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span:last-child { display: flex; flex-direction: column; font-size: .92rem; }
.switch-track { position: relative; width: 42px; height: 24px; flex-shrink: 0; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--border-strong); transition: background .25s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .25s var(--ease), background .25s; }
.switch input:checked + .switch-track { background: linear-gradient(135deg, var(--primary), var(--violet)); border-color: transparent; }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(139, 92, 246, .35); }
.switch-lg .switch-track { width: 52px; height: 28px; }
.switch-lg .switch-track::after { width: 22px; height: 22px; }
.switch-lg input:checked + .switch-track::after { transform: translateX(24px); }

.filters { display: flex; gap: .65rem; align-items: center; flex-wrap: wrap; padding: .85rem; margin-bottom: 1.25rem; }
.filters select { width: auto; min-width: 150px; }
.field-search { flex: 1; min-width: 220px; margin: 0; position: relative; }
.field-search .icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.field-search input { padding-left: 2.4rem; }

/* ---------- Alerts & toasts ---------- */
.alert {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; margin-bottom: 1rem;
    border-radius: var(--radius-sm); border: 1px solid; font-size: .92rem; animation: fade-up .35s var(--ease);
}
.alert-success { background: rgba(34, 197, 94, .08); border-color: rgba(34, 197, 94, .3); color: #bbf7d0; }
.alert-error { background: rgba(239, 68, 68, .08); border-color: rgba(239, 68, 68, .3); color: #fecaca; }
.alert-warning { background: rgba(245, 158, 11, .08); border-color: rgba(245, 158, 11, .3); color: #fde68a; }
.alert-info { background: rgba(96, 165, 250, .08); border-color: rgba(96, 165, 250, .3); color: #bfdbfe; }
.alert-close { background: none; border: 0; color: inherit; font-size: 1.3rem; cursor: pointer; opacity: .7; line-height: 1; }
.alert-close:hover { opacity: 1; }
.toast-container { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 100; display: flex; flex-direction: column; gap: .6rem; max-width: min(380px, calc(100vw - 2.5rem)); }
.toast {
    padding: .8rem 1rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border-strong);
    box-shadow: var(--shadow); font-size: .9rem; animation: toast-in .35s var(--ease); border-left: 3px solid var(--primary);
}
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warn); }
.toast.hide { animation: toast-out .3s forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }

/* ---------- Tables ---------- */
.table-card { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: .85rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.table td { padding: .8rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .2s; }
.table tbody tr:hover { background: rgba(139, 92, 246, .05); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { text-align: right; width: 1%; white-space: nowrap; }
.person { display: flex; align-items: center; gap: .75rem; }
.person > span:last-child { display: flex; flex-direction: column; }
.person-sm { gap: .45rem; font-size: .84rem; font-weight: 550; }
.trust { display: inline-flex; gap: 3px; }
.trust-dot { width: 14px; height: 6px; border-radius: 3px; background: var(--surface-3); }
.trust-dot.on { background: linear-gradient(90deg, var(--primary), var(--violet)); box-shadow: 0 0 6px rgba(139, 92, 246, .5); }
.pagination { display: flex; gap: .35rem; justify-content: center; margin-top: 1.25rem; flex-wrap: wrap; }
.page-link { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; border: 1px solid var(--border); font-size: .88rem; transition: all .2s; }
.page-link:hover { border-color: var(--primary); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Contact profile ---------- */
.profile-head { display: flex; align-items: center; gap: 1rem; }
.profile-head h2 small { font-size: .95rem; font-weight: 500; }
.details { display: grid; grid-template-columns: 200px 1fr; gap: .65rem 1rem; margin: 0; font-size: .92rem; }
.details dt { color: var(--muted); font-weight: 500; }
.details dd { margin: 0; display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.memory-item { display: flex; align-items: center; gap: .75rem; padding: .6rem .65rem; border-radius: var(--radius-sm); border-left: 3px solid var(--cat); background: var(--bg-2); margin-bottom: .45rem; animation: fade-up .35s var(--ease); }
.memory-text { flex: 1; font-size: .92rem; }
.memory-meta { display: flex; align-items: center; gap: .45rem; }
.memory-meta form { margin: 0; }
.importance { color: #fbbf24; font-size: .8rem; letter-spacing: 1px; white-space: nowrap; }
.importance .muted { color: var(--surface-3); }
.mini-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1.1rem 0 .5rem; }
.mini-log li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; flex-wrap: wrap; }
.topic-cloud { display: flex; flex-wrap: wrap; gap: .45rem; }
.topic-form { margin: 0; }
.topic {
    --w: 1; font-size: calc(.82rem * var(--w)); padding: .3rem .7rem; border-radius: 99px; cursor: pointer;
    background: rgba(34, 211, 238, .08); color: #a5f3fc; border: 1px solid rgba(34, 211, 238, .25); font-family: var(--font); transition: all .2s;
}
.topic small { opacity: .6; }
.topic:hover { background: rgba(34, 211, 238, .18); transform: translateY(-1px); }

/* ---------- Personality ---------- */
.persona-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.persona-orb {
    width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; margin-bottom: .5rem;
    background: radial-gradient(circle at 30% 30%, #f3e8ff, var(--violet) 40%, var(--primary-2) 80%);
    box-shadow: 0 0 40px var(--glow); animation: orb-breathe 4s ease-in-out infinite; font-size: 1.6rem; font-weight: 800; color: #fff;
}
.preview-reply { margin-top: 1rem; padding: .9rem 1rem; border-radius: 14px 14px 14px 4px; background: linear-gradient(135deg, rgba(139, 92, 246, .2), rgba(168, 85, 247, .1)); border: 1px solid rgba(139, 92, 246, .35); font-size: .92rem; animation: fade-up .3s var(--ease); white-space: pre-wrap; }

/* ---------- Conversations ---------- */
.conv-cards { display: flex; flex-direction: column; gap: .75rem; }
.conv-card { display: flex; align-items: center; gap: 1rem; padding: 1rem; }
.conv-card-main { flex: 1; display: flex; gap: .9rem; min-width: 0; }
.conv-card-body { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.conv-card-title { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.conv-preview { color: var(--text-2); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview em { color: var(--lilac); font-style: normal; }
.conv-context { display: flex; align-items: center; gap: .3rem; color: var(--muted); }

/* ---------- Chat ---------- */
.chat-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr) 300px; gap: 1rem; height: calc(100vh - 64px - 3.5rem); min-height: 520px; }
.chat-layout.no-conversation { grid-template-columns: 280px minmax(0, 1fr); }
.chat-list, .chat-panel, .chat-info { padding: 0; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.chat-list-head { padding: .85rem; border-bottom: 1px solid var(--border); }
.chat-list-head .field-search { min-width: 0; }
.chat-list-items { overflow-y: auto; flex: 1; padding: .4rem; }
.chat-list-item { display: flex; gap: .65rem; padding: .65rem; border-radius: var(--radius-sm); transition: background .2s; align-items: flex-start; }
.chat-list-item:hover { background: var(--surface-2); }
.chat-list-item.active { background: rgba(139, 92, 246, .16); box-shadow: inset 2px 0 0 var(--violet); }
.chat-list-item.archived { opacity: .6; }
.chat-list-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-list-body strong { font-size: .88rem; }
.chat-list-body small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-time { white-space: nowrap; font-size: .7rem; }
.chat-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 1rem; }
.chat-empty .stack-form { width: min(360px, 100%); }
.chat-head { display: flex; align-items: center; gap: .8rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.chat-head-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head-info small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-badges { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.chat-head .chat-info-toggle, .chat-head .chat-back { display: none; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: .7rem; scroll-behavior: smooth;
    background: radial-gradient(500px 300px at 50% 0%, rgba(139, 92, 246, .06), transparent 70%);
}
.chat-hint { margin: auto; text-align: center; max-width: 420px; padding: 1.5rem; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); }
.msg { display: flex; animation: msg-in .35s var(--ease); }
.msg-contact { justify-content: flex-start; }
.msg-ai, .msg-admin { justify-content: flex-end; }
.msg-bubble { max-width: min(560px, 78%); padding: .65rem .9rem .5rem; border-radius: 16px; position: relative; display: flex; flex-direction: column; gap: .15rem; }
.msg-contact .msg-bubble { background: var(--surface-3); border: 1px solid var(--border-strong); border-bottom-left-radius: 4px; }
.msg-ai .msg-bubble { background: linear-gradient(135deg, var(--primary-2), var(--violet)); color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 6px 20px rgba(139, 92, 246, .25); }
.msg-admin .msg-bubble { background: rgba(245, 158, 11, .12); border: 1px solid rgba(245, 158, 11, .35); border-bottom-right-radius: 4px; }
.msg-author { font-size: .72rem; font-weight: 700; opacity: .75; }
.msg-text { font-size: .93rem; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-time { font-size: .68rem; opacity: .6; align-self: flex-end; }
.msg-system { justify-content: center; }
.msg-system .msg-bubble { max-width: 90%; background: rgba(96, 165, 250, .08); border: 1px dashed rgba(96, 165, 250, .35); color: #bfdbfe; font-size: .82rem; text-align: center; padding: .45rem .8rem; border-radius: 10px; }
.msg-memory .msg-bubble { background: rgba(192, 132, 252, .08); border-color: rgba(192, 132, 252, .4); color: #e9d5ff; }
@keyframes msg-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.typing .msg-bubble { padding: .75rem 1rem; }
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: #fff; opacity: .5; animation: bounce 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }
.chat-composer { border-top: 1px solid var(--border); padding: .75rem; background: var(--surface-2); display: flex; flex-direction: column; gap: .55rem; }
.sender-toggle { display: flex; gap: .4rem; flex-wrap: wrap; }
.sender-toggle label { cursor: pointer; }
.sender-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.sender-toggle span { display: inline-block; padding: .28rem .7rem; border-radius: 99px; font-size: .78rem; font-weight: 600; border: 1px solid var(--border-strong); color: var(--muted); transition: all .2s; }
.sender-toggle input:checked + span { color: #fff; border-color: var(--primary); background: rgba(139, 92, 246, .2); }
.sender-toggle input:focus-visible + span { box-shadow: 0 0 0 3px rgba(139, 92, 246, .35); }
.composer-row { display: flex; gap: .55rem; align-items: flex-end; }
.composer-row textarea { max-height: 160px; resize: none; }
.btn-send { height: 44px; width: 48px; padding: 0; flex-shrink: 0; }
.chat-info { overflow-y: auto; }
.chat-info-section { padding: 1rem; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: .55rem; }
.chat-info-section:last-child { border-bottom: 0; }
.chat-info-section h4 { display: flex; align-items: center; gap: .45rem; font-size: .88rem; }
.chat-info-section h4 .icon { color: var(--violet); width: 16px; height: 16px; }
.chat-info-section .btn { align-self: flex-start; }
.chat-info-actions { flex-direction: column; }
.chat-info-actions form { margin: 0; }
.chat-info-actions .btn { align-self: stretch; }
.memory-mini { display: flex; flex-direction: column; gap: .4rem; max-height: 260px; overflow-y: auto; }
.memory-mini li { font-size: .84rem; padding: .45rem .55rem; border-radius: 8px; background: var(--bg-2); border-left: 3px solid var(--cat); }
.memory-mini li.new { animation: highlight 2s var(--ease); }
@keyframes highlight { 0% { background: rgba(192, 132, 252, .35); } 100% { background: var(--bg-2); } }

/* ---------- Memory module ---------- */
.category-tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.cat-tab { padding: .45rem .9rem; border-radius: 99px; border: 1px solid var(--border-strong); font-size: .85rem; font-weight: 550; color: var(--text-2); display: inline-flex; gap: .45rem; align-items: center; transition: all .2s; }
.cat-tab span { font-size: .75rem; padding: 0 .45rem; border-radius: 99px; background: var(--surface-3); }
.cat-tab:hover { border-color: var(--cat, var(--primary)); color: #fff; }
.cat-tab.active { background: color-mix(in srgb, var(--cat, #8b5cf6) 18%, transparent); border-color: var(--cat, var(--primary)); color: #fff; }
.memory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.memory-card { display: flex; flex-direction: column; gap: .65rem; padding: 1rem; border-top: 3px solid var(--cat); animation: fade-up .4s var(--ease) both; }
.memory-card header, .memory-card footer { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.memory-card p { margin: 0; flex: 1; font-size: .93rem; }
.memory-card footer { border-top: 1px solid var(--border); padding-top: .6rem; }
.memory-card footer small { flex-basis: 100%; order: 3; }
.memory-card.editing { box-shadow: 0 0 0 2px var(--primary), var(--shadow); }
.topic-bars li { display: grid; grid-template-columns: 90px 1fr 28px; align-items: center; gap: .6rem; padding: .3rem 0; font-size: .86rem; }
.topic-bars li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-bar { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.topic-bar span { display: block; height: 100%; width: var(--w); border-radius: 99px; background: linear-gradient(90deg, #0891b2, #22d3ee); animation: widen 1s var(--ease) both; }
@keyframes widen { from { width: 0; } }

/* ---------- Settings tabs ---------- */
.tabs { display: flex; gap: .35rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: .45rem; padding: .7rem 1rem; color: var(--muted); font-weight: 550; font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; transition: color .2s, border-color .2s; }
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--violet); }
.tab.active .icon { color: var(--violet); }
.tab-panel { display: flex; flex-direction: column; gap: 1.25rem; animation: fade-up .35s var(--ease); max-width: 920px; }
.js .tab-panel:not(.active) { display: none; }

/* ---------- Auth ---------- */
.auth-body { display: grid; place-items: center; padding: 1.5rem; overflow: hidden; }
.auth-glow { position: fixed; inset: 0; margin: auto; width: 600px; height: 600px; max-width: 100vw; border-radius: 50%; background: radial-gradient(circle, rgba(139, 92, 246, .22), transparent 65%); animation: glow-pulse 6s ease-in-out infinite; pointer-events: none; }
@keyframes glow-pulse { 50% { opacity: .6; transform: scale(1.08); } }
.auth-card { position: relative; width: min(420px, 100%); padding: 2.25rem 2rem; border-radius: 20px; border: 1px solid rgba(139, 92, 246, .3); background: rgba(17, 17, 24, .9); backdrop-filter: blur(20px); box-shadow: 0 25px 60px rgba(0, 0, 0, .6), 0 0 60px rgba(139, 92, 246, .1); animation: fade-up .5s var(--ease); }
.auth-title { font-size: 1.35rem; text-align: center; margin-bottom: .4rem; }
.auth-card > p { text-align: center; margin-bottom: 1.5rem; font-size: .9rem; }
.auth-card .btn-block { margin-top: .5rem; }
.error-detail { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; font-size: .8rem; white-space: pre-wrap; color: #fca5a5; margin-bottom: 1rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
    .chat-layout { grid-template-columns: 250px minmax(0, 1fr); }
    .chat-info { position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 90vw); z-index: 60; border-radius: 0; transform: translateX(105%); transition: transform .35s var(--ease); }
    .chat-info.open { transform: none; }
    .chat-head .chat-info-toggle { display: inline-grid; }
}
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .layout-aside { grid-template-columns: 1fr; }
    .aside-stack { position: static; }
}
@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
    .sidebar.open { transform: none; }
    .sidebar-backdrop.open { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px); }
    .main { margin-left: 0; }
    .topbar .menu-toggle { display: inline-grid; }
    .topbar { padding: .75rem 1rem; }
    .content { padding: 1.1rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .chat-layout, .chat-layout.no-conversation { grid-template-columns: 1fr; height: calc(100vh - 60px - 2.2rem); }
    .chat-layout:not(.no-conversation) .chat-list { display: none; }
    .chat-layout.no-conversation .chat-list { max-height: 260px; }
    .chat-head .chat-back { display: inline-grid; }
    .hero-orb { display: none; }
}
@media (max-width: 760px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
    .stat-value { font-size: 1.45rem; }
    .form-grid { grid-template-columns: 1fr; }
    .details { grid-template-columns: 1fr; gap: .2rem; }
    .details dd { margin-bottom: .6rem; }
    .hide-sm { display: none; }
    .hero-card { padding: 1.35rem; }
    .hero-text h2 { font-size: 1.25rem; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
    .table td { border: 0; padding: .3rem 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; text-align: right; }
    .table td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; text-align: left; }
    .table td:first-child { justify-content: flex-start; text-align: left; }
    .table td:first-child::before, .table td.actions-col::before { content: none; }
    .table td.actions-col { justify-content: flex-end; width: 100%; }
    .filters select, .filters .btn { flex: 1; min-width: 0; }
    .conv-card { flex-direction: column; align-items: stretch; }
    .msg-bubble { max-width: 88%; }
    .chat-head-badges .badge:not([data-ai-status-label]) { display: none; }
    .memory-item { flex-wrap: wrap; }
    .memory-text { flex-basis: 100%; order: 2; }
    .memory-meta { margin-left: auto; }
    .status-pill span:last-child { display: none; }
    .status-pill { padding: .5rem; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
