#comments-popup {
  display: none;
  position: absolute;
  right: 2em;
  /* top: 10em; */
  z-index: 1000;
  width: 420px;
  min-width: 200px;
  min-height: 200px;
  transition: all 0.2s;
}

#comments-popup .resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -5px;
  z-index: 1001;
}

#comments-popup .resize-handle-left {
  left: -5px;
  cursor: nwse-resize;
}

#comments-popup .resize-handle-right {
  right: -5px;
  cursor: nesw-resize;
}

#comments-list {
  margin-top: 0.5em;
    overflow-y: auto;
    height: 380px;
    /* align to vertical bottom */
    display: flex;
    flex-direction: column-reverse;
}

#new-comment-form {
    margin-top: auto;
}

#new-comment-form textarea {
  width: 94%;
  resize: vertical;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  padding: 0.5em;
  font-size: 16px; /* Prevent iOS zoom on focus */
}

#new-comment-form button[type="submit"] {
  margin-top: 0.5em;
  float: right;
}

#new-comment-form #cancel-edit-btn {
  margin-top: 0.5em;
  float: right;
  margin-right: 0.5em;
}

.comment-item {
    border-top: 1px solid var(--color-border);
    padding: 0.5em 1.8em 1.5em 0;
    position: relative;
}

.comment-item.selected-for-move {
    background-color: var(--color-section-bg);
    border-color: var(--color-border);
}

.comment-select {
    position: absolute;
    top: 0.4em;
    right: 0.2em;
}

.comment-select-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.comment-item.last-read {
    border-bottom: 2px solid var(--color-border);
}

.comment-content {
    margin-top:0.2em;
}

.comment-action-block {
    margin-top: 0.6em;
}

.comment-action-summary {
    cursor: pointer;
    font-weight: 600;
}

.comment-action-json {
    background: var(--color-section-bg);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin-top: 0.4em;
    padding: 0.5em;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 220px;
    overflow: auto;
    font-family: var(--font-family-monospace, 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace);
    font-size: 0.9em;
}

.comment-action-edit-form {
    margin-top: 0.6em;
}

.comment-action-edit-textarea {
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.5em;
    font-family: var(--font-family-monospace, 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace);
    font-size: 0.9em;
    min-height: 160px;
    resize: vertical;
}

.comment-action-edit-buttons {
    margin-top: 0.4em;
    display: flex;
    justify-content: flex-end;
    gap: 0.5em;
}

.edit-comment-action-btn {
    margin-top: 0.6em;
}

.comment-status-label {
    margin-left: 0.4em;
    font-size: 0.85em;
    color: var(--color-muted);
}

.comment-action-container {
    position: absolute;
    bottom: 0.2em;
    right: 0.2em;
    display: flex;
    gap: 0.2em;
}

#move-comments-btn,
#search-comments-btn,
#cancel-edit-btn,
#new-comment-form button[type="submit"] {
    margin-top: 0.5em;
}

#move-comments-btn,
#search-comments-btn,
#cancel-edit-btn {
    float: right;
    margin-right: 0.5em;
}

#new-comment-form button[type="submit"] {
    float: right;
}

#move-comments-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.delete-comment-btn,
.edit-comment-btn,
.copy-comment-link-btn {
    border: none;
    background: none;
    font-weight: bold;
    cursor: pointer;
}

.comment-owner-only {
    display: none;
}

.comment-copy-notice {
    position: absolute;
    right: 0.2em;
    bottom: 2.4em;
    background: var(--color-section-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.2em 0.6em;
    font-size: 0.75em;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.comment-copy-notice.visible {
    opacity: 1;
    transform: translateY(0);
}

.send-icon {
    width: 28px;
    height: 28px;
    color: var(--color-text);
}

@media (max-width: 600px) {
    #comments-popup {
        position: fixed;
        right: 0;
        left: 0;
        top: auto;
        bottom: env(keyboard-inset-height, 0);
        width: auto;
        min-width: 0;
        max-width: none;
        padding: 0.5em;
        border-radius: 10px 10px 0 0;
        transform: translateY(100%);
        transition: transform 0.3s;
    }

    #comments-popup.open {
        transform: translateY(0);
    }
}

.comment-item.highlight-flash {
    animation: comment-flash 2s ease-out;
}

@keyframes comment-flash {
    from { background: #ffff99; }
    to { background: transparent; }
}

#comment-participants {
  margin-bottom: 0.3em;
}

#typing-indicator {
  font-style: italic;
  margin: 0.3em 0;
  min-height: 24px;
  display: flex;
  align-items: center;
}

#typing-indicator .avatar-wrapper {
  width: 20px;
  height: 20px;
  margin-right: 0.2em;
}

.comment-presence-avatar {
  margin-right: 0.2em;
}

.comment-presence-avatar.inactive {
  opacity: 0.4;
  filter: grayscale(1);
}
.comment-presence-avatar.inactive + .avatar-initial {
  opacity: 0.4;
  filter: grayscale(1);
}
