:root {
  color-scheme: light;
  --bg: #f6f6f5;
  --editor-bg: #fafaf9;
  --panel: #ffffff;
  --text: #18181b;
  --text-soft: #27272a;
  --muted: #71717a;
  --muted-light: #a1a1aa;
  --line: #e4e4e7;
  --line-soft: #ececee;
  --button: #18181b;
  --button-hover: #27272a;
  --button-pressed: #3f3f46;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-line: #fecaca;
  --focus-ring: rgba(24, 24, 27, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 18px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

button:hover {
  background: #f4f4f5;
}

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

button.primary:hover {
  border-color: var(--button-hover);
  background: var(--button-hover);
}

button.primary:active {
  border-color: var(--button-pressed);
  background: var(--button-pressed);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.back-login {
  justify-self: start;
  min-height: 32px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.back-login:hover {
  background: transparent;
  color: var(--text);
}

label {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-weight: 400;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4.5 6.25L8 9.75L11.5 6.25' stroke='%2371717A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  padding-right: 38px;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-light);
}

input:hover,
select:hover,
textarea:hover {
  border-color: #d4d4d8;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--muted-light);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

textarea {
  min-height: 220px;
  border-radius: 10px;
  padding: 14px;
  line-height: 1.6;
  resize: vertical;
}

.shell {
  width: min(760px, calc(100vw - 48px));
  margin: 88px auto;
}

.access-shell {
  width: min(440px, calc(100vw - 32px));
}

.admin-shell {
  width: min(1080px, calc(100vw - 48px));
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 36px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 12px rgba(0, 0, 0, 0.03);
}

.stack {
  display: grid;
  gap: 24px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.role-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #fafafa;
  padding: 4px;
}

.role-tabs button {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.role-tabs button:hover {
  background: #f4f4f5;
}

.role-tabs button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.page-heading {
  display: grid;
  gap: 8px;
}

.centered {
  text-align: center;
}

.title {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.error {
  border: 1px solid var(--danger-line);
  border-radius: 8px;
  background: var(--danger-bg);
  padding: 10px 12px;
  color: var(--danger);
  font-size: 13px;
}

.field-note {
  justify-self: end;
  color: var(--muted-light);
  font-size: 12px;
  font-weight: 400;
}

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

.preview-grid .wide {
  grid-column: 1 / -1;
}

.admin-new {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr auto;
  gap: 14px;
  align-items: end;
}

.admin-list {
  display: grid;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  overflow: hidden;
}

.admin-list-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 16px;
  background: #fff;
  border-bottom: 1px solid var(--line-soft);
}

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

.admin-list-row strong {
  font-size: 15px;
  font-weight: 600;
}

.admin-editor-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  background: #fff;
}

.admin-editor-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  align-content: start;
  gap: 28px;
  border-right: 1px solid var(--line-soft);
  padding: 32px 20px;
  background: #fafafa;
}

.admin-doc-nav {
  display: grid;
  gap: 6px;
}

.admin-doc-nav button {
  justify-content: flex-start;
  min-height: 40px;
  border: 0;
  background: transparent;
  padding: 0 12px;
  color: var(--muted);
  text-align: left;
}

.admin-doc-nav button:hover {
  background: #f4f4f5;
  color: var(--text);
}

.admin-doc-nav button.active {
  background: var(--button);
  color: #fff;
}

.admin-editor-content {
  min-width: 0;
  padding: 48px min(64px, 5vw) 56px;
}

.admin-editor-header {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 34px;
}

.admin-doc-panel {
  display: grid;
  gap: 12px;
}

.admin-doc-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.admin-doc-heading h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.doc-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 10px;
}

.doc-tabs button {
  min-height: 36px;
  padding: 0 12px;
}

.doc-tabs button.active {
  border-color: var(--button);
  background: var(--button);
  color: #fff;
}

.admin-doc {
  min-height: calc(100vh - 210px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.65;
}

.editor-page {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--editor-bg);
}

.editor-bar,
.editor-footer {
  position: sticky;
  z-index: 2;
  background: rgba(255, 255, 255, 0.95);
  border-color: var(--line);
}

.editor-bar {
  top: 0;
  min-height: 60px;
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 18px;
}

.editor-footer {
  bottom: 0;
  border-top: 1px solid var(--line-soft);
  padding: 10px 18px;
  color: var(--muted-light);
  font-size: 12px;
  text-align: center;
}

.editor-main {
  width: min(780px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 56px 0 100px;
  display: grid;
  gap: 22px;
}

.subject-input {
  height: auto;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.35;
}

.body-editor {
  min-height: calc(100vh - 230px);
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text-soft);
  font-size: 16px;
  line-height: 1.8;
  resize: none;
}

.subject-input:focus,
.body-editor:focus {
  box-shadow: none;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 24, 27, 0.18);
  animation: fade-in 160ms ease;
}

.dialog {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 22px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.08);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
}

.dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 700px) {
  .shell {
    width: calc(100vw - 32px);
    margin: 32px auto;
  }

  .panel {
    padding: 22px;
  }

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

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

  .admin-editor-page {
    grid-template-columns: 1fr;
  }

  .admin-editor-sidebar {
    position: static;
    height: auto;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .admin-doc-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-editor-content {
    padding: 24px 18px 40px;
  }

  .admin-editor-header {
    flex-direction: column;
  }

  .row {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1 1 auto;
  }

  .editor-bar {
    align-items: stretch;
    flex-direction: row;
  }

  .editor-main {
    width: calc(100vw - 36px);
    padding: 28px 0 80px;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }
}
