body {
    background-color: #f5f5f5;
    font-family: 'Roboto', sans-serif;
    /* Ensure padding for sticky footer so content isn't hidden */
    padding-bottom: 80px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.grid {
    width: 100%;
    display: flow-root;
    /* Clearfix for floated items */
}

.grid-sizer,
.grid-item {
    width: 32%;
    /* 3 columns */
}

@media (max-width: 900px) {

    .grid-sizer,
    .grid-item {
        width: 48%;
        /* 2 columns */
    }
}

@media (max-width: 600px) {

    .grid-sizer,
    .grid-item {
        width: 100%;
        /* 1 column */
    }
}

.grid-item {
    float: left;
    margin-bottom: 10px;
    padding: 0;
    /* gutter imitation */
}

.note-card {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    background: #fff;
    box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    transition: box-shadow 0.2s;
    overflow: hidden;
}

.note-card:hover {
    box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 2px 6px 2px rgba(60, 64, 67, 0.15);
}

.note-title {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 10px;
    display: block;
    color: #202124;
    text-decoration: none;
}

.note-items-preview {
    font-size: 0.9em;
    color: #5f6368;
}

.note-item-preview {
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-item-checked {
    text-decoration: line-through;
    color: #b0b0b0;
}

.note-actions {
    margin-top: 15px;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.note-card:hover .note-actions {
    opacity: 1;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: #5f6368;
    text-decoration: none;
    font-size: 0.9em;
}

.btn-icon:hover {
    color: #202124;
}

.note-image-preview img {
    max-width: 100%;
    border-radius: 4px;
    margin-bottom: 8px;
}

/* Sticky Header and Footer Styles */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 1030;
    /* Bootstrap sticky-top z-index */
    background-color: rgba(245, 245, 245, 0.95);
    /* Match body bg with slight transparency */
    backdrop-filter: blur(5px);
    padding-top: 10px;
    padding-bottom: 10px;
    margin-bottom: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.sticky-footer {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    /* max-width: 800px;  Removed to allow full width on mobile if needed, handled by media query if specific */
    max-width: 800px;
    /* Match note container max-width */
    z-index: 1030;
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    border-top: 1px solid #e0e0e0;
    border-radius: 8px 8px 0 0;
    /* Rounded top corners */

    /* Mobile optimization for horizontal scrolling */
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    /* Hide scrollbar for cleaner look */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.sticky-footer::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

/* Tiptap Editor Styles */
.tiptap-editor img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.tiptap-editor li p {
    margin-top: 0;
    margin-bottom: 0;
}

.tiptap-editor .ProseMirror-focused {
    outline: 1px solid #e0e0e0;
}

.tiptap-editor pre {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.5rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    white-space: pre-wrap;
    margin: 0.5rem 0;
}

.tiptap-editor code {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.1rem 0.3rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.875em;
    color: #e83e8c;
}

.tiptap-editor .ProseMirror {
    outline: none;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
}

.tiptap-editor pre code {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
    font-family: inherit;
}

.sortable-ghost {
    opacity: 0.4;
    background-color: #e0e0e0;
    border: 1px dashed #999;
}

.sortable-drag {
    cursor: grabbing;
    opacity: 1;
}


/* Note Order Buttons */
.note-order-buttons {
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.note-card:hover .note-order-buttons {
    opacity: 1;
}

/* Default state: hide all first, then show based on rules */
.order-btn-up,
.order-btn-down,
.order-btn-top,
.order-btn-bottom {
    display: none;
}

/* Rules for > 2 items */
/* We need to be specific about direct children grid items */
.grid:not(.count-1):not(.count-2) .grid-item .order-btn-up,
.grid:not(.count-1):not(.count-2) .grid-item .order-btn-down {
    display: inline-block;
}

/* First item in > 2 list */
/* .grid-sizer is first child, so first actual item is nth-child(2) */
.grid:not(.count-1):not(.count-2) .grid-item:nth-child(2) .order-btn-up,
.grid:not(.count-1):not(.count-2) .grid-item:nth-child(2) .order-btn-top {
    display: none;
}

.grid:not(.count-1):not(.count-2) .grid-item:nth-child(2) .order-btn-down,
.grid:not(.count-1):not(.count-2) .grid-item:nth-child(2) .order-btn-bottom {
    display: inline-block;
}

/* Last item in > 2 list */
.grid:not(.count-1):not(.count-2) .grid-item:last-child .order-btn-down,
.grid:not(.count-1):not(.count-2) .grid-item:last-child .order-btn-bottom {
    display: none;
}

.grid:not(.count-1):not(.count-2) .grid-item:last-child .order-btn-up,
.grid:not(.count-1):not(.count-2) .grid-item:last-child .order-btn-top {
    display: inline-block;
}


/* Rules for exactly 2 items */
/* First item (2nd child) */
.grid.count-2 .grid-item:nth-child(2) .order-btn-down {
    display: inline-block;
}

/* Last item */
.grid.count-2 .grid-item:last-child .order-btn-up {
    display: inline-block;
}

/* Hide top/bottom buttons/other checks for 2 items or less */
.grid.count-2 .order-btn-top,
.grid.count-2 .order-btn-bottom {
    display: none !important;
}

.grid.count-1 .order-btn-top,
.grid.count-1 .order-btn-bottom,
.grid.count-1 .order-btn-up,
.grid.count-1 .order-btn-down {
    display: none !important;
}

/* Mobile Optimizations */
@media (max-width: 600px) {
    body {
        /* Mobile padding adjustment */
        padding-bottom: 100px;
    }

    .container {
        padding: 10px;
    }

    .note-card {
        padding: 12px;
    }

    .note-actions {
        opacity: 1 !important;
        /* Always show actions on mobile because there is no hover */
        margin-top: 10px;
    }

    /* Larger touch targets for inputs */
    input.form-control,
    textarea.form-control {
        font-size: 16px !important;
        /* Prevent iOS zoom */
        padding: 10px;
    }

    /* Color palette balls bigger on mobile */
    .color-ball {
        width: 36px !important;
        height: 36px !important;
    }

    /* Adjust sticky footer buttons for better touch */
    .sticky-footer .btn {
        padding: 0.5rem 0.75rem;
        font-size: 1.1rem;
    }

    /* Note Edit Page: Full width on mobile */
    .note-edit-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .note-edit-container .card {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

/* Fix for checkbox items in Note Index to be inline */
.note-checkbox-content p {
    display: inline;
    margin: 0;
}

/* TipTap Line Numbers */
.tiptap-editor.show-line-numbers {
    counter-reset: line;
}

.tiptap-editor.show-line-numbers .ProseMirror>* {
    position: relative;
    padding-left: 2.5rem;
    /* Space for line numbers */
}

.tiptap-editor.show-line-numbers .ProseMirror>*::before {
    counter-increment: line;
    content: counter(line);
    position: absolute;
    left: 0;
    top: 0;
    width: 2rem;
    height: 100%;
    text-align: right;
    color: #adb5bd;
    /* Text muted color */
    font-size: 0.8rem;
    user-select: none;
    padding-right: 5px;
    border-right: 1px solid #e9ecef;
}

/* History Read More functionality */
.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    /* Standard property for compatibility */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.read-more-btn {
    font-size: 0.8em;
    padding: 0;
    margin-top: 5px;
    text-decoration: none;
    color: #0dcaf0;
    /* Bootstrap info */
    cursor: pointer;
    background: none;
    border: none;
}

.read-more-btn:hover {
    text-decoration: underline;
    color: #0aa2c0;
}
/* Tiptap Link Context Menu */
.tiptap-link-context-menu {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 6px;
    z-index: 9999;
    display: none;
    flex-direction: column;
    padding: 6px 0;
    min-width: 200px;
    font-size: 14px;
}

.tiptap-link-context-menu button {
    background: none;
    border: none;
    text-align: left;
    padding: 8px 16px;
    width: 100%;
    cursor: pointer;
    color: #333;
    display: block;
    transition: background-color 0.2s;
    font-size: 14px;
}

.tiptap-link-context-menu button:hover {
    background-color: #f5f5f5;
    color: #000;
}

/* Custom Video Analysis Icon */
.bi-video-analysis {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    content: "";
    background-color: currentColor;
    -webkit-mask-image: url("../images/video-analysis-ab4f8ea030dfcc5e04a46e07a972ffb3.svg");
    mask-image: url("../images/video-analysis-ab4f8ea030dfcc5e04a46e07a972ffb3.svg");
    -webkit-mask-size: cover;
    mask-size: cover;
}

/* ─── Report Output ──────────────────────────────────── */
.report-output {
    max-height: 75vh;
    overflow-y: auto;
    font-size: 0.92em;
    line-height: 1.6;
}

.report-output h1,
.report-output h2,
.report-output h3 {
    border-bottom: 1px solid #eee;
    padding-bottom: 0.3em;
    margin-top: 1.2em;
    margin-bottom: 0.6em;
}

.report-output h1 { font-size: 1.4em; }
.report-output h2 { font-size: 1.15em; }
.report-output h3 { font-size: 1em; }

.report-output table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.8em 0;
    font-size: 0.9em;
}

.report-output th,
.report-output td {
    border: 1px solid #dee2e6;
    padding: 6px 10px;
    text-align: left;
}

.report-output th {
    background: #f8f9fa;
    font-weight: 600;
}

.report-output tr:nth-child(even) {
    background: #fafafa;
}

.report-output svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.5em auto;
}

.report-output pre {
    background: #f6f8fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 0.8em;
    overflow-x: auto;
    font-size: 0.85em;
    max-height: 400px;
}

.report-output code {
    background: #f6f8fa;
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
}

/* Markdown Preview Wrapping Fix */
.markdown-preview,
.markdown-preview-index {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
}

.markdown-preview pre,
.markdown-preview-index pre {
    white-space: pre-wrap;
    overflow-x: auto;
    max-width: 100%;
}

.markdown-preview img,
.markdown-preview-index img {
    max-width: 100%;
    height: auto;
}

.markdown-preview svg,
.markdown-preview-index svg {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Nuanced formatting for Note Detail markdown preview */
.markdown-preview {
    font-size: 1rem;
    color: #202124;
    line-height: 1.6;
}

.markdown-preview h1 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-top: 1em;
    margin-bottom: 0.5em;
    color: #202124;
}

.markdown-preview h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 1em;
    margin-bottom: 0.5em;
    color: #202124;
}

.markdown-preview h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: 0.8em;
    margin-bottom: 0.4em;
    color: #202124;
}

.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 0.8em;
    margin-bottom: 0.4em;
    color: #202124;
}

.markdown-preview blockquote {
    border-left: 4px solid #dadce0;
    padding-left: 1em;
    margin-left: 0;
    color: #5f6368;
    font-style: italic;
}

/* Nuanced formatting for Note Index markdown preview */
.markdown-preview-index {
    font-size: 0.9em;
    color: #3c4043;
    line-height: 1.4;
}

.markdown-preview-index h1 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 0.5em;
    margin-bottom: 0.3em;
    color: #202124;
}

.markdown-preview-index h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 0.5em;
    margin-bottom: 0.3em;
    color: #202124;
}

.markdown-preview-index h3,
.markdown-preview-index h4,
.markdown-preview-index h5,
.markdown-preview-index h6 {
    font-size: 1rem;
    font-weight: 600;
    margin-top: 0.4em;
    margin-bottom: 0.2em;
    color: #202124;
}

.markdown-preview-index p {
    margin-bottom: 0.5em;
}

.markdown-preview-index p:last-child {
    margin-bottom: 0;
}

.markdown-preview-index ul,
.markdown-preview-index ol {
    padding-left: 1.2em;
    margin-bottom: 0.5em;
}

.markdown-preview-index blockquote {
    border-left: 3px solid #dadce0;
    padding-left: 0.8em;
    margin-left: 0;
    color: #5f6368;
    font-style: italic;
}

.markdown-preview-index code {
    background-color: #f1f3f4;
    padding: 0.15em 0.3em;
    border-radius: 3px;
    font-size: 0.9em;
    color: #d63384;
}

.markdown-preview-index pre {
    background-color: #f8f9fa;
    border: 1px solid #e8eaed;
    border-radius: 4px;
    padding: 0.5em;
    margin-bottom: 0.5em;
}

.markdown-preview-index pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
}

/* Compact text preview rules */
.compact-text-preview p {
    display: inline;
    margin: 0;
}

.compact-text-preview h1,
.compact-text-preview h2,
.compact-text-preview h3,
.compact-text-preview h4,
.compact-text-preview h5,
.compact-text-preview h6 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.2rem 0;
    line-height: 1.2;
    display: inline-block;
}

.compact-text-preview ul,
.compact-text-preview ol {
    margin-bottom: 0;
    padding-left: 1.2em;
}

.compact-text-preview blockquote {
    margin-bottom: 0;
    padding-left: 0.8em;
    border-left: 2px solid #dadce0;
    font-style: italic;
    color: #5f6368;
}

.compact-text-preview img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    margin: 0.5em 0;
}
