/* Scoped late overrides: keep existing Math/composer and legacy layout untouched. */
#memoryPanel [hidden] { display: none !important; }
html body #appRoot.app #memoryPanel { overflow-y: auto; padding-bottom: 24px; }
html body #appRoot.app #memoryPanel #memoryList { list-style: none; padding: 12px; height: auto; min-height: 170px; max-height: min(46dvh, 520px); overflow: auto; }
#memoryPanel #memoryDescription { margin-bottom: 12px; }
#memoryStatus { min-height: 1.3em; margin: 0 0 10px; color: #687083; font-size: .85rem; }
#memoryPanel .memory-card { padding: 14px; margin: 0 0 12px; border: 1px solid rgba(130, 110, 175, .16); border-radius: 12px; background: rgba(255, 255, 255, .55); }
#memoryPanel .memory-card p, #memoryPanel .memory-agenda { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; margin: 8px 0; }
#memoryPanel .memory-card.is-background { opacity: .67; }
#memoryPanel .memory-group-title { margin: 16px 4px 10px; font-size: .95rem; font-weight: 700; }
#memoryPanel .memory-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
#memoryPanel .memory-actions button, #memoryPanel .memory-refresh, .memory-version-switch button { min-height: 36px; border: 1px solid rgba(136, 103, 186, .22); border-radius: 9px; background: rgba(255, 255, 255, .65); color: #635179; padding: 7px 10px; cursor: pointer; }
#memoryPanel .memory-card .memory-actions { flex-wrap: nowrap; width: 100%; }
#memoryPanel .memory-card .memory-actions .memory-icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 36px; width: 36px; height: 36px; min-height: 36px; padding: 8px;
  border: 0; background: transparent; box-shadow: none; color: #687083; cursor: pointer;
}
#memoryPanel .memory-icon-button svg { display: block; width: 20px; height: 20px; }
#memoryPanel .memory-card .memory-icon-button:hover { color: #8446df; }
#memoryPanel .memory-card .memory-icon-button:focus-visible { outline: 2px solid #8d4ded; outline-offset: 2px; }
#memoryPanel .memory-card .memory-icon-button:disabled { opacity: .45; cursor: wait; }
#memoryPanel .memory-card .memory-actions .memory-delete-button { margin-inline-start: auto; color: #d83b48; }
#memoryPanel .memory-card .memory-actions .memory-delete-button:hover { color: #b52032; }
.memory-version-switch { display: flex; gap: 6px; }
.memory-version-switch button { flex: 1; }
.memory-version-switch button[aria-pressed="true"] { background: #8d4ded; color: white; }
#memoryPanel .memory-mode-switch {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; overflow: hidden; border: 1px solid rgba(112, 91, 142, .18);
  border-radius: 13px; background: rgba(100, 90, 120, .09);
  touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab;
}
#memoryPanel .memory-mode-switch:active { cursor: grabbing; }
#memoryPanel .memory-mode-switch::before {
  content: ""; position: absolute; z-index: 0; top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 6px); border-radius: 9px; background: #8546e8;
  box-shadow: 0 2px 7px rgba(92, 40, 170, .25);
  transform: translateX(0); transition: transform .2s ease;
}
#memoryPanel .memory-mode-switch.is-temporary::before { transform: translateX(calc(100% + 4px)); }
#memoryPanel .memory-mode-switch button {
  position: relative; z-index: 1; min-width: 0; min-height: 38px; padding: 8px 12px;
  border: 0; border-radius: 9px; background: transparent; color: #5e6270;
  font: inherit; font-weight: 650; cursor: pointer; transition: color .16s ease;
}
#memoryPanel .memory-mode-switch button[aria-selected="true"] { color: #fff; background: transparent; }
#memoryPanel .memory-mode-switch button:focus-visible { outline: 2px solid #8546e8; outline-offset: -2px; }
.memory-settings { border-top: 1px solid rgba(128, 128, 128, .16); margin-top: 16px; padding-top: 4px; }
.memory-settings h4 { margin: 12px 0; }
.memory-switch-row { display: flex; align-items: center; gap: 12px; cursor: pointer; margin: 14px 0; position: relative; }
.memory-switch-row > span:first-child { flex: 1; }
.memory-switch-row strong { font-size: .9rem; }
.memory-switch-row small { display: block; line-height: 1.5; margin-top: 4px; color: #7f8390; font-size: .78rem; }
.memory-switch-row input { position: absolute; right: 0; width: 48px; height: 28px; opacity: 0; cursor: pointer; }
.memory-ios-switch { flex: 0 0 48px; height: 28px; background: #b7b8c1; border-radius: 20px; transition: background .18s; pointer-events: none; }
.memory-ios-switch::before { content: ""; display: block; width: 22px; height: 22px; border-radius: 50%; margin: 3px; background: white; box-shadow: 0 1px 3px #0002; transition: transform .18s; }
.memory-switch-row input:checked + .memory-ios-switch { background: #9456ed; }
.memory-switch-row input:checked + .memory-ios-switch::before { transform: translateX(20px); }
.memory-switch-row input:focus-visible + .memory-ios-switch { outline: 3px solid #bca1ef; outline-offset: 3px; }
.memory-edit-dialog { width: min(640px, calc(100vw - 32px)); border: 1px solid #d6cbe9; border-radius: 18px; padding: 22px; color: #20202b; background: #faf9fc; box-sizing: border-box; }
.memory-edit-dialog::backdrop { background: #18102566; backdrop-filter: blur(3px); }
.memory-edit-dialog textarea { width: 100%; box-sizing: border-box; min-height: 220px; max-height: 55dvh; resize: vertical; border: 1px solid #cfc5e0; border-radius: 10px; padding: 12px; font: inherit; color: inherit; background: transparent; line-height: 1.55; }
.memory-edit-dialog .memory-actions { display: flex; justify-content: flex-end; gap: 8px; }
.memory-edit-dialog button { padding: 9px 15px; border-radius: 9px; border: 1px solid #cfc5e0; cursor: pointer; }
.memory-edit-dialog button[type="submit"] { background: #8d4ded; color: white; }
.memory-edit-dialog output { display: block; padding: 8px 0; color: #767082; font-size: .83rem; }
body.ui-dark-mode #memoryPanel .memory-card { background: rgba(255,255,255,.03); }
body.ui-dark-mode #memoryPanel .memory-actions button, body.ui-dark-mode #memoryPanel .memory-refresh, body.ui-dark-mode .memory-version-switch button { background: #292331; color: #d3c1ee; }
body.ui-dark-mode .memory-version-switch button[aria-pressed="true"] { background: #8d4ded; color: white; }
body.ui-dark-mode .memory-edit-dialog { background: #201d28; color: #ece6f8; }
body.ui-dark-mode #memoryPanel .memory-mode-switch { background: rgba(255,255,255,.07); border-color: rgba(210,190,240,.18); }
body.ui-dark-mode #memoryPanel .memory-mode-switch button { color: #d0c7dc; }
body.ui-dark-mode #memoryPanel .memory-mode-switch button[aria-selected="true"] { color: #fff; }
body.ui-dark-mode #memoryPanel .memory-mode-switch::before { background: #8546e8; }
body.ui-dark-mode #memoryPanel .memory-card .memory-actions .memory-icon-button { background: transparent; color: #b4a9c9; }
body.ui-dark-mode #memoryPanel .memory-card .memory-actions .memory-icon-button:hover { color: #c79aff; }
body.ui-dark-mode #memoryPanel .memory-card .memory-actions .memory-delete-button { color: #ff6976; }
body.ui-dark-mode #memoryPanel .memory-card .memory-actions .memory-delete-button:hover { color: #ff8c96; }
@media(max-width:700px) { #memoryPanel .memory-actions button { min-height: 40px; } html body #appRoot.app #memoryPanel #memoryList { max-height: 40dvh; padding: 8px; } }
@media(max-width:700px) { #memoryPanel .memory-card .memory-actions .memory-icon-button { flex-basis: 44px; width: 44px; height: 44px; min-height: 44px; } }
@media(prefers-reduced-motion:reduce) { .memory-ios-switch, .memory-ios-switch::before { transition: none; } }
@media(prefers-reduced-motion:reduce) { #memoryPanel .memory-mode-switch::before { transition: none; } }
