:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #182230;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #2f5fc7;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.page-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.button.danger {
  color: var(--danger);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}

.role-actions {
  display: grid;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin-bottom: 4px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.management-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
}

.folder-panel,
.article-panel,
.error-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.article-panel {
  overflow-x: auto;
}

.error-list {
  margin-bottom: 16px;
  border-color: var(--danger);
  color: var(--danger);
}

.error-list p {
  margin: 0;
}

.folder-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.folder-link {
  display: block;
  padding: 8px;
  color: var(--text);
  text-decoration: none;
}

.article-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.article-table th,
.article-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  max-width: 100%;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf3ff;
  color: #244a9b;
  font-size: 12px;
  white-space: nowrap;
}

.badge.muted {
  background: #eef1f5;
  color: #475467;
}

.state-badge {
  background: #e8f5ef;
  color: #146c43;
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.compact-form,
.article-create-form {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.compact-form input,
.compact-form select,
.article-create-form input,
.article-create-form select,
.inline-rename input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
}

.inline-rename {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  padding: 0 8px 8px;
}

.inline-rename button {
  min-height: 34px;
}

.back-link {
  display: inline-flex;
  margin-bottom: 6px;
  color: var(--accent);
  text-decoration: none;
}

.editor-shell {
  max-width: 1320px;
}

.editor-topbar {
  align-items: flex-start;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.article-document {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px 28px;
  min-height: 520px;
}

.module-editor-row {
  display: grid;
  gap: 10px;
}

.article-module {
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 16px;
  padding: 10px 0;
}

.module-gutter {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.module-editor-row:hover .module-gutter,
.module-editor-row:focus-within .module-gutter {
  opacity: 1;
  pointer-events: auto;
}

.module-gutter form {
  margin: 0;
}

.icon-button {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.icon-button.danger {
  color: var(--danger);
}

.icon-only-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--text);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.icon-only-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.icon-only-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.module-content {
  min-width: 0;
  font-size: 16px;
  line-height: 1.55;
}

.module-content h2,
.module-content h3,
.module-content p {
  margin-top: 0;
}

.document-header h2 {
  font-size: 34px;
  line-height: 1.15;
  margin-bottom: 8px;
}

.document-banner {
  background: #fff7ed;
  border-left: 4px solid #f97316;
  padding: 16px;
}

.document-overview {
  color: #344054;
  font-size: 18px;
}

.document-paragraph,
.document-paragraph p,
.document-footer p,
.document-overview p,
.document-step p,
.document-accordion p {
  white-space: pre-wrap;
}

.document-step {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
}

.step-number {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #e8f5ef;
  color: #146c43;
  font-weight: 700;
}

.document-accordion {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.document-accordion summary {
  cursor: pointer;
  font-weight: 700;
}

.document-video {
  background: #f6f7fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.module-sidebar,
.module-edit-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.module-sidebar {
  position: sticky;
  top: 16px;
}

.module-sidebar h2 {
  margin-top: 0;
}

.module-edit-panel {
  margin-left: 80px;
  margin-bottom: 16px;
  background: #fbfcfe;
}

.module-form {
  display: grid;
  gap: 10px;
}

.module-form input,
.module-form select,
.module-form textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
}

.module-form textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field-error {
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.repository-browser {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  color: var(--text);
  background: #eef2f6;
}

.repository-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.repository-header h1,
.folder-detail-panel h1,
.article-detail-header h1 {
  margin: 0;
}

.repository-header p,
.article-detail-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.repository-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.repository-sidebar {
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #f8fafc;
  padding: 16px 12px;
}

.sidebar-header h2 {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.repository-tree {
  display: grid;
  gap: 2px;
}

.tree-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  min-height: 34px;
  padding-left: calc(var(--tree-depth) * 18px);
  border-radius: 6px;
}

.tree-row.is-hidden {
  display: none;
}

.tree-row.is-selected {
  background: #dce9ff;
}

.tree-caret,
.tree-caret-placeholder {
  width: 22px;
  height: 28px;
}

.tree-caret {
  border: 0;
  background: transparent;
  color: #475467;
  cursor: pointer;
}

.tree-caret::before {
  content: ">";
  display: inline-block;
  transition: transform 0.12s ease;
}

.tree-row[data-expanded="true"] .tree-caret::before {
  transform: rotate(90deg);
}

.tree-link {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 8px 0 2px;
  color: var(--text);
  text-decoration: none;
}

.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-icon {
  position: relative;
  flex: 0 0 auto;
}

.folder-icon {
  width: 16px;
  height: 13px;
  margin-top: 2px;
  border: 1px solid #bf7b16;
  border-radius: 2px;
  background: #f2b84b;
}

.folder-icon::before {
  content: "";
  position: absolute;
  left: 1px;
  top: -5px;
  width: 8px;
  height: 5px;
  border: 1px solid #bf7b16;
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  background: #ffd071;
}

.document-icon {
  width: 14px;
  height: 16px;
  border: 1px solid #667085;
  border-radius: 2px;
  background: #ffffff;
}

.document-icon::after {
  content: "";
  position: absolute;
  top: -1px;
  right: -1px;
  border-left: 5px solid transparent;
  border-bottom: 5px solid #dce9ff;
}

.repository-content {
  min-width: 0;
  overflow: auto;
  padding: 24px;
  background: #ffffff;
}

.folder-detail-panel,
.article-detail-panel {
  max-width: 1180px;
}

.folder-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 190px));
  gap: 12px;
  margin: 20px 0 24px;
}

.stat-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 16px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
}

.stat-label {
  color: var(--muted);
}

.folder-detail-form,
.article-detail-form {
  display: grid;
  gap: 16px;
  max-width: 620px;
}

.article-detail-form {
  margin-bottom: 24px;
}

.folder-detail-form input[type="text"],
.folder-detail-form input[name="name"],
.article-detail-form input[name="title"],
.folder-detail-form select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
}

.access-fieldset {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

.access-fieldset legend {
  margin-bottom: 8px;
  font-weight: 700;
}

.access-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.access-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 0 10px;
  text-transform: capitalize;
}

.context-actions,
.article-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.context-actions {
  margin-top: 20px;
}

.article-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.article-identity {
  min-width: 0;
}

.inline-edit-group {
  min-width: 0;
}

.inline-edit-display {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.article-title-display h1 {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.article-title-display h1 span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.article-location {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
}

.article-location form {
  margin: 0;
}

.article-language-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.article-language-group .inline-edit-panel {
  margin-top: 0;
}

.inline-edit-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.inline-edit-panel[hidden],
.add-module-panel[hidden] {
  display: none;
}

.inline-edit-panel input,
.inline-edit-panel select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
}

.article-title-edit input {
  min-width: min(420px, 100%);
}

.inline-edit-trigger {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.inline-edit-group:hover .inline-edit-trigger,
.inline-edit-group:focus-within .inline-edit-trigger {
  opacity: 1;
  pointer-events: auto;
}

@media (hover: none), (pointer: coarse) {
  .inline-edit-trigger {
    opacity: 1;
    pointer-events: auto;
  }
}

.add-module-region {
  display: grid;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.add-module-region > .button {
  justify-self: start;
}

.add-module-panel {
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.add-module-panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.article-audit {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.article-audit p {
  margin: 0;
}

.settings-shell {
  max-width: 1440px;
}

.settings-css-form {
  display: block;
}

.settings-css-layout {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.settings-css-editor,
.settings-css-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.settings-css-editor {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 10px;
}

.settings-css-editor label {
  font-weight: 700;
}

.settings-css-editor textarea {
  width: 100%;
  min-height: 560px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font: 14px/1.5 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color: var(--text);
}

.settings-css-preview {
  overflow: auto;
}

.settings-css-preview-frame {
  display: block;
  width: 100%;
  min-height: 720px;
  border: 0;
  background: var(--panel);
}

.settings-sample-document {
  min-height: auto;
}

.settings-sample-document .article-module {
  grid-template-columns: minmax(0, 1fr);
}

.module-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

@media (max-width: 760px) {
  .page-shell {
    padding: 16px;
  }

  .topbar,
  .management-layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: start;
  }

  .editor-layout,
  .settings-css-layout,
  .repository-layout {
    grid-template-columns: 1fr;
  }

  .module-sidebar,
  .settings-css-editor {
    position: static;
    order: -1;
  }

  .repository-header,
  .article-detail-header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .repository-sidebar {
    max-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .repository-content {
    padding: 16px;
  }

  .access-options,
  .folder-stats {
    grid-template-columns: 1fr;
  }

  .article-document {
    padding: 16px;
  }

  .article-module {
    grid-template-columns: 1fr;
  }

  .module-gutter {
    flex-direction: row;
    flex-wrap: wrap;
    opacity: 1;
    pointer-events: auto;
  }

  .module-gutter .icon-button {
    width: auto;
    min-width: 58px;
  }

  .module-edit-panel {
    margin-left: 0;
  }
}
