/* Comment thread used outside Bitacora (incident modal, etc.).
   Bitacora keeps its own copy in style_bitacora.css. */
#modal .comments-head .k {
  font-size: 11px;
  letter-spacing: .02em;
  color: var(--text-dim, var(--muted, #6b7280));
  font-weight: 800;
}

#modal .comments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

#modal .comment-item {
  display: grid;
  gap: 4px;
  max-width: 92%;
  justify-items: start;
  position: relative;
  overflow: visible;
}

#modal .comment-item.me {
  margin-left: auto;
  justify-items: end;
}

#modal .comment-item.has-files {
  max-width: 100%;
  width: 100%;
}

#modal .comment-item.is-pending {
  opacity: .72;
}

#modal .comment-bubble {
  position: relative;
  z-index: 1;
  overflow: visible;
  border-radius: 12px;
  padding: 8px 44px 8px 10px;
  min-height: 40px;
  background: #1d4ed8;
  color: #fff;
  display: inline-block;
  max-width: 86%;
  word-break: break-word;
}

#modal .comment-item.has-files .comment-bubble {
  width: 100%;
  max-width: 360px;
  box-sizing: border-box;
}

#modal .comment-item.me .comment-bubble {
  background: #15803d;
}

#modal .comment-meta {
  font-size: 11px;
  color: var(--text-dim, #9ca3af);
  display: flex;
  gap: 6px;
  align-items: baseline;
}

#modal .comment-item.me .comment-receipt {
  font-size: 10px;
  line-height: 1.35;
  color: var(--text-dim, #9ca3af);
  margin-top: 2px;
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-end;
}

#modal .comment-receipt-line {
  display: block;
}

#modal .comment-del {
  position: absolute;
  top: 6px;
  right: 6px;
  border: none;
  background: rgba(0, 0, 0, .16);
  cursor: pointer;
  opacity: .85;
  font-size: 12px;
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  border-radius: 8px;
  color: inherit;
}

#modal .comment-del.icon-btn {
  min-width: 24px;
  min-height: 24px;
}

#modal .comment-del:hover {
  background: rgba(0, 0, 0, .24);
  opacity: 1;
}

#modal .comment-item:not(.me) .comment-del {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  #modal .comment-del {
    display: none;
  }
}

#modal .comment-gallery {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  max-width: 100%;
  overflow-x: auto;
  padding: 2px 2px 6px;
  scrollbar-gutter: stable;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

#modal .comment-gallery .cg-item {
  display: block;
  width: 96px;
  height: 96px;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--ui-line, #e5e7eb);
  background: color-mix(in srgb, var(--ui-panel-2, #f8fafc) 92%, #000);
  position: relative;
  scroll-snap-align: start;
  flex: 0 0 auto;
}

#modal .comment-gallery .cg-item:hover {
  border-color: color-mix(in srgb, var(--ui-line, #cbd5e1) 70%, var(--ui-text, #fff) 30%);
  background: color-mix(in srgb, var(--ui-panel, #fff) 88%, var(--ui-text, #000) 12%);
}

#modal .comment-gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#modal .comment-gallery .cg-file {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 96px;
  height: 96px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .08);
  color: #e5e7eb;
  text-decoration: none;
  text-align: center;
  padding: 6px;
  gap: 4px;
  scroll-snap-align: start;
  flex: 0 0 auto;
}

#modal .comment-gallery .cg-file:hover {
  border-color: rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .12);
}

#modal .comment-gallery .cg-file-ic {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  letter-spacing: .04em;
}

#modal .comment-gallery .cg-file-name {
  font-size: 11px;
  max-width: 84px;
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-weight: 600;
  text-align: center;
}

#modal .comment-gallery .cg-file-meta {
  font-size: 10px;
  opacity: .8;
}

#modal .comment-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  width: 100%;
}

#modal .comment-file {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-areas:
    "ic name"
    "ic meta";
  column-gap: 8px;
  row-gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .08);
  color: #e5e7eb;
  text-decoration: none;
  max-width: 100%;
  width: 100%;
}

#modal .comment-file:hover {
  border-color: rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .12);
}

#modal .comment-file-ic {
  grid-area: ic;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 10px;
  font-weight: 800;
  border-radius: 6px;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  letter-spacing: .04em;
}

#modal .comment-file-name {
  grid-area: name;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-weight: 600;
}

#modal .comment-file-meta {
  grid-area: meta;
  font-size: 11px;
  opacity: .75;
}

#modal .cg-more {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}

#modal .comment-gallery--video {
  margin-top: 8px;
}

#modal .comment-gallery .cg-video {
  width: 100%;
  max-width: min(100%, 320px);
  min-height: 0;
  height: auto;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ui-panel-2, #111) 90%, #000);
}

#modal .comment-gallery .cg-video video {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: #000;
}

.cg-video-thumb {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #000;
  color: #fff;
  cursor: pointer;
}

.cg-video-thumb video {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  pointer-events: none;
}

.cg-video-play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  transform: translate(-50%, -50%);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.cg-video-play svg {
  width: 22px;
  height: 22px;
  margin-left: 3px;
}

.cg-video-thumb:hover .cg-video-play {
  background: rgba(0, 0, 0, 0.75);
  border-color: rgba(255, 255, 255, 0.6);
}

.cg-video-thumb:focus-visible {
  outline: 2px solid var(--acc, #fbbf24);
  outline-offset: 2px;
}

#modal .attach-previews .cg-video-thumb,
#modal .attach-previews .cg-video-thumb video {
  height: 100%;
  max-height: none;
  object-fit: cover;
}

#modal .attach-previews .cg-video-play {
  width: 32px;
  height: 32px;
}

#modal .attach-previews .cg-video-play svg {
  width: 16px;
  height: 16px;
  margin-left: 2px;
}

#modal .attach-previews {
  margin: 8px 0 10px;
}

#modal .attach-previews .cg-item {
  position: relative;
}

#modal .attach-previews .cg-item .hkmod-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(0, 0, 0, .24);
  border: 1px solid rgba(255, 255, 255, .35);
  color: #fff;
  cursor: pointer;
  z-index: 2;
}

#modal .attach-previews .cg-item .hkmod-del::before,
#modal .attach-previews .cg-item .hkmod-del::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 1.5px;
  background: currentColor;
  border-radius: 2px;
  transform-origin: center;
}

#modal .attach-previews .cg-item .hkmod-del::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

#modal .attach-previews .cg-item .hkmod-del::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

@media (max-width: 720px) {
  #modal .comment-gallery .cg-item,
  #modal .comment-gallery .cg-file {
    width: 88px;
    height: 88px;
  }
}

@media (max-width: 560px) {
  #modal .comment-gallery .cg-item,
  #modal .comment-gallery .cg-file {
    width: 80px;
    height: 80px;
  }

  #modal .comment-item.has-files .comment-bubble {
    width: 88%;
    max-width: 88%;
  }

  #modal .comment-bubble {
    padding: 8px 38px 8px 10px;
  }
}

@media (max-width: 420px) {
  #modal .comment-gallery .cg-item,
  #modal .comment-gallery .cg-file {
    width: 72px;
    height: 72px;
  }

  #modal .comment-item {
    max-width: 100%;
  }
}

:root[data-theme="light"] #modal .comment-bubble {
  background: #2563eb;
}

:root[data-theme="light"] #modal .comment-item.me .comment-bubble {
  background: #16a34a;
}

:root[data-theme="light"] #modal .comment-gallery .cg-item {
  background: #f8fafc;
  border-color: #d7dee8;
}

:root[data-theme="light"] #modal .comment-gallery .cg-file,
:root[data-theme="light"] #modal .comment-file {
  border-color: #d7dee8;
  background: #f7f9fc;
  color: #1f2937;
}

:root[data-theme="light"] #modal .comment-gallery .cg-file-ic,
:root[data-theme="light"] #modal .comment-file-ic {
  background: #e2e8f0;
  color: #0f172a;
}

/* Video recorder overlay (opened from incident comments on mobile) */
body.comment-vrec-open {
  overflow: hidden;
}

.comment-vrec-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147483660;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.55);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.comment-vrec-dialog {
  width: min(100%, 440px);
  max-height: min(92dvh, 720px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 14px 16px;
  margin: auto;
  border-radius: 16px;
  border: 1px solid var(--ui-line, var(--line, #2a384c));
  background: var(--ui-panel, var(--panel, #141b25));
  box-sizing: border-box;
}

.comment-vrec-stage-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-width: 0;
  flex: 0 1 auto;
  min-height: 0;
}

.comment-vrec-stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  width: min(100%, 340px);
  max-width: 100%;
  margin-inline: auto;
  aspect-ratio: 9 / 16;
  max-height: min(62dvh, 520px);
  height: auto;
  flex-shrink: 0;
}

.comment-vrec-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  display: block;
  background: #000;
}

.comment-vrec-timer {
  position: absolute;
  left: 10px;
  bottom: 10px;
  margin: 0;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}

.comment-vrec-limit,
.comment-vrec-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-dim, var(--ui-muted, #a1aec2));
  text-align: center;
  width: 100%;
}

.comment-vrec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  flex-shrink: 0;
}

.comment-vrec-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.comment-vrec-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--ui-line, var(--line, #2a384c));
  background: transparent;
  color: var(--ui-text, var(--text, inherit));
  cursor: pointer;
  flex-shrink: 0;
}

.comment-vrec-close::before {
  content: "x";
  font-size: 22px;
  line-height: 1;
}

.comment-vrec-stage.is-recording {
  outline: 3px solid color-mix(in srgb, #ef4444 85%, transparent);
  outline-offset: -3px;
}

.comment-vrec-stage.is-loading .comment-vrec-preview {
  opacity: 0.35;
}

.comment-vrec-loading {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  margin: 0;
  padding: 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2;
}

.comment-vrec-loading.is-visible {
  display: grid;
}

.comment-vrec-rec-dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
}

.comment-vrec-record.is-stop {
  background: color-mix(in srgb, #ef4444 88%, #000) !important;
  border-color: color-mix(in srgb, #ef4444 70%, var(--ui-line, #333)) !important;
  color: #fff !important;
}

.comment-vrec-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  flex-shrink: 0;
}

.comment-vrec-actions .comment-vrec-cancel {
  justify-self: start;
}

.comment-vrec-actions .comment-vrec-record,
.comment-vrec-actions .comment-vrec-use {
  justify-self: center;
  min-width: min(100%, 160px);
}

@media (max-width: 720px) {
  .comment-vrec-dialog {
    width: min(100%, calc(100vw - 20px));
    padding: 12px 14px max(14px, env(safe-area-inset-bottom));
  }

  .comment-vrec-stage {
    width: min(100%, min(72vw, 340px));
    max-height: min(58dvh, 480px);
  }
}

@media (max-width: 420px) {
  .comment-vrec-dialog {
    width: min(100%, calc(100vw - 16px));
    padding: 12px;
    border-radius: 14px;
  }

  .comment-vrec-stage {
    width: 100%;
    max-height: min(52dvh, 420px);
  }

  .comment-vrec-actions {
    grid-template-columns: 1fr 1fr;
  }

  .comment-vrec-actions .comment-vrec-cancel {
    grid-column: 1 / -1;
    justify-self: stretch;
  }

  .comment-vrec-actions .comment-vrec-record,
  .comment-vrec-actions .comment-vrec-use {
    justify-self: stretch;
    width: 100%;
  }
}

/* @mentions */
#modal .comment-mention,
.comment-mention {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.18);
  font-weight: 600;
  font-size: 0.95em;
  line-height: 1.35;
  vertical-align: baseline;
}

#modal .comment-item.me .comment-mention {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.2);
}

:root[data-theme="light"] #modal .comment-mention {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.12);
}

.comments-compose .comment-mention-panel,
.comment-mention-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 220px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--border-soft, #d7dee8);
  border-radius: 8px;
  background: var(--surface, #fff);
  color: var(--text, #0f172a);
}

.comments-compose .comment-mention-panel[hidden],
.comment-mention-panel[hidden] {
  display: none !important;
}

.comment-mention-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  white-space: normal;
}

.comment-mention-option:hover,
.comment-mention-option.is-active {
  background: var(--surface-2, #f1f5f9);
  border-color: var(--border-soft, #d7dee8);
}

.comment-mention-user {
  font-weight: 600;
  font-size: 13px;
}

.comment-mention-name {
  font-size: 11px;
  opacity: 0.75;
}

.comment-mention-empty {
  padding: 8px 10px;
  font-size: 12px;
  opacity: 0.75;
}

:root[data-theme="dark"] .comments-compose .comment-mention-panel {
  background: var(--surface, #1e293b);
  border-color: var(--border-soft, #334155);
  color: var(--text, #e2e8f0);
}

:root[data-theme="dark"] .comment-mention-option:hover,
:root[data-theme="dark"] .comment-mention-option.is-active {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-soft, #475569);
}
