/* R13 production repair: interaction safety, readable light mode, editable cards, public chat. */
:root{--afx-r13-line:rgba(255,255,255,.10);--afx-r13-card:#121217;--afx-r13-text:#f7f7f8;--afx-r13-muted:#9ca3af}
html[data-theme="light"]{--afx-r13-line:rgba(15,23,42,.12);--afx-r13-card:#fff;--afx-r13-text:#151821;--afx-r13-muted:#5f6877}

/* Never let a closed overlay eat the mouse. */
#workspace-overlay.overlay-hidden{pointer-events:none!important;visibility:hidden!important}
#workspace-overlay.overlay-visible{pointer-events:auto!important;visibility:visible!important}
#settings-scrim.opacity-0{pointer-events:none!important;visibility:hidden!important}
#settings-drawer.drawer-closed{pointer-events:none!important;visibility:hidden!important}
#settings-drawer.drawer-open{pointer-events:auto!important;visibility:visible!important}
main,#main-scroll,#view-home,#view-library,#view-chat{pointer-events:auto}

/* Supplied AethexFlow artwork is the brand in every theme. */
#app-sidebar .sidebar-brand.afx-r13-brand{background:#070709!important;padding:10px 14px!important;min-height:72px!important}
#app-sidebar .sidebar-brand.afx-r13-brand .afx-brand-home{display:flex!important;align-items:center!important;width:100%!important;height:100%!important}
#app-sidebar .sidebar-brand.afx-r13-brand .afx-brand-logo{display:block!important;width:100%!important;max-width:190px!important;height:auto!important;filter:none!important}
body.sidebar-collapsed #app-sidebar .sidebar-brand.afx-r13-brand .afx-brand-logo{width:52px!important;height:44px!important;object-fit:cover!important;object-position:left center!important}

/* Tool library: no black controls in light mode and no washed-out card copy. */
.afx16-tools-toolbar{border:1px solid var(--border)!important;padding:12px 14px!important;display:flex!important;justify-content:space-between!important;gap:12px!important;align-items:center!important;margin-bottom:16px!important}
html[data-theme="light"] .afx16-tools-toolbar{background:#fff!important;color:#151821!important;border-color:rgba(15,23,42,.12)!important;box-shadow:0 10px 28px rgba(15,23,42,.055)!important}
html[data-theme="light"] .afx16-tools-toolbar b,html[data-theme="light"] .afx16-count{color:#4b5563!important}
html[data-theme="light"] .afx16-select,html[data-theme="light"] .afx16-select option{background:#fff!important;color:#151821!important;border-color:#d7dce4!important}
html[data-theme="light"] .afx16-store-card,html[data-theme="light"] .afx16-home-card{background:#fff!important;border-color:rgba(15,23,42,.11)!important;box-shadow:0 8px 24px rgba(15,23,42,.055)!important}
html[data-theme="light"] .afx16-card-title h3{color:#151821!important}
html[data-theme="light"] .afx16-card-desc{color:#525c6b!important}
html[data-theme="light"] .afx16-usage{color:#697386!important}
html[data-theme="light"] .afx16-pin{background:#f7f8fa!important;border-color:#dfe3e8!important;color:#697386!important}
html[data-theme="light"] .afx16-pin.active{color:#e32636!important;background:#fff1f2!important;border-color:#fecdd3!important}
html[data-theme="light"] .afx16-open{color:#c81e2c!important;background:#fff1f2!important;border-color:#fecdd3!important}
.afx16-store-card,.afx16-home-card,.afx16-card-body,.afx16-card-title,button,.nav-btn,.cat-btn{-webkit-user-select:none;user-select:none}
input,textarea,select,[contenteditable="true"]{-webkit-user-select:text;user-select:text}
.afx16-thumb{background:#090a0f!important}
.afx16-thumb img{object-fit:cover!important;opacity:1!important;visibility:visible!important}

/* Card editing controls. */
.afx-r13-card-actions{display:flex;align-items:center;gap:6px;margin-left:auto}
.afx-r13-card-action{width:28px;height:28px;border:1px solid var(--border);background:rgba(255,255,255,.035);color:var(--muted);border-radius:9px;display:grid;place-items:center;cursor:pointer}
.afx-r13-card-action:hover{color:var(--text);border-color:rgba(255,59,63,.28);background:rgba(255,59,63,.08)}
html[data-theme="light"] .afx-r13-card-action{background:#f7f8fa;color:#5f6877;border-color:#dfe3e8}
html[data-theme="light"] .afx-r13-card-action:hover{color:#c81e2c;background:#fff1f2;border-color:#fecdd3}

#afxCardEditor{position:fixed;inset:0;z-index:140;display:none;align-items:center;justify-content:center;padding:18px;background:rgba(5,6,9,.58);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px)}
#afxCardEditor.open{display:flex}
#afxCardEditor .afx-r13-editor-card{width:min(520px,100%);border:1px solid var(--border);background:var(--surface,#111114);color:var(--text);border-radius:20px;padding:18px;box-shadow:0 30px 90px rgba(0,0,0,.35)}
#afxCardEditor .afx-r13-editor-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px}
#afxCardEditor .afx-r13-editor-head h3{margin:0;font-size:17px}
#afxCardEditor label{display:block;margin:10px 0;color:var(--muted);font-size:11px}
#afxCardEditor input,#afxCardEditor textarea{margin-top:6px;width:100%;border:1px solid var(--border);background:var(--surface-2,#18181d);color:var(--text);border-radius:10px;padding:10px 11px}
#afxCardEditor textarea{min-height:92px;resize:vertical}
#afxCardEditor .afx-r13-editor-actions{display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;margin-top:14px}

/* Public Chat: user-facing, no server-brain diagnostics or localhost endpoints. */
#view-chat{max-width:900px;margin:0 auto;padding-top:22px;padding-bottom:36px}
.afx-chat-shell{display:flex;flex-direction:column;height:min(720px,calc(100dvh - 140px));min-height:520px;border:1px solid var(--border);background:var(--panel);border-radius:22px;overflow:hidden;box-shadow:0 18px 50px rgba(0,0,0,.08)}
.afx-chat-head{padding:18px 20px;border-bottom:1px solid var(--border);display:flex;align-items:center;justify-content:space-between;gap:12px}
.afx-chat-head h1{margin:0;font-size:22px}.afx-chat-head p{margin:4px 0 0;color:var(--muted);font-size:11px}.afx-chat-mode{font-size:10px;padding:6px 9px;border-radius:999px;border:1px solid rgba(54,211,153,.22);background:rgba(54,211,153,.08);color:#36d399;font-weight:800;white-space:nowrap}
.afx-chat-log{flex:1;overflow:auto;padding:20px;display:flex;flex-direction:column;gap:12px;background:rgba(0,0,0,.06)}
.afx-chat-message{max-width:min(82%,720px);padding:11px 13px;border-radius:14px;white-space:pre-wrap;line-height:1.55;font-size:13px;border:1px solid var(--border)}
.afx-chat-message.user{align-self:flex-end;background:rgba(255,59,63,.11);border-color:rgba(255,59,63,.20)}
.afx-chat-message.assistant{align-self:flex-start;background:var(--surface-2,#18181d)}
html[data-theme="light"] .afx-chat-message.assistant{background:#fff}
.afx-chat-compose{padding:12px;border-top:1px solid var(--border);display:flex;gap:9px;background:var(--surface,#111114)}
.afx-chat-compose textarea{flex:1;min-height:48px;max-height:150px;resize:none;border:1px solid var(--border);background:var(--surface-2,#18181d);color:var(--text);border-radius:13px;padding:12px 13px;outline:none}
.afx-chat-send{width:50px;flex:0 0 50px;border:0;border-radius:13px;background:#ff3b3f;color:#fff;cursor:pointer;font-weight:900}

.afx-r13-restore-row{margin-top:8px}
.afx-r13-restore-row button{width:100%;border:1px solid var(--border);background:rgba(255,255,255,.04);color:var(--text);border-radius:10px;padding:9px 10px;font-size:11px;font-weight:700;cursor:pointer}

@media(max-width:767px){
 #app-sidebar .sidebar-brand.afx-r13-brand{display:none!important}
 #view-chat{padding-top:8px}.afx-chat-shell{height:calc(100dvh - 166px);min-height:430px}.afx-chat-head{padding:14px}.afx-chat-log{padding:14px}.afx-chat-message{max-width:92%}
}


/* R13 nav polish — Dashboard first + Library */
#app-sidebar .nav-btn[data-view="home"] i { color: inherit; }
#app-sidebar .nav-btn.active[data-view="home"] i { color: var(--red, #ff3b3f); }
html[data-theme="light"] #app-sidebar .nav-btn {
  color: #5f6877;
}
html[data-theme="light"] #app-sidebar .nav-btn:hover {
  background: rgba(20,24,32,0.04);
  color: #16181d;
}
html[data-theme="light"] #app-sidebar .nav-btn.active {
  background: rgba(255,59,63,0.1) !important;
  color: #c81e2c !important;
  box-shadow: inset 0 0 0 1px rgba(255,59,63,0.12);
}
