:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --text: #17201b;
  --muted: #69736d;
  --line: #dce3dd;
  --accent: #18725f;
  --accent-dark: #105647;
  --danger: #a73535;
}

* {
  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;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
.button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  font: inherit;
  font-weight: 650;
}

button:hover,
.button:hover {
  background: var(--accent-dark);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
}

textarea {
  min-height: 0;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
}

label span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

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

.brand {
  color: var(--text);
  font-weight: 800;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 0 0 auto;
}

.topbar form,
.action-buttons form {
  margin: 0;
}

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

.topbar-editor {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.topbar-editor form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-editor select,
.topbar-editor input {
  height: 36px;
  padding: 0 8px;
}

.share-form select {
  width: 58px;
  height: 36px;
  min-height: 36px;
  line-height: 36px;
  appearance: auto;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  font-size: 22px;
  line-height: 0;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.save-status {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.save-status[data-state="dirty"],
.save-status[data-state="saving"] {
  color: #8a671d;
}

.save-status[data-state="error"] {
  color: var(--danger);
}

.link-button,
.danger-link {
  min-height: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 500;
}

.topbar-action {
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  min-height: 34px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  font-weight: 650;
}

.topbar-action:hover {
  background: var(--accent-dark);
  color: #fff;
}

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

.link-button:hover,
.danger-link:hover {
  background: transparent;
  text-decoration: underline;
}

.container {
  width: min(1120px, calc(100vw - 32px));
  margin: 34px auto;
}

.narrow {
  width: min(760px, calc(100vw - 32px));
}

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

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

h1 {
  font-size: 30px;
  line-height: 1.2;
  margin-bottom: 8px;
}

h2 {
  font-size: 18px;
}

.page-title p,
.muted-link,
.share-state {
  color: var(--muted);
}

.filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto auto auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.checkbox input {
  width: auto;
}

.checkbox span {
  margin: 0;
  font-size: 15px;
}

.table-wrap {
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th:first-child,
td:first-child {
  width: 50%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 10%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 8%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 17%;
}

th:nth-child(5),
td:nth-child(5) {
  width: 15%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  text-align: left;
  vertical-align: middle;
}

tbody td {
  padding-top: 18px;
  padding-bottom: 18px;
}

tbody .title-cell {
  padding-top: 18px;
  padding-bottom: 18px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.title-link {
  color: var(--text);
  display: inline-block;
  font-weight: 700;
  line-height: 1.45;
}

.row-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 7px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.active {
  border-color: #b7dfd4;
  background: #e8f6f1;
  color: var(--accent-dark);
}

.status-pill.off {
  border-color: var(--line);
  background: #f4f6f3;
  color: var(--muted);
}

.status-pill.expired {
  border-color: #ead7ad;
  background: #fff8e8;
  color: #7a5a13;
}

.actions-cell {
  white-space: nowrap;
}

.action-buttons {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
}

.icon-action {
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
}

.icon-action:hover {
  background: var(--surface-2);
  color: var(--accent);
}

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

.icon-action.danger:hover {
  border-color: #e3b7b7;
  background: #fff5f5;
  color: var(--danger);
}

.icon-action svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.login-body,
.reader-body {
  min-height: 100vh;
  background: #fbfbf8;
}

.login-panel {
  width: min(420px, calc(100vw - 32px));
  margin: 14vh auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
}

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

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

.success {
  color: var(--accent);
  margin: 0;
}

.editor-shell {
  width: calc(100vw - 20px);
  margin: 0 auto;
  padding: 0;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: calc(100vh - 58px);
}

.editor-form,
.side-panel,
.settings-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 26px;
}

.editor-form,
.side-panel {
  height: calc(100vh - 60px);
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.meta-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
  gap: 12px;
  align-items: end;
}

.content-label {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.content-label textarea {
  flex: 1;
  height: auto;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.secondary {
  background: var(--surface-2);
  color: var(--text);
}

.secondary:hover {
  background: #dde8df;
}

.preview {
  height: 100%;
  min-height: 0;
  max-height: none;
  overflow: auto;
}

.reader {
  width: min(780px, calc(100vw - 34px));
  margin: 0 auto;
  padding: 56px 0 80px;
}

.reader h1 {
  font-size: 38px;
  margin-bottom: 30px;
}

.unavailable {
  padding-top: 20vh;
}

.prose {
  line-height: 1.78;
  font-size: 17px;
}

.prose h1,
.prose h2,
.prose h3 {
  line-height: 1.3;
  margin-top: 1.7em;
}

.prose img {
  max-width: 100%;
  border-radius: 6px;
}

.prose pre {
  overflow-x: auto;
  background: #101715;
  color: #f3f7f5;
  border-radius: 8px;
  padding: 16px;
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.prose blockquote {
  margin-left: 0;
  padding-left: 16px;
  border-left: 3px solid var(--accent);
  color: #48534d;
}

.settings-block + .settings-block {
  margin-top: 18px;
}

.warning {
  border-color: #e3c4a8;
}

@media (max-width: 900px) {
  .editor-grid,
  .filters {
    grid-template-columns: 1fr;
  }

  .page-title,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 0 16px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .topbar-editor {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .topbar nav {
    gap: 10px;
    flex-wrap: wrap;
  }

  textarea {
    min-height: 46vh;
    height: auto;
    resize: vertical;
  }

  .preview {
    min-height: 50vh;
    max-height: none;
  }

  .editor-grid {
    min-height: 0;
  }

  .meta-row {
    grid-template-columns: 1fr;
  }

  .editor-form,
  .side-panel {
    height: auto;
  }

  .action-buttons {
    flex-wrap: wrap;
  }
}
