:root {
  --bg: #f4efe4;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-strong: #fffaf1;
  --surface: rgba(255, 255, 255, 0.72);
  --editor-font-size: 16px;
  --line: rgba(49, 41, 28, 0.12);
  --line-strong: rgba(49, 41, 28, 0.18);
  --text: #2f261c;
  --muted: #756652;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: rgba(15, 118, 110, 0.1);
  --warning: #9a3412;
  --shadow: 0 18px 55px rgba(67, 45, 18, 0.12);
  --glow: rgba(15, 118, 110, 0.2);
  --radius: 24px;
  --font-sans: "IBM Plex Sans", "Segoe UI", sans-serif;
}

body[data-theme="dark"] {
  --bg: #0b1220;
  --panel: rgba(17, 28, 47, 0.9);
  --panel-strong: #0f1c34;
  --surface: rgba(21, 36, 62, 0.86);
  --line: rgba(148, 163, 184, 0.2);
  --line-strong: rgba(43, 59, 94, 0.92);
  --text: #d9e3f0;
  --muted: #8fa3c2;
  --accent: #60a5fa;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(96, 165, 250, 0.18);
  --warning: #fda4af;
  --shadow: 0 24px 54px rgba(8, 15, 35, 0.62);
  --glow: rgba(37, 99, 235, 0.26);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 30%),
    linear-gradient(135deg, #efe4cf 0%, #f7f2e9 45%, #e8f2ef 100%);
  transition: background 0.2s ease, color 0.2s ease;
}

body[data-theme="dark"] {
  background:
    radial-gradient(circle at top left, rgba(96, 165, 250, 0.16), transparent 26%),
    radial-gradient(circle at bottom right, rgba(29, 78, 216, 0.16), transparent 24%),
    linear-gradient(145deg, #0b1220 0%, #0d1728 42%, #111c2f 100%);
}

body {
  height: 100vh;
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

.eyebrow {
  display: none;
}

.label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  color: var(--muted);
}

.button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.78rem 1.15rem;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    background-color 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    color 0.18s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.button-primary {
  background: var(--accent);
  color: #f7fbfb;
}

.button-primary:hover {
  background: var(--accent-strong);
}

body[data-theme="dark"] .button-primary {
  background: linear-gradient(145deg, rgba(96, 165, 250, 0.94), rgba(29, 78, 216, 1));
  border-color: rgba(191, 219, 254, 0.55);
  box-shadow: 0 16px 28px var(--glow);
}

body[data-theme="dark"] .button-primary:hover {
  background: linear-gradient(145deg, rgba(125, 181, 251, 0.96), rgba(37, 99, 235, 1));
  box-shadow: 0 20px 34px rgba(37, 99, 235, 0.34);
}

.button-secondary {
  background: rgba(255, 255, 255, 0.66);
  border-color: var(--line);
  color: var(--text);
}

body[data-theme="dark"] .button-secondary {
  background: rgba(17, 24, 39, 0.82);
  border-color: rgba(148, 163, 184, 0.34);
  color: var(--text);
}

body[data-theme="dark"] .button-secondary:hover {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(191, 219, 254, 0.5);
}

.button-large {
  width: 100%;
  text-align: center;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.login-card {
  width: min(100%, 460px);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 32px;
  padding: 2.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

body[data-theme="dark"] .login-card {
  background:
    linear-gradient(180deg, rgba(17, 28, 47, 0.96), rgba(15, 28, 52, 0.92));
  border-color: var(--line-strong);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(191, 219, 254, 0.08);
}

.login-card h1 {
  margin: 0.4rem 0 0.9rem;
  font-size: clamp(2.1rem, 5vw, 3rem);
}

.login-copy,
.login-hint,
.muted {
  color: var(--muted);
}

.alert {
  padding: 1rem 1.1rem;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  margin: 1rem 0 1.2rem;
}

.alert-error {
  color: var(--warning);
  border-color: rgba(154, 52, 18, 0.25);
  background: rgba(255, 245, 240, 0.9);
}

body[data-theme="dark"] .alert-error {
  border-color: rgba(190, 24, 93, 0.45);
  background: rgba(69, 10, 10, 0.42);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 1.2rem;
  padding: 1.2rem;
  overflow: hidden;
}

.sidebar,
.workspace-panel {
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

body[data-theme="dark"] .sidebar,
body[data-theme="dark"] .workspace-panel {
  background:
    linear-gradient(180deg, rgba(17, 28, 47, 0.96), rgba(15, 28, 52, 0.92));
  border-color: var(--line-strong);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(191, 219, 254, 0.05);
}

.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.brand-block,
.sidebar-actions {
  padding: 0.8rem 1rem;
}

.workspace-topbar {
  padding: 0.4rem 0.9rem;
}

.statusbar {
  padding: 0.2rem 0.9rem;
  font-size: 0.74rem;
}

.brand-block h1,
.workspace-topbar h2 {
  margin: 0;
  font-size: 1rem;
}

.workspace-topbar .label {
  display: none;
}

#current-file-path {
  margin: 0;
  font-size: 0.72rem;
}

body[data-theme="dark"] .brand-block h1,
body[data-theme="dark"] .workspace-topbar h2,
body[data-theme="dark"] .modal-header h3 {
  color: #c8d5e8;
}

.sidebar-path {
  margin: 0;
  color: var(--muted);
  word-break: break-word;
}

.sidebar-actions {
  padding-top: 0;
}

.sidebar-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.sidebar-toolbar .button {
  flex: 1 1 0;
  min-width: 0;
}

.sidebar-tree-controls {
  display: none;
}

.sidebar-toolbar-icons {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  align-items: center;
}

.sidebar-toolbar-sep {
  flex: 1;
}

.sidebar-tree-icon {
  color: var(--muted);
}

.sidebar-tree-icon.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

body[data-theme="dark"] .sidebar-tree-icon {
  background: rgba(17, 24, 39, 0.78);
  border-color: rgba(148, 163, 184, 0.22);
}

body[data-theme="dark"] .sidebar-tree-icon:hover {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(191, 219, 254, 0.28);
}

body[data-theme="dark"] .sidebar-tree-icon.is-active {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(191, 219, 254, 0.32);
  color: #c6d5e9;
}

.context-menu {
  position: fixed;
  z-index: 50;
  width: min(280px, calc(100vw - 24px));
  padding: 0.5rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(16px);
}

.context-menu-header {
  display: grid;
  gap: 0.15rem;
  padding: 0.45rem 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.35rem;
}

.context-menu-title {
  font-size: 0.94rem;
}

.context-menu-path {
  font-size: 0.76rem;
  color: var(--muted);
  word-break: break-word;
}

.context-menu-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.context-menu-item:hover {
  background: var(--accent-soft);
}

.context-menu-item-muted {
  color: var(--muted);
}

.context-menu-item-danger {
  color: var(--warning);
  font-weight: 600;
}

body[data-theme="dark"] .context-menu {
  border-color: rgba(148, 163, 184, 0.22);
  background: linear-gradient(180deg, rgba(17, 28, 47, 0.98), rgba(15, 28, 52, 0.96));
  box-shadow: 0 24px 48px rgba(3, 8, 20, 0.5);
}

body[data-theme="dark"] .context-menu-header {
  border-color: rgba(148, 163, 184, 0.16);
}

body[data-theme="dark"] .context-menu-item {
  color: #c5d2e3;
}

body[data-theme="dark"] .context-menu-item:hover {
  background: rgba(59, 130, 246, 0.14);
}

body[data-theme="dark"] .context-menu-item-muted {
  color: #94a7c3;
}

.settings-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.settings-input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0.72rem 0.8rem;
  color: var(--text);
}

.settings-input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.settings-path-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.7rem;
  align-items: center;
}

.settings-browse-button {
  white-space: nowrap;
}

body[data-theme="dark"] .settings-input {
  background: rgba(17, 24, 39, 0.78);
  border-color: rgba(148, 163, 184, 0.28);
}

.small-note {
  margin: 0;
  font-size: 0.78rem;
}

.tree-root {
  overflow: auto;
  padding: 0 0.6rem 1rem 0.75rem;
}

.tree-scope-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.5rem;
  align-items: center;
  margin: 0 0 0.75rem;
}

.tree-scope-up {
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 0.28rem 0.55rem;
  cursor: pointer;
}

.tree-scope-label {
  min-width: 0;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-root.is-drop-target-root {
  outline: 1px dashed rgba(15, 118, 110, 0.45);
  outline-offset: -6px;
  background: rgba(15, 118, 110, 0.06);
}

body[data-theme="dark"] .tree-root {
  background:
    linear-gradient(180deg, rgba(11, 18, 32, 0), rgba(11, 18, 32, 0.22));
}

body[data-theme="dark"] .tree-root.is-drop-target-root {
  outline-color: rgba(96, 165, 250, 0.5);
  background: rgba(59, 130, 246, 0.1);
}

body[data-theme="dark"] .tree-scope-up {
  background: rgba(17, 24, 39, 0.78);
  color: #c3d0e1;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

body[data-theme="dark"] .tree-scope-up:hover {
  background: rgba(59, 130, 246, 0.14);
}

.tree-list {
  list-style: none;
  margin: 0;
  padding-left: 0.85rem;
}

.tree-list-root {
  padding-left: 0;
}

.tree-item {
  margin: 0.08rem 0;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tree-toggle,
.tree-link {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0.28rem 0.35rem;
  border-radius: 10px;
}

.tree-toggle {
  width: 1.8rem;
  color: var(--muted);
  cursor: pointer;
}

.tree-link {
  flex: 1;
  text-align: left;
  cursor: pointer;
}

.tree-link:hover,
.tree-link.is-active,
.tree-toggle:hover {
  background: var(--accent-soft);
}

body[data-theme="dark"] .tree-link,
body[data-theme="dark"] .tree-toggle {
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

body[data-theme="dark"] .tree-link:hover,
body[data-theme="dark"] .tree-toggle:hover {
  background: rgba(59, 130, 246, 0.16);
}

body[data-theme="dark"] .tree-link.is-active {
  background: linear-gradient(145deg, rgba(59, 130, 246, 0.28), rgba(29, 78, 216, 0.24));
  box-shadow: inset 0 0 0 1px rgba(191, 219, 254, 0.22);
}

.tree-row.is-draggable {
  cursor: grab;
}

.tree-row.is-draggable:active {
  cursor: grabbing;
}

.tree-row.is-dragging {
  opacity: 0.45;
}

.tree-row.is-drop-target {
  background: rgba(15, 118, 110, 0.12);
  outline: 1px dashed rgba(15, 118, 110, 0.45);
}

body[data-theme="dark"] .tree-row.is-drop-target {
  background: rgba(59, 130, 246, 0.16);
  outline-color: rgba(96, 165, 250, 0.5);
}

.tree-link.is-disabled {
  color: var(--muted);
}

.tree-link.is-disabled {
  opacity: 0.6;
}

.workspace-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.workspace-topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

body[data-theme="dark"] .workspace-topbar,
body[data-theme="dark"] .statusbar,
body[data-theme="dark"] .modal-header,
body[data-theme="dark"] .modal-actions {
  border-color: rgba(148, 163, 184, 0.18);
}

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

.user-chip {
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  color: var(--muted);
}

body[data-theme="dark"] .user-chip {
  background: rgba(17, 24, 39, 0.85);
  border-color: rgba(148, 163, 184, 0.28);
  color: #b9c9df;
}

.icon-button {
  width: 2.75rem;
  height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-button svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

.icon-button-small {
  width: 2.35rem;
  height: 2.35rem;
}

.icon-button:hover {
  background: var(--accent-soft);
}

body[data-theme="dark"] .icon-button {
  background: rgba(17, 24, 39, 0.84);
  border-color: rgba(148, 163, 184, 0.3);
  box-shadow: inset 0 1px 0 rgba(191, 219, 254, 0.05);
}

body[data-theme="dark"] .icon-button:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(191, 219, 254, 0.42);
}

.editor-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--panel-strong);
}

body[data-theme="dark"] .editor-stage {
  background:
    linear-gradient(180deg, rgba(15, 28, 52, 0.98), rgba(11, 18, 32, 0.96));
}

.editor-zoom {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.editor-zoom-label {
  min-width: 3.4rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.editor-stage #editor,
.toastui-editor-defaultUI {
  height: 100%;
}

.file-preview {
  height: 100%;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  overflow: auto;
}

.upload-stage {
  height: 100%;
  padding: 1.4rem;
  overflow: auto;
}

.upload-card {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  gap: 1rem;
}

.upload-card h3 {
  margin: 0.25rem 0 0;
}

.upload-dropzone {
  border: 1px dashed var(--line-strong);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.5);
  padding: 1.4rem;
  display: grid;
  gap: 0.8rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.upload-dropzone strong {
  font-size: 1.06rem;
}

.upload-dropzone.is-dragover,
.upload-dropzone:hover,
.upload-dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.08);
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.upload-file-list {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  padding: 0.9rem 1rem;
}

.upload-file-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.upload-file-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.1rem;
  border-bottom: 1px solid var(--line);
}

.upload-file-item:last-child {
  border-bottom: 0;
}

.upload-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-file-size,
.upload-file-empty {
  color: var(--muted);
  font-size: 0.88rem;
}

.file-preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
  background: rgba(255, 255, 255, 0.68);
}

.file-preview-pdf {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 0;
  border-radius: 18px;
  background: #fff;
}

body[data-theme="dark"] .file-preview-image {
  background: rgba(17, 24, 39, 0.78);
  box-shadow: 0 24px 44px rgba(3, 8, 20, 0.4);
}

body[data-theme="dark"] .file-preview-pdf {
  background: #0f172a;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.14);
}

body[data-theme="dark"] .upload-dropzone {
  background: rgba(17, 24, 39, 0.56);
  border-color: rgba(148, 163, 184, 0.28);
}

body[data-theme="dark"] .upload-dropzone.is-dragover,
body[data-theme="dark"] .upload-dropzone:hover,
body[data-theme="dark"] .upload-dropzone:focus-visible {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(96, 165, 250, 0.58);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

body[data-theme="dark"] .upload-file-list {
  background: rgba(17, 24, 39, 0.68);
  border-color: rgba(148, 163, 184, 0.2);
}

.overlay-card {
  position: absolute;
  inset: 1.4rem;
  border-radius: 24px;
  border: 1px dashed var(--line);
  display: grid;
  place-content: center;
  text-align: center;
  padding: 2rem;
  background: rgba(255, 251, 245, 0.86);
}

body[data-theme="dark"] .overlay-card {
  background: rgba(15, 23, 42, 0.88);
  border-color: rgba(148, 163, 184, 0.24);
  box-shadow: inset 0 1px 0 rgba(191, 219, 254, 0.04);
}

.overlay-card strong {
  font-size: 1.05rem;
}

.statusbar {
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.toastui-editor-defaultUI {
  border: 0 !important;
  font-family: var(--font-sans);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.toastui-editor-main {
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0;
}

.toastui-editor-md-container,
.toastui-editor-ww-container {
  height: 100% !important;
  min-height: 0;
}

.toastui-editor-toolbar {
  border-bottom-color: var(--line) !important;
  background: var(--surface) !important;
}

.toastui-editor-defaultUI-toolbar {
  border-bottom-color: var(--line) !important;
  background: var(--surface) !important;
}

.toastui-editor-contents {
  font-size: var(--editor-font-size);
}

/* ── Hide default mode switch, use toolbar button instead ── */
.toastui-editor-mode-switch {
  display: none !important;
}

.editor-mode-btn {
  background-image: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  border: 1px solid var(--line) !important;
  border-radius: 4px !important;
  padding: 0 0.55rem !important;
  font-size: 0.72rem !important;
  font-weight: 600 !important;
  letter-spacing: 0.04em !important;
  height: 26px !important;
  margin: auto 4px auto auto !important;
  white-space: nowrap;
  cursor: pointer;
}

.editor-mode-btn:hover {
  background: var(--accent-soft) !important;
  color: var(--accent) !important;
  border-color: var(--accent) !important;
}

/* ── Diagrams ─────────────────────────────────────────────── */
.mermaid-diagram {
  text-align: center;
  margin: 1rem 0;
  overflow-x: auto;
}

.mermaid-diagram svg {
  max-width: 100%;
  height: auto;
}

.diagram-plantuml {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1rem auto;
}

body[data-theme="dark"] .toastui-editor-defaultUI,
body[data-theme="dark"] .toastui-editor-main,
body[data-theme="dark"] .toastui-editor-md-container,
body[data-theme="dark"] .toastui-editor-ww-container,
body[data-theme="dark"] .toastui-editor-toolbar,
body[data-theme="dark"] .toastui-editor-defaultUI-toolbar,
body[data-theme="dark"] .toastui-editor-mode-switch,
body[data-theme="dark"] .toastui-editor-popup {
  background: #0f1c34 !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

body[data-theme="dark"] .toastui-editor-toolbar,
body[data-theme="dark"] .toastui-editor-defaultUI-toolbar,
body[data-theme="dark"] .toastui-editor-mode-switch {
  background:
    linear-gradient(180deg, rgba(11, 18, 32, 0.96), rgba(15, 28, 52, 0.96)) !important;
  box-shadow:
    inset 0 -1px 0 rgba(148, 163, 184, 0.12),
    inset 0 1px 0 rgba(191, 219, 254, 0.04);
}

body[data-theme="dark"] .toastui-editor-mode-switch {
  flex: 0 0 auto;
  display: flex !important;
  height: auto !important;
  min-height: 3.5rem;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.7rem 0.8rem !important;
  border-top: 1px solid rgba(148, 163, 184, 0.14) !important;
  box-sizing: border-box;
}

body[data-theme="dark"] .toastui-editor-toolbar button,
body[data-theme="dark"] .toastui-editor-defaultUI-toolbar button,
body[data-theme="dark"] .toastui-editor-mode-switch .tab-item {
  color: #aebfd8 !important;
}

body[data-theme="dark"] .toastui-editor-mode-switch .tab-item {
  min-width: 7.5rem;
  border: 1px solid rgba(148, 163, 184, 0.18) !important;
  border-radius: 999px !important;
  background: rgba(17, 24, 39, 0.68) !important;
  box-shadow: inset 0 1px 0 rgba(191, 219, 254, 0.03);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

body[data-theme="dark"] .toastui-editor-toolbar-icons {
  filter: invert(0.96) hue-rotate(180deg) saturate(0.9);
}

body[data-theme="dark"] .toastui-editor-contents,
body[data-theme="dark"] .toastui-editor-contents p,
body[data-theme="dark"] .toastui-editor-md-preview,
body[data-theme="dark"] .ProseMirror {
  color: #c6d1df !important;
}

body[data-theme="dark"] .toastui-editor-contents li,
body[data-theme="dark"] .toastui-editor-md-preview li,
body[data-theme="dark"] .toastui-editor-contents td,
body[data-theme="dark"] .toastui-editor-md-preview td {
  color: #c1ccdb !important;
}

body[data-theme="dark"] .toastui-editor-contents strong,
body[data-theme="dark"] .toastui-editor-md-preview strong {
  color: #d2dbe8 !important;
}

body[data-theme="dark"] .toastui-editor-md-preview {
  background: #111c2f !important;
}

body[data-theme="dark"] .toastui-editor-contents blockquote,
body[data-theme="dark"] .toastui-editor-md-preview blockquote,
body[data-theme="dark"] .toastui-editor-contents blockquote p,
body[data-theme="dark"] .toastui-editor-md-preview blockquote p {
  color: #93a4bb !important;
  border-left-color: rgba(148, 163, 184, 0.24) !important;
}

body[data-theme="dark"] .toastui-editor-contents code,
body[data-theme="dark"] .toastui-editor-md-preview code {
  background: rgba(148, 163, 184, 0.1) !important;
  color: #c7b7ca !important;
}

body[data-theme="dark"] .toastui-editor-contents pre,
body[data-theme="dark"] .toastui-editor-md-preview pre {
  background: rgba(11, 18, 32, 0.6) !important;
  color: #b9c8da !important;
}

body[data-theme="dark"] .toastui-editor-contents a,
body[data-theme="dark"] .toastui-editor-md-preview a {
  color: #9dbbe2 !important;
}

body[data-theme="dark"] .toastui-editor-toolbar-group {
  border-color: rgba(148, 163, 184, 0.18) !important;
}

body[data-theme="dark"] .toastui-editor-toolbar button,
body[data-theme="dark"] .toastui-editor-defaultUI-toolbar button {
  border-radius: 10px !important;
}

body[data-theme="dark"] .toastui-editor-toolbar button:hover,
body[data-theme="dark"] .toastui-editor-defaultUI-toolbar button:hover,
body[data-theme="dark"] .toastui-editor-mode-switch .tab-item:hover,
body[data-theme="dark"] .toastui-editor-mode-switch .tab-item.active {
  background: rgba(59, 130, 246, 0.16) !important;
}

body[data-theme="dark"] .toastui-editor-toolbar button:hover,
body[data-theme="dark"] .toastui-editor-defaultUI-toolbar button:hover,
body[data-theme="dark"] .toastui-editor-mode-switch .tab-item:hover {
  color: #d6e1f0 !important;
}

body[data-theme="dark"] .toastui-editor-mode-switch .tab-item.active {
  color: #dde8f6 !important;
  border-color: rgba(191, 219, 254, 0.34) !important;
  background: linear-gradient(145deg, rgba(59, 130, 246, 0.28), rgba(29, 78, 216, 0.24)) !important;
  box-shadow:
    inset 0 0 0 1px rgba(191, 219, 254, 0.18),
    0 8px 18px rgba(37, 99, 235, 0.18);
}

body[data-theme="dark"] .toastui-editor-popup-body input,
body[data-theme="dark"] .toastui-editor-popup-body label,
body[data-theme="dark"] .toastui-editor-popup-body select {
  color: var(--text) !important;
}

body[data-theme="dark"] .toastui-editor-contents h1,
body[data-theme="dark"] .toastui-editor-contents h2,
body[data-theme="dark"] .toastui-editor-contents h3,
body[data-theme="dark"] .toastui-editor-contents h4,
body[data-theme="dark"] .toastui-editor-md-preview h1,
body[data-theme="dark"] .toastui-editor-md-preview h2,
body[data-theme="dark"] .toastui-editor-md-preview h3,
body[data-theme="dark"] .toastui-editor-md-preview h4 {
  color: #b7c7da !important;
}

body[data-theme="dark"] .toastui-editor-contents h1,
body[data-theme="dark"] .toastui-editor-md-preview h1 {
  border-bottom-color: rgba(148, 163, 184, 0.32) !important;
}

body[data-theme="dark"] .toastui-editor-contents h2,
body[data-theme="dark"] .toastui-editor-md-preview h2 {
  border-bottom-color: rgba(148, 163, 184, 0.2) !important;
}

.ProseMirror,
.toastui-editor-md-preview,
.toastui-editor-contents,
.toastui-editor-contents p,
.toastui-editor-contents li,
.toastui-editor-md-preview p,
.toastui-editor-md-preview li {
  font-size: var(--editor-font-size) !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 20, 27, 0.46);
  display: grid;
  place-items: center;
  padding: 1.5rem;
  z-index: 30;
}

body[data-theme="dark"] .modal-backdrop {
  background: rgba(3, 8, 20, 0.72);
}

.modal-card {
  width: min(100%, 520px);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-card-wide {
  width: min(100%, 760px);
}

body[data-theme="dark"] .modal-card {
  background:
    linear-gradient(180deg, rgba(17, 28, 47, 0.98), rgba(15, 28, 52, 0.96));
  border-color: var(--line-strong);
}

body[data-theme="dark"] .directory-browser-path,
body[data-theme="dark"] .directory-browser-item,
body[data-theme="dark"] .directory-browser-empty {
  background: rgba(17, 24, 39, 0.78);
  border-color: rgba(148, 163, 184, 0.22);
}

body[data-theme="dark"] .directory-browser-item:hover {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(191, 219, 254, 0.32);
}

.modal-header,
.modal-content,
.modal-actions {
  padding: 1.2rem 1.3rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0.3rem 0 0;
}

.modal-content {
  display: grid;
  gap: 0.7rem;
}

.directory-browser-current {
  display: grid;
  gap: 0.35rem;
}

.directory-browser-path {
  padding: 0.8rem 0.95rem;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  word-break: break-word;
}

.directory-browser-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.directory-browser-list {
  display: grid;
  gap: 0.55rem;
  max-height: min(50vh, 420px);
  overflow: auto;
  padding-right: 0.2rem;
}

.directory-browser-item {
  width: 100%;
  display: grid;
  gap: 0.2rem;
  text-align: left;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.directory-browser-item:hover {
  transform: translateY(-1px);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.directory-browser-item-name {
  font-weight: 600;
}

.directory-browser-item-path {
  font-size: 0.82rem;
  color: var(--muted);
  word-break: break-word;
}

.directory-browser-empty {
  padding: 1rem;
  border-radius: 16px;
  border: 1px dashed var(--line);
  background: var(--surface);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 320px minmax(0, 1fr);
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .workspace-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .sidebar-toolbar .button {
    flex-basis: calc(50% - 0.3rem);
  }
}

/* ── Tree icons ──────────────────────────────────────────── */

.tree-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: 0.3rem;
}

.tree-icon svg {
  width: 14px;
  height: 14px;
}

.tree-link-dir {
  display: inline-flex;
  align-items: center;
}

.tree-toggle-file {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tree-icon-folder { color: #c8974a; }
.tree-icon-md     { color: #6b9fd4; }
.tree-icon-image  { color: #6aaf76; }
.tree-icon-pdf    { color: #c96b6b; }
.tree-icon-generic { color: var(--muted); }

/* ── Obsidian theme ──────────────────────────────────────── */

body[data-theme="obsidian"] {
  --bg: #1e1e1e;
  --panel: #252526;
  --panel-strong: #1e1e1e;
  --surface: #2d2d30;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  --text: #cccccc;
  --muted: #808080;
  --accent: #7c6fcd;
  --accent-strong: #6a5db8;
  --accent-soft: rgba(124, 111, 205, 0.15);
  --warning: #f28779;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  --glow: transparent;
  --radius: 4px;

  background: #1e1e1e;
}

body[data-theme="obsidian"] .app-shell {
  gap: 0;
  padding: 0;
  height: 100vh;
}

body[data-theme="obsidian"] .sidebar,
body[data-theme="obsidian"] .workspace-panel {
  border-radius: 0;
  backdrop-filter: none;
  box-shadow: none;
  background: var(--panel);
  border: none;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

body[data-theme="obsidian"] .workspace-panel {
  border-right: none;
}

body[data-theme="obsidian"] .brand-block h1,
body[data-theme="obsidian"] .workspace-topbar h2,
body[data-theme="obsidian"] .modal-header h3 {
  color: #d4d4d4;
}

body[data-theme="obsidian"] .button {
  border-radius: 4px;
  transform: none !important;
}

body[data-theme="obsidian"] .button-primary {
  background: var(--accent);
  border-color: transparent;
  box-shadow: none;
  color: #fff;
}

body[data-theme="obsidian"] .button-primary:hover {
  background: var(--accent-strong);
  box-shadow: none;
}

body[data-theme="obsidian"] .button-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
}

body[data-theme="obsidian"] .button-secondary:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

body[data-theme="obsidian"] .icon-button {
  border-radius: 4px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

body[data-theme="obsidian"] .icon-button:hover {
  background: var(--accent-soft);
  border-color: transparent;
}

body[data-theme="obsidian"] .user-chip {
  border-radius: 4px;
  background: var(--surface);
  border-color: var(--line-strong);
}

body[data-theme="obsidian"] .tree-toggle,
body[data-theme="obsidian"] .tree-link {
  border-radius: 3px;
}

body[data-theme="obsidian"] .tree-link:hover,
body[data-theme="obsidian"] .tree-toggle:hover {
  background: var(--accent-soft);
}

body[data-theme="obsidian"] .tree-link.is-active {
  background: var(--accent-soft);
  color: #a89de8;
  box-shadow: none;
}

body[data-theme="obsidian"] .sidebar-tree-icon {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

body[data-theme="obsidian"] .sidebar-tree-icon:hover {
  background: var(--accent-soft);
  border-color: transparent;
}

body[data-theme="obsidian"] .sidebar-tree-icon.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

body[data-theme="obsidian"] .workspace-topbar,
body[data-theme="obsidian"] .statusbar,
body[data-theme="obsidian"] .modal-header,
body[data-theme="obsidian"] .modal-actions {
  border-color: rgba(255, 255, 255, 0.1);
}

body[data-theme="obsidian"] .editor-stage {
  background: #1e1e1e;
}

body[data-theme="obsidian"] .toastui-editor-defaultUI,
body[data-theme="obsidian"] .toastui-editor-main,
body[data-theme="obsidian"] .toastui-editor-md-container,
body[data-theme="obsidian"] .toastui-editor-ww-container,
body[data-theme="obsidian"] .toastui-editor-popup {
  background: #1e1e1e !important;
  color: #cccccc !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

body[data-theme="obsidian"] .toastui-editor-toolbar,
body[data-theme="obsidian"] .toastui-editor-defaultUI-toolbar,
body[data-theme="obsidian"] .toastui-editor-mode-switch {
  background: #252526 !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  box-shadow: none !important;
}

body[data-theme="obsidian"] .toastui-editor-toolbar-icons {
  filter: invert(0.82) hue-rotate(180deg) saturate(0.7);
}

body[data-theme="obsidian"] .toastui-editor-toolbar button,
body[data-theme="obsidian"] .toastui-editor-defaultUI-toolbar button {
  border-radius: 3px !important;
  color: #808080 !important;
}

body[data-theme="obsidian"] .toastui-editor-toolbar button:hover,
body[data-theme="obsidian"] .toastui-editor-defaultUI-toolbar button:hover {
  background: var(--accent-soft) !important;
  color: #cccccc !important;
}

body[data-theme="obsidian"] .toastui-editor-toolbar-group {
  border-color: rgba(255, 255, 255, 0.08) !important;
}

body[data-theme="obsidian"] .toastui-editor-mode-switch {
  min-height: 2.8rem;
  padding: 0.5rem 0.6rem !important;
  border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
}

body[data-theme="obsidian"] .toastui-editor-mode-switch .tab-item {
  border-radius: 3px !important;
  background: var(--surface) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  color: #808080 !important;
  box-shadow: none !important;
}

body[data-theme="obsidian"] .toastui-editor-mode-switch .tab-item.active {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  color: #a89de8 !important;
  box-shadow: none !important;
}

body[data-theme="obsidian"] .toastui-editor-contents,
body[data-theme="obsidian"] .toastui-editor-contents p,
body[data-theme="obsidian"] .ProseMirror,
body[data-theme="obsidian"] .toastui-editor-md-preview {
  background: #1e1e1e !important;
  color: #cccccc !important;
}

body[data-theme="obsidian"] .toastui-editor-contents h1,
body[data-theme="obsidian"] .toastui-editor-contents h2,
body[data-theme="obsidian"] .toastui-editor-contents h3,
body[data-theme="obsidian"] .toastui-editor-contents h4,
body[data-theme="obsidian"] .toastui-editor-md-preview h1,
body[data-theme="obsidian"] .toastui-editor-md-preview h2,
body[data-theme="obsidian"] .toastui-editor-md-preview h3,
body[data-theme="obsidian"] .toastui-editor-md-preview h4 {
  color: #e8e8e8 !important;
}

body[data-theme="obsidian"] .toastui-editor-contents h1,
body[data-theme="obsidian"] .toastui-editor-md-preview h1 {
  border-bottom-color: rgba(255, 255, 255, 0.12) !important;
}

body[data-theme="obsidian"] .toastui-editor-contents h2,
body[data-theme="obsidian"] .toastui-editor-md-preview h2 {
  border-bottom-color: rgba(255, 255, 255, 0.07) !important;
}

body[data-theme="obsidian"] .toastui-editor-contents code,
body[data-theme="obsidian"] .toastui-editor-md-preview code {
  background: rgba(255, 255, 255, 0.07) !important;
  color: #ce9178 !important;
}

body[data-theme="obsidian"] .toastui-editor-contents pre,
body[data-theme="obsidian"] .toastui-editor-md-preview pre {
  background: #1a1a1a !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: #d4d4d4 !important;
}

body[data-theme="obsidian"] .toastui-editor-contents a,
body[data-theme="obsidian"] .toastui-editor-md-preview a {
  color: #569cd6 !important;
}

body[data-theme="obsidian"] .toastui-editor-contents blockquote,
body[data-theme="obsidian"] .toastui-editor-md-preview blockquote,
body[data-theme="obsidian"] .toastui-editor-contents blockquote p,
body[data-theme="obsidian"] .toastui-editor-md-preview blockquote p {
  border-left-color: var(--accent) !important;
  color: #808080 !important;
}

body[data-theme="obsidian"] .toastui-editor-contents li,
body[data-theme="obsidian"] .toastui-editor-md-preview li {
  color: #cccccc !important;
}

body[data-theme="obsidian"] .toastui-editor-contents strong,
body[data-theme="obsidian"] .toastui-editor-md-preview strong {
  color: #e8e8e8 !important;
}

body[data-theme="obsidian"] .toastui-editor-popup-body input,
body[data-theme="obsidian"] .toastui-editor-popup-body label,
body[data-theme="obsidian"] .toastui-editor-popup-body select {
  color: var(--text) !important;
}

body[data-theme="obsidian"] .context-menu {
  border-radius: 6px;
  background: #2d2d30;
  border-color: rgba(255, 255, 255, 0.13);
  backdrop-filter: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

body[data-theme="obsidian"] .context-menu-item {
  border-radius: 3px;
  color: #cccccc;
}

body[data-theme="obsidian"] .context-menu-item:hover {
  background: var(--accent-soft);
}

body[data-theme="obsidian"] .context-menu-item-muted {
  color: #808080;
}

body[data-theme="obsidian"] .context-menu-header {
  border-color: rgba(255, 255, 255, 0.1);
}

body[data-theme="obsidian"] .modal-backdrop {
  background: rgba(0, 0, 0, 0.65);
}

body[data-theme="obsidian"] .modal-card {
  border-radius: 6px;
  background: #252526;
  border-color: rgba(255, 255, 255, 0.13);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

body[data-theme="obsidian"] .settings-input {
  border-radius: 3px;
  background: #2d2d30;
  border-color: rgba(255, 255, 255, 0.13);
  color: #cccccc;
}

body[data-theme="obsidian"] .settings-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

body[data-theme="obsidian"] .directory-browser-path,
body[data-theme="obsidian"] .directory-browser-item,
body[data-theme="obsidian"] .directory-browser-empty {
  border-radius: 4px;
  background: #2d2d30;
  border-color: rgba(255, 255, 255, 0.1);
  color: #cccccc;
}

body[data-theme="obsidian"] .directory-browser-item:hover {
  transform: none;
  background: var(--accent-soft);
  border-color: var(--accent);
}

body[data-theme="obsidian"] .login-card {
  border-radius: 6px;
  background: #252526;
  border-color: rgba(255, 255, 255, 0.13);
  backdrop-filter: none;
}

body[data-theme="obsidian"] .upload-dropzone {
  border-radius: 4px;
  background: #2d2d30;
  border-color: rgba(255, 255, 255, 0.13);
}

body[data-theme="obsidian"] .upload-dropzone:hover,
body[data-theme="obsidian"] .upload-dropzone.is-dragover,
body[data-theme="obsidian"] .upload-dropzone:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: none;
}

body[data-theme="obsidian"] .upload-file-list {
  border-radius: 4px;
  background: #2d2d30;
  border-color: rgba(255, 255, 255, 0.1);
}

body[data-theme="obsidian"] .overlay-card {
  border-radius: 4px;
  background: rgba(37, 37, 38, 0.95);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

body[data-theme="obsidian"] .tree-scope-up {
  border-radius: 3px;
  background: #2d2d30;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cccccc;
}

body[data-theme="obsidian"] .tree-scope-up:hover {
  background: var(--accent-soft);
}

body[data-theme="obsidian"] .alert-error {
  background: rgba(80, 20, 20, 0.6);
  border-color: rgba(242, 135, 121, 0.3);
}

body[data-theme="obsidian"] .tree-icon-folder { color: #d4a73a; }
body[data-theme="obsidian"] .tree-icon-md     { color: #6b9fd4; }
body[data-theme="obsidian"] .tree-icon-image  { color: #6aaf76; }
body[data-theme="obsidian"] .tree-icon-pdf    { color: #c96b6b; }
body[data-theme="obsidian"] .tree-icon-generic { color: #808080; }
