:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-alt: #eef3f0;
  --text: #1f2528;
  --muted: #637078;
  --line: #d8dfdc;
  --accent: #2f6b5f;
  --accent-dark: #214c44;
  --danger: #a33d35;
  --focus: #d79d3f;
  --shadow: 0 10px 30px rgba(31, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(215, 157, 63, 0.42);
  outline-offset: 2px;
}

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

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

main {
  width: min(1540px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px max(16px, calc((100vw - 1540px) / 2 + 16px));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.toolbar,
.page-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.search-box {
  display: grid;
  gap: 6px;
}

.search-box span,
.dialog-form label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.search-box input,
.dialog-form input,
.dialog-form select,
.dialog-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 10px 12px;
}

.page-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 14px;
}

.publish-status {
  min-height: 20px;
  margin: -6px 0 10px;
  color: var(--muted);
  font-size: 0.8rem;
}

.link-check-panel {
  margin: -2px 0 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.link-check-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
}

.link-check-list {
  display: grid;
  gap: 7px;
  max-height: 360px;
  margin: 10px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.link-check-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid #ecd3d0;
  border-radius: 6px;
  background: #fff7f6;
}

.link-check-title {
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.link-check-meta,
.link-check-more {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.link-check-actions {
  display: flex;
  gap: 6px;
}

.page-tab {
  flex: 0 0 auto;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.page-tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.board {
  column-count: var(--page-columns, 3);
  column-gap: 14px;
}

.section-card {
  display: inline-block;
  position: relative;
  width: 100%;
  min-width: 0;
  margin: 0 0 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  break-inside: avoid;
  page-break-inside: avoid;
  overflow: hidden;
}

.section-card.drag-over,
.bookmark-list.drag-over {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(215, 157, 63, 0.2);
}

.section-card.drag-before {
  box-shadow: inset 0 4px 0 var(--focus), var(--shadow);
}

.section-card.drag-after {
  box-shadow: inset 0 -4px 0 var(--focus), var(--shadow);
}

.section-header {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 9px 7px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
}

.section-title {
  min-width: 0;
}

.section-title h2 {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.25;
}

.section-actions,
.bookmark-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.editor-mode .section-actions,
.editor-mode .bookmark-actions {
  position: absolute;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.editor-mode .section-actions {
  top: 4px;
  right: 4px;
  max-width: calc(100% - 8px);
}

.editor-mode .bookmark-actions {
  top: 3px;
  right: 4px;
  max-width: calc(100% - 8px);
}

.editor-mode .section-card:hover > .section-header .section-actions,
.editor-mode .section-card:focus-within > .section-header .section-actions,
.editor-mode .bookmark-row:hover > .bookmark-actions,
.editor-mode .bookmark-row:focus-within > .bookmark-actions {
  opacity: 1;
  pointer-events: auto;
}

.small-button {
  min-height: 26px;
  padding: 0 7px;
  font-size: 0.74rem;
  box-shadow: 0 4px 12px rgba(31, 37, 40, 0.12);
}

.bookmark-list {
  display: grid;
  gap: 0;
  min-height: 40px;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 2px solid transparent;
}

.bookmark-row {
  display: grid;
  position: relative;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

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

.bookmark-row.drag-over {
  box-shadow: inset 0 3px 0 var(--focus);
}

.bookmark-row.link-problem {
  border-bottom-color: #c90000;
  background: #ff1f1f;
  color: #ffffff;
}

.bookmark-main {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.favicon {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: transparent;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.favicon img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.bookmark-text {
  min-width: 0;
}

.bookmark-text a {
  color: var(--text);
  display: block;
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.bookmark-text a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.bookmark-row.link-problem .bookmark-text a,
.bookmark-row.link-problem .bookmark-text a:hover {
  color: #ffffff;
}

.bookmark-row.link-problem .tag {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.bookmark-row.link-problem .small-button {
  border-color: rgba(255, 255, 255, 0.56);
  background: rgba(255, 255, 255, 0.92);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 3px;
}

.tag {
  max-width: 100%;
  border-radius: 999px;
  background: #e5ece9;
  color: #314942;
  font-size: 0.66rem;
  padding: 1px 5px;
  overflow-wrap: anywhere;
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  text-align: center;
  padding: 24px;
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop {
  background: rgba(31, 37, 40, 0.42);
}

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

.dialog-form h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog-form label {
  display: grid;
  gap: 6px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .board {
    column-count: 2;
  }
}

@media (max-width: 680px) {
  main {
    width: min(100% - 20px, 1540px);
  }

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

  .page-tools {
    justify-content: flex-start;
  }

  .link-check-item {
    grid-template-columns: 1fr;
  }

  .link-check-actions {
    justify-content: flex-start;
  }

  .board {
    column-count: 1;
  }

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