:root {
  --bg: #f7f5f1;
  --surface: #fffefa;
  --line: #ded9cf;
  --text: #24211d;
  --muted: #6f6a61;
  --accent: #0f766e;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
a {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 0.48rem 0.7rem;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
a:hover {
  border-color: var(--accent);
}

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

.admin-shell {
  min-height: 100vh;
}

.login-panel {
  width: min(360px, calc(100% - 2rem));
  margin: 14vh auto;
}

.login-panel form,
.meta-grid,
.editor,
.sidebar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.login-panel form {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0.55rem 0.65rem;
}

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

.app {
  width: min(1380px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.topbar h1 {
  margin: 0;
}

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

.topbar-actions,
.sidebar-actions,
.editor-actions,
.checks,
.source-mode,
.view-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.sidebar-filters {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.post-count {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 1rem;
}

.sidebar,
.editor {
  padding: 0.9rem;
}

.sidebar {
  align-self: start;
}

.post-list-admin {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.8rem;
  max-height: calc(100vh - 11rem);
  overflow: auto;
}

.post-item {
  width: 100%;
  text-align: left;
}

.post-item.is-published {
  background: #f5fbf9;
}

.post-item.is-draft {
  background: #fff8e6;
}

.post-item.is-hidden {
  background: #f4f4f5;
}

.post-item.is-pinned {
  border-color: #0f766e;
  box-shadow: inset 3px 0 0 #0f766e;
}

.status-badge {
  display: inline-flex;
  border-radius: 999px;
  background: #e9ecef;
  padding: 0.08rem 0.38rem;
  color: var(--text);
  font-size: 0.75rem;
}

.status-badge.is-published {
  background: #dff5ef;
}

.status-badge.is-draft {
  background: #ffe9ad;
}

.status-badge.is-hidden {
  background: #e5e7eb;
}

.status-badge.is-pinned {
  background: #ccece7;
}

.post-item strong {
  display: block;
}

.post-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.post-item small {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  padding: 0.8rem;
}

.meta-grid label,
.checks label,
.term-select-field {
  color: var(--muted);
  font-size: 0.9rem;
}

.term-select-field,
.summary-field {
  grid-column: 1 / -1;
}

.term-select-field .ts-wrapper {
  margin-top: 0.35rem;
}

.summary-field textarea {
  display: block;
  width: 100%;
  min-height: 5.5rem;
  margin-top: 0.35rem;
  resize: vertical;
  font-family: inherit;
  line-height: 1.55;
}

.term-select-field .ts-control {
  max-height: 7.5rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.32rem 0.4rem;
  box-shadow: none;
}

.term-select-field .ts-control.focus {
  border-color: var(--accent);
}

.term-select-field .ts-control .item {
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 999px;
  background: #eef7f5;
  color: var(--text);
  padding: 0.14rem 0.55rem;
}

.term-select-field .ts-control .item .remove {
  border-left: 0;
  color: var(--muted);
  margin-left: 0.2rem;
}

.term-select-field .ts-dropdown {
  z-index: 50;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 12px 28px rgb(36 33 29 / 14%);
}

.term-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  border: 0;
  border-radius: 5px;
  background: transparent;
  padding: 0.45rem 0.5rem;
  color: var(--text);
  text-align: left;
}

.term-option:hover {
  background: #eef7f5;
}

.term-option input {
  width: auto;
}

.checks,
.editor-actions {
  margin-top: 0.8rem;
}

.checks input {
  width: auto;
}

.source-mode {
  margin-left: auto;
}

.view-mode {
  margin-left: auto;
}

.source-mode label,
.view-mode label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.source-mode input,
.view-mode input {
  width: auto;
}

.raw-error:empty {
  display: none;
}

.raw-error {
  margin: 0.7rem 0 0;
}

.editor.raw-mode .structured-only,
.editor.raw-mode .preview,
.editor.raw-mode #body {
  display: none;
}

.editor.raw-mode .panes {
  grid-template-columns: minmax(0, 1fr);
}

.editor.raw-mode .raw-body {
  display: block;
  min-height: calc(100vh - 8rem);
}

.panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.9rem;
  margin-top: 0.9rem;
}

.panes.edit-only,
.panes.preview-only {
  grid-template-columns: minmax(0, 1fr);
}

.panes.edit-only .preview,
.panes.preview-only textarea,
.panes.preview-only .raw-body {
  display: none;
}

.editor.raw-mode .panes.preview-only .raw-body,
.editor.raw-mode .panes.edit-only .raw-body {
  display: block;
}

textarea {
  min-height: calc(100vh - 18rem);
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  line-height: 1.55;
}

.preview {
  min-height: calc(100vh - 18rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0.8rem;
  line-height: 1.7;
}

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

.preview pre {
  overflow: auto;
  padding: 0.8rem;
  background: #1f2523;
  color: #f4f1e8;
  border-radius: 7px;
}

@media (max-width: 920px) {
  .workspace,
  .panes,
  .meta-grid {
    grid-template-columns: 1fr;
  }
}
