:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #edf4fb;
  --ink: #162536;
  --muted: #64768a;
  --line: #d5e0eb;
  --accent: #3f6f9f;
  --accent-strong: #2f5d88;
  --accent-soft: #e5eff8;
  --warm: #4f7f9f;
  --warm-soft: #e6f1f7;
  --danger: #b4233a;
  --shadow: 0 12px 30px rgba(36, 70, 105, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 24px;
  overflow-y: auto;
}

.brand {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

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

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.panel-heading h2,
.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.panel-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.sort-control {
  min-width: 230px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
}

.field-help {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

textarea,
input[type="search"],
input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 96px;
  padding: 10px 12px;
}

textarea:focus,
input[type="search"]:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.button-row {
  margin-top: 10px;
}

.primary-button,
.ghost-button,
.icon-button,
.load-more {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: 120ms ease;
}

.primary-button {
  flex: 1;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: transparent;
  color: var(--accent);
  padding: 0 8px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  background: var(--surface-soft);
  color: var(--ink);
  border-color: var(--line);
  font-weight: 700;
}

.icon-button:hover,
.ghost-button:hover {
  border-color: var(--accent);
}

button:disabled,
button.is-busy {
  cursor: wait;
  opacity: 0.52;
  filter: saturate(0.55);
}

.primary-button:disabled,
.primary-button.is-busy,
.ghost-button:disabled,
.ghost-button.is-busy,
.icon-button:disabled,
.icon-button.is-busy,
.danger-button:disabled,
.danger-button.is-busy,
.row-actions button:disabled,
.row-actions button.is-busy {
  pointer-events: none;
}

.primary-button:disabled:hover,
.primary-button.is-busy:hover {
  background: var(--accent);
}

.ghost-button:disabled:hover,
.ghost-button.is-busy:hover,
.icon-button:disabled:hover,
.icon-button.is-busy:hover {
  border-color: transparent;
}

.tag-picker {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfe;
}

.tag-controls {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.tag-clear {
  justify-self: end;
  min-height: 30px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-list[hidden] {
  display: none;
}

.tag-list-scroll {
  max-height: 152px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.tag-list-selected {
  max-height: none;
  overflow: visible;
}

.tag-empty {
  width: 100%;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.tag-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tag-tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.15;
}

.tag-tab.active {
  background: #fff;
  color: var(--accent-strong);
  box-shadow: 0 1px 3px rgba(36, 70, 105, 0.12);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 5px 10px;
  font-size: 14px;
}

.tag small {
  color: var(--muted);
}

.tag.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tag.excluded {
  border-color: var(--warm);
  background: var(--warm-soft);
  color: var(--warm);
}

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

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

.toolbar h2 {
  font-size: 28px;
  line-height: 1.2;
  margin-top: 4px;
}

.search {
  display: grid;
  grid-template-columns: 24px minmax(120px, 220px);
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
}

.search span {
  color: var(--muted);
}

.search input {
  border: 0;
  padding: 0;
}

.search input:focus {
  box-shadow: none;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  min-height: 38px;
  padding: 0 10px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
  margin-bottom: 14px;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 4px 9px;
  color: var(--muted);
  font-size: 13px;
}

.feed {
  display: grid;
  gap: 12px;
}

.post {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.post.seen {
  opacity: 0.68;
}

.post-main {
  min-width: 0;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.post h3 {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.3;
}

.post p {
  color: #24364a;
  margin-bottom: 12px;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.post-tag {
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  padding: 3px 8px;
  font-size: 12px;
}

.post-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.post-actions a,
.post-actions button {
  min-height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 5px 10px;
  text-decoration: none;
  font-size: 14px;
}

.post-actions a {
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
}

.thumb {
  width: 132px;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-soft);
}

.attachment-note {
  display: grid;
  place-items: center;
  width: 132px;
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 8px;
  font-size: 13px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  color: var(--muted);
}

.load-more {
  display: none;
  width: 100%;
  margin-top: 14px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--accent-strong);
  font-weight: 700;
}

.load-more.visible {
  display: block;
}

.admin-layout {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.admin-header .brand {
  margin-bottom: 0;
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-strong);
  padding: 0 12px;
  text-decoration: none;
  font-weight: 700;
}

.admin-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.admin-tabs button {
  min-height: 38px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-weight: 700;
}

.admin-tabs button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.auth-panel {
  max-width: 560px;
}

.admin-form {
  display: grid;
  gap: 10px;
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 8px;
}

.admin-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr)) 160px;
  gap: 10px;
  margin-bottom: 14px;
}

.tech-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.admin-summary > div,
.admin-summary > button,
.tech-summary > div {
  min-height: 66px;
  border-radius: 8px;
}

.admin-summary > div,
.tech-summary > div {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 12px;
}

.admin-summary span,
.tech-summary span {
  display: block;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
}

.admin-summary small,
.admin-table small,
.tech-summary small {
  color: var(--muted);
}

.source-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr) 120px 140px;
  gap: 10px;
  align-items: end;
}

.tag-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(140px, 0.8fr) minmax(160px, 1fr) 140px;
  gap: 10px;
  align-items: end;
}

.full-field {
  grid-column: 1 / -1;
}

.tag-admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.tags-table {
  min-width: 720px;
}

.tags-table tr.active {
  background: var(--accent-soft);
}

.tags-table tbody tr {
  cursor: pointer;
}

.tags-table tbody tr:hover,
.tags-table tbody tr:focus {
  background: var(--surface-soft);
  outline: none;
}

.tags-table tbody tr.active:hover,
.tags-table tbody tr.active:focus {
  background: var(--accent-soft);
}

.tag-edit-form {
  display: grid;
  gap: 10px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.tag-edit-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.tag-edit-heading h3 {
  margin: 0;
  font-size: 18px;
}

.tag-edit-heading small {
  color: var(--muted);
}

.compact-toggle {
  justify-content: center;
  margin-bottom: 0;
}

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

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

.traffic-wrap {
  margin-top: 12px;
}

.traffic-table {
  min-width: 720px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

.admin-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.admin-table a {
  color: var(--accent-strong);
  text-decoration: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 700;
}

.status-pill.ok {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-pill.muted {
  background: var(--surface-soft);
  color: var(--muted);
}

.row-actions {
  display: grid;
  gap: 6px;
  min-width: 112px;
}

.row-actions button,
.danger-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 4px 8px;
}

.danger-button {
  border-color: rgba(180, 35, 58, 0.38);
  color: var(--danger);
}

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

.admin-status {
  min-height: 24px;
  color: var(--muted);
}

.admin-status.ok {
  color: var(--accent-strong);
}

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

.queue-panel {
  margin-bottom: 14px;
}

.progress-line {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

#queueProgressText {
  color: var(--muted);
  font-size: 13px;
}

.queue-items {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.queue-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
}

.queue-item span,
.queue-item small {
  display: block;
}

.queue-item span {
  font-weight: 700;
}

.queue-item small {
  color: var(--muted);
}

.queue-item.running {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.queue-item.error {
  border-color: rgba(180, 35, 58, 0.42);
}

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

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
}

.chart-box {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.chart-box.wide {
  grid-column: 1 / -1;
}

.chart-box h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.chart-box canvas {
  display: block;
  width: 100%;
  max-width: 100%;
}

.tech-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
  margin: 0;
}

.tech-details div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.tech-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.tech-details dd {
  margin: 4px 0 0;
}

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

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

  .toolbar {
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .search {
    flex: 1;
    grid-template-columns: 24px minmax(0, 1fr);
  }

  .admin-summary,
  .tech-summary,
  .chart-grid,
  .tech-details,
  .source-form,
  .tag-form,
  .tag-admin-layout {
    grid-template-columns: 1fr 1fr;
  }

  .admin-summary > button,
  .source-form > button,
  .tag-form > button,
  .tag-edit-form,
  .tag-admin-layout > * {
    grid-column: 1 / -1;
  }

  .tag-edit-form {
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-top: 14px;
  }
}

@media (max-width: 640px) {
  .content,
  .sidebar {
    padding: 18px;
  }

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

  .thumb,
  .attachment-note {
    width: 100%;
  }

  .admin-layout {
    width: min(100% - 24px, 1240px);
    padding-top: 16px;
  }

  .admin-header,
  .inline-fields {
    grid-template-columns: 1fr;
  }

  .admin-header {
    display: grid;
  }

  .admin-header-actions {
    justify-content: stretch;
  }

  .admin-header-actions > * {
    flex: 1;
    justify-content: center;
  }

  .panel-heading {
    align-items: flex-start;
  }

  .panel-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .sort-control {
    min-width: min(230px, 100%);
  }

  .admin-summary,
  .tech-summary,
  .chart-grid,
  .tech-details,
  .source-form,
  .tag-form,
  .tag-admin-layout {
    grid-template-columns: 1fr;
  }

  .progress-line {
    grid-template-columns: 1fr;
  }
}
