.viewerDialog {
  width: min(1100px, calc(100% - 18px));
  height: min(92vh, 900px);
  max-width: none;
  max-height: none;
  background: #172829;
  overflow: hidden;
}
.viewerHead {
  height: 74px;
  padding: 13px 20px;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.viewerHead h2 { font-family: Georgia, serif; font-size: 22px; font-weight: 500; margin: 3px 0; }
.viewerStage {
  position: relative;
  height: calc(100% - 74px);
  overflow: auto;
  background: #344748;
  user-select: none;
  -webkit-user-select: none;
}
.viewerStage iframe { display: block; width: 100%; height: 100%; border: 0; background: white; }
.imageGallery { min-height: 100%; }
.imageGallery img { display: block; max-width: 100%; height: auto; margin: 0 auto 8px; pointer-events: none; }
.watermark {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 150px;
  align-items: center;
  justify-items: center;
  overflow: hidden;
  pointer-events: none;
}
.watermark span {
  color: rgba(12, 65, 63, .23);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .5px;
  white-space: nowrap;
  transform: rotate(-28deg);
  text-shadow: 0 0 1px rgba(255, 255, 255, .35);
}
@media (max-width: 600px) {
  .watermark { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 120px; }
  .watermark span { font-size: 11px; }
  .viewerDialog { height: 94vh; }
}
.headerActions { display: flex; gap: 10px; align-items: center; }
.secondary { border: 1px solid var(--teal); background: var(--paper); color: var(--teal); padding: 12px 16px; border-radius: 8px; font-weight: 750; cursor: pointer; }
.ownerPanel { padding: 26px; }
.ownerIntro { color: var(--muted); margin-top: -8px; }
.ownerChats { display: grid; gap: 10px; margin-top: 20px; max-height: 58vh; overflow: auto; }
.addGroupForm { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 0 10px; align-items: end; padding: 14px; margin-top: 18px; border: 1px solid var(--line); border-radius: 8px; background: #f4f1e8; }
.addGroupForm label { margin: 0; }
.addGroupForm .primary { align-self: end; }
.addGroupForm .error { grid-column: 1/-1; margin: 7px 0 0; }
.ownerChat { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px 16px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.ownerChat strong,.ownerChat small { display: block; }
.ownerChat small { color: var(--muted); margin-top: 4px; }
.status { align-self: start; border-radius: 20px; padding: 4px 8px; font-size: 11px; font-weight: 800; }
.status.approved { color: #17613c; background: #daf1e3; }
.status.pending { color: #835b0b; background: #fff0c7; }
.ownerActions { grid-column: 1/-1; display: flex; gap: 8px; }
.ownerActions button { border: 1px solid var(--line); background: var(--paper); color: var(--teal); padding: 8px 11px; border-radius: 6px; font-weight: 700; cursor: pointer; }
.editLibraryForm { grid-column: 1/-1; display: grid; grid-template-columns: 1fr 1fr auto; gap: 7px; align-items: end; padding-top: 10px; margin-top: 2px; border-top: 1px solid var(--line); }
.editLibraryForm > strong,.editLibraryForm .error { grid-column: 1/-1; }
.editLibraryForm label { gap: 3px; margin: 0; font-size: 10px; }
.editLibraryForm input { min-width: 0; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 6px; padding: 8px 10px; }
.editLibraryForm button { border: 1px solid var(--line); background: var(--paper); color: var(--teal); border-radius: 6px; padding: 8px 10px; font-weight: 700; }
.editLibraryForm .error { margin: 0; }
.emptyOwner { color: var(--muted); text-align: center; padding: 24px; }
@media (max-width: 600px) { .headerActions { width: 100%; } .headerActions button { flex: 1; } .addGroupForm,.editLibraryForm { grid-template-columns: 1fr; gap: 8px; } .addGroupForm .error,.editLibraryForm .error,.editLibraryForm > strong { grid-column: 1; } }

.editImageButton { width: 100%; padding: 8px 10px; font-size: 12px; }
.imageToEdit { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 8px; background: var(--paper); color: var(--ink); font-size: 12px; }
.editedFileStatus { min-height: 14px; color: var(--muted); font-weight: 600; }
.editedImagePreview { display: block; width: 100%; height: 96px; min-height: 0; max-height: 96px; object-fit: contain; object-position: center; border: 1px solid var(--line); border-radius: 7px; background: #20272c; }
.imageEditorDialog { width: min(900px, calc(100% - 10px)); max-width: none; height: calc(100vh - 12px); height: calc(var(--tg-viewport-stable-height, 100dvh) - 12px); max-height: 900px; padding: 10px; overflow: hidden; }
.imageEditorDialog[open] { display: grid; grid-template-rows: auto auto auto auto minmax(120px, 1fr) auto auto; }
.imageEditorHead { display: flex; align-items: start; justify-content: space-between; }
.imageEditorHead h2 { margin: 2px 0 0; font-family: Georgia, serif; font-size: 24px; font-weight: 500; }
.imageEditorHelp { margin: 3px 0 4px; color: var(--muted); font-size: 11px; }
.imageEditorStatus { margin: 0 0 5px; color: var(--teal); font-size: 11px; font-weight: 800; }
.imageEditorError { margin: 4px 0 0; min-height: 16px; }
.imageEditorError:empty { display: none; }
.editorViewTools { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; margin-bottom: 7px; }
.editorModeSwitch,.editorZoomControls { display: flex; min-width: 0; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.editorModeSwitch button { flex: 1; }
.editorZoomControls button { flex: 1; }
.editorViewTools button { min-height: 34px; border: 0; border-radius: 6px; padding: 5px 9px; background: transparent; color: var(--ink); font-size: 12px; font-weight: 800; }
.editorViewTools .editorTool.active { border-color: var(--teal); background: var(--teal); color: var(--button-text); }
.editorViewTools strong { display: grid; min-width: 44px; place-items: center; color: var(--muted); font-size: 11px; }
.editorCanvasWrap { display: block; min-height: 0; height: auto; overflow: auto; background: #1b2328; border-radius: 7px; overscroll-behavior: contain; }
.imageEditorDialog canvas { display: block; width: 100%; height: auto; margin: auto; background: white; }
.editorCanvasWrap.moveMode,.editorCanvasWrap.moveMode canvas { touch-action: none; cursor: grab; }
.editorCanvasWrap.blurMode,.editorCanvasWrap.blurMode canvas { touch-action: none; cursor: crosshair; }
.imageEditorTools { display: grid; grid-template-columns: auto auto minmax(140px, 1fr); align-items: stretch; gap: 6px; margin-top: 7px; }
.imageEditorTools label { gap: 2px; margin: 0; font-size: 10px; }
.imageEditorTools select,.imageEditorTools button { min-height: 38px; }
.imageEditorTools select { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 7px; background: var(--paper); color: var(--ink); }
@media (max-width: 560px) {
  .imageEditorDialog { padding: 8px; }
  .imageEditorHead h2 { font-size: 21px; }
  .editorViewTools { grid-template-columns: minmax(0,.9fr) minmax(0,1.1fr); gap: 5px; }
  .editorViewTools button { padding: 4px 6px; }
  .imageEditorTools button { min-width: 0; padding-left: 7px; padding-right: 7px; font-size: 12px; }
}
@media (max-width: 340px) { .editorViewTools { grid-template-columns: 1fr; } }
