:root {
  color-scheme: dark;
  --ape-bg: #101415;
  --ape-panel: #1d2a2e;
  --ape-panel-soft: #172225;
  --ape-field: #26383e;
  --ape-ink: #f6f3ea;
  --ape-muted: #b8c3c5;
  --ape-line: #526a72;
  --ape-accent: #ff8a2b;
  --ape-link: #ffe45e;
  --ape-info: #8ddcff;
}

.ape-page {
  background: var(--ape-bg);
  color: var(--ape-ink);
  font: 16px/1.5 Consolas, "Courier New", monospace;
  margin: 0;
  padding: clamp(22px, 5vw, 40px);
}

.ape-login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.ape-registration-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.ape-admin-page {
  padding: 24px;
}

.ape-page *,
.ape-page *::before,
.ape-page *::after {
  box-sizing: border-box;
}

.ape-page a {
  color: var(--ape-link);
}

.ape-page .is-hidden {
  display: none !important;
}

.ape-page h1,
.ape-page h2,
.ape-page h3 {
  color: var(--ape-accent);
  line-height: 1.15;
  margin: 0 0 16px;
}

.ape-page p {
  margin: 0 0 14px;
}

.ape-card,
.box {
  background: var(--ape-panel);
  border: 1px solid var(--ape-line);
  max-width: 820px;
  padding: 18px;
}

.ape-message,
.msg {
  color: var(--ape-link);
}

.ape-message-error {
  color: #ff9a8a;
}

.ape-admin-shell > .ape-message {
  background: var(--ape-panel);
  border: 1px solid var(--ape-line);
  margin: 14px 0 0;
  padding: 10px 12px;
}

.ape-page .muted {
  color: var(--ape-muted);
}

.ape-page label {
  display: block;
  margin: 14px 0;
}

.ape-page input,
.ape-page button,
.ape-page textarea,
.ape-page select {
  background: var(--ape-field);
  border: 1px solid var(--ape-line);
  color: var(--ape-ink);
  font: inherit;
  padding: 8px;
}

.ape-page input {
  max-width: 100%;
}

.ape-page input[type="checkbox"] {
  height: 18px;
  margin: 0;
  width: 18px;
}

.ape-page button,
.ape-button {
  cursor: pointer;
}

.ape-page button:hover,
.ape-button:hover {
  border-color: var(--ape-accent);
}

.ape-page button,
.ape-mini-button {
  min-height: 36px;
  text-decoration: none;
}

.ape-button-primary {
  background: var(--ape-accent) !important;
  border-color: var(--ape-accent) !important;
  color: #17100b !important;
  font-weight: 700;
}

.ape-page textarea {
  min-height: 150px;
  width: 100%;
}

.ape-page table {
  border-collapse: collapse;
  margin-top: 18px;
  width: 100%;
}

.ape-page td,
.ape-page th {
  border: 1px solid var(--ape-line);
  padding: 7px;
  text-align: left;
  vertical-align: top;
}

.ape-page th:last-child,
.ape-page td:last-child {
  min-width: 220px;
}

.ape-page code {
  background: #080d0f;
  border: 1px solid var(--ape-line);
  color: #fff;
  padding: 1px 5px;
}

.ape-login-shell {
  width: min(440px, 100%);
}

.ape-registration-shell {
  width: min(680px, 100%);
}

.ape-login-card {
  background: var(--ape-panel);
  border: 1px solid var(--ape-line);
  box-shadow: 0 20px 60px rgba(0,0,0,.38);
  padding: 24px;
}

.ape-login-card input,
.ape-login-card button {
  width: 100%;
}

.ape-registration-card {
  box-shadow: 0 20px 60px rgba(0,0,0,.32);
  max-width: none;
  padding: clamp(18px, 4vw, 28px);
}

.ape-registration-card input,
.ape-registration-card button {
  width: 100%;
}

.ape-registration-card form {
  margin-top: 18px;
}

.ape-registration-price {
  border: 1px solid var(--ape-line);
  background: var(--ape-panel-soft);
  padding: 10px 12px;
}

.ape-registration-legal {
  border-top: 1px solid var(--ape-line);
  margin-top: 16px;
  padding-top: 14px;
}

.ape-card-content ul,
.ape-card-content ol {
  margin: 10px 0 14px 24px;
  padding: 0;
}

.ape-card-content li {
  margin: 6px 0;
}

.ape-card-content blockquote {
  border-left: 3px solid var(--ape-accent);
  color: var(--ape-muted);
  margin: 16px 0;
  padding: 4px 0 4px 14px;
}

.ape-card-content pre {
  background: #080d0f;
  border: 1px solid var(--ape-line);
  overflow-x: auto;
  padding: 12px;
}

.ape-card-content pre code {
  border: 0;
  padding: 0;
}

.ape-card-content hr {
  border: 0;
  border-top: 1px solid var(--ape-line);
  margin: 22px 0;
}

.ape-login-mark {
  align-items: center;
  background: var(--ape-accent);
  color: #17100b;
  display: inline-flex;
  font-weight: 700;
  height: 42px;
  justify-content: center;
  margin-bottom: 18px;
  width: 54px;
}

.ape-admin-shell {
  margin: 0 auto;
  max-width: 1240px;
}

.ape-admin-header {
  align-items: center;
  background: var(--ape-panel);
  border: 1px solid var(--ape-line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 18px;
}

.ape-admin-header h1,
.ape-admin-header p {
  margin-bottom: 4px;
}

.ape-admin-kicker {
  color: var(--ape-info);
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.ape-tabs {
  background: var(--ape-panel-soft);
  border: 1px solid var(--ape-line);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 18px 0;
  padding: 6px;
}

.ape-tabs a {
  border: 1px solid transparent;
  color: var(--ape-ink);
  padding: 9px 12px;
  text-decoration: none;
}

.ape-tabs a.active {
  background: var(--ape-accent);
  border-color: var(--ape-accent);
  color: #17100b;
  font-weight: 700;
}

.ape-status-tabs,
.ape-document-tabs,
.ape-update-tabs,
.ape-home-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.ape-status-tabs a,
.ape-document-tabs a,
.ape-update-tabs button,
.ape-home-tabs button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--ape-line);
  color: var(--ape-ink);
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  font: inherit;
  min-height: 34px;
  padding: 6px 8px;
  text-decoration: none;
}

.ape-status-tabs a.active,
.ape-document-tabs a.active,
.ape-update-tabs button.active,
.ape-home-tabs button.active {
  border-color: var(--ape-accent);
  color: var(--ape-link);
}

.ape-status-tabs span {
  color: var(--ape-muted);
}

.ape-panel-card {
  background: var(--ape-panel);
  border: 1px solid var(--ape-line);
  padding: 18px;
}

.ape-section-head {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.ape-section-head h2 {
  margin-bottom: 6px;
}

.ape-count,
.ape-status,
.ape-mini-button {
  border: 1px solid var(--ape-line);
  display: inline-flex;
  padding: 6px 8px;
}

.ape-status {
  background: #152329;
  color: var(--ape-info);
  font-weight: 700;
}

.ape-status-pending {
  background: #263039;
  border-color: #728292;
  color: #dce8f2;
}

.ape-status-payment_started {
  background: #2d2a18;
  border-color: #d6b84a;
  color: #ffe58a;
}

.ape-status-payment_failed {
  background: #341d20;
  border-color: #b65a61;
  color: #ffc3c8;
}

.ape-status-paid {
  background: #173028;
  border-color: #58bd91;
  color: #9af0c6;
}

.ape-status-licensed {
  background: #172d35;
  border-color: #6bc4d8;
  color: #a9ecfa;
}

.ape-status-invalidated {
  background: #2d2529;
  border-color: #9d6b7a;
  color: #f0c4d0;
}

.ape-status-trashed {
  background: #1f1f22;
  border-color: #74747d;
  color: #cfcfd8;
}

.ape-mini-button {
  align-items: center;
  color: var(--ape-ink) !important;
}

.ape-mini-button:hover {
  border-color: var(--ape-accent);
  text-decoration: none;
}

.ape-table-wrap {
  overflow-x: auto;
}

.ape-actions-inline {
  align-items: center;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  white-space: nowrap;
}

.ape-actions-inline form {
  margin: 0;
}

.ape-bulk-actions {
  align-items: end;
  background: var(--ape-panel-soft);
  border: 1px solid var(--ape-line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 280px) minmax(260px, 1fr) auto;
  margin: 0 0 14px;
  padding: 12px;
}

.ape-bulk-actions label {
  margin: 0;
}

.ape-bulk-actions input,
.ape-bulk-actions select {
  width: 100%;
}

.ape-check-cell {
  min-width: 42px !important;
  text-align: center !important;
  width: 42px;
}

.ape-checkbox-label {
  align-items: center;
  display: flex !important;
  gap: 8px;
}

.ape-danger-button {
  border-color: #a94b43 !important;
  color: #ffd0cc !important;
}

.ape-danger-button:hover {
  border-color: #ff6a5e !important;
}

.ape-doc-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.ape-doc-editor {
  border: 1px solid var(--ape-line);
  background: var(--ape-panel-soft);
  padding: 16px;
}

.ape-doc-editor input {
  width: 100%;
}

.ape-form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.ape-doc-editor input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
}

.ape-update-editor textarea {
  min-height: 160px;
}

.ape-update-panel {
  display: grid;
  gap: 14px;
}

.ape-update-package-box {
  background: rgba(14, 20, 22, .46);
  border: 1px solid rgba(82, 106, 114, .72);
  padding: 12px;
}

.ape-update-package-box h3 {
  margin-top: 0;
}

.ape-page button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.ape-home-editor {
  display: grid;
  gap: 14px;
}

.ape-home-editor fieldset {
  background:
    linear-gradient(90deg, rgba(255,138,43,.10), transparent 46%),
    var(--ape-panel-soft);
  border: 1px solid var(--ape-line);
  margin: 0;
  padding: 14px;
}

.ape-home-editor legend {
  color: var(--ape-link);
  padding: 0 8px;
}

.ape-home-editor input,
.ape-home-editor textarea,
.ape-home-editor select {
  width: 100%;
}

.ape-home-editor textarea {
  min-height: 110px;
}

.ape-home-panel {
  display: grid;
  gap: 14px;
}

.ape-media-settings {
  border-top: 1px solid var(--ape-line);
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
}

.ape-media-settings h3 {
  color: var(--ape-info);
  font-size: 16px;
  margin: 0;
}

.ape-record-editor {
  background: rgba(14, 20, 22, .34);
  border: 1px solid rgba(82, 106, 114, .72);
  display: grid;
  gap: 12px;
  margin: 14px 0;
  padding: 12px;
}

.ape-record-editor-head {
  align-items: start;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.ape-record-editor-head h3 {
  color: var(--ape-info);
  font-size: 16px;
  margin: 0 0 4px;
}

.ape-record-list {
  display: grid;
  gap: 12px;
}

.ape-record-row {
  background: rgba(29, 42, 46, .72);
  border: 1px solid rgba(82, 106, 114, .72);
  padding: 12px;
}

.ape-record-summary {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.ape-drag-handle {
  cursor: grab;
  font-size: 17px;
  min-height: 32px;
}

.ape-drag-handle:active {
  cursor: grabbing;
}

.ape-icon-button {
  align-items: center;
  display: inline-flex;
  flex: 0 0 auto;
  height: 34px;
  justify-content: center;
  min-height: 34px !important;
  padding: 0 !important;
  width: 34px;
}

.ape-record-row.is-dragging,
.ape-block-row.is-dragging {
  opacity: .55;
}

.ape-record-row.is-drop-before,
.ape-block-row.is-drop-before {
  box-shadow: inset 0 4px 0 var(--ape-accent);
}

.ape-record-row.is-drop-after,
.ape-block-row.is-drop-after {
  box-shadow: inset 0 -4px 0 var(--ape-accent);
}

.ape-record-summary strong {
  color: var(--ape-link);
  flex: 1 1 auto;
  overflow-wrap: anywhere;
}

.ape-record-body {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 12px;
}

.ape-record-row.is-collapsed .ape-record-body {
  display: none;
}

.ape-record-row label {
  margin: 0 0 10px;
}

.ape-record-row textarea {
  min-height: 92px;
}

.ape-record-actions {
  align-content: start;
  display: grid;
  gap: 8px;
}

.ape-record-media-pick {
  align-self: end;
  display: flex;
  margin-bottom: 10px;
}

.ape-media-library-panel {
  background:
    linear-gradient(90deg, rgba(141, 220, 255, .10), transparent 48%),
    var(--ape-panel-soft);
  border: 1px solid var(--ape-line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
  display: grid;
  gap: 14px;
  max-height: min(86vh, 880px);
  max-width: 1180px;
  overflow: auto;
  padding: 14px;
  position: relative;
  width: min(1180px, calc(100vw - 32px));
  z-index: 2;
}

.ape-dialog-panel {
  background:
    linear-gradient(90deg, rgba(255, 138, 43, .12), transparent 48%),
    var(--ape-panel);
  border: 1px solid var(--ape-line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
  max-height: min(84vh, 780px);
  max-width: 860px;
  overflow: auto;
  padding: clamp(16px, 3vw, 24px);
  position: relative;
  width: min(860px, calc(100vw - 32px));
  z-index: 2;
}

.ape-dialog-content {
  color: var(--ape-ink);
}

.ape-dialog-content ul,
.ape-dialog-content ol {
  margin: 10px 0 14px 24px;
  padding: 0;
}

.ape-modal {
  align-items: center;
  display: grid;
  inset: 0;
  justify-items: center;
  padding: 16px;
  position: fixed;
  z-index: 50;
}

.ape-modal-backdrop {
  background: rgba(4, 7, 8, .78);
  inset: 0;
  position: absolute;
}

.ape-modal-open {
  overflow: hidden;
}

.ape-media-upload-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 1fr) auto;
}

.ape-media-library-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  margin-top: 12px;
}

.ape-media-tile {
  background: rgba(14, 20, 22, .56);
  border: 1px solid rgba(82, 106, 114, .75);
  display: grid;
  gap: 8px;
  padding: 10px;
}

.ape-media-tile label {
  margin: 0;
}

.ape-media-tile input {
  width: 100%;
}

.ape-media-tile img {
  background: #080d0f;
  border: 1px solid var(--ape-line);
  display: block;
  height: 120px;
  object-fit: contain;
  padding: 6px;
  width: 100%;
}

.ape-media-tile img.ape-media-selectable {
  cursor: pointer;
}

.ape-media-tile img.ape-media-selectable:hover {
  border-color: var(--ape-accent);
}

.ape-media-tile code {
  overflow-wrap: anywhere;
}

.ape-block-matrix {
  display: grid;
  gap: 8px;
}

.ape-block-row {
  align-items: center;
  background: rgba(14, 20, 22, .48);
  border: 1px solid rgba(82, 106, 114, .75);
  display: grid;
  gap: 10px;
  grid-template-columns: auto minmax(180px, 1fr) 120px minmax(90px, auto);
  padding: 10px;
}

.ape-block-row label {
  margin: 0;
}

.ape-block-row input[type="number"] {
  margin-top: 4px;
  width: 100%;
}

.ape-doc-editor textarea {
  min-height: 360px;
}

.ape-markdown-help code {
  display: inline-block;
  margin: 2px 0;
}

.ape-doc-editor-wide textarea {
  min-height: 520px;
}

.ape-settings-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

@media (max-width: 720px) {
  .ape-page {
    font-size: 15px;
    padding: 16px;
  }

  .ape-login-page {
    padding: 16px;
  }

  .ape-admin-header,
  .ape-section-head {
    display: block;
  }

  .ape-page table,
  .ape-page tbody,
  .ape-page tr,
  .ape-page td,
  .ape-page th {
    display: block;
  }

  .ape-page th:last-child,
  .ape-page td:last-child {
    min-width: 0;
  }

  .ape-block-row {
    grid-template-columns: 1fr;
  }

  .ape-record-editor-head,
  .ape-record-row,
  .ape-record-body {
    display: block;
  }

  .ape-record-actions {
    display: flex;
    flex-wrap: wrap;
  }

  .ape-media-upload-form {
    grid-template-columns: 1fr;
  }

  .ape-actions-inline {
    overflow-x: auto;
  }

  .ape-bulk-actions {
    grid-template-columns: 1fr;
  }
}
