/* Library / Context / Essays: reading first, tools within reach. */
.library-shell,
.library-shell :where(.library-grid, .library-main, .library-specialized,
  .library-reader-panel, .library-reader-panel-main, .library-book-page,
  .library-book-toc, .tasks-column, .task-card-main, .goals-smart-canvas,
  .calendar-layout, .calendar-agenda, .calendar-sidebar, .cmd-stack) {
  min-width: 0;
}
.library-main { container: library-content / inline-size; }
.library-mobile-navigation { display: none; }
.library-mobile-overview { display: none; }
.library-mobile-tags-control { display: none; }
.library-secondary-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.library-status--routine {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.library-tools-disclosure { min-width: 0; }
.library-tools-disclosure > summary { display: none; }
.library-tools-disclosure-body { display: contents; }
.library-controls > .library-tools-disclosure { display: contents; }
.library-reader-panel-tools .library-tools-disclosure-body { display: block; }
.library-popover > div { width: 100%; max-width: 100%; }
.library-popover { overscroll-behavior: contain; }
.library-shell :where(.library-card-title, .library-card-snippet,
  .library-inspector-text, .library-inspector-meta-row, .library-book-page-body,
  .task-card-title, .calendar-card-title, .cmd-analysis-copy,
  .purpose-planner-surface) { overflow-wrap: anywhere; }
.library-shell :where(button, select, input, textarea):focus-visible,
.library-tools-disclosure > summary:focus-visible {
  outline: 2px solid var(--accent, #0cb27c);
  outline-offset: 3px;
}
.library-inspector { overscroll-behavior: contain; scroll-padding-block: 12px; }
.essay-tools-disclosure > summary { display: none; }
.ausry-bg.essay-workspace .essays-grid > *,
.ausry-bg.context-workspace .ctx-layout > * { min-width: 0; }
.ausry-bg.essay-workspace .essay-drawer-panel {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.ausry-bg.context-workspace :where(.ctx-note-panel, .ctx-note-metric, .ctx-note-row,
  .ctx-note-text, .ctx-note-inspector-title, .ctx-note-chip) {
  min-width: 0;
  overflow-wrap: anywhere;
}
/* Use available panel width: the app's own sidebar consumes desktop space. */
@container library-content (max-width: 900px) {
  .library-reader-panel-body { grid-template-columns: minmax(0, 1fr); }
  .library-reader-panel-tools {
    border-left: 0;
    border-top: 1px solid var(--border-light);
    padding: 12px 0 0;
  }
  .tasks-board-columns,
  .goals-smart-shell { grid-template-columns: minmax(0, 1fr); }
  .tasks-column-header { flex-wrap: wrap; }
}
@container library-content (max-width: 640px) {
  .library-reader-view { grid-template-columns: minmax(0, 1fr); }
  .library-reader-list { max-height: min(28dvh, 220px); }
  .library-reader-panel-header { flex-direction: column; }
  .library-reader-actions { min-width: 0; width: 100%; justify-content: flex-start; }
  .decision-matrix-grid { grid-template-columns: minmax(0, 1fr); }
  .library-shell .idea-lanes-grid { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (max-width: 1099px) {
  .library-shell > .library-mobile-navigation {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    font-size: .8rem;
  }
  .library-mobile-navigation select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    color: var(--text-primary);
    background: var(--main-surface-secondary);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    font: inherit;
    font-size: 16px;
  }
  .library-shell .library-sidebar { display: none; }
}
@media (max-width: 900px) {
  .ausry-bg.essay-workspace .essays-grid { display: flex; flex-direction: column; }
  .ausry-bg.essay-workspace .essays-grid > * { width: 100%; }
  .ausry-bg.essay-workspace .essays-daily { order: -1; }
  .essay-tools-disclosure > summary {
    display: list-item;
    cursor: pointer;
    min-height: 44px;
    padding: 12px;
    border-radius: 12px;
    background: var(--main-surface-secondary);
    color: var(--text-primary);
    font-size: .9rem;
  }
  .essay-tools-disclosure[open] > summary { margin-bottom: 8px; }
  .ausry-bg.context-workspace .ctx-layout { display: flex; flex-direction: column; }
  .ausry-bg.context-workspace .ctx-layout > * { width: 100%; }
  .ausry-bg.context-workspace .ctx-summary-column { order: -1; }
  .ausry-bg.context-workspace .ctx-period-navigation .ctx-rail-sticky > .p-4 { display: none; }
  .ausry-bg.context-workspace .ctx-period-navigation .ctx-rail-sticky > .px-4 { padding: 12px; }
  .ausry-bg.context-workspace .ctx-period-navigation .ctx-rail-sticky .mt-2 { display: none; }
  .ausry-bg.context-workspace .ctx-note-list {
    max-height: min(32dvh, 280px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px;
  }
}
@media (max-width: 720px) {
  .library-shell { gap: 12px; padding-bottom: 80px; }
  .library-shell .library-head { display: none; }
  .library-shell .library-mobile-overview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    color: var(--text-secondary);
    font-size: .8rem;
    padding: 0 0 12px;
  }
  .library-shell .library-head-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }
  .library-shell .library-head-pill { min-width: 0; padding: 8px; gap: 4px; }
  .library-shell .library-head-pill span { font-size: .65rem; letter-spacing: .03em; }
  .library-shell .library-head-pill strong { font-size: 1.12rem; }
  .library-shell .library-main { padding: 0; min-height: 0; background: transparent; }
  .library-shell .library-controls {
    position: static;
    padding: 0;
    gap: 8px;
    margin-bottom: 12px;
    background: transparent;
  }
  .library-shell .library-search { flex: 1 1 100%; min-width: 0; }
  .library-shell .library-icon-toolbar { display: flex; gap: 4px; width: 100%; justify-content: space-between; }
  .library-shell .library-icon-btn { width: auto; min-height: 44px; padding: 8px; }
  .library-shell .library-icon-btn .material-symbols-outlined { font-size: 20px; }
  .library-shell .library-icon-label { font-size: .6rem; letter-spacing: 0; }
  .library-shell .library-icon-toolbar > .library-icon-btn .library-icon-label { display: none; }
  .library-shell .library-view-mode-buttons { display: flex; flex: 1; justify-content: center; }
  .library-shell .library-view-mode-buttons .library-icon-btn { flex: 1; }
  .library-shell .library-secondary-controls { margin-bottom: 8px; }
  .library-shell .library-tools-disclosure { display: block; width: 100%; }
  .library-shell .library-tools-disclosure > summary {
    display: list-item;
    cursor: pointer;
    padding: 12px;
    min-height: 44px;
    border-radius: 12px;
    background: var(--main-surface-secondary);
    color: var(--text-secondary);
    font-size: .85rem;
  }
  .library-shell .library-tools-disclosure-body { display: block; padding: 10px 0; }
  .library-shell .library-control-row { gap: 8px; }
  .library-shell .library-btn { width: auto; min-height: 44px; max-width: 100%; }
  .library-shell :where(input:not([type="checkbox"]):not([type="radio"]), textarea, select) {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
  }
  .library-shell :where(.library-pill, .calendar-view-button, .calendar-filter-chip,
    .calendar-card-action, .library-card-action, .library-book-tag-action) { min-height: 40px; }
  .library-shell .library-filter-panel { padding: 10px; margin-bottom: 12px; }
  .library-shell .library-reader-panel { padding: 14px; }
  .library-shell .library-reader-panel-text-editor { font-size: 16px; line-height: 1.7; min-height: 38dvh; }
  .library-shell .library-reader-actions { min-width: 0; gap: 8px; }
  .library-shell .library-reader-voice-select { max-width: 100%; min-height: 44px; flex: 1 1 110px; }
  .library-shell .library-reader-panel-tools { border: 0; padding: 0; }
  .library-shell .library-book-page-body { font-size: 1rem; line-height: 1.7; }
  .library-shell .library-book-page-head { flex-wrap: wrap; gap: 10px; }
  .library-shell .idea-lanes-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .library-shell .decision-matrix-grid { grid-template-columns: minmax(0, 1fr); }
  .library-shell .tasks-column-header { flex-wrap: wrap; padding: 14px; gap: 12px; }
  .library-shell .tasks-column-header { flex-direction: row; align-items: center; padding: 10px 12px; gap: 8px; }
  .library-shell .tasks-column-header > .library-tools-disclosure { width: auto; flex: 0 1 auto; }
  .library-shell .tasks-column-header > .library-tools-disclosure[open] { width: 100%; flex-basis: 100%; }
  .library-shell .tasks-column-header > .library-tools-disclosure > summary { font-size: .72rem; padding: 12px 8px; }
  .library-shell .tasks-column-body { padding: 14px; }
  .library-shell .tasks-column-controls { width: 100%; gap: 10px; }
  .library-shell .tasks-column-select { display: flex; align-items: center; gap: 8px; max-width: 100%; }
  .library-shell .tasks-column-select .library-select-control { min-width: 0; margin-left: 0; max-width: 100%; }
  .library-shell .tasks-group-toggle { flex-wrap: wrap; }
  .library-shell .tasks-board-summary { flex-direction: row; align-items: center; flex-wrap: nowrap; padding: 8px 12px; gap: 8px; }
  .library-shell .tasks-board-summary-title { font-size: .88rem; }
  .library-shell .tasks-board-summary-subtitle { font-size: .72rem; }
  .library-shell .tasks-board-progress { flex: 0 0 64px; }
  .library-shell .tasks-board-progress-bar { width: 64px; }
  .library-shell .tasks-board-progress-label { display: none; }
  .library-shell[data-active-tab="Tasks"] .library-filter-panel {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0;
    margin: 0 0 10px;
  }
  .library-shell[data-active-tab="Tasks"] .library-filter-panel .library-select-label { margin: 0; font-size: .68rem; }
  .library-shell[data-active-tab="Tasks"] .library-filter-panel .library-control-row { width: auto; }
  .library-shell .library-specialized { margin-top: 0; }
  .library-shell .tasks-board { gap: 8px; }
  .library-tags-float-btn, .library-shell .fab-inspector { display: none; }
  .library-shell .library-mobile-tags-control { display: inline-flex; align-items: center; }
  .library-shell .task-card-title-row { flex-wrap: wrap; }
  .library-shell .task-card-meta { flex-wrap: wrap; }
  .library-shell .goals-north-star-panel { position: static; }
  .library-shell .goals-smart-list { height: auto; max-height: min(40dvh, 340px); }
  .library-shell .goals-smart-shell { min-height: 0; }
  .library-shell .calendar-toolbar { gap: 10px; align-items: stretch; }
  .library-shell .calendar-view-switch { width: 100%; }
  .library-shell .calendar-view-button { flex: 1; }
  .library-shell .calendar-layout { grid-template-columns: minmax(0, 1fr); }
  .library-shell .calendar-composer-row { flex-direction: column; }
  .library-shell .calendar-composer-datetime { flex-wrap: wrap; }
  .library-shell .calendar-composer-datetime label { flex: 1 1 120px; min-width: 0; }
  .library-shell .calendar-card-body { flex-wrap: wrap; }
  .library-shell .calendar-sidebar { position: static; }
  .library-shell .cmd-source-nav {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 6px;
    scroll-snap-type: x proximity;
  }
  .library-shell .cmd-source-btn { flex: 0 0 auto; min-width: 125px; min-height: 48px; scroll-snap-align: start; }
  .library-shell .cmd-hero-layout { grid-template-columns: minmax(0, 1fr); }
  .library-shell .cmd-purpose-urn { display: none; }
  .library-shell .cmd-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-shell .cmd-action-row { flex-wrap: wrap; }
  .library-inspector .library-btn { min-height: 44px; }
  .library-inspector :where(input, textarea, select) { font-size: 16px; }
  .library-inspector .library-btn--danger { margin-right: 0; }
  .ausry-bg.essay-workspace > .mx-auto,
  .ausry-bg.context-workspace > .mx-auto { padding: 8px 0 16px; }
  .ausry-bg.essay-workspace .essay-editor-stack { padding-left: 0; }
  .ausry-bg.essay-workspace .essay-shortcuts { position: static; flex-direction: row; flex-wrap: wrap; margin-bottom: 8px; }
  .ausry-bg.essay-workspace .essay-shortcuts button { width: 44px; height: 44px; }
  .ausry-bg.essay-workspace .essay-editor { min-height: 48dvh; font-size: 16px; line-height: 1.7; }
  .ausry-bg.essay-workspace .layout-switch { flex-wrap: wrap; }
  .ausry-bg.essay-workspace .layout-switch button { min-height: 40px; padding: 8px 10px; }
  .ausry-bg.essay-workspace .essays-compact-header { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ausry-bg.essay-workspace .essays-compact-pill { min-width: 0; padding: 10px; }
  .ausry-bg.context-workspace .ctx-header-actions { gap: 8px; }
  .ausry-bg.context-workspace .ctx-header-actions > button { width: auto; flex: 1 1 auto; min-height: 44px; }
  .ausry-bg.context-workspace .ctx-mode-pill { flex-wrap: nowrap; padding: 3px; }
  .ausry-bg.context-workspace .ctx-mode-pill button { min-width: 0; min-height: 44px; padding: 8px 6px; flex: 1; }
  .ausry-bg.context-workspace .ctx-view-switch button { min-height: 44px; }
  .ausry-bg.context-workspace .ctx-note-body-grid { grid-template-columns: minmax(0, 1fr); }
  .ausry-bg.context-workspace .ctx-note-text { font-size: 1rem; line-height: 1.7; }
  .ausry-bg.context-workspace .ctx-note-chip { white-space: normal; line-height: 1.35; }
}
@media (prefers-reduced-motion: reduce) {
  .library-shell *, .ausry-bg.essay-workspace *, .ausry-bg.context-workspace * {
    scroll-behavior: auto !important;
    transition-duration: 0s !important;
  }
}
