:root {
  color-scheme: light;
  --admin-bg: #fff;
  --admin-surface: #fff;
  --admin-border: #d9dde5;
  --admin-muted: #f6f7f9;
  --admin-text: #222;
  --admin-primary: #1f6feb;
  --admin-primary-hover: #174ea6;
  --admin-secondary: #636b74;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  margin: 0;
  background: var(--admin-bg);
  color: var(--admin-text);
  overflow-x: hidden;
}

h2 {
  text-align: center;
  color: inherit;
  margin: 0;
}

.form-container {
  max-width: 1120px;
  margin: 0 auto;
  background: var(--admin-surface);
  padding: 18px;
  box-sizing: border-box;
}

.field-block {
  margin-bottom: 22px;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  overflow: hidden;
}

.field-label {
  font-weight: bold;
  padding: 10px 12px;
  background: var(--admin-muted);
  border-bottom: 1px solid var(--admin-border);
}

.field-wrapper {
  position: relative;
  overflow: visible;
  background: #fff;
}

.sticky-buttons {
  position: sticky;
  top: 0;
  background: #fff;
  padding: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  border-bottom: 1px solid var(--admin-border);
  z-index: 10;
}

textarea,
input[type="number"],
input[type="text"],
input[type="url"] {
  min-height: auto;
  max-height: none;
  width: 100%;
  box-sizing: border-box;
  border: 0;
  outline: none;
  padding: 12px;
  color: var(--admin-text);
  background: #fff;
  font: 16px/1.55 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
}

textarea {
  display: block;
  resize: vertical;
}

.editor-number-input {
  height: 3.6em;
}

.prose-editor {
  min-height: 70vh;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.65;
}

button.save-btn {
  background-color: var(--admin-primary);
  color: white;
  border: none;
  padding: 9px 14px;
  font-size: .95rem;
  border-radius: 6px;
  cursor: pointer;
  box-sizing: border-box;
  max-width: 100%;
  white-space: nowrap;
}

button.save-btn:hover {
  background-color: var(--admin-primary-hover);
}

.ai-format-btn {
  background-color: #6f42c1 !important;
}

.new-topic-actions .ai-format-btn {
  margin-right: 8px;
}

a.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  line-height: 1;
  padding: 9px 12px;
  background-color: var(--admin-secondary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  max-width: 100%;
  white-space: nowrap;
}

a.button-link:hover {
  background-color: #666;
}

.save-status {
  color: green;
  font-size: .9rem;
  margin-top: 5px;
  display: none;
}

.topic-list {
  columns: 2;
  gap: 20px;
}

.topic-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #ececec;
  color: #333;
  text-decoration: none;
  break-inside: avoid;
  min-width: 0;
  overflow-wrap: anywhere;
}

.topic-link:hover {
  background: #dedede;
}

.topic-left {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  color: inherit;
  flex: 1 1 auto;
  flex-wrap: wrap;
  min-width: 0;
}

.topic-id {
  opacity: .7;
}

.topic-title {
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}

.topic-section {
  flex: 0 1 auto;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3949ab;
  border: 1px solid #cfd8ff;
  white-space: nowrap;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.stub {
  opacity: .9;
  background: #f8f8f8;
  border: 1px dashed #d2d2d2;
}

.stub .topic-title {
  font-weight: 500;
  font-style: italic;
  opacity: .8;
}

.section-header-link {
  background: #fffaf1;
  border-style: solid;
  border-color: #e5d19a;
}

.section-header-link .topic-title {
  color: #8c6a1b;
  font-style: normal;
  font-weight: 700;
  opacity: 1;
}

.row-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.row-nav .button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.collapsible-panel {
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  margin-bottom: 18px;
  background: var(--admin-muted);
  overflow: hidden;
}

.collapsible-panel > summary {
  cursor: pointer;
  font-weight: 700;
  padding: 12px 14px;
  background: var(--admin-muted);
  border-bottom: 1px solid transparent;
}

.collapsible-panel[open] > summary {
  border-bottom-color: var(--admin-border);
}

.collapsible-body,
.new-card {
  padding: 14px;
}

.prose-panel .field-block {
  margin-bottom: 0;
}

.danger-panel {
  border-color: #f0b4b4;
}

.danger-panel > summary {
  color: #9f1d1d;
  background: #fff5f5;
}

.danger-copy {
  margin: 0 0 10px;
  color: #7f1d1d;
}

button.danger-btn {
  background-color: #b42318;
}

button.danger-btn:hover {
  background-color: #8f1c13;
}

.new-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.new-grid-full {
  grid-column: 1 / -1;
}

.new-topic-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 10px;
}

#new-prose {
  min-height: 180px;
  border: 1px solid var(--admin-border);
  border-radius: 6px;
}

.error-text {
  color: #b00020;
  font-size: .9rem;
  display: none;
  margin-top: 6px;
}

.ok-text {
  color: green;
  font-size: .9rem;
  display: none;
  margin-top: 6px;
}

body.no-scroll {
  overflow: hidden;
}

.field-wrapper.expanded {
  position: fixed !important;
  inset: 10px;
  z-index: 9999;
  max-height: none;
  overflow: hidden;
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  background: #fff;
}

.field-wrapper.expanded .sticky-buttons {
  position: sticky;
  top: 0;
  z-index: 2;
}

.field-wrapper.expanded .prose-editor {
  height: calc(100% - 52px);
  min-height: 0 !important;
  resize: none;
  overflow: auto;
}

.editor-done-btn {
  display: none;
}

.field-wrapper.expanded .editor-expand-btn {
  display: none;
}

.field-wrapper.expanded .editor-done-btn {
  display: inline-flex;
}

.field-wrapper,
.prose-editor {
  scrollbar-gutter: stable both-edges;
}

@media (max-width: 700px) {
  body {
    padding: 0;
  }

  h2 {
    text-align: left;
    font-size: 1.15rem;
  }

  .form-container {
    width: 100%;
    padding: 10px;
  }

  .row-nav {
    align-items: stretch;
  }

  .row-nav,
  .row-nav .button-row,
  .new-topic-actions {
    flex-direction: column;
  }

  .row-nav .button-row a {
    width: fit-content;
    max-width: 100%;
  }

  .new-topic-actions button {
    width: 100%;
  }

  .new-grid {
    grid-template-columns: 1fr;
  }

  .field-block {
    margin-bottom: 14px;
  }

  .field-label {
    padding: 8px 10px;
  }

  .sticky-buttons {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sticky-buttons button,
  .sticky-buttons a {
    width: 100%;
    min-width: 0;
    padding-left: 8px;
    padding-right: 8px;
  }

  .sticky-buttons .ai-format-btn {
    grid-column: 1 / -1;
  }

  .prose-editor {
    min-height: 72svh;
    padding: 12px 10px 28px;
  }

  .field-wrapper.expanded {
    inset: 0;
    border-radius: 0;
  }

  .topic-list {
    columns: 1;
  }

  .topic-link {
    align-items: flex-start;
    flex-direction: column;
  }

  .topic-section {
    white-space: normal;
  }
}
