.comments-section {
    margin-top: var(--spacing-8);
    padding-top: var(--spacing-6);
    border-top: 1px solid var(--background-200);
}

.user {
    flex: 0 0 var(--size);
    width: var(--size);
    height: var(--size);
    background-color: transparent;
    overflow: hidden;
}

.user .avatar {
    width: 100%;
    height: 100%;
    background-color: var(--background-300);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* comment component */

.comment {
    --size: var(--spacing-8);
    position: relative;
    display: flex;
    gap: var(--spacing-2);

    p {
        font-family: "Flow Circular", sans-serif;
        color: var(--text-500);
    }

    /*@container style(--depth: 1) or style(--depth: 2) {*/
    /*    --size: var(--spacing-6);*/
    /*}*/
}

.comment-content {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.comment-author-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: var(--size);
}

.author-line {
    display: flex;
    align-items: center;
    line-height: 1.2;
}

.author-name {
    font-weight: 700;
    color: var(--text-600);
    font-size: var(--font-size-xs);
}

.comment-time {
    color: var(--text-600);
    font-size: var(--font-size-xs);
}

.author-badge {
    color: var(--text-600);
    font-size: var(--font-size-xs);
    line-height: 1.2;
    margin-top: 2px;
}

/* Single line author info centering */
.comment-author-info:has(.author-badge:empty) {
    justify-content: center;
}

/* Two line author info centering */
.comment-author-info:not(:has(.author-badge:empty)) {
    justify-content: center;
}

/* Remove all list markers from comments */
.comments-list ul,
.comments-list li {
    list-style: none;
    list-style-type: none;
}

.comments-list li::marker {
    display: none;
}

/* Comments header with refresh button */
.comments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-4);
}

.comments-header h3 {
    margin: 0;
    flex: 1;
}

/* Comments refresh button */
.comments-refresh-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-1);
    padding: var(--spacing-2) var(--spacing-3);
    background: var(--background-100);
    border: 1px solid var(--background-200);
    border-radius: var(--radius-sm);
    color: var(--text-500);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.comments-refresh-btn:hover:not(:disabled) {
    background: var(--background-200);
    border-color: var(--background-300);
    color: var(--text-600);
}

.comments-refresh-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.comments-refresh-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Spinning animation for refresh icon */
.comments-refresh-btn svg.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Responsive behavior for refresh button */
@media (max-width: 640px) {
    .comments-refresh-btn {
        padding: var(--spacing-1) var(--spacing-2);
        font-size: var(--font-size-xs);
    }
    
    .comments-refresh-btn svg {
        width: 14px;
        height: 14px;
    }
}

.comments-list > ul,
.comments-list li > ul {
    list-style: none;
}

.comment-actions {
    display: flex;
    gap: var(--spacing-1);
    padding-block: var(--spacing-2);
    position: relative;

    a {
        text-decoration: none;
        color: var(--text-800);
        font-size: var(--font-size-sm);
        font-weight: bold;
    }
}

.comment-actions .collapse-button,
.comment-actions .expand-button {
    background: var(--background-50);
    color: var(--text-500);
    position: absolute;
    right: calc(-1 * 35px);
    top: 50%;
    transform: translateY(-50%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: all 0.2s ease;
}

.comment-actions .collapse-button:hover,
.comment-actions .expand-button:hover {
    border-color: var(--text-500);
    color: var(--primary-600);
}

.comment-actions .expand-button:hover {
    color: var(--primary-600);
}

.comment-actions .collapse-button:active {
    transform: translateY(-50%) scale(0.95);
}

.comment-body {
    /* Base text elements */
    p {
        color: var(--text-700);
        font-size: var(--font-size-sm);
        font-family: var(--font-family-primary);
        margin: 0;
        line-height: 1.5;
    }

    /* Lists */
    ul, ol {
        color: var(--text-700);
        font-size: var(--font-size-sm);
        font-family: var(--font-family-primary);
        margin: 0;
        padding-inline-start: var(--spacing-4);
        list-style-position: inside;
    }

    ul {
        list-style-type: disc;
    }

    ol {
        list-style-type: decimal;
    }

    /* Handle Quill's data-list format - override list-style for mixed lists */
    ol li[data-list="bullet"] {
        list-style-type: disc;
    }

    ol li[data-list="ordered"] {
        list-style-type: decimal;
    }

    /* More specific styling for Quill lists to ensure proper display */
    ol li[data-list="bullet"]::marker {
        content: "• ";
    }

    ol li[data-list="ordered"] {
        counter-increment: list-counter;
    }

    ol li[data-list="ordered"]::marker {
        content: counter(list-counter) ". ";
    }

    /* Reset counter for each ol in comment body */
    .comment-body ol {
        counter-reset: list-counter;
    }

    li {
        color: var(--text-700);
        font-size: var(--font-size-sm);
        font-family: var(--font-family-primary);
        margin: var(--spacing-1) 0;
        list-style: inherit;
        padding-inline-start: 0;
    }

    /* Nested lists */
    ul ul, ol ol, ul ol, ol ul {
        margin-top: var(--spacing-1);
        margin-bottom: var(--spacing-1);
        padding-inline-start: var(--spacing-3);
    }

    ul ul {
        list-style-type: circle;
    }

    ul ul ul {
        list-style-type: square;
    }

    /* Blockquotes */
    blockquote {
        margin: var(--spacing-2) 0;
        padding-inline-start: var(--spacing-3);
        border-inline-start: 3px solid var(--text-400);
        color: var(--text-600);
        font-style: italic;
        background: var(--background-100);
        border-radius: 0 4px 4px 0;
        padding: var(--spacing-2) var(--spacing-3);
    }

    /* Links */
    a {
        color: var(--primary-600);
        text-decoration: underline;
        text-decoration-thickness: 1px;
        text-underline-offset: 2px;
        transition: color 0.2s ease;
    }

    a:hover {
        color: var(--primary-700);
        text-decoration-thickness: 2px;
    }

    a:visited {
        color: var(--primary-500);
    }

    /* Text formatting */
    strong, b {
        font-weight: 700;
        color: var(--text-800);
    }

    em, i {
        font-style: italic;
        color: var(--text-700);
    }

    u {
        text-decoration: underline;
        text-decoration-thickness: 1px;
        text-underline-offset: 2px;
    }

    s, strike {
        text-decoration: line-through;
        color: var(--text-500);
    }

    /* Code blocks */
    code {
        background: var(--background-200);
        color: var(--text-800);
        padding: 2px 4px;
        border-radius: 3px;
        font-family: "Courier New", Consolas, monospace;
        font-size: calc(var(--font-size-sm) * 0.9);
        direction: ltr;
        unicode-bidi: embed;
    }

    pre {
        background: var(--background-200);
        color: var(--text-800);
        padding: var(--spacing-2);
        border-radius: 4px;
        overflow-x: auto;
        font-family: "Courier New", Consolas, monospace;
        font-size: calc(var(--font-size-sm) * 0.9);
        direction: ltr;
        white-space: pre-wrap;
        word-wrap: break-word;
    }

    pre code {
        background: none;
        padding: 0;
        border-radius: 0;
    }

    /* Line breaks */
    br {
        line-height: 1.5;
    }

    /* Horizontal rules */
    hr {
        border: none;
        border-top: 1px solid var(--background-300);
        margin: var(--spacing-3) 0;
    }

    /* Sub and superscript */
    sub, sup {
        font-size: calc(var(--font-size-sm) * 0.8);
        line-height: 0;
        position: relative;
        vertical-align: baseline;
    }

    sup {
        top: -0.5em;
    }

    sub {
        bottom: -0.25em;
    }

    /* Spacing between elements */
    > * + * {
        margin-top: var(--spacing-2);
    }

    /* Override spacing for specific combinations */
    > p + ul,
    > p + ol,
    > ul + p,
    > ol + p {
        margin-top: var(--spacing-1);
    }

    > blockquote + *,
    > * + blockquote {
        margin-top: var(--spacing-3);
    }
}

.comments-section li:last-child {
    padding-bottom: var(--spacing-2);
}

.comments-list > ul[depth="0"] > li {
    padding-bottom: var(--spacing-3);

    &:before {
        background: none !important;
    }
    &:after {
        border: none !important;
    }
}
.comments-list ul.list > li:has(ul) > .comment {
    position: relative;

    &:before {
        content: "";
        position: absolute;
        inset-inline-start: 12px;
        top: calc(var(--size) + 8px);
        bottom: 18px;
        width: 2px;
        background: var(--text-400);
    }
}

.comments-list ul.list > li:not(:last-child) {
    position: relative;

    &:before {
        content: "";
        position: absolute;
        inset-inline-start: 12px;
        top: 0;
        bottom: 0;
        width: 2px;
        background: var(--text-400);
    }
}

.comments-list ul.list > li {
    position: relative;

    &:after {
        content: "";
        position: absolute;
        inset-inline-start: 12px;
        top: -25px;
        height: 45px;
        width: 30px;
        border-inline-start: 2px solid var(--text-400);
        border-bottom: 2px solid var(--text-400);
        background: transparent;
        border-end-start-radius: 20px;
    }
}

@container style(--nested: true) {
    .comment {
        position: relative;
        padding-top: var(--spacing-1);
    }

    li {
        padding-inline-start: var(--spacing-12);
    }
}

/* Vote buttons styling */
.vote-buttons {
    display: flex;
    align-items: center;
    gap: var(--spacing-1);
    margin-right: -0.5rem;
}

.vote-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    color: var(--text-500);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    position: relative;
}

.vote-btn:hover {
    background-color: var(--background-100);
}

.vote-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.vote-btn.active.vote-up {
    color: var(--accent-400);
}

.vote-btn.vote-up:hover {
    color: var(--accent-400);
}

.vote-btn.vote-down:hover {
    color: var(--primary-500);
}

.vote-btn.active.vote-up:hover {
    background-color: color-mix(in srgb, var(--accent-400) 10%, transparent);
}

.vote-btn.active.vote-down {
    color: var(--primary-500);
}

.vote-btn.active.vote-down:hover {
    color: var(--primary-500);
    background-color: color-mix(in srgb, var(--primary-500) 10%, transparent);
}

.vote-score {
    font-weight: 600;
    color: var(--text-500);
    text-align: center;
    font-size: var(--font-size-xs);
    line-height: var(--font-size-base);
    direction: ltr;
}

.comment-actions {
    display: flex;
    align-items: center;
    margin-top: var(--spacing-1);
}

/* Edit button styling */
.comment-actions .edit-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-1);
    padding: var(--spacing-1) var(--spacing-2);
    border-radius: 16px;
    color: var(--text-500);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    background: none;
    border: none;
    cursor: pointer;
}

.comment-actions .edit-btn:hover {
    background-color: var(--background-100);
    color: var(--primary-600);
    text-decoration: none;
}

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

/* Reply button styling */
.comment-actions .reply-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-1);
    padding: var(--spacing-1) var(--spacing-2);
    border-radius: 16px;
    color: var(--text-500);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    background: none;
    border: none;
    cursor: pointer;
}

.comment-actions .reply-btn:hover {
    background-color: var(--background-100);
    color: var(--text-500);
    text-decoration: none;
}

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

/* New Comment Form Styling - Reddit Style */
.new-comment-form {
    background: var(--background-50);
    border: 1px solid var(--background-200);
    border-radius: 8px;
    margin-bottom: var(--spacing-4);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.new-comment-form:focus-within {
    border-color: var(--accent-500);
    /*box-shadow: 0 0 0 1px var(--accent-500);*/
}

.new-comment-form .form-header {
    padding: var(--spacing-3) var(--spacing-3) 0;
}

.new-comment-form .user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
}

.new-comment-form .user-avatar {
    width: 24px;
    height: 24px;
    object-fit: cover;
}

.new-comment-form .user-avatar-placeholder {
    width: 24px;
    height: 24px;
    background: var(--background-300);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-700);
    font-size: 12px;
}

.new-comment-form .user-name {
    font-weight: 600;
    color: var(--text-900);
    font-size: var(--font-size-sm);
}

/* Textarea Container - Reddit Style */
.textarea-container {
    position: relative;
    background: var(--background-50);
    transition: all 0.2s ease;
}

.textarea-container:focus-within {
    /*transform: translateY(-1px);*/
}

.textarea-container textarea {
    width: 100%;
    min-height: 90px;
    padding: var(--spacing-3);
    padding-bottom: 48px; /* Space for buttons */
    border: none;
    outline: none;
    font-family: var(--font-family-primary);
    font-size: var(--font-size-base);
    line-height: 1.5;
    resize: vertical;
    background: transparent;
    color: var(--text-900);
    transition: all 0.2s ease;
}

.textarea-container textarea::placeholder {
    color: var(--text-400);
}

.textarea-container .add-comment-form-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-2) var(--spacing-3);
    background: var(--background-100);
    border-top: 1px solid var(--background-200);
}

.textarea-container .submit-btn {
    background: var(--accent-500);
    color: var(--background-50);
    border: none;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
}

.textarea-container .submit-btn:hover {
    background: var(--primary-500);
    transform: translateY(-1px);
}

.textarea-container .submit-btn:active {
    transform: translateY(0);
}

.textarea-container .submit-btn:disabled {
    background: var(--background-300);
    cursor: not-allowed;
    transform: none;
    opacity: 0.6;
}

.textarea-container .cancel-btn {
    background: transparent;
    color: var(--text-600);
    border: 1px solid var(--background-300);
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
}

.textarea-container .cancel-btn:hover {
    background: var(--background-100);
    border-color: var(--text-400);
}

.textarea-container .char-count {
    font-size: 12px;
    color: var(--text-500);
    font-weight: 500;
}

.textarea-container .char-count.warning {
    color: var(--accent-400);
}

.textarea-container .char-count.error {
    color: var(--accent-700);
}

/* Edit Form Styling - Same Reddit Style */
.edit-form {
    background: var(--background-50);
    border: 1px solid var(--primary-300);
    border-radius: 8px;
    margin-top: var(--spacing-2);
    margin-bottom: var(--spacing-2);
    overflow: hidden;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(-10px);
    animation: slideIn 0.3s ease forwards;
}

.edit-form:focus-within {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-500) 20%, transparent);
}

.edit-form .form-header {
    padding: var(--spacing-2) var(--spacing-3) 0;
    background: color-mix(in srgb, var(--primary-100) 50%, transparent);
}

.edit-form .user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
}

.edit-form .edit-label {
    font-size: 12px;
    color: var(--primary-700);
    font-weight: 600;
}

.edit-form .textarea-container {
    position: relative;
    background: var(--background-50);
    transition: all 0.2s ease;
}

.edit-form .textarea-container:focus-within {
    /*transform: translateY(-1px);*/
}

.edit-form .textarea-container textarea::placeholder {
    color: var(--text-400);
}

.edit-form .textarea-container .add-comment-form-actions {
    position: relative;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-2) var(--spacing-3);
    background: var(--background-100);
    border-top: 1px solid var(--background-200);
}

.edit-form .submit-btn {
    background: var(--primary-600);
    color: var(--background-50);
}

.edit-form .submit-btn:hover {
    background: var(--primary-700);
}

/* Reply Form Styling - Same Reddit Style */
.reply-form {
    background: var(--background-50);
    border: 1px solid var(--background-200);
    border-radius: 8px;
    margin-top: var(--spacing-2);
    margin-bottom: var(--spacing-2);
    overflow: hidden;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(-10px);
    animation: slideIn 0.3s ease forwards;
}

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

.reply-form:focus-within {
    border-color: var(--accent-500);
    /*box-shadow: 0 0 0 1px var(--accent-500);*/
}

.reply-form .form-header {
    padding: var(--spacing-2) var(--spacing-3) 0;
}

.reply-form .user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
}

.reply-form .reply-to {
    font-size: 12px;
    color: var(--text-600);
    font-weight: 500;
}

.reply-form .textarea-container {
    position: relative;
    background: var(--background-50);
    transition: all 0.2s ease;
}

.reply-form .textarea-container:focus-within {
    /*transform: translateY(-1px);*/
}

.reply-form .textarea-container textarea::placeholder {
    color: var(--text-400);
}

.reply-form .textarea-container .add-comment-form-actions {
    position: relative;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-2) var(--spacing-3);
    background: none;
    border-top: none;
}

/* Login Prompt Styling */
.login-prompt {
    background: var(--background-100);
    border: 1px solid var(--background-200);
    border-radius: 12px;
    padding: var(--spacing-4);
    margin-bottom: var(--spacing-4);
    text-align: center;
}

.login-prompt p {
    margin: 0;
    color: var(--text-600);
    font-size: var(--font-size-base);
}

.login-prompt a {
    color: var(--text-600);
    text-decoration: none;
    font-weight: 600;
}

.login-prompt a:hover {
    color: var(--text-700);
    text-decoration: underline;
}

/* Sort buttons styling */
.sort-buttons {
    display: flex;
    gap: var(--spacing-1);
    margin-bottom: var(--spacing-4);
    padding: var(--spacing-2);
    background: var(--background-100);
    border-radius: 8px;
    border: 1px solid var(--background-200);
}

.sort-btn {
    padding: var(--spacing-1) var(--spacing-3);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-600);
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    cursor: pointer;
}

.sort-btn:hover {
    background: var(--background-50);
    color: var(--text-900);
}

.sort-btn.active {
    background: var(--text-600);
    color: var(--background-50);
}

.sort-btn.active:hover {
    background: var(--text-700);
}

/* Quill Editor Styling */
.quill-editor {
    background: var(--background-50);
    border: none;
    border-radius: 8px;
    font-family: "Flow Circular", sans-serif;
    direction: rtl;
}

.quill-editor .ql-toolbar {
    border: none;
    padding: var(--spacing-2);
    direction: ltr;
}

.quill-editor .ql-toolbar .ql-formats {
    margin-right: 0;
    margin-left: var(--spacing-2);
}

.quill-editor .ql-toolbar .ql-formats:first-child {
    margin-left: 0;
}

.quill-editor .ql-container {
    border: none;
    font-family: "Flow Circular", sans-serif;
    font-size: var(--font-size-base);
    direction: rtl;
}

.quill-editor .ql-editor {
    padding: var(--spacing-3);
    min-height: 90px;
    color: var(--text-900);
    line-height: 1.5;
    border: none !important;
    resize: vertical !important;
    padding-bottom: 5em;
}

.quill-editor .ql-editor.ql-blank::before {
    color: var(--text-500);
    font-style: normal;
    right: var(--spacing-3);
    left: auto;
}

.quill-editor .ql-toolbar button {
    color: var(--text-600);
    border-radius: 4px;
    padding: var(--spacing-1);
}

.quill-editor .ql-toolbar button:hover {
    color: var(--text-900);
    background: var(--background-100);
}

.quill-editor .ql-toolbar button.ql-active {
    color: var(--text-900);
    background: var(--background-200);
}

.quill-editor .ql-stroke {
    stroke: currentColor;
}

.quill-editor .ql-fill {
    fill: currentColor;
}

.quill-editor .ql-container.ql-snow {
    border: none !important;
}

.quill-editor .ql-toolbar.ql-snow {
    border: none !important;
}

.quill-editor * {
    border: none !important;
}

/* Focus state for Quill editor */
.quill-editor:focus-within {
    border: none;
    box-shadow: none;
}
.quill-editor {
    border: none !important;
}
.textarea-container .ql-toolbar.ql-snow {
    border: none;
    border-bottom: 1px solid var(--background-200);
    display: none;
}
.show-toolbar .textarea-container .ql-toolbar.ql-snow {
    display: block;
}
.textarea-container .ql-editor .ql-direction-rtl {
    direction: rtl;
    text-align: right;
}
.textarea-container .ql-toolbar.ql-snow .ql-formats {
    margin-right: 0;
    margin-left: 15px;
}

/* Toolbar toggle button */
.add-comment-toolbar-toggle-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-600);
    margin-left: auto;
}

.add-comment-toolbar-toggle-btn:hover {
    background-color: var(--background-100);
    color: var(--text-800);
}

.add-comment-toolbar-toggle-btn.active {
    background-color: var(--text-500);
    color: var(--background-50);
}

.add-comment-toolbar-toggle-icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.add-comment-form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}