/* ============================================================
   Devil AI (DAI) v0.0.1 — Web GUI styles
   Native CSS, no frameworks, dark "devil" theme.
   ============================================================ */

:root {
  --bg: #08080d;
  --bg-soft: #0c0c14;
  --bg-elev: #12121c;
  --panel: #161622;
  --panel-2: #1c1c2b;
  --panel-3: #232335;
  --border: #2b2b3f;
  --border-soft: #222233;
  --text: #ececf5;
  --text-soft: #c4c4d6;
  --muted: #8b8ba6;
  --accent: #e11d3f;
  --accent-bright: #ff3b5c;
  --accent-deep: #8f1027;
  --purple: #8b5cff;
  --purple-deep: #5b2fd6;
  --gold: #f5b942;
  --green: #34d399;
  --danger: #ff4d5e;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --shadow-soft: 0 8px 26px rgba(0, 0, 0, .3);
  --grad-accent: linear-gradient(135deg, #ff3b5c 0%, #b11434 55%, #6d0c22 100%);
  --grad-purple: linear-gradient(135deg, #a77bff 0%, #7a4dff 50%, #4b23b8 100%);
  --grad-panel: linear-gradient(160deg, rgba(255, 59, 92, .07), rgba(139, 92, 255, .05));
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(225, 29, 63, .16), transparent 58%),
    radial-gradient(1000px 600px at 95% 0%, rgba(139, 92, 255, .14), transparent 55%),
    radial-gradient(900px 800px at 50% 120%, rgba(80, 20, 120, .12), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg { display: block; max-width: 100%; }

/* Иконки: единый базовый размер, иначе SVG без width/height растягивается. */
.ico {
  width: 18px;
  height: 18px;
  flex: none;
  max-width: none;
  pointer-events: none;
}
.btn .ico { width: 16px; height: 16px; }
.btn-sm .ico { width: 15px; height: 15px; }
.btn-lg .ico { width: 18px; height: 18px; }
.btn-icon .ico { width: 18px; height: 18px; }
.icon-btn .ico { width: 18px; height: 18px; }
.send-btn .ico { width: 18px; height: 18px; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(225, 29, 63, .45); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #2c2c40;
  border-radius: 20px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: #3b3b55; }

/* ---------------------------------------------------------- layout */

.app-root { min-height: 100%; }
.noscript {
  margin: 40px auto;
  max-width: 520px;
  padding: 20px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
}

.shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px 18px;
  border-right: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(18, 18, 28, .88), rgba(10, 10, 16, .92));
  backdrop-filter: blur(10px);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
  filter: drop-shadow(0 4px 16px rgba(225, 29, 63, .5));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .6px;
  background: linear-gradient(120deg, #fff, #ffb3c0 55%, #a77bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 1.6px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-label {
  padding: 12px 12px 6px;
  font-size: 10.5px;
  letter-spacing: 1.7px;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
  font-size: 14.5px;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, .045); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(225, 29, 63, .2), rgba(139, 92, 255, .1));
  border-color: rgba(225, 29, 63, .34);
  color: #fff;
  box-shadow: inset 0 0 24px rgba(225, 29, 63, .08);
}
.nav-item .ico { width: 19px; height: 19px; flex: none; opacity: .92; }
.nav-item .nav-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 30px;
  background: rgba(255, 255, 255, .08);
  color: var(--text-soft);
}
.nav-item.active .nav-badge { background: rgba(225, 29, 63, .35); color: #fff; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: rgba(255, 255, 255, .025);
}
.avatar {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  background: var(--grad-accent);
  box-shadow: 0 4px 14px rgba(225, 29, 63, .35);
  text-transform: uppercase;
}
.user-meta { min-width: 0; line-height: 1.25; }
.user-mail {
  font-size: 12.5px;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 138px;
}
.user-role { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.side-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--muted);
  border-radius: 9px;
  background: rgba(0, 0, 0, .22);
  border: 1px solid var(--border-soft);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--green); box-shadow: 0 0 10px rgba(52, 211, 153, .8); }
.dot.bad { background: var(--danger); box-shadow: 0 0 10px rgba(255, 77, 94, .8); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 26px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(10, 10, 16, .72);
  backdrop-filter: blur(12px);
}
.topbar-title { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.topbar-title small { display: block; font-weight: 400; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.topbar-spacer { flex: 1; }

.chip-balance {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(245, 185, 66, .35);
  background: rgba(245, 185, 66, .08);
  color: #ffd77e;
  white-space: nowrap;
}
.chip-balance .coin { width: 15px; height: 15px; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, .03);
  color: var(--text-soft);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; border-color: var(--border); }

.menu-toggle { display: none; }

.view {
  width: 100%;
  max-width: 1340px;
  margin: 0 auto;
  padding: 26px;
  flex: 1;
}

.page-head { margin-bottom: 20px; }
.page-title { margin: 0 0 6px; font-size: 26px; letter-spacing: -.4px; }
.page-sub { margin: 0; color: var(--muted); font-size: 14px; max-width: 760px; line-height: 1.55; }

/* ---------------------------------------------------------- auth */

.auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
}
.auth-hero {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 26px;
  padding: 60px clamp(28px, 5vw, 88px);
  border-right: 1px solid var(--border-soft);
}
.auth-hero::before {
  content: "";
  position: absolute;
  inset: -20% -30% auto auto;
  width: 680px;
  height: 680px;
  background: radial-gradient(circle, rgba(225, 29, 63, .28), transparent 62%);
  filter: blur(10px);
  pointer-events: none;
}
.auth-hero::after {
  content: "";
  position: absolute;
  inset: auto auto -25% -20%;
  width: 560px;
  height: 560px;
  background: radial-gradient(circle, rgba(139, 92, 255, .22), transparent 65%);
  pointer-events: none;
}
.auth-hero .brand { position: relative; border: 0; padding: 0; }
.auth-hero .brand-name { font-size: 26px; }
.auth-hero h1 {
  position: relative;
  margin: 0;
  font-size: clamp(36px, 4.4vw, 58px);
  line-height: 1.03;
  letter-spacing: -1.6px;
  max-width: 640px;
}
.auth-hero h1 .grad {
  background: var(--grad-accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-hero p.lead {
  position: relative;
  margin: 0;
  max-width: 540px;
  color: var(--text-soft);
  font-size: 16px;
  line-height: 1.65;
}
.auth-features { position: relative; display: grid; gap: 10px; max-width: 520px; }
.auth-feature {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: rgba(255, 255, 255, .022);
  color: var(--text-soft);
  font-size: 13.5px;
  line-height: 1.45;
}
.auth-feature b { color: var(--text); }
.auth-feature .ico { width: 20px; height: 20px; flex: none; color: var(--accent-bright); }

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px clamp(20px, 4vw, 64px);
}
.auth-card {
  width: 100%;
  max-width: 430px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(28, 28, 43, .92), rgba(16, 16, 26, .96));
  box-shadow: var(--shadow);
}
.auth-card h2 { margin: 0 0 4px; font-size: 22px; }
.auth-card .hint { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  border-radius: 11px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--border-soft);
}
.auth-tab {
  padding: 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  transition: background .15s, color .15s;
}
.auth-tab.active { background: rgba(255, 255, 255, .09); color: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .3); }

.auth-foot { margin-top: 18px; font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.5; }

/* ---------------------------------------------------------- generic */

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(26, 26, 40, .85), rgba(17, 17, 27, .9));
  box-shadow: var(--shadow-soft);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .hint { font-size: 12px; color: var(--muted); margin-left: auto; }
.card-body { padding: 20px; }

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--text-soft);
}
.section-title .ico { width: 17px; height: 17px; color: var(--accent-bright); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 30px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .05);
  color: var(--text-soft);
  white-space: nowrap;
}
.badge.red { border-color: rgba(255, 77, 94, .4); background: rgba(255, 77, 94, .1); color: #ff97a1; }
.badge.purple { border-color: rgba(139, 92, 255, .4); background: rgba(139, 92, 255, .11); color: #c2a8ff; }
.badge.green { border-color: rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .1); color: #86efc9; }
.badge.gold { border-color: rgba(245, 185, 66, .38); background: rgba(245, 185, 66, .1); color: #ffd77e; }
.badge.blue { border-color: rgba(96, 165, 250, .4); background: rgba(96, 165, 250, .1); color: #93c5fd; }
.badge.nsfw { border-color: rgba(255, 59, 92, .5); background: rgba(255, 59, 92, .14); color: #ff8fa2; }
.badge.ghost { background: transparent; }

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px;
}
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 800; letter-spacing: -.6px; }
.stat .value.accent { color: var(--accent-bright); }
.stat .value.green { color: var(--green); }
.stat .value.purple { color: #b79bff; }

/* ---------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 18px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  text-decoration: none;
}
.btn:hover { background: rgba(255, 255, 255, .08); border-color: #3a3a54; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary {
  border-color: transparent;
  background: var(--grad-accent);
  color: #fff;
  box-shadow: 0 8px 24px rgba(225, 29, 63, .3);
}
.btn-primary:hover { background: linear-gradient(135deg, #ff4d6b, #c0183c 60%, #7d0e26); box-shadow: 0 10px 30px rgba(225, 29, 63, .42); }

.btn-purple {
  border-color: transparent;
  background: var(--grad-purple);
  color: #fff;
  box-shadow: 0 8px 24px rgba(122, 77, 255, .28);
}
.btn-purple:hover { filter: brightness(1.08); }

.btn-ghost { background: transparent; border-color: var(--border-soft); color: var(--text-soft); }
.btn-ghost:hover { color: #fff; background: rgba(255, 255, 255, .05); }

.btn-danger { border-color: rgba(255, 77, 94, .35); background: rgba(255, 77, 94, .1); color: #ff8f9c; }
.btn-danger:hover { background: rgba(255, 77, 94, .18); }

.btn-sm { min-height: 32px; padding: 6px 12px; font-size: 12.5px; border-radius: 9px; }
.btn-lg { min-height: 46px; padding: 12px 24px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; min-height: 34px; }

.btn .spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ---------------------------------------------------------- forms */

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field > label, .label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: .2px;
}
.field .help { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.field .error-text { font-size: 11.5px; color: var(--danger); }

.input, .textarea, .select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, .28);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input::placeholder, .textarea::placeholder { color: #6c6c85; }
.input:focus, .textarea:focus, .select:focus {
  border-color: rgba(225, 29, 63, .6);
  box-shadow: 0 0 0 3px rgba(225, 29, 63, .14);
  background: rgba(0, 0, 0, .38);
}
.textarea { resize: vertical; min-height: 110px; line-height: 1.55; }
.textarea.tall { min-height: 170px; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.select option { background: #161622; color: var(--text); }

.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row .input { flex: 1; min-width: 0; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
}
.check input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  flex: none;
  border: 1px solid #3a3a54;
  border-radius: 5px;
  background: rgba(0, 0, 0, .3);
  display: grid;
  place-items: center;
  transition: background .15s, border-color .15s;
  margin: 0;
}
.check input[type="checkbox"]:checked {
  background: var(--grad-accent);
  border-color: transparent;
}
.check input[type="checkbox"]:checked::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}
.check input[type="checkbox"]:focus-visible { box-shadow: 0 0 0 3px rgba(225, 29, 63, .18); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--val, 40%), #2c2c40 var(--val, 40%));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: span 2; }

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: rgba(0, 0, 0, .24);
}
.seg button {
  padding: 7px 13px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.seg button.active { background: rgba(255, 255, 255, .09); color: #fff; }

/* ---------------------------------------------------------- tag picker */

.tag-picker { position: relative; }

.tag-picker-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, .28);
  transition: border-color .15s, box-shadow .15s;
}
.tag-picker-box:focus-within {
  border-color: rgba(225, 29, 63, .6);
  box-shadow: 0 0 0 3px rgba(225, 29, 63, .12);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 5px 4px 9px;
  border-radius: 8px;
  font-size: 12.5px;
  background: rgba(139, 92, 255, .14);
  border: 1px solid rgba(139, 92, 255, .32);
  color: #cbb6ff;
  max-width: 100%;
}
.tag-chip .t-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.tag-chip.nsfw { background: rgba(255, 59, 92, .13); border-color: rgba(255, 59, 92, .34); color: #ff9fb0; }
.tag-chip .t-weight {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 4px;
  border-radius: 5px;
  background: rgba(0, 0, 0, .28);
  font-family: var(--mono);
  font-size: 10.5px;
  color: #e6d9ff;
}
.tag-chip .t-weight button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0 2px;
  line-height: 1;
  font-size: 12px;
  opacity: .7;
}
.tag-chip .t-weight button:hover { opacity: 1; }
.tag-chip .t-remove {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  opacity: .65;
  font-size: 14px;
  line-height: 1;
}
.tag-chip .t-remove:hover { opacity: 1; background: rgba(255, 255, 255, .12); }

.tag-picker-input {
  flex: 1;
  min-width: 140px;
  border: 0;
  background: transparent;
  padding: 5px 4px;
  font-size: 13.5px;
  outline: none;
  color: var(--text);
}
.tag-picker-input::placeholder { color: #6c6c85; }

.tag-tools { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.tag-tools .select { width: auto; min-width: 150px; padding: 6px 30px 6px 10px; font-size: 12px; }
.tag-hint { font-size: 11.5px; color: var(--muted); margin-left: auto; }

.tag-suggest {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #16161f;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  padding: 6px;
}
.tag-suggest[hidden] { display: none; }
.tag-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
  font-size: 13px;
}
.tag-option:hover, .tag-option.active { background: rgba(255, 255, 255, .06); color: #fff; }
.tag-option .t-slug { font-family: var(--mono); font-size: 12px; color: var(--text); }
.tag-option .t-rname { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-option .t-meta { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
.tag-option .t-count { font-size: 10.5px; color: var(--muted); }
.tag-suggest-empty { padding: 14px 12px; color: var(--muted); font-size: 12.5px; text-align: center; }

.tag-popular { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag-popular button {
  padding: 4px 10px;
  border-radius: 30px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, .03);
  color: var(--muted);
  font-size: 11.5px;
  transition: background .15s, color .15s, border-color .15s;
}
.tag-popular button:hover { background: rgba(255, 255, 255, .08); color: #fff; border-color: var(--border); }
.tag-popular button.selected { border-color: rgba(139, 92, 255, .5); background: rgba(139, 92, 255, .14); color: #cbb6ff; }

/* ---------------------------------------------------------- image view */

.gen-layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; align-items: start; }
.gen-preview { position: sticky; top: 88px; }
.preview-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 380px;
  padding: 16px;
  border: 1px dashed #32324a;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 30% 20%, rgba(225, 29, 63, .08), transparent 50%),
    radial-gradient(circle at 80% 90%, rgba(139, 92, 255, .08), transparent 55%),
    rgba(0, 0, 0, .22);
  overflow: hidden;
}
.preview-frame img { border-radius: 10px; max-height: 560px; width: auto; }
.preview-empty { text-align: center; color: var(--muted); padding: 24px; }
.preview-empty .ico { width: 54px; height: 54px; margin: 0 auto 14px; color: #3b3b55; }
.preview-empty p { margin: 0; font-size: 13px; line-height: 1.5; max-width: 260px; }
.preview-meta { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.preview-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.progress { height: 7px; border-radius: 20px; background: #232335; overflow: hidden; }
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--grad-accent);
  transition: width .4s ease;
  box-shadow: 0 0 12px rgba(225, 29, 63, .6);
}
.progress.indeterminate > span { width: 35% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

.recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.recent-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  background: #101018;
  cursor: pointer;
  padding: 0;
}
.recent-thumb img { width: 100%; height: 100%; object-fit: cover; }
.recent-thumb:hover { border-color: var(--accent); }

/* ---------------------------------------------------------- chat */

.chat-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  height: calc(100vh - 150px);
  min-height: 520px;
}
.conv-panel { display: flex; flex-direction: column; overflow: hidden; }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 4px;
  width: 100%;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: 12.5px;
}
.conv-item:hover { background: rgba(255, 255, 255, .04); }
.conv-item.active { background: rgba(225, 29, 63, .1); border-color: rgba(225, 29, 63, .28); color: #fff; }
.conv-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px 10px 12px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: 12.5px;
}
.conv-open .c-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-open .c-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 0; font-size: 10.5px; color: var(--muted); }
.conv-rename {
  flex: none;
  width: 32px;
  margin: 6px 6px 6px 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s, border-color .15s;
}
.conv-item:hover .conv-rename, .conv-item.active .conv-rename, .conv-rename:focus-visible { opacity: 1; }
.conv-rename:hover { background: rgba(255, 255, 255, .08); color: #fff; border-color: var(--border-soft); }
.conv-rename .ico { width: 15px; height: 15px; }
.conv-rename-form { display: flex; align-items: center; gap: 5px; width: 100%; padding: 7px; }
.conv-rename-form .input { flex: 1; min-width: 0; height: 34px; padding: 6px 9px; font-size: 12.5px; }
.conv-rename-form .btn { flex: none; min-height: 32px; padding: 6px 8px; }
.conv-empty { padding: 20px 14px; text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

.chat-panel { display: flex; flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
.chat-head > div { min-width: 0; }
.chat-head .c-title { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .c-sub { font-size: 11px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .spacer { flex: 1; }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.msg { display: flex; gap: 10px; max-width: 88%; }
.msg .msg-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, .07);
  color: var(--text-soft);
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .msg-avatar { background: var(--grad-accent); color: #fff; }
.msg.assistant .msg-avatar { background: var(--grad-purple); color: #fff; }
.msg-bubble {
  padding: 11px 14px;
  border-radius: 13px;
  background: rgba(255, 255, 255, .045);
  border: 1px solid var(--border-soft);
  font-size: 13.8px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg.user .msg-bubble { background: rgba(225, 29, 63, .14); border-color: rgba(225, 29, 63, .28); }
.msg .msg-tags { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 4px; }
.msg .msg-tags .tag-chip { font-size: 10.5px; padding: 2px 6px; }

.msg-bubble .cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent-bright);
  animation: blink 1s steps(2) infinite;
  border-radius: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-compose { border-top: 1px solid var(--border-soft); padding: 14px 16px; background: rgba(0, 0, 0, .18); }
.chat-compose .compose-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-compose .compose-row .textarea { flex: 1; min-width: 0; min-height: 52px; max-height: 180px; }
.chat-compose .send-btn { flex: none; height: 44px; width: 46px; padding: 0; }
.chat-compose-foot { margin-top: 9px; gap: 12px; }
.chat-compose-foot .tag-trigger-slot { margin-left: auto; }

.chat-empty {
  margin: auto;
  max-width: 420px;
  text-align: center;
  color: var(--muted);
  padding: 30px;
}
.chat-empty .ico { width: 48px; height: 48px; margin: 0 auto 14px; color: #3b3b55; }
.chat-empty h3 { color: var(--text-soft); margin: 0 0 6px; }
.chat-empty p { margin: 0; font-size: 13px; line-height: 1.55; }

/* ---------------------------------------------------------- gallery */

.gallery-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.gallery-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.gallery-card:hover { transform: translateY(-3px); border-color: rgba(225, 29, 63, .35); box-shadow: 0 18px 40px rgba(0, 0, 0, .42); }
.gallery-card .g-img {
  position: relative;
  aspect-ratio: 1;
  background: #0e0e16;
  overflow: hidden;
  cursor: zoom-in;
}
.gallery-card .g-img img { width: 100%; height: 100%; object-fit: cover; }
.gallery-card .g-badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 5px; flex-wrap: wrap; }
.gallery-card .g-body { padding: 12px 13px 14px; }
.gallery-card .g-prompt {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 36px;
}
.gallery-card .g-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.gallery-card .g-actions { display: flex; gap: 6px; margin-top: 10px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 22px; }
.pager .page-info { font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.tbl th { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: rgba(255, 255, 255, .022); }
.td-right { text-align: right !important; }
.td-nowrap { white-space: nowrap; }
.amount-plus { color: var(--green); font-weight: 600; }
.amount-minus { color: #ff8f9c; font-weight: 600; }

/* ---------------------------------------------------------- profile */

.balance-hero {
  position: relative;
  overflow: hidden;
  padding: 24px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(225, 29, 63, .18), rgba(139, 92, 255, .1)), var(--panel);
  border: 1px solid rgba(225, 29, 63, .25);
}
.balance-hero::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -60px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(225, 29, 63, .3), transparent 65%);
}
.balance-hero .label { font-size: 11.5px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.balance-hero .amount { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; }
.balance-hero .amount b { font-size: 40px; letter-spacing: -1.5px; }
.balance-hero .amount span { color: var(--muted); font-size: 13px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; }

/* ---------------------------------------------------------- admin */

.admin-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  margin-bottom: 18px;
  padding: 4px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: rgba(0, 0, 0, .22);
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.admin-tab {
  flex: 0 0 auto;
  padding: 8px 15px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.admin-tab.active { background: rgba(255, 255, 255, .09); color: #fff; }

.help { font-size: 11.5px; color: var(--muted); line-height: 1.45; }

.admin-filters {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.admin-filters .select,
.admin-filters .input {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  height: 36px;
  padding: 7px 30px 7px 10px;
  font-size: 12.5px;
  border-radius: 9px;
}
.admin-filters .select { max-width: 190px; }
.admin-filters .input { flex: 1 1 220px; min-width: 170px; padding-right: 12px; }
.admin-filters .btn { flex: 0 0 auto; white-space: nowrap; }

.user-detail { display: flex; flex-direction: column; gap: 18px; }
.user-detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border-soft); }
.user-detail-title { font-size: 17px; font-weight: 700; }
.user-detail-balance { margin-left: auto; text-align: right; display: flex; flex-direction: column; gap: 2px; }
.user-detail-balance b { font-size: 20px; color: #ffd77e; }

.user-stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.user-stat { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border-soft); background: rgba(0, 0, 0, .18); font-size: 12px; color: var(--muted); }
.user-stat b { font-size: 18px; color: var(--text); }

.admin-section { padding: 16px; border: 1px solid var(--border-soft); border-radius: 14px; background: rgba(0, 0, 0, .14); }
.admin-section h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-soft); }
.admin-inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.admin-inline-form .select, .admin-inline-form .input { width: auto; flex: 1 1 160px; min-width: 0; }
.admin-section.danger-zone { border-color: rgba(255, 77, 94, .35); background: rgba(255, 77, 94, .05); }

.access-models { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.access-model { align-items: flex-start; }
.access-model.is-disabled { opacity: .55; }

.callout.danger { border-color: rgba(255, 77, 94, .35); background: rgba(255, 77, 94, .08); color: #ffb3ba; }

.health-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.health-row:last-child { border-bottom: 0; }
.health-row .h-name { min-width: 150px; color: var(--text-soft); }
.health-row .h-note { color: var(--muted); font-size: 12px; margin-left: auto; text-align: right; }

/* ---------------------------------------------------------- modal/toast */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 3, 8, .78);
  backdrop-filter: blur(6px);
  animation: fade .18s ease;
}
.modal {
  width: min(760px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #14141f;
  box-shadow: var(--shadow);
  animation: pop .2s ease;
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border-soft); }
.modal img { border-radius: 10px; margin: 0 auto; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } }

.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: #1a1a27;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
  animation: toast-in .22s ease;
}
.toast .toast-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--muted); }
.toast.success { border-color: rgba(52, 211, 153, .35); }
.toast.success .toast-dot { background: var(--green); box-shadow: 0 0 10px rgba(52, 211, 153, .7); }
.toast.error { border-color: rgba(255, 77, 94, .4); }
.toast.error .toast-dot { background: var(--danger); box-shadow: 0 0 10px rgba(255, 77, 94, .7); }
.toast.info .toast-dot { background: var(--purple); box-shadow: 0 0 10px rgba(139, 92, 255, .7); }
.toast .toast-close { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 2px; }
.toast .toast-close:hover { color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------------------------------------------------------- misc */

.skeleton {
  border-radius: 8px;
  background: linear-gradient(90deg, #1c1c2b 25%, #242437 50%, #1c1c2b 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state .ico { width: 46px; height: 46px; margin: 0 auto 12px; color: #3b3b55; }
.empty-state h3 { margin: 0 0 6px; color: var(--text-soft); font-size: 15px; }
.empty-state p { margin: 0; font-size: 12.5px; line-height: 1.5; }

.divider { height: 1px; background: var(--border-soft); margin: 16px 0; border: 0; }

.code-block {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .35);
  border: 1px solid var(--border-soft);
  color: var(--text-soft);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.callout {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(139, 92, 255, .3);
  background: rgba(139, 92, 255, .08);
  font-size: 12.5px;
  line-height: 1.5;
  color: #cfc0ff;
}
.callout.warn { border-color: rgba(245, 185, 66, .35); background: rgba(245, 185, 66, .08); color: #ffe2a8; }
.callout .ico { width: 17px; height: 17px; flex: none; margin-top: 1px; }

/* ---------------------------------------------------------- overflow safety */

.card,
.card-body,
.card-head,
.admin-section,
.modal,
.modal-body,
.gen-layout,
.chat-layout,
.grid,
.form-grid,
.field,
.stack,
.user-detail,
.admin-settings { min-width: 0; }

.card-head { flex-wrap: wrap; row-gap: 6px; }
.card-head h3,
.card-head .hint { min-width: 0; overflow-wrap: anywhere; }
.card-head .hint { margin-left: auto; text-align: right; }

.page-sub,
.help,
.kv .v,
.health-row .h-note,
.callout,
.callout > div,
.user-detail-title,
.user-stat b,
.stat .value,
.preview-empty p { overflow-wrap: anywhere; }

.kv { align-items: flex-start; }
.kv .k { flex: 0 0 auto; max-width: 46%; overflow-wrap: anywhere; }
.kv .v { min-width: 0; max-width: 54%; }

.table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl td { overflow-wrap: anywhere; }
table.tbl td.td-nowrap { overflow-wrap: normal; }

.health-row { flex-wrap: wrap; row-gap: 4px; }
.health-row .h-name { flex: 1 1 150px; min-width: 0; overflow-wrap: anywhere; }
.health-row .h-note { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }

.code-block { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }

.log-view {
  margin: 0;
  padding: 14px;
  max-height: 480px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, .4);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
}

.admin-settings { display: flex; flex-direction: column; gap: 18px; }
.admin-settings-save {
  position: sticky;
  bottom: 14px;
  z-index: 6;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(16, 16, 26, .94);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
}

/* ---------------------------------------------------------- field help tip */

.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 5px;
  border-radius: 50%;
  border: 1px solid rgba(225, 29, 63, .55);
  background: rgba(225, 29, 63, .16);
  color: #ff97a1;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  vertical-align: 1px;
  cursor: help;
  user-select: none;
}
.tip:hover,
.tip:focus-visible { background: rgba(225, 29, 63, .32); color: #fff; outline: none; }
.tip::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 90;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: max-content;
  max-width: min(300px, 70vw);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #1b1b28;
  color: var(--text-soft);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease, visibility .14s;
}
.tip:hover::after,
.tip:focus-visible::after { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.tip[data-tip-align="right"]::after { left: auto; right: 0; transform: translateY(4px); }
.tip[data-tip-align="right"]:hover::after,
.tip[data-tip-align="right"]:focus-visible::after { transform: translateY(0); }

/* ---------------------------------------------------------- contextual tag popover */

.tag-trigger-slot { display: inline-flex; margin-left: auto; }

.tag-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid rgba(139, 92, 255, .32);
  background: rgba(139, 92, 255, .1);
  color: #cbb6ff;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.tag-trigger:hover { background: rgba(139, 92, 255, .18); border-color: rgba(139, 92, 255, .5); color: #fff; }
.tag-trigger.active { border-color: rgba(225, 29, 63, .5); background: rgba(225, 29, 63, .14); color: #ffd7de; }
.tag-trigger .ico { width: 15px; height: 15px; }
.tag-trigger-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 20px;
  background: rgba(0, 0, 0, .35);
  font-family: var(--mono);
  font-size: 10.5px;
  text-align: center;
}

.tag-field-foot { justify-content: space-between; gap: 8px; margin-top: 2px; }

.tag-popover {
  position: fixed;
  z-index: 260;
  display: flex;
  flex-direction: column;
  max-height: min(600px, calc(100vh - 24px));
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #14141f;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7);
  overflow: hidden;
  animation: pop .16s ease;
}
.tag-popover.hidden { display: none; }
.tag-popover.dragging { cursor: grabbing; user-select: none; }
.tag-popover-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(139, 92, 255, .12), rgba(0, 0, 0, 0));
  cursor: grab;
  touch-action: none;
}
.tag-popover-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; font-weight: 700; color: var(--text); }
.tag-popover-title .ico { width: 15px; height: 15px; color: #b79bff; }
.tag-popover-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-popover-count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.tag-popover-close { width: 30px; height: 30px; flex: none; }
.tag-popover-body { display: flex; flex-direction: column; gap: 10px; min-height: 0; padding: 12px; overflow-y: auto; }
.tag-popover .tag-suggest { position: static; max-height: 230px; box-shadow: none; border-radius: 10px; }
.tag-popover .tag-tools { margin-top: 0; }
.tag-popover .tag-tools .select { max-width: 100%; }
.tag-popover .tag-popular { margin-top: 0; max-height: 120px; overflow-y: auto; }
.tag-popover-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-soft);
  background: rgba(0, 0, 0, .18);
}
.tag-popover-foot .help { margin-right: auto; font-size: 11px; }

/* ---------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  .gen-layout { grid-template-columns: 1fr; }
  .gen-preview { position: static; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-screen { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-panel { min-height: 100vh; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 30px 0 60px rgba(0, 0, 0, .5);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: grid; }
  .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(2px);
  }
  .view { padding: 18px; }
  .topbar { padding: 11px 16px; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .conv-panel { max-height: 220px; }
  .chat-panel { min-height: 520px; height: calc(100vh - 190px); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .user-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-tabs { width: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-tab { flex: none; }
  .chip-balance { padding: 6px 10px; font-size: 12px; }
  .topbar { gap: 10px; }
}

@media (max-width: 560px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .gallery-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .gallery-card .g-body { padding: 9px 10px 11px; }
  .gallery-card .g-prompt { font-size: 11.5px; }
  .balance-hero .amount b { font-size: 32px; }
  .msg { max-width: 96%; }
  .view { padding: 14px; }
  .page-title { font-size: 22px; }
  .topbar-title small { display: none; }
  .user-stat-grid { grid-template-columns: 1fr 1fr; }
  .user-detail-balance { margin-left: 0; text-align: left; }
  .admin-filters .select { max-width: 160px; }
  .admin-filters .input { flex-basis: 170px; min-width: 150px; }
  .admin-inline-form .select, .admin-inline-form .input { flex-basis: 100%; }
  .card-body { padding: 16px; }
  .modal-body { padding: 16px; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { max-height: 94vh; border-radius: 18px 18px 0 0; }
  .toast-root { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .access-models { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}
