:root {
    --desktop-topbar-h: 62px;
    --sidebar-width: 330px;
    --bg: #f3f4f6;
    --surface: #f9fafb;
    --card: #ffffff;
    --ink: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #1d4ed8;
    --primary-strong: #1e40af;
    --accent: #059669;
    --danger: #dc2626;
    --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    --ring: 0 0 0 2px rgba(29, 78, 216, 0.2);
    --radius: 10px;
    --sidebar-grad-start: #ffffff;
    --sidebar-grad-end: #f9fafb;
    --sidebar-node-ink: #374151;
    --sidebar-node-hover: #f3f4f6;
    --sidebar-node-active-bg: #1d4ed8;
    --sidebar-node-active-ink: #ffffff;
    --sidebar-system-ink: #111827;
    --sidebar-sep: #e5e7eb;
    --btn-subtle-bg: #f3f4f6;
    --btn-subtle-ink: #374151;
    --btn-subtle-hover: #e5e7eb;
    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --topbar-bg: rgba(255, 255, 255, 0.92);
    --topbar-border: #e5e7eb;
    --topbar-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

@font-face {
    font-family: "Manrope";
    src: url("fonts/manrope-latin-400-700.woff2") format("woff2");
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
}

@font-face {
    font-family: "Literata";
    src: url("fonts/literata-latin-500-700.woff2") format("woff2");
    font-style: normal;
    font-weight: 500 700;
    font-display: swap;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    font-family: "Manrope", "Segoe UI", Tahoma, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    overflow-x: hidden;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 20px;
}

h1, h2, h3 {
    margin: 0;
    font-family: "Literata", Georgia, serif;
    letter-spacing: -0.01em;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ================================================================
   TOPBAR
   ================================================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: auto minmax(260px, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 10px 18px;
    min-height: var(--desktop-topbar-h);
    border-bottom: 1px solid var(--topbar-border);
    background: var(--topbar-bg);
    backdrop-filter: blur(8px);
    box-shadow: var(--topbar-shadow);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-home {
    color: inherit;
    text-decoration: none;
}

.brand-home:hover {
    text-decoration: none;
}

.brand-wrap strong {
    display: block;
    font-size: 18px;
}

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--primary);
    position: relative;
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.3);
}

.top-search {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
    width: min(540px, 100%);
    justify-self: center;
}

.top-search input {
    min-width: 180px;
}

.top-search input,
.top-search button,
.top-search .btn {
    margin: 0;
}

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

.mobile-header-toggle {
    display: none !important;
}

.mobile-sidebar-toggle {
    display: none !important;
}

.mobile-sidebar-toggle,
.mobile-header-toggle {
    min-height: 34px;
    padding: 7px 12px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
}

.mobile-sidebar-toggle i.bi,
.mobile-header-toggle i.bi {
    margin-right: 0;
    font-size: 14px;
}

.topbar-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.topbar-buttons-primary {
    padding-right: 8px;
    border-right: 1px solid var(--line);
}

.topbar-buttons-secondary {
    padding-left: 2px;
}

/* User chip - clearly NOT a button */
.user-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 10px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--muted);
    border: 1px solid var(--line);
    background: var(--surface);
    cursor: default;
    user-select: none;
    line-height: 1.3;
}

.user-chip-name {
    font-weight: 700;
    color: var(--ink);
    font-size: 13px;
}

.user-chip-role {
    font-weight: 500;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.04em;
    opacity: 0.7;
}

.user-chip-role::before {
    content: "|";
    margin-right: 6px;
    opacity: 0.4;
}

.user-chip-public .user-chip-name {
    color: var(--muted);
    font-weight: 600;
}

/* ================================================================
   LAYOUT
   ================================================================ */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    gap: 18px;
    padding: 16px;
    align-items: start;
}

body.sidebar-collapsed .layout {
    grid-template-columns: 0 minmax(0, 1fr);
    gap: 0;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: 16px;
}

.sidebar {
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 94px);
    height: auto;
    overflow: auto;
    background: var(--card);
    align-self: start;
    width: var(--sidebar-width);
    min-width: 0;
    transition: width 0.2s ease, padding 0.2s ease, border-color 0.2s ease, opacity 0.16s ease, transform 0.2s ease;
    z-index: 35;
}

body:not(.sidebar-collapsed) .sidebar {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

body.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    padding: 0;
    border-color: transparent;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-24px);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    clear: both;
}

.sidebar-handle-toggle {
    position: fixed;
    top: 132px;
    left: 0;
    z-index: 95;
    width: 37px;
    height: 44px;
    min-width: 37px;
    min-height: 44px;
    padding: 0;
    font-size: 0;
    border-radius: 0 10px 10px 0;
    border: 1px solid var(--line);
    border-left: 0;
    background: var(--card);
    color: var(--muted);
    box-shadow: var(--shadow-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: left 0.2s ease, background 0.12s ease, color 0.12s ease;
    line-height: 1;
}

.sidebar-handle-toggle:hover,
.sidebar-handle-toggle:focus-visible {
    background: var(--sidebar-node-hover);
    color: var(--ink);
    outline: none;
}

.sidebar-handle-toggle i.bi {
    margin-right: 0;
    font-size: 14px;
    transition: color 0.12s ease;
}

body:not(.sidebar-collapsed) .sidebar-handle-toggle {
    left: calc(16px + var(--sidebar-width) - 1px);
}

.mobile-header-panel {
    display: none;
}

.content {
    min-height: calc(100vh - 102px);
    box-shadow: var(--shadow-2);
    background: var(--card);
    overflow: visible;
    min-width: 0;
}

.page-index-panel {
    position: fixed;
    top: 132px;
    right: 0;
    width: min(270px, calc(100vw - 32px));
    border: 1px solid var(--line);
    border-radius: 10px 0 0 10px;
    border-right: 0;
    background: var(--card);
    box-shadow: var(--shadow-2);
    z-index: 40;
    overflow: hidden;
    transition: width 0.2s ease;
}

.page-index-head {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 37px 0 10px;
    min-height: 44px;
    border-bottom: 1px solid var(--line);
    position: relative;
    overflow: hidden;
}

.page-index-head strong {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    opacity: 1;
    transition: opacity 0.14s ease 0.06s;
}

.page-index-toggle {
    position: absolute;
    right: 0;
    top: 0;
    width: 37px;
    height: 100%;
    min-width: 37px;
    min-height: 100%;
    padding: 0;
    border-radius: 0;
    border: 1px solid var(--line);
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    background: var(--card);
    color: var(--muted);
}

.page-index-toggle:hover,
.page-index-toggle:focus-visible {
    background: var(--sidebar-node-hover);
    color: var(--ink);
    outline: none;
}

.page-index-toggle i.bi {
    margin-right: 0;
    font-size: 14px;
    transition: color 0.12s ease;
}

.page-index-nav {
    max-height: min(62vh, 520px);
    overflow: auto;
    padding: 8px 8px 10px;
}

.page-index-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 2px;
}

.page-index-list a {
    display: block;
    padding: 5px 8px;
    border-radius: 7px;
    color: var(--sidebar-node-ink);
    font-size: 13px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.page-index-list a:hover {
    background: var(--sidebar-node-hover);
    text-decoration: none;
}

.page-index-list .toc-lvl-1 { font-weight: 700; }
.page-index-list .toc-lvl-2 { padding-left: 14px; }
.page-index-list .toc-lvl-3 { padding-left: 22px; }
.page-index-list .toc-lvl-4 { padding-left: 30px; }
.page-index-list .toc-lvl-5 { padding-left: 38px; }
.page-index-list .toc-lvl-6 { padding-left: 46px; }

.page-index-panel.is-collapsed {
    width: 45px;
}

.page-index-panel.is-collapsed .page-index-head {
    border-bottom: 0;
}

.page-index-panel.is-collapsed .page-index-head strong {
    opacity: 0;
}

.page-index-panel.is-collapsed .page-index-nav {
    display: none;
}

/* ================================================================
   SIDEBAR TREE
   ================================================================ */
.tree-filter,
.quick-jump {
    margin-top: 10px;
}

.tree {
    list-style: none;
    padding-left: 14px;
    margin: 8px 0 0;
    border-left: 2px solid var(--sidebar-sep);
}

.tree .tree {
    margin-top: 4px;
}

.tree li {
    margin: 2px 0;
    position: relative;
}

.tree .node {
    display: block;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--sidebar-node-ink);
    font-weight: 600;
    font-size: 13.5px;
    transition: background 0.12s ease, color 0.12s ease;
    line-height: 1.4;
}

.tree .node:hover {
    background: var(--sidebar-node-hover);
    text-decoration: none;
}

.tree .node.active {
    background: var(--sidebar-node-active-bg);
    color: var(--sidebar-node-active-ink);
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

.system-block {
    margin-bottom: 4px;
}

.system-title {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--sidebar-sep);
    font-size: 13px;
    font-weight: 700;
    color: var(--sidebar-system-ink);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.system-block:first-child .system-title {
    margin-top: 6px;
    padding-top: 0;
    border-top: 0;
}

.system-title-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
}

.node-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.drag-handle {
    width: 18px;
    min-width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
}

.drag-handle i.bi {
    font-size: 11px;
    margin-right: 0;
}

.drag-handle:active {
    cursor: grabbing;
}

.tree-empty {
    min-height: 22px;
    margin-left: 14px;
    border-left: 2px dashed var(--sidebar-sep);
    padding-left: 10px;
}

/* Edit mode tree adjustments */
body.is-edit-mode .sidebar {
    padding: 12px;
}

body.is-edit-mode .system-title {
    margin-top: 9px;
    padding-top: 8px;
    font-size: 12px;
}

body.is-edit-mode .tree {
    margin-top: 4px;
    padding-left: 10px;
}

body.is-edit-mode .tree li {
    margin: 1px 0;
}

body.is-edit-mode .tree .node {
    padding: 5px 8px;
    border-radius: 7px;
    font-size: 13px;
}

body.is-edit-mode .tree-toggle,
body.is-edit-mode .system-toggle,
body.is-edit-mode .tree-toggle-placeholder {
    width: 20px;
    min-width: 20px;
    height: 20px;
}

body.is-edit-mode .tree-empty {
    min-height: 16px;
    margin-left: 10px;
    padding-left: 8px;
}

/* ================================================================
   DARK THEME
   ================================================================ */
body.theme-dark {
    --bg: #0f1620;
    --surface: #151f2e;
    --card: #1a2538;
    --ink: #e4ecf7;
    --muted: #8da0bb;
    --line: #2c4060;
    --primary: #5e9bff;
    --primary-strong: #4a87f0;
    --accent: #4ad2ba;
    --danger: #e06373;
    --shadow-1: 0 6px 18px rgba(0, 0, 0, 0.25);
    --shadow-2: 0 24px 48px rgba(0, 0, 0, 0.35);
    --ring: 0 0 0 3px rgba(94, 155, 255, 0.3);
    --sidebar-grad-start: #162030;
    --sidebar-grad-end: #111b28;
    --sidebar-node-ink: #c8d9f0;
    --sidebar-node-hover: #1f3350;
    --sidebar-node-active-bg: #3672cc;
    --sidebar-node-active-ink: #ffffff;
    --sidebar-system-ink: #9db5d6;
    --sidebar-sep: #283e5a;
    --btn-subtle-bg: #1f3350;
    --btn-subtle-ink: #c8d9f0;
    --btn-subtle-hover: #27405e;
    --input-bg: #151f2e;
    --input-border: #2f4564;
    --topbar-bg: rgba(18, 28, 44, 0.95);
    --topbar-border: #2c4060;
    --topbar-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

body.theme-dark .topbar {
    border-bottom-color: var(--topbar-border);
    background: var(--topbar-bg);
    box-shadow: var(--topbar-shadow);
}

body.theme-dark .content {
    background: var(--card);
}

body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea {
    color: var(--ink);
    border-color: var(--input-border);
    background: #151f2e;
}

body.theme-dark input::placeholder,
body.theme-dark textarea::placeholder {
    color: #6b829e;
}

body.theme-dark .btn.subtle,
body.theme-dark button.secondary {
    background: var(--btn-subtle-bg);
    color: var(--btn-subtle-ink);
}

body.theme-dark .btn.subtle:hover,
body.theme-dark button.secondary:hover {
    background: var(--btn-subtle-hover);
}

body.theme-dark .settings-tab {
    background: #1a2d44;
    border-color: #2f4564;
    color: #b0c8e6;
}

body.theme-dark .settings-tab:hover {
    background: #22384f;
}

body.theme-dark .settings-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

body.theme-dark .media-item-card,
body.theme-dark .media-summary-grid > div {
    background: #1a2d44;
    border-color: #2f4a6d;
}

body.theme-dark .media-file-link {
    background: #1a2d44;
    border-color: #36577e;
    color: #c8d9f0;
}


body.theme-dark .user-chip {
    background: #1a2d44;
    border-color: #2f4564;
    color: #8da0bb;
}

body.theme-dark .user-chip-name {
    color: #e4ecf7;
}

body.theme-dark label {
    color: #8da0bb;
}

body.theme-dark .settings-card {
    background: #152030;
    border-color: #2c4060;
}

body.theme-dark .system-list li {
    background: #152030;
    border-color: #2c4060;
}

body.theme-dark .role-badge {
    background: #1a2d44;
    border-color: #2f4564;
    color: #b0c8e6;
}

body.theme-dark .role-admin {
    background: #2d2010;
    border-color: #5a3d1f;
    color: #e8b86a;
}

body.theme-dark .role-editor {
    background: #0f2b20;
    border-color: #1a5040;
    color: #6dd4a8;
}

body.theme-dark .role-viewer {
    background: #152030;
    border-color: #2c4060;
    color: #8da0bb;
}

body.theme-dark .alert.success {
    background: #0f2b20;
    border-color: #1a5040;
    color: #6dd4a8;
}

body.theme-dark .alert.error {
    background: #2d1218;
    border-color: #5a2030;
    color: #f0808e;
}

body.theme-dark .result-item {
    background: var(--card);
    border-color: var(--line);
}

body.theme-dark .result-item:hover {
    background: var(--surface);
}

body.theme-dark .empty-state {
    background: #152030;
    border-color: #2c4060;
}

body.theme-dark .live-search-results {
    background: #1a2538;
    border-color: #2c4060;
}

body.theme-dark .live-search-item:hover {
    background: #1f3350;
}

body.theme-dark .live-search-item {
    border-bottom-color: #2c4060;
}

body.theme-dark .sticky-editor-actions {
    background: var(--surface);
    border-color: var(--line);
}

body.theme-dark .editor-top-toolbar {
    background: var(--card) !important;
    border-color: var(--line) !important;
}

body.theme-dark .editor-shell .ql-container.ql-snow {
    border-color: #2c4060;
    color: var(--ink);
}

body.theme-dark .editor-shell .ql-snow .ql-stroke {
    stroke: #8da0bb;
}

body.theme-dark .editor-shell .ql-snow .ql-fill {
    fill: #8da0bb;
}

body.theme-dark .editor-shell .ql-snow .ql-picker-label {
    color: #8da0bb;
}

body.theme-dark .raw-html-editor {
    background: #131c2a;
    border-color: #2c4060;
    color: #c8d9f0;
}

body.theme-dark .record-mode-dialog {
    background: #1a2538;
    border-color: #2c4060;
}

body.theme-dark .record-placeholder {
    background: #152030;
    border-color: #2c4060;
}

body.theme-dark .voice-meter {
    background: #152030;
    border-color: #2c4060;
    color: #8da0bb;
}

body.theme-dark .tree-toggle,
body.theme-dark .system-toggle {
    background: #1a2d44;
    border-color: #2f4564;
    color: #8da0bb;
}

body.theme-dark .sortable-chosen .node-row {
    background: #1f3350;
}

body.theme-dark .tree .sortable-drag .node-row {
    background: #27405e;
    border-color: #3a6aaa;
}

body.theme-dark .manual-content td,
body.theme-dark .manual-content th {
    border-color: #2c4060;
}

body.theme-dark .media-size-inline {
    background: #152030;
    border-color: #2c4060;
}

body.theme-dark .section-sep {
    border-top-color: #2c4060;
}

body.theme-dark .checkbox-row span,
body.theme-dark .compact-card label {
    color: #b0c8e6;
}

/* ================================================================
   SPECIAL THEME (warm parchment)
   ================================================================ */
body.theme-special {
    --bg: #f5efe4;
    --surface: #fdf8f0;
    --card: #fffdf7;
    --ink: #32281a;
    --muted: #7a6a52;
    --line: #ddd0b8;
    --primary: #b25a1e;
    --primary-strong: #944417;
    --accent: #2d8f66;
    --danger: #b03939;
    --shadow-1: 0 6px 18px rgba(80, 50, 20, 0.1);
    --shadow-2: 0 24px 48px rgba(80, 50, 20, 0.15);
    --ring: 0 0 0 3px rgba(178, 90, 30, 0.2);
    --sidebar-grad-start: #fdf8f0;
    --sidebar-grad-end: #f4e8d3;
    --sidebar-node-ink: #4a381e;
    --sidebar-node-hover: #f0e0c8;
    --sidebar-node-active-bg: #b25a1e;
    --sidebar-node-active-ink: #fff7ef;
    --sidebar-system-ink: #5a4020;
    --sidebar-sep: #dcc8a6;
    --btn-subtle-bg: #f0e4d0;
    --btn-subtle-ink: #5a4020;
    --btn-subtle-hover: #e8d8be;
    --input-bg: #fdf8f0;
    --input-border: #d8c8aa;
    --topbar-bg: rgba(253, 248, 240, 0.95);
    --topbar-border: #ddd0b8;
    --topbar-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

body.theme-special .topbar {
    border-bottom-color: var(--topbar-border);
    background: var(--topbar-bg);
}

body.theme-special .content {
    background: var(--card);
}

body.theme-special input,
body.theme-special select,
body.theme-special textarea {
    border-color: var(--input-border);
    background: var(--input-bg);
    color: var(--ink);
}

body.theme-special .btn.subtle,
body.theme-special button.secondary {
    background: var(--btn-subtle-bg);
    color: var(--btn-subtle-ink);
}

body.theme-special .btn.subtle:hover,
body.theme-special button.secondary:hover {
    background: var(--btn-subtle-hover);
}

body.theme-special .settings-tab {
    background: #f0e4d0;
    border-color: #d8c8aa;
    color: #5a4020;
}

body.theme-special .settings-tab:hover {
    background: #e8d8be;
}

body.theme-special .settings-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

body.theme-special label {
    color: #6a5535;
}

body.theme-special .settings-card {
    background: #faf3e8;
    border-color: #ddd0b8;
}

body.theme-special .system-list li {
    background: #faf3e8;
    border-color: #ddd0b8;
}

body.theme-special .role-badge {
    background: #f0e4d0;
    border-color: #d8c8aa;
    color: #5a4020;
}

body.theme-special .result-item {
    background: var(--card);
    border-color: var(--line);
}

body.theme-special .result-item:hover {
    background: var(--surface);
}

body.theme-special .tree-toggle,
body.theme-special .system-toggle {
    background: #f0e4d0;
    border-color: #d8c8aa;
    color: #6a5535;
}


body.theme-special .alert.success {
    background: #e8f5ec;
    border-color: #b5dcc2;
    color: #1a6040;
}

body.theme-special .alert.error {
    background: #fce8e8;
    border-color: #e8b0b0;
    color: #8a2020;
}

body.theme-special .brand-mark {
    background: linear-gradient(145deg, #b25a1e 0%, #d07828 100%);
    box-shadow: 0 8px 20px rgba(178, 90, 30, 0.3);
}

body.theme-special .user-chip {
    background: #f0e4d0;
    border-color: #d8c8aa;
}

body.theme-special .sticky-editor-actions {
    background: var(--surface);
    border-color: var(--line);
}

body.theme-special .live-search-results {
    background: #fffdf7;
    border-color: #d8c8aa;
}

body.theme-special .live-search-item:hover {
    background: #f0e4d0;
}

body.theme-special .live-search-item {
    border-bottom-color: #ddd0b8;
}

body.theme-special .sortable-chosen .node-row {
    background: #f0e4d0;
}

body.theme-special .tree .sortable-drag .node-row {
    background: #e8d8be;
    border-color: #c8a870;
}

/* ================================================================
   TREE TOGGLE BUTTONS
   ================================================================ */
.tree-toggle,
.system-toggle {
    width: 22px;
    height: 22px;
    min-width: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 0;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    box-shadow: none;
    line-height: 1;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
    transition: background 0.12s ease;
}

.tree-toggle:hover,
.system-toggle:hover {
    background: var(--sidebar-node-hover);
    transform: none;
    box-shadow: none;
}

.system-link {
    color: inherit;
}

.system-link:hover {
    text-decoration: underline;
}

.tree-toggle-placeholder {
    display: inline-block;
    width: 22px;
    min-width: 22px;
    height: 22px;
    flex-shrink: 0;
}

/* Drag & drop states */
.sortable-ghost {
    opacity: 0.4;
}

.sortable-chosen .node-row {
    background: var(--sidebar-node-hover);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.tree .sortable-drag .node-row {
    background: var(--sidebar-node-hover);
    border: 2px solid var(--primary);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.tree .sortable-swap-highlight {
    outline: 2px dashed var(--primary);
    outline-offset: 2px;
    border-radius: 8px;
}

.tree li.drop-target > .node-row {
    background: var(--sidebar-node-hover);
    border-radius: 8px;
    box-shadow: inset 0 0 0 2px var(--primary);
}

.collapsed > ul.tree {
    display: none;
}

.system-block.collapsed > ul.tree {
    display: none;
}

/* ================================================================
   FORM ELEMENTS
   ================================================================ */
label {
    display: block;
    margin: 13px 0 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

input,
select,
textarea,
button {
    width: 100%;
    border-radius: 7px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--ink);
    padding: 8px 11px;
    font-size: 14px;
    font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    box-shadow: var(--ring);
    border-color: var(--primary);
}

button,
.btn {
    width: auto;
    border: 0;
    border-radius: 7px;
    padding: 7px 14px;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    box-shadow: none;
    transition: background 0.1s ease;
}

button:hover,
.btn:hover {
    background: var(--primary-strong);
    text-decoration: none;
}

button.secondary,
.btn.subtle {
    background: var(--btn-subtle-bg);
    color: var(--btn-subtle-ink);
    box-shadow: none;
}

button.secondary:hover,
.btn.subtle:hover {
    background: var(--btn-subtle-hover);
    box-shadow: none;
}

#ai-polish.ai-inactive {
    opacity: 0.48;
    filter: saturate(0.7);
}

#ai-polish.ai-inactive:hover {
    background: var(--btn-subtle-bg);
}

button.danger {
    margin-top: 12px;
    background: var(--danger);
}

button.danger:hover {
    background: #b91c1c;
}

.split-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

/* ================================================================
   EDITOR
   ================================================================ */
.editor-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.status-pill {
    border-radius: 999px;
    border: 1px solid #c5ecde;
    padding: 7px 10px;
    font-size: 12px;
    color: #0e6e56;
    background: #e8faf4;
    font-weight: 700;
}

.status-pill.is-live-recording {
    background: #ffecee;
    border-color: #f7bcc5;
    color: #9a2036;
}

.status-pill.is-live-voice {
    background: #eef7ff;
    border-color: #bfd8ff;
    color: #1f4fa8;
}

.sticky-editor-actions {
    position: sticky;
    top: var(--desktop-topbar-h);
    z-index: 10;
    margin: 0 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow-1);
    padding: 10px;
}

.editor-top-toolbar {
    margin-top: 8px;
    border-radius: 8px;
    border: 1px solid var(--line) !important;
    background: var(--card) !important;
}

.action-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.button-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding-right: 8px;
    margin-right: 4px;
    border-right: 1px solid var(--line);
}

.toolbar-group-save {
    border-right: 0;
    padding-right: 0;
    margin-right: 0;
}

.form-actions {
    margin-top: 14px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.hidden-action {
    display: none !important;
}

.action-row .danger {
    margin-top: 0;
}

button i.bi,
.btn i.bi,
.settings-tab i.bi {
    margin-right: 6px;
    font-size: 0.95em;
    vertical-align: -0.08em;
}

.media-size-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 7px 10px;
}

.media-size-inline input[type="range"] {
    width: 120px;
    margin: 0;
}

.editor-shell {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: visible;
}

.editor-shell .ql-toolbar.ql-snow {
    display: none;
}

.editor-shell .ql-container.ql-snow {
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 470px;
    font-size: 15px;
    line-height: 1.65;
}

.editor-shell .ql-editor img {
    max-width: 100%;
    border-radius: 12px;
    cursor: grab;
}

.editor-shell .ql-editor video {
    max-width: 100%;
    border-radius: 12px;
    cursor: grab;
}

.raw-html-editor {
    width: 100%;
    min-height: 520px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    background: var(--surface);
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ink);
}

.editor-shell .ql-editor img.is-selected {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.editor-shell .ql-editor video.is-selected {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.manual-content {
    margin-top: 14px;
    line-height: 1.65;
}

.manual-content p,
.manual-content h1,
.manual-content h2,
.manual-content h3,
.manual-content h4,
.manual-content h5,
.manual-content h6,
.manual-content ul,
.manual-content ol,
.manual-content pre,
.manual-content blockquote {
    margin: 0 0 0.72em;
}

.manual-content p:last-child,
.manual-content h1:last-child,
.manual-content h2:last-child,
.manual-content h3:last-child,
.manual-content h4:last-child,
.manual-content h5:last-child,
.manual-content h6:last-child,
.manual-content ul:last-child,
.manual-content ol:last-child,
.manual-content pre:last-child,
.manual-content blockquote:last-child {
    margin-bottom: 0;
}

.manual-content h1,
.manual-content h2,
.manual-content h3,
.manual-content h4,
.manual-content h5,
.manual-content h6,
.ql-editor h1,
.ql-editor h2,
.ql-editor h3,
.ql-editor h4,
.ql-editor h5,
.ql-editor h6 {
    scroll-margin-top: 92px;
}

.manual-content ul,
.manual-content ol {
    padding-left: 1.5em;
}

.manual-content li {
    margin: 0;
    padding: 0;
}

.manual-content blockquote,
.ql-editor blockquote {
    border-left: 4px solid var(--line);
    background: var(--surface);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--muted);
}

.manual-content pre,
.ql-editor pre {
    white-space: pre-wrap;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 12px;
    font-size: 13px;
    line-height: 1.55;
    font-family: Consolas, "Courier New", monospace;
}

.manual-content .ql-code-block-container,
.system-doc-content .ql-code-block-container,
.ql-editor .ql-code-block-container {
    white-space: pre-wrap;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 12px;
    margin: 0 0 0.72em;
    font-size: 13px;
    line-height: 1.55;
    font-family: Consolas, "Courier New", monospace;
}

.manual-content .ql-code-block-container .ql-code-block,
.system-doc-content .ql-code-block-container .ql-code-block,
.ql-editor .ql-code-block-container .ql-code-block {
    margin: 0;
    padding: 0;
    white-space: pre-wrap;
}

.manual-content :not(pre) > code,
.ql-editor :not(pre) > code {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    padding: 1px 6px;
    font-size: 0.92em;
    font-family: Consolas, "Courier New", monospace;
}

.manual-content .callout,
.manual-content .note,
.manual-content .warning,
.manual-content .tip,
.ql-editor .callout,
.ql-editor .note,
.ql-editor .warning,
.ql-editor .tip {
    border: 1px solid var(--line);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    padding: 10px 12px;
    margin: 0 0 0.72em;
    background: var(--surface);
}

.manual-content .ql-size-small,
.ql-editor .ql-size-small {
    font-size: 0.82em;
}

.manual-content .ql-size-large,
.ql-editor .ql-size-large {
    font-size: 1.32em;
}

.manual-content .ql-size-huge,
.ql-editor .ql-size-huge {
    font-size: 1.72em;
}

.manual-content p:empty::before {
    content: "\00a0";
}

.manual-content img,
.manual-content video {
    max-width: 100%;
    border-radius: 12px;
}

.manual-content video,
.system-doc-content video,
.editor-shell .ql-editor video {
    max-height: calc(100vh - 150px);
    height: auto;
    object-fit: contain;
}

.manual-content table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.system-doc-content table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.manual-content td,
.manual-content th {
    border: 1px solid var(--line);
    padding: 8px 10px;
}

.manual-content th {
    background: var(--surface);
    font-weight: 700;
}

.manual-content table.doc-table-sortable th.sortable-col {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 20px;
}

.manual-content table.doc-table-sortable-nohead td.sortable-col {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 20px;
    font-weight: 700;
    background: var(--surface);
}

.manual-content table.doc-table-sortable-nohead td.sortable-col::after {
    content: '\2195';
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 12px;
}

.manual-content table.doc-table-sortable th.sortable-col::after {
    content: '\2195';
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 12px;
}

.manual-content table.doc-table-sortable th.sorted-asc::after {
    content: '\2191';
    color: var(--primary);
}

.manual-content table.doc-table-sortable th.sorted-desc::after {
    content: '\2193';
    color: var(--primary);
}

.manual-content table.doc-table-sortable-nohead td.sorted-asc::after {
    content: '\2191';
    color: var(--primary);
}

.manual-content table.doc-table-sortable-nohead td.sorted-desc::after {
    content: '\2193';
    color: var(--primary);
}

.manual-content tbody tr:nth-child(even) {
    background: var(--surface);
}

body.theme-dark .table-up-menu,
body.theme-dark .table-up-align {
    background: #1a2538;
    color: #e4ecf7;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.42);
}

body.theme-dark .table-up-menu .table-up-menu__item,
body.theme-dark .table-up-align .table-up-align__item {
    color: #e4ecf7;
}

body.theme-dark .table-up-menu .table-up-menu__item:hover,
body.theme-dark .table-up-align .table-up-align__item:hover {
    background: #2a3a56;
}

body.theme-dark .table-up-menu .is-break,
body.theme-dark .table-up-align .is-break {
    background-color: #3a4f72;
}

/* ================================================================
   RECORDING / VOICE
   ================================================================ */
.record-panel {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface);
    display: none;
}

.record-panel.open {
    display: block;
}

.record-mode-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 26, 44, 0.44);
    display: grid;
    place-items: center;
    z-index: 100;
}

.record-mode-modal[hidden] {
    display: none !important;
}

.record-mode-dialog {
    width: min(760px, calc(100% - 24px));
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
    padding: 20px;
    max-height: calc(100vh - 24px);
    overflow: auto;
}

.record-device-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.record-device-row button {
    margin: 0;
}

#record-camera-name {
    margin: 6px 0 0;
}

.record-options {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin: 8px 0;
}

.record-preview {
    width: 100%;
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    display: none;
    min-height: 220px;
    max-height: 44vh;
    background: #0f1726;
}

.record-placeholder {
    margin-top: 10px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 14px;
}

.placeholder-art {
    width: 100%;
    height: 180px;
    border-radius: 8px;
    margin-bottom: 10px;
    background: var(--bg);
}

.record-modal-actions {
    margin-top: 12px;
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding-top: 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}

.media-library-list {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    max-height: 42vh;
    overflow: auto;
    padding: 6px;
    display: grid;
    gap: 6px;
}

.media-library-item {
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    padding: 8px 10px;
    display: grid;
    gap: 2px;
}

.media-library-head {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.media-library-text {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.media-library-thumb {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--surface);
    border: 1px solid var(--line);
}

.media-library-thumb-file {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

.media-library-item.is-selected {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
}

.media-library-title {
    font-weight: 700;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.media-library-meta {
    font-size: 12px;
    color: var(--muted);
}

.ai-progress-dialog {
    text-align: center;
    max-width: 680px;
}

.progress-meter {
    margin: 12px auto 0;
    width: min(520px, 100%);
    height: 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    overflow: hidden;
}

.progress-meter-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #4bb39f);
    transition: width 0.18s ease;
}

.ai-spinner {
    width: 54px;
    height: 54px;
    border: 4px solid var(--line);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 14px auto;
    animation: spin 0.9s linear infinite;
}

.voice-meter {
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    padding: 10px;
    color: var(--muted);
    font-weight: 600;
}

.voice-btn {
    font-weight: 700;
}

.voice-start {
    background: #138a56;
    color: #fff;
}

.voice-start:hover {
    background: #0f6f46;
}

.voice-pause {
    background: #f2b436 !important;
    color: #1f2430 !important;
}

.voice-resume {
    background: #1f78e0 !important;
    color: #fff !important;
}

.voice-stop {
    background: #c93646 !important;
    color: #fff !important;
}

button.is-live-recording,
.btn.is-live-recording {
    background: #cc3648 !important;
    color: #fff;
    animation: pulseRec 1.05s infinite;
}

button.is-live-voice,
.btn.is-live-voice {
    background: #1e5bd7 !important;
    color: #fff;
    animation: pulseVoice 1.2s infinite;
}

/* ================================================================
   SEARCH RESULTS
   ================================================================ */
.results-list {
    margin-top: 14px;
    display: grid;
    gap: 10px;
}

.result-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--card);
    display: block;
    transition: background 0.1s ease;
}

.result-item span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.result-item:hover {
    background: var(--surface);
    text-decoration: none;
}

.system-doc-list {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}

.system-doc-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    padding: 10px 12px;
}

.system-doc-item h3 {
    margin: 0 0 8px;
    font-size: 20px;
}

.system-doc-item h3 a {
    color: inherit;
}

.system-doc-content {
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.system-doc-item.depth-1 {
    margin-left: 14px;
}

.system-doc-item.depth-2 {
    margin-left: 28px;
}

.system-doc-item.depth-3 {
    margin-left: 42px;
}

.system-doc-item.depth-4 {
    margin-left: 56px;
}

.system-doc-item.depth-5 {
    margin-left: 70px;
}

.empty-state {
    margin-top: 12px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface);
    color: var(--muted);
}

/* ================================================================
   ALERTS / FLASH
   ================================================================ */
.alert {
    border-radius: 7px;
    padding: 10px 12px;
    border: 1px solid transparent;
    margin: 0;
    font-size: 14px;
    box-shadow: var(--shadow-2);
}

.alert.success {
    background: #e7f9f1;
    border-color: #c2ebda;
    color: #19654f;
}

.alert.error {
    background: #ffe8ec;
    border-color: #f7c8d1;
    color: #7f2a3a;
}

.alert.fade-out {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.45s ease, transform 0.45s ease;
}

.flash-wrap {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 120;
    width: min(520px, calc(100vw - 28px));
    pointer-events: none;
}

/* ================================================================
   LIVE SEARCH
   ================================================================ */
.live-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 60;
    max-height: 360px;
    overflow: auto;
}

.live-search-item {
    display: block;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}

.live-search-item:last-child {
    border-bottom: 0;
}

.live-search-item span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}

.live-search-item:hover {
    background: var(--sidebar-node-hover);
    text-decoration: none;
}

.live-search-empty {
    padding: 10px 12px;
    color: var(--muted);
}

/* ================================================================
   ATTACHMENTS / CHECKBOXES
   ================================================================ */
.attachments {
    margin-top: 10px;
    padding-left: 20px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.checkbox-row input {
    width: auto;
    margin: 0;
}

.inline-check {
    margin: 0;
}

/* ================================================================
   SETTINGS
   ================================================================ */
.user-row-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.compact-head {
    margin-bottom: 0;
    min-width: 170px;
}

.section-sep {
    margin: 18px 0;
    border: 0;
    border-top: 1px solid var(--line);
}

.system-list {
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

.compact-list {
    margin-top: 10px;
}

.system-list li {
    margin-bottom: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 10px 12px;
}

.compact-list li {
    margin-bottom: 8px;
    padding: 9px 10px;
}

.system-row-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}

.system-create-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: 8px;
    align-items: center;
}

.system-create-row input[type="text"] {
    margin: 0;
}

.compact-row-form {
    margin: 0;
}

.system-row-main {
    grid-template-columns: minmax(130px, 260px) auto auto;
}

.system-name-input {
    max-width: 260px;
}

.system-delete-form {
    margin-top: 10px;
}

.settings-row-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.settings-row-inline .system-row-form {
    margin: 0;
}

.settings-row-inline .system-delete-form {
    margin-top: 0;
}

.settings-row-inline .danger {
    margin-top: 0;
}

.system-share-row {
    margin-top: 8px;
    display: grid;
    grid-template-columns: auto minmax(220px, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.system-share-row input[type="text"] {
    max-width: 100%;
    margin: 0;
}

.system-share-label,
.system-share-note {
    white-space: nowrap;
}

.user-row-inline {
    justify-content: space-between;
    flex-wrap: nowrap;
}

.user-password-form {
    grid-template-columns: minmax(150px, 220px) auto;
    justify-content: start;
}

.user-password-form input[type="password"] {
    max-width: 220px;
}

.settings-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: var(--surface);
}

.compact-card {
    padding: 11px 12px;
}

.settings-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 10px 0 14px;
}

.settings-tab {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 14px;
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    transition: background 0.12s ease, color 0.12s ease;
}

.settings-tab:hover {
    text-decoration: none;
    background: var(--sidebar-node-hover);
    color: var(--ink);
}

.settings-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ================================================================
   MEDIA MANAGER
   ================================================================ */
.media-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.media-summary-grid > div {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
    background: var(--surface);
    display: grid;
    gap: 2px;
}

.media-search-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.media-search-form input[type="text"] {
    max-width: 520px;
}

.media-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 9px;
}

.media-item-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 10px;
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
}

.media-select-row {
    align-self: center;
}

.media-thumb-wrap {
    width: 160px;
}

.media-thumb {
    width: 160px;
    max-height: 100px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #0f1726;
}

.media-file-link {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
    padding: 8px 10px;
    font-weight: 600;
}

.media-meta {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.media-meta strong {
    overflow-wrap: anywhere;
}

.media-delete-form {
    margin: 0;
}

.logs-list {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.log-entry {
    padding: 10px 12px;
}

.log-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.log-meta {
    margin-bottom: 6px;
    font-size: 12px;
}

.log-payload {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 12px;
    line-height: 1.35;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 8px;
    max-height: 260px;
    overflow: auto;
}

.revision-modal-dialog {
    max-width: 820px;
}

.revision-list {
    display: grid;
    gap: 8px;
    max-height: 56vh;
    overflow: auto;
    padding-right: 2px;
}

.revision-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.revision-item-meta {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.revision-item-meta strong {
    font-size: 13px;
}

.revision-item-meta .muted {
    font-size: 12px;
    overflow-wrap: anywhere;
}

.revision-item-actions {
    margin: 0;
}

.compact-card label {
    margin: 9px 0 4px;
    font-size: 12px;
}

.split-form-tight {
    gap: 8px;
}

/* ================================================================
   ROLE BADGES
   ================================================================ */
.role-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    text-transform: uppercase;
    white-space: nowrap;
}

.role-editor {
    background: #eafaf4;
    border-color: #c9ecd9;
    color: #166a51;
}

.role-viewer {
    background: #f1f6ff;
    border-color: #d6e1f3;
    color: #395476;
}

.role-admin {
    background: #fff5eb;
    border-color: #f3ddbf;
    color: #8d5418;
}

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

.hidden-input {
    display: none;
}

.hidden-inline-form {
    display: none;
}

/* ================================================================
   LOGIN
   ================================================================ */
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    border-radius: 12px;
    box-shadow: var(--shadow-2);
}

.login-form label {
    margin-top: 10px;
}

.login-form .form-actions {
    margin-top: 10px;
}

/* ================================================================
   FOOTER
   ================================================================ */
.app-footer {
    text-align: center;
    padding: 10px 14px 18px;
    color: var(--muted);
    font-size: 12px;
}

/* ================================================================
   ANIMATIONS
   ================================================================ */
@keyframes pulseRec {
    0% { box-shadow: 0 0 0 0 rgba(204, 54, 72, 0.35); }
    100% { box-shadow: 0 0 0 10px rgba(204, 54, 72, 0); }
}

@keyframes pulseVoice {
    0% { box-shadow: 0 0 0 0 rgba(30, 91, 215, 0.35); }
    100% { box-shadow: 0 0 0 10px rgba(30, 91, 215, 0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 1080px) {
    :root {
        --mobile-topbar-h: 64px;
    }

    .topbar {
        grid-template-columns: 1fr auto 1fr;
        gap: 8px;
        align-items: center;
        min-height: var(--mobile-topbar-h);
        padding: 8px 12px;
        z-index: 130;
    }

    .brand-wrap {
        grid-column: 2;
        grid-row: 1;
        justify-self: center;
    }

    .brand-wrap .muted {
        display: none;
    }

    .mobile-header-toggle {
        display: inline-flex !important;
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
    }

    .mobile-sidebar-toggle {
        display: inline-flex !important;
        grid-column: 1;
        grid-row: 1;
        justify-self: start;
    }

    .top-search,
    .topbar-actions,
    .sidebar-head {
        display: none !important;
    }

    .mobile-header-panel {
        position: fixed;
        top: 62px;
        right: 12px;
        left: 12px;
        z-index: 96;
        border: 1px solid var(--line);
        border-radius: 12px;
        background: var(--card);
        box-shadow: var(--shadow-2);
        padding: 10px;
        display: block;
    }

    .mobile-header-panel[hidden] {
        display: none !important;
    }

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

    .mobile-search {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
    }

    .mobile-search input {
        margin: 0;
    }

    .record-mode-dialog {
        width: calc(100% - 10px);
        max-height: calc(100vh - 8px);
        padding: 10px 12px;
    }

    .record-preview {
        min-height: 96px;
        max-height: 22vh;
    }

    .placeholder-art {
        height: 78px;
    }

    .record-modal-actions {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .record-mode-modal {
        align-items: center;
        place-items: center;
        overflow: auto;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    #ai-progress-modal {
        align-items: center;
        place-items: center;
    }

    .sticky-editor-actions {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .sticky-editor-actions .action-row {
        flex-wrap: nowrap;
        width: max-content;
        min-width: 100%;
    }

    .toolbar-group-media,
    .toolbar-group-editor,
    .toolbar-group-history,
    .toolbar-group-save {
        display: inline-flex;
        align-items: center;
        flex-wrap: nowrap;
        gap: 6px;
    }

    .toolbar-group-media button,
    .toolbar-group-editor button,
    .toolbar-group-history button,
    .toolbar-group-save button,
    .toolbar-group-save .btn {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .mobile-panel-actions {
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .layout {
        grid-template-columns: 1fr;
        padding: 0;
        gap: 0;
    }

    body.sidebar-collapsed .layout {
        grid-template-columns: 1fr;
    }

    .sidebar-handle-toggle {
        display: none !important;
    }

    .drag-handle {
        width: 22px;
        min-width: 22px;
        height: 22px;
    }

    .page-index-panel {
        top: 70px;
        right: 0;
        left: auto;
        width: min(220px, calc(100vw - 18px));
        max-width: calc(100vw - 18px);
        z-index: 102;
    }

    body.is-edit-mode .page-index-panel {
        top: calc(var(--mobile-topbar-h) + 96px);
    }

    .page-index-nav {
        max-height: 70vh;
    }

    body.is-edit-mode .page-index-nav {
        max-height: calc(100vh - var(--mobile-topbar-h) - 170px);
    }

    .page-index-panel.is-collapsed {
        width: 45px;
        left: auto;
    }

    .sidebar {
        position: fixed;
        top: var(--mobile-topbar-h);
        left: 0;
        width: min(340px, calc(100vw - 34px));
        max-height: calc(100vh - var(--mobile-topbar-h));
        height: calc(100vh - var(--mobile-topbar-h));
        z-index: 90;
        border-radius: 0;
        transform: translateX(calc(-100% - 8px));
        transition: transform 0.22s ease;
        box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
        overflow: auto;
        z-index: 100;
    }

    body:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
    }

    body:not(.sidebar-collapsed)::after {
        display: none;
    }

    body:not(.sidebar-collapsed) .page-index-panel {
        display: none;
    }

    body.mobile-header-open .sidebar-handle-toggle,
    body.mobile-header-open .page-index-panel {
        opacity: 0;
        pointer-events: none;
    }

    .content,
    .system-doc-item,
    .manual-content,
    .system-doc-content {
        min-width: 0;
        max-width: 100%;
    }

    .content {
        overflow-x: hidden;
    }

    .content.card {
        padding: 12px;
    }

    .manual-content,
    .system-doc-content {
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .manual-content img,
    .manual-content video,
    .system-doc-content img,
    .system-doc-content video {
        max-width: 100% !important;
        height: auto;
    }

    .manual-content video,
    .system-doc-content video,
    .editor-shell .ql-editor video {
        max-height: 75vh;
    }

    .manual-content table,
    .system-doc-content table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
    }

    .manual-content pre,
    .system-doc-content pre {
        overflow-x: auto;
        max-width: 100%;
    }

    body.mobile-header-open::before {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(10, 18, 30, 0.24);
        z-index: 80;
    }

    body.mobile-header-open .page-index-panel {
        opacity: 0;
        pointer-events: none;
    }

    .quick-jump {
        display: none;
    }

    body.mobile-header-open {
        overflow: hidden;
    }

    .split-form {
        grid-template-columns: 1fr;
    }

    .sticky-editor-actions {
        position: -webkit-sticky;
        position: sticky;
        top: var(--mobile-topbar-h);
        z-index: 95;
        border-radius: 0;
        margin: 0 0 8px;
        background: var(--surface);
    }

    .editor-top-toolbar.ql-toolbar.ql-snow {
        display: flex !important;
        flex-wrap: nowrap;
        overflow: visible;
        white-space: nowrap;
        padding: 6px;
        gap: 2px;
        width: max-content;
        min-width: 100%;
    }

    .editor-top-toolbar.ql-toolbar.ql-snow .ql-formats {
        margin-right: 6px;
        white-space: nowrap;
        display: inline-flex;
        flex-wrap: nowrap;
        align-items: center;
        flex: 0 0 auto;
    }

    .editor-top-toolbar.ql-toolbar.ql-snow button,
    .editor-top-toolbar.ql-toolbar.ql-snow .ql-picker {
        flex: 0 0 auto;
    }

    .content {
        overflow: visible;
    }

    .media-size-inline {
        width: 100%;
        justify-content: space-between;
    }

    .system-row-form {
        grid-template-columns: 1fr;
    }

    .system-create-row {
        grid-template-columns: 1fr auto;
    }

    .system-create-row button {
        grid-column: 1 / span 2;
        justify-self: start;
    }

    .media-summary-grid {
        grid-template-columns: repeat(2, minmax(110px, 1fr));
    }

    .media-item-card {
        grid-template-columns: 1fr;
    }

    .media-thumb-wrap,
    .media-thumb {
        width: 100%;
        max-height: 180px;
    }

    .system-row-main {
        grid-template-columns: 1fr;
    }

    .system-share-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .system-share-label,
    .system-share-note {
        white-space: normal;
    }

    .user-password-form {
        grid-template-columns: 1fr;
    }

    .settings-row-inline {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .compact-head {
        min-width: 0;
        width: 100%;
    }

    .system-doc-item.depth-1,
    .system-doc-item.depth-2,
    .system-doc-item.depth-3,
    .system-doc-item.depth-4,
    .system-doc-item.depth-5 {
        margin-left: 0;
    }
}
