* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f6f7fb; color: #111827; }
.container { width: min(960px, 92%); margin: 0 auto; }
.centered { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.card { background: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.08); padding: 24px; width: min(460px, 100%); }
h1, h2, h3 { margin-top: 0; }
.btn { display: inline-block; padding: 10px 16px; border: 0; border-radius: 8px; cursor: pointer; background: #1d4ed8; color: #fff; text-decoration: none; }
.btn.secondary { background: #334155; }
.btn.tiny { padding: 6px 10px; font-size: 12px; margin-right: 6px; }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 6px; font-size: 14px; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #d1d5db; border-radius: 8px; padding: 10px; font-family: inherit; }
.field textarea { min-height: 90px; }
.error { color: #b91c1c; font-size: 14px; min-height: 18px; }
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: #0f172a; color: #fff; padding: 24px 16px; }
.sidebar h3 { margin: 0 0 16px; }
.menu-item { display: block; color: #cbd5e1; text-decoration: none; padding: 8px 10px; border-radius: 6px; margin-bottom: 6px; }
.menu-item:hover, .menu-item.active { background: #1e293b; color: #fff; }
.main { display: flex; flex-direction: column; }
.topbar { height: 62px; background: #fff; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; }
.content { padding: 20px; }
.muted { color: #64748b; }

.page-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.search-input { max-width: 280px; width: 100%; border-radius: 8px; border: 1px solid #d1d5db; padding: 10px; }
.flash { margin-bottom: 16px; padding: 10px 12px; border-radius: 8px; }
.flash.success { background: #dcfce7; color: #166534; }
.flash.error { background: #fee2e2; color: #991b1b; }
.flash.hidden { display: none; }
.panel-card { background: #fff; border-radius: 12px; border: 1px solid #e2e8f0; padding: 16px; margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px; border-bottom: 1px solid #e2e8f0; vertical-align: middle; }
.status-pill { padding: 4px 8px; border-radius: 999px; font-size: 12px; text-transform: uppercase; background: #e2e8f0; }
.status-pill.active { background: #dcfce7; color: #166534; }
.status-pill.inactive { background: #fee2e2; color: #991b1b; }
.org-header { display: grid; grid-template-columns: 120px 1fr auto; gap: 16px; align-items: center; }
.org-logo-wrap { width: 120px; height: 120px; }
.org-logo { width: 120px; height: 120px; object-fit: contain; border-radius: 10px; border: 1px solid #cbd5e1; background: #fff; }
.org-logo.placeholder { display: flex; align-items: center; justify-content: center; font-size: 12px; color: #64748b; border: 1px dashed #cbd5e1; border-radius: 10px; width: 120px; height: 120px; }
.actions-right { justify-self: end; }
.grid-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid h2, .field-full, .actions-row { grid-column: 1 / -1; }
.actions-row { display: flex; gap: 8px; }
.checkbox-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px; }
.checkbox-item { display: flex; gap: 8px; align-items: center; font-size: 14px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .grid-two, .form-grid, .org-header { grid-template-columns: 1fr; }
  .checkbox-list { grid-template-columns: 1fr; }
}

.hidden { display: none !important; }
.scope-pill { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; background: #dbeafe; color: #1e3a8a; }
.scope-pill.scope-system { background: #fee2e2; color: #991b1b; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.permission-group { border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.permission-group h4 { margin: 0 0 8px; }
.permission-group-system { border-color: #fecaca; background: #fff7f7; }
.panel-note { border: 1px dashed #94a3b8; border-radius: 8px; padding: 8px 10px; color: #334155; background: #f8fafc; }
.impersonation-banner { background: #fef3c7; border-bottom: 1px solid #f59e0b; padding: 10px 20px; color: #78350f; }
.impersonation-banner-content { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.status-pill.draft { background: #e2e8f0; color: #0f172a; }
.status-pill.published { background: #dcfce7; color: #166534; }
.status-pill.archived { background: #f1f5f9; color: #475569; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid.compact { gap: 10px; }
.checkbox-inline { display: flex; align-items: center; }
code { background: #f1f5f9; border: 1px solid #e2e8f0; padding: 2px 6px; border-radius: 6px; }
.op-tree { display: flex; flex-direction: column; gap: 12px; }
.op-division { border: 1px solid #334155; border-radius: 10px; padding: 12px; background: #0f172a; color: #e2e8f0; }
.op-age-group, .op-level, .op-group { border: 1px solid #334155; border-radius: 8px; padding: 10px; margin-top: 10px; background: #1e293b; }
.op-level { background: #1a2437; }
.op-group { background: #152033; }
.op-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.op-title { margin: 0; font-size: 15px; font-weight: 700; }
.op-subtitle { font-size: 13px; color: #cbd5e1; margin: 4px 0 0; }
.op-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.op-form-inline { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.op-form-inline input, .op-form-inline select { min-width: 180px; }
.op-apparatus-list { margin: 8px 0 0; padding-left: 18px; }
.op-apparatus-item { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 6px; }

.doc-editor-shell { display: flex; flex-direction: column; gap: 10px; }
.doc-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.doc-editor-tabs { display: flex; gap: 8px; }
.doc-editor-tab-help { margin: 0; }
.doc-editor-pane {
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
}
.doc-editor-surface {
  padding: 12px;
  background: #fff;
  border-radius: 0 0 10px 10px;
}
.doc-editor {
  min-height: 340px;
  font-family: "Times New Roman", Times, serif;
  color: #0f172a;
  line-height: 1.5;
}
.doc-editor:focus-within { outline: none; }
.doc-editor-fallback {
  min-height: 340px;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
.doc-editor .ProseMirror {
  min-height: 316px;
  outline: none;
}
.doc-editor .ProseMirror p { margin: 0 0 12px; }
.doc-editor .ProseMirror h2 {
  margin: 16px 0 10px;
  font-size: 24px;
  line-height: 1.25;
}
.doc-editor .ProseMirror h3 {
  margin: 14px 0 8px;
  font-size: 18px;
  line-height: 1.3;
}
.doc-editor .ProseMirror ul,
.doc-editor .ProseMirror ol {
  padding-left: 24px;
  margin: 0 0 12px;
}
.doc-editor .ProseMirror blockquote {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-left: 3px solid #334155;
  color: #334155;
  background: #f8fafc;
}

.doc-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid #d1d5db;
  background: #f8fafc;
  border-radius: 10px 10px 0 0;
}
.doc-toolbar-group {
  display: flex;
  gap: 6px;
  align-items: center;
  padding-right: 8px;
  border-right: 1px solid #e2e8f0;
}
.doc-toolbar-group:last-child {
  border-right: 0;
  padding-right: 0;
}
.doc-toolbar-button {
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: #0f172a;
  font-size: 12px;
  padding: 6px 8px;
  cursor: pointer;
  min-width: 34px;
}
.doc-toolbar-button:hover { background: #f1f5f9; }
.doc-toolbar-button.is-active {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e3a8a;
}
.doc-toolbar-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.doc-html-textarea {
  min-height: 340px;
  border: 0;
  border-radius: 10px;
  width: 100%;
  box-sizing: border-box;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  background: #fff;
}

.competition-document-template { font-family: "Times New Roman", Times, serif; color: #111827; }
.doc-institutional {
  font-size: 14px;
  line-height: 1.55;
}
.doc-card-shell {
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px 16px 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}
.doc-header-block { margin: 4px 0 26px; }
.doc-header-brand-line {
  height: 6px;
  background: linear-gradient(90deg, #0f172a, #1d4ed8);
  border-radius: 3px;
  margin-bottom: 14px;
}
.doc-header-main {
  display: grid;
  grid-template-columns: minmax(130px, 210px) 1fr;
  align-items: center;
  column-gap: 18px;
}
.doc-header-logo { display: flex; justify-content: center; margin: 2px 0; min-height: 96px; }
.doc-header-logo-image { max-width: 220px; max-height: 120px; object-fit: contain; }
.doc-header-logo-placeholder {
  border: 1px dashed #94a3b8;
  color: #64748b;
  border-radius: 8px;
  min-width: 180px;
  min-height: 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 13px;
}
.doc-header-titles { text-align: center; }
.doc-header-organization {
  margin: 0 0 8px;
  font-size: 15px;
  letter-spacing: 1.4px;
  font-weight: 700;
  color: #0f172a;
}
.doc-header-title {
  margin: 0;
  font-size: 24px;
  text-transform: uppercase;
  line-height: 1.2;
  color: #020617;
}
.doc-header-subtitle {
  margin: 8px 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: #475569;
}
.doc-header-divider {
  margin: 0 auto;
  width: 100%;
  border-bottom: 1px solid #0f172a;
}
.doc-body-block p { margin: 0 0 12px; }
.doc-section {
  margin: 0 0 24px;
  page-break-inside: avoid;
}
.doc-section-title {
  margin: 0 0 10px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 2px solid #1e293b;
  padding-bottom: 7px;
}
.doc-section-content p {
  margin: 0 0 10px;
}

.topbar-user {
  position: relative;
}
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
}
.user-menu-trigger:hover {
  background: #f8fafc;
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #1e293b;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}
.user-trigger-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}
.user-menu-card {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  min-width: 260px;
  padding: 14px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.16);
  z-index: 1000;
}
.user-menu-info {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid #e2e8f0;
}
.user-menu-name {
  margin: 0 0 4px;
  font-weight: 700;
}
.user-menu-sub {
  margin: 0;
  color: #64748b;
  font-size: 13px;
}
.user-menu-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.btn.danger {
  background: #b91c1c;
}
.btn.danger:hover {
  background: #991b1b;
}

.account-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
}
.account-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.account-modal-card {
  position: relative;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  width: min(480px, 92vw);
  padding: 16px;
  box-shadow: 0 22px 42px rgba(15, 23, 42, 0.25);
}
.account-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.icon-button {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: #475569;
  font-size: 18px;
}
.feedback-message {
  min-height: 20px;
  margin: 0;
  font-size: 14px;
}
.feedback-message.error { color: #b91c1c; }
.feedback-message.success { color: #166534; }

@media (max-width: 900px) {
  .topbar {
    height: auto;
    min-height: 62px;
    padding: 10px 16px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .user-menu-card {
    right: -6px;
    min-width: min(280px, calc(100vw - 32px));
  }
}
.doc-section-content p:last-child {
  margin-bottom: 0;
}
.doc-opening-eyebrow {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.7px;
  color: #1e293b;
}
.doc-opening-intro {
  margin: 0 0 10px;
  font-size: 14px;
}
.doc-opening-summary {
  margin: 0;
  font-size: 13px;
  color: #334155;
}
.doc-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.doc-info-item {
  border: 1px solid #94a3b8;
  border-left: 4px solid #1d4ed8;
  border-radius: 8px;
  padding: 8px 10px 9px;
  background: #f8fafc;
}
.doc-info-label {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: #334155;
}
.doc-info-value {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}
.doc-bullet-list {
  margin: 0;
  padding-left: 18px;
}
.doc-bullet-list li {
  margin: 0 0 6px;
}
.doc-highlight-grid {
  display: grid;
  gap: 10px;
}
.doc-highlight-card {
  border: 1px solid #bfdbfe;
  border-left: 4px solid #1d4ed8;
  border-radius: 10px;
  background: #f8fbff;
  padding: 10px 12px;
}
.doc-highlight-card-title {
  margin: 0 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #1e3a8a;
}
.doc-highlight-card .doc-bullet-list {
  margin-top: 6px;
}
.doc-footer-block {
  margin-top: 26px;
  border-top: 1px solid #0f172a;
  padding-top: 16px;
  text-align: center;
}
.doc-footer-block p {
  margin: 0 0 6px;
}

.competition-document-export-sheet {
  position: fixed;
  top: 0;
  left: 0;
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  color: #111827;
  padding: 16mm 14mm;
  box-sizing: border-box;
  z-index: -1;
  pointer-events: none;
}

.competition-document-print-root {
  width: 100%;
  min-height: calc(297mm - 32mm);
}

@media (max-width: 800px) {
  .doc-header-main {
    grid-template-columns: 1fr;
    row-gap: 8px;
  }
}

.user-avatar.avatar-image {
  object-fit: cover;
  padding: 0;
  background: #e2e8f0;
}

.user-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.table-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd5e1;
  background: #e2e8f0;
  font-size: 11px;
  font-weight: 700;
  color: #334155;
}

.avatar-field {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
}

.avatar-preview-box {
  width: 112px;
  height: 112px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-preview-placeholder {
  font-size: 12px;
  color: #64748b;
}

.avatar-field-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.actions-row.compact {
  justify-content: flex-start;
}

.avatar-editor-card {
  width: min(860px, 96vw);
}

.avatar-editor-body {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 16px;
  margin-bottom: 12px;
}

.avatar-editor-canvas-wrap {
  width: 320px;
  height: 320px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  background: #0f172a;
}

.avatar-editor-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.avatar-editor-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.avatar-editor-controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: #334155;
}

@media (max-width: 900px) {
  .avatar-field {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .avatar-field-actions {
    width: 100%;
  }

  .avatar-editor-body {
    grid-template-columns: 1fr;
  }

  .avatar-editor-canvas-wrap {
    width: min(320px, 100%);
    height: auto;
    aspect-ratio: 1 / 1;
  }
}
