/*
 * Wooshin Tutor note detail polish
 *
 * Final, narrowly scoped corrections for the note library and handwriting
 * workspace. Load after note-reference.css. This layer deliberately avoids
 * canvas sizing, pointer behavior, and application navigation.
 */

/* --------------------------------------------------------------------------
 * Shared containment
 * ----------------------------------------------------------------------- */

.notes-workspace :where(
  .workspace-head,
  .workspace-head-actions,
  .note-workspace-metrics,
  .note-toolbar,
  .note-tabs,
  .note-layout,
  .note-list,
  .note-card,
  .note-inspector,
  .note-inspector > .form,
  .note-inspector > form,
  .market-grid,
  .market-card
) {
  min-width: 0;
  max-width: 100%;
}

.notes-workspace :where(button, input, select, textarea) {
  max-width: 100%;
}

.notes-workspace :where(.icon, svg) {
  flex: 0 0 auto;
}

.notes-workspace :where(.card-head, .meta, .chips) > * {
  min-width: 0;
}

/* A text-only note must not reserve the thumbnail column. */
.notes-workspace .note-card.notice-card:not(:has(.note-thumb)) {
  grid-template-columns: minmax(0, 1fr);
}

.notes-workspace .note-card.notice-card:not(:has(.note-thumb)) :where(.card-head, .meta, p) {
  grid-column: 1;
}

.notes-workspace .note-card .card-head strong,
.notes-workspace .market-card .card-head strong,
.notes-workspace .note-title-edit span {
  overflow-wrap: anywhere;
}

/* Keep the selected state quiet: the row changes tone, not geometry. */
.notes-workspace .note-card.notice-card.active-note {
  outline: 0;
}

.notes-workspace .note-card.notice-card.active-note::before {
  display: none;
}

/* The DOM-filter fallback should remain Korean and use the same empty rhythm. */
.notes-workspace .note-list[data-empty="true"]::after {
  content: "검색 결과가 없습니다.";
  min-height: 180px;
  padding: 24px 16px;
  color: var(--note-muted, #68736e);
}

/* --------------------------------------------------------------------------
 * Flat library and inspector
 * ----------------------------------------------------------------------- */

.notes-workspace .note-layout.grid.two {
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
}

.notes-workspace .note-list.notice-list {
  overscroll-behavior: contain;
}

.notes-workspace .note-card.notice-card {
  min-height: 94px;
}

.notes-workspace .note-inspector.panel {
  scroll-margin-block: 76px calc(80px + env(safe-area-inset-bottom));
}

/* Text-note controls read as one settings sheet instead of nested cards. */
.notes-workspace .note-inspector > form.form {
  gap: 0;
}

.notes-workspace .note-inspector > form.form .note-inspector-head {
  margin-bottom: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--note-line, #dfe6e2);
}

.notes-workspace .note-inspector > form.form :where(.input, .select) {
  min-height: 50px;
  margin: 0;
  padding-inline: 0;
  border: 0;
  border-bottom: 1px solid var(--note-line, #dfe6e2);
  border-radius: 0;
  background-color: transparent;
}

.notes-workspace .note-inspector > form.form :where(.input, .select):focus {
  border-color: var(--note-green, #0f654b);
  box-shadow: inset 0 -1px 0 var(--note-green, #0f654b);
}

.notes-workspace .note-inspector > form.form .note-textarea {
  min-height: 290px;
  margin-top: 12px;
  border-color: var(--note-line, #dfe6e2);
}

.notes-workspace .note-inspector > form.form > .chips {
  margin-top: 12px;
}

.notes-workspace .note-inspector .compact-empty {
  width: 100%;
  min-height: 168px;
  border: 0;
  background: transparent;
}

.notes-workspace .note-empty.empty {
  width: 100%;
  min-height: 220px;
  padding-inline: clamp(16px, 5vw, 36px);
}

.notes-workspace .note-empty.empty > :where(strong, span) {
  max-width: 340px;
}

.notes-workspace .note-empty.empty button {
  width: auto;
  max-width: 100%;
}

/* Prevent an oversized market preview from forcing the information column. */
.notes-workspace .market-card .note-full-preview,
.notes-workspace .market-card .note-thumb {
  min-width: 0;
}

/* --------------------------------------------------------------------------
 * Handwriting editor containment
 * ----------------------------------------------------------------------- */

.app-shell.has-note-editor,
.has-note-editor .note-editor-backdrop,
.has-note-editor .note-editor {
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  overscroll-behavior: none;
}

.has-note-editor .note-editor :where(
  .note-editor-top,
  .note-editor-leading,
  .note-document-copy,
  .note-editor-actions,
  .note-editor-body,
  .note-toolrail,
  .note-workbench,
  .note-tool-inspector,
  .hand-canvas-stage
) {
  min-width: 0;
  max-width: 100%;
}

.has-note-editor .note-document-copy {
  flex: 1 1 auto;
  overflow: hidden;
}

.has-note-editor .note-title-input {
  display: block;
  max-width: 100%;
}

.has-note-editor .note-editor-actions button :where(.icon, svg),
.has-note-editor .note-editor-back-button :where(.icon, svg) {
  width: 18px;
  height: 18px;
}

.has-note-editor .note-tool-inspector,
.has-note-editor .note-toolrail {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  scroll-padding-inline: 10px;
}

.has-note-editor .note-tool-inspector > *,
.has-note-editor .note-toolrail .note-tool-group {
  flex-shrink: 0;
}

.has-note-editor .note-tool-inspector :where(button, input, output),
.has-note-editor .note-toolrail button {
  touch-action: manipulation;
}

.has-note-editor .note-size-wrap output {
  min-width: 31px;
  text-align: right;
}

.has-note-editor .hand-canvas-stage {
  isolation: isolate;
  scrollbar-gutter: stable both-edges;
}

/* There is no rail or inspector in read-only mode. Remove both reserved slots. */
.has-note-editor .note-editor-readonly .note-editor-body {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

.has-note-editor .note-editor-readonly .note-workbench {
  grid-column: 1;
  grid-row: 1;
  grid-template-rows: minmax(0, 1fr);
}

.has-note-editor .note-editor-readonly .hand-canvas-stage {
  grid-row: 1;
}

/* Undo/redo/fit already live in the desktop header; avoid duplicate controls. */
@media (min-width: 761px) {
  .has-note-editor .note-rail-actions {
    display: none;
  }
}

/* --------------------------------------------------------------------------
 * Tablet and mobile
 * ----------------------------------------------------------------------- */

@media (max-width: 960px) {
  .notes-workspace .note-layout.grid.two {
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .profile-tab-notes,
  .profile-tab-notes .notes-workspace {
    min-width: 0;
    max-width: 100%;
  }

  .notes-workspace {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .notes-workspace .note-toolbar.workspace-section {
    align-items: stretch;
  }

  .notes-workspace .note-toolbar :where(.search-field, .compact-select) {
    height: 44px;
    min-height: 44px;
  }

  .notes-workspace .note-tabs.workspace-tabs {
    scroll-padding-inline: 12px;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* Let the page own vertical scrolling. Nested list scrolling was easy to miss. */
  .notes-workspace .note-list.notice-list {
    max-height: none;
    overflow: visible;
    border-inline: 0;
    border-radius: 0;
  }

  .notes-workspace .note-card.notice-card {
    min-height: 92px;
    padding-inline: 2px;
  }

  .notes-workspace .note-card.notice-card:focus-visible {
    outline-offset: 0;
  }

  .notes-workspace .note-layout.grid.two {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  /* The document editor is a page section on mobile, not a card inside a card. */
  .notes-workspace .note-inspector.panel {
    padding: 16px 2px 0;
    overflow: visible;
    border: 0;
    border-top: 1px solid var(--note-line, #dfe6e2);
    border-radius: 0;
    background: transparent;
  }

  .notes-workspace .note-inspector .hand-note-summary {
    background: #f5f7f6;
  }

  .notes-workspace .note-empty.empty {
    min-height: 210px;
    padding-block: 30px;
    border-block: 1px solid var(--note-line, #dfe6e2);
  }

  .has-note-editor .note-editor-backdrop,
  .has-note-editor .note-editor {
    height: 100dvh;
    min-height: 100dvh;
  }

  .has-note-editor .note-editor-top {
    padding-top: max(7px, env(safe-area-inset-top));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }

  .has-note-editor .note-editor-leading {
    overflow: hidden;
  }

  .has-note-editor .note-title-input {
    width: 100%;
    max-width: min(48vw, 190px);
  }

  .has-note-editor .note-save-status {
    max-width: min(46vw, 190px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .has-note-editor .note-editor-body {
    height: 100%;
  }

  .has-note-editor .note-toolrail {
    scroll-padding-right: max(12px, env(safe-area-inset-right));
    scroll-padding-left: max(12px, env(safe-area-inset-left));
  }

  .has-note-editor .note-tool-inspector {
    scrollbar-width: none;
  }

  .has-note-editor .note-tool-inspector::-webkit-scrollbar {
    display: none;
  }

  .has-note-editor .hand-canvas-stage {
    scrollbar-gutter: auto;
  }

  .has-note-editor .note-editor-readonly .note-editor-body {
    grid-template-rows: minmax(0, 1fr);
  }
}

@media (max-width: 430px) {
  .notes-workspace .note-workspace-metrics {
    border-inline: 0;
    border-radius: 0;
  }

  .notes-workspace .note-stat {
    padding-inline: 5px;
  }

  .notes-workspace .note-toolbar.workspace-section {
    grid-template-columns: minmax(0, 1fr) minmax(104px, 30%);
  }

  .notes-workspace .note-card.notice-card {
    padding-block: 12px;
  }

  .notes-workspace .note-inspector .chips {
    gap: 6px;
  }

  .notes-workspace .note-inspector .chips > button {
    min-height: 42px;
  }

  .notes-workspace .note-inspector .chips > .danger:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .has-note-editor .note-editor-top {
    gap: 4px;
  }

  .has-note-editor .note-title-input {
    max-width: min(45vw, 168px);
  }

  .has-note-editor .note-tool-inspector {
    gap: 7px;
  }

  .has-note-editor .note-colors {
    padding-inline: 6px;
  }
}

@media (max-width: 760px) and (max-height: 600px) {
  .has-note-editor .note-editor-top {
    min-height: calc(52px + env(safe-area-inset-top));
  }

  .has-note-editor .note-workbench {
    grid-template-rows: 46px minmax(0, 1fr);
  }

  .has-note-editor .note-tool-inspector {
    min-height: 46px;
    padding-block: 4px;
  }

  .has-note-editor .note-editor-body:not(:has(.note-toolrail)) {
    grid-template-rows: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .notes-workspace .note-inspector,
  .has-note-editor :where(.note-toolrail, .note-tool-inspector, .hand-canvas-stage) {
    scroll-behavior: auto;
  }
}
