:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1d2528;
  --muted: #667276;
  --line: #dfe4df;
  --brand: #23645a;
  --brand-strong: #17463f;
  --accent: #c64f2f;
  --warn: #a66b00;
  --shadow: 0 16px 40px rgba(29, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button,
.file-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 13px;
  cursor: pointer;
  line-height: 1;
}

button:hover,
.file-button:hover {
  border-color: var(--brand);
}

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

button.danger {
  color: #a13d2a;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(35, 100, 90, 0.14);
}

.app-header {
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
}

h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

.header-actions,
.auth-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.language-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.language-picker select {
  width: auto;
  min-width: 124px;
  padding: 8px 10px;
}

.user-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfcfa;
}

.user-chip strong {
  display: block;
  font-size: 14px;
}

.user-chip span {
  color: var(--muted);
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 104px);
}

.sidebar {
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  text-align: left;
}

.nav-item.active {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

.admin-only {
  display: none;
}

body.is-admin .admin-only {
  display: block;
}

.content {
  min-width: 0;
  padding: 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

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

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(240px, 360px) minmax(0, 1fr);
  gap: 20px;
}

.article-list,
.article-detail,
.preview-panel,
.editor-form,
.stat-card,
.admin-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.article-list {
  display: grid;
  align-content: start;
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.article-row {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 16px;
  text-align: left;
}

.article-row.active {
  background: #edf5f1;
}

.article-row strong {
  display: block;
  margin-bottom: 6px;
}

.article-row span,
.article-meta,
.preview-meta,
.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.article-detail {
  min-height: 560px;
  padding: 28px;
}

.article-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 18px 0;
}

.share-box,
.comments-box {
  margin-top: 18px;
}

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

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

.workspace-articles {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 14px;
}

.workspace-articles button {
  min-width: 190px;
  text-align: left;
}

.workspace-articles button.active {
  border-color: var(--brand);
  background: #edf5f1;
}

.workspace-articles small {
  display: block;
  color: var(--muted);
  margin-top: 5px;
}

.upload-warnings {
  padding: 10px 12px;
  border: 1px solid #e7bd70;
  border-radius: 8px;
  background: #fff8e8;
  color: #77520b;
  font-size: 13px;
}

.editor-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.editor-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.markdown-editor {
  min-height: 430px;
  font-family: "Cascadia Code", Consolas, monospace;
  line-height: 1.55;
  resize: vertical;
}

.preview-panel {
  padding: 18px;
  min-height: 620px;
}

.preview-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.markdown-body {
  line-height: 1.7;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin-top: 1.25em;
}

.markdown-body pre {
  position: relative;
  overflow: auto;
  background: #17201f;
  color: #ecf2ed;
  border-radius: 8px;
  padding: 14px;
}

.copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 8px;
  border-color: #41504e;
  background: #263330;
  color: white;
  font-size: 12px;
}

.markdown-body code {
  background: #eef2ef;
  border-radius: 5px;
  padding: 2px 5px;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
}

.markdown-body blockquote {
  margin-left: 0;
  padding-left: 16px;
  border-left: 4px solid var(--brand);
  color: var(--muted);
}

.markdown-body img {
  max-width: 100%;
  border-radius: 8px;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--line);
  padding: 8px 10px;
}

.markdown-body th {
  background: #f1f5f2;
}

.table-scroll {
  overflow-x: auto;
}

.heading-anchor {
  margin-left: 8px;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
}

.markdown-body h1:hover .heading-anchor,
.markdown-body h2:hover .heading-anchor,
.markdown-body h3:hover .heading-anchor {
  opacity: 1;
}

.article-toc {
  margin: 18px 0;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.article-toc a {
  display: block;
  padding: 3px 0;
  color: var(--brand);
  text-decoration: none;
}

.stats-grid,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
}

.stat-card,
.admin-card {
  padding: 18px;
}

.metric-value {
  display: block;
  font-size: 30px;
  font-weight: 800;
  margin-top: 6px;
}

.admin-card ul {
  padding-left: 18px;
  margin-bottom: 0;
}

.admin-card li {
  margin-bottom: 10px;
}

.admin-card li button {
  margin-left: 6px;
  padding: 7px 9px;
}

.admin-wide {
  grid-column: span 2;
}

.empty-state {
  padding: 24px;
  color: var(--muted);
}

@media (max-width: 960px) {
  .app-header,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .reader-layout,
  .editor-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .content,
  .app-header {
    padding: 18px;
  }

  .sidebar nav,
  .field-row,
  .stats-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }
}
