* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light Theme - Warm & Literary (matching MonoDraft) */
    --bg-primary: #faf9f7;
    --bg-secondary: #f0ede8;
    --bg-tertiary: #e8e4dd;
    --text-primary: #2c2c2c;
    --text-secondary: #6b6b6b;
    --text-muted: #8a8a8a;
    --accent: #c45d3e;
    --accent-hover: #a84d32;
    --accent-secondary: #2d5a4a;
    --border-color: #e4e0db;
    --border-subtle: #ebe8e3;
    --code-bg: #f5f2ed;
    --toolbar-bg: rgba(250, 249, 247, 0.92);
    --shadow-sm: 0 1px 2px rgba(44, 44, 44, 0.04);
    --shadow-md: 0 4px 12px rgba(44, 44, 44, 0.08);
    --shadow-lg: 0 12px 32px rgba(44, 44, 44, 0.12);

    /* Sizing */
    --header-height: 56px;
    --toolbar-height: 48px;
    --status-bar-height: 40px;
    --touch-target-min: 44px;

    /* Typography */
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'Source Serif 4', Georgia, serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Animation */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;

    /* Canvas-specific variables */
    --grid-color: rgba(44, 44, 44, 0.06);
    --grid-color-major: rgba(44, 44, 44, 0.12);
    --canvas-bg: #faf9f7;
    --node-bg: #ffffff;
    --node-border: #e4e0db;
    --node-shadow: 0 2px 8px rgba(44, 44, 44, 0.08);
    --node-selected-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(44, 44, 44, 0.12);
    --connection-color: #6b6b6b;
    --anchor-size: 12px;
}

[data-theme="dark"] {
    --bg-primary: #1c1b19;
    --bg-secondary: #282623;
    --bg-tertiary: #333028;
    --text-primary: #e8e4de;
    --text-secondary: #9a958c;
    --text-muted: #6e6a62;
    --accent: #e07a5f;
    --accent-hover: #eb8d74;
    --accent-secondary: #5fa386;
    --border-color: #3a3632;
    --border-subtle: #302d29;
    --code-bg: #252320;
    --toolbar-bg: rgba(28, 27, 25, 0.92);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);

    /* Canvas dark theme */
    --grid-color: rgba(232, 228, 222, 0.04);
    --grid-color-major: rgba(232, 228, 222, 0.08);
    --canvas-bg: #1c1b19;
    --node-bg: #282623;
    --node-border: #3a3632;
    --node-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --connection-color: #9a958c;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background var(--duration-normal) var(--ease-out),
                color var(--duration-normal) var(--ease-out);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
    overflow: hidden;
}

/* Selection */
::selection {
    background: var(--accent);
    color: white;
}

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

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--toolbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 12px 20px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    z-index: 100;
    transition: transform var(--duration-normal) var(--ease-out),
                opacity var(--duration-normal) var(--ease-out);
}

.header.hidden {
    transform: translateY(-100%);
    opacity: 0;
}

.header-content {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.brand-link {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: -0.02em;
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-out);
}

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

/* About Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-primary);
    border-radius: 14px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform var(--duration-normal) var(--ease-out);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}

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

.modal-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.modal-subtitle {
    color: var(--text-secondary);
    margin: 0 0 24px;
    font-size: 16px;
}

.modal-content {
    color: var(--text-primary);
    line-height: 1.6;
}

.modal-content p {
    margin: 0 0 16px;
}

.modal-content h3 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin: 24px 0 12px;
}

.modal-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.modal-content li {
    padding: 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-content li::before {
    content: "\2022";
    color: var(--accent);
    font-weight: bold;
}

.modal-content kbd {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 8px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    font-size: 12px;
    min-width: 80px;
    display: inline-block;
}

.modal-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.modal-footer p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.modal-footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.modal-footer a:hover {
    text-decoration: underline;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

button {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
}

button:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    box-shadow: var(--shadow-sm);
}

button.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.toolbar {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--toolbar-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    gap: 4px;
    align-items: center;
    z-index: 99;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.toolbar.faded {
    opacity: 0.2;
}

.toolbar:hover {
    opacity: 1 !important;
}

.toolbar button {
    padding: 6px 10px;
    font-size: 13px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    transition: all var(--duration-fast) var(--ease-out);
}

.toolbar button:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: none;
}

.toolbar button.active {
    background: var(--accent);
    color: white;
}

.toolbar .separator {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

/* Toolbar Dropdowns */
.toolbar-dropdown {
    position: relative;
}

.dropdown-trigger {
    padding: 6px 10px;
    font-size: 13px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: none;
    z-index: 150;
}

.dropdown-menu.active {
    display: block;
}

.dropdown-menu button {
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    font-size: 13px;
    background: transparent;
    border: none;
    border-radius: 4px;
    margin-bottom: 2px;
}

.dropdown-menu button:last-child {
    margin-bottom: 0;
}

.dropdown-menu button:hover {
    background: var(--accent);
    color: white;
    transform: none;
}

.zoom-indicator {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
    padding: 6px 8px;
    user-select: none;
}

/* ===== CANVAS STYLES ===== */
.canvas-container {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: var(--status-bar-height);
    overflow: hidden;
    background: var(--canvas-bg);
}

body.sidebar-open .canvas-container {
    left: 280px;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: default;
}

.canvas-wrapper.tool-pan {
    cursor: grab;
}

.canvas-wrapper.tool-pan.panning {
    cursor: grabbing;
}

.canvas-wrapper.tool-connect {
    cursor: crosshair;
}

.canvas-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Grid background using CSS patterns */
.canvas-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-size: 20px 20px, 20px 20px, 100px 100px, 100px 100px;
    background-image:
        linear-gradient(to right, var(--grid-color) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color) 1px, transparent 1px),
        linear-gradient(to right, var(--grid-color-major) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-color-major) 1px, transparent 1px);
    background-position: 0 0, 0 0, 0 0, 0 0;
}

/* ===== NODES LAYER ===== */
.nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
}

/* ===== WORKFLOW NODE ===== */
.workflow-node {
    position: absolute;
    background: var(--node-bg);
    border: 2px solid var(--node-border);
    border-radius: 8px;
    box-shadow: var(--node-shadow);
    pointer-events: all;
    cursor: move;
    user-select: none;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    display: flex;
    flex-direction: column;
    min-width: 120px;
    min-height: 60px;
}

.workflow-node:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.workflow-node.selected {
    box-shadow: var(--node-selected-shadow);
    border-color: var(--accent);
}

.workflow-node.dragging {
    opacity: 0.9;
    z-index: 1000;
    cursor: grabbing;
}

/* Node type variations */
.workflow-node.node-start {
    border-left: 4px solid #22c55e;
}

.workflow-node.node-start .node-header {
    border-left: none;
}

.workflow-node.node-end {
    border-left: 4px solid #ef4444;
}

.workflow-node.node-decision {
    border-left: 4px solid #f59e0b;
}

.workflow-node.node-process {
    border-left: 4px solid var(--accent);
}

/* Category colors */
.workflow-node.category-brainstorm {
    border-left: 4px solid #8b5cf6;
}

.workflow-node.category-business {
    border-left: 4px solid #06b6d4;
}

.workflow-node.category-tech {
    border-left: 4px solid #10b981;
}

/* Specific node type colors within categories */
.workflow-node.node-idea { border-left-color: #fbbf24; }
.workflow-node.node-question { border-left-color: #8b5cf6; }
.workflow-node.node-problem { border-left-color: #ef4444; }
.workflow-node.node-solution { border-left-color: #22c55e; }
.workflow-node.node-note { border-left-color: #6b7280; }
.workflow-node.node-pro { border-left-color: #22c55e; }
.workflow-node.node-con { border-left-color: #ef4444; }

.workflow-node.node-task { border-left-color: #3b82f6; }
.workflow-node.node-milestone { border-left-color: #f59e0b; }
.workflow-node.node-stakeholder { border-left-color: #8b5cf6; }
.workflow-node.node-resource { border-left-color: #06b6d4; }
.workflow-node.node-risk { border-left-color: #ef4444; }
.workflow-node.node-goal { border-left-color: #22c55e; }

.workflow-node.node-server { border-left-color: #6366f1; }
.workflow-node.node-database { border-left-color: #ec4899; }
.workflow-node.node-api { border-left-color: #f59e0b; }
.workflow-node.node-service { border-left-color: #06b6d4; }
.workflow-node.node-user { border-left-color: #8b5cf6; }
.workflow-node.node-cloud { border-left-color: #3b82f6; }

/* Top and bottom anchors */
.anchor-top-input,
.anchor-bottom-output {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--anchor-bg);
    border: 2px solid var(--accent);
    border-radius: 50%;
    cursor: crosshair;
    z-index: 10;
    left: 50%;
    transform: translateX(-50%);
}

.anchor-top-input {
    top: -6px;
}

.anchor-bottom-output {
    bottom: -6px;
}

.anchor-top-input:hover,
.anchor-bottom-output:hover {
    background: var(--accent);
    transform: translateX(-50%) scale(1.3);
}

/* Node header */
.node-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    border-radius: 6px 6px 0 0;
    min-height: 36px;
}

.node-icon {
    font-size: 12px;
    opacity: 0.7;
    flex-shrink: 0;
}

.node-label {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    outline: none;
    border: none;
    background: transparent;
    padding: 2px 4px;
    margin: -2px -4px;
    border-radius: 4px;
    min-width: 60px;
}

.node-label:focus {
    background: var(--bg-primary);
    box-shadow: 0 0 0 2px var(--accent);
}

/* Node content */
.node-content {
    flex: 1;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    min-height: 24px;
    outline: none;
    border-radius: 0 0 6px 6px;
}

.node-content:empty::before {
    content: "Add description...";
    opacity: 0.5;
    pointer-events: none;
}

.node-content:focus {
    background: var(--bg-secondary);
}

/* ===== CONNECTION ANCHORS ===== */
.node-anchors {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.anchor {
    position: absolute;
    width: var(--anchor-size);
    height: var(--anchor-size);
    background: var(--bg-primary);
    border: 2px solid var(--accent);
    border-radius: 50%;
    pointer-events: all;
    cursor: crosshair;
    transition: transform 0.15s ease, background 0.15s ease;
    opacity: 0;
    z-index: 10;
}

.workflow-node:hover .anchor,
.workflow-node.selected .anchor,
.anchor.active {
    opacity: 1;
}

.anchor:hover,
.anchor.active {
    background: var(--accent);
    transform: scale(1.3);
}

.anchor-input {
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
}

.anchor-input:hover,
.anchor-input.active {
    transform: translateY(-50%) scale(1.3);
}

.anchor-output {
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
}

.anchor-output:hover,
.anchor-output.active {
    transform: translateY(-50%) scale(1.3);
}

/* Multiple outputs for decision nodes */
.anchor-output-0 {
    right: -6px;
    top: 35%;
    transform: translateY(-50%);
}

.anchor-output-1 {
    right: -6px;
    top: 65%;
    transform: translateY(-50%);
}

.anchor-output-0:hover,
.anchor-output-1:hover {
    transform: translateY(-50%) scale(1.3);
}

/* ===== CONNECTIONS (SVG) ===== */
.connection {
    fill: none;
    stroke: var(--connection-color);
    stroke-width: 2;
    pointer-events: stroke;
    cursor: pointer;
    transition: stroke-width 0.15s ease, stroke 0.15s ease;
}

.connection:hover {
    stroke-width: 3;
    stroke: var(--accent);
}

.connection.selected {
    stroke-width: 3;
    stroke: var(--accent);
}

.temp-connection {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 8, 4;
    pointer-events: none;
    opacity: 0.8;
}

.connection-label {
    font-size: 11px;
    fill: var(--text-secondary);
    text-anchor: middle;
    pointer-events: none;
    font-family: inherit;
}

/* ===== SELECTION RECTANGLE ===== */
.selection-rect {
    fill: rgba(92, 124, 250, 0.1);
    stroke: var(--accent);
    stroke-width: 1;
    stroke-dasharray: 4, 2;
    pointer-events: none;
}

/* ===== STATUS BAR ===== */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--toolbar-bg);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    padding: 10px 20px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
    z-index: 98;
}

body.sidebar-open .status-bar {
    left: 280px;
}

.status-bar .status-left {
    display: flex;
    gap: 20px;
}

.status-bar .status-right {
    display: flex;
    gap: 15px;
    align-items: center;
}

.export-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: none;
    min-width: 160px;
    z-index: 150;
}

.export-menu.active {
    display: block;
}

.export-menu button {
    width: 100%;
    text-align: left;
    margin-bottom: 4px;
    background: transparent;
    border: none;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--text-primary);
    transition: background 0.15s ease, color 0.15s ease;
}

.export-menu button:last-child {
    margin-bottom: 0;
}

.export-menu button:hover {
    background: var(--accent);
    color: white;
    transform: none;
}

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 300;
}

.toast.show {
    opacity: 1;
}

/* ===== MOBILE MENU STYLES ===== */
.mobile-menu-toggle {
    display: none;
    padding: 8px;
    background: transparent;
    border: 1px solid transparent;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    align-items: center;
    justify-content: center;
}

.hamburger-icon {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    position: relative;
}

.hamburger-icon::before,
.hamburger-icon::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    left: 0;
}

.hamburger-icon::before { top: -6px; }
.hamburger-icon::after { top: 6px; }

.header-actions-menu {
    display: contents;
}

/* ===== TABLET BREAKPOINT (max-width: 768px) ===== */
@media (max-width: 768px) {
    .canvas-container {
        top: calc(var(--header-height) + var(--toolbar-height) + 8px);
    }

    .toolbar {
        top: calc(var(--header-height) + 4px);
        left: 8px;
        right: 8px;
        transform: none;
        border-radius: 8px;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 6px 10px;
    }

    .toolbar::-webkit-scrollbar {
        display: none;
    }

    .toolbar button {
        flex-shrink: 0;
        min-width: 40px;
        min-height: 40px;
        padding: 8px 12px;
    }

    .toolbar .separator {
        flex-shrink: 0;
    }

    .header {
        padding: 10px 15px;
    }

    .header-actions {
        position: relative;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    .header-actions-menu {
        position: absolute;
        top: 100%;
        right: 0;
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        display: none;
        flex-direction: column;
        gap: 4px;
        min-width: 160px;
        margin-top: 8px;
        z-index: 110;
    }

    .header-actions-menu.active {
        display: flex;
    }

    .header-actions-menu button {
        width: 100%;
        text-align: left;
        min-height: var(--touch-target-min);
    }

    .header-actions-menu > div {
        width: 100%;
    }

    .header-actions-menu > div button {
        width: 100%;
    }

    .modal {
        padding: 24px;
        width: 95%;
        border-radius: 10px;
    }

    .modal-title { font-size: 24px; }
    .modal-close {
        width: var(--touch-target-min);
        height: var(--touch-target-min);
    }

    .status-bar {
        padding: 8px 12px;
        font-size: 12px;
    }

    .status-bar .status-left {
        gap: 12px;
    }

    /* Sidebar overlay on mobile */
    .document-sidebar {
        width: 100%;
        max-width: 320px;
    }

    body.sidebar-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 104;
    }

    body.sidebar-open .canvas-container,
    body.sidebar-open .status-bar {
        left: 0;
    }
}

/* ===== SMALL PHONE BREAKPOINT (max-width: 480px) ===== */
@media (max-width: 480px) {
    :root {
        --header-height: 48px;
        --toolbar-height: 44px;
        --status-bar-height: 32px;
    }

    .header {
        padding: 8px 10px;
    }

    .brand {
        font-size: 16px;
    }

    .btn-menu {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
        margin-right: 8px;
    }

    .toolbar {
        padding: 4px 8px;
        gap: 2px;
    }

    .toolbar button {
        min-width: 36px;
        min-height: 36px;
        padding: 6px 8px;
        font-size: 12px;
    }

    .modal {
        padding: 16px;
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .modal-title { font-size: 20px; }

    .modal-content kbd {
        min-width: 60px;
        font-size: 11px;
    }

    .status-bar {
        padding: 6px 10px;
        font-size: 11px;
    }

    .status-bar .status-left {
        gap: 8px;
    }

    /* Hide connection count on very small screens */
    .status-bar #connectionCount {
        display: none;
    }

    .document-sidebar {
        max-width: 100%;
    }

    .sidebar-header {
        padding: 12px;
    }

    .sidebar-actions {
        padding: 10px;
    }

    .btn-new-doc {
        padding: 12px;
        min-height: var(--touch-target-min);
    }

    .doc-search {
        min-height: var(--touch-target-min);
        padding: 10px 14px;
    }

    .document-item {
        padding: 14px 12px;
    }
}

/* ===== TOUCH DEVICE IMPROVEMENTS ===== */
@media (hover: none) and (pointer: coarse) {
    button {
        min-height: var(--touch-target-min);
    }

    .btn-icon {
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
    }

    .btn-menu {
        min-width: 48px;
        min-height: 48px;
        padding: 8px;
    }

    .doc-action-btn {
        min-width: 36px;
        min-height: 36px;
        padding: 8px;
    }

    .export-menu button {
        min-height: var(--touch-target-min);
        padding: 12px 14px;
    }

    /* Always show doc actions on touch */
    .document-item .doc-actions {
        display: flex;
    }

    /* Larger anchors for touch */
    .anchor {
        width: 16px;
        height: 16px;
        opacity: 1;
    }
}

/* Focus mode styles */
body.focus-mode .header,
body.focus-mode .toolbar,
body.focus-mode .status-bar {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Focus mode trigger zone at top */
.focus-trigger {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    z-index: 99;
    pointer-events: none;
}

body.focus-mode .focus-trigger {
    pointer-events: all;
}

body.focus-mode .focus-trigger:hover {
    pointer-events: none;
}

body.focus-mode:has(.focus-trigger:hover) .header,
body.focus-mode:has(.focus-trigger:hover) .toolbar,
body.focus-mode:has(.focus-trigger:hover) .status-bar,
body.focus-mode .header:hover,
body.focus-mode:has(.header:hover) .toolbar,
body.focus-mode:has(.header:hover) .status-bar,
body.focus-mode .toolbar:hover,
body.focus-mode .status-bar:hover {
    opacity: 1;
    pointer-events: all;
}

#focusToggle.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Print styles */
@media print {
    .header,
    .toolbar,
    .status-bar,
    .document-sidebar {
        display: none;
    }

    .canvas-container {
        position: static;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
}

/* Document Sidebar Styles */
.document-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 105;
    display: flex;
    flex-direction: column;
}

body.sidebar-open .document-sidebar {
    transform: translateX(0);
}

body.sidebar-open .header {
    left: 280px;
}

body.sidebar-open .toolbar {
    left: calc(280px + 50%);
}

@media (max-width: 768px) {
    body.sidebar-open .header,
    body.sidebar-open .toolbar {
        left: 0;
    }

    body.sidebar-open .toolbar {
        transform: none;
    }
}

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

.sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--bg-primary);
}

.btn-menu {
    height: 36px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--duration-fast) var(--ease-out);
}

.btn-menu:hover {
    background: var(--bg-secondary);
    color: var(--accent);
}

.btn-menu svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

.btn-new-doc {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 10px;
    transition: all var(--duration-fast) var(--ease-out);
}

.btn-new-doc:hover {
    background: var(--accent-hover);
    transform: none;
    box-shadow: var(--shadow-sm);
}

.doc-search {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
}

.doc-search:focus {
    border-color: var(--accent);
}

.document-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.document-item {
    padding: 12px;
    background: var(--accent);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    position: relative;
    color: white;
}

.document-item:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.document-item.active {
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--accent);
}

.document-item .doc-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.document-item .doc-meta {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.75);
}

.document-item.active .doc-meta {
    color: rgba(255, 255, 255, 0.9);
}

.doc-actions {
    display: none;
    gap: 4px;
}

.document-item:hover .doc-actions {
    display: flex;
}

.doc-action-btn {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    border-radius: 3px;
}

.doc-action-btn:hover {
    background: var(--bg-secondary);
}

.document-item.active .doc-action-btn {
    color: rgba(255, 255, 255, 0.8);
}

.document-item.active .doc-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Hide sidebar in focus mode */
body.focus-mode .document-sidebar {
    transform: translateX(-100%);
}

body.focus-mode.sidebar-open .header,
body.focus-mode.sidebar-open .canvas-container,
body.focus-mode.sidebar-open .toolbar,
body.focus-mode.sidebar-open .status-bar {
    left: 0;
}
