/* Main CSS - Keepers */

/* ============================================
   THIRD-PARTY COMPONENT ISOLATION
   ============================================

   When using third-party components (Excalidraw, etc.) that manage their own
   styling, avoid global selectors that override their internal CSS:

   NEVER USE:
   - * { font-family: ... }           -- Breaks component fonts/icons
   - :focus-visible { ... }           -- Interferes with focus management
   - *:not(.component) { ... }        -- Invalid CSS, doesn't work
   - *:not(.component *) { ... }      -- Invalid CSS (no descendant in :not)

   INSTEAD USE:
   - html, body { font-family: ... }  -- Inheritance-based, components override
   - Specific selectors: a, button, input, etc.
   - :where() for low-specificity defaults that components can override

   Third-party components in this project:
   - Excalidraw (.excalidraw) - Sketch editor with custom fonts and focus

   ============================================ */

/* ============================================
   Excalifont - Excalidraw's hand-drawn font
   Preloaded to ensure local fonts work correctly
   ============================================ */
@font-face {
    font-family: "Excalifont";
    src: url("/assets/fonts/Excalifont/Excalifont-Regular.woff2")
        format("woff2");
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/*
 * Font Strategy:
 * - Set font on html/body for inheritance (not * which breaks Excalidraw)
 * - Excalidraw manages its own fonts internally
 * - Form elements need explicit font-family as they don't inherit by default
 */
html,
body {
    font-family: "JetBrains Mono", ui-monospace, monospace;
}

/* Form elements don't inherit font by default */
input,
textarea,
select,
button {
    font-family: inherit;
}

/* Hidden until JavaScript initializes */
[data-cloak] {
    display: none !important;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Apply theme colors */
.bg-primary {
    background-color: var(--bg-primary);
}
.bg-secondary {
    background-color: var(--bg-secondary);
}
.bg-tertiary {
    background-color: var(--bg-tertiary);
}
.text-primary {
    color: var(--text-primary);
}
.text-secondary {
    color: var(--text-secondary);
}
.text-muted {
    color: var(--text-muted);
}
.text-accent {
    color: var(--accent);
}
.text-success {
    color: var(--success);
}
.text-warning {
    color: var(--warning);
}
.text-error {
    color: var(--error);
}
.text-info {
    color: var(--info);
}
.bg-accent {
    background-color: var(--accent);
}
.border-default {
    border-color: var(--border);
}
.border-accent {
    border-color: var(--accent);
}

/* Hover utilities */
.hover\:bg-tertiary:hover {
    background-color: var(--bg-tertiary);
}
.hover\:text-primary:hover {
    color: var(--text-primary);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Transitions */
.theme-transition {
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        border-color 0.2s ease;
}

/* Memo card entrance animation - CSS-only stagger via --i variable */
@keyframes memo-card-enter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Card hover - Enhanced with shadow system */
.memo-card {
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition:
        box-shadow var(--transition-normal),
        border-color var(--transition-normal),
        transform var(--transition-normal);
    min-width: 0;
    width: 100%;
    max-width: 100%;
    /* Allow dropdown menus to overflow card boundaries */
    overflow: visible;
    /* CSS entrance animation with stagger delay via --i CSS variable (server-rendered) */
    /* Capped at 10 items (500ms max) to prevent long delays with many memos */
    animation: memo-card-enter 0.3s ease-out both;
    animation-delay: calc(min(var(--i, 0), 10) * 50ms);
}

/* Prevent memo content from overflowing card boundaries */
.memo-card .memo-content {
    overflow: hidden;
}
.memo-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* Elevate card when dropdown is open to ensure menu appears above sibling cards */
.memo-card--dropdown-open {
    position: relative;
    z-index: 100;
}

/* New memo highlight animation - accent glow that fades out */
@keyframes memo-highlight {
    0% {
        box-shadow:
            0 0 0 2px var(--accent),
            0 0 20px color-mix(in srgb, var(--accent) 40%, transparent);
        border-color: var(--accent);
    }
    70% {
        box-shadow:
            0 0 0 2px var(--accent),
            0 0 10px color-mix(in srgb, var(--accent) 20%, transparent);
        border-color: var(--accent);
    }
    100% {
        box-shadow: none;
        border-color: var(--border);
    }
}

.memo-card-new {
    animation: memo-highlight 1.5s ease-out forwards;
}

/* Note: Memo card entrance animations are CSS-only via @keyframes memo-card-enter.
   CSS animation runs once on initial render. */

/* Pinned card hover */
.pinned-card {
    transition:
        transform var(--transition-fast),
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}
.pinned-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Pinned cards are always visible by default. JS handles animation via inline styles. */
.pinned-card {
    opacity: 1;
    transform: none;
}

/* Button transitions */
.btn {
    transition:
        transform var(--transition-fast),
        background-color var(--transition-fast),
        box-shadow var(--transition-fast);
}
.btn:hover {
    transform: translateY(-1px);
}
.btn:active {
    transform: translateY(0);
}

/* ============================================
   Button Hierarchy - Primary, Secondary, Ghost
   ============================================ */

/* Primary Buttons - High emphasis actions */
.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        filter var(--transition-fast);
    font-weight: 500;
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    filter: brightness(1.1);
}
.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
    filter: brightness(0.95);
}
.btn-primary:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow), var(--shadow-md);
}

/* Secondary Buttons - Medium emphasis actions */
.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    transition:
        background var(--transition-fast),
        border-color var(--transition-fast),
        transform var(--transition-fast);
}
.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--accent);
    transform: translateY(-1px);
}
.btn-secondary:active {
    transform: translateY(0);
}
.btn-secondary:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
}

/* Ghost/Icon Buttons - Low emphasis, icon-only or subtle actions */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    transition:
        background var(--transition-fast),
        color var(--transition-fast);
}
.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.btn-ghost:active {
    background: var(--bg-secondary);
}
.btn-ghost:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
}

/* Button Sizes */
.btn-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 0.375rem;
}
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    border-radius: 0.5rem;
}
.btn-md {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border-radius: 0.5rem;
}
.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border-radius: 0.625rem;
}

/* Interactive elements */
.interactive {
    transition:
        background-color 0.12s ease,
        color 0.12s ease,
        transform 0.1s ease;
}
.interactive:active {
    transform: scale(0.98);
}

/* Input focus with animated ring expansion */
input,
textarea,
select {
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease-out;
}
input:focus,
textarea:focus,
select:focus {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Focus ring expand animation for Motion.js enhanced inputs */
.input-focus-animate {
    animation: focus-ring-expand 0.15s ease-out forwards;
}

@keyframes focus-ring-expand {
    from {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 20%, transparent);
    }
    to {
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
    }
}

/* Nav link transitions */
.nav-link {
    transition:
        background-color 0.12s ease,
        color 0.12s ease;
}

/* Tag styles */
.tag {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        transform 0.12s ease;
}
.tag:hover {
    background-color: var(--accent);
    color: var(--bg-primary);
    transform: translateY(-1px);
}

/* Tag active/selected state */
.tag:active {
    transform: scale(0.95);
}

/* Tag click pulse animation (Motion.js fallback) */
@keyframes tag-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

.tag-pulse {
    animation: tag-pulse var(--duration-normal) var(--ease-out);
}

/* Dropdown/menu animations */
.dropdown {
    transition:
        opacity var(--transition-fast),
        transform var(--transition-fast);
}
.dropdown.hidden {
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
}
.dropdown:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
}

/* Checkbox transitions */
input[type="checkbox"] {
    transition: transform 0.1s ease;
}
input[type="checkbox"]:active {
    transform: scale(0.9);
}

/* Subtle pulse for empty pin slot */
.empty-slot {
    transition:
        border-color 0.2s ease,
        background-color 0.2s ease;
}
.empty-slot:hover {
    border-color: var(--accent);
    background-color: color-mix(in srgb, var(--accent) 5%, var(--bg-secondary));
}

/* Icon button micro-interaction */
.icon-btn {
    transition:
        color 0.12s ease,
        background-color 0.12s ease,
        transform 0.12s ease;
}
.icon-btn:hover {
    transform: scale(1.08);
}
.icon-btn:active {
    transform: scale(0.92);
}

/* Icon button click feedback animation */
@keyframes icon-btn-feedback {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.92);
    }
    100% {
        transform: scale(1);
    }
}

.icon-btn-feedback {
    animation: icon-btn-feedback 0.15s ease-out;
}

/* Submit/action button micro-interactions */
.btn-submit {
    position: relative;
    transition:
        opacity 0.15s ease,
        box-shadow 0.2s ease,
        transform 0.15s ease;
}

/* Submit button loading state pulse */
@keyframes submit-pulse {
    0%,
    100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

.btn-submit--loading {
    animation: submit-pulse 1.5s ease-in-out infinite;
}

/* Submit button success flash */
@keyframes submit-success {
    0% {
        box-shadow: 0 0 0 0 transparent;
    }
    50% {
        box-shadow: 0 0 12px 3px
            color-mix(in srgb, var(--success) 60%, transparent);
    }
    100% {
        box-shadow: 0 0 0 0 transparent;
    }
}

.btn-submit--success {
    animation: submit-success 0.4s ease-out;
}

/* Submit button error shake */
@keyframes submit-error {
    0%,
    100% {
        transform: translateX(0);
    }
    10% {
        transform: translateX(-6px);
    }
    20% {
        transform: translateX(6px);
    }
    30% {
        transform: translateX(-4px);
    }
    40% {
        transform: translateX(4px);
    }
    50% {
        transform: translateX(-2px);
    }
    60% {
        transform: translateX(2px);
    }
}

.btn-submit--error {
    animation: submit-error 0.4s ease-out;
}

/* Form styles */
.form-input {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
}
.form-input::placeholder {
    color: var(--text-muted);
}
.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Alert styles */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid;
}
.alert-error {
    background-color: color-mix(in srgb, var(--error) 10%, var(--bg-secondary));
    border-color: var(--error);
    color: var(--error);
}
.alert-success {
    background-color: color-mix(
        in srgb,
        var(--success) 10%,
        var(--bg-secondary)
    );
    border-color: var(--success);
    color: var(--success);
}
.alert-warning {
    background-color: color-mix(
        in srgb,
        var(--warning) 10%,
        var(--bg-secondary)
    );
    border-color: var(--warning);
    color: var(--warning);
}
.alert-info {
    background-color: color-mix(in srgb, var(--info) 10%, var(--bg-secondary));
    border-color: var(--info);
    color: var(--info);
}

/* ============================================
   Toast Notification Styles
   ============================================ */

/* Toast item base styles */
.toast-item {
    will-change: transform, opacity;
    box-shadow:
        var(--shadow-lg),
        0 0 0 1px rgba(0, 0, 0, 0.05);
    min-width: 280px;
    max-width: 400px;
}

/* Toast type variants - using color-mix for theme-aware backgrounds */
.toast-item.toast-success {
    background-color: color-mix(
        in srgb,
        var(--success) 12%,
        var(--bg-secondary)
    );
    border-color: color-mix(in srgb, var(--success) 40%, var(--border));
    color: var(--success);
}

.toast-item.toast-error {
    background-color: color-mix(in srgb, var(--error) 12%, var(--bg-secondary));
    border-color: color-mix(in srgb, var(--error) 40%, var(--border));
    color: var(--error);
}

.toast-item.toast-warning {
    background-color: color-mix(
        in srgb,
        var(--warning) 12%,
        var(--bg-secondary)
    );
    border-color: color-mix(in srgb, var(--warning) 40%, var(--border));
    color: var(--warning);
}

.toast-item.toast-info {
    background-color: color-mix(in srgb, var(--info) 12%, var(--bg-secondary));
    border-color: color-mix(in srgb, var(--info) 40%, var(--border));
    color: var(--info);
}

/* Legacy border classes for backwards compatibility */
.toast-item.border-success {
    border-color: var(--success);
}

.toast-item.border-error {
    border-color: var(--error);
}

.toast-item.border-warning {
    border-color: var(--warning);
}

.toast-item.border-info {
    border-color: var(--info);
}

/* Reduced motion: skip glow animations, use simpler transitions */
@media (prefers-reduced-motion: reduce) {
    .toast-item {
        transition: opacity 0.1s ease-out !important;
        animation: none !important;
    }
}

/* Loading spinner */
.spinner {
    animation: spin 1s linear infinite;
}
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* HTMX loading indicator */
.htmx-indicator {
    display: none;
}
.htmx-request .htmx-indicator {
    display: inline-block;
}
.htmx-request.htmx-indicator {
    display: inline-block;
}

/* Code block styles */
pre,
code {
    font-family: "JetBrains Mono", ui-monospace, monospace;
}
pre {
    background-color: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 0.375rem;
    overflow-x: auto;
    max-width: 100%;
}
code {
    background-color: var(--bg-tertiary);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}
pre code {
    background-color: transparent;
    padding: 0;
}

/* Memo feed container - constrain children */
#memo-feed {
    min-width: 0;
    overflow-x: hidden; /* Constrain horizontal overflow for code blocks */
    overflow-y: visible; /* Allow dropdown menus to extend beyond container */
    padding-top: 4px; /* Prevent clipping of first memo's hover effects */
    padding-bottom: 12rem; /* Space for dropdown menus on bottom-most memo */
    position: relative; /* For loading shimmer overlay positioning */
}

/* Ensure code blocks in memo content wrap instead of scroll */
.memo-content pre {
    max-width: 100%;
    width: 100%;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
    overflow-x: hidden;
    box-sizing: border-box;
}

.memo-content pre code {
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
}

/* Code block copy button */
.code-block-wrapper {
    position: relative;
}

.copy-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    opacity: 0;
    transform: translateX(8px);
    transition:
        opacity 0.15s ease,
        color 0.12s ease,
        transform 0.15s ease;
}

/* Show copy button on code block hover - slide in from right */
.code-block-wrapper:hover .copy-button,
.code-block-wrapper:focus-within .copy-button {
    opacity: 0.6;
    transform: translateX(0);
}

.copy-button:hover {
    opacity: 1 !important;
    color: var(--text-primary);
}

.copy-button:active {
    transform: translateX(0) scale(0.95);
}

.copy-button--copied {
    color: var(--success);
    opacity: 1 !important;
}

/* Copy button success glow animation */
@keyframes copy-success-glow {
    0% {
        box-shadow: 0 0 0 0 transparent;
    }
    50% {
        box-shadow: 0 0 8px 2px
            color-mix(in srgb, var(--success) 50%, transparent);
    }
    100% {
        box-shadow: 0 0 0 0 transparent;
    }
}

.copy-button--copied {
    animation: copy-success-glow 0.4s ease-out;
}

/* Copy button icon toggle */
.copy-button .check-icon {
    display: none;
}
.copy-button--copied .copy-icon {
    display: none;
}
.copy-button--copied .check-icon {
    display: block;
}

/* Theme-aware syntax highlighting for highlight.js */
.hljs {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary);
}
.hljs-comment,
.hljs-quote {
    color: var(--text-muted);
    font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-addition {
    color: var(--accent);
}
.hljs-number,
.hljs-string,
.hljs-meta .hljs-meta-string,
.hljs-literal,
.hljs-doctag,
.hljs-regexp {
    color: var(--success);
}
.hljs-title,
.hljs-section,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
    color: var(--info);
}
.hljs-attribute,
.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-class .hljs-title,
.hljs-type {
    color: var(--warning);
}
.hljs-symbol,
.hljs-bullet,
.hljs-subst,
.hljs-meta,
.hljs-meta .hljs-keyword,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-link {
    color: var(--accent-secondary);
}
.hljs-built_in,
.hljs-deletion {
    color: var(--error);
}
.hljs-formula {
    background: var(--bg-secondary);
}
.hljs-emphasis {
    font-style: italic;
}
.hljs-strong {
    font-weight: bold;
}

/* Text Highlighting - Apple Notes style */
mark.highlight,
.highlight {
    background-color: rgba(251, 191, 36, 0.35);
    padding: 0.1em 0.2em;
    border-radius: 0.2em;
    color: inherit;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

/* CodeMirror highlight syntax markers (==) - subtle styling */
.cm-content .tok-processingInstruction {
    color: var(--text-muted);
    opacity: 0.6;
}

/* Adjust highlight for dark themes - slightly more vibrant */
@media (prefers-color-scheme: dark) {
    mark.highlight,
    .highlight {
        background-color: rgba(251, 191, 36, 0.3);
    }
}

/* Theme-aware highlight using CSS variables for manual theme toggle */
[data-theme="dark"] mark.highlight,
[data-theme="dark"] .highlight {
    background-color: rgba(251, 191, 36, 0.3);
}

[data-theme="light"] mark.highlight,
[data-theme="light"] .highlight {
    background-color: rgba(255, 235, 130, 0.6);
}

/* Search result highlighting - distinct from user ==text== highlights
 * Uses the warning/orange color with higher contrast for visibility
 * Applied to search matches in memo content */
mark.search-highlight {
    background-color: var(--warning);
    color: var(--bg-primary);
    padding: 0 0.15em;
    border-radius: 0.15em;
    font-weight: 500;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

/* Dark theme search highlight - slightly adjusted for contrast */
[data-theme="dark"] mark.search-highlight {
    background-color: var(--warning);
    color: var(--bg-primary);
}

/* Light theme search highlight - ensure good contrast */
[data-theme="light"] mark.search-highlight {
    background-color: var(--warning);
    color: var(--bg-primary);
}

/* Respect system color scheme preference */
@media (prefers-color-scheme: dark) {
    mark.search-highlight {
        background-color: var(--warning);
        color: var(--bg-primary);
    }
}

/* SVG search highlight - applied to tspan elements in sketches */
.svg-search-highlight {
    fill: var(--warning) !important;
    font-weight: bold;
}

/* Line clamp utilities */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Focus ring for keyboard navigation */
.focus-ring:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================
   Global Focus States - Accessible focus indicators
   ============================================ */

/* Global focus-visible for interactive elements (not Excalidraw - it manages its own) */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible:not([tabindex="-1"]) {
    outline: none;
    box-shadow: var(--shadow-glow);
}

/* Elements that need outline instead of box-shadow (e.g., complex layouts) */
:focus-visible:where(input, textarea, select) {
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
    border-color: var(--accent);
}

/* Smooth transitions for all interactive elements */
a,
button {
    transition:
        color 0.12s ease,
        background-color 0.12s ease;
}

/* ============================================
   Link Styling - Distinguishable from plain text
   ============================================ */

/* Default link styling - excludes buttons, tags, and card links */
a:not(.btn):not(.btn-primary):not(.btn-secondary):not(.btn-ghost):not(.tag):not(
        .memo-card
    ):not(.nav-link):not(.dropdown-menu-item):not(.user-menu-item):not(
        .theme-item
    ):not(.memo-menu-item):not(.pinned-card) {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
    text-underline-offset: 2px;
    transition:
        text-decoration-color var(--transition-fast),
        color var(--transition-fast);
}
a:not(.btn):not(.btn-primary):not(.btn-secondary):not(.btn-ghost):not(.tag):not(
        .memo-card
    ):not(.nav-link):not(.dropdown-menu-item):not(.user-menu-item):not(
        .theme-item
    ):not(.memo-menu-item):not(.pinned-card):hover {
    text-decoration-color: var(--accent);
}
a:not(.btn):not(.btn-primary):not(.btn-secondary):not(.btn-ghost):not(.tag):not(
        .memo-card
    ):not(.nav-link):not(.dropdown-menu-item):not(.user-menu-item):not(
        .theme-item
    ):not(.memo-menu-item):not(.pinned-card):focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
    border-radius: 2px;
}

/* Placeholder styling */
::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* Selection styling */
::selection {
    background-color: var(--accent);
    color: var(--bg-primary);
}

/* Markdown prose styling */
.memo-content {
    word-wrap: break-word;
    overflow-wrap: break-word;
    /* Constrain width to prevent code blocks from overflowing card */
    min-width: 0;
    width: 100%;
}
.memo-content p {
    margin-bottom: 0.75rem;
}
.memo-content p:last-child {
    margin-bottom: 0;
}
.memo-content h1,
.memo-content h2,
.memo-content h3,
.memo-content h4 {
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}
.memo-content h1 {
    font-size: 1.25rem;
}
.memo-content h2 {
    font-size: 1.125rem;
}
.memo-content h3 {
    font-size: 1rem;
}
.memo-content ul,
.memo-content ol {
    margin-left: 1.25rem;
    margin-bottom: 0.75rem;
}
.memo-content ul {
    list-style-type: disc;
}
.memo-content ol {
    list-style-type: decimal;
}
.memo-content li {
    margin-bottom: 0.25rem;
}
.memo-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--text-secondary);
    font-style: italic;
}
.memo-content a {
    color: var(--accent);
    text-decoration: underline;
}
.memo-content a:hover {
    opacity: 0.8;
}
.memo-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}
.memo-content img {
    max-width: 100%;
    border-radius: 0.375rem;
}
.memo-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
}
.memo-content th,
.memo-content td {
    border: 1px solid var(--border);
    padding: 0.5rem;
    text-align: left;
}
.memo-content th {
    background-color: var(--bg-tertiary);
    font-weight: 600;
}
.memo-content input[type="checkbox"] {
    margin-right: 0.5rem;
}

/* Sketch content container */
.memo-content-sketch {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100px;
}

.sketch-container {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
    border-radius: 0.375rem;
    background-color: var(--bg-tertiary);
    padding: 0.5rem;
}

.sketch-container svg {
    max-height: 400px;
    width: auto;
    height: auto;
}

/* Sketch editor (Excalidraw) */
.sketch-editor-container {
    width: 100%;
    min-height: 400px;
}

/* ============================================
   Fullscreen Sketch Editor
   ============================================ */

.sketch-fullscreen-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    /* Note: not using align-items: center because we want full-height stretch */
}

.sketch-fullscreen-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.sketch-fullscreen-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
}

.sketch-fullscreen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

.sketch-fullscreen-canvas {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.sketch-fullscreen-canvas .sketch-editor-container {
    min-height: 100%;
    height: 100%;
}

.sketch-fullscreen-canvas .sketch-canvas {
    height: 100% !important;
    min-height: 100% !important;
}

/* Ensure Excalidraw fills the fullscreen canvas */
.sketch-fullscreen-canvas .excalidraw-container,
.sketch-fullscreen-canvas .excalidraw {
    width: 100% !important;
    height: 100% !important;
}

/* Dark mode backdrop adjustments */
.theme-catppuccin-mocha .sketch-fullscreen-backdrop,
.theme-gruvbox-dark .sketch-fullscreen-backdrop,
.theme-kanagawa-dragon .sketch-fullscreen-backdrop,
.theme-kanagawa-wave .sketch-fullscreen-backdrop,
.theme-solarized-dark .sketch-fullscreen-backdrop,
.theme-tokyonight-dark .sketch-fullscreen-backdrop {
    background-color: rgba(0, 0, 0, 0.85);
}

/* Animation base states */
.sketch-fullscreen-overlay.hidden {
    display: none !important;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .sketch-fullscreen-backdrop,
    .sketch-fullscreen-container {
        transition: none !important;
        animation: none !important;
    }
}

.sketch-canvas {
    width: 100%;
    min-width: 300px;
}

/* Responsive sketch canvas height for unified composer */
/* Mobile: maximize viewport usage for better drawing experience */
/* Desktop: fixed height to balance with text editor */
.sketch-canvas-responsive {
    height: 400px;
}

@media (max-width: 767px) {
    .sketch-canvas-responsive {
        height: auto;
        min-height: 60vh;
    }
}

/* Ensure Excalidraw fills its container */
.sketch-canvas .excalidraw-container,
.sketch-canvas .excalidraw {
    width: 100% !important;
    height: 100% !important;
}

/* REMOVED: pointer-events: auto on layer-ui__wrapper
 * This was blocking mouse events from reaching the canvas.
 * Excalidraw handles pointer-events internally - the wrapper should be
 * pointer-events: none (default) while toolbar buttons have pointer-events: auto.
 */

/* Sketch theme inversion - applied when sketch was saved in opposite theme mode
 * Uses CSS filter to invert colors and rotate hue to maintain color relationships
 * invert(1) inverts all colors (black<->white, etc.)
 * hue-rotate(180deg) corrects hue shift from inversion (preserves original hue intent)
 * This makes light theme sketches visible on dark backgrounds and vice versa
 *
 * NOTE: We do NOT override svg text fill here - the SVG contains proper colors
 * from Excalidraw's export, and the invert filter handles theme adaptation.
 * Previously there was a rule `.sketch-container svg text { fill: var(--text-primary); }`
 * which broke inversion by fighting against the filter.
 */
.sketch-container.sketch-theme-invert svg {
    filter: invert(1) hue-rotate(180deg);
    transition: filter 0.2s ease;
}

/* Smooth transition when theme changes */
.sketch-container svg {
    transition: filter 0.2s ease;
}

/* ============================================
   Memo Open View - Full Window Editor
   ============================================ */

/* Main container - fills parent height */
.memo-open-container {
    background-color: var(--bg-primary);
    min-height: 100%;
}

/* Header bar */
.memo-open-header {
    flex-shrink: 0;
    z-index: 10;
}

/* Editor area - fills remaining space */
.memo-open-editor {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Markdown editor wrapper - fills available space */
.memo-open-editor-wrapper {
    flex: 1;
    min-height: 0;
}

/* CodeMirror in full open mode - fill height without max-height constraint */
.memo-open-editor-wrapper .cm-editor {
    height: 100%;
    max-height: none !important;
}

.memo-open-editor-wrapper .cm-scroller {
    overflow-y: auto !important;
}

/* Sketch canvas in full open mode - fill entire space */
.memo-open-sketch-canvas {
    height: 100% !important;
    min-height: 100% !important;
}

.memo-open-sketch-canvas .excalidraw-container,
.memo-open-sketch-canvas .excalidraw {
    width: 100% !important;
    height: 100% !important;
}

/* Preview panel in full open mode */
.memo-open-preview {
    background-color: var(--bg-secondary);
}

/* Toolbar in full open mode */
.memo-open-toolbar {
    flex-shrink: 0;
}

/* Tag bar footer at bottom of card - sits flush without consuming free space */
.memo-open-footer {
    flex-shrink: 0;
    margin-top: 0; /* remove auto gap - editor flex:1 fills space instead */
}

/* Override composer-tags flex:1 when used in memo-open footer */
.memo-open-footer.composer-tags {
    flex: 0 0 auto;
}

/* Ensure sketch editor container fills height */
#memo-open-sketch-editor {
    position: relative;
    display: flex;
    flex-direction: column;
}

#memo-open-sketch-editor > [data-sketch-editor-target="container"],
#memo-open-sketch-editor .sketch-canvas {
    flex: 1;
    min-height: 0;
}

/* Reduced motion support for memo open animations */
@media (prefers-reduced-motion: reduce) {
    .memo-open-container,
    .memo-open-header,
    .memo-open-editor {
        transition: none !important;
        animation: none !important;
    }
}

/* Tag highlight in memo content - inline hashtags */
.tag-highlight {
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.12s ease;
}
.tag-highlight:hover {
    opacity: 0.75;
}

/* Floating Header */
.header-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Calendar Heatmap Widget */
.calendar-widget {
    padding: 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: 0.5rem;
}

.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.calendar-title {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.calendar-nav {
    display: flex;
    gap: 0.25rem;
}

.calendar-nav-btn {
    padding: 0.125rem 0.25rem;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 0.25rem;
    transition:
        color 0.12s ease,
        background-color 0.12s ease;
}

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

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.calendar-weekday {
    font-size: 0.625rem;
    color: var(--text-muted);
    text-align: center;
    padding-bottom: 0.25rem;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    color: var(--text-secondary);
    border-radius: 0.125rem;
    cursor: pointer;
    transition:
        background-color 0.12s ease,
        transform 0.1s ease;
}

.calendar-day:hover {
    transform: scale(1.1);
    background-color: var(--bg-tertiary);
}

.calendar-day-empty {
    cursor: default;
    color: transparent;
}

.calendar-day-empty:hover {
    transform: none;
    background-color: transparent;
}

.calendar-day-today {
    font-weight: 600;
    color: var(--text-primary);
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

/* Heatmap intensity levels using theme accent color */
.calendar-intensity-0 {
    background-color: transparent;
}

.calendar-intensity-1 {
    background-color: color-mix(in srgb, var(--accent) 20%, transparent);
}

.calendar-intensity-2 {
    background-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.calendar-intensity-3 {
    background-color: color-mix(in srgb, var(--accent) 60%, transparent);
}

.calendar-intensity-4 {
    background-color: color-mix(in srgb, var(--accent) 80%, transparent);
}

/* Intensity hover states - slightly brighter */
.calendar-intensity-1:hover {
    background-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.calendar-intensity-2:hover {
    background-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.calendar-intensity-3:hover {
    background-color: color-mix(in srgb, var(--accent) 70%, transparent);
}

.calendar-intensity-4:hover {
    background-color: color-mix(in srgb, var(--accent) 90%, transparent);
}

/* Theme transition for calendar elements */
.calendar-widget,
.calendar-day,
.calendar-nav-btn {
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        border-color 0.2s ease;
}

/* ===========================================
   Calendar Transition Styles
   =========================================== */

/* Loading state - fade out during month navigation */
.calendar-loading {
    opacity: 0.5;
    transition: opacity 150ms ease;
}

/* Calendar day hover - elevate above others */
.calendar-day:hover:not(.calendar-day-empty) {
    z-index: 10;
    position: relative;
}

/* ===========================================
   Sidebar Navigation Animation Styles
   =========================================== */

/* Sidebar nav links */
.sidebar-nav-link {
    position: relative;
}

/* Active nav link indicator (animated border) */
.sidebar-nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: var(--nav-active-width, 100%);
    background-color: var(--accent);
    border-radius: 0 2px 2px 0;
    transition: height 0.2s ease-out;
}

/* Tags - show immediately (motion.js stagger removed) */
#tag-list .sidebar-tag {
    opacity: 1;
    transform: none;
}

/* Tag hover shadow enhancement */
.sidebar-tag:hover {
    z-index: 5;
    position: relative;
}

/* ===========================================
   Reduced Motion Support
   =========================================== */

@media (prefers-reduced-motion: reduce) {
    /* Calendar: minimal hover effect */
    .calendar-day {
        transition: background-color 0.1s ease;
    }

    .calendar-day:hover {
        transform: scale(1.02) !important;
    }

    /* Calendar: instant loading state */
    .calendar-loading {
        transition: none;
    }

    /* Sidebar: disable translateX hover */
    .sidebar-nav-link,
    .sidebar-tag {
        transform: none !important;
        transition:
            background-color 0.1s ease,
            color 0.1s ease;
    }

    /* Tags: already visible (stagger removed) */
}

/* User Dropdown */
.user-dropdown {
    width: 280px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border);
    overflow: hidden;
    z-index: 50;
    transform-origin: bottom left;
}

/* Dark mode - stronger shadow, no border */
.theme-catppuccin-mocha .user-dropdown,
.theme-gruvbox-dark .user-dropdown,
.theme-kanagawa-dragon .user-dropdown,
.theme-kanagawa-wave .user-dropdown,
.theme-solarized-dark .user-dropdown,
.theme-tokyonight-dark .user-dropdown {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border: none;
}

/* User identity block (top of dropdown) */
.user-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.user-identity-avatar {
    width: 48px;
    height: 48px;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 500;
    flex-shrink: 0;
}

.user-identity-info {
    min-width: 0;
    flex: 1;
}

.user-identity-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-identity-username {
    font-size: 13px;
    color: var(--text-muted);
}

/* Dropdown menu items */
.dropdown-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-secondary);
    transition:
        background-color 0.1s ease,
        color 0.1s ease;
    cursor: pointer;
    text-decoration: none;
}

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

.dropdown-menu-item.danger:hover {
    color: var(--error);
}

/* Focus styles for keyboard navigation */
.dropdown-menu-item:focus {
    outline: none;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown-menu-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.dropdown-menu-item.danger:focus {
    color: var(--error);
}

/* Variant that doesn't change background on hover (for interactive items like theme toggle) */
.dropdown-menu-item--no-hover:hover {
    background-color: transparent;
}

.dropdown-menu-item--no-hover:focus {
    background-color: var(--bg-tertiary);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--border);
    margin: 4px 0;
}

/* Avatar trigger button */
.avatar-trigger {
    border-radius: 9999px;
    padding: 2px;
    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease;
    background: transparent;
    border: none;
    cursor: pointer;
}

.avatar-trigger:hover {
    transform: scale(1.03);
    box-shadow: 0 0 0 2px var(--border);
}

.avatar-trigger:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent);
}

/* Theme Toggle - Pill Switch */
.theme-toggle {
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border);
    position: relative;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease;
    flex-shrink: 0;
}

.theme-toggle:hover {
    border-color: var(--text-muted);
}

.theme-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent);
}

.theme-toggle.is-dark {
    background-color: var(--accent);
    border-color: var(--accent);
}

.theme-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.theme-toggle.is-dark .theme-toggle-knob {
    transform: translateX(18px);
}

.theme-toggle-knob svg {
    width: 10px;
    height: 10px;
    color: var(--text-muted);
}

.theme-toggle.is-dark .theme-toggle-knob svg {
    color: var(--accent);
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */

/* Mobile adjustments - Below 768px */
@media (max-width: 768px) {
    /* Content area adjustments */
    #main-content {
        padding-left: 12px;
        padding-right: 12px;
    }
}

/* Small mobile - Below 640px */
@media (max-width: 640px) {
    #main-content {
        padding-left: 8px;
        padding-right: 8px;
    }
}

/* ============================================
   Memo Action Dropdown Menu
   ============================================ */

.memo-dropdown {
    width: 180px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    overflow: visible;
    padding: 4px 0;
}

/* Dark mode - stronger shadow */
.theme-catppuccin-mocha .memo-dropdown,
.theme-gruvbox-dark .memo-dropdown,
.theme-kanagawa-dragon .memo-dropdown,
.theme-kanagawa-wave .memo-dropdown,
.theme-solarized-dark .memo-dropdown,
.theme-tokyonight-dark .memo-dropdown {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
}

.memo-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    transition:
        background-color 0.1s ease,
        color 0.1s ease;
}

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

.memo-menu-item:focus {
    outline: none;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.memo-menu-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.memo-menu-item--has-submenu {
    position: relative;
}

.memo-menu-item--danger:hover,
.memo-menu-item--danger:focus {
    color: var(--error);
}

.memo-menu-divider {
    height: 1px;
    background-color: var(--border);
    margin: 4px 0;
}

/* Submenu positioning - opens to the left since dropdown is right-aligned */
.memo-submenu {
    position: absolute;
    right: 100%;
    left: auto;
    top: 0;
    margin-right: 4px;
    width: 160px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    padding: 4px 0;
    z-index: 60;
}

/* Dark mode submenu */
.theme-catppuccin-mocha .memo-submenu,
.theme-gruvbox-dark .memo-submenu,
.theme-kanagawa-dragon .memo-submenu,
.theme-kanagawa-wave .memo-submenu,
.theme-solarized-dark .memo-submenu,
.theme-tokyonight-dark .memo-submenu {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Mobile: Submenu appears below instead of to the right */
@media (max-width: 640px) {
    .memo-dropdown {
        width: 200px;
    }

    .memo-menu-item {
        padding: 12px 14px;
        min-height: 44px;
        font-size: 14px;
    }

    .memo-submenu {
        position: static;
        left: auto;
        top: auto;
        margin-left: 0;
        margin-top: 4px;
        width: 100%;
        box-shadow: none;
        border: none;
        border-top: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        background-color: var(--bg-tertiary);
    }

    .memo-submenu .memo-menu-item {
        padding-left: 36px;
    }
}

/* Mobile overlay for dropdown */
.mobile-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    transition: opacity 200ms ease;
}

.mobile-overlay.mobile-overlay-visible {
    opacity: 1;
}

/* ============================================
   Cropper.js Theme Customization
   ============================================ */

/* Cropper container */
.cropper-container {
    font-family: "JetBrains Mono", ui-monospace, monospace;
}

/* Crop box border */
.cropper-view-box {
    outline: 2px solid var(--accent);
    outline-color: var(--accent);
}

/* Dashed lines inside crop area */
.cropper-dashed {
    border-color: var(--accent);
    opacity: 0.5;
}

/* Center crosshair */
.cropper-center {
    opacity: 0.5;
}

.cropper-center::before,
.cropper-center::after {
    background-color: var(--accent);
}

/* Drag points (resize handles) */
.cropper-point {
    background-color: var(--accent);
    opacity: 1;
    width: 8px;
    height: 8px;
}

/* Circular crop preview overlay */
.cropper-view-box {
    border-radius: 50%;
}

.cropper-face {
    border-radius: 50%;
    background-color: transparent;
}

/* Make the crop area circular by adding an inset shadow */
.cropper-crop-box::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

/* Hide the rectangular mask since we use circular */
.cropper-modal {
    background-color: rgba(0, 0, 0, 0.5);
}

/* Line guides */
.cropper-line {
    background-color: var(--accent);
    opacity: 0.3;
}

/* Mobile dropdown - full width bottom sheet */
@media (max-width: 640px) {
    .user-dropdown {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        margin: 0;
        max-height: 80vh;
        overflow-y: auto;
        z-index: 50;
    }

    /* Bottom sheet drag handle indicator */
    .user-dropdown::before {
        content: "";
        display: block;
        width: 36px;
        height: 4px;
        background-color: var(--border);
        border-radius: 2px;
        margin: 8px auto 4px;
    }

    /* Larger touch targets on mobile */
    .dropdown-menu-item {
        padding: 14px 16px;
        min-height: 48px;
    }

    .user-identity {
        padding: 16px;
    }

    /* Avatar trigger larger touch target */
    .avatar-trigger {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ============================================
   User Menu V2 - Redesigned Components
   ============================================ */

/* User Menu Container - positioning context for dropdown */
.user-menu-container {
    position: relative;
    width: 100%;
}

/* Full-Width Trigger Button */
.user-menu-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 56px;
    padding: 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.user-menu-trigger:hover {
    background-color: color-mix(in srgb, var(--bg-tertiary) 50%, transparent);
}

.user-menu-trigger--active {
    background-color: var(--bg-tertiary);
}

.user-menu-trigger:focus-visible {
    outline: none;
    background-color: var(--bg-tertiary);
}

.user-menu-trigger-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.user-menu-trigger-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.user-menu-trigger-avatar--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 500;
    background-color: var(--accent);
    color: var(--bg-primary);
}

.user-menu-trigger-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-trigger-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    opacity: 0.5;
    flex-shrink: 0;
    transition:
        opacity 0.15s ease,
        transform 0.2s ease;
}

.user-menu-trigger:hover .user-menu-trigger-chevron,
.user-menu-trigger--active .user-menu-trigger-chevron {
    opacity: 1;
}

.user-menu-trigger-chevron--open {
    transform: rotate(180deg);
}

/* Main Menu Dropdown V2 */
.user-dropdown-v2 {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 8px;
    width: 200px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border);
    padding: 4px 0;
    z-index: 50;
    transform-origin: bottom left;
    /* Initial state - hidden */
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity 150ms ease,
        transform 150ms ease;
}

/* Open state */
.user-dropdown-v2.user-menu-open {
    opacity: 1;
    transform: translateY(0);
}

/* Dark mode - stronger shadow, no border */
.theme-catppuccin-mocha .user-dropdown-v2,
.theme-gruvbox-dark .user-dropdown-v2,
.theme-kanagawa-dragon .user-dropdown-v2,
.theme-kanagawa-wave .user-dropdown-v2,
.theme-solarized-dark .user-dropdown-v2,
.theme-tokyonight-dark .user-dropdown-v2 {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border: none;
}

/* Menu Items */
.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 40px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    text-decoration: none;
    text-align: left;
    transition:
        background-color 0.1s ease,
        color 0.1s ease;
}

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

.user-menu-item:focus {
    outline: none;
}

.user-menu-item:focus-visible {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.user-menu-item--has-submenu {
    justify-content: flex-start;
}

.user-menu-item--danger:hover,
.user-menu-item--danger:focus {
    color: var(--error);
}

.user-menu-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.user-menu-chevron {
    width: 12px;
    height: 12px;
    margin-left: auto;
    color: var(--text-muted);
    flex-shrink: 0;
}

.user-menu-item-wrapper {
    position: relative;
}

.user-menu-divider {
    height: 1px;
    background-color: var(--border);
    margin: 4px 0;
}

/* Theme Submenu Flyout */
.theme-submenu {
    position: absolute;
    left: 100%;
    bottom: 0;
    margin-left: 4px;
    width: 180px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border);
    padding: 4px 0;
    z-index: 60;
    max-height: 300px;
    overflow-y: auto;
    /* Initial state */
    opacity: 0;
    transform: scale(0.95);
    transform-origin: left bottom;
    transition:
        opacity 120ms ease,
        transform 120ms ease;
}

/* Open state */
.theme-submenu.theme-submenu-open {
    opacity: 1;
    transform: scale(1);
}

/* Dark mode submenu */
.theme-catppuccin-mocha .theme-submenu,
.theme-gruvbox-dark .theme-submenu,
.theme-kanagawa-dragon .theme-submenu,
.theme-kanagawa-wave .theme-submenu,
.theme-solarized-dark .theme-submenu,
.theme-tokyonight-dark .theme-submenu {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border: none;
}

.theme-group-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 12px 4px;
    letter-spacing: 0.02em;
}

.theme-group-header:not(:first-child) {
    margin-top: 4px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.theme-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 12px 8px 24px;
    font-size: 13px;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    transition:
        background-color 0.1s ease,
        color 0.1s ease;
}

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

.theme-item:focus {
    outline: none;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.theme-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.theme-check {
    width: 14px;
    height: 14px;
    color: var(--accent);
    flex-shrink: 0;
}

/* User Menu Animations */
.user-menu-enter {
    transition:
        opacity 150ms ease-out,
        transform 150ms ease-out;
}

.user-menu-enter-start {
    opacity: 0;
    transform: translateY(4px);
}

.user-menu-enter-end {
    opacity: 1;
    transform: translateY(0);
}

.user-menu-leave {
    transition:
        opacity 100ms ease-in,
        transform 100ms ease-in;
}

.user-menu-leave-start {
    opacity: 1;
    transform: translateY(0);
}

.user-menu-leave-end {
    opacity: 0;
    transform: translateY(4px);
}

/* ============================================
   Search/Filter Transition Animations
   ============================================ */

/* Search loading indicator - pulse animation on search icon */
.search-loading .search-icon {
    animation: search-pulse 1s ease-in-out infinite;
}

@keyframes search-pulse {
    0%,
    100% {
        opacity: 0.4;
        transform: translateY(-50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translateY(-50%) scale(1.1);
    }
}

/* Search input container - overflow hidden for animation clipping */
.search-container {
    position: relative;
    overflow: hidden;
}

/* Search input container loading state - uses HTMX native htmx-request class */
.search-container:has(#search-input.htmx-request)::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--accent) 50%,
        transparent 100%
    );
    animation: search-shimmer 1.2s ease-in-out infinite;
}

/* Fallback for browsers without :has() support - uses JS-managed class */
.search-container.search-loading::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--accent) 50%,
        transparent 100%
    );
    animation: search-shimmer 1.2s ease-in-out infinite;
}

@keyframes search-shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Tag selected state in sidebar - outline matching memo card tag pills */
.tag-selected {
    outline: 1px solid currentColor;
    outline-offset: -1px;
    border-radius: var(--radius-sm);
}

/* Tag filter button - scale pulse on click */
.tag-filter-active {
    animation: tag-pulse var(--duration-normal) var(--ease-out);
}

/* Tag background color transition for active state */
.nav-link.tag-item {
    transition:
        background-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
}

/* Memo feed loading shimmer overlay */
#memo-feed.feed-loading::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        color-mix(in srgb, var(--bg-secondary) 50%, transparent) 50%,
        transparent 100%
    );
    animation: feed-shimmer 1.5s ease-in-out infinite;
    pointer-events: none;
    z-index: 10;
}

@keyframes feed-shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Memo feed transition classes - animation handled by JS */

/* Screen reader only - visually hidden but accessible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Reduced motion: disable search/filter animations */
@media (prefers-reduced-motion: reduce) {
    .search-loading .search-icon,
    .search-container.search-loading::after,
    .tag-filter-active,
    #memo-feed.feed-loading::before {
        animation: none !important;
    }
}

/* ============================================
   Motion.js Modal Animations
   ============================================ */

/* Modal base styles - Motion.js handles animation */
.delete-modal-backdrop,
.modal-backdrop {
    will-change: opacity;
}

.delete-modal-content,
.modal-content {
    will-change: opacity, transform;
}

/* ============================================
   Motion.js Dropdown Animations
   ============================================ */

/* Dropdown elements - Motion.js handles animations */
.user-dropdown-v2,
.theme-submenu,
.memo-dropdown {
    will-change: opacity, transform;
}

/* Chevron rotation */
.user-menu-trigger-chevron {
    transition: opacity 0.15s ease;
}

/* ============================================
   Reduced Motion Preferences
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    /* Disable all CSS animations and transitions for reduced motion */
    .memo-card,
    .pinned-card,
    .btn,
    .interactive,
    .tag,
    .dropdown,
    .icon-btn,
    .nav-link,
    .theme-transition,
    .empty-state,
    .empty-state-icon,
    .user-dropdown-v2,
    .theme-submenu,
    .memo-dropdown,
    .mobile-overlay,
    .user-menu-trigger-chevron {
        transition: none !important;
        animation: none !important;
    }

    /* Keep essential visibility transitions but make them instant */
    .memo-card:hover {
        transform: none;
    }

    .btn:hover,
    .btn:active {
        transform: none;
    }

    /* Disable hover transforms */
    .pinned-card:hover,
    .tag:hover,
    .tag:active,
    .icon-btn:hover,
    .icon-btn:active {
        transform: none;
    }

    /* Disable micro-interaction animations */
    .icon-btn-feedback,
    .tag-pulse,
    .btn-submit--loading,
    .btn-submit--success,
    .btn-submit--error,
    .copy-button--copied {
        animation: none !important;
    }

    /* Copy button visible immediately on hover */
    .code-block-wrapper:hover .copy-button,
    .code-block-wrapper:focus-within .copy-button {
        opacity: 0.6;
        transform: none;
    }

    /* Disable breathing animation on empty state icon */
    .empty-state-icon {
        animation: none !important;
    }

    /* Dropdowns appear instantly */
    .user-dropdown-v2,
    .theme-submenu,
    .memo-dropdown {
        transform: none !important;
    }
}

/* Theme Submenu Animations */
.theme-submenu-enter {
    transition:
        opacity 120ms ease-out,
        transform 120ms ease-out;
}

.theme-submenu-enter-start {
    opacity: 0;
    transform: translateY(8px);
}

.theme-submenu-enter-end {
    opacity: 1;
    transform: translateY(0);
}

.theme-submenu-leave {
    transition:
        opacity 80ms ease-in,
        transform 80ms ease-in;
}

.theme-submenu-leave-start {
    opacity: 1;
    transform: translateY(0);
}

.theme-submenu-leave-end {
    opacity: 0;
    transform: translateY(8px);
}

/* Mobile V2 - Bottom Sheet */
@media (max-width: 640px) {
    .user-dropdown-v2 {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        margin: 0;
        max-height: 80vh;
        overflow-y: auto;
        z-index: 50;
        /* Mobile initial state - slide up */
        opacity: 0;
        transform: translateY(100%);
        transition:
            opacity 200ms ease,
            transform 200ms ease;
    }

    .user-dropdown-v2.user-menu-open {
        opacity: 1;
        transform: translateY(0);
    }

    /* Bottom sheet drag handle indicator */
    .user-dropdown-v2::before {
        content: "";
        display: block;
        width: 36px;
        height: 4px;
        background-color: var(--border);
        border-radius: 2px;
        margin: 8px auto 4px;
    }

    /* Larger touch targets on mobile */
    .user-menu-item {
        padding: 14px 16px;
        min-height: 48px;
    }

    .user-menu-trigger {
        height: 60px;
        padding: 14px;
    }

    /* Theme submenu inline on mobile */
    .theme-submenu {
        position: static;
        left: auto;
        bottom: auto;
        margin-left: 0;
        margin-top: 4px;
        width: 100%;
        max-height: none;
        box-shadow: none;
        border: none;
        border-top: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        background-color: var(--bg-tertiary);
        /* Mobile submenu animation */
        opacity: 0;
        transform: translateY(-8px);
    }

    .theme-submenu.theme-submenu-open {
        opacity: 1;
        transform: translateY(0);
    }

    /* Theme submenu transition states */
    .theme-submenu-enter-start,
    .theme-submenu-leave-end {
        opacity: 0;
        transform: translateY(-8px);
    }

    .theme-submenu-enter-end,
    .theme-submenu-leave-start {
        opacity: 1;
        transform: translateY(0);
    }

    .theme-item {
        padding: 12px 16px 12px 32px;
        min-height: 44px;
    }

    .theme-group-header {
        padding: 12px 16px 6px;
    }
}

/* ============================================
   Filter Tabs - Pill Style
   ============================================ */

.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
    width: fit-content;
}

.filter-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition:
        background var(--transition-fast),
        color var(--transition-fast),
        box-shadow var(--transition-fast);
    position: relative;
}

.filter-tab:hover:not(.filter-tab--active) {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.filter-tab:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
}

.filter-tab--active {
    background: var(--accent);
    color: var(--bg-primary);
    box-shadow: var(--shadow-sm);
}

.filter-tab--active:hover {
    filter: brightness(1.05);
}

.filter-tab--active svg {
    color: var(--bg-primary);
}

.filter-tab svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* Compact filter tabs for sidebar */
.filter-tabs--compact {
    gap: 2px;
    padding: 3px;
    width: 100%;
}

.filter-tabs--compact .filter-tab {
    padding: 5px 10px;
    font-size: 11px;
    flex: 1;
    justify-content: center;
}

.filter-tabs--compact .filter-tab svg {
    width: 10px;
    height: 10px;
}

/* Reduced motion: disable filter tab transitions */
@media (prefers-reduced-motion: reduce) {
    .filter-tab {
        transition: none;
    }
}

/* ============================================
   Type Filter List - Vertical Stack Style
   Sidebar-native filter matching nav pattern
   ============================================ */

.type-filter-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    margin: 8px 0;
}

.type-filter-btn {
    display: flex;
    align-items: center;
    height: 40px;
    padding: 0 12px;
    gap: 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    transition:
        background 150ms ease,
        color 150ms ease;
}

.type-filter-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: color 150ms ease;
}

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

.type-filter-btn:hover svg {
    color: var(--text-secondary);
}

.type-filter-btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
}

.type-filter-btn--active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.type-filter-btn--active svg {
    color: var(--text-primary);
}

/* Reduced motion: disable type filter transitions */
@media (prefers-reduced-motion: reduce) {
    .type-filter-btn,
    .type-filter-btn svg {
        transition: none;
    }
}

/* ============================================
   Memo Card Action Animations
   ============================================ */

/* Pin icon animation base state */
.pin-icon {
    transform-origin: center center;
}

/* Visibility pulse animation - CSS fallback if JS fails */
@keyframes visibility-pulse {
    0% {
        box-shadow: 0 0 0 0 var(--pulse-color, var(--text-muted));
    }
    50% {
        box-shadow: 0 0 12px 2px
            color-mix(
                in srgb,
                var(--pulse-color, var(--text-muted)) 40%,
                transparent
            );
    }
    100% {
        box-shadow: 0 0 0 0 transparent;
    }
}

.memo-card.visibility-pulse {
    animation: visibility-pulse 0.6s ease-out;
}

.memo-card.visibility-pulse--private {
    --pulse-color: var(--text-muted);
}

.memo-card.visibility-pulse--protected {
    --pulse-color: var(--warning);
}

.memo-card.visibility-pulse--public {
    --pulse-color: var(--success);
}

/* Archive slide animation CSS fallback */
@keyframes slide-out-left {
    0% {
        transform: translateX(0);
        opacity: 1;
    }
    100% {
        transform: translateX(-100%);
        opacity: 0;
    }
}

@keyframes slide-out-right {
    0% {
        transform: translateX(0);
        opacity: 1;
    }
    100% {
        transform: translateX(100%);
        opacity: 0;
    }
}

.memo-card.archiving {
    animation: slide-out-left 0.3s ease-in forwards;
}

.memo-card.unarchiving {
    animation: slide-out-right 0.3s ease-in forwards;
}

/* Delete collapse animation CSS fallback */
@keyframes delete-collapse {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0;
        transform: scale(0.95);
    }
    100% {
        opacity: 0;
        transform: scale(0.95);
        height: 0;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
}

.memo-card.deleting {
    animation: delete-collapse 0.45s ease-in forwards;
}

/* Pin icon pop animation CSS fallback */
@keyframes pin-pop {
    0% {
        transform: scale(1) rotate(0deg);
    }
    50% {
        transform: scale(1.3) rotate(15deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

@keyframes pin-deflate {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(0.8);
        opacity: 0.6;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.pin-icon.pin-pop {
    animation: pin-pop 0.4s ease-out;
}

.pin-icon.pin-deflate {
    animation: pin-deflate 0.32s ease-out;
}

/* Reduced motion: disable all memo action animations */
@media (prefers-reduced-motion: reduce) {
    .memo-card,
    .pin-icon {
        will-change: auto;
    }

    .memo-card.visibility-pulse,
    .memo-card.archiving,
    .memo-card.unarchiving,
    .memo-card.deleting,
    .pin-icon.pin-pop,
    .pin-icon.pin-deflate {
        animation: none !important;
    }

    /* Instant visibility changes */
    .memo-card.archiving,
    .memo-card.unarchiving,
    .memo-card.deleting {
        opacity: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
    }
}

/* ============================================
   Tag Color Picker
   ============================================ */

/* Tag item wrapper for hover reveal of color picker */
.tag-item-wrapper {
    position: relative;
    padding-right: 24px; /* Space for the picker trigger */
}

/* Color picker trigger button */
.tag-color-picker-trigger {
    z-index: 5;
}

/* Color picker dropdown */
.tag-color-picker {
    width: auto;
    min-width: 180px;
}

/* Dark mode - stronger shadow */
.theme-catppuccin-mocha .tag-color-picker,
.theme-gruvbox-dark .tag-color-picker,
.theme-kanagawa-dragon .tag-color-picker,
.theme-kanagawa-wave .tag-color-picker,
.theme-solarized-dark .tag-color-picker,
.theme-tokyonight-dark .tag-color-picker {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Color option buttons */
.tag-color-option {
    cursor: pointer;
    flex-shrink: 0;
}

.tag-color-option:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent);
}

/* Reduced motion: disable color picker animations */
@media (prefers-reduced-motion: reduce) {
    .tag-color-option {
        transition: none;
    }

    .tag-color-option:hover {
        transform: none;
    }

    .tag-color-dot {
        transition: background-color 0.1s ease;
    }
}

/* ============================================
   Composer Header - Mode Toggle & Post
   ============================================ */

.composer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.composer-header__left,
.composer-header__right {
    display: flex;
    align-items: center;
}

/* Mode Toggle - Segmented Control */
.composer-mode-toggle {
    display: inline-flex;
    border-radius: 9999px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    padding: 2px;
    gap: 2px;
}

.composer-mode-toggle__segment {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 150ms ease;
    color: var(--text-secondary);
    background: transparent;
    border: none;
}

.composer-mode-toggle__segment--active {
    background: var(--accent);
    color: white;
}

.composer-mode-toggle__segment:not(
        .composer-mode-toggle__segment--active
    ):hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.composer-mode-toggle__segment:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.composer-mode-toggle__segment:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.composer-mode-toggle__icon {
    width: 14px;
    height: 14px;
}

/* ============================================
   Composer Footer - Tags (sketch mode only)
   ============================================ */

.composer-footer {
    /* Note: display is controlled by hidden class and flex utility in template */
    align-items: center;
}

.composer-tags {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
}

/* Ensure hidden class works on composer-tags */
.composer-tags.hidden {
    display: none !important;
}

.composer-tags__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.composer-tags__input-wrapper {
    position: relative;
}

.composer-tags__input {
    background: transparent;
    border: none;
    font-size: 0.75rem;
    color: var(--text-secondary);
    width: 80px;
    padding: 4px 8px;
}

.composer-tags__input:focus {
    outline: none;
    width: 100px;
}

.composer-tags__input::placeholder {
    color: var(--text-tertiary);
}

/* Post Button */
.composer-post-btn {
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 150ms ease;
}

.composer-post-btn:hover {
    opacity: 0.9;
}

.composer-post-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.composer-post-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Mode Switch Animation */
/* NOTE: Only use opacity, NOT transform. Excalidraw initializes when the
   container becomes visible and measures dimensions - any transform (like
   translateY) causes it to miscalculate positions for its UI elements
   (hamburger menu, Library button, zoom controls). */
@keyframes editor-fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@keyframes editor-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.editor-switching-out {
    animation: editor-fade-out 150ms ease-out forwards;
}

.editor-switching-in {
    animation: editor-fade-in 200ms ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
    .editor-switching-out,
    .editor-switching-in {
        animation: none;
    }
}

/* ============================================
   Collapsible Sidebar
   ============================================ */

/* Sidebar base - smooth width transition */
.sidebar {
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
}

/* Sidebar collapsed state - icon-only width (64px) */
.sidebar--collapsed {
    width: 4rem !important;
}

/* Header branding syncs with sidebar width */
.header-branding {
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.header-branding--collapsed {
    width: 4rem !important;
}

/* Content that hides when sidebar is collapsed */
.sidebar-content-hide {
    opacity: 1;
    visibility: visible;
    transition:
        opacity 0.15s ease,
        visibility 0.15s ease;
    overflow: hidden;
}

.sidebar--collapsed .sidebar-content-hide {
    opacity: 0;
    visibility: hidden;
    height: 0;
    width: 0;
    max-width: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

/* Text labels that hide in collapsed state */
.sidebar-label-hide {
    opacity: 1;
    transition: opacity 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar--collapsed .sidebar-label-hide {
    display: none !important; /* Completely remove from layout in collapsed state */
}

/* Icon-only elements visible when collapsed */
.sidebar-icon-only {
    display: none !important; /* Must override .sidebar-section-icon display:flex */
    opacity: 0;
    transition: opacity 0.2s ease 0.1s;
}

.sidebar--collapsed .sidebar-icon-only {
    display: flex !important;
    opacity: 1;
}

/* Section icon button - 40px hover target centered in 64px rail */
.sidebar-section-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 2px 12px; /* Explicit 12px for integer pixel alignment */
    padding: 0;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition:
        background-color 0.15s ease,
        color 0.15s ease;
    position: relative;
}

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

.sidebar-section-icon:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
}

/* 20px icons centered in 40px hover target */
.sidebar-section-icon svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Sidebar toggle button */
.sidebar-toggle {
    position: absolute;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    z-index: 20;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        transform 0.15s ease;
    box-shadow: var(--shadow-sm);
}

.sidebar-toggle:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--accent);
}

.sidebar-toggle:focus-visible {
    outline: none;
    box-shadow: var(--shadow-glow);
}

.sidebar-toggle svg {
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Rotate chevron when collapsed */
.sidebar--collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* CSS-only tooltips for collapsed state */
.sidebar-tooltip {
    position: relative;
}

.sidebar-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 10px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 0.15s ease,
        visibility 0.15s ease;
    z-index: 100;
}

/* Only show tooltips in collapsed state and on hover */
.sidebar--collapsed .sidebar-tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Collapsed state - remove padding but keep section borders, prevent horizontal scroll */
.sidebar--collapsed > div,
.sidebar--collapsed > nav {
    padding: 0 !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
}

/* Nav links in collapsed state - center icons, no background */
.sidebar--collapsed .sidebar-nav-link {
    justify-content: center;
    align-items: center;
    gap: 0 !important; /* Override gap-3 from HTML to center icon */
    padding: 0;
    width: 40px;
    height: 40px;
    margin: 2px 12px; /* Explicit 12px for integer pixel alignment */
    background: transparent !important;
    border-radius: 8px;
}

.sidebar--collapsed .sidebar-nav-link.bg-tertiary {
    background: var(--bg-tertiary) !important;
}

.sidebar--collapsed .sidebar-nav-link:hover {
    background: var(--bg-tertiary) !important;
}

.sidebar--collapsed .sidebar-nav-link svg {
    margin: 0;
    width: 20px;
    height: 20px;
}

/* User menu collapsed state */
.sidebar--collapsed .user-menu-trigger {
    justify-content: center;
    padding: 12px 0;
}

.sidebar--collapsed .user-menu-trigger-left {
    justify-content: center;
}

.sidebar--collapsed .user-menu-trigger-name,
.sidebar--collapsed .user-menu-trigger-chevron {
    display: none;
}

/* Calendar, Type filter, and Tag list containers hidden in collapsed state - no padding */

/* Reduced motion: disable sidebar transitions */
@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .header-branding,
    .sidebar-content-hide,
    .sidebar-label-hide,
    .sidebar-icon-only,
    .sidebar-toggle,
    .sidebar-toggle svg {
        transition: none;
    }
}

/* ============================================
   Expanded Composer (fills main-content area)
   ============================================ */

/* Main content needs relative positioning for expanded composer */
/* Also ensure it always has dimensions for absolutely positioned children */
#main-content {
    position: relative;
    /* Fix for HTMX navigation: ensure stable dimensions before flex calculation completes */
    /* The flex-1 class sets flex-basis: 0%, which can cause 0 height momentarily */
    min-height: 100%;
}

/* Expanded composer fills main-content area with padding for visual breathing room */
.composer-expanded {
    position: absolute !important;
    inset: 16px; /* Add padding on all sides to prevent edge cutoff */
    z-index: 100;
    background: var(--bg-primary);
    margin: 0 !important;
    max-width: none !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 12px; /* Rounded corners since we have padding */
    box-shadow: var(--shadow-lg); /* Add shadow for depth */
}

/* Hide memo feed when composer is expanded - prevents scroll bleed */
.composer-expanded ~ #memo-feed {
    display: none !important;
}

/* Toolbar stays at top when expanded */
.composer-expanded .composer-toolbar,
.composer-expanded > .bg-secondary {
    flex-shrink: 0;
}

/* Text editor fills remaining space when expanded */
/* Only apply flex when visible (not hidden) */
.composer-expanded .text-editor-wrapper:not(.hidden) {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 768px;
    width: 100%;
    margin: 0 auto;
    padding: 24px; /* uniform padding - was 24px 16px */
    overflow-y: auto;
    border: none !important;
    border-radius: 0 !important;
}

/* Height propagation through inner containers */
.composer-expanded .text-editor-wrapper #editor-wrapper-new {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: auto; /* override h-full */
}

.composer-expanded .text-editor-wrapper #editor-wrapper-new form {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.composer-expanded .text-editor-wrapper #editor-wrapper-new form > .relative {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.composer-expanded .text-editor-wrapper .editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow editor to shrink; was 200px which blocked flex growth */
}

/* Ensure CodeMirror fills the space */
.composer-expanded .text-editor-wrapper .cm-editor {
    flex: 1;
    min-height: 0;
}

/* CSS fallback for placeholder when CodeMirror widget doesn't render.
   Shows when: expanded + no native placeholder + single cm-line with only br (empty state).
   Hides when: typing (br removed), multiple lines, or native placeholder present. */
.composer-expanded .cm-content {
    position: relative;
}

.composer-expanded
    .cm-content:not(:has(.cm-placeholder)):has(.cm-line:only-child):has(
        .cm-line > br:only-child
    )::after {
    content: "Sup? Try #tags or paste/drop images...";
    color: var(--color-text-muted);
    opacity: 0.5; /* Subtle placeholder in fullscreen mode */
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
}

/* Sketch editor height chain when expanded */
/* Only apply flex when visible (not hidden) */
.composer-expanded .sketch-editor-wrapper:not(.hidden) {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-radius: 0 !important;
}

.composer-expanded .sketch-editor-wrapper #sketch-editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.composer-expanded .sketch-editor-wrapper #sketch-editor-wrapper form {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.composer-expanded
    .sketch-editor-wrapper
    #sketch-editor-wrapper
    form
    > .relative {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.composer-expanded .sketch-editor-wrapper #sketch-editor-new {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.composer-expanded .sketch-editor-wrapper .sketch-canvas {
    flex: 1;
    height: auto !important;
    min-height: 0;
}

/* Excalidraw needs explicit height to render */
.composer-expanded .sketch-editor-wrapper .excalidraw {
    height: 100% !important;
    min-height: 400px;
}

/* Expand animation - opacity only, no transform to avoid Excalidraw coordinate issues */
.composer-expanded {
    animation: composer-expand 0.2s ease-out;
}

@keyframes composer-expand {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Reduced motion: disable composer expand animation */
@media (prefers-reduced-motion: reduce) {
    .composer-expanded {
        animation: none;
    }
}

/* ============================================
   View Transitions API - Pin Animation
   ============================================ */

/* Enable View Transitions for same-document navigations */
@view-transition {
    navigation: auto;
}

/* Disable root transition to prevent full-page flash */
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0ms;
}

/* Memo card view transitions - smooth position changes */
::view-transition-group(memo-*) {
    animation-duration: 500ms;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Memo card old/new states during transition */
::view-transition-old(memo-*),
::view-transition-new(memo-*) {
    /* Crossfade effect during transition */
    animation-duration: 500ms;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sweeping light border animation for pinned card */
@keyframes border-sweep {
    0% {
        --sweep-angle: 0deg;
    }
    100% {
        --sweep-angle: 360deg;
    }
}

@property --sweep-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: false;
}

.memo-card.pin-highlight {
    position: relative;
    overflow: visible;
}

.memo-card.pin-highlight::before {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: calc(var(--rounded-lg, 0.5rem) + 3px);
    background: conic-gradient(
        from var(--sweep-angle),
        transparent 0deg,
        transparent 270deg,
        var(--text-muted) 330deg,
        transparent 360deg
    );
    z-index: -1;
    animation: border-sweep 2s linear forwards;
    opacity: 0.9;
}

.memo-card.pin-highlight::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--rounded-lg, 0.5rem);
    background: var(--bg-secondary);
    z-index: -1;
}

/* Reduced motion: instant transitions */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(memo-*),
    ::view-transition-old(memo-*),
    ::view-transition-new(memo-*) {
        animation-duration: 0ms;
    }
}

/* ========== Animation System ========== */
/* CSS keyframe animations for UI transitions */

/* --- Fade Animations --- */
@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* --- Scale + Fade (for modals, dropdowns) --- */
@keyframes scale-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scale-out {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

/* --- Slide (for toasts) --- */
@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slide-down {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(8px);
    }
}

/* --- Memo delete/archive exit animation --- */
@keyframes memo-exit {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.95);
        max-height: 0;
        margin-top: 0;
        margin-bottom: 0;
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
    }
}

/* --- Sidebar count pulse (jiggle) animation --- */
@keyframes sidebar-count-pulse {
    0% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.3) rotate(-5deg);
    }
    50% {
        transform: scale(1.2) rotate(5deg);
    }
    75% {
        transform: scale(1.1) rotate(-2deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

.sidebar-count-pulse {
    animation: sidebar-count-pulse 400ms ease-out;
}

/* --- Transition Utilities --- */
.transition-opacity {
    transition-property: opacity;
}
.transition-transform {
    transition-property: transform;
}
.transition-all {
    transition-property: all;
}
.duration-150 {
    transition-duration: 150ms;
}
.duration-200 {
    transition-duration: 200ms;
}
.duration-300 {
    transition-duration: 300ms;
}
.ease-in {
    transition-timing-function: ease-in;
}
.ease-out {
    transition-timing-function: ease-out;
}
.ease-in-out {
    transition-timing-function: ease-in-out;
}

/* ============================================
   Tag Input Bar - Composer
   ============================================ */

/* Tag bar container (legacy class) */
.tag-bar {
    min-height: 2.5rem;
}

/* Tag chip - base styles (scoped to tag-bar and composer-tags to avoid memo card conflicts) */
.tag-bar .tag-chip,
.composer-tags .tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    background-color: var(--bg-tertiary);
    font-size: 0.75rem;
    line-height: 1;
    color: var(--text-secondary);
    transition: background-color 0.15s ease;
}

.tag-bar .tag-chip:hover,
.composer-tags .tag-chip:hover {
    background-color: var(--bg-tertiary);
}

/* Tag chip - inline variant (read-only, muted) */
.tag-bar .tag-chip--inline,
.composer-tags .tag-chip--inline {
    opacity: 0.7;
}

/* Tag chip color dot */
.tag-bar .tag-chip__dot,
.composer-tags .tag-chip__dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 9999px;
    background-color: var(--accent);
    flex-shrink: 0;
}

/* Inline tag dot - muted/gray */
.tag-bar .tag-chip__dot--inline,
.composer-tags .tag-chip__dot--inline {
    background-color: var(--text-tertiary);
}

/* Tag chip name */
.tag-bar .tag-chip__name,
.composer-tags .tag-chip__name {
    white-space: nowrap;
}

/* Tag chip remove button */
.tag-bar .tag-chip__remove,
.composer-tags .tag-chip__remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    padding: 0;
    margin-left: 0.125rem;
    border: none;
    border-radius: 9999px;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    transition:
        color 0.15s ease,
        background-color 0.15s ease;
}

.tag-bar .tag-chip__remove:hover,
.composer-tags .tag-chip__remove:hover {
    color: var(--error);
    background-color: var(--error-bg, rgba(239, 68, 68, 0.1));
}

/* Tag input field */
.tag-input-field {
    width: 6rem;
    min-width: 4rem;
}

.tag-input-field:focus {
    width: 10rem;
}

/* Tag autocomplete dropdown */
.tag-dropdown {
    max-height: 12rem;
    overflow-y: auto;
    padding: 0.25rem;
}

/* Tag suggestion item */
.tag-suggestion {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 0.375rem;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

.tag-suggestion:hover,
.tag-suggestion--highlighted {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Tag suggestion dot */
.tag-suggestion__dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 9999px;
    background-color: var(--accent);
    flex-shrink: 0;
}

/* ============================================
   Animation Exit Classes
   Used by animation.ts utilities for robust
   exit animations that respect CSS tokens
   ============================================ */

.toast-exit {
    animation: slide-down var(--duration-fast) var(--ease-in) forwards;
}

.dropdown-exit {
    animation: scale-out var(--duration-fast) var(--ease-in) forwards;
}

.modal-exit {
    animation: fade-out var(--duration-fast) var(--ease-in) forwards;
}

.memo-card-exit {
    animation: memo-exit var(--duration-normal) var(--ease-in) forwards;
}

/* --- Reduced Motion Support (Accessibility) --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
