:root {
  --bg: #07111d;
  --panel: #0c1828;
  --panel-2: #101f32;
  --line: #29405a;
  --line-strong: #3b5e82;
  --text: #f5f8fc;
  --muted: #9fb2c8;
  --primary: #2788ff;
  --primary-strong: #4ca0ff;
  --accent: #18c6a3;
  --danger: #ff6b6b;
  --warning: #ffcc66;
  --shadow: 0 18px 44px rgba(0,0,0,.22);
}
* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100%; background: radial-gradient(circle at 12% -10%, rgba(39,136,255,.15), transparent 34%), var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { color: inherit; }
.app-shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; padding: 22px 0 30px; }
.topbar { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:18px; }
.brand { display:flex; align-items:center; gap:12px; min-width:0; }
.brand-icon { width:46px; height:46px; border-radius:11px; }
.brand-copy { min-width:0; }
.brand h1 { margin:0; font-size:clamp(18px,3.4vw,25px); letter-spacing:-.02em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.brand h1 span { color: var(--primary-strong); }
.brand p { margin:4px 0 0; color:var(--muted); font-size:13px; }
.header-actions { display:flex; align-items:center; gap:9px; }
.local-badge, .rap-badge, .type-pill { display:inline-flex; align-items:center; justify-content:center; border:1px solid var(--line); background:#0a1727; color:#cbe1f7; border-radius:999px; padding:6px 10px; font-size:12px; font-weight:700; white-space:nowrap; }
.local-badge::before { content:""; width:7px; height:7px; margin-inline-end:6px; border-radius:50%; background:var(--accent); }
.select, input[type="search"], input[type="number"] { border:1px solid var(--line-strong); background:#081525; color:var(--text); border-radius:8px; min-height:42px; padding:0 11px; outline:none; }
.select:focus, input:focus, button:focus-visible, .drop-zone:focus-visible { border-color:var(--primary); box-shadow:0 0 0 3px rgba(39,136,255,.19); outline:none; }
.select.compact { min-height:38px; }
.drop-zone { display:grid; grid-template-columns:auto minmax(0,1fr) auto; align-items:center; gap:16px; border:1px dashed #47719b; background:linear-gradient(135deg,rgba(39,136,255,.09),rgba(24,198,163,.035)); padding:18px; border-radius:14px; transition:.15s ease; }
.drop-zone.dragover { border-style:solid; border-color:var(--primary-strong); background:rgba(39,136,255,.16); transform:translateY(-1px); }
.drop-mark { width:58px; height:58px; border-radius:14px; display:grid; place-items:center; background:#102b49; border:1px solid #28527c; color:#8bc2ff; font-size:11px; font-weight:900; letter-spacing:.08em; }
.drop-copy { display:flex; flex-direction:column; gap:4px; min-width:0; }
.drop-copy strong { font-size:16px; }
.drop-copy span { color:var(--muted); font-size:13px; }
.drop-actions { display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.btn { border:1px solid var(--line-strong); background:#13243a; color:#eef6ff; border-radius:8px; min-height:42px; padding:0 14px; cursor:pointer; font-weight:750; transition:.12s ease; }
.btn:hover:not(:disabled) { background:#18304d; border-color:#567ca3; }
.btn.primary { background:#1e73d8; border-color:#368ae7; }
.btn.primary:hover:not(:disabled) { background:#2788ff; }
.btn.accent { background:#107e6d; border-color:#1ca58e; }
.btn.accent:hover:not(:disabled) { background:#13937e; }
.btn:disabled { opacity:.42; cursor:not-allowed; }
.workspace { display:grid; grid-template-columns:minmax(280px,390px) minmax(0,1fr); gap:14px; margin-top:14px; align-items:stretch; }
.panel { background:rgba(12,24,40,.96); border:1px solid var(--line); border-radius:14px; box-shadow:var(--shadow); }
.preview-panel, .library-panel { padding:15px; min-width:0; }
.panel-heading, .library-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.eyebrow { display:block; color:#7ba3cb; text-transform:uppercase; letter-spacing:.1em; font-size:10px; font-weight:850; margin-bottom:4px; }
.panel h2 { margin:0; font-size:16px; line-height:1.25; overflow-wrap:anywhere; }
.preview-stage { position:relative; display:grid; place-items:center; aspect-ratio:1/1; max-height:390px; margin-top:13px; border-radius:12px; overflow:hidden; border:1px solid #203a56; background:repeating-conic-gradient(#07111d 0 25%,#0a1625 0 50%) 50%/20px 20px; }
.preview-stage img { display:block; width:100%; height:100%; object-fit:contain; image-rendering:auto; }
.preview-empty { display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; gap:7px; padding:20px; color:var(--muted); }
.preview-empty strong { color:#dceafa; }
.empty-orb { width:82px; height:82px; display:grid; place-items:center; border-radius:50%; border:1px solid #305577; background:#0d2034; color:#6fa9e4; font-weight:900; font-size:20px; margin-bottom:4px; }
.details { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:12px 0 0; }
.details div { min-width:0; border:1px solid #1f354c; background:#091624; padding:9px 10px; border-radius:9px; }
.details dt { color:#7895b4; font-size:10px; font-weight:800; text-transform:uppercase; letter-spacing:.06em; }
.details dd { margin:3px 0 0; font-size:12px; font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.main-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:12px; }
.main-actions .grow { width:100%; }
.library-panel { display:flex; flex-direction:column; min-height:520px; }
.library-head { align-items:center; }
.filter-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.check { display:flex; align-items:center; gap:7px; min-height:42px; border:1px solid var(--line); background:#091624; border-radius:8px; padding:0 10px; color:#d3e0ef; font-size:12px; font-weight:700; white-space:nowrap; }
.check input { accent-color:var(--primary); }
.search-wrap { display:flex; gap:8px; margin:12px 0 9px; }
.search-wrap input { width:100%; min-width:0; }
.rap-badge { min-width:70px; }
.avatar-list { display:flex; flex-direction:column; gap:5px; overflow:auto; min-height:0; max-height:550px; padding-right:2px; }
.avatar-row { display:grid; grid-template-columns:minmax(0,1fr) auto auto; gap:9px; align-items:center; width:100%; text-align:start; border:1px solid #1e344b; background:#091624; border-radius:9px; padding:9px 10px; cursor:pointer; color:var(--text); }
.avatar-row:hover { border-color:#3a638a; background:#0d1c2d; }
.avatar-row.selected { border-color:var(--primary); background:#102d4c; box-shadow:inset 3px 0 0 var(--primary); }
.avatar-name { min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; font-weight:760; font-size:12px; }
.avatar-source { color:#7f9dbb; font-size:10px; margin-top:2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.avatar-type { color:#b6d5f4; font-size:10px; font-weight:850; border:1px solid #31516f; border-radius:999px; padding:4px 7px; white-space:nowrap; }
.avatar-size { color:#93aac1; font-size:11px; font-variant-numeric:tabular-nums; white-space:nowrap; }
.list-empty { margin:auto; display:flex; flex-direction:column; gap:5px; text-align:center; color:var(--muted); padding:30px 16px; }
.list-empty strong { color:#d8e7f5; }
.advanced { margin-top:14px; overflow:hidden; }
.advanced summary { cursor:pointer; padding:13px 15px; font-weight:800; color:#dceafa; }
.advanced summary::marker { color:var(--primary); }
.advanced-grid { display:grid; grid-template-columns:minmax(220px,320px) 1fr; gap:12px; border-top:1px solid var(--line); padding:13px 15px 15px; }
.advanced-grid label { display:flex; flex-direction:column; gap:6px; color:var(--muted); font-size:12px; font-weight:700; }
.advanced-note { display:flex; flex-direction:column; gap:4px; justify-content:center; color:var(--muted); font-size:12px; }
.advanced-note strong { color:#dceafa; }
.statusbar { display:flex; align-items:center; gap:8px; color:#8fa8c1; font-size:12px; padding:12px 4px 0; }
.status-dot { width:8px; height:8px; border-radius:50%; background:var(--accent); box-shadow:0 0 0 4px rgba(24,198,163,.08); }
.status-dot.busy { background:var(--warning); box-shadow:0 0 0 4px rgba(255,204,102,.08); }
.status-dot.error { background:var(--danger); box-shadow:0 0 0 4px rgba(255,107,107,.08); }
.status-progress { width:120px; max-width:22vw; height:5px; overflow:hidden; border-radius:999px; background:rgba(143,168,193,.16); }
.status-progress > span { display:block; width:0; height:100%; border-radius:inherit; background:currentColor; transition:width .14s ease; }
@media (max-width:640px){ .status-progress { width:84px; max-width:20vw; } }

.spacer { flex:1; }
.toast-stack { position:fixed; right:16px; bottom:16px; z-index:50; display:flex; flex-direction:column; gap:8px; width:min(360px,calc(100% - 32px)); pointer-events:none; }
.toast { border:1px solid #365675; background:#0d1c2d; color:#f4f8fc; border-radius:10px; padding:11px 13px; box-shadow:0 16px 40px rgba(0,0,0,.35); font-size:13px; animation:toastIn .18s ease; }
.toast.error { border-color:#8b464a; }
@keyframes toastIn { from { opacity:0; transform:translateY(6px); } }
.context-menu { position:fixed; z-index:80; min-width:180px; border:1px solid #3c5876; background:#0b1929; border-radius:10px; box-shadow:0 18px 50px rgba(0,0,0,.45); padding:5px; }
.context-menu button { display:block; width:100%; border:0; background:transparent; color:#eef6ff; padding:9px 10px; border-radius:7px; text-align:start; cursor:pointer; }
.context-menu button:hover { background:#16304c; }
[dir="rtl"] .avatar-row.selected { box-shadow:inset -3px 0 0 var(--primary); }
[dir="rtl"] .avatar-list { padding-right:0; padding-left:2px; }

@media (max-width: 820px) {
  .app-shell { width:min(100% - 18px, 680px); padding-top:12px; }
  .topbar { align-items:flex-start; }
  .local-badge { display:none; }
  .drop-zone { grid-template-columns:auto 1fr; }
  .drop-actions { grid-column:1/-1; justify-content:stretch; }
  .drop-actions .btn { flex:1; }
  .workspace { grid-template-columns:1fr; }
  .preview-stage { max-height:none; }
  .library-panel { min-height:430px; }
  .avatar-list { max-height:470px; }
}
@media (max-width: 520px) {
  .brand-icon { width:40px; height:40px; }
  .brand p { display:none; }
  .header-actions { gap:4px; }
  .select.compact { width:100px; }
  .drop-zone { grid-template-columns:1fr; text-align:center; justify-items:center; padding:15px 12px; }
  .drop-actions { width:100%; }
  .drop-actions .btn { min-width:0; padding:0 10px; }
  .panel-heading, .library-head { align-items:flex-start; }
  .filter-row { width:100%; justify-content:flex-start; }
  .library-head { flex-direction:column; }
  .filter-row .select { flex:1; min-width:130px; }
  .main-actions { grid-template-columns:1fr 1fr; }
  .details { grid-template-columns:1fr 1fr; }
  .avatar-row { grid-template-columns:minmax(0,1fr) auto; }
  .avatar-size { display:none; }
  .advanced-grid { grid-template-columns:1fr; }
  #memoryNote { display:none; }
}
@media (max-width: 360px) {
  .app-shell { width:calc(100% - 12px); }
  .brand h1 { font-size:16px; }
  .brand h1 span { display:none; }
  .details { grid-template-columns:1fr; }
  .main-actions { grid-template-columns:1fr; }
  .drop-actions { flex-direction:column; }
}
