.operation-tabs {
  position: sticky;
  z-index: 10;
  top: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-bottom: 20px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(241, 245, 249, 0.96);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}

.operation-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 680;
  cursor: pointer;
  transition: color var(--duration) ease, border-color var(--duration) ease, background var(--duration) ease, box-shadow var(--duration) ease;
}

.operation-tabs button svg {
  width: 18px;
  height: 18px;
}

.operation-tabs button:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
}

.operation-tabs button.active {
  border-color: #d7e0ec;
  color: var(--primary);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}

.operation-panel[hidden] {
  display: none;
}

.operation-panel > .panel:last-child {
  margin-bottom: 0;
}

.import-form,
.bundled-action {
  max-width: 880px;
}

.bundled-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
  max-width: 880px;
  margin-top: 24px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.source-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-separator::before,
.source-separator::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.emoji-library-panel {
  container-type: inline-size;
}

.emoji-upload-panel {
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.emoji-upload-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.emoji-library-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(210px, 1fr) auto;
  align-items: end;
  gap: 14px;
  margin-bottom: 12px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

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

.search-field {
  position: relative;
  display: block;
}

.search-field svg {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.search-field input {
  padding-left: 39px;
}

.emoji-selection-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 36px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 650;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

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

.emoji-card[hidden] {
  display: none;
}

.emoji-preview {
  position: relative;
  display: grid;
  height: 178px;
  place-items: center;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background-color: #f4f6fa;
  background-image:
    linear-gradient(45deg, #e7ebf1 25%, transparent 25%),
    linear-gradient(-45deg, #e7ebf1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e7ebf1 75%),
    linear-gradient(-45deg, transparent 75%, #e7ebf1 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.emoji-preview img {
  width: 126px;
  height: 126px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(15, 23, 42, 0.12));
}

.emoji-select {
  position: absolute;
  z-index: 2;
  top: 10px;
  left: 10px;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  min-height: 44px;
  gap: 7px;
  padding: 6px 9px;
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.emoji-select input {
  width: 17px;
  min-height: 17px;
  margin: 0;
  accent-color: var(--primary);
}

.emoji-select span {
  font-size: 11px;
}

.emoji-motion {
  position: absolute;
  right: 10px;
  bottom: 10px;
  border-color: #f1d4aa;
  color: var(--warning);
  background: rgba(255, 247, 237, 0.94);
}

.emoji-card-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.emoji-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 8px;
}

.emoji-card-meta strong {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emoji-name-form {
  gap: 10px;
  padding-top: 3px;
}

.emoji-name-form textarea {
  min-height: 58px;
}

.emoji-name-form .button {
  width: 100%;
  min-height: 44px;
}

.emoji-search-empty {
  min-height: 180px;
}

.legacy-emoji-import {
  margin-top: 20px;
}

.builder-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

#channel-cards {
  display: grid;
  gap: 16px;
}

.channel-builder-card,
.weekday-card,
.tribe-route-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.channel-builder-card {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.channel-card-head,
.weekday-card-head,
.tribe-route-heading,
.builder-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.channel-card-head {
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.channel-card-head h3 {
  margin: 0;
}

.channel-main-grid,
.invite-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.channel-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.builder-actions {
  padding-top: 4px;
}

.invite-panel + .invite-panel {
  margin-top: 20px;
}

#invite-channels,
#performance-channels {
  min-height: 220px;
}

.tribe-route-heading {
  align-items: baseline;
}

.tribe-route-list {
  display: grid;
  gap: 10px;
}

.tribe-route-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  padding: 13px;
  background: var(--surface-subtle);
}

.message-schedule-grid {
  display: grid;
  grid-template-columns: 1.3fr 1.3fr 1fr 1fr;
  gap: 16px;
}

.message-template-create {
  margin-bottom: 18px;
}

.template-create-form {
  margin: 0;
}

.message-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.message-template-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.message-template-card > summary {
  display: block;
  min-height: 154px;
  padding: 16px;
  cursor: pointer;
  list-style: none;
  transition: background var(--duration) ease;
}

.message-template-card > summary::-webkit-details-marker {
  display: none;
}

.message-template-card > summary:hover {
  background: var(--surface);
}

.message-template-summary-main {
  display: grid;
  min-width: 0;
  gap: 10px;
}

.message-template-card-meta,
.message-template-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.message-template-card-title {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
  line-height: 1.35;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.message-template-card-meta {
  min-width: 0;
  flex-wrap: wrap;
}

.message-template-card-meta small,
.template-picker small {
  color: var(--muted);
}

.message-template-card-meta-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 10px;
}

.message-template-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

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

.template-tag {
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 11px;
  font-weight: 650;
}

.message-template-toggle {
  display: flex;
  min-height: 44px;
  align-items: center;
  flex: 0 0 auto;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.message-template-toggle-expanded {
  display: none;
}

.message-template-card[open] .message-template-toggle-collapsed,
.message-template-card[open] .message-template-preview {
  display: none;
}

.message-template-card[open] .message-template-toggle-expanded {
  display: inline;
}

.message-template-card[open] > summary {
  min-height: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.message-template-card-content {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.message-template-card textarea {
  min-height: 150px;
}

.message-template-readonly {
  display: grid;
  gap: 12px;
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}

.message-template-readonly p {
  margin: 0;
  color: var(--ink);
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-template-readonly small {
  align-self: end;
  color: var(--muted);
  line-height: 1.45;
}

.message-template-actions {
  margin-top: auto;
  padding-top: 2px;
}

.template-version-history {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.template-version-history > summary {
  min-height: 44px;
  color: var(--primary);
  cursor: pointer;
  font-weight: 700;
}

.template-version-list {
  display: grid;
  gap: 8px;
}

.template-version-row {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-subtle);
}

.template-version-row > span:first-child {
  display: grid;
  min-width: 0;
}

.template-version-row small {
  color: var(--muted);
}

.template-variables {
  display: grid;
  gap: 10px;
  border-color: #bfdbfe;
  background: var(--surface-blue);
}

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

.template-picker {
  gap: 7px;
}

.template-picker select {
  min-height: 44px;
}

.compact-empty {
  min-height: 130px;
}

.message-preview {
  max-width: 420px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-error {
  display: block;
  max-width: 260px;
  margin-top: 6px;
  color: var(--danger);
  line-height: 1.4;
}

.recurring-head {
  margin-top: 38px;
}

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

.weekday-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 17px;
  background: var(--surface-subtle);
}

.weekday-card-head {
  min-height: 44px;
}

.weekday-card-head strong {
  color: var(--ink);
  font-size: 15px;
}

.schedule-disclosure {
  padding: 0;
  overflow: hidden;
}

.schedule-summary {
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  cursor: pointer;
  list-style: none;
  transition: background var(--duration) ease;
}

.schedule-summary::-webkit-details-marker {
  display: none;
}

.schedule-summary:hover {
  background: var(--surface-subtle);
}

.schedule-summary-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.schedule-summary-copy strong {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.3;
}

.schedule-summary-copy small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.schedule-summary-actions,
.schedule-summary-toggle {
  display: flex;
  align-items: center;
}

.schedule-summary-actions {
  flex: 0 0 auto;
  gap: 14px;
}

.schedule-summary-toggle {
  min-height: 44px;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.schedule-summary-toggle-expanded {
  display: none;
}

.schedule-disclosure[open] .schedule-summary-toggle-collapsed {
  display: none;
}

.schedule-disclosure[open] .schedule-summary-toggle-expanded {
  display: inline;
}

.schedule-disclosure[open] > .schedule-summary {
  border-bottom: 1px solid var(--line);
  background: var(--surface-subtle);
}

.schedule-content {
  padding: 22px;
}

.schedule-content > .test-actions {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

@media (max-width: 1200px) {
  .message-schedule-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .emoji-library-toolbar {
    grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1.2fr);
  }

  .emoji-toolbar-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 1023px) {
  .operation-tabs {
    top: 76px;
  }
}

@media (max-width: 900px) {
  .invite-grid,
  .weekday-grid,
  .emoji-upload-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .operation-tabs {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }

  .operation-tabs button {
    flex: 0 0 auto;
    min-width: 120px;
    scroll-snap-align: start;
  }

  .builder-toolbar,
  .channel-main-grid,
  .channel-options,
  .message-schedule-grid,
  .tribe-route-card,
  .bundled-action,
  .emoji-library-toolbar {
    grid-template-columns: 1fr;
  }

  .tribe-route-card .button,
  .bundled-action .button {
    width: 100%;
  }

  .builder-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .builder-actions .button {
    width: 100%;
  }

  .emoji-toolbar-actions {
    grid-column: auto;
    align-items: stretch;
    flex-direction: column;
  }

  .emoji-toolbar-actions .button {
    width: 100%;
    min-height: 44px;
  }

  .emoji-selection-status {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

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

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

  .message-template-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .message-template-actions form,
  .message-template-actions .button {
    width: 100%;
  }

  .message-template-actions .button {
    min-height: 44px;
  }

  .message-template-card-meta small {
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .message-template-card > summary {
    min-height: 154px;
  }

  .message-template-card-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .message-template-card-meta-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .message-template-card-meta-actions .message-template-toggle {
    width: 100%;
    justify-content: flex-end;
  }

  .schedule-summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
  }

  .schedule-summary-copy {
    width: 100%;
  }

  .schedule-summary-actions {
    width: 100%;
    justify-content: space-between;
  }

  .schedule-summary-copy small {
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .schedule-content {
    padding: 16px;
  }
}
