:root {
    --font-mono: 'JetBrains Mono', monospace;
    --bg-sidebar: #09090b;
    --bg-main: #121215;
    --border-color: #27272a;
    --border-subtle: rgba(255, 255, 255, 0.07);
    --text-primary: #f4f4f5;
    --text-secondary: #71717a;
    --text-dim: #a1a1aa;
    --primary-bg: #fafafa;
    --primary-text: #09090b;
    --primary-hover: #e4e4e7;
    --surface-hover: #18181b;
    --active-item: #18181b;
    --danger: #ef4444;
    --warning: #eab308;
    --success: #22c55e;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: var(--font-mono);
    background-color: var(--bg-sidebar);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    font-size: 13.5px;
}

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

/* Sidebar */
.sidebar {
    width: 310px;
    min-width: 270px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.admin-badge-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.2rem 0.35rem;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.btn-ghost-sm {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    transition: all 0.15s ease;
}

.btn-ghost-sm:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn-new {
    width: 100%;
    justify-content: center;
}

.sidebar-list-header {
    padding: 1rem 1rem 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    font-family: var(--font-mono);
}

.count-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.sidebar-notes-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Sidebar Item */
.note-item {
    padding: 0.75rem 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-family: var(--font-mono);
}

.note-item:hover {
    background: var(--surface-hover);
}

.note-item.active {
    background: var(--active-item);
    border: 1px solid var(--border-color);
}

.note-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.note-item-title {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.note-item-date {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.68rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.badge-admin {
    background: #27272a;
    color: #e4e4e7;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.badge-status {
    font-size: 0.7rem;
    padding: 0.2rem 0.45rem;
}

.badge-draft {
    background: rgba(234, 179, 8, 0.12);
    color: #facc15;
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.badge-published {
    background: rgba(34, 197, 94, 0.1);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.badge-deleted {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Sidebar Pagination Footer */
.sidebar-pagination {
    padding: 0.65rem 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-sidebar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-mono);
}

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

.btn-ghost {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    transition: color 0.15s ease;
}

.btn-ghost:hover:not(:disabled) {
    color: var(--text-primary);
}

.btn-ghost:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Main View */
.main-view {
    flex: 1;
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}

.view-state {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

.empty-view {
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
    font-family: var(--font-mono);
}

.empty-view h2 {
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.empty-view p {
    font-size: 0.9rem;
}

/* Active Note Toolbar */
.note-toolbar {
    padding: 0.85rem 2.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-main);
    font-family: var(--font-mono);
    position: sticky;
    top: 0;
    z-index: 5;
}

.note-meta {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.note-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-family: var(--font-mono);
    transition: all 0.15s ease;
}

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

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

.btn-secondary {
    background: #18181b;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #27272a;
}

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

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

.btn-danger-ghost {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    transition: color 0.15s ease;
}

.btn-danger-ghost:hover {
    color: var(--danger);
}

/* Content Area */
.note-content-area {
    flex: 1;
    padding: 2.5rem 3rem;
    width: 100%;
}

.note-editor-area {
    flex: 1;
    padding: 2.5rem 3rem;
    overflow-y: auto;
    width: 100%;
}

.note-display-title {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    font-family: var(--font-mono);
}

/* Editor Inputs */
.editor-header-fields {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.editor-title-input {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.4rem 0;
    outline: none;
    font-family: var(--font-mono);
}

.editor-title-input:focus {
    border-bottom-color: var(--text-primary);
}

.field-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.field-inline label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-select {
    background: #18181b;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.45rem 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.status-select:focus {
    border-color: var(--text-primary);
}

.editor-body-input {
    width: 100%;
    height: calc(100% - 80px);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    outline: none;
    resize: none;
}

.editor-body-input:focus {
    border-color: var(--text-primary);
}

/* Live preview area inside the editor (same box as the textarea) */
.editor-preview {
    height: calc(100% - 80px);
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

/* Live preview inside the create modal */
.modal-preview {
    min-height: 160px;
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

/* Highlight a textarea while an image is dragged over it */
textarea.drag-over {
    border-color: var(--success);
    outline: 1px dashed var(--success);
    outline-offset: -3px;
    background: rgba(34, 197, 94, 0.06);
}

/* Markdown Rendering in Viewer */
.markdown-rendered {
    font-family: var(--font-mono);
    font-size: 0.93rem;
    color: var(--text-dim);
    line-height: 1.75;
    overflow-wrap: break-word;
    word-break: break-word;
}

.markdown-rendered h1,
.markdown-rendered h2,
.markdown-rendered h3 {
    color: var(--text-primary);
    margin-top: 1.4rem;
    margin-bottom: 0.6rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.markdown-rendered h1 { font-size: 1.4rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.3rem; }
.markdown-rendered h2 { font-size: 1.2rem; }
.markdown-rendered h3 { font-size: 1.05rem; }

.markdown-rendered p { margin-bottom: 1rem; }
.markdown-rendered ul, .markdown-rendered ol { margin-left: 1.4rem; margin-bottom: 1rem; }
.markdown-rendered li { margin-bottom: 0.25rem; }

.markdown-rendered blockquote {
    border-left: 2px solid var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    color: var(--text-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown-rendered code {
    font-family: var(--font-mono);
    background: #18181b;
    color: #f4f4f5;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.88em;
    border: 1px solid var(--border-color);
}

.markdown-rendered pre {
    background: #18181b;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.markdown-rendered pre code {
    background: transparent;
    padding: 0;
    border: none;
    color: #f4f4f5;
}

/* Tables (GFM) */
.markdown-rendered table {
    display: block;              /* let wide tables scroll instead of breaking the layout */
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.9rem;
}

.markdown-rendered th,
.markdown-rendered td {
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.markdown-rendered th {
    background: var(--surface-hover);
    color: var(--text-primary);
    font-weight: 600;
}

.markdown-rendered tbody tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

/* Modal Popup */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: #121215;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 70vw;
    height: 75vh;
    max-width: 1200px;
    min-width: 500px;
    padding: 2rem;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    font-family: var(--font-mono);
}

.modal-card-sm {
    width: 440px;
    height: auto;
    min-width: 320px;
    padding: 1.75rem;
}

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

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    font-family: var(--font-mono);
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    flex: 1;
    overflow: hidden;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.field-hint {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.field-textarea {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.field label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.modal-form input[type="text"],
.modal-form input[type="password"] {
    background: #09090b;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.92rem;
    outline: none;
}

.modal-form textarea {
    flex: 1;
    width: 100%;
    height: 100%;
    background: #09090b;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    outline: none;
    resize: none;
    min-height: 0;
}

.modal-form input:focus,
.modal-form textarea:focus {
    border-color: var(--text-primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
}

.form-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

.form-success {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.4);
    color: #86efac;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

/* -------------------------------------------------------------------------
   Reactions
   ---------------------------------------------------------------------- */

.reactions-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 0 0.5rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1.5rem;
}

.reaction-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.35rem 0.85rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.reaction-btn:hover {
    border-color: var(--text-dim);
    color: var(--text-primary);
}

.reaction-btn.active-like {
    border-color: #22c55e;
    color: #22c55e;
    background: rgba(34, 197, 94, 0.08);
}

.reaction-btn.active-dislike {
    border-color: #ef4444;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

/* -------------------------------------------------------------------------
   Comments Section
   ---------------------------------------------------------------------- */

.comments-section {
    margin-top: 3rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border-color);
}

.comments-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 1rem;
}

/* Form for new comment — cohesive compose card */
.comment-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
    padding: 1rem;
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.comment-form input,
.comment-form textarea {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.15s;
}

.comment-form input:focus,
.comment-form textarea:focus {
    border-color: var(--text-dim);
}

.comment-form textarea {
    resize: vertical;
    min-height: 70px;
}

.comment-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Comment tree */
.comments-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.comment-item {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border-subtle);
    padding: 0.9rem 0;
}

.comment-item:first-child {
    border-top: none;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.35rem;
}

.comment-author {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
}

.comment-date {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.comment-body {
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.comment-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.4rem;
}

.btn-reply {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
}

.btn-reply:hover {
    color: var(--text-primary);
}

.btn-delete-comment {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
}

.btn-delete-comment:hover {
    color: var(--danger);
}

/* Replies indent */
.comment-replies {
    margin-left: 1.4rem;
    padding-left: 1rem;
    border-left: 2px solid var(--border-color);
}

/* Inline reply form */
.inline-reply-form {
    margin-top: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.inline-reply-form textarea {
    background: #09090b;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.75rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    resize: vertical;
    min-height: 60px;
    outline: none;
}

.inline-reply-form textarea:focus {
    border-color: var(--text-dim);
}

.inline-reply-form input {
    background: #09090b;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    outline: none;
}

.inline-reply-form-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.comments-load-more {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

/* Bigger emoji inside buttons (e.g. Restore) */
.btn-emoji {
    font-size: 1.15rem;
    line-height: 1;
}

/* -------------------------------------------------------------------------
   Mobile: collapsible sidebar drawer, full-screen note
   ---------------------------------------------------------------------- */
.mobile-only {
    display: none;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

@media (max-width: 768px) {
    .mobile-only {
        display: inline-flex;
    }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 50;
        width: 82%;
        max-width: 320px;
        min-width: 0;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .app-layout.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
    }

    .app-layout.sidebar-open .sidebar-backdrop {
        display: block;
    }

    /* Full-screen note: stack the meta/date row ABOVE the action buttons */
    .note-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.55rem;
        padding: 0.7rem 1.1rem;
        position: static; /* tall stacked toolbar shouldn't eat the screen as a sticky header */
    }

    .note-meta {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.4rem 0.7rem;
    }

    .note-date {
        font-size: 0.72rem;
        white-space: normal;
        line-height: 1.4;
    }

    .toolbar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    #mobileMenuBtn {
        font-size: 1.25rem;
        padding: 0.15rem 0.3rem;
    }

    .note-content-area,
    .note-editor-area {
        padding: 1.5rem 1.1rem;
    }
}

