/* ── Reset & Variables ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:              #04020a;
  --surface:         #0e0a1a;
  --surface2:        #161028;
  --surface3:        #1e1840;
  --border:          rgba(139,92,246,0.2);
  --border-active:   rgba(167,139,250,0.45);
  --accent:          #8b5cf6;
  --accent2:         #a78bfa;
  --accent-dim:      #6d28d9;
  --accent-glow:     rgba(139,92,246,0.35);
  --a-glow:          rgba(139,92,246,0.18);
  --text:            #f0ecff;
  --text2:           #9d8cc5;
  --text3:           #4d3f6b;
  --danger:          #ef4444;
  --success:         #10b981;
  --warn:            #f59e0b;
  --glow-sm:         0 0 12px rgba(139,92,246,0.35);
  --glow-md:         0 0 24px rgba(139,92,246,0.45);
  --sidebar-w:       260px;
  --radius:          12px;
  --font:            'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:       'Space Mono', 'Courier New', monospace;
  /* Structural backgrounds — overridden in bright mode */
  --input-bg:        rgba(22,16,40,0.8);
  --panel-bg:        rgba(14,10,26,0.97);
  --sidebar-bg:      rgba(6,3,15,0.97);
  --auth-card-bg:    rgba(14,10,26,0.92);
  --mob-bar-bg:      rgba(6,3,15,0.97);
  --glass-overlay:   rgba(255,255,255,0.07);
  --glass-hover:     rgba(255,255,255,0.12);
  --glass-text:      rgba(255,255,255,0.85);
  --glass-text-dim:  rgba(255,255,255,0.4);
  --overlay-bg:      rgba(0,0,0,0.7);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #150830 0%, #04020a 65%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Ambient Blobs ───────────────────────────────────────────── */
.amb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
}
.amb-1 {
  width: 500px; height: 500px;
  background: rgba(109,40,217,0.12);
  top: -10%; left: 40%;
}
.amb-2 {
  width: 300px; height: 300px;
  background: rgba(192,132,252,0.07);
  bottom: 5%; right: 5%;
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.3); border-radius: 2px; }

/* ── Utilities ───────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-2  { margin-top: 12px; }
.mb-2  { margin-bottom: 12px; }
.mobile-only { display: none !important; }

/* ── Typography ──────────────────────────────────────────────── */
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; font-weight: 600; color: var(--text2); margin: 24px 0 12px; }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }

/* ── Logo ────────────────────────────────────────────────────── */
.logo {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 7px;
}
.logo-v    { color: var(--accent2); }
.logo-bang { color: var(--accent2); font-style: normal; }
.logo-rest { color: var(--text); }

/* ── Buttons ─────────────────────────────────────────────────── */
button { cursor: pointer; font-family: var(--font); font-size: 14px; border: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: #fff;
  padding: 9px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  box-shadow: 0 0 18px rgba(109,40,217,0.38);
  transition: box-shadow .2s, transform .1s, opacity .15s;
}
.btn-primary:hover { box-shadow: 0 0 26px rgba(109,40,217,0.55); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-full { width: 100%; }

.btn-sm {
  background: var(--a-glow);
  color: var(--accent2);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn-sm:hover { background: rgba(139,92,246,0.25); border-color: var(--border-active); }

.btn-sm-danger {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.35);
  color: #ef4444;
  padding: 6px 14px; border-radius: 8px;
  font-size: 13px; cursor: pointer; transition: background .15s;
}
.btn-sm-danger:hover { background: rgba(239,68,68,.25); }

.btn-sm-warn {
  background: rgba(234,179,8,.12);
  border: 1px solid rgba(234,179,8,.35);
  color: #eab308;
  padding: 6px 14px; border-radius: 8px;
  font-size: 13px; cursor: pointer; transition: background .15s;
}
.btn-sm-warn:hover { background: rgba(234,179,8,.25); }

.btn-send {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 14px rgba(109,40,217,0.45);
  transition: box-shadow .15s, transform .1s;
}
.btn-send:hover { box-shadow: 0 0 20px rgba(109,40,217,0.65); transform: scale(1.05); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

.icon-btn {
  background: transparent;
  color: var(--text2);
  padding: 7px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--a-glow); color: var(--text); }
.icon-btn.danger:hover { background: rgba(239,68,68,.15); color: var(--danger); }

/* ── Form Fields ─────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .08em;
}

input, textarea, select {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
}
input:disabled, textarea:disabled { opacity: .5; cursor: not-allowed; }
textarea { resize: none; min-height: 42px; max-height: 140px; line-height: 1.5; }
select option { background: var(--surface2); }

.form-error   { color: var(--danger);  font-size: 13px; padding: 8px 12px; background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.2);  border-radius: 8px; margin-bottom: 10px; }
.form-success { color: var(--success); font-size: 13px; padding: 8px 12px; background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.2); border-radius: 8px; margin-bottom: 10px; }

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

/* ── AUTH SCREEN ─────────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #150830 0%, #04020a 65%);
  background-attachment: fixed;
  padding: 20px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}


.auth-card { position: relative; z-index: 1; }

.auth-forgot-link {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color .15s;
}
.auth-forgot-link:hover { color: var(--accent2); }

.auth-card {
  background: var(--auth-card-bg);
  border: 1px solid rgba(139,92,246,0.28);
  border-radius: 20px;
  padding: 36px;
  width: 100%;
  max-width: 400px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 0 60px rgba(109,40,217,0.15), 0 24px 64px rgba(0,0,0,.5);
}

.auth-logo {
  text-align: center;
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.auth-logo .logo-v    { color: var(--accent2); }
.auth-logo .logo-bang { color: var(--accent2); }
.auth-logo .logo-rest { color: var(--text); }

.auth-tagline  { text-align: center; color: var(--text2); font-size: 12px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1.2px; }
.auth-nexus-pill {
  text-align: center;
  margin: 0 auto 24px;
  display: inline-block;
  width: fit-content;
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}
.auth-nexus-pill span,
.auth-nexus-pill {
  background: rgba(139,92,246,0.1);
  border: 1px solid rgba(139,92,246,0.28);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--accent2);
}

.auth-tabs {
  display: flex;
  background: rgba(139,92,246,0.07);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 24px;
  gap: 0;
}
.auth-tab {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text3);
  background: transparent;
  transition: background .15s, color .15s;
}
.auth-tab.active { background: rgba(139,92,246,0.22); color: var(--accent2); }

/* ── Head Pill (shared) ──────────────────────────────────────── */
.head-pill {
  background: rgba(139,92,246,0.1);
  border: 1px solid rgba(139,92,246,0.28);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--accent2);
}

/* ── APP SHELL ───────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ── SIDEBAR ─────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  height: 100vh;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}
.logo-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
#app-version-tag {
  font-size: .6rem;
  font-weight: 500;
  color: var(--text2);
  letter-spacing: .03em;
  opacity: .8;
  line-height: 1;
}
body.bright-mode #app-version-tag {
  color: var(--accent-dim);
  opacity: .9;
}

.sidebar-nav {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-item:hover { background: var(--a-glow); color: var(--text); }
.nav-item.active {
  background: rgba(139,92,246,0.15);
  color: var(--accent2);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-item.active .nav-icon { filter: drop-shadow(0 0 6px var(--accent)); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-chars { flex: 1; padding: 12px 8px; overflow-y: auto; }
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 4px 8px 8px;
}

.sidebar-char-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
  font-size: 13px;
  color: var(--text2);
}
.sidebar-char-item:hover { background: var(--a-glow); color: var(--text); }
.sidebar-char-item.active { background: rgba(139,92,246,0.15); color: var(--text); }
.sidebar-char-item .char-mini-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface3);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent2);
  border: 1px solid var(--border);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-avatar-sm {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-dim), var(--accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(109,40,217,0.4);
}
.user-avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user-info { min-width: 0; }
.sidebar-username { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-balance  { font-size: 11px; color: var(--accent2); font-weight: 600; font-family: var(--font-mono); }

/* ── MOBILE TOPBAR ───────────────────────────────────────────── */
.mobile-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform .3s ease;
}
.mobile-balance { font-size: 11px; color: var(--accent2); font-weight: 700; font-family: var(--font-mono); }

/* ── MOBILE BOTTOM TAB BAR ───────────────────────────────────── */
.mobile-bottom-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 82px;
  background: var(--mob-bar-bg);
  border-top: 1px solid var(--border);
  display: none;
  align-items: center;
  justify-content: space-around;
  padding: 0 10px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform .3s ease;
}

/* ── MOBILE CHAT HANDLE ──────────────────────────────────────── */
.mob-chat-handle {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 110;
  display: none;
  width: 48px;
  height: 28px;
  background: rgba(139,92,246,0.18);
  border: 1px solid rgba(139,92,246,0.45);
  border-radius: 14px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  align-items: center;
  justify-content: center;
  color: var(--accent2);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  user-select: none;
  transition: opacity .25s ease;
}

.mob-tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text3);
  transition: color 0.2s;
  flex: 1;
  position: relative;
}
.mob-tab-btn.on { color: var(--accent2); }
.mob-tab-btn.on::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 28px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 2px;
}
.mob-tab-icon { font-size: 20px; line-height: 1; }
.mob-tab-btn.on .mob-tab-icon { filter: drop-shadow(0 0 6px var(--accent)); }
.mob-tab-lbl  { font-size: 9px; font-weight: 600; letter-spacing: 0.9px; text-transform: uppercase; }

.mob-tab-hub {
  width: 56px; height: 56px;
  background: linear-gradient(145deg, #5b1fbe, var(--accent), var(--accent2));
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  border: none;
  color: #fff;
  box-shadow: 0 0 20px rgba(109,40,217,0.55), 0 0 40px rgba(109,40,217,0.2);
  transition: all 0.2s;
  flex-shrink: 0;
  animation: hubGlow 4s ease-in-out infinite;
}
.mob-tab-hub:hover { box-shadow: 0 0 28px rgba(167,139,250,0.8), 0 0 56px rgba(109,40,217,0.4); }
@keyframes hubGlow {
  0%,100% { box-shadow: 0 0 20px rgba(109,40,217,0.55), 0 0 40px rgba(109,40,217,0.2); }
  50%      { box-shadow: 0 0 28px rgba(167,139,250,0.7), 0 0 56px rgba(109,40,217,0.4); }
}

/* ── MAIN CONTENT ────────────────────────────────────────────── */
#main {
  flex: 1;
  overflow-y: auto;
  height: 100vh;
  position: relative;
}

.view {
  min-height: 100%;
  padding: 32px;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.section-title          { font-size: 1rem; font-weight: 600; color: var(--text2); margin: 24px 0 14px; }
.settings-section-title { font-size: .8rem; font-weight: 600; color: var(--accent2); text-transform: uppercase; letter-spacing: .06em; margin: 20px 0 8px; }

/* ── FILTER PILLS ────────────────────────────────────────────── */
.library-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.lib-filter {
  background: var(--a-glow);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 20px;
  padding: 5px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.lib-filter.active, .lib-filter:hover {
  background: rgba(139,92,246,0.22);
  color: var(--accent2);
  border-color: var(--border-active);
  box-shadow: var(--glow-sm);
}
.lib-tag-filter-label { font-size: 12px; color: var(--text2); margin-left: 6px; }
.lib-tag-input {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12px;
  width: 150px;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
}
.lib-tag-input:focus { border-color: var(--border-active); }
.lib-search-input {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 20px;
  padding: 5px 14px 5px 32px;
  font-size: 12px;
  width: 220px;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239d8cc5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.lib-search-input:focus {
  border-color: var(--border-active);
  box-shadow: var(--glow-sm);
}
@media (max-width: 700px) {
  .lib-search-input { width: 160px; }
}

/* ── CHARACTERS GRID ─────────────────────────────────────────── */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.char-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .2s, transform .15s, box-shadow .2s;
  position: relative;
}
.char-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(140deg, rgba(139,92,246,0.05) 0%, transparent 60%);
  pointer-events: none;
}
.char-card:hover {
  border-color: var(--border-active);
  transform: translateY(-3px);
  box-shadow: var(--glow-md);
}

.char-card-portrait {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 800;
  color: var(--accent2);
  letter-spacing: -2px;
  position: relative;
}
.char-card-portrait img { width: 100%; height: 100%; object-fit: cover; }

.char-card-body { padding: 14px; }
.char-card-name { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.char-card-desc {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.char-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.char-fame      { font-size: 11px; color: var(--text2); }
.char-fame span { color: var(--warn); }
.char-chat-btn {
  background: rgba(139,92,246,0.15);
  color: var(--accent2);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(139,92,246,0.35);
  transition: background .15s, box-shadow .15s;
}
.char-chat-btn:hover { background: rgba(139,92,246,0.28); box-shadow: var(--glow-sm); }

.empty-state { text-align: center; padding: 64px 24px; color: var(--text2); }
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* ── CHAT VIEW ───────────────────────────────────────────────── */
#view-chat {
  display: flex;
  flex-direction: row;
  height: 100vh;
  padding: 0;
  overflow: hidden;
}

.chat-main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── INCEPTION WINDOW ────────────────────────────────────────── */
/* Now a global fixed overlay — works from any view, not just chat */
.inception-window {
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  width: 380px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  opacity: 0;
  transition: transform .22s ease, opacity .22s ease;
  z-index: 200;
  box-shadow: -4px 0 24px rgba(0,0,0,0.18);
}
.iw-resize-handle {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 5px;
  cursor: ew-resize;
  z-index: 10;
  transition: background .15s;
}
.iw-resize-handle:hover,
.iw-resize-handle.dragging {
  background: rgba(139,92,246,0.35);
}
.inception-window.open {
  transform: translateX(0);
  opacity: 1;
}
/* When inception is open in chat, push chat content left so it isn't fully covered */
#view-chat.iw-open .chat-main-area {
  margin-right: 380px;
  transition: margin-right .22s ease;
}
#view-chat .chat-main-area {
  transition: margin-right .22s ease;
}
.inception-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface2);
}
.iw-icon { font-size: 18px; line-height: 1; }
.inception-title { font-weight: 700; font-size: 15px; flex: 1; }
.iw-count-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}
.inception-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* Empty state */
.iw-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
}
.iw-empty-icon { font-size: 36px; opacity: 0.25; }
.iw-empty-title { font-weight: 700; font-size: 15px; color: var(--text2); }
.iw-empty-desc { font-size: 13px; color: var(--text3); line-height: 1.5; }
/* Artifact list */
.iw-artifact-list { display: flex; flex-direction: column; gap: 10px; }
.iw-artifact {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s;
}
.iw-artifact:hover { border-color: var(--border-active); }
.iw-artifact-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 8px;
  cursor: pointer;
  user-select: none;
}
.iw-type-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.iw-type-badge.thinking { background: rgba(139,92,246,0.18); color: var(--accent2); }
.iw-type-badge.text     { background: rgba(52,211,153,0.15); color: #34d399; }
.iw-type-badge.file     { background: rgba(251,191,36,0.15);  color: #fbbf24; }
.iw-type-badge.image    { background: rgba(96,165,250,0.15);  color: #60a5fa; }
.iw-type-badge.error    { background: rgba(248,113,113,0.15); color: #f87171; }
.iw-char-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--glass-overlay);
  color: var(--text2);
  flex-shrink: 0;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.iw-artifact-label {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.iw-artifact-ts { font-size: 11px; color: var(--text3); flex-shrink: 0; }
.iw-artifact-chevron { font-size: 12px; color: var(--text3); flex-shrink: 0; transition: transform .15s; }
.iw-artifact.is-collapsed .iw-artifact-chevron { transform: rotate(-90deg); }
.iw-stop-btn {
  display: none;
  background: none; border: none; padding: 0 4px; margin: 0;
  font-size: 10px; line-height: 1; cursor: pointer;
  color: #ef4444; flex-shrink: 0;
  transition: color .15s, opacity .15s;
}
.iw-artifact.is-running .iw-stop-btn { display: inline-flex; align-items: center; }
.iw-stop-btn:hover { color: #dc2626; }
.iw-delete-btn {
  background: none; border: none; padding: 0 2px; margin: 0;
  font-size: 16px; line-height: 1; cursor: pointer;
  color: var(--text3); flex-shrink: 0;
  opacity: 0; transition: opacity .15s, color .15s;
}
.iw-artifact:hover .iw-delete-btn { opacity: 1; }
.iw-delete-btn:hover { color: #ef4444; }
.iw-artifact.is-running .iw-delete-btn { display: none; }
.iw-artifact-body {
  padding: 0 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.iw-artifact.is-collapsed .iw-artifact-body { display: none; }
/* Plan steps — shown upfront, updated as skill progresses */
.iw-plan {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.iw-plan:empty { display: none; }
.iw-plan:not(:empty) + .iw-steps:not(:empty) { margin-top: 6px; }
.iw-plan-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--text3);
  transition: background .2s, color .2s;
}
.iw-plan-item.active {
  color: var(--text);
  background: rgba(139,92,246,0.08);
  font-weight: 600;
}
.iw-plan-item.done { color: #34d399; }
.iw-plan-icon {
  font-size: 11px;
  width: 14px;
  flex-shrink: 0;
  text-align: center;
  line-height: 1;
}
.iw-plan-item.done .iw-plan-icon { color: #34d399; font-weight: 700; }
.iw-mini-spinner {
  display: inline-block;
  width: 10px; height: 10px;
  border: 1.5px solid rgba(139,92,246,0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: iwSpin .7s linear infinite;
  vertical-align: middle;
}
/* Thinking steps */
.iw-steps { display: flex; flex-direction: column; gap: 4px; }
.iw-step {
  font-size: 12px;
  color: var(--text2);
  padding: 4px 8px;
  border-left: 2px solid var(--accent);
  border-radius: 0 4px 4px 0;
  background: rgba(139,92,246,0.06);
  line-height: 1.45;
  animation: iwStepIn .2s ease;
}
.iw-step.done { border-left-color: #34d399; color: var(--text); }
@keyframes iwStepIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: none; }
}
/* Hyperbrowser live view iframe — shown while HyperAgent is running */
.iw-live-view {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(139,92,246,0.35);
  margin-top: 8px;
  animation: iwStepIn .3s ease;
}
.iw-live-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  background: rgba(139,92,246,0.12);
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
}
.iw-live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #f87171;
  flex-shrink: 0;
  animation: iwDotPulse 1.4s ease-in-out infinite;
}
.iw-live-label { flex: 1; }
.iw-live-ext {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  line-height: 1;
  opacity: 0.8;
}
.iw-live-ext:hover { opacity: 1; }
.iw-live-iframe {
  display: block;
  width: 100%;
  height: 320px;
  border: none;
  background: #111;
}
/* Live thinking cursor (bouncing dots) shown below steps while running */
.iw-thinking-cursor {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 2px;
}
.iw-artifact.is-running .iw-thinking-cursor { display: flex; }
.iw-thinking-cursor span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: iwDotPulse 1.2s ease-in-out infinite;
}
.iw-thinking-cursor span:nth-child(2) { animation-delay: .2s; }
.iw-thinking-cursor span:nth-child(3) { animation-delay: .4s; }
@keyframes iwDotPulse {
  0%, 80%, 100% { transform: scale(.7); opacity: .3; }
  40%           { transform: scale(1);  opacity: .9; }
}
/* Text artifact */
.iw-text-content {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  max-height: 280px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.iw-text-content p { margin: 0 0 8px; }
.iw-text-content p:last-child { margin-bottom: 0; }
/* Image artifact */
.iw-img-preview {
  width: 100%;
  border-radius: 8px;
  display: block;
  max-height: 300px;
  object-fit: contain;
  background: var(--bg);
}
/* HTML artifact inline preview */
.iw-html-preview-wrap {
  width: 100%;
  margin-top: 8px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}
.iw-html-preview-frame {
  width: 100%;
  height: 520px;
  border: none;
  display: block;
  background: #fff;
}
/* File artifact */
.iw-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
}
.iw-file-icon { font-size: 22px; flex-shrink: 0; }
.iw-file-name { flex: 1; font-size: 13px; font-weight: 600; word-break: break-all; }
.iw-file-size { font-size: 11px; color: var(--text3); flex-shrink: 0; }
/* Footer row */
.iw-artifact-footer {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
/* History (DB-loaded) artifact cards — subtle de-emphasis */
.iw-artifact.iw-history { opacity: 0.75; }
.iw-artifact.iw-history:hover { opacity: 1; }
.iw-history-tag {
  font-size: 10px;
  color: var(--text3);
  font-style: italic;
}
.iw-save-status {
  font-size: 11px;
  color: var(--text3);
  font-weight: 600;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.iw-add-lib-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(139,92,246,0.15);
  color: var(--accent2);
  border: 1px solid rgba(139,92,246,0.3);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  font-family: var(--font);
}
.iw-add-lib-btn:hover { background: rgba(139,92,246,0.28); box-shadow: var(--glow-sm); }
.iw-add-lib-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.iw-download-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
  font-family: var(--font);
}
.iw-download-btn:hover { background: var(--glass-overlay); }
.iw-make-page-btn {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 6px;
  background: rgba(251,191,36,0.12);
  color: #fbbf24;
  border: 1px solid rgba(251,191,36,0.35);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  font-family: var(--font);
  font-weight: 600;
  letter-spacing: .02em;
}
.iw-make-page-btn:hover { background: rgba(251,191,36,0.25); box-shadow: 0 0 8px rgba(251,191,36,0.3); }
.iw-open-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(52,211,153,0.12);
  color: #34d399;
  border: 1px solid rgba(52,211,153,0.35);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  font-family: var(--font);
}
.iw-open-btn:hover { background: rgba(52,211,153,0.25); box-shadow: 0 0 8px rgba(52,211,153,0.25); }
.iw-edit-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(96,165,250,0.1);
  color: #60a5fa;
  border: 1px solid rgba(96,165,250,0.3);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  font-family: var(--font);
}
.iw-edit-btn:hover { background: rgba(96,165,250,0.22); box-shadow: 0 0 8px rgba(96,165,250,0.25); }
.iw-attach-btn {
  background: none; border: 1px solid rgba(139,92,246,0.35); border-radius: 6px;
  color: var(--accent2); font-size: 11px; font-weight: 600; cursor: pointer;
  padding: 3px 9px; transition: background .15s, box-shadow .15s;
}
.iw-attach-btn:hover { background: rgba(139,92,246,0.18); box-shadow: 0 0 7px rgba(139,92,246,0.3); }
.iw-open-lib-btn {
  background: none; border: 1px solid rgba(52,211,153,0.30); border-radius: 6px;
  color: #34d399; font-size: 11px; font-weight: 600; cursor: pointer;
  padding: 3px 9px; transition: background .15s, box-shadow .15s;
}
.iw-open-lib-btn:hover { background: rgba(52,211,153,0.15); box-shadow: 0 0 7px rgba(52,211,153,0.25); }
/* ── HTML Edit Modal ─────────────────────────────────────────── */
.html-edit-modal {
  position: fixed;
  inset: 0;
  background: var(--panel-bg);
  z-index: 12000;
  display: flex;
  flex-direction: column;
}
.hem-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--surface);
  border-bottom: 1px solid rgba(139,92,246,0.25);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.hem-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hem-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
}
.hem-cmd, .hem-img-label {
  background: rgba(139,92,246,0.1);
  border: 1px solid rgba(139,92,246,0.22);
  color: var(--text);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
  font-family: var(--font);
  line-height: 1.6;
}
.hem-cmd:hover, .hem-img-label:hover { background: rgba(139,92,246,0.24); }
.hem-actions { display: flex; gap: 7px; }
.hem-save {
  background: rgba(139,92,246,0.18);
  border: 1px solid rgba(139,92,246,0.4);
  color: #a78bfa;
  border-radius: 6px;
  padding: 4px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
}
.hem-save:hover { background: rgba(139,92,246,0.32); box-shadow: var(--glow-sm); }
.hem-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s;
  font-family: var(--font);
}
.hem-cancel:hover { border-color: var(--border-active); }
.hem-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  min-height: 0;
}
.hem-body iframe {
  flex: 1;
  border: none;
  width: 100%;
  height: 100%;
  display: block;
}
.hem-hint {
  padding: 5px 14px;
  font-size: 11px;
  color: var(--text3);
  background: var(--surface);
  border-top: 1px solid rgba(139,92,246,0.12);
  flex-shrink: 0;
  text-align: center;
  letter-spacing: .01em;
}
/* Running pulse on active thinking */
.iw-artifact.is-running .iw-artifact-header { animation: iwPulse 2s ease-in-out infinite; }
@keyframes iwPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}
/* Spinner */
.iw-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: iwSpin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes iwSpin { to { transform: rotate(360deg); } }

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
  backdrop-filter: blur(12px);
}

.chat-char-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface2);
  border: 2px solid var(--accent);
  box-shadow: 0 0 10px rgba(139,92,246,0.4);
}

.chat-char-info { flex: 1; min-width: 0; }
.chat-char-name   { font-weight: 700; font-size: 15px; }
.chat-char-status { font-size: 11px; color: var(--success); }

.chat-info-panel {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text2);
  max-height: 200px;
  overflow-y: auto;
  flex-shrink: 0;
}
.mem-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin: 10px 0 6px; }
.mem-item  { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.mem-item button { color: var(--danger); background: none; font-size: 12px; opacity: .6; }
.mem-item button:hover { opacity: 1; }
.mem-add   { display: flex; gap: 8px; margin-top: 8px; }
.mem-input { flex: 1; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { display: flex; gap: 10px; max-width: 76%; animation: msgIn .2s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg.user      { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--surface3);
  align-self: flex-end;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--accent-dim), var(--accent));
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 0 16px rgba(109,40,217,0.3);
}
.msg.assistant .msg-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* ── iOS Messages-style typing indicator ─────────────────────── */

/* Override the standard bubble when it's a typing bubble */
.msg.assistant .msg-bubble.typing-bubble {
  border: none;
  border-radius: 22px;
  background: var(--surface2);
  padding: 14px 18px;
  display: inline-flex;
  align-items: center;
  position: relative;
  overflow: visible;       /* let tail circles bleed outside */
  white-space: normal;
  animation: none;
  min-width: 0;
}

/* First tail circle — large, sits at bottom-left of bubble */
.msg.assistant .typing-bubble::before {
  content: '';
  position: absolute;
  left: -11px;
  bottom: 2px;
  width: 18px;
  height: 18px;
  background: var(--surface2);
  border-radius: 50%;
}

/* Second tail circle — small, bleeds further left-down */
.msg.assistant .typing-bubble::after {
  content: '';
  position: absolute;
  left: -20px;
  bottom: -6px;
  width: 10px;
  height: 10px;
  background: var(--surface2);
  border-radius: 50%;
}

/* Dot container */
.typing-dots {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 0;
}

/* Individual dots */
.typing-dots .dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: rgba(180, 180, 210, 0.35);
  display: block;
  flex-shrink: 0;
}

.typing-dots .dot.one   { animation: typingCycleOne   1.1s ease-in-out infinite; }
.typing-dots .dot.two   { animation: typingCycleTwo   1.1s ease-in-out infinite; }
.typing-dots .dot.three { animation: typingCycleThree 1.1s ease-in-out infinite; }

@keyframes typingCycleOne {
  0%       { background: rgba(180, 180, 210, 0.35); }
  33.333%  { background: rgba(200, 200, 230, 1);    }
  66.667%  { background: rgba(180, 180, 210, 0.35); }
  100%     { background: rgba(180, 180, 210, 0.35); }
}
@keyframes typingCycleTwo {
  0%       { background: rgba(180, 180, 210, 0.35); }
  33.333%  { background: rgba(180, 180, 210, 0.35); }
  66.667%  { background: rgba(200, 200, 230, 1);    }
  100%     { background: rgba(180, 180, 210, 0.35); }
}
@keyframes typingCycleThree {
  0%       { background: rgba(180, 180, 210, 0.35); }
  33.333%  { background: rgba(180, 180, 210, 0.35); }
  66.667%  { background: rgba(180, 180, 210, 0.35); }
  100%     { background: rgba(200, 200, 230, 1);    }
}

/* ── Skill thinking bubble ───────────────────────────────────── */
.skill-thinking-bubble {
  background: rgba(109,40,217,0.08);
  border: 1px solid rgba(139,92,246,0.25);
  font-size: 12.5px;
  max-width: 520px;
  padding: 10px 14px 12px;
}
.skill-thinking-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.skill-thinking-header:hover { color: var(--accent); }
.skill-think-toggle {
  margin-left: auto;
  font-size: 11px;
  transition: transform .2s;
  opacity: 0.7;
}
.skill-thinking-bubble.is-collapsed .skill-think-toggle {
  transform: rotate(-90deg);
}
.skill-thinking-bubble.is-collapsed .skill-thinking-steps {
  display: none;
}
.skill-thinking-bubble.is-collapsed {
  padding-bottom: 10px;
}
.skill-thinking-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  animation: bounce .9s infinite;
}
.skill-thinking-steps {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
}
.skill-thinking-step {
  color: var(--text2);
  font-size: 12px;
  line-height: 1.5;
  padding: 1px 0;
  animation: stepIn .15s ease;
  white-space: pre-wrap;
}
@keyframes stepIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: none; }
}

/* ── Skill Called badge ──────────────────────────────────────── */
.skill-called-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  background: rgba(99,102,241,0.12);
  color: var(--accent);
  border: 1px solid rgba(99,102,241,0.28);
  letter-spacing: 0.01em;
  vertical-align: middle;
  cursor: pointer;
}
.skill-called-badge:hover { background: rgba(99,102,241,0.2); }
.msg.user .skill-called-badge {
  background: rgba(0,0,0,0.35);
  color: #fff;
  border-color: rgba(255,255,255,0.25);
}
.msg.user .skill-called-badge:hover { background: rgba(0,0,0,0.5); }
.msg.user .skill-call-raw {
  background: rgba(0,0,0,0.3);
  border-color: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
}
/* Clickable links rendered inside chat messages */
.chat-link {
  color: var(--accent2);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: inherit;
  word-break: break-all;
}
.chat-link:hover { color: #fff; }
.skill-call-raw {
  display: none;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text2);
  background: rgba(0,0,0,0.18);
  border-radius: 6px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid var(--border);
  font-family: 'Space Mono', monospace;
}

/* LLM prose that follows the skill-call tag — shown so the full message is never cut. */
.skill-call-after { margin-top: 6px; }

.chat-input-bar {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
  position: relative;
  backdrop-filter: blur(12px);
}

.chat-attach-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px 4px;
  flex-wrap: wrap;
}

/* Legacy chip styles kept for any other usages */
.attach-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 8px 4px 4px;
  font-size: 12px;
  color: var(--text2);
}
.attach-chip-skill  { padding: 4px 8px; gap: 5px; color: var(--accent2); border-color: rgba(139,92,246,.4); }
.attach-chip-del    { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 12px; padding: 0 2px; line-height: 1; }
.attach-chip-del:hover { color: var(--danger); }

/* New card-style attachment chips */
.attach-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 64px;
  flex-shrink: 0;
}
.attach-card-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: var(--surface2);
  flex-shrink: 0;
}
.attach-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ac-doc-svg {
  width: 28px;
  height: 35px;
}
.ac-type-icon {
  font-size: 24px;
  opacity: .85;
  line-height: 1;
}
.attach-card-badge {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid;
  white-space: nowrap;
  letter-spacing: .03em;
  pointer-events: none;
}
.attach-card-name {
  font-size: 10px;
  color: var(--text3);
  text-align: center;
  width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}
.attach-card-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface3, #3a3a4a);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: background .12s, color .12s;
}
.attach-card-del:hover {
  background: var(--danger, #e05252);
  color: #fff;
  border-color: var(--danger, #e05252);
}
.attach-card-skill-thumb {
  background: linear-gradient(135deg, rgba(139,92,246,.25) 0%, rgba(99,102,241,.25) 100%) !important;
  border-color: rgba(139,92,246,.5) !important;
}
.ac-skill-icon {
  font-size: 26px;
  line-height: 1;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
}

.attach-wrap { position: relative; flex-shrink: 0; }

.attach-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 130px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5), var(--glow-sm);
  z-index: 50;
}

.attach-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background .12s;
}
.attach-opt:hover { background: var(--a-glow); }
.attach-opt-icon  { font-size: 16px; }

.attach-skill-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 240px;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px rgba(0,0,0,.5), var(--glow-sm);
  z-index: 50;
  overflow: hidden;
}

.attach-skill-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.attach-skill-search-wrap { padding: 6px 8px 2px; flex-shrink: 0; }
.attach-skill-search {
  width: 100%; box-sizing: border-box;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 12px;
  padding: 6px 10px; outline: none; transition: border-color .15s;
  font-family: var(--font);
}
.attach-skill-search:focus { border-color: var(--accent); }
.attach-skill-list  { overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.attach-skill-opt   { background: transparent; border: none; color: var(--text); font-size: 13px; padding: 8px 12px; border-radius: 8px; cursor: pointer; text-align: left; transition: background .12s; }
.attach-skill-opt:hover { background: var(--a-glow); }
.attach-skill-empty { color: var(--text3); font-size: 12px; padding: 8px 12px; margin: 0; }

.chat-input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 22px;
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
  font-family: var(--font);
}
.chat-input:focus { border-color: var(--border-active); box-shadow: 0 0 0 3px rgba(139,92,246,0.1); }

#stream-toggle {
  font-size: 17px;
  flex-direction: column;
  gap: 2px;
  padding: 5px 8px;
  min-width: 40px;
  color: var(--text3);
  border: 1px solid transparent;
  border-radius: 10px;
  transition: color .15s, background .15s, border-color .15s, box-shadow .15s;
}
#stream-toggle::after {
  content: 'OFF';
  font-family: var(--font);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .05em;
  line-height: 1;
  color: var(--text3);
  transition: color .15s;
}
#stream-toggle.active {
  color: var(--accent2);
  background: rgba(139,92,246,0.15);
  border-color: rgba(139,92,246,0.35);
  box-shadow: 0 0 10px rgba(139,92,246,0.2);
}
#stream-toggle.active::after {
  content: 'ON';
  color: var(--accent2);
}

/* ── CREDITS VIEW ────────────────────────────────────────────── */
.credits-balance-card {
  background: linear-gradient(135deg, var(--a-glow), var(--panel-bg));
  border: 1px solid rgba(139,92,246,0.28);
  border-radius: 22px;
  padding: 32px;
  text-align: center;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
}
.credits-balance-card::after {
  content: '◎';
  position: absolute;
  font-size: 120px;
  color: rgba(139,92,246,0.05);
  right: -20px; bottom: -20px;
  line-height: 1;
  pointer-events: none;
}
.balance-label  { font-size: 11px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 10px; }
.balance-amount {
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -2px;
  line-height: 1.1;
  margin: 8px 0 4px;
  background: linear-gradient(135deg, #fff, var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.balance-sub    { font-size: 13px; color: var(--text2); }

.packages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }

.pkg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  text-align: center;
  transition: border-color .2s, transform .15s, box-shadow .2s;
}
.pkg-card:hover { border-color: var(--border-active); transform: translateY(-2px); box-shadow: var(--glow-sm); }
.pkg-name    { font-weight: 700; font-size: 1rem; margin-bottom: 6px; }
.pkg-price   { font-size: 1.4rem; font-weight: 800; color: var(--accent2); margin-bottom: 4px; font-family: var(--font-mono); }
.pkg-credits { font-size: 13px; color: var(--text2); margin-bottom: 14px; }
.pkg-credits strong { color: var(--text); }

.credit-log { display: flex; flex-direction: column; gap: 6px; }
.log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
}
.log-amount          { font-weight: 700; font-family: var(--font-mono); }
.log-amount.positive { color: var(--success); }
.log-amount.negative { color: var(--danger); }
.log-action          { color: var(--text2); }
.log-date            { color: var(--text2); font-size: 11px; }

/* ── PROFILE VIEW ────────────────────────────────────────────── */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.avatar-upload-section { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.profile-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface2);
  border: 2px solid var(--border);
  box-shadow: 0 0 16px rgba(139,92,246,0.3);
}

/* ── ADMIN VIEW ──────────────────────────────────────────────── */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.admin-tab {
  padding: 9px 18px;
  color: var(--text2);
  background: transparent;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent2); border-bottom-color: var(--accent); }

.admin-panel { }

/* Table inside a card: pull it to card edges so row borders are full-width */
.card .data-table { margin: 0 -20px; width: calc(100% + 40px); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--a-glow); }
.data-table tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-purple { background: rgba(139,92,246,0.2); color: var(--accent2); }
.badge-cyan   { background: rgba(167,139,250,0.2); color: var(--accent2); }
.badge-green  { background: rgba(16,185,129,0.2);  color: var(--success); }
.badge-red    { background: rgba(239,68,68,0.2);   color: var(--danger); }

/* ── SKILL STORE ─────────────────────────────────────────────── */
.ss-search {
  width: 100%; padding: 9px 14px; box-sizing: border-box;
  background: var(--surface3); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 13px;
  outline: none; transition: border-color .15s;
  font-family: var(--font);
}
.ss-search:focus { border-color: var(--border-active); }
.ss-filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 6px; }
.ss-filter {
  padding: 4px 13px; border-radius: 20px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: transparent;
  color: var(--text2); cursor: pointer; transition: all .15s; font-family: var(--font);
}
.ss-filter:hover { border-color: var(--border-active); color: var(--text); }
.ss-filter.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ss-grid { display: flex; flex-direction: column; }
.ss-card {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 4px; border-radius: 10px;
  cursor: pointer; transition: background .12s; min-height: 72px;
}
.ss-card:hover { background: rgba(139,92,246,0.07); padding-left: 8px; padding-right: 4px; }
.ss-icon {
  width: 52px; height: 52px; border-radius: 13px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -0.5px;
}
.ss-info { flex: 1; min-width: 0; }
.ss-name { font-size: 14px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-sub  { font-size: 11px; color: var(--text3); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-desc { font-size: 12px; color: var(--text2); margin-top: 3px; line-height: 1.4;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.ss-get {
  flex-shrink: 0; padding: 5px 16px; border-radius: 20px;
  background: rgba(139,92,246,0.15); border: 1px solid rgba(139,92,246,0.35);
  color: var(--accent2); font-size: 12px; font-weight: 700;
  cursor: pointer; transition: all .15s; font-family: var(--font);
}
.ss-get:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.ss-get:disabled { opacity: .45; cursor: not-allowed; }
.ss-sep { height: 1px; background: var(--border); margin: 0 0 0 66px; }

/* ── MODAL ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--panel-bg);
  border: 1px solid rgba(139,92,246,0.28);
  border-radius: 20px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 0 60px rgba(109,40,217,0.2), 0 24px 64px rgba(0,0,0,.6);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; max-height: calc(85vh - 70px); }

/* ── TOAST ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  box-shadow: 0 8px 24px rgba(0,0,0,.5), var(--glow-sm);
  animation: slideLeft .2s ease;
  max-width: 320px;
  backdrop-filter: blur(12px);
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger); }
.toast.memory  { border-color: var(--accent); color: var(--accent); }
@keyframes slideLeft { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* In-panel memory saved announcement */
.mem-announcement {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600;
  padding: 6px 10px; margin: 6px 0;
  border-radius: 8px;
  background: rgba(139,92,246,0.1);
  border: 1px solid rgba(139,92,246,0.25);
  color: var(--text);
}
.mem-ann-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.mem-ann-in  { animation: memAnnIn .22s ease forwards; }
.mem-ann-out { animation: memAnnOut .3s ease forwards; }
@keyframes memAnnIn  { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:none; } }
@keyframes memAnnOut { from { opacity:1; } to { opacity:0; } }

/* ── LOADING SPINNER ─────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text2);
}

/* ── MEDIA LIBRARY ───────────────────────────────────────────── */
.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
@media (max-width: 600px) { .lib-grid { grid-template-columns: repeat(2, 1fr); } }

.lib-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  cursor: pointer;
}
.lib-card:hover { border-color: var(--border-active); transform: translateY(-2px); box-shadow: var(--glow-sm); }

.lib-thumb {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  background: var(--surface2);
}
.lib-media { width: 100%; height: 100%; object-fit: cover; display: block; }

.lib-badge {
  position: absolute;
  top: 6px; right: 6px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.lib-badge-uploaded  { background: rgba(34,211,238,0.15); color: #67e8f9; border: 1px solid rgba(34,211,238,0.2); }
.lib-badge-generated { background: rgba(139,92,246,0.15); color: var(--accent2); border: 1px solid var(--border); }

.lib-thumb-audio {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.lib-audio-icon { font-size: 40px; color: var(--accent2); line-height: 1; user-select: none; filter: drop-shadow(0 0 8px var(--accent)); }
.lib-audio-name { font-size: 11px; color: var(--text2); text-align: center; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90%; }

.lib-thumb-doc {
  background: linear-gradient(135deg, rgba(30,20,58,1) 0%, var(--surface2) 100%);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
/* PPTX / image thumbnails inside doc card must fill the container */
.lib-thumb-doc > img.lib-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  flex: none;
}
.lib-doc-icon { font-size: 38px; line-height: 1; user-select: none; filter: drop-shadow(0 0 6px rgba(139,92,246,0.5)); }
.lib-doc-ext  { font-size: 10px; font-weight: 700; letter-spacing: .06em; color: var(--accent2); text-transform: uppercase; background: rgba(139,92,246,0.15); border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; }

.lib-detail-preview.is-doc {
  aspect-ratio: unset;
  height: 280px;
  background: var(--surface2);
  overflow: hidden;
  align-items: stretch;
}
.lib-detail-preview.is-doc > iframe { width: 100%; height: 100%; border: none; }

.lib-card-body  { padding: 8px 10px; }
.lib-label      { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px; }
.lib-tags       { display: flex; flex-wrap: wrap; gap: 4px; min-height: 18px; margin-bottom: 6px; }
.lib-tag        { background: var(--a-glow); color: var(--text2); font-size: 10px; padding: 2px 7px; border-radius: 10px; border: 1px solid var(--border); }
.lib-actions    { display: flex; gap: 4px; flex-wrap: wrap; }
.lib-analysis   { margin-top: 6px; font-size: 11px; color: var(--text2); line-height: 1.4; max-height: 54px; overflow: hidden; }

/* ── Library Detail Panel ─────────────────────────────────────── */
#lib-detail-backdrop.hidden {
  display: block !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
#lib-detail-panel.hidden {
  display: flex !important;
  transform: translateX(100%) !important;
  pointer-events: none !important;
}

.lib-detail-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 190;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.lib-detail-backdrop.open { opacity: 1; pointer-events: auto; }

.lib-detail-panel {
  position: fixed;
  top: 0; right: 0;
  width: 400px;
  height: 100vh;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
  backdrop-filter: blur(16px);
}
.lib-detail-panel.open { transform: translateX(0); }

.lib-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.lib-detail-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface2);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lib-detail-preview img,
.lib-detail-preview video { width: 100%; height: 100%; object-fit: contain; }

.lib-detail-preview.is-audio {
  aspect-ratio: unset;
  height: auto;
  min-height: 140px;
  padding: 28px 24px;
  flex-direction: column;
  gap: 12px;
}
.lib-detail-preview.is-audio audio { width: 100%; height: 48px; }

.lib-preview-fullscreen-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  border-radius: 6px;
  padding: 4px 8px;
  line-height: 1;
  opacity: 0;
  transition: opacity .15s;
}
.lib-detail-preview:hover .lib-preview-fullscreen-btn { opacity: 1; }

.lib-detail-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 0; }

.lib-detail-input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--font);
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.lib-detail-input:focus { border-color: var(--border-active); }
.lib-detail-input[readonly] { opacity: .6; cursor: default; }

.lib-detail-meta {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 8px 0 12px;
}
.lib-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.lib-meta-row:last-child { border-bottom: none; }
.lib-meta-label { color: var(--text2); font-weight: 500; }

.lib-detail-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding-top: 4px; }

/* ── LIBRARY: LOCK / VIEWS / DOC THUMB / SHARE ───────────────── */
.lib-lock-badge {
  position: absolute;
  top: 6px; left: 6px;
  font-size: 12px;
  line-height: 1;
  background: rgba(0,0,0,.55);
  border-radius: 6px;
  padding: 2px 5px;
  pointer-events: none;
}
.lib-views-badge {
  position: absolute;
  bottom: 6px; left: 6px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
  background: rgba(0,0,0,.55);
  color: var(--text2);
  pointer-events: none;
}
.lib-card-locked { opacity: .65; }
.lib-card-locked .lib-thumb { filter: grayscale(.4); }

/* HTML card thumbnail — scaled-down iframe */
.lib-html-thumb-wrap {
  width: 100%; height: 100%;
  overflow: hidden;
  position: relative;
}
/* Loading shimmer shown before lazy iframe fires */
.lib-thumb-lazy {
  background: var(--surface2);
}
.lib-thumb-lazy:not(:has(iframe))::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%, rgba(255,255,255,.04) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }
.lib-html-thumb-iframe {
  position: absolute;
  top: 0; left: 0;
  width: 300%;
  height: 300%;
  transform: scale(.333);
  transform-origin: top left;
  border: none;
  pointer-events: none;
}

.lib-badge-shared { background: rgba(16,185,129,0.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.25); }

/* Share-with-users section */
/* Inline share panel — drops below Share button */
.lib-share-inline {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 6px;
  background: var(--surface2);
  animation: fadeInDown .15s ease;
}
.lib-share-inline.hidden { display: none; }
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.lib-share-inline-input {
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
  font-family: inherit;
}
.lib-share-inline-input::placeholder { color: var(--text2); }
.lib-share-inline-input:focus { background: var(--surface3, rgba(255,255,255,.03)); }
.lib-share-results, .lib-share-current { padding: 4px 0; }
.lib-share-result-row, .lib-share-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background .12s;
}
.lib-share-result-row:hover { background: var(--surface3, rgba(255,255,255,.04)); }
.lib-share-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: var(--surface2); }
.lib-share-uname { font-size: 13px; font-weight: 500; flex: 1; }
.lib-share-email { font-size: 11px; color: var(--text2); }
.lib-share-add-btn {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border-active);
  border-radius: 6px;
  background: transparent;
  color: var(--accent2);
  cursor: pointer;
  white-space: nowrap;
}
.lib-share-add-btn:hover { background: rgba(139,92,246,.15); }
.lib-share-remove {
  background: transparent;
  border: none;
  color: var(--text2);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  margin-left: auto;
}
.lib-share-remove:hover { color: #f87171; }
.lib-share-empty { font-size: 12px; color: var(--text2); padding: 8px 12px; }
/* Count badge inside Share button */
.lib-share-btn-badge {
  display: inline-block;
  background: var(--accent2);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 6px;
  min-width: 16px;
  text-align: center;
  margin-left: 4px;
  vertical-align: middle;
}
/* Separator between search results and current shared list */
#ld-share-current-list:not(:empty) { border-top: 1px solid var(--border); }
/* Public link section */
.lib-share-public-section {
  border-top: 1px solid var(--border);
  padding: 8px 10px;
}
.lib-share-public-link-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.lib-share-public-link-input {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text1);
  font-size: 11px;
  padding: 4px 8px;
  cursor: text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-share-public-views {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
}
.lib-share-public-btn {
  width: 100%;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 7px;
  color: var(--text2);
  font-size: 12px;
  padding: 7px 10px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  text-align: center;
}
.lib-share-public-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── CHARACTER DETAIL VIEW ───────────────────────────────────── */
#view-character-detail {
  padding: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.cd-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
  gap: 12px;
  backdrop-filter: blur(12px);
}

.cd-topbar-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.cd-avatar-wrap {
  width: 38px; height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid var(--accent);
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent2);
  box-shadow: 0 0 10px rgba(139,92,246,0.4);
}

.cd-identity    { min-width: 0; }
.cd-name        { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cd-desc-short  { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cd-tab-bar {
  display: flex;
  gap: 2px;
  background: rgba(139,92,246,0.07);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  flex-shrink: 0;
}

.cd-tab {
  padding: 7px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text2);
  background: transparent;
  transition: background .15s, color .15s;
}
.cd-tab.active { background: rgba(139,92,246,0.22); color: var(--accent2); }
.cd-tab:hover:not(.active) { background: rgba(139,92,246,0.08); color: var(--text); }

.cd-topbar-right { flex-shrink: 0; }

/* ── Panels ─────────────────────────────────────────────────── */
.cd-panel { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.cd-panel-memory { overflow: hidden; position: relative; }

/* ── Skills Panel ────────────────────────────────────────────── */
.cd-skills-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 40px 20px 20px;
  text-align: center;
  flex-shrink: 0;
}

.cd-skills-avatar-ring {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid transparent;
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
  color: var(--accent2);
  box-shadow: 0 0 28px rgba(139,92,246,0.4), 0 0 60px rgba(109,40,217,0.2);
}

.cd-skills-hero-title  { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; }
.cd-skills-hero-sub    { font-size: 1rem; color: var(--text2); margin-top: 2px; }
.cd-charname-accent    { color: var(--text); font-weight: 700; }

.cd-skills-filter-bar { display: flex; justify-content: center; gap: 8px; padding: 0 24px 18px; flex-shrink: 0; }

.cd-sf {
  background: var(--a-glow);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 20px;
  padding: 5px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.cd-sf.active { background: rgba(139,92,246,0.22); color: var(--accent2); border-color: var(--border-active); box-shadow: var(--glow-sm); }
.cd-sf:hover:not(.active) { background: rgba(139,92,246,0.12); color: var(--text); }

.cd-skills-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 24px 32px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}
@media (max-width: 700px) { .cd-skills-grid { grid-template-columns: 1fr; padding: 0 16px 24px; } }

.cd-skill-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: border-color .15s, box-shadow .15s;
  position: relative;
}
.cd-skill-card:hover      { border-color: var(--border-active); box-shadow: var(--glow-sm); }
.cd-skill-card.active-skill { border-color: rgba(139,92,246,0.35); }

.cd-skill-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--a-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.cd-skill-info  { flex: 1; min-width: 0; }
.cd-skill-name  { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.cd-skill-desc  { font-size: 12px; color: var(--text2); line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.cd-skill-check { position: absolute; top: 12px; right: 14px; color: var(--success); font-size: 14px; font-weight: 700; }

.cd-skill-card { cursor: pointer; }

.cd-skill-action-btn {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  font-size: 18px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  align-self: center;
}
.cd-skill-action-btn.add:hover  { background: var(--accent); border-color: var(--accent); color: #fff; }
.cd-skill-action-btn.remove     { border-color: rgba(239,68,68,.4); color: rgba(239,68,68,.8); }
.cd-skill-action-btn.remove:hover { background: rgba(239,68,68,.15); border-color: rgba(239,68,68,.7); color: #ef4444; }

/* ── Skill Detail Sheet ──────────────────────────────────────── */
.skill-sheet-overlay {
  position: fixed; inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  z-index: 200;
}
.skill-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 540px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  z-index: 201;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.skill-sheet.open { transform: translateY(0); }
.skill-sheet-handle {
  width: 40px; height: 4px;
  background: var(--border-active);
  border-radius: 2px;
  margin: 12px auto 0;
}
.skill-sheet-body { padding: 20px 24px 28px; }
.skill-sheet-header {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 16px;
}
.skill-sheet-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--a-glow);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.skill-sheet-title-block { flex: 1; min-width: 0; }
.skill-sheet-name     { font-size: 18px; font-weight: 700; }
.skill-sheet-category { font-size: 12px; color: var(--accent2); text-transform: uppercase; letter-spacing: .06em; margin-top: 2px; }
.skill-sheet-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text2); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.skill-sheet-desc {
  font-size: 14px; color: var(--text2); line-height: 1.6;
  margin-bottom: 20px;
}
.skill-sheet-meta {
  display: flex; gap: 12px; margin-bottom: 24px;
}
.skill-meta-item {
  flex: 1; background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px;
}
.skill-meta-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text3); }
.skill-meta-val   { font-size: 13px; font-weight: 600; color: var(--text); }
.skill-sheet-actions { display: flex; }
.skill-sheet-actions .btn-primary,
.skill-sheet-actions .btn-danger  { flex: 1; justify-content: center; }

.btn-danger {
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.4);
  color: #ef4444;
  padding: 10px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.btn-danger:hover { background: rgba(239,68,68,.25); }

/* ── Memory Panel ────────────────────────────────────────────── */
.cd-mem-header { text-align: center; padding: 28px 20px 10px; flex-shrink: 0; }
.cd-mem-title  { font-size: 1.5rem; font-weight: 800; color: var(--text); letter-spacing: -0.02em; margin: 0 0 4px; }
.cd-mem-subtitle { font-size: 13px; color: var(--text2); }
.cd-mem-actions { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.cd-mem-action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--glass-overlay); color: var(--text2); font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.cd-mem-action-btn:hover { background: var(--glass-hover); border-color: var(--border-active); color: var(--text); }
.cd-mem-action-evolve:hover { border-color: rgba(139,92,246,.6); color: rgb(167,139,250); }
.cd-mem-action-danger:hover { border-color: rgba(239,68,68,.5); color: var(--danger); }

/* Source tag badge on memory pills */
.mcn-source-tag {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 1px 5px; border-radius: 6px; margin-left: 5px; opacity: .75;
  background: rgba(255,255,255,.12); color: var(--text2); white-space: nowrap; flex-shrink: 0;
}
.mcn-source-tag.src-chat { background: rgba(6,182,212,.18); color: rgb(103,232,249); }
.mcn-source-tag.src-doc  { background: rgba(245,158,11,.18); color: rgb(252,211,77); }
.mcn-source-tag.src-skill { background: rgba(124,58,237,.2); color: rgb(196,181,253); }
.mcn-source-tag.src-evolve { background: rgba(174,226,50,.18); color: rgb(190,242,100); }
a.mcn-source-tag.src-file { background: rgba(16,185,129,.18); color: rgb(52,211,153); text-decoration: none; cursor: pointer; }
a.mcn-source-tag.src-file:hover { background: rgba(16,185,129,.32); opacity: 1; }

/* Memory file-link inline form */
.cd-mem-filelink-form {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

/* Evolve modal */
.evolve-modal { max-width: 540px; width: 92vw; }
.evolve-subtitle { font-size: 13px; color: var(--text2); margin: 0 0 14px; }
.evolve-proposals { display: flex; flex-direction: column; gap: 10px; max-height: 52vh; overflow-y: auto; }
.evolve-card {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--glass-overlay); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.evolve-card.selected { border-color: var(--border-active); background: var(--glass-hover); }
.evolve-card-check { width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--border); flex-shrink: 0; margin-top: 1px; display: flex; align-items: center; justify-content: center; background: transparent; transition: background .12s, border-color .12s; }
.evolve-card.selected .evolve-card-check { background: var(--accent); border-color: var(--accent); }
.evolve-card-check::after { content: '✓'; font-size: 11px; color: #fff; display: none; }
.evolve-card.selected .evolve-card-check::after { display: block; }
.evolve-card-body { flex: 1; }
.evolve-card-content { font-size: 13px; color: var(--text); font-weight: 600; line-height: 1.4; margin-bottom: 4px; }
.evolve-card-note { font-size: 11px; color: var(--text2); }
.evolve-card-absorbs { font-size: 10px; color: rgba(245,158,11,.8); margin-top: 3px; }
.evolve-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Conflict modal */
.conflict-modal { max-width: 420px; width: 92vw; }
.conflict-existing-label { font-size: 12px; color: var(--text2); margin: 0 0 6px; font-weight: 600; }
.conflict-existing-box { background: var(--glass-overlay); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--text); margin-bottom: 14px; line-height: 1.5; }
.conflict-question { font-size: 13px; color: var(--text2); margin: 0 0 12px; }
.conflict-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@keyframes mcn-root-glow {
  0%, 100% { box-shadow: 0 0 14px rgba(0,0,0,.5), 0 0 32px rgba(174,226,50,.4), 0 0 72px rgba(174,226,50,.15); }
  50%       { box-shadow: 0 0 14px rgba(0,0,0,.5), 0 0 54px rgba(174,226,50,.7), 0 0 110px rgba(174,226,50,.28); }
}

.cd-mem-map {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 240px;
  background: radial-gradient(ellipse 60% 55% at 50% 50%, rgba(139,92,246,.07) 0%, rgba(0,0,0,0) 70%), #09050f;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.cd-mem-map.mem-panning { cursor: grabbing !important; }

.mem-cv-vp  { position: absolute; top: 0; left: 0; transform-origin: 0 0; pointer-events: none; }
.mem-cv-svg { position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.mem-cv-nd  { position: absolute; top: 0; left: 0; width: 0; height: 0; }

.mcn-root {
  position: absolute;
  width: 72px; height: 72px;
  border-radius: 50%;
  transform: translate(-36px, -36px);
  pointer-events: auto;
  overflow: hidden;
  box-shadow: 0 0 14px rgba(0,0,0,.5), 0 0 32px rgba(174,226,50,.4), 0 0 72px rgba(174,226,50,.15);
  background: radial-gradient(circle, #e4ff55 0%, #aadc35 55%, #6aab10 100%);
  cursor: pointer;
  animation: mcn-root-glow 2.8s ease-in-out infinite;
}

.mcn-cat {
  position: absolute;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--a-glow);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(-21px, -21px);
  pointer-events: auto;
  cursor: grab;
  transition: background .2s, border-color .2s, box-shadow .2s;
}
.mcn-cat:hover {
  background: var(--glass-overlay);
  border-color: var(--border-active);
  box-shadow: 0 0 18px var(--accent-glow);
}

.mcn-pill         { position: absolute; height: 34px; border-radius: 34px; transform: translate(-50%, -17px); }
.mcn-pill-fill    { background: var(--glass-overlay); border: 1px solid var(--glass-hover); color: var(--text); font-size: 12px; padding: 0 14px; white-space: nowrap; display: flex; align-items: center; pointer-events: auto; cursor: grab; transition: background .15s, border-color .15s, box-shadow .15s; }
.mcn-pill-fill:hover { background: var(--glass-hover); border-color: var(--border-active); box-shadow: 0 0 12px var(--accent-glow); }

.mcn-title     { position: absolute; transform: translate(-50%, -100%); text-align: center; pointer-events: none; white-space: nowrap; padding-bottom: 8px; }
.mcn-t1        { font-size: 15px; font-weight: 700; color: var(--text); }
.mcn-t2        { font-size: 12px; color: var(--text2); margin-top: 2px; }

.mcn-add-node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: auto;
  cursor: pointer;
}
.mcn-add-circle {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--a-glow);
  border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  font-size: 18px; line-height: 1;
  transition: background .2s, border-color .2s, color .2s, box-shadow .2s;
}
.mcn-add-lbl {
  font-size: 10px;
  color: var(--text3);
  white-space: nowrap;
  letter-spacing: 0.02em;
  transition: color .2s;
}
.mcn-add-node:hover .mcn-add-circle {
  background: rgba(139,92,246,0.22);
  border-color: rgba(139,92,246,0.65);
  border-style: solid;
  color: #fff;
  box-shadow: 0 0 16px rgba(139,92,246,0.35);
}
.mcn-add-node:hover .mcn-add-lbl { color: var(--text2); }

/* Hover-triggered add node: fade in */
.mcn-hover-add { opacity: 0; transition: opacity .18s ease; pointer-events: none; }
.mcn-hover-add:not(.hidden) { opacity: 1; pointer-events: auto; }

/* Pill edit mode: glow the selected pill */
.mcn-pill-fill.mem-active-edit {
  background: rgba(139,92,246,0.22);
  border-color: rgba(167,139,250,0.6);
  box-shadow: 0 0 14px rgba(139,92,246,0.4);
}

.cd-mem-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px 13px;
  border-top: 1px solid var(--border);
  background: var(--sidebar-bg);
  flex-shrink: 0;
  backdrop-filter: blur(12px);
}
.cd-mem-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cd-mem-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cd-mem-bar-label { font-size: 13px; color: var(--text2); font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.cd-mem-token-counter {
  font-size: 11px;
  color: var(--text2);
  opacity: 0.6;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cd-mem-token-counter.near-limit { color: rgba(245,158,11,0.9); opacity: 1; }
.cd-mem-token-counter.at-limit   { color: rgba(239,68,68,0.9);  opacity: 1; }

.cd-mem-bar-input {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 3px 6px;
  transition: border-color .15s, box-shadow .15s;
}
.cd-mem-bar-input:focus-within { border-color: var(--border-active); box-shadow: 0 0 0 3px rgba(139,92,246,0.1); }

/* Edit mode: amber tint on bar */
.cd-mem-bar.mem-editing .cd-mem-bar-label::after { content: ' (editing)'; color: rgba(245,158,11,0.8); font-size: 11px; }
.cd-mem-bar.mem-editing .cd-mem-bar-input { border-color: rgba(245,158,11,0.4); }
.cd-mem-bar.mem-editing .cd-mem-bar-input:focus-within { border-color: rgba(245,158,11,0.7); box-shadow: 0 0 0 3px rgba(245,158,11,0.12); }
.cd-mem-bar.mem-editing .btn-send { background: linear-gradient(135deg,#b45309,#d97706); }
.cd-mem-del { display: none; color: rgba(239,68,68,0.8); }
.cd-mem-bar.mem-editing .cd-mem-del { display: inline-flex; }
.cd-mem-del:hover { color: rgb(239,68,68); }

/* ── Memory image preview chip ─────────────────────────────────── */
.cd-mem-img-preview {
  display: flex;
  align-items: center;
  padding: 0 2px;
}
.cd-mem-img-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(139,92,246,0.12);
  border: 1px solid rgba(139,92,246,0.35);
  border-radius: 10px;
  padding: 4px 6px 4px 4px;
  font-size: 12px;
  color: var(--text2);
  max-width: 100%;
}
.cd-mem-img-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  border: 1px solid rgba(139,92,246,0.3);
}
.cd-mem-img-chip-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text1);
  font-size: 12px;
}
.cd-mem-img-chip-del {
  flex-shrink: 0;
  width: 20px !important;
  height: 20px !important;
  font-size: 11px !important;
  color: var(--text2);
  border-radius: 50% !important;
}
.cd-mem-img-chip-del:hover { color: var(--danger) !important; }
.cd-mem-img-chip--loading { border-color: rgba(139,92,246,0.6); animation: memChipPulse 1.2s ease-in-out infinite; }
.cd-mem-img-chip--loading .cd-mem-img-chip-label { color: var(--accent2); font-style: italic; }
@keyframes memChipPulse {
  0%, 100% { box-shadow: none; }
  50%       { box-shadow: 0 0 10px rgba(139,92,246,0.4); }
}

/* ── Memory attach menu ────────────────────────────────────────── */
.cd-mem-attach-wrap { position: relative; flex-shrink: 0; }
.cd-mem-attach-btn {
  font-size: 18px;
  border-radius: 50%;
  width: 34px; height: 34px;
  padding: 0;
  position: relative;
  transition: transform .18s, color .15s, background .15s;
  overflow: visible;
}
.cd-mem-attach-btn::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(174,226,50,0.32) 0%, rgba(174,226,50,0.12) 55%, transparent 75%);
  opacity: 0;
  transform: scale(0.55);
  transition: opacity .22s, transform .22s;
  pointer-events: none;
}
.cd-mem-attach-btn:hover::before { opacity: 1; transform: scale(1); }
.cd-mem-attach-btn:hover {
  color: var(--accent);
  background: transparent !important;
  transform: rotate(45deg);
}

.cd-mem-attach-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  background: var(--panel-bg);
  border: 1px solid rgba(139,92,246,0.28);
  border-radius: 14px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 200px;
  box-shadow: 0 8px 40px rgba(0,0,0,.85), 0 0 0 1px rgba(139,92,246,.15);
  z-index: 120;
  animation: fadeSlideUp .15s ease;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cd-mem-attach-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  transition: background .12s, color .12s;
  text-align: left;
  width: 100%;
  cursor: pointer;
}
.cd-mem-attach-opt:hover { background: rgba(139,92,246,0.22); color: #fff; }
.cd-mem-attach-icon { font-size: 15px; width: 22px; text-align: center; flex-shrink: 0; }

/* ── Skill / Library pickers (bottom sheet style) ──────────────── */
.cd-mem-skill-picker,
.cd-mem-lib-picker {
  position: absolute;
  bottom: 70px;
  left: 12px; right: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,.7);
  backdrop-filter: blur(20px);
  z-index: 110;
  overflow: hidden;
  animation: fadeSlideUp .15s ease;
}
.cd-mem-picker-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px 10px;
  font-size: 13px; font-weight: 700; color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cd-mem-skill-list {
  overflow-y: auto;
  padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.cd-mem-skill-opt {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: background .12s;
}
.cd-mem-skill-opt:hover { background: rgba(139,92,246,0.18); color: #fff; }

.cd-mem-lib-grid {
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}
.cd-mem-lib-thumb {
  border-radius: 8px;
  border: 1.5px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--glass-overlay);
  font-size: 11px; color: var(--text2);
  text-align: center; padding: 4px;
  transition: border-color .12s, background .12s;
}
.cd-mem-lib-thumb:hover { border-color: rgba(139,92,246,.6); background: rgba(139,92,246,.1); }
.cd-mem-lib-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.cd-mem-lib-thumb .lib-thumb-icon { font-size: 22px; margin-bottom: 3px; }
.cd-mem-lib-thumb .lib-thumb-lbl  { font-size: 10px; color: var(--text2); line-height: 1.2; word-break: break-all; max-width: 100%; }

/* Chat library picker — override attach-skill-picker sizing */
#chat-lib-picker {
  left: 0;
  right: 0;
  width: auto;
  max-height: 420px;
}

/* Chat library picker grid */
.chat-lib-grid {
  overflow-y: auto;
  padding: 6px 10px 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  max-height: 300px;
}
.chat-lib-selectable {
  position: relative;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.chat-lib-selectable.selected {
  border-color: var(--accent) !important;
  background: rgba(139,92,246,0.18) !important;
  box-shadow: 0 0 0 2px rgba(139,92,246,0.35);
}
.chat-lib-selectable.selected::after {
  content: '✓';
  position: absolute;
  top: 3px; right: 5px;
  font-size: 11px; font-weight: 800;
  color: var(--accent);
  pointer-events: none;
}

.cd-mem-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  padding: 5px 4px;
  outline: none;
  min-width: 0;
  font-family: var(--font);
}

/* ── CHARACTER EDIT BUTTON ───────────────────────────────────── */
.char-edit-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,.6);
  border: none;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.char-card:hover .char-edit-btn { opacity: 1; }

/* ── MODAL TABS ──────────────────────────────────────────────── */
.modal-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.modal-tab {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 4px 12px;
  font-size: 13px;
  border-radius: 6px;
  font-family: var(--font);
}
.modal-tab.active { background: rgba(139,92,246,0.22); color: var(--accent2); }

/* ── SKILL FILE VIEWER ───────────────────────────────────────── */
.skill-file-pre {
  margin: 0;
  padding: 14px 16px;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  overflow: auto;
  max-height: 56vh;
  white-space: pre;
  tab-size: 4;
}

/* ── SETTINGS GRID ───────────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .settings-grid { grid-template-columns: 1fr; } }

/* ── MISC UTILITIES ──────────────────────────────────────────── */
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-secondary {
  background: var(--a-glow);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  font-family: var(--font);
  transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: rgba(139,92,246,0.22); border-color: var(--border-active); }
.skills-sub-tab.active { background: rgba(139,92,246,0.22); border-color: var(--border-active); color: var(--accent2); }

/* ── Role Permission Editor ───────────────────────────────────── */
.role-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.role-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.role-label-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 5px 10px;
}
.role-label-input:focus { outline: none; border-color: var(--border-active); }
.role-desc-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  font-family: var(--font);
  font-size: 12px;
  padding: 6px 10px;
  resize: none;
  margin-bottom: 10px;
}
.role-desc-input:focus { outline: none; border-color: var(--border-active); color: var(--text); }
.role-perms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 6px 16px;
}
.role-perm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  padding: 3px 0;
}
.role-perm-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.role-perm-row:hover { color: var(--text); }

.mb-3        { margin-bottom: 20px; }
.field-hint  { font-size: 12px; color: var(--text2); margin-bottom: 10px; }
.view-sub    { color: var(--text2); font-size: 13px; margin-bottom: 18px; }

/* ── MOBILE ──────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .mobile-only { display: flex !important; }

  #sidebar {
    position: fixed;
    left: -280px;
    width: var(--sidebar-w);
    top: 0; bottom: 0;
    z-index: 150;
    transition: left .25s ease;
    box-shadow: 4px 0 32px rgba(109,40,217,0.2);
    -webkit-overflow-scrolling: touch;
  }
  #sidebar.open { left: 0; }

  #app    { flex-direction: column; }
  #main   { padding-top: 56px; padding-bottom: 82px; overflow-x: hidden; -webkit-overflow-scrolling: touch; }

  .view        { padding: 16px; }
  .view-header { margin-bottom: 18px; }
  h1           { font-size: 1.3rem; }

  .char-grid    { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .packages-grid { grid-template-columns: 1fr 1fr; }
  .profile-grid  { grid-template-columns: 1fr; }

  .msg { max-width: 88%; }

  .toast { bottom: 90px; right: 12px; left: 12px; max-width: none; }

  .mobile-bottom-bar { display: flex; }

  /* ── Fullscreen chat mode ─────────────────────────── */
  body.mob-chat-mode .mobile-topbar     { transform: translateY(-100%); pointer-events: none; }
  body.mob-chat-mode .mobile-bottom-bar { transform: translateY(100%);  pointer-events: none; }
  body.mob-chat-mode #main              { padding-top: 0 !important; padding-bottom: 0 !important; }
  body.mob-chat-mode #view-chat         { height: 100vh !important; height: 100svh !important; }

  body.mob-chat-mode .mob-chat-handle   { display: flex; opacity: 1; pointer-events: auto; }

  /* Bars pulled up: restore layout, hide handle */
  body.mob-chat-mode.mob-bars-visible .mobile-topbar     { transform: translateY(0); pointer-events: auto; }
  body.mob-chat-mode.mob-bars-visible .mobile-bottom-bar { transform: translateY(0); pointer-events: auto; }
  body.mob-chat-mode.mob-bars-visible #main              { padding-top: 56px !important; padding-bottom: 82px !important; }
  body.mob-chat-mode.mob-bars-visible #view-chat         { height: calc(100vh - 56px - 82px) !important; height: calc(100svh - 56px - 82px) !important; }
  body.mob-chat-mode.mob-bars-visible .mob-chat-handle   { opacity: 0; pointer-events: none; }

  /* svh = small viewport height (address bar fully visible) — prevents input from hiding under browser chrome */
  #view-chat {
    flex-direction: column;
    height: calc(100vh - 56px - 82px);       /* fallback for old browsers */
    height: calc(100svh - 56px - 82px);      /* stable: sized for worst-case chrome */
  }
  /* Mobile: full-width drawer from the top.
     Use an explicit height (not just max-height) so the flex container has a
     defined size — without it, flex:1 on the body has nothing to grow into and
     collapses to 0px, hiding all artifacts behind overflow:hidden.
     translateY(-100%) also measures the element's own height, so an explicit
     height gives the slide animation a stable, predictable distance. */
  .inception-window {
    position: fixed;
    top: 0; left: 0; right: 0;
    width: 100%;
    height: 55vh;           /* explicit height — replaces max-height */
    max-height: 55vh;       /* belt-and-suspenders cap */
    border-left: none;
    border-bottom: 1px solid var(--border);
    z-index: 200;
    transform: translateY(-100%);
    opacity: 1;
    transition: transform .25s ease;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  }
  .inception-window.open {
    transform: translateY(0);
    opacity: 1;
  }
  .iw-resize-handle { display: none; }

  /* Override desktop rule — inception slides from top on mobile, not from right */
  #view-chat.iw-open .chat-main-area { margin-right: 0; }

  /* Push chat content below the inception overlay when both are open */
  body.mob-chat-mode #view-chat.iw-open { padding-top: 55vh; }

  /* Body fills the remaining height below the header and scrolls internally. */
  .inception-body {
    flex: 1;
    min-height: 0;           /* allow flex child to shrink below content size */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #view-character-detail {
    height: calc(100vh - 56px - 82px);
    height: calc(100svh - 56px - 82px);
  }

  .cd-topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px 0; }
  .cd-topbar-left  { flex: 1; min-width: 0; }
  .cd-topbar-right { flex-shrink: 0; }
  .cd-tab-bar { order: 3; width: 100%; justify-content: center; margin-bottom: 2px; }
  .cd-tab     { padding: 7px 14px; font-size: 13px; }

  .cd-skills-hero  { padding: 20px 16px 14px; }
  .cd-skills-hero-title { font-size: 1.2rem; }

  .cd-mem-bar { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 14px; }
  .cd-mem-bar-label { text-align: center; }

  /* Admin — scrollable tabs + table */
  .admin-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-tab  { flex-shrink: 0; padding: 9px 12px; font-size: 13px; }
  .admin-panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Users table: hide ID and Email columns so table fits viewport */
  #users-table .data-table th:nth-child(1),
  #users-table .data-table td:nth-child(1),
  #users-table .data-table th:nth-child(3),
  #users-table .data-table td:nth-child(3) { display: none; }

  /* Tighten remaining cell padding on mobile */
  .data-table th, .data-table td { padding: 8px 8px; }
}

/* ── PWA STANDALONE MODE ─────────────────────────────────────── */
/* When launched from home screen (no browser chrome), use full 100svh */
@media (display-mode: standalone) {
  #view-chat,
  #view-character-detail {
    height: calc(100svh - 56px - 82px);
  }
  /* Push content below the iOS status bar (notch) */
  .mobile-topbar {
    padding-top: env(safe-area-inset-top, 0);
    height: calc(56px + env(safe-area-inset-top, 0));
  }
  #main {
    padding-top: calc(56px + env(safe-area-inset-top, 0));
  }
  /* iOS home indicator clearance on bottom nav */
  .mobile-bottom-bar {
    height: calc(82px + env(safe-area-inset-bottom, 0));
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  #main {
    padding-bottom: calc(82px + env(safe-area-inset-bottom, 0));
  }
}

/* ── SIDEBAR OVERLAY (mobile) ────────────────────────────────── */
#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); z-index: 140; }
#sidebar-overlay.show { display: block; }

/* ── LANGUAGE SWITCHER ───────────────────────────────────────── */
.lang-switcher {
  display: flex;
  gap: 3px;
  align-items: center;
  flex-shrink: 0;
}
.lang-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.15s, border-color 0.15s;
}
.lang-btn.active {
  opacity: 1;
  border-color: var(--accent);
}
.lang-btn:hover { opacity: 0.8; }

/* ── Timezone picker ─────────────────────────────────────────── */
.tz-picker { position: relative; }
.tz-picker #tz-search { cursor: pointer; padding-right: 32px; }
.tz-picker #tz-search:focus { cursor: text; }
.tz-picker::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text2);
  pointer-events: none;
  font-size: 13px;
}
.tz-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border-active);
  border-radius: var(--radius);
  max-height: 260px;
  overflow-y: auto;
  z-index: 9999;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55);
}
.tz-group {
  padding: 5px 12px 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
  background: var(--surface3);
  position: sticky;
  top: 0;
  z-index: 1;
}
.tz-opt {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
}
.tz-opt:hover,
.tz-opt.focused { background: var(--glass-hover); }
.tz-opt.active {
  color: var(--accent2);
  background: var(--a-glow);
}

/* Auth screen lang switcher — centered below logo */
.auth-lang {
  justify-content: center;
  margin: 6px 0 4px;
}

/* Sidebar lang switcher — sits below logo in column group */
.sidebar-lang {
  margin: 0;
}

/* Mobile topbar lang picker — single active flag + dropdown */
.mob-lang-picker { position: relative; }
.mob-lang-trigger {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(139,92,246,0.1);
  border: 1px solid rgba(139,92,246,0.3);
  border-radius: 8px;
  padding: 3px 7px 3px 5px;
  cursor: pointer;
  line-height: 0;
  transition: background 0.15s, border-color 0.15s;
}
.mob-lang-trigger:hover { background: rgba(139,92,246,0.2); border-color: rgba(139,92,246,0.5); }
.mob-lang-caret { font-size: 10px; color: var(--accent2); opacity: 0.7; line-height: 1; }
.mob-lang-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  z-index: 400;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 44px;
}
.mob-lang-dropdown.open { display: flex; }
.mob-lang-dropdown .lang-btn { width: 100%; justify-content: center; padding: 4px 6px; }

/* ── Google Connector ─────────────────────────────────────────────────────── */

.connector-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.connector-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}

.connector-card-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--a-glow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.connector-card-info {
  flex: 1;
  min-width: 0;
}

.connector-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.connector-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.connector-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.connector-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

.connector-badge.connected {
  background: rgba(34,197,94,0.15);
  color: #22c55e;
  border: 1px solid rgba(34,197,94,0.3);
}

.connector-badge.disconnected {
  background: rgba(148,163,184,0.1);
  color: var(--text-muted);
  border: 1px solid rgba(148,163,184,0.15);
}

.connector-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}

.connector-btn.connect {
  background: var(--accent);
  color: #fff;
}

.connector-btn.connect:hover { opacity: 0.85; }

.connector-btn.disconnect {
  background: rgba(239,68,68,0.15);
  color: #ef4444;
  border: 1px solid rgba(239,68,68,0.25);
}

.connector-btn.disconnect:hover { background: rgba(239,68,68,0.25); }

.connector-btn.secondary {
  background: var(--glass-overlay);
  color: var(--text2);
  border: 1px solid var(--border);
}

.connector-btn.secondary:hover { background: var(--glass-hover); }

.connector-btn.save {
  background: #22c55e;
  color: #fff;
}

.connector-btn.save:hover { opacity: 0.85; }

/* ── V1Ron in Chrome expanded connector card ─────────────────────────────── */

.vic-expanded {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
}

.vic-expanded .connector-card-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.vic-expanded .connector-card-info { flex: 1; min-width: 0; }
.vic-expanded .connector-card-actions { flex-shrink: 0; }

.vic-key-section {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.vic-key-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.vic-key-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.vic-key-input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #a78bfa;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  padding: 8px 12px;
  outline: none;
  min-width: 0;
}

.vic-key-input::placeholder { color: var(--text-muted); opacity: 0.6; font-family: inherit; }

.vic-copy-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(167,139,250,0.12);
  color: #a78bfa;
  border: 1px solid rgba(167,139,250,0.25);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.vic-copy-btn:hover { background: rgba(167,139,250,0.22); }

.vic-action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.vic-action-row .connector-btn {
  flex: 1;
  min-width: 120px;
  text-align: center;
}

/* ── Collapsible install guide ────────────────────────────────────────────── */

.vic-guide {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.vic-guide-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
.vic-guide-toggle:hover { color: var(--text-secondary); }

.vic-guide-arrow {
  font-size: 10px;
  transition: transform 0.2s;
  display: inline-block;
}
.vic-guide-arrow.open { transform: rotate(90deg); }

.vic-guide-steps {
  display: none;
  margin-top: 12px;
}
.vic-guide-steps.open { display: flex; flex-direction: column; gap: 8px; }

/* ── Google Connector Modal ───────────────────────────────────────────────── */

.gc-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gc-modal {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: min(760px, 96vw);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

.gc-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--glass-overlay);
}

.gc-modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.gc-modal-close {
  opacity: 0.6;
}

.gc-import-body {
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gc-import-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gc-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.gc-step-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.gc-step kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--glass-overlay);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
}

.gc-step code {
  background: var(--glass-overlay);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: monospace;
}


.gc-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

/* ── Theme: Bright Mode ─────────────────────────────────────── */
body.bright-mode {
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #e8e0ff 0%, var(--bg,#f5f3ff) 65%);
  /* Override structural background variables for light theme */
  --input-bg:       rgba(255,255,255,0.9);
  --panel-bg:       rgba(255,255,255,0.97);
  --sidebar-bg:     rgba(255,255,255,0.98);
  --auth-card-bg:   rgba(255,255,255,0.95);
  --mob-bar-bg:     rgba(255,255,255,0.97);
  --glass-overlay:  rgba(0,0,0,0.05);
  --glass-hover:    rgba(0,0,0,0.10);
  --glass-text:     var(--text);
  --glass-text-dim: var(--text2);
  --overlay-bg:     rgba(0,0,0,0.40);
}
body.bright-mode .amb-1 { background: rgba(109,40,217,0.06); }
body.bright-mode .amb-2 { background: rgba(192,132,252,0.04); }

/* Auth screen light background */
body.bright-mode #auth-screen {
  background: radial-gradient(ellipse 80% 60% at 50% 30%, #e8e0ff 0%, #f5f3ff 65%);
}

/* Auth card light shadow */
body.bright-mode .auth-card {
  box-shadow: 0 8px 40px rgba(109,40,217,0.15), 0 2px 8px rgba(0,0,0,0.08);
}

/* Sidebar icon labels readable on light bg */
body.bright-mode .nav-label { color: var(--text2); }
body.bright-mode .nav-item.active .nav-label { color: var(--accent); }

/* Dropdown / picker text on light bg */
body.bright-mode select option { background: #ffffff; color: #1a1040; }

/* Memory map: replace dark sky with light background in bright mode */
body.bright-mode .cd-mem-map {
  background: radial-gradient(ellipse 60% 55% at 50% 50%, rgba(139,92,246,.10) 0%, rgba(168,139,250,.04) 70%), #f4f0ff;
}

/* ── Theme: Color Mode Buttons ──────────────────────────────── */
.theme-mode-btn { min-width: 96px; }
.theme-mode-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Theme: Color Picker Row ────────────────────────────────── */
.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.color-picker {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}
.color-hex {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════════════════
   SCHEDULE VIEW
   ═══════════════════════════════════════════════════════════════ */

/* ── Header ─────────────────────────────────────────────────── */
.sched-view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.sched-header-left { display: flex; flex-direction: column; gap: 2px; }
.sched-subtitle { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ── Workspace layout ────────────────────────────────────────── */
.sched-workspace {
  display: flex;
  gap: 0;
  align-items: flex-start;
  min-height: 0;
  flex: 1;
}
.sched-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
  transition: margin-right .28s ease;
}
.sched-workspace.panel-open .sched-main {
  margin-right: 360px;
}

/* ── Calendar card ───────────────────────────────────────────── */
.sched-cal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.sched-cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.sched-cal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sched-cal-label {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .02em;
  min-width: 150px;
  text-align: center;
}
/* View-mode pills (Month / Week / 3 Days / Range) */
.sched-cal-modes { display: flex; gap: 6px; flex-wrap: wrap; }
.sched-mode-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  transition: all .15s;
}
.sched-mode-btn:hover { border-color: var(--accent); color: var(--accent); }
.sched-mode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
/* Custom date-range inputs */
.sched-range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.sched-range-input {
  padding: 6px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.sched-range-input:focus { border-color: var(--border-active); }
.sched-range-sep { color: var(--text2); font-size: 14px; }
/* Day-column views (week / 3-day / range) */
.sched-days {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(130px, 1fr);
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.sched-day-col {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  min-height: 220px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s;
}
.sched-day-col:hover { border-color: var(--accent); }
.sched-day-col.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sched-day-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.sched-day-dow { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.sched-day-num { font-size: 16px; font-weight: 700; color: var(--text); }
.sched-day-mon { font-size: 11px; color: var(--text3); }
.sched-day-col.today .sched-day-num { color: var(--accent); }
.sched-day-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}
.sched-day-body .sched-cal-event { white-space: normal; }
.sched-day-empty { color: var(--text3); font-size: 12px; text-align: center; padding: 8px 0; }
.sched-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.sched-cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  padding: 4px 0 8px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.sched-cal-cell {
  min-height: 68px;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sched-cal-cell:hover { background: var(--surface2); border-color: var(--border); }
.sched-cal-cell.today { border-color: var(--accent) !important; background: rgba(139,92,246,.08); }
.sched-cal-cell.other-month .sched-cal-daynum { color: var(--text3); }
.sched-cal-cell.has-events { background: var(--surface2); }
.sched-cal-daynum { font-size: 12px; font-weight: 600; color: var(--text2); line-height: 1; }
.sched-cal-cell.today .sched-cal-daynum {
  color: var(--accent);
  background: rgba(139,92,246,.18);
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.sched-cal-event {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(139,92,246,.22);
  color: var(--accent2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.sched-cal-event:hover { background: rgba(139,92,246,.38); }
.sched-cal-event.status-paused  { background: rgba(245,158,11,.18); color: var(--warn); }
.sched-cal-event.status-stopped { background: rgba(239,68,68,.15);  color: var(--danger); }
.sched-cal-event.status-completed { background: rgba(16,185,129,.15); color: var(--success); }
.sched-cal-more { font-size: 10px; color: var(--text3); padding: 0 2px; }

/* ── Schedule list ───────────────────────────────────────────── */
.sched-list-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.sched-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.sched-list-title { font-weight: 700; font-size: 14px; }
.sched-list-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.sched-filter {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  transition: all .15s;
}
.sched-filter:hover { border-color: var(--accent); color: var(--accent); }
.sched-filter.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.sched-list { display: flex; flex-direction: column; }
.sched-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 20px;
  text-align: center;
}
.sched-empty-icon { font-size: 36px; opacity: .25; }
.sched-empty-title { font-weight: 700; font-size: 15px; color: var(--text2); }
.sched-empty-desc { font-size: 13px; color: var(--text3); }

.sched-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .13s;
}
.sched-row:last-child { border-bottom: none; }
.sched-row:hover { background: var(--surface2); }
.sched-row.active-row { background: rgba(139,92,246,.06); }
.sched-row-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(139,92,246,.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.sched-row-body { flex: 1; min-width: 0; }
.sched-row-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-row-meta { font-size: 12px; color: var(--text2); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.sched-row-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Status badge */
.sched-status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.sched-status-badge.status-active    { background: rgba(16,185,129,.18);  color: var(--success); }
.sched-status-badge.status-paused    { background: rgba(245,158,11,.18);  color: var(--warn); }
.sched-status-badge.status-stopped   { background: rgba(239,68,68,.15);   color: var(--danger); }
.sched-status-badge.status-completed { background: rgba(139,92,246,.18);  color: var(--accent2); }

/* ── Detail slide-out panel ──────────────────────────────────── */
.sched-detail-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  height: 100vh;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(100%);
  opacity: 0;
  transition: transform .28s ease, opacity .28s ease;
}
.sched-detail-panel.open {
  transform: translateX(0);
  opacity: 1;
}
.sched-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}
.sched-detail-title-row { display: flex; flex-direction: column; gap: 6px; }
.sched-detail-name { font-weight: 700; font-size: 16px; }
.sched-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sched-detail-section { display: flex; flex-direction: column; gap: 8px; }
.sched-detail-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text2);
}
.sched-detail-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(139,92,246,.1);
}
.sched-detail-info-row:last-child { border-bottom: none; }
.sched-detail-info-label { color: var(--text2); }
.sched-detail-info-val { font-weight: 600; }

.sched-step-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.sched-step-num { font-size: 10px; color: var(--text3); font-weight: 700; margin-bottom: 4px; }
.sched-step-prompt { color: var(--text); line-height: 1.4; }
.sched-step-skills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.sched-step-skill-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(139,92,246,.15);
  color: var(--accent2);
}

.sched-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}
.sched-act-stop   { color: var(--warn) !important; border-color: rgba(245,158,11,.3) !important; }
.sched-act-delete { color: var(--danger) !important; border-color: rgba(239,68,68,.3) !important; }

/* ── Artifacts section ───────────────────────────────────────── */
.sched-artifacts-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.sched-artifacts-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.sched-artifacts-title { font-weight: 700; font-size: 14px; }
.sched-artifacts-name { font-size: 12px; color: var(--accent2); font-weight: 600; }
.sched-artifacts-list { display: flex; flex-direction: column; }
.sched-artifact-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.sched-artifact-row:last-child { border-bottom: none; }
.sched-artifact-icon { font-size: 18px; flex-shrink: 0; }
.sched-artifact-body { flex: 1; min-width: 0; }
.sched-artifact-label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-artifact-meta { font-size: 11px; color: var(--text2); margin-top: 3px; }
.sched-artifact-preview {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text2);
  background: var(--surface2);
  border-radius: 6px;
  padding: 8px 10px;
  max-height: 80px;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.sched-artifact-err { color: var(--danger) !important; }
.sched-artifact-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.sched-artifact-lib-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; cursor: pointer;
  background: color-mix(in srgb, var(--abtn-color, var(--accent2)) 15%, transparent);
  color: var(--abtn-color, var(--accent2));
  border: 1px solid color-mix(in srgb, var(--abtn-color, var(--accent2)) 30%, transparent);
  text-decoration: none;
  transition: background 0.15s;
}
.sched-artifact-lib-btn:hover {
  background: color-mix(in srgb, var(--abtn-color, var(--accent2)) 25%, transparent);
}

/* ── Creation / Edit Modal ───────────────────────────────────── */
.sched-modal { max-width: 600px; width: 100%; }
.sched-modal-body { padding: 0; display: flex; flex-direction: column; gap: 0; }
.sched-form-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sched-form-section:last-of-type { border-bottom: none; }
.sched-form-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sched-timing-row { display: flex; gap: 12px; }
.sched-char-select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  outline: none;
  appearance: none;
  cursor: pointer;
}
.sched-char-select:focus { border-color: var(--accent); }
.sched-repeat-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.sched-repeat-pill {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.sched-repeat-pill:hover { border-color: var(--accent); color: var(--accent); }
.sched-repeat-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.sched-custom-repeat {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text2);
}
.sched-interval-input {
  width: 70px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 7px 10px;
  outline: none;
}
.sched-interval-input:focus { border-color: var(--accent); }
.sched-unit-select {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 7px 10px;
  outline: none;
  cursor: pointer;
}
.sched-unit-select:focus { border-color: var(--accent); }

/* Steps */
.sched-steps-list { display: flex; flex-direction: column; gap: 12px; }
.sched-step-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.sched-step-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface3);
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
}
.sched-step-card-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.sched-step-textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  padding: 10px 12px;
  outline: none;
  line-height: 1.5;
}
.sched-step-textarea:focus { border-color: var(--accent); }
.sched-step-skill-row { display: flex; flex-direction: column; gap: 6px; }
.sched-step-skill-label { font-size: 11px; font-weight: 600; color: var(--text2); }
.sched-step-skill-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sched-skill-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .13s;
}
.sched-skill-chip:hover { border-color: var(--accent); color: var(--text); }
.sched-skill-chip.selected { background: rgba(139,92,246,.2); border-color: var(--accent); color: var(--accent2); }
.sched-skill-chip-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.sched-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

/* ── Running indicator ───────────────────────────────────────── */
.sched-running-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: sched-pulse 1.4s ease-in-out infinite;
  margin-right: 4px;
}
@keyframes sched-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.7); }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 700px) {
  .sched-workspace.panel-open .sched-main { margin-right: 0; }
  .sched-detail-panel {
    width: 100vw;
    height: 70vh;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(100%);
  }
  .sched-detail-panel.open { transform: translateY(0); }
  .sched-timing-row { flex-direction: column; }
  .sched-modal { max-width: 100%; }
}

/* ══════════════════════════════════════════════════════════════
   SERVER HEALTH PANEL
   ══════════════════════════════════════════════════════════════ */

/* Metrics grid — 4 columns, stacks down on small screens */
.srv-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 1100px) { .srv-metrics-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px)  { .srv-metrics-grid { grid-template-columns: 1fr; } }

/* Metric card — canvas gauge + text side-by-side */
.srv-metric-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px !important;
}
.srv-metric-card canvas { flex-shrink: 0; }
.srv-metric-body { flex: 1; min-width: 0; }
.srv-metric-body--full { width: 100%; }
.srv-metric-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text2);
  margin-bottom: 3px;
}
.srv-metric-sub { font-size: 12px; color: var(--text2); margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Stacked bar (RAM used / cached / free) */
.srv-stacked-bar {
  display: flex;
  height: 5px;
  border-radius: 3px;
  overflow: hidden;
  background: rgba(139,92,246,0.08);
  margin: 3px 0 4px;
}
.srv-bar-fill { height: 100%; transition: width .5s ease; min-width: 0; }

.srv-swap-row { font-size: 11px; color: var(--text2); }

/* System card key-value rows */
.srv-sys-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(139,92,246,0.07);
}
.srv-sys-row:last-child { border-bottom: none; }
.srv-sys-row > span:first-child { color: var(--text2); }
.srv-sys-row > span:last-child  { font-family: var(--font-mono); font-weight: 600; }

/* Section header */
.srv-section { padding: 16px !important; }
.srv-section-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Two-column layout for crons + actions */
.srv-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 700px) { .srv-two-col { grid-template-columns: 1fr; } }

/* Tables */
.srv-scroll-x { overflow-x: auto; }
.srv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.srv-table th, .srv-table td { padding: 7px 10px; text-align: left; border-bottom: 1px solid rgba(139,92,246,0.08); }
.srv-table th { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text2); background: rgba(139,92,246,0.04); }
.srv-table tr:last-child td { border-bottom: none; }
.srv-table tr:hover td { background: rgba(139,92,246,0.04); }

/* Quick actions */
.srv-action-btn { width: 100%; justify-content: flex-start !important; text-align: left; }
.srv-action-out {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  line-height: 1.5;
  background: rgba(139,92,246,0.08);
  color: var(--text);
  word-break: break-all;
}
.srv-action-out.hidden { display: none; }
.srv-action-out.srv-action-ok  { background: rgba(34,197,94,0.1);  color: #22c55e; }
.srv-action-out.srv-action-err { background: rgba(239,68,68,0.1);  color: #ef4444; }
.srv-action-out.srv-action-run { background: rgba(234,179,8,0.1);  color: #eab308; }

/* Log viewer */
.srv-log-pre {
  background: rgba(0,0,0,0.35);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text2);
  line-height: 1.65;
  overflow-y: auto;
  max-height: 360px;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 12px;
}
.srv-log-pre--drawer {
  max-height: calc(100vh - 54px);
  border-radius: 0;
  margin-top: 0;
  flex: 1;
}

/* Container log drawer */
.srv-log-drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 640px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 400;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.srv-log-drawer.hidden { display: none; }
.srv-log-drawer-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface2);
}

/* Loading placeholder */
.srv-loading { color: var(--text2); font-size: 13px; padding: 8px 0; }

/* Health badges (reuse existing .badge, add yellow) */
.badge-yellow { background: rgba(234,179,8,0.15); color: #eab308; }

/* Margin utility if not already defined */
.mb-3 { margin-bottom: 12px; }

/* ── Domain pills ── */
.char-domain-pills{display:flex;flex-wrap:wrap;gap:3px;margin-top:5px}
.domain-pill{display:inline-flex;align-items:center;font-size:9px;padding:2px 6px;border-radius:8px;border:1px solid;font-weight:700;letter-spacing:.4px;font-family:'SF Mono','Fira Code',monospace;text-transform:uppercase;white-space:nowrap}

/* ── Password show/hide toggle (auth forms) ── */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { flex: 1; padding-right: 42px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: .65;
  transition: opacity .15s ease, background .15s ease;
}
.pw-toggle:hover { opacity: 1; background: rgba(139,92,246,.15); }
.pw-toggle.on { opacity: 1; }

/* ── Admin users: search box ── */
.users-search-wrap { position: relative; margin-bottom: 14px; }
.users-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  font-size: 16px;
  pointer-events: none;
}
.users-search-input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s ease;
}
.users-search-input:focus { border-color: var(--border-active); }
.users-search-input::placeholder { color: var(--text3); }

/* ── Admin users: title badge ── */
.user-title-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(139,92,246,.16);
  color: var(--accent2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ── Schedule: ICS feed + subscribe card ── */
.sched-ics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.sched-ics-row { display: flex; flex-wrap: wrap; gap: 20px; }
.sched-ics-block { flex: 1; min-width: 240px; }
.sched-ics-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.sched-ics-controls { display: flex; gap: 8px; }
.sched-ics-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
}
.sched-ics-input:focus { border-color: var(--border-active); }
.sched-ics-input[readonly] { color: var(--text2); cursor: text; }
.sched-ics-hint { font-size: 11px; color: var(--text3); margin-top: 6px; }

/* External (subscribed) calendar events */
.sched-cal-event-ext {
  background: rgba(34,197,94,.16);
  color: var(--success);
  cursor: default;
  border: 1px dashed rgba(34,197,94,.4);
}
.sched-cal-event-ext:hover { background: rgba(34,197,94,.26); }
