/* SuriVerse - Modern Knowledge Base Styles */
/* Catppuccin Macchiato-Rosewater Theme with Adwaita GTK-inspired design */

:root {
    /* Colors - Catppuccin Macchiato palette with Rosewater accent */
    --bg-primary: #24273a;       /* Base */
    --bg-secondary: #1e2030;     /* Mantle */
    --bg-tertiary: #181926;      /* Crust */
    --bg-hover: #363a4f;         /* Surface0 */
    --bg-active: #494d64;        /* Surface1 */
    --bg-surface2: #5b6078;      /* Surface2 */

    --text-primary: #cad3f5;     /* Text */
    --text-secondary: #b8c0e0;   /* Subtext1 */
    --text-muted: #a5adcb;       /* Subtext0 */
    --text-dim: #939ab7;         /* Overlay2 */

    /* Rosewater accent for primary actions */
    --accent: #f4dbd6;           /* Rosewater */
    --accent-hover: #f5e0dc;     /* Flamingo (lighter rosewater) */
    --accent-dim: rgba(244, 219, 214, 0.15);
    --accent-text: #24273a;      /* Dark text on accent */

    /* Secondary accent colors */
    --accent-blue: #8aadf4;      /* Blue */
    --accent-pink: #f5bde6;      /* Pink */
    --accent-mauve: #c6a0f6;     /* Mauve */
    --accent-teal: #8bd5ca;      /* Teal */

    /* Status colors */
    --success: #a6da95;          /* Green */
    --warning: #eed49f;          /* Yellow */
    --danger: #ed8796;           /* Red */
    --info: #8aadf4;             /* Blue */

    --border: #363a4f;           /* Surface0 */
    --border-light: #494d64;     /* Surface1 */

    /* Sizing */
    --sidebar-width: 300px;
    --toolbar-height: 52px;
    --header-height: 60px;

    /* Border radius - Adwaita GTK-inspired rounded design */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;

    /* Transitions - Smooth Adwaita-style animations */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Shadows - Softer, more modern */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.15);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.2);
    --shadow-glow: 0 0 20px rgba(244, 219, 214, 0.15);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal), min-width var(--transition-normal), width var(--transition-normal), visibility var(--transition-normal);
    overflow: hidden;
}

.sidebar.collapsed {
    min-width: 0;
    width: 0;
    transform: translateX(-100%);
    visibility: hidden;
    border-right: none;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.sidebar-toggle {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Sidebar Actions */
.sidebar-actions {
    padding: 12px;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-actions .btn {
    flex: 1;
    justify-content: center;
}

/* File Tree */
.file-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

.tree-list {
    list-style: none;
}

.tree-list.root {
    padding: 0 8px;
}

.tree-item {
    user-select: none;
}

/* Folder row layout - container for toggle and content */
.folder-row {
    position: relative;
    display: flex;
    align-items: center;
}

/* For non-folder items, just show the link */
.tree-item:not(.folder) {
    display: block;
}

.tree-item-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
    width: 100%;
}

/* For folder rows, add left padding for the toggle arrow */
.folder-row > .tree-item-content,
.folder-row > a.tree-item-content {
    padding-left: 32px;
}

.tree-item-content:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tree-item.active > .folder-row > .tree-item-content,
.tree-item.active > .folder-row > a.tree-item-content,
.tree-item.active > .tree-item-content,
.tree-item.active > a.tree-item-content {
    background: var(--accent-dim);
    color: var(--accent);
}

.tree-link {
    text-decoration: none;
    color: inherit;
}

/* Clickable folder links (folders with index.md) - now same as tree-item-content */
a.folder-link {
    text-decoration: none;
    color: inherit;
}

a.folder-link:hover {
    color: var(--text-primary);
}

a.folder-link:hover .tree-name {
    text-decoration: underline;
}

.folder-toggle {
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0; /* Fills parent height via top/bottom anchoring */
    width: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast);
    cursor: pointer;
    z-index: 10;
}

.folder-toggle:hover {
    color: var(--text-primary);
}

.folder-toggle-spacer {
    display: none;
}

.tree-item.folder.expanded > .folder-row > .folder-toggle {
    transform: rotate(90deg);
}

.tree-item.folder:not(.expanded) > .tree-list {
    display: none;
}

/* Nested list takes full width */
.tree-item.folder > .tree-list {
    width: 100%;
}

.tree-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

.tree-name {
    flex: 1;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-list .tree-list {
    padding-left: 20px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.user-name {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-badge {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 8px;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

/* Desktop sidebar open button - shown when sidebar is collapsed */
.sidebar-open-btn {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    z-index: 50;
    box-shadow: var(--shadow-md);
}

.sidebar-open-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Mobile Header - Hidden on desktop */
.mobile-header {
    display: none;
    height: var(--header-height);
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.mobile-menu-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.mobile-header-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Editor Toolbar */
.editor-toolbar {
    height: var(--toolbar-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

.toolbar-btn {
    height: 38px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.toolbar-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.toolbar-btn svg {
    flex-shrink: 0;
}

/* Content Wrapper */
.content-wrapper {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Editor Container */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.markdown-editor {
    flex: 1;
    width: 100%;
    padding: 24px 32px;
    background: var(--bg-primary);
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9375rem;
    line-height: 1.7;
    resize: none;
    outline: none;
}

.markdown-editor::placeholder {
    color: var(--text-muted);
}

/* Drag and drop styling */
.markdown-editor.drag-over {
    border: 2px dashed var(--accent);
    background: var(--accent-dim);
}

/* Content View & Preview */
.content-view,
.content-preview {
    flex: 1;
    overflow-y: auto;
    padding: 32px 48px;
    min-width: 0;
}

.content-view.hidden,
.content-preview.hidden,
.editor-container.hidden {
    display: none;
}

/* Split Mode */
.content-wrapper.split-mode .editor-container,
.content-wrapper.split-mode .content-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.content-wrapper.split-mode .editor-container {
    border-right: 1px solid var(--border);
}

.content-wrapper.split-mode .content-view {
    display: none;
}

.content-wrapper.split-mode .content-preview {
    display: block;
}

/* View Mode */
.content-wrapper.view-mode .editor-container {
    display: none;
}

.content-wrapper.view-mode .content-view {
    display: block;
}

.content-wrapper.view-mode .content-preview {
    display: none;
}

/* Edit Mode */
.content-wrapper.edit-mode .editor-container {
    display: flex;
}

.content-wrapper.edit-mode .content-view {
    display: none;
}

.content-wrapper.edit-mode .content-preview {
    display: none;
}

/* Prose Styling */
.prose {
    max-width: 800px;
    margin: 0 auto;
    color: var(--text-primary);
}

.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.3;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.prose h1:first-child,
.prose h2:first-child,
.prose h3:first-child {
    margin-top: 0;
}

.prose h1 {
    font-size: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3em;
}

.prose h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.2em;
}

.prose h3 { font-size: 1.25rem; }
.prose h4 { font-size: 1.125rem; }
.prose h5 { font-size: 1rem; }
.prose h6 { font-size: 0.875rem; color: var(--text-secondary); }

.prose p {
    margin-bottom: 1em;
}

.prose ul, .prose ol {
    margin-bottom: 1em;
    padding-left: 1.5em;
}

.prose li {
    margin-bottom: 0.25em;
}

.prose li > ul, .prose li > ol {
    margin-top: 0.25em;
    margin-bottom: 0;
}

.prose blockquote {
    margin: 1em 0;
    padding: 0.75em 1.25em;
    border-left: 4px solid var(--accent);
    background: var(--bg-secondary);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.prose blockquote p:last-child {
    margin-bottom: 0;
}

.prose code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    padding: 0.25em 0.5em;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    color: var(--accent);
}

.prose pre {
    margin: 1em 0;
    padding: 1.25em;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    overflow-x: auto;
}

.prose pre code {
    padding: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* Note: Table styles moved to Enhanced Table Styling section below */

.prose img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-lg);
    margin: 1.5em 0;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.prose img:hover {
    transform: scale(1.01);
    box-shadow: var(--shadow-lg);
}

.prose hr {
    margin: 2em 0;
    border: none;
    border-top: 1px solid var(--border);
}

.prose a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.prose a:hover {
    color: var(--accent-hover);
}

/* Task lists */
.prose input[type="checkbox"] {
    margin-right: 0.5em;
    accent-color: var(--accent);
}

/* Buttons - Adwaita GTK-inspired */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-small {
    padding: 8px 14px;
    font-size: 0.8125rem;
    border-radius: var(--radius-sm);
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
}

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

.btn-danger {
    background: var(--danger);
    color: var(--bg-primary);
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    filter: brightness(1.1);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* Modal - Adwaita-inspired */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    width: 420px;
    max-width: 90vw;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
}

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

.modal-title {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

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

/* Form Elements */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9375rem;
    transition: all var(--transition-fast);
}

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

.form-input::placeholder {
    color: var(--text-muted);
}

/* Context Menu */
.context-menu {
    position: fixed;
    min-width: 180px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    z-index: 1001;
}

.context-menu.hidden {
    display: none;
}

.context-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.context-menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.context-menu-item.context-menu-danger:hover {
    background: rgba(237, 135, 150, 0.15);
    color: var(--danger);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 22px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1002;
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.hidden {
    display: none;
}

.toast.success {
    border-color: var(--success);
    background: linear-gradient(135deg, var(--bg-secondary), rgba(166, 218, 149, 0.08));
}

.toast.error {
    border-color: var(--danger);
    background: linear-gradient(135deg, var(--bg-secondary), rgba(237, 135, 150, 0.08));
}

.toast-message {
    font-size: 0.875rem;
    color: var(--text-primary);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar Styling - Modern rounded */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* ==========================================
 *   Custom Video Player Styling - Adwaita GTK
 *   ========================================== */
.prose video {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-lg);
    background: var(--bg-tertiary);
    box-shadow: var(--shadow-md);
    margin: 1.5em 0;
}

/* Video container for custom controls */
.video-container {
    position: relative;
    width: 100%;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-tertiary);
    box-shadow: var(--shadow-md);
    margin: 1.5em 0;
}

.video-container video {
    width: 100%;
    display: block;
    border-radius: var(--radius-lg);
    margin: 0;
    box-shadow: none;
}

/* Style native video controls */
video::-webkit-media-controls-panel {
    background: linear-gradient(transparent, rgba(30, 32, 48, 0.95));
    padding: 10px;
}

video::-webkit-media-controls-play-button,
video::-webkit-media-controls-mute-button,
video::-webkit-media-controls-fullscreen-button {
    border-radius: var(--radius-md);
    background: rgba(244, 219, 214, 0.2);
    transition: all var(--transition-fast);
}

video::-webkit-media-controls-play-button:hover,
video::-webkit-media-controls-mute-button:hover,
video::-webkit-media-controls-fullscreen-button:hover {
    background: rgba(244, 219, 214, 0.35);
}

video::-webkit-media-controls-timeline {
    border-radius: var(--radius-full);
    background: var(--bg-hover);
    height: 6px;
}

video::-webkit-media-controls-current-time-display,
video::-webkit-media-controls-time-remaining-display {
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
}

video::-webkit-media-controls-volume-slider {
    border-radius: var(--radius-full);
    background: var(--bg-hover);
}

/* ==========================================
 *   Custom Audio Player Styling - Adwaita GTK
 *   ========================================== */
.prose audio {
    width: 100%;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    margin: 1.5em 0;
    box-shadow: var(--shadow-md);
}

/* Audio container wrapper for better styling */
.audio-container {
    width: 100%;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    margin: 1.5em 0;
}

.audio-container audio {
    width: 100%;
    margin: 0;
    box-shadow: none;
    background: transparent;
}

/* Style native audio controls */
audio::-webkit-media-controls-panel {
    background: transparent;
    padding: 8px 0;
}

audio::-webkit-media-controls-play-button {
    border-radius: var(--radius-full);
    background: var(--accent);
    color: var(--accent-text);
    width: 40px;
    height: 40px;
    transition: all var(--transition-fast);
}

audio::-webkit-media-controls-play-button:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

audio::-webkit-media-controls-mute-button {
    border-radius: var(--radius-md);
    background: var(--bg-hover);
    transition: all var(--transition-fast);
}

audio::-webkit-media-controls-mute-button:hover {
    background: var(--bg-active);
}

audio::-webkit-media-controls-timeline {
    border-radius: var(--radius-full);
    background: var(--bg-hover);
    height: 6px;
}

audio::-webkit-media-controls-current-time-display,
audio::-webkit-media-controls-time-remaining-display {
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
}

audio::-webkit-media-controls-volume-slider {
    border-radius: var(--radius-full);
    background: var(--bg-hover);
}

/* Firefox audio/video styling */
audio::-moz-range-track,
video::-moz-range-track {
    background: var(--bg-hover);
    border-radius: var(--radius-full);
}

audio::-moz-range-thumb,
video::-moz-range-thumb {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-full);
}

/* ==========================================
 *   Enhanced Table Styling
 *   ========================================== */
.prose table {
    width: 100%;
    margin: 1.5em 0;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.prose th, .prose td {
    padding: 0.875em 1.25em;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.prose th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.prose tr:last-child td {
    border-bottom: none;
}

.prose tbody tr {
    background: var(--bg-primary);
    transition: background var(--transition-fast);
}

.prose tbody tr:hover {
    background: var(--bg-hover);
}

/* ==========================================
 *   Mobile Responsive Design
 *   ========================================== */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
        --header-height: 56px;
        --toolbar-height: 48px;
    }

    /* Mobile sidebar: 85% width for smaller screens, capped at 320px for larger phones/tablets
     *       This ensures the sidebar doesn't take up too much space while remaining usable */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 85%;
        max-width: 320px;
        z-index: 100;
        background: var(--bg-secondary);
        box-shadow: var(--shadow-lg);
        transition: transform var(--transition-normal), visibility var(--transition-normal);
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
        box-shadow: none;
        visibility: hidden;
    }

    /* Mobile menu overlay - covers the content area when sidebar is open */
    .sidebar:not(.collapsed)::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: -1; /* Behind sidebar content but visible to user */
        pointer-events: auto;
    }

    /* Better touch targets on mobile */
    .tree-item-content {
        padding: 12px 16px;
        min-height: 44px;
    }

    /* For folder rows on mobile, add more left padding for larger toggle */
    .folder-row > .tree-item-content,
    .folder-row > a.tree-item-content {
        padding-left: 44px;
    }

    .folder-toggle {
        width: 36px;
        min-height: 44px;
        left: 4px;
    }

    .btn {
        min-height: 44px;
        padding: 12px 20px;
    }

    .btn-small {
        min-height: 40px;
        padding: 10px 16px;
    }

    .toolbar-btn {
        min-height: 44px;
        padding: 0 16px;
    }

    /* Mobile sidebar header */
    .sidebar-header {
        padding: 0 16px;
        position: sticky;
        top: 0;
        background: var(--bg-secondary);
        z-index: 10;
    }

    /* Mobile toggle button - always visible */
    .sidebar-toggle {
        width: 44px;
        height: 44px;
    }

    /* Sidebar footer sticky at bottom on mobile */
    .sidebar-footer {
        position: sticky;
        bottom: 0;
        background: var(--bg-secondary);
        padding: 12px 16px;
        border-top: 1px solid var(--border);
    }

    /* Show mobile header on mobile */
    .mobile-header {
        display: flex;
    }

    /* Content padding on mobile */
    .content-view,
    .content-preview {
        padding: 20px 16px;
    }

    .markdown-editor {
        padding: 20px 16px;
        font-size: 16px; /* Prevent iOS zoom */
    }

    /* Modal mobile adjustments */
    .modal {
        width: 95vw;
        max-height: 90vh;
        overflow-y: auto;
        border-radius: var(--radius-lg);
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        flex-direction: column;
        gap: 10px;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Form inputs - larger touch targets */
    .form-input {
        padding: 14px 16px;
        font-size: 16px; /* Prevent iOS zoom */
        min-height: 48px;
    }

    /* Toast on mobile */
    .toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
        text-align: center;
    }

    /* Split mode on mobile - stack vertically */
    .content-wrapper.split-mode .editor-container,
    .content-wrapper.split-mode .content-preview {
        flex: none;
        width: 100%;
    }

    .content-wrapper.split-mode {
        flex-direction: column;
    }

    .content-wrapper.split-mode .editor-container {
        border-right: none;
        border-bottom: 1px solid var(--border);
        height: 50%;
    }

    .content-wrapper.split-mode .content-preview {
        height: 50%;
    }

    /* Prose adjustments for mobile */
    .prose {
        max-width: 100%;
    }

    .prose h1 {
        font-size: 1.625rem;
    }

    .prose h2 {
        font-size: 1.375rem;
    }

    .prose h3 {
        font-size: 1.125rem;
    }

    .prose pre {
        padding: 1em;
        font-size: 0.8125rem;
        border-radius: var(--radius-md);
    }

    /* Tables on mobile - wrap in scrollable container */
    .prose table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .prose th, .prose td {
        padding: 0.75em 1em;
    }

    /* Audio/video on mobile */
    .prose audio,
    .prose video {
        border-radius: var(--radius-md);
    }

    .audio-container {
        padding: 12px 16px;
        border-radius: var(--radius-md);
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .sidebar-actions {
        flex-direction: column;
        gap: 8px;
    }

    .sidebar-actions .btn {
        width: 100%;
    }

    .toolbar-group {
        gap: 2px;
    }

    .toolbar-btn span {
        display: none;
    }

    .toolbar-btn {
        padding: 0 12px;
    }

    .editor-toolbar {
        padding: 0 12px;
    }
}

/* Tablet portrait */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }

    .content-view,
    .content-preview {
        padding: 28px 32px;
    }
}

/* ==========================================
 *   Dark Mode Focus States for Accessibility
 *   ========================================== */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn:focus-visible,
.toolbar-btn:focus-visible,
.form-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================
 *   Print Styles
 *   ========================================== */
@media print {
    .sidebar,
    .editor-toolbar,
    .editor-container,
    .context-menu,
    .toast,
    .modal-overlay {
        display: none !important;
    }

    .main-content {
        width: 100%;
    }

    .content-view {
        padding: 0;
    }

    .prose {
        max-width: 100%;
        color: #000;
    }

    .prose a {
        color: #000;
        text-decoration: underline;
    }

    .prose pre,
    .prose code {
        background: #f0f0f0;
        color: #000;
    }
}
