:root {
  --page-bg: #f6f7f9;
  --panel-bg: #ffffff;
  --text: #1f2933;
  --muted: #64748b;
  --line: #dde3ea;
  --accent: #1677ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  min-width: 220px;
  cursor: pointer;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.content {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.content.narrow {
  width: min(1080px, 100%);
}

.main-nav,
.viewer-actions,
.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.page-head,
.form-head {
  margin-bottom: 18px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.page-head h1,
.form-head h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
}

.page-head p,
.form-head p,
.admin-login p {
  margin: 6px 0 0;
  color: var(--muted);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) repeat(4, minmax(150px, 220px));
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 460px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.list {
  min-height: 520px;
  overflow: hidden;
}

.list-item {
  cursor: pointer;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  transition: background 0.15s ease;
}

.list-item:hover,
.list-item.active {
  background: #eef6ff;
}

.doc-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.doc-row:last-child {
  border-bottom: 0;
}

.doc-row:hover {
  background: #f8fbff;
}

.item-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.item-meta,
.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.doc-meta-below {
  margin-top: 18px;
}

.item-summary {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.viewer {
  min-height: 520px;
  padding: 28px;
}

.viewer h1 {
  margin: 0;
  font-size: 38px;
  font-weight: 700;
  line-height: 1.2;
}

.document-html {
  margin-top: 24px;
  line-height: 1.65;
}

.document-html img {
  max-width: 100%;
  height: auto;
}

.attachments {
  margin-top: 22px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.attachments h3 {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.3;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.attachment-list {
  margin: 0;
  padding-left: 20px;
}

.attachment-list li {
  margin: 8px 0;
  line-height: 1.45;
}

.attachment-list span {
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
}

.attachment-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.attachment-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #edf0f3;
}

.attachment-body {
  padding: 10px;
  font-size: 13px;
}

.file-preview {
  display: grid;
  min-height: 140px;
  place-items: center;
  gap: 8px;
  padding: 18px;
  background: #f8fafc;
  color: var(--muted);
  text-align: center;
}

.file-icon {
  display: grid;
  width: 54px;
  height: 64px;
  place-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

.file-name {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.version-link {
  height: auto;
  padding: 0;
  white-space: normal;
  text-align: left;
}

.version-preview-html {
  margin-top: 18px;
  max-height: 62vh;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.65;
}

.empty-state {
  display: grid;
  min-height: 420px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  gap: 18px;
}

.admin-form {
  padding: 22px;
}

.admin-login {
  max-width: 420px;
  padding: 18px;
}

.editor-fallback {
  min-height: 280px;
}

#editorHost {
  background: #fff;
}

#contentEditor {
  min-height: 360px;
  background: #fff;
}

.ql-toolbar.ql-snow {
  border-radius: 8px 8px 0 0;
}

.ql-container.ql-snow {
  border-radius: 0 0 8px 8px;
  font-family: inherit;
  font-size: 15px;
}

.script-frame {
  width: 100%;
  min-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

@media (max-width: 980px) {
  .topbar,
  .content {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .brand {
    min-width: 0;
    flex: 1 1 260px;
  }

  .main-nav {
    flex: 0 1 auto;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .toolbar,
  .layout,
  .admin-grid,
  .page-head,
  .form-head,
  .doc-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .page-head,
  .form-head,
  .viewer-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .viewer h1 {
    font-size: 30px;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
  }

  .main-nav {
    width: 100%;
    justify-content: flex-start;
  }

  .main-nav .ant-btn {
    min-width: 0;
  }

  .page-head h1,
  .form-head h1 {
    font-size: 28px;
  }

  .item-title {
    font-size: 17px;
  }
}
