.notes {
  --notes-gap: 0.7rem;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--notes-gap);
  position: relative;
}

.notes__kicker {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand-muted, #64748b);
}

.notes__toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.75rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.notes__toolbar-title {
  flex: 1 1 16rem;
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
}

/* Modern menus (replace native selects) */
.notes__menu {
  position: relative;
  min-width: 0;
}

.notes__menu > summary {
  list-style: none;
}

.notes__menu > summary::-webkit-details-marker {
  display: none;
}

.notes__menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 12rem;
  border: 1px solid var(--brand-border, #e2e8f0);
  background: #fff;
  border-radius: 0.75rem;
  padding: 0.42rem 0.65rem;
  cursor: pointer;
  min-width: 0;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.notes__menu-trigger--field {
  width: 100%;
  max-width: none;
  justify-content: space-between;
  padding: 0.62rem 0.75rem;
  border-radius: 0.7rem;
}

.notes__menu-trigger strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}

.notes__menu-label {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--brand-muted, #64748b);
  flex: 0 0 auto;
}

.notes__menu-caret {
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.55;
  margin-left: auto;
  flex: 0 0 auto;
}

.notes__menu[open] > .notes__menu-trigger {
  border-color: color-mix(in srgb, var(--brand-primary, #8b5cf6) 45%, var(--brand-border, #e2e8f0));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary, #8b5cf6) 14%, transparent);
}

.notes__menu-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: min(18rem, 78vw);
  max-width: min(22rem, 90vw);
  border: 1px solid var(--brand-border, #e2e8f0);
  border-radius: 0.9rem;
  background: #fff;
  box-shadow: 0 18px 40px rgb(15 23 42 / 0.16);
  padding: 0.45rem;
}

.notes__menu--tone .notes__menu-panel {
  right: 0;
  left: auto;
  width: 100%;
  min-width: 0;
}

.notes__menu-heading {
  margin: 0.2rem 0.45rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--brand-muted, #64748b);
}

.notes__menu-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 14rem;
  overflow: auto;
}

.notes__menu-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 0.65rem;
  padding: 0.55rem 0.6rem;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.notes__menu-item small {
  font-size: 0.7rem;
  color: var(--brand-muted, #64748b);
}

.notes__menu-item:hover,
.notes__menu-item.is-active {
  background: color-mix(in srgb, var(--brand-primary, #8b5cf6) 10%, #fff);
}

.notes__menu-item.is-active {
  font-weight: 700;
}

.notes__menu-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--brand-border, #e2e8f0);
}

.notes__menu-footer .notes__btn {
  flex: 1 1 auto;
  font-size: 0.78rem;
  padding: 0.45rem 0.6rem;
}

.notes__toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
}

.notes__book-title {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--brand-border, #e2e8f0);
  border-radius: 0.65rem;
  padding: 0.5rem 0.75rem;
  font-weight: 800;
  font-size: 1rem;
  box-sizing: border-box;
  background: #fff;
}

.notes__words {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-muted, #64748b);
  white-space: nowrap;
}

.notes__btn {
  border: 0;
  border-radius: 0.55rem;
  padding: 0.48rem 0.85rem;
  font-weight: 700;
  background: var(--brand-primary, #8b5cf6);
  color: var(--brand-button-text, #fff);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.notes__btn--ghost {
  background: transparent;
  border: 1px solid var(--brand-border, #e2e8f0);
  color: inherit;
}

.notes__btn--primary {
  background: var(--brand-primary, #8b5cf6);
  color: var(--brand-button-text, #fff);
}

.notes__btn--danger {
  background: #b91c1c;
  color: #fff;
}

.notes__btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.notes__status {
  font-size: 0.78rem;
  color: var(--brand-muted, #64748b);
  font-weight: 600;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes__mobile-tabs {
  display: none;
  flex: 0 0 auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

.notes__mobile-tabs button {
  border: 1px solid var(--brand-border, #e2e8f0);
  background: #fff;
  border-radius: 0.65rem;
  padding: 0.55rem 0.4rem;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  color: inherit;
}

.notes__mobile-tabs button.is-active {
  background: var(--brand-primary, #8b5cf6);
  color: var(--brand-button-text, #fff);
  border-color: transparent;
}

.notes__workspace {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(11rem, 14rem) minmax(0, 1fr) minmax(14rem, 17rem);
  gap: var(--notes-gap);
  align-items: stretch;
}

.notes__side,
.notes__main,
.notes__ai {
  border: 1px solid var(--brand-border, #e2e8f0);
  border-radius: 1rem;
  background: var(--brand-card-bg, #fff);
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
}

.notes__side {
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: auto;
}

.notes__side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.notes__side-head h3,
.notes__ai-head h3,
.notes__draft-head h4 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
}

.notes__add {
  border: 0;
  background: transparent;
  color: var(--brand-primary, #8b5cf6);
  font-weight: 800;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 0.4rem;
}

.notes__pages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1 1 auto;
  min-height: 0;
}

.notes__page-item {
  border: 1px solid transparent;
  border-radius: 0.75rem;
  background: color-mix(in srgb, var(--brand-surface, #f8fafc) 80%, #fff);
  padding: 0.3rem;
}

.notes__page-item.is-active {
  border-color: color-mix(in srgb, var(--brand-primary, #8b5cf6) 45%, var(--brand-border, #e2e8f0));
  background: color-mix(in srgb, var(--brand-primary, #8b5cf6) 8%, #fff);
}

.notes__page-btn {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.4rem 0.45rem;
  border-radius: 0.55rem;
  cursor: pointer;
  color: inherit;
}

.notes__page-name {
  display: block;
  font-size: 0.86rem;
  font-weight: 800;
  word-break: break-word;
}

.notes__page-meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--brand-muted, #64748b);
  line-height: 1.3;
}

.notes__page-actions,
.notes__rename,
.notes__draft-actions,
.notes__confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.notes__rename input {
  flex: 1 1 100%;
  min-width: 0;
  border: 1px solid var(--brand-border, #e2e8f0);
  border-radius: 0.45rem;
  padding: 0.4rem 0.5rem;
  box-sizing: border-box;
}

.notes__mini {
  border: 1px solid var(--brand-border, #e2e8f0);
  background: #fff;
  border-radius: 0.4rem;
  padding: 0.25rem 0.45rem;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  color: inherit;
}

.notes__mini--primary {
  background: var(--brand-primary, #8b5cf6);
  color: var(--brand-button-text, #fff);
  border-color: transparent;
}

.notes__mini--danger {
  color: #b91c1c;
  border-color: color-mix(in srgb, #b91c1c 35%, #fff);
}

.notes__main {
  padding: 0.75rem 0.85rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow: hidden;
}

.notes__editor-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.notes__page-title {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--brand-border, #e2e8f0);
  font-size: 1.1rem;
  font-weight: 800;
  padding: 0.2rem 0 0.4rem;
  box-sizing: border-box;
  background: transparent;
}

.notes__body {
  flex: 1 1 auto;
  width: 100%;
  min-height: 12rem;
  height: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--brand-border, #e2e8f0);
  border-radius: 0.8rem;
  padding: 0.85rem 0.95rem;
  font: inherit;
  line-height: 1.55;
  resize: none;
  background: #fff;
  overflow: auto;
}

.notes__ai {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: color-mix(in srgb, var(--brand-surface, #f8fafc) 75%, #fff);
}

.notes__ai-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.notes__ai-head p {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--brand-muted, #64748b);
}

.notes__label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 0;
}

.notes__label textarea,
.notes__label select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--brand-border, #e2e8f0);
  border-radius: 0.65rem;
  padding: 0.6rem 0.7rem;
  font: inherit;
  resize: vertical;
  background: #fff;
}

.notes__ai-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.notes__ai-actions .notes__btn--primary {
  grid-column: 1 / -1;
}

.notes__ai-actions .notes__btn {
  padding: 0.45rem 0.55rem;
  font-size: 0.8rem;
}

.notes__draft,
.notes__summary {
  border-radius: 0.8rem;
  padding: 0.7rem;
  background: color-mix(in srgb, var(--brand-primary, #8b5cf6) 8%, #fff);
  border: 1px solid color-mix(in srgb, var(--brand-primary, #8b5cf6) 18%, var(--brand-border, #e2e8f0));
}

.notes__summary {
  padding: 0.55rem 0.7rem;
}

.notes__summary summary {
  cursor: pointer;
  font-weight: 800;
  font-size: 0.82rem;
}

.notes__summary[open] summary {
  margin-bottom: 0.45rem;
}

.notes__draft-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.notes__draft pre,
.notes__summary pre {
  white-space: pre-wrap;
  margin: 0;
  font-family: inherit;
  font-size: 0.84rem;
  line-height: 1.45;
  word-break: break-word;
  max-height: 14rem;
  overflow: auto;
}

.notes__confirm {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(15 23 42 / 0.35);
  border-radius: 1rem;
}

.notes__confirm-card {
  width: min(100%, 22rem);
  background: #fff;
  border-radius: 1rem;
  border: 1px solid var(--brand-border, #e2e8f0);
  padding: 1rem 1.05rem;
  box-shadow: 0 18px 40px rgb(0 0 0 / 0.18);
}

.notes__confirm-card h3 {
  margin: 0.2rem 0 0.35rem;
  font-size: 1.05rem;
}

.notes__confirm-card p {
  margin: 0;
  color: var(--brand-muted, #64748b);
  font-size: 0.88rem;
}

.notes__confirm-actions {
  margin-top: 0.85rem;
  justify-content: flex-end;
}

/* Shared dock window controls — the same sizing and drag model as AI Buddy. */
.notes-dock-modal__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  min-width: 0;
}

.notes-dock-modal__sizes {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem;
  border: 1px solid var(--brand-border, color-mix(in srgb, CanvasText 16%, transparent));
  border-radius: 0.6rem;
  background: color-mix(in srgb, var(--brand-primary) 5%, transparent);
}

.notes-dock-modal__sizes button {
  min-height: 1.8rem;
  padding: 0.25rem 0.45rem;
  border: 0;
  border-radius: 0.4rem;
  color: var(--brand-muted, color-mix(in srgb, CanvasText 62%, transparent));
  background: transparent;
  font: inherit;
  font-size: 0.65rem;
  font-weight: 800;
  cursor: pointer;
}

.notes-dock-modal__sizes button.is-active,
.notes-dock-modal__sizes button:hover,
.notes-dock-modal__sizes button:focus-visible {
  color: var(--brand-button-text);
  background: var(--brand-primary);
}

#lms-hw-root .lms-tools__panel--notes.notes-dock-size--small {
  width: min(38rem, calc(100vw - 1.25rem));
  height: min(72vh, 48rem);
  max-height: min(72vh, 48rem);
}

#lms-hw-root .lms-tools__panel--notes.notes-dock-size--half {
  width: min(72rem, calc(100vw - 1.25rem));
  height: min(84vh, 58rem);
  max-height: min(84vh, 58rem);
}

#lms-hw-root .lms-tools__panel--notes.notes-dock-size--full {
  width: min(96rem, calc(100vw - 1.25rem));
  height: min(94vh, 72rem);
  max-height: min(94vh, 72rem);
}

#lms-hw-root .lms-tools[data-lms-notes-modal] {
  pointer-events: auto;
}

#lms-hw-root .lms-tools[data-lms-notes-modal] .lms-tools__backdrop {
  display: block;
  background: color-mix(in srgb, CanvasText 38%, transparent);
  pointer-events: auto;
}

#lms-hw-root .lms-tools__panel--notes > .lms-tools__header[data-office-drag-handle] {
  cursor: grab;
  user-select: none;
  touch-action: none;
}

#lms-hw-root .lms-tools__panel--notes > .lms-tools__header[data-office-drag-handle].is-dragging {
  cursor: grabbing;
}

/* Fill dock shell */
#lms-hw-root .lms-tools__panel--notes {
  padding-bottom: 0.85rem;
}

#lms-hw-root .lms-tools__panel--notes > .lms-tools__header--compact {
  margin-bottom: 0.55rem;
}

#lms-hw-root .lms-tools__panel--notes > .lms-tools__header--compact h2 {
  font-size: 1.05rem;
}

#lms-hw-root .lms-tools__livewire--fill {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden !important;
}

#lms-hw-root .lms-tools__livewire--fill > .notes {
  flex: 1 1 auto;
  min-height: 0;
}

/* Tablet: editor + AI stacked under pages row, or 2-col */
@media (max-width: 1100px) {
  .notes__workspace {
    grid-template-columns: minmax(10rem, 12.5rem) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .notes__side {
    grid-row: 1 / 2;
  }

  .notes__main {
    grid-row: 1 / 2;
  }

  .notes__ai {
    grid-column: 1 / -1;
    max-height: min(38vh, 20rem);
  }
}

/* Phone: one pane at a time */
@media (max-width: 820px) {
  .notes__mobile-tabs {
    display: grid;
  }

  .notes__workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .notes__side,
  .notes__main,
  .notes__ai {
    display: none;
    max-height: none;
  }

  .notes__side.is-mobile-active,
  .notes__main.is-mobile-active,
  .notes__ai.is-mobile-active {
    display: flex;
    min-height: 0;
  }

  .notes__toolbar-title {
    grid-template-columns: 1fr;
  }

  .notes__menu--notebook .notes__menu-trigger {
    max-width: none;
    width: 100%;
  }

  .notes__words {
    justify-self: start;
  }

  .notes__toolbar-actions {
    width: 100%;
  }

  .notes__toolbar-actions .notes__btn {
    flex: 1 1 auto;
  }

  .notes__ai-actions {
    grid-template-columns: 1fr 1fr;
  }

  .notes__body {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  #lms-hw-root .lms-tools__panel--notes.notes-dock-size--small,
  #lms-hw-root .lms-tools__panel--notes.notes-dock-size--half,
  #lms-hw-root .lms-tools__panel--notes.notes-dock-size--full {
    width: calc(100vw - 1rem);
    height: calc(100dvh - 1rem);
    max-height: calc(100dvh - 1rem);
  }

  .notes-dock-modal__actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 420px) {
  .notes__ai-actions {
    grid-template-columns: 1fr;
  }
}
