#posts-index {
  display: none;
}

#posts-workspace {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.posts-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.45fr) minmax(280px, 1.4fr) repeat(4, minmax(150px, 1fr)) auto;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.posts-search-wrap,
.posts-filter-field,
.posts-date-filter {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.posts-filter-bar {
  display: contents;
}

.posts-search-wrap label,
.posts-filter-field > span,
.posts-date-filter > span,
.posts-form-grid label > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.posts-toolbar input,
.posts-toolbar select,
.posts-form-grid input,
.posts-form-grid select,
.posts-form-grid textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 600 13px/1.3 inherit;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.posts-choice {
  position: relative;
  min-width: 0;
}

.posts-choice-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 600 13px/1.3 inherit;
  text-align: left;
  cursor: pointer;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.posts-choice-trigger:hover {
  border-color: #d8dde6;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .08);
}

.posts-choice-trigger:focus,
.posts-choice.is-open .posts-choice-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.posts-choice-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.posts-choice-caret {
  flex: 0 0 auto;
  margin-left: 10px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  transition: transform .16s ease;
}

.posts-choice.is-open .posts-choice-caret {
  transform: rotate(180deg);
}

.posts-choice-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  display: grid;
  width: 100%;
  padding: 6px;
  border: 1px solid #eef2f6;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(16, 24, 40, .12), 0 2px 8px rgba(16, 24, 40, .06);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity .16s ease, transform .16s ease, visibility .16s ease;
}

.posts-choice.is-open .posts-choice-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.posts-choice-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  gap: 10px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-soft);
  font: 500 14px/1.2 inherit;
  text-align: left;
  cursor: pointer;
}

.posts-choice-option:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.posts-choice-option.is-selected {
  background: var(--accent-softer);
  color: var(--text);
}

.posts-choice-check {
  min-width: 16px;
  color: var(--text);
  font-weight: 700;
  opacity: 0;
}

.posts-choice-option.is-selected .posts-choice-check {
  opacity: 1;
}

.posts-toolbar input,
.posts-toolbar select,
.posts-form-grid input,
.posts-form-grid select {
  height: 40px;
  padding: 0 11px;
}

.posts-toolbar input:focus,
.posts-toolbar select:focus,
.posts-form-grid input:focus,
.posts-form-grid select:focus,
.posts-form-grid textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.posts-date-filter > .posts-date-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 7px;
}

.posts-date-filter > .posts-date-inputs span {
  color: var(--muted);
  font-size: 11px;
}

.posts-date-filter input {
  padding: 0 7px;
}

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

.posts-clear-button,
.posts-create-button,
.posts-update-button,
.posts-form-cancel,
.posts-form-submit {
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-soft);
  font: 700 12px/1 inherit;
  white-space: nowrap;
  cursor: pointer;
}

.posts-clear-button {
  padding: 0 13px;
}

.posts-create-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 15px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.posts-create-button span {
  font-size: 17px;
  line-height: 1;
}

.posts-clear-button:hover,
.posts-update-button:hover,
.posts-form-cancel:hover {
  border-color: #cfd4dd;
  background: var(--surface-subtle);
}

.posts-create-button:hover,
.posts-form-submit:hover {
  filter: brightness(.94);
}

.posts-table-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.posts-table-heading {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto minmax(90px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.posts-table-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 750;
}

.posts-table-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.posts-table-meta {
  justify-self: end;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.posts-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

.posts-summary-item {
  display: grid;
  grid-template-columns: auto minmax(24px, auto);
  align-items: center;
  min-height: 36px;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-soft);
  font-family: inherit;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, filter .16s ease;
}

.posts-summary-item:hover {
  filter: brightness(.97);
}

.posts-summary-item:focus-visible,
.posts-summary-item.is-active {
  border-color: currentColor;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .9), 0 0 0 4px currentColor;
}

.posts-summary-item strong {
  font-size: 15px;
  font-weight: 800;
  text-align: right;
}

.posts-summary-item--total,
.posts-summary-item--stopped {
  background: #f2f4f7;
  color: #475467;
}

.posts-summary-item--running {
  background: #e8f7ed;
  color: #18753a;
}

.posts-summary-item--unmapped {
  background: var(--accent-soft);
  color: var(--accent);
}

.posts-table-scroll {
  max-width: 100%;
  overflow: auto;
}

.posts-table {
  width: 100%;
  min-width: 1560px;
  border-collapse: collapse;
  table-layout: fixed;
}

.posts-table th,
.posts-table td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  text-align: left;
}

.posts-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.posts-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.posts-sort:hover,
.posts-sort:focus-visible,
.posts-sort.is-active {
  color: var(--text);
}

.posts-sort:focus-visible {
  border-radius: 4px;
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.posts-sort__icons {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.posts-sort__arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  opacity: 0.6;
}

.posts-sort__arrow.is-current {
  color: var(--accent);
  opacity: 1;
  font-weight: 700;
}

.posts-table th:nth-child(1) { width: 105px; }
.posts-table th:nth-child(2) { width: 130px; }
.posts-table th:nth-child(3) { width: 96px; }
.posts-table th:nth-child(4) { width: 135px; }
.posts-table th:nth-child(5) { width: 135px; }
.posts-table th:nth-child(6) { width: 110px; }
.posts-table th:nth-child(7) { width: 310px; }
.posts-table th:nth-child(8),
.posts-table th:nth-child(9),
.posts-table th:nth-child(10) { width: 170px; }
.posts-table th:nth-child(11) { width: 115px; }
.posts-table th:nth-child(12) { width: 105px; }

.posts-table td {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.35;
}

.posts-table tbody tr:hover td {
  background: var(--accent-softer);
}

.posts-date-cell,
.posts-id-cell {
  white-space: nowrap;
}

.posts-content-id {
  color: var(--text) !important;
  font-weight: 750;
}

.posts-content-id[data-empty="true"] {
  color: #b54708 !important;
}

.posts-title-cell {
  overflow: hidden;
  color: var(--text) !important;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.posts-id-cell {
  color: var(--muted) !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px !important;
}

.posts-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.posts-status--running_ads {
  background: #e8f7ed;
  color: #18753a;
}

.posts-status--stopped_ads {
  background: #f2f4f7;
  color: #475467;
}

.posts-status--not_found_in_ads {
  background: #fff4e5;
  color: #9a5200;
}

.posts-status--unmapped {
  background: var(--accent-soft);
  color: var(--accent);
}

.posts-action-cell {
  position: sticky;
  right: 0;
  z-index: 1;
  background: var(--surface);
  box-shadow: -8px 0 12px -12px rgba(16, 24, 40, .35);
}

.posts-table th:last-child {
  position: sticky;
  right: 0;
  z-index: 3;
  background: var(--surface-subtle);
  box-shadow: -8px 0 12px -12px rgba(16, 24, 40, .35);
}

.posts-table tbody tr:hover .posts-action-cell {
  background: var(--accent-softer);
}

.posts-update-button {
  width: 80px;
  height: 32px;
  color: var(--accent);
}

.posts-empty-row td {
  padding: 50px 16px;
  color: var(--muted);
  text-align: center;
}

.posts-empty-row td[data-tone="error"] {
  color: #b42318;
}

.posts-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 10px 18px;
  border-top: 1px solid var(--border-soft);
  color: var(--muted);
  font-size: 11px;
}

#posts-pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.posts-page-button,
.posts-page-arrow {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-soft);
  font: 700 11px/1 inherit;
  cursor: pointer;
}

.posts-page-button.is-current {
  border-color: #155a46;
  background: #155a46;
  color: #fff;
}

.posts-page-button:disabled,
.posts-page-arrow:disabled {
  opacity: .38;
  cursor: default;
}

.posts-page-gap {
  width: 24px;
  color: var(--muted);
  text-align: center;
}

.posts-drawer[hidden] {
  display: none;
}

.posts-drawer {
  position: fixed;
  z-index: 1000;
  inset: 0;
}

.posts-drawer-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(16, 24, 40, .32);
  cursor: default;
}

.posts-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  width: min(590px, 100vw);
  height: 100%;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  box-shadow: -18px 0 45px rgba(16, 24, 40, .18);
}

.posts-drawer-panel > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border-soft);
}

.posts-drawer-panel h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
}

.posts-drawer-panel header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.posts-drawer-close {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-soft);
  font: 400 24px/1 inherit;
  cursor: pointer;
}

.posts-drawer form {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 22px;
}

.posts-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 14px;
}

.posts-form-grid label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.posts-form-grid textarea {
  min-height: 84px;
  resize: vertical;
  padding: 10px 11px;
}

.posts-form-wide {
  grid-column: 1 / -1;
}

.posts-form-hint,
.posts-form-error {
  margin: 12px 0 0;
  font-size: 11px;
}

.posts-form-hint {
  color: var(--muted);
}

.posts-form-error {
  min-height: 16px;
  color: #b42318;
  font-weight: 650;
}

.posts-form-grid > div.posts-form-wide {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.posts-form-grid > .posts-form-wide > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.platform-logo-group {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.platform-logo {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
  flex: 0 0 auto;
}

/* TikTok ships two artwork variants (black icon for light backgrounds, white icon for
   dark); both are rendered and only one is shown, picked by the app's data-theme attribute
   (frontend/theme.js) so it reacts live to the theme toggle. */
.platform-logo--theme-dark {
  display: none;
}

html[data-theme="dark"] .platform-logo--theme-light {
  display: none;
}

html[data-theme="dark"] .platform-logo--theme-dark {
  display: block;
}

.posts-platform-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.platform-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font: 600 13px/1 inherit;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, color .16s ease;
}

.platform-chip:hover {
  border-color: #d8dde6;
  background: var(--surface-subtle);
}

.platform-chip.is-selected {
  border-color: var(--accent);
  background: var(--accent-softer);
  color: var(--text);
}

.posts-platform-titles {
  display: grid;
  gap: 14px;
}

.posts-platform-title-field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.posts-platform-title-field span {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.posts-meta-ids {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 14px;
}

.posts-form-grid > .posts-meta-ids[hidden] {
  display: none;
}

.posts-platforms-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.posts-drawer form > footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: auto;
  padding-top: 18px;
}

.posts-form-cancel,
.posts-form-submit {
  padding: 0 16px;
}

.posts-form-submit {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.posts-form-submit:disabled {
  opacity: .58;
  cursor: wait;
}

body.posts-drawer-open {
  overflow: hidden;
}

@media (max-width: 1500px) {
  .posts-toolbar {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
  }

  .posts-search-wrap,
  .posts-date-filter {
    grid-column: span 2;
  }

  .posts-toolbar-actions {
    justify-content: flex-end;
    grid-column: span 2;
  }
}

@media (max-width: 900px) {
  .posts-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .posts-search-wrap,
  .posts-date-filter,
  .posts-toolbar-actions {
    grid-column: 1 / -1;
  }

  .posts-toolbar-actions > button {
    flex: 1;
  }

  .posts-table-heading {
    grid-template-columns: 1fr auto;
  }

  .posts-summary {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    overflow-x: auto;
  }
}

@media (max-width: 620px) {
  .posts-toolbar {
    grid-template-columns: minmax(0, 1fr);
    padding: 14px;
  }

  .posts-search-wrap,
  .posts-date-filter,
  .posts-toolbar-actions {
    grid-column: auto;
  }

  .posts-date-filter > .posts-date-inputs {
    grid-template-columns: 1fr;
  }

  .posts-date-filter > .posts-date-inputs span {
    display: none;
  }

  .posts-table-heading,
  .posts-pagination {
    align-items: flex-start;
  }

  .posts-table-heading {
    grid-template-columns: 1fr;
  }

  .posts-table-meta,
  .posts-summary {
    justify-self: stretch;
  }

  .posts-summary {
    grid-column: 1;
    grid-row: auto;
  }

  .posts-pagination {
    padding: 14px;
  }

  #posts-pagination-controls {
    max-width: 100%;
    overflow-x: auto;
  }

  .posts-drawer-panel > header,
  .posts-drawer form {
    padding-right: 16px;
    padding-left: 16px;
  }

  .posts-form-grid {
    grid-template-columns: 1fr;
  }

  .posts-form-wide {
    grid-column: auto;
  }
}
