:root {
  color-scheme: light dark;
  --bg: #0b1220;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #22c55e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

/* До загрузки app.js: не мигать экраном входа, если токен уже в хранилище */
html.gfxTokenPresent #authScreen {
  display: none !important;
}

html.gfxTokenPresent #appShell.hidden {
  display: flex !important;
  flex-direction: column;
  min-height: 100vh;
}

.srOnly {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.authScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.authCard {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.colorPicker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.colorSwatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.colorSwatch input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  /* Глобальное правило `input { background: #0f172a }` и нативная отрисовка radio
     иначе дают «чёрные кружки» поверх .swatch — убираем фон и системный вид. */
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 0;
  width: 0;
  height: 0;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none;
}

.colorSwatch .swatch {
  position: relative;
  z-index: 1;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  /* Цвет задаётся классами scheduleSwatch* — inline style на label запрещён CSP (style-src 'self'). */
  background-color: #334155;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35) inset;
  forced-color-adjust: none;
}

.colorSwatch.scheduleSwatchDark .swatch {
  background-color: #0f172a;
}
.colorSwatch.scheduleSwatchBlue .swatch {
  background-color: #2563eb;
}
.colorSwatch.scheduleSwatchGreen .swatch {
  background-color: #16a34a;
}
.colorSwatch.scheduleSwatchYellow .swatch {
  background-color: #eab308;
}
.colorSwatch.scheduleSwatchRed .swatch {
  background-color: #dc2626;
}
.colorSwatch.scheduleSwatchBeige .swatch {
  background-color: #dede8d;
}

.colorSwatch input:checked + .swatch {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
  border-color: rgba(255, 255, 255, 0.65);
}

#appShell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.appShellBody {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#mainTabNav {
  flex-shrink: 0;
}

#appMain {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}

.authRow {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.topRightMenu {
  position: relative;
}

.menuDots {
  width: 40px;
  font-size: 20px;
  line-height: 1;
  padding: 4px 0;
}

.menuPanel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 230px;
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}

.menuUser {
  color: var(--muted);
  font-size: 12px;
  padding: 4px 2px 8px;
}

.modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, 92vw);
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 51;
}

.modalHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modalBody {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modalFooter {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.iconBtn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.secondaryBtn {
  background: #0b1220;
  border-color: #2a3446;
}

.userPickRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.userPickRow label {
  flex: 1;
}
nav {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}

main {
  padding: 0 16px 24px;
}

.articleDetailHeaderRow {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.articleDetailContent {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.articleDetailFooter {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  padding-top: 8px;
  border-top: 1px solid #1f2937;
  margin-top: auto;
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

button,
input,
textarea {
  border: 1px solid #374151;
  background: #0f172a;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
}

/* Текст статьи при создании и редактировании */
#createArticleModal #articleBodyInput,
#articleDetailView #editArticleBodyInput {
  min-height: min(520px, 55vh);
  resize: vertical;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  line-height: 1.45;
}

button {
  cursor: pointer;
}

button.active {
  border-color: var(--accent);
}

.chatForm,
.formCol {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

#chat.tab.active {
  display: flex;
  flex-direction: column;
  min-height: 68vh;
}

.chatTopBar,
.knowledgeTopBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 10px;
}

.knowledgeTitle {
  margin: 0;
  flex: 1;
}

.knowledgeTopActions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.knowledgeMenuHost {
  position: relative;
}

.articleDetailView {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 16px 24px;
  background: var(--bg);
  overflow-y: auto;
}

.articleDetailToolbar {
  margin: 6px 0 4px;
}

.articleDetailHeading {
  margin: 0;
  flex: 1;
  font-size: 1.25rem;
  line-height: 1.3;
}

.articleDetailBody {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  padding: 4px 0 8px;
  min-height: 2rem;
}

.articleStandaloneWrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 32px;
}

.articleStandaloneHeader {
  margin-bottom: 16px;
}

.articleStandaloneTitle {
  margin: 0 0 8px;
  font-size: 1.35rem;
  line-height: 1.35;
}

.chatTitle {
  margin: 0;
  flex: 1;
  text-align: center;
}

.chatItem {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.chatItemTitle {
  font-weight: 700;
}

.chatItemMeta {
  color: var(--muted);
  font-size: 12px;
}

.fileAttachment {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fileLink {
  color: var(--accent);
  text-decoration: none;
  word-break: break-word;
}

.chatMessages {
  flex: 1;
  overflow-y: auto;
  min-height: 320px;
  max-height: 68vh;
  margin-bottom: 12px;
}

.chatRoomToolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0 10px;
}

.chatRoomSearchRow {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
}

.chatRoomSearchRow #chatSearchInput {
  width: 100%;
}

.pinnedBar {
  background: rgba(17, 24, 39, 0.75);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 8px;
}

.pinnedHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.pinnedTitle {
  margin: 0;
}

.pinnedList {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 140px;
  overflow: auto;
}

.pinnedItem {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid #243049;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.pinnedItem:hover {
  border-color: rgba(34, 197, 94, 0.55);
}

.pinnedItemText {
  font-size: 13px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.pinnedItemMeta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.pinnedItemActions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pinnedItemActions button {
  padding: 6px 10px;
  border-radius: 999px;
}

.messageText mark {
  background: rgba(234, 179, 8, 0.28);
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

.linkPreview {
  margin-top: 8px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #243049;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.linkPreviewTitle {
  font-weight: 700;
  font-size: 13px;
}

.linkPreviewUrl {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.linkPreviewActions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.chatComposer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
}

.pendingAttachments {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pendingAttachmentRow {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid #243049;
  background: rgba(15, 23, 42, 0.55);
}

.pendingThumb {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.pendingMeta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pendingName {
  font-size: 13px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.pendingInfo {
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.mediaGalleryModal {
  width: min(920px, 96vw);
}

.mediaGalleryGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 900px) {
  .mediaGalleryGrid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.mediaGalleryItem {
  position: relative;
  border-radius: 12px;
  border: 1px solid #243049;
  background: rgba(15, 23, 42, 0.55);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
}

.mediaGalleryItem img,
.mediaGalleryItem video {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}

.mediaGalleryBadge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
}

.mediaGalleryTabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.mediaGalleryTab {
  border: 1px solid #374151;
  background: #0f172a;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}

.mediaGalleryTab.isActive {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18);
}

.mediaGalleryGridWrap {
  min-height: 120px;
}

.mediaGalleryLinksList {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mediaGalleryLinkRow {
  cursor: pointer;
  text-align: left;
}

.mediaGalleryLinkRow .linkPreviewActions a {
  pointer-events: auto;
}

.mediaGalleryFileItem {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  min-height: 110px;
  padding: 12px;
  text-align: left;
}

.mediaGalleryFileName {
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
  word-break: break-word;
  width: 100%;
}

.mediaGalleryFileMeta {
  font-size: 12px;
  color: var(--muted);
}
.chatInputWrap {
  position: relative;
  flex: 1;
}

.chatInputWrap #messageInput {
  width: 100%;
  padding-right: 42px;
}

.chatInputWrap #attachFileBtn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}

.iconActionBtn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.iconActionBtn svg {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
}

.sendBtn {
  border-color: var(--accent);
  color: var(--accent);
}

.formRow {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.scheduleFilterGroup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scheduleFilterBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  border: 1px solid #374151;
  background: #0f172a;
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  margin: 0;
}

.scheduleFilterBtn input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.scheduleFilterBtn:hover {
  border-color: #64748b;
}

/* Selected state (modern browsers) */
.scheduleFilterBtn:has(input[type="radio"]:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18);
}

/* Fallback if :has() is not supported */
.scheduleFilterBtn.isSelected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 10px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.messageHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chatMessages .messageHeader {
  min-width: 0;
  flex-wrap: wrap;
  align-items: flex-start;
}

.chatMessages .messageHeader span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chatMessages .messageText {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chatMessages .fileAttachment,
.chatMessages .fileAttachment * {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chatMessages .messageCard {
  max-width: min(760px, 86%);
  min-width: 0;
}

.chatMessages .messageOwn {
  align-self: flex-end;
  margin-right: 6px;
  background: rgba(34, 197, 94, 0.10);
  border-color: rgba(34, 197, 94, 0.35);
}

.chatMessages .messageOther {
  align-self: flex-start;
  margin-left: 6px;
  background: rgba(37, 99, 235, 0.10);
  border-color: rgba(37, 99, 235, 0.35);
}

.chatMessages .messageOwn .meta,
.chatMessages .messageOther .meta {
  margin-bottom: 6px;
}

.messageJumpFlash {
  outline: 2px solid rgba(234, 179, 8, 0.75);
  box-shadow: 0 0 0 4px rgba(234, 179, 8, 0.18);
}

.dangerBtn {
  border-color: #7f1d1d;
}

.messageActions {
  position: relative;
}

.iconDotsBtn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 6px;
}

.iconDotsBtn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.messageMenu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 140px;
  background: var(--card);
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}

#currentUser {
  color: var(--muted);
  font-size: 12px;
}

.media {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-top: 8px;
}

.uploadQueue {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 60;
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid #1f2937;
  border-radius: 12px;
  padding: 10px;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(40vh, 320px);
  overflow: auto;
}

.uploadQueueHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.uploadQueueTitle {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.uploadItem {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid #243049;
  border-radius: 10px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.uploadItemName {
  font-size: 13px;
  font-weight: 700;
  word-break: break-word;
}

.uploadItemMeta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.uploadItemRight {
  display: flex;
  align-items: center;
  gap: 8px;
}

.uploadPct {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  min-width: 44px;
  text-align: right;
}

.progressBar {
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
  margin-top: 6px;
}

.progressBarFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  transition: width 120ms linear;
}

.uploadStatusOk .progressBarFill {
  background: linear-gradient(90deg, #22c55e, #22c55e);
}

.uploadStatusErr .progressBarFill {
  background: linear-gradient(90deg, #ef4444, #dc2626);
}

.uploadClearBtn {
  padding: 6px 10px;
  border-radius: 999px;
}

pre {
  white-space: pre-wrap;
  margin: 8px 0 0;
}

@media (max-width: 900px) {
  .formRow {
    grid-template-columns: 1fr;
  }
}
