/* ==========================================================================
   INFERISE WIKI STYLESHEET
   Adapted from ../www/prod/css/inferise.css
   Anti-AI Web Aesthetics • Editorial UX • Dynamic Light/Dark Theming
   ========================================================================== */

:root {
  /* Editorial Typography from ../www */
  --font-serif: "Newsreader", Charter, "Bitstream Charter", "Sitka Text", Cambria, serif;
  --font-sans: "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", Menlo, Consolas, "Courier New", monospace;

  /* Raw Light Mode Tokens (Editorial Warm Paper from ../www) */
  --bg-canvas-light: #FAF9F6;
  --bg-surface-light: #FFFFFF;
  --bg-subtle-light: #F4F2EB;
  --bg-hover-light: #EBE7DC;

  --text-primary-light: #14171A;
  --text-secondary-light: #545C66;
  --text-muted-light: #7E8792;

  --border-color-light: #E4E0D6;
  --border-strong-light: #CECABF;

  --brand-primary-light: #1D75BC;
  --brand-hover-light: #165F99;
  --brand-primary-text-light: #FFFFFF;
  --brand-soft-light: rgba(29, 117, 188, 0.10);
  --brand-border-light: rgba(29, 117, 188, 0.28);

  /* Raw Dark Mode Tokens (Approachable Dark from ../www) */
  --bg-canvas-dark: #131619;
  --bg-surface-dark: #181C20;
  --bg-subtle-dark: #21262C;
  --bg-hover-dark: #282E36;

  --text-primary-dark: #F2F0EB;
  --text-secondary-dark: #A0A7AE;
  --text-muted-dark: #6B727A;

  --border-color-dark: #262B32;
  --border-strong-dark: #363D47;

  --brand-primary-dark: #E85D26;
  --brand-hover-dark: #F26F3A;
  --brand-primary-text-dark: #FFFFFF;
  --brand-soft-dark: rgba(232, 93, 38, 0.14);
  --brand-border-dark: rgba(232, 93, 38, 0.35);

  --danger-light: #D64545;
  --danger-dark: #E55353;
  --success-light: #2E9E67;
  --success-dark: #35B276;

  --scrollbar-thumb-light: #B3ADA0;
  --scrollbar-thumb-dark: #4B5462;
  --scrollbar-track-light: #F4F2EB;
  --scrollbar-track-dark: #131619;

  --radius-xs: 2px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --header-height: 64px;

  /* Default Light Assignments */
  --bg-canvas: var(--bg-canvas-light);
  --bg-surface: var(--bg-surface-light);
  --bg-subtle: var(--bg-subtle-light);
  --bg-hover: var(--bg-hover-light);
  --text-primary: var(--text-primary-light);
  --text-secondary: var(--text-secondary-light);
  --text-muted: var(--text-muted-light);
  --border-color: var(--border-color-light);
  --border-strong: var(--border-strong-light);
  --brand-primary: var(--brand-primary-light);
  --brand-hover: var(--brand-hover-light);
  --brand-primary-text: var(--brand-primary-text-light);
  --brand-soft: var(--brand-soft-light);
  --brand-border: var(--brand-border-light);
  --danger: var(--danger-light);
  --success: var(--success-light);
  --scrollbar-thumb: var(--scrollbar-thumb-light);
  --scrollbar-track: var(--scrollbar-track-light);

  /* Fallback for browsers without light-dark() support */
  @media (prefers-color-scheme: dark) {
    --bg-canvas: var(--bg-canvas-dark);
    --bg-surface: var(--bg-surface-dark);
    --bg-subtle: var(--bg-subtle-dark);
    --bg-hover: var(--bg-hover-dark);
    --text-primary: var(--text-primary-dark);
    --text-secondary: var(--text-secondary-dark);
    --text-muted: var(--text-muted-dark);
    --border-color: var(--border-color-dark);
    --border-strong: var(--border-strong-dark);
    --brand-primary: var(--brand-primary-dark);
    --brand-hover: var(--brand-hover-dark);
    --brand-primary-text: var(--brand-primary-text-dark);
    --brand-soft: var(--brand-soft-dark);
    --brand-border: var(--brand-border-dark);
    --danger: var(--danger-dark);
    --success: var(--success-dark);
    --scrollbar-thumb: var(--scrollbar-thumb-dark);
    --scrollbar-track: var(--scrollbar-track-dark);
  }

  @supports (color: light-dark(white, black)) {
    --bg-canvas: light-dark(var(--bg-canvas-light), var(--bg-canvas-dark));
    --bg-surface: light-dark(var(--bg-surface-light), var(--bg-surface-dark));
    --bg-subtle: light-dark(var(--bg-subtle-light), var(--bg-subtle-dark));
    --bg-hover: light-dark(var(--bg-hover-light), var(--bg-hover-dark));
    --text-primary: light-dark(var(--text-primary-light), var(--text-primary-dark));
    --text-secondary: light-dark(var(--text-secondary-light), var(--text-secondary-dark));
    --text-muted: light-dark(var(--text-muted-light), var(--text-muted-dark));
    --border-color: light-dark(var(--border-color-light), var(--border-color-dark));
    --border-strong: light-dark(var(--border-strong-light), var(--border-strong-dark));
    --brand-primary: light-dark(var(--brand-primary-light), var(--brand-primary-dark));
    --brand-hover: light-dark(var(--brand-hover-light), var(--brand-hover-dark));
    --brand-primary-text: light-dark(var(--brand-primary-text-light), var(--brand-primary-text-dark));
    --brand-soft: light-dark(var(--brand-soft-light), var(--brand-soft-dark));
    --brand-border: light-dark(var(--brand-border-light), var(--brand-border-dark));
    --danger: light-dark(var(--danger-light), var(--danger-dark));
    --success: light-dark(var(--success-light), var(--success-dark));
    --scrollbar-thumb: light-dark(var(--scrollbar-thumb-light), var(--scrollbar-thumb-dark));
    --scrollbar-track: light-dark(var(--scrollbar-track-light), var(--scrollbar-track-dark));
  }

  color-scheme: light dark;
  accent-color: var(--brand-primary);
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;

  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
  }
  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
  }
}

@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
  }
  ::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background-color: var(--brand-primary);
  color: #FFFFFF;
}

[hidden] {
  display: none !important;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.2;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.kicker {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--brand-primary);
  display: inline-block;
  margin-bottom: 0.35rem;
}

/* Light / Dark Official Inferise Logo Switching */
.brand-logo {
  height: 26px;
  width: auto;
  display: block;
}

.logo-dark { display: none; }
.logo-light { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .logo-dark {
    display: block;
  }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .logo-light {
    display: none;
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .logo-dark {
  display: block;
}
:root:has(> head > meta[name="color-scheme"][content="dark"]) .logo-light {
  display: none;
}
:root:has(> head > meta[name="color-scheme"][content="light"]) .logo-dark {
  display: none;
}
:root:has(> head > meta[name="color-scheme"][content="light"]) .logo-light {
  display: block;
}

.wiki-divider {
  width: 1px;
  height: 20px;
  background-color: var(--border-strong);
  display: inline-block;
}

.brand-wiki-tag,
.brand-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-primary);
}

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 36px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 22px;
}

.auth-logo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  font-size: 0.86rem;
  margin-bottom: 22px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-footnote {
  margin: 22px 0 0;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: center;
}

/* App Shell & Header (matching ../www site-header) */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--header-height);
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  flex-shrink: 0;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-left: 6px;
}

.breadcrumbs a {
  color: var(--text-secondary);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--brand-primary);
}

.topbar-center {
  flex: 1;
  max-width: 520px;
}

.search-trigger-wrap {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 8px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.search-input:focus {
  outline: 1px solid var(--brand-primary);
  border-color: var(--brand-primary);
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  max-height: 380px;
  overflow-y: auto;
  z-index: 60;
}

.search-result-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
}

.search-result-item:hover {
  background: var(--bg-subtle);
}

.search-result-meta {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  font-size: 0.82rem;
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-xs);
  background: var(--brand-primary);
  color: var(--brand-primary-text);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Workspace Layout Grid */
.workspace-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) auto;
  min-height: calc(100vh - var(--header-height));
}

.workspace-grid.sidebar-collapsed {
  grid-template-columns: 0px minmax(0, 1fr) auto;
}

.workspace-grid.sidebar-collapsed .sidebar {
  display: none;
}

/* Sidebar */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  max-height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  scrollbar-width: thin;
}

.sidebar-section {
  padding: 14px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-tree-section {
  flex: 1;
  border-bottom: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sidebar-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.nav-list,
.spaces-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item,
.space-item-btn {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  font-size: 0.9rem;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.nav-item:hover,
.space-item-btn:hover {
  background: var(--bg-subtle);
}

.nav-item.active,
.space-item-btn.active {
  background: var(--brand-soft);
  border-color: var(--brand-border);
  color: var(--brand-primary);
  font-weight: 600;
}

.count-pill {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: var(--radius-xs);
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.tree-filter-wrap {
  margin-bottom: 8px;
}

.tree-filter-input {
  width: 100%;
  padding: 6px 9px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-color);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: 0.82rem;
}

/* Hierarchical Folder & Page Tree */
.page-tree {
  font-size: 0.86rem;
}

.tree-folder {
  margin: 3px 0;
}

.tree-folder > summary {
  cursor: pointer;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
}

.tree-folder > summary:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.tree-children {
  padding-left: 14px;
  border-left: 1px solid var(--border-color);
  margin-left: 8px;
}

.tree-page-link {
  display: block;
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-page-link:hover {
  background: var(--bg-subtle);
}

.tree-page-link.active {
  background: var(--brand-soft);
  color: var(--brand-primary);
  font-weight: 600;
}

/* Main Canvas */
.main-canvas {
  padding: 32px 40px;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.dashboard-hero {
  position: relative;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 28px 32px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.dashboard-hero-text {
  max-width: 660px;
  position: relative;
  z-index: 2;
}

.dashboard-hero-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}

.home-custom-card {
  margin-bottom: 24px;
}

.dashboard-hero h1 {
  margin: 4px 0 8px;
  font-size: 2.1rem;
}

.dashboard-watermark {
  position: absolute;
  right: -36px;
  top: 50%;
  transform: translateY(-50%);
  width: 210px;
  height: 210px;
  opacity: 0.06;
  pointer-events: none;
}

.spaces-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.space-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.space-card:hover {
  border-color: var(--brand-primary);
  transform: translateY(-1px);
}

.space-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.space-card-title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.15rem;
}

.space-card-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0;
}

.dashboard-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 20px;
}

.card-header h2 {
  margin: 2px 0 14px;
  font-size: 1.35rem;
}

.page-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.page-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}

.page-list-item:last-child {
  border-bottom: none;
}

.page-list-link {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
}

.page-list-link:hover {
  color: var(--brand-primary);
}

/* Page View */
.page-view {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 36px 42px;
}

.page-header {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 20px;
  margin-bottom: 26px;
}

.page-meta-top {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.space-badge {
  font-family: var(--font-mono);
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  color: var(--brand-primary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: 0.7rem;
}

.version-badge {
  font-family: var(--font-mono);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  font-weight: 600;
}

.admin-pill,
.visibility-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.admin-pill,
.visibility-badge.private {
  background: rgba(232, 93, 38, 0.14);
  border-color: rgba(232, 93, 38, 0.4);
  color: var(--brand-primary);
}

.lock-indicator {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--brand-primary);
  margin-left: 6px;
}

.acl-admins-banner {
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  background: var(--brand-soft);
  border: 1px solid var(--brand-border);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.acl-rule-form {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  background: var(--bg-canvas);
  padding: 16px;
}

.acl-rule-form h3,
.acl-rules-table-wrap h3 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.acl-form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.acl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.acl-table th,
.acl-table td {
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
}

.acl-table th {
  background: var(--bg-subtle);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.page-path-code {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.page-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  margin: 0;
  font-size: 2.35rem;
  line-height: 1.18;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.page-byline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 12px;
}

.comments-jump-link {
  color: var(--brand-primary);
  text-decoration: none;
  font-weight: 500;
}

.tags-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.tag-chip {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

/* Confluence WYSIWYG + Markdown Editor */
.editor-section {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-canvas);
  padding: 18px;
  margin-bottom: 28px;
}

.editor-meta-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  padding: 5px 8px;
  border-radius: var(--radius-xs);
  font-size: 0.8rem;
  cursor: pointer;
}

.tool-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-color);
}

.toolbar-mode-switch {
  display: flex;
  background: var(--bg-subtle);
  border-radius: var(--radius-xs);
  padding: 2px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--bg-surface);
  color: var(--brand-primary);
  font-weight: 600;
}

.editor-work-area {
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--radius-xs) var(--radius-xs);
  background: var(--bg-surface);
  min-height: 420px;
}

.editor-work-area.mode-wysiwyg .markdown-textarea {
  display: none;
}

.editor-work-area.mode-markdown .wysiwyg-surface {
  display: none;
}

.editor-work-area.mode-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.editor-work-area.mode-split .markdown-textarea {
  border-left: 1px solid var(--border-color);
}

.wysiwyg-surface {
  padding: 22px;
  min-height: 420px;
  outline: none;
}

.markdown-textarea {
  width: 100%;
  min-height: 420px;
  padding: 18px;
  border: none;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.55;
  resize: vertical;
  outline: none;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.change-note-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.editor-footer-actions {
  display: flex;
  gap: 8px;
}

/* Wiki Prose Typography (Editorial style matching ../www) */
.wiki-prose {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-primary);
}

.wiki-prose h1,
.wiki-prose h2,
.wiki-prose h3,
.wiki-prose h4 {
  font-family: var(--font-serif);
  margin-top: 1.6em;
  margin-bottom: 0.55em;
  line-height: 1.22;
}

.wiki-prose h1 {
  font-size: 2rem;
}

.wiki-prose h2 {
  font-size: 1.55rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.wiki-prose h3 {
  font-size: 1.25rem;
}

.wiki-prose p {
  margin: 0 0 1.15em;
}

.wiki-prose pre {
  background: #131619;
  color: #F2F0EB;
  border: 1px solid #262B32;
  color-scheme: dark;
  accent-color: var(--brand-primary);
  padding: 14px 16px;
  border-radius: var(--radius-xs);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 16px 0;
}

.wiki-prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-subtle);
  padding: 2px 5px;
  border-radius: var(--radius-xs);
}

.wiki-prose pre code {
  background: transparent;
  padding: 0;
}

.wiki-prose blockquote,
.wiki-prose .confluence-callout {
  margin: 18px 0;
  padding: 14px 18px;
  border-left: 3px solid var(--brand-primary);
  background: var(--bg-subtle);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.wiki-prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 0.94rem;
}

.wiki-prose th,
.wiki-prose td {
  border: 1px solid var(--border-strong);
  padding: 9px 12px;
  text-align: left;
}

.wiki-prose th {
  background: var(--bg-subtle);
  font-weight: 600;
}

.wiki-prose a {
  color: var(--brand-primary);
  text-decoration: underline;
}

/* Comments Section */
.comments-section {
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

.comments-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 16px;
}

.comments-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.comment-form textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: inherit;
}

.comment-form-actions {
  display: flex;
  justify-content: flex-end;
}

.selection-quote-preview,
.comment-quote {
  padding: 8px 12px;
  border-left: 3px solid var(--brand-primary);
  background: var(--brand-soft);
  border-radius: var(--radius-xs);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.selection-comment-bar {
  margin-bottom: 10px;
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.comment-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 14px 16px;
  background: var(--bg-canvas);
}

.comment-card.resolved {
  opacity: 0.7;
}

.comment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.comment-author {
  font-weight: 700;
  color: var(--text-primary);
}

.comment-body {
  font-size: 0.94rem;
  white-space: pre-wrap;
}

.comment-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.comment-replies {
  margin-top: 12px;
  padding-left: 16px;
  border-left: 2px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Right TOC Rail */
.toc-rail {
  width: 240px;
  padding: 32px 18px 32px 0;
}

.toc-card {
  position: sticky;
  top: 90px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 16px;
}

.toc-heading {
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
}

.toc-link {
  color: var(--text-secondary);
  text-decoration: none;
}

.toc-link:hover {
  color: var(--brand-primary);
}

.toc-level-3 {
  padding-left: 12px;
}

/* Dialogs */
dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 0;
  width: 92%;
  max-width: 500px;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.35);
}

.modal-dialog.modal-lg {
  max-width: 680px;
}

.modal-content {
  display: flex;
  flex-direction: column;
}

.modal-header,
.modal-footer {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header {
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  border-top: 1px solid var(--border-color);
  justify-content: flex-end;
  gap: 8px;
}

.revisions-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.revision-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}

.theme-fieldset {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 12px 14px;
}

.theme-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* Forms & Buttons (matching ../www buttons) */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-field input,
.form-field select {
  padding: 8px 11px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: 0.92rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.16s ease;
}

.btn-primary {
  background: var(--brand-primary);
  color: var(--brand-primary-text);
  border-color: var(--brand-primary);
}

.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: var(--border-color);
}

.btn-ghost,
.btn-icon {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-icon {
  padding: 6px 8px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.84rem;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 0.76rem;
}

.btn-full {
  width: 100%;
}

.muted {
  color: var(--text-secondary);
}

@media (max-width: 1024px) {
  .toc-rail {
    display: none;
  }
  .workspace-grid {
    grid-template-columns: 240px minmax(0, 1fr);
  }
}
