/* =============================================
   Design Tokens — Primer Design System (GitHub)
   ============================================= */

:root {
  /* Colors */
  --primary: #0969DA;
  --primary-hover: #0550AE;
  --primary-soft: #DDF4FF;
  --secondary: #57606A;
  --accent: #8250DF;
  --page-bg: #FFFFFF;
  --card-bg: #FFFFFF;
  --soft-bg: #F3F4F6;
  --hover-bg: #EFF2F5;
  --border: #D0D7DE;
  --text-main: #1F2328;
  --text-body: #24292F;
  --text-muted: #59636E;
  --text-subtle: #818B98;
  --icon-accent: #0969DA;

  /* Semantic colors */
  --success: #1F883D;
  --success-soft: #DAFBE1;
  --warning: #9A6700;
  --warning-soft: #FFF8C5;
  --danger: #CF222E;
  --danger-soft: #FFEBE9;
  --done: #8250DF;
  --done-soft: #FBEFFF;
  --code-bg: #F6F8FA;
  --code-border: #D0D7DE;

  /* Scrollbar */
  --scrollbar-thumb: #D0D7DE;
  --scrollbar-thumb-hover: #94A3B8;

  /* Login panel */
  --login-panel-bg: linear-gradient(145deg, #1E3A5F, #16213e);
  --login-panel-icon: #54AEFF;
  --login-panel-accent-icon: #A78BFA;
  --login-panel-text: #CBD5E1;
  --login-panel-muted: #94A3B8;
  --login-panel-heading: #F8FAFC;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.08);
  --shadow-md: 0 8px 24px rgba(140, 149, 159, 0.18);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Spacing scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 40px;
  --space-3xl: 56px;

  /* Font size scale */
  --text-xs: 0.7rem;
  --text-sm: 0.82rem;
  --text-base: 0.9rem;
  --text-lg: 1.05rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.75rem;
  --text-hero: 2.25rem;

  /* Font weight */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Layout */
  --navbar-height: 56px;
  --sidebar-width: 240px;
  --content-max: 1100px;
  --toc-width: 240px;

  /* Z-index */
  --z-navbar: 100;
  --z-toolbar: 120;
  --z-backdrop: 700;
  --z-floating: 800;
  --z-floating-panel: 820;
  --z-tooltip: 840;
  --z-modal: 900;
  --z-toast: 1000;

  /* Transition */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 0.15s;
  --transition-base: 0.2s;
}

/* =============================================
   Base — reset, layout, scrollbar, transitions
   ============================================= */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

html {
  /*
   * Keep the viewport width stable when navigating between short pages and
   * pages that need a vertical scrollbar. Without this, the root scrollbar
   * appears/disappears and the centered navbar content shifts sideways.
   */
  scrollbar-gutter: stable;
}

@supports not (scrollbar-gutter: stable) {
  html { overflow-y: scroll; }
}

.app-page {
  background: var(--page-bg);
  color: var(--text-body);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

/* --- Scrollbar --- */

::-webkit-scrollbar { width: 4px; height: 4px; }

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 2px; }

::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* --- Transition defaults --- */

.app-card,

.navbar-item,
.tag {
  transition: all var(--transition-base) var(--ease-out);
}

/* ---- Tabs (minimal Bulma-compatible) ---- */

.tabs { margin-bottom: 1.5rem; }

.tabs ul {
  display: flex; align-items: flex-end;
  border-bottom: 1px solid var(--border);
  list-style: none; margin: 0; padding: 0;
}

.tabs li { display: block; }

.tabs a {
  display: flex; align-items: center; gap: 6px;
  padding: 0.5em 1em;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-muted); text-decoration: none;
  font-size: var(--text-sm); cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tabs a:hover { color: var(--text-main); }

.tabs li.is-active a {
  color: var(--primary); border-bottom-color: var(--primary);
  font-weight: 600;
}

.tabs.is-boxed a { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }

.tabs.is-small a { font-size: var(--text-xs); padding: 0.4em 0.8em; }

/* =============================================
   Typography — headings, utilities, helpers
   ============================================= */

.app-title        { font-size: var(--text-3xl); font-weight: var(--weight-bold);     color: var(--text-main); line-height: 1.3; }

.app-section-title { font-size: var(--text-xl); font-weight: var(--weight-semibold); color: var(--text-main); line-height: 1.35; }

.app-subtitle      { font-size: var(--text-base); color: var(--text-muted); line-height: 1.6; max-width: 65ch; }

/* --- Font-size utilities --- */

.text-xs   { font-size: var(--text-xs); }

.text-sm   { font-size: var(--text-sm); }

.text-base { font-size: var(--text-base); }

.text-lg   { font-size: var(--text-lg); }

.text-xl   { font-size: var(--text-xl); }

.text-2xl  { font-size: var(--text-2xl); }

.text-hero { font-size: var(--text-hero); }

/* --- Color utilities --- */

.muted-text  { color: var(--text-muted); }

.subtle-text { color: var(--text-subtle); }

/* =============================================
   Components — cards, panels, actions, utilities
   ============================================= */

/* --- Cards --- */

.app-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base) var(--ease-out),
              transform var(--transition-base) var(--ease-out);
}

.app-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.app-card--static {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

/* --- Panels --- */

.soft-panel {
  background: var(--soft-bg);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}

.toc-panel {
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 14px;
  overflow-y: auto;
}

/* --- Actions --- */

.term-link {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px dashed var(--primary);
  cursor: pointer;
}

.term-link:hover {
  color: var(--primary-hover);
  border-bottom-style: solid;
}

.ai-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-md) var(--space-lg);
}

/* --- Status utilities --- */

.is-success-soft { color: var(--success); background: var(--success-soft); }

.is-warning-soft { color: var(--warning); background: var(--warning-soft); }

.is-danger-soft  { color: var(--danger);  background: var(--danger-soft);  }

.is-done-soft    { color: var(--done);    background: var(--done-soft);    }

/* --- Shared utility patterns --- */

.icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  background: var(--primary-soft);
  flex-shrink: 0;
}

.icon-wrapper--sm  { width: 40px; height: 40px; border-radius: var(--radius-sm); }

.icon-wrapper--md  { width: 48px; height: 48px; border-radius: 10px; }

.icon-wrapper--lg  { width: 52px; height: 52px; border-radius: 12px; }

.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: 20px;
}

.chapter-card {
  display: flex;
  align-items: center;
  padding: var(--space-lg) 28px;
  gap: 20px;
}

.chapter-card-body {
  flex: 1;
  min-width: 0;
}

.chapter-card h3 {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-main);
  margin-bottom: var(--space-xs);
}

.empty-state {
  text-align: center;
  padding: 48px;
}

.empty-state--lg {
  text-align: center;
  padding: 64px;
}

.breadcrumb-nav {
  margin-bottom: var(--space-md);
  font-size: var(--text-sm);
}

.breadcrumb-sep {
  margin: 0 5px;
}

.breadcrumb-current {
  font-weight: var(--weight-semibold);
  color: var(--text-main);
}

.mini-tag-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.mini-tag-row--tight {
  margin-bottom: var(--space-sm);
}

.hero-inner {
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
}

.hero-eyebrow {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--primary);
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  text-transform: uppercase;
}

/* =============================================
   Tree — document outline / sidebar navigation
   ============================================= */

.tree-node-link {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 5px 10px;
  padding-left: calc(12px + var(--tree-depth, 0) * 18px);
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  line-height: 1.6;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-base) var(--ease-out),
              color var(--transition-base) var(--ease-out);
  color: var(--text-body);
  background: transparent;
}

.tree-node-link:hover {
  background: var(--hover-bg);
  color: var(--text-main);
}

.tree-node-link.is-active {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: var(--weight-semibold);
  position: relative;
}

.tree-node-link.is-active::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 2px;
  background: var(--primary);
}

/* =============================================
   Doc — document rendering styles
   Adapted from tiptap-ui-components/tiptap-node/*.scss
   ============================================= */

/* ---- Spacing knobs (change these to adjust everything) ---- */

:root {
  --doc-para-gap: 0.35rem;       /* paragraph spacing */
  --doc-block-gap: 0.5rem;       /* list / blockquote / code-block / image spacing */
  --doc-line-height: 1.55;       /* body line-height */
}

/* =============================================
   RESET — normalize browser defaults for tiptap output
   ============================================= */

.doc-content,
.simple-editor-content .tiptap.ProseMirror {
  /* headings */
  h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; margin: 0; }
  /* lists */
  ol, ul { list-style: none; margin: 0; padding: 0; }
  /* block elements */
  blockquote, figure, p, pre { margin: 0; }
  /* images */
  img { max-width: 100%; height: auto; display: inline-block; vertical-align: text-bottom; }
  /* links */
  a { color: inherit; text-decoration: inherit; }
}

/* =============================================
   COMMON PROSE STYLES (both editor + viewer)
   ============================================= */

.doc-content,
.simple-editor-content .tiptap.ProseMirror {
  font-size: 1.0625rem;
  line-height: var(--doc-line-height);
  color: var(--text-body);
  outline: none;

  /* ---- Paragraph ---- */
  p:not(:first-child) {
    margin-top: var(--doc-para-gap);
  }
  p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    float: left;
    pointer-events: none;
    height: 0;
  }

  /* ---- Headings ---- */
  h1, h2, h3, h4 {
    position: relative;
    color: inherit;
    font-style: inherit;
  }
  h1:first-child, h2:first-child, h3:first-child, h4:first-child { margin-top: 0; }

  h1 { font-size: 2em; font-weight: 700; margin-top: 1.5em; }
  h2 { font-size: 1.5em; font-weight: 700; margin-top: 1.25em; }
  h3 { font-size: 1.25em; font-weight: 600; margin-top: 1em; }
  h4 { font-size: 1.1em; font-weight: 600; margin-top: 0.75em; }

  /* ---- Links ---- */
  a {
    color: var(--primary);
    text-decoration: underline;
  }

  /* ---- Blockquote ---- */
  blockquote {
    position: relative;
    padding-left: 1em;
    padding-top: 0.375em;
    padding-bottom: 0.375em;
    margin: var(--doc-block-gap) 0;

    p { margin-top: 0; }

    &::before {
      position: absolute;
      bottom: 0; left: 0; top: 0;
      height: 100%;
      width: 0.25em;
      background-color: var(--text-main);
      content: "";
      border-radius: 0;
    }
  }

  /* ---- Inline Code ---- */
  code {
    background-color: rgba(175, 184, 193, 0.20);
    color: var(--text-main);
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875em;
    line-height: 1.4;
    border-radius: 6px;
    padding: 0.1em 0.2em;
  }

  /* ---- Code Block ---- */
  pre {
    background-color: var(--code-bg);
    color: var(--text-main);
    border: 1px solid var(--code-border);
    margin-top: var(--doc-block-gap);
    margin-bottom: var(--doc-block-gap);
    padding: 0.75rem 1rem;
    font-size: 1em;
    border-radius: 6px;

    code {
      background-color: transparent;
      border: none;
      border-radius: 0;
      color: inherit;
    }
  }

  /* ---- Lists ---- */
  ol, ul {
    margin-top: var(--doc-block-gap);
    margin-bottom: var(--doc-block-gap);
    padding-left: 1.5rem;

    &:first-child { margin-top: 0; }
    &:last-child { margin-bottom: 0; }

    ol, ul {
      margin-top: 0;
      margin-bottom: 0;
    }
  }
  li p { margin-top: 0; line-height: 1.6; }

  /* Ordered list nesting */
  ol {
    list-style: decimal;
    ol { list-style: lower-alpha;
      ol { list-style: lower-roman; }
    }
  }

  /* Unordered list nesting */
  ul:not([data-type="taskList"]) {
    list-style: disc;
    ul { list-style: circle;
      ul { list-style: square; }
    }
  }

  /* ---- Task List ---- */
  ul[data-type="taskList"] {
    padding-left: 0.25em;

    li {
      display: flex;
      flex-direction: row;
      align-items: flex-start;

      &:not(:has(> p:first-child)) { list-style-type: none; }

      &[data-checked="true"] {
        > div > p {
          opacity: 0.5;
          text-decoration: line-through;
          span { text-decoration: line-through; }
        }
      }

      label {
        position: relative;
        padding-top: 0.375rem;
        padding-right: 0.5rem;

        input[type="checkbox"] {
          position: absolute;
          opacity: 0;
          width: 0; height: 0;
        }

        span {
          display: block;
          width: 1em; height: 1em;
          border: 1px solid var(--border);
          border-radius: 4px;
          position: relative;
          cursor: pointer;
          background-color: var(--soft-bg);
          transition: background-color 80ms ease-out, border-color 80ms ease-out;

          &::before {
            content: "";
            position: absolute;
            left: 50%; top: 50%;
            transform: translate(-50%, -50%);
            width: 0.75em; height: 0.75em;
            background-color: #fff;
            opacity: 0;
            -webkit-mask: url("data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22currentColor%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20d%3D%22M21.4142%204.58579C22.1953%205.36683%2022.1953%206.63317%2021.4142%207.41421L10.4142%2018.4142C9.63317%2019.1953%208.36684%2019.1953%207.58579%2018.4142L2.58579%2013.4142C1.80474%2012.6332%201.80474%2011.3668%202.58579%2010.5858C3.36683%209.80474%204.63317%209.80474%205.41421%2010.5858L9%2014.1716L18.5858%204.58579C19.3668%203.80474%2020.6332%203.80474%2021.4142%204.58579Z%22%20fill%3D%22currentColor%22%2F%3E%3C%2Fsvg%3E")
              center/contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22currentColor%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20d%3D%22M21.4142%204.58579C22.1953%205.36683%2022.1953%206.63317%2021.4142%207.41421L10.4142%2018.4142C9.63317%2019.1953%208.36684%2019.1953%207.58579%2018.4142L2.58579%2013.4142C1.80474%2012.6332%201.80474%2011.3668%202.58579%2010.5858C3.36683%209.80474%204.63317%209.80474%205.41421%2010.5858L9%2014.1716L18.5858%204.58579C19.3668%203.80474%2020.6332%203.80474%2021.4142%204.58579Z%22%20fill%3D%22currentColor%22%2F%3E%3C%2Fsvg%3E")
              center/contain no-repeat;
          }
        }

        input[type="checkbox"]:checked + span {
          background: var(--text-main);
          border-color: var(--text-main);
          &::before { opacity: 1; }
        }
      }

      div {
        flex: 1 1 0%;
        min-width: 0;
      }
    }
  }

  /* ---- Images ---- */
  img:not([data-type="emoji"] img) {
    max-width: 100%;
    height: auto;
    display: inline-block;
    vertical-align: text-bottom;
    margin: var(--doc-block-gap) 0.35em 0 0;
    border-radius: 4px;
  }

  /* ---- Horizontal Rule ---- */
  hr {
    border: none;
    height: 1px;
    background-color: var(--border);
    margin-top: var(--doc-block-gap);
    margin-bottom: var(--doc-block-gap);
  }

  /* ---- Selection ---- */
  ::selection {
    background-color: rgba(157, 138, 255, 0.2);
  }

  /* ---- Highlight / Mark ---- */
  mark {
    padding: 0 2px;
    border-radius: 2px;
  }

  /* ---- Table ---- */
  table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
    margin: var(--doc-block-gap) 0;
    overflow: hidden;
  }
  td, th {
    min-width: 50px;
    border: 1px solid var(--border);
    padding: 6px 10px;
    vertical-align: top;
    box-sizing: border-box;
    position: relative;
  }
  th {
    font-weight: 600;
    text-align: left;
    background-color: var(--soft-bg);
  }
  .selectedCell::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(99, 145, 255, 0.12);
    pointer-events: none;
    z-index: 2;
  }
  .column-resize-handle {
    position: absolute;
    right: -2px; top: 0; bottom: 0;
    width: 4px;
    background-color: var(--primary);
    pointer-events: none;
  }
}

/* =============================================
   Doc editor — Tiptap toolbar and editor chrome
   ============================================= */

:root {
  --tt-toolbar-height: 44px;
  --color-highlight-green: #DCFCE7;
  --color-highlight-blue: #DBEAFE;
  --color-highlight-red: #FEE2E2;
  --color-highlight-purple: #F3E8FF;
  --color-highlight-yellow: #FEF9C3;
  --color-highlight-orange: #FFEDD5;
  --color-highlight-pink: #FCE7F3;
  --color-highlight-gray: #F3F4F6;
}

.tiptap-toolbar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.tiptap-toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}

.tiptap-toolbar-group:empty { display: none; }

.tiptap-toolbar-group:empty + .tiptap-separator,
.tiptap-separator + .tiptap-toolbar-group:empty { display: none; }

.tiptap-toolbar[data-variant="fixed"] {
  position: sticky;
  top: 0;
  z-index: var(--z-toolbar);
  width: 100%;
  min-height: var(--tt-toolbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--soft-bg);
  padding: 0 0.5rem;
  overflow-x: auto;
  overflow-y: visible;
}

.tiptap-toolbar[data-variant="fixed"]::-webkit-scrollbar { display: none; }

.tiptap-separator {
  flex-shrink: 0;
  background-color: var(--border);
}

.tiptap-separator[data-orientation="vertical"] { height: 1.5rem; width: 1px; }

.tiptap-separator[data-orientation="horizontal"] { height: 1px; width: 100%; margin: 0.5rem 0; }

.tiptap-spacer { flex: 1; }

.tiptap-button {
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.15;
  height: 2rem;
  min-width: 2rem;
  border: none;
  padding: 0.5rem;
  gap: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
  background-color: transparent;
  color: var(--text-body);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}

.tiptap-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.tiptap-button:hover:not([disabled]) {
  background-color: var(--soft-bg);
  color: var(--text-main);
}

.tiptap-button:active:not([disabled]) { transform: translateY(1px); }

.tiptap-button[data-active-state="on"]:not([disabled]) {
  background-color: var(--soft-bg);
  color: var(--primary);
  font-weight: 600;
}

.tiptap-button[data-active-state="on"]:hover:not([disabled]) { background-color: var(--soft-bg); }

.tiptap-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.tiptap-button-text {
  padding: 0 0.125rem;
  flex-grow: 1;
  text-align: left;
  line-height: 1.5rem;
}

.tiptap-button-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.tiptap-icon--flip-y { transform: scaleY(-1); }

.tiptap-icon--flip-x { transform: scaleX(-1); }

.tiptap-button-dropdown-small {
  width: 0.625rem;
  height: 0.625rem;
  flex-shrink: 0;
}

.tiptap-button-dropdown-arrows {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
}

.tiptap-button-group {
  position: relative;
  display: flex;
  vertical-align: middle;
}

.tiptap-button-group[data-orientation="vertical"] {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-width: max-content;
}

.tiptap-button-group[data-orientation="vertical"] > .tiptap-button { width: 100%; }

.tiptap-button-group[data-orientation="horizontal"] {
  gap: 0.125rem;
  flex-direction: row;
  align-items: center;
}

.tiptap-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  z-index: var(--z-floating);
  min-width: 160px;
  outline: none;
}

.tiptap-popover { outline: none; }

.tiptap-floating {
  position: fixed;
  top: var(--floating-top);
  left: var(--floating-left);
  z-index: var(--z-floating);
  margin-top: 0;
}

.tiptap-card {
  --card-padding: 0.375rem;
  border-radius: calc(0.375rem + 0.75rem);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  outline: none;
  align-items: center;
  position: relative;
  min-width: 0;
}

.tiptap-card--floating { box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15); }

.tiptap-card-body {
  padding: 0.375rem;
  flex: 1 1 auto;
  overflow-y: auto;
}

.tiptap-card-item-group {
  position: relative;
  display: flex;
  vertical-align: middle;
  min-width: max-content;
}

.tiptap-card-item-group[data-orientation="vertical"] {
  flex-direction: column;
  justify-content: center;
}

.tiptap-card-item-group[data-orientation="horizontal"] {
  gap: 0.25rem;
  flex-direction: row;
  align-items: center;
}

.tiptap-button-highlight {
  position: relative;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0 -0.175rem;
  border-radius: 9999px;
  background-color: var(--highlight-color);
  transition: transform 0.2s ease;
}

.tiptap-button-highlight::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  border-radius: inherit;
  box-sizing: border-box;
  border: 1px solid var(--highlight-color);
  filter: brightness(95%);
  mix-blend-mode: multiply;
}

.tt-link-popover-field {
  display: flex;
  align-items: center;
}

.tt-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text-main);
  outline: none;
  min-width: 200px;
}

.tt-input:focus { border-color: var(--primary); }

.tt-backdrop { position: fixed; inset: 0; z-index: var(--z-backdrop); }

.tt-dropdown { position: relative; display: inline-flex; }

.tt-popover { display: inline-flex; }

.simple-editor-wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
}

.simple-editor-content {
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.simple-editor-content .tiptap.ProseMirror.simple-editor {
  flex: 1;
  padding: 2rem 0.75rem 30vh;
}

.tt-tooltip {
  position: fixed;
  top: var(--floating-top);
  left: var(--floating-left);
  transform: translate(-50%, -100%);
  padding: 4px 10px;
  background: #1F2328;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-tooltip);
  font-family: inherit;
}

.tiptap.ProseMirror .resizable-image-node {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: normal;
  vertical-align: text-bottom;
  margin: var(--doc-block-gap) 0.35em 0 0;
}

.tiptap.ProseMirror .resizable-image-node img {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: pointer;
  border-radius: 4px;
}

.tiptap.ProseMirror .resizable-image-node.is-selected img {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.image-resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  display: none;
  z-index: 2;
}

.resizable-image-node.is-selected .image-resize-handle { display: block; }

.image-resize-handle--nw { top: -6px; left: -6px; cursor: nwse-resize; }

.image-resize-handle--ne { top: -6px; right: -6px; cursor: nesw-resize; }

.image-resize-handle--sw { bottom: -6px; left: -6px; cursor: nesw-resize; }

.image-resize-handle--se { bottom: -6px; right: -6px; cursor: nwse-resize; }

@media screen and (max-width: 480px) {
  .simple-editor-content .tiptap.ProseMirror.simple-editor {
    padding: 1rem 1rem 30vh;
  }
}

/* =============================================
   Course manager
   ============================================= */

.pw-admin {
  display: flex;
  position: absolute;
  top: var(--navbar-height, 52px);
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--page-bg);
  font-size: 14px;
  overflow: hidden;
}

.pw-mobile-unsupported {
  display: none;
}

.pw-content {
  flex: 1;
  min-width: 0;
  padding: 24px 24px 0;
  margin-left: 180px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pw-sidebar {
  position: fixed;
  top: calc(var(--navbar-height, 52px) + 16px);
  left: 16px;
  width: 148px;
  background: var(--card-bg);
  border-radius: 10px;
  padding: 20px 14px;
  z-index: var(--z-floating-panel);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.pw-sidebar__name {
  font-size: 13px;
  font-weight: var(--weight-bold);
  color: var(--text-main);
  margin-bottom: 12px;
}

.pw-sidebar__menu {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.pw-sidebar__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: none;
  background: none;
  color: var(--text-body);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 10px;
  text-align: left;
  font-weight: 400;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}

.pw-sidebar__item:hover {
  background: var(--soft-bg);
}

.pw-sidebar__item.is-active {
  background: var(--soft-bg);
  color: var(--text-body);
  font-weight: 500;
  box-shadow: none;
  position: relative;
}

.pw-sidebar__item.is-active::before {
  content: "";
  width: 3px;
  height: 18px;
  border-radius: 999px;
  background: var(--primary);
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.pw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 36px;
}

.pw-header__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-sm);
}

.pw-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  min-width: 0;
}

.pw-back:hover {
  color: var(--primary);
}

.pw-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 400;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.12s;
  white-space: nowrap;
}

.pw-btn:hover {
  filter: brightness(1.06);
}

.pw-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.pw-btn--primary {
  background: var(--primary);
  color: #fff;
}

.pw-btn--outline {
  background: var(--card-bg);
  color: var(--text-body);
  border: 1px solid var(--border);
}

.pw-btn--danger {
  border-color: color-mix(in srgb, var(--danger) 36%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.pw-btn--danger:hover {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, var(--card-bg));
}

.pw-card {
  background: var(--card-bg);
  border-radius: 10px;
  box-shadow: none;
  border: none;
  overflow: hidden;
}

.pw-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
}

.pw-empty h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.pw-empty__icon {
  opacity: 0.14;
}

.pw-doc-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 24px;
}

.pw-doc-split {
  display: flex;
  gap: 16px;
  align-items: stretch;
  flex: 1;
  overflow: hidden;
}

.pw-doc-tree {
  width: 220px;
  flex-shrink: 0;
  display: flex;
}

.pw-doc-tree__card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.pw-doc-tree__header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pw-doc-tree__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.pw-doc-tree__body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.pw-doc-tree__empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.pw-doc-tree__actions {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.pw-doc-tree__btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 6px;
}

.pw-doc-tree__btn:hover:not(:disabled) {
  background: var(--soft-bg);
  color: var(--primary);
}

.pw-doc-tree__btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.pw-doc-editor {
  flex: 1;
  min-width: 0;
  display: flex;
}

.pw-doc-editor__card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.pw-doc-editor__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
  flex-shrink: 0;
}

.pw-doc-editor__delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.1s, background 0.1s;
}

.pw-doc-editor__delete:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.pw-doc-editor__title-input {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  border: none;
  border-radius: 0;
  padding: 0;
  outline: none;
  font-family: inherit;
  background: transparent;
  width: 100%;
}

.pw-doc-editor__save-status {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.pw-doc-editor__save-status.is-saving,
.pw-doc-editor__save-status.is-dirty {
  color: var(--text-muted);
}

.pw-doc-editor__save-status.is-saved {
  color: var(--success);
}

.pw-doc-editor__save-status.is-error {
  color: var(--danger);
}

.pw-doc-editor__info--dim {
  font-size: 14px;
  color: #646a73;
}

.pw-doc-editor__actions {
  display: flex;
  gap: 8px;
}

.pw-doc-editor__body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .pw-admin {
    display: none;
  }

  .pw-mobile-unsupported {
    display: flex;
    min-height: calc(100dvh - var(--navbar-height));
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--page-bg);
  }

  .pw-mobile-unsupported__panel {
    width: min(360px, 100%);
    padding: 28px 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    box-shadow: var(--shadow-sm);
    text-align: center;
  }

  .pw-mobile-unsupported__icon {
    color: var(--primary);
    margin-bottom: 14px;
  }

  .pw-mobile-unsupported h1 {
    margin: 0 0 10px;
    font-size: var(--text-xl);
    color: var(--text-main);
  }

  .pw-mobile-unsupported p {
    margin: 0 0 18px;
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: 1.7;
  }

  .pw-mobile-unsupported .pw-btn {
    justify-content: center;
  }
}

/* =============================================
   Responsive — media queries
   ============================================= */

@media (max-width: 768px) {
  .app-container { padding: 0 var(--space-md); }
  .app-title     { font-size: var(--text-2xl); }
  .text-hero     { font-size: var(--text-2xl); }

  /* Course detail */
  .course-page { padding: var(--space-lg) 0 44px; }
  .course-page .breadcrumb-nav { margin-bottom: var(--space-sm); }
  .course-page .course-header .course-header__top {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-md);
  }
  .course-page .course-header__title { font-size: 1.35rem; }
  .course-page .course-enroll-btn {
    width: 100%;
    justify-content: center;
  }
  .course-page .course-tabs {
    overflow-x: auto;
    margin-bottom: 20px;
    padding-bottom: 2px;
  }
  .course-page .course-tabs ul {
    flex-wrap: nowrap;
    min-width: max-content;
  }
  .course-page .course-tabs__link {
    padding: var(--space-sm) 14px;
  }
  .course-page .course-doc-grid.course-doc-grid {
    grid-template-columns: 1fr;
  }
  .course-page .course-doc-card.course-doc-card {
    padding: 22px 18px;
  }

  /* Reader */
  body .node-page {
    padding: var(--space-md) var(--space-md) 0;
    overflow-y: auto;
  }
  body .node-page .node-layout {
    height: auto;
    min-height: 100%;
  }
  body .node-page .node-body {
    flex-direction: column;
    gap: 12px;
    overflow: visible;
  }
  body .node-page .node-sidebar {
    width: 100%;
    max-height: 34dvh;
    padding: 0;
    border-radius: var(--radius-md);
  }
  body .node-page .node-toc {
    max-height: 34dvh;
    padding: 10px;
  }
  body .node-page .node-toc__heading {
    margin-bottom: 8px;
  }
  body .node-page .node-content {
    display: block;
    overflow: visible;
    padding: 0 0 var(--space-lg);
  }
  body .node-page .node-header {
    margin-bottom: var(--space-md);
  }
  body .node-page .node-title {
    font-size: 1.3rem;
  }
  body .node-page .node-content-card {
    padding: 20px 16px;
    margin-bottom: 20px;
    overflow: visible;
  }
  body .node-page .node-section-index__item.node-section-index__item {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
  body .node-page .node-ai-panel.node-ai-panel {
    left: 50% !important;
    top: auto !important;
    bottom: 14px;
    width: calc(100vw - 32px) !important;
    max-height: min(50dvh, 420px) !important;
    transform: translateX(-50%);
  }
}

@media (max-width: 480px) {
  .app-toast-stack {
    left: 12px;
    right: 12px;
  }
  .app-toast-item {
    max-width: none;
  }
}

.app-confirm__overlay[data-v-2507764e] {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 24, 43, 0.48);
  backdrop-filter: blur(2px);
}
.app-confirm[data-v-2507764e] {
  box-sizing: border-box;
  width: min(440px, 100%);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-bg);
  box-shadow: 0 24px 70px rgba(7, 24, 43, 0.28);
}
.app-confirm__header[data-v-2507764e] {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  padding: 22px 22px 16px;
}
.app-confirm__icon[data-v-2507764e] {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 11px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 11%, white);
}
.app-confirm--primary .app-confirm__icon[data-v-2507764e] {
  color: var(--primary);
  background: var(--primary-soft);
}
.app-confirm__header h2[data-v-2507764e] {
  margin: 1px 0 6px;
  color: var(--text-main);
  font-size: 17px;
  font-weight: 650;
}
.app-confirm__header p[data-v-2507764e] {
  margin: 0;
  color: var(--text-body);
  font-size: 14px;
  line-height: 1.55;
}
.app-confirm__close[data-v-2507764e] {
  display: grid;
  padding: 5px;
  border: 0;
  border-radius: 7px;
  place-items: center;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
}
.app-confirm__close[data-v-2507764e]:hover {
  color: var(--text-main);
  background: var(--soft-bg);
}
.app-confirm__description[data-v-2507764e] {
  margin: 0 22px 18px 72px;
  padding: 11px 13px;
  border-radius: 9px;
  color: var(--text-body);
  background: var(--soft-bg);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}
.app-confirm__actions[data-v-2507764e] {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px 20px;
  border-top: 1px solid var(--border);
}
.app-confirm__button[data-v-2507764e] {
  min-width: 84px;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.app-confirm__button--cancel[data-v-2507764e] {
  border-color: var(--border);
  color: var(--text-body);
  background: var(--card-bg);
}
.app-confirm__button--cancel[data-v-2507764e]:hover {
  background: var(--hover-bg);
}
.app-confirm__button--confirm[data-v-2507764e] {
  background: var(--danger);
  color: #fff;
}
.app-confirm--primary .app-confirm__button--confirm[data-v-2507764e] {
  background: var(--primary);
}
.app-confirm__button[data-v-2507764e]:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}
.app-confirm-enter-active[data-v-2507764e],
.app-confirm-leave-active[data-v-2507764e] {
  transition: opacity 0.18s ease;
}
.app-confirm-enter-active .app-confirm[data-v-2507764e],
.app-confirm-leave-active .app-confirm[data-v-2507764e] {
  transition: transform 0.2s ease, opacity 0.18s ease;
}
.app-confirm-enter-from[data-v-2507764e],
.app-confirm-leave-to[data-v-2507764e],
.app-confirm-enter-from .app-confirm[data-v-2507764e],
.app-confirm-leave-to .app-confirm[data-v-2507764e] {
  opacity: 0;
}
.app-confirm-enter-from .app-confirm[data-v-2507764e],
.app-confirm-leave-to .app-confirm[data-v-2507764e] {
  transform: translateY(8px) scale(0.98);
}
@media (max-width: 520px) {
.app-confirm__description[data-v-2507764e] {
    margin-left: 22px;
}
}

.app-toast-stack {
  position: fixed; top: 12px; right: 16px; z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: 8px;
}
.app-toast-item {
  padding: 10px 18px; border-radius: 10px;
  font-size: 0.875rem; font-weight: 500; font-family: inherit;
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  min-width: 160px; max-width: 320px;
}
.app-toast--success { background: var(--success); color: #fff;
}
.app-toast--error   { background: var(--danger); color: #fff;
}
.toast-enter-active { transition: all 0.25s var(--ease-out);
}
.toast-leave-active { transition: all 0.18s var(--ease-out);
}
.toast-enter-from { opacity: 0; transform: translateY(-12px);
}
.toast-leave-to   { opacity: 0; transform: translateX(20px);
}
