.insight-inbox-page {
  --insight-panel-width: 328px;
  --insight-card-bg: var(--bg-secondary);
  display: flex;
  height: calc(100% + 48px);
  margin: -24px;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.insight-inbox-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 12px;
}

.insight-inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 2px 10px;
  border-bottom: 1px solid var(--border-color);
}

.insight-inbox-title-block {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.insight-inbox-title-line {
  display: flex;
  align-items: center;
  gap: 10px;

  h2 {
    margin: 0;
    font-size: 21px;
    font-weight: 700;
    color: var(--text-primary);
  }
}

.insight-inbox-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
}

.insight-inbox-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-secondary);

  span + span::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 3px;
    margin-right: 10px;
    border-radius: 50%;
    background: var(--text-tertiary);
    vertical-align: middle;
  }
}

.insight-icon-btn,
.insight-action-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;

  &:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
  }
}

.insight-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.insight-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;

  &.code {
    color: var(--primary);
  }
}

.spinning {
  animation: insight-spin 0.9s linear infinite;
}

@keyframes insight-spin {
  to {
    transform: rotate(360deg);
  }
}

.insight-focus-bar {
  margin: 10px 2px 0;
  padding: 8px 10px;
  border: 1px solid rgba(91, 147, 144, 0.22);
  border-radius: 8px;
  background: rgba(91, 147, 144, 0.08);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;

  button {
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    font-size: 13px;
  }
}

.insight-record-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 2px 18px;
}

.insight-date-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.insight-date-label {
  position: sticky;
  top: 0;
  z-index: 1;
  width: fit-content;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-tertiary);
  font-size: 12px;
}

.insight-card {
  display: flex;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--insight-card-bg);
  box-shadow: none;
  transition: border-color 0.15s ease, background 0.15s ease;

  &:hover {
    border-color: rgba(91, 147, 144, 0.28);
    background: color-mix(in srgb, var(--bg-secondary) 86%, var(--bg-primary));
  }

  &.unread {
    border-left: 4px solid var(--primary);
  }

  &.focused {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px rgba(91, 147, 144, 0.28);
  }
}

.insight-card-avatar {
  flex: 0 0 auto;
}

.insight-card-content {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.insight-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.insight-recipient {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.insight-recipient-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.insight-recipient-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.insight-session-id {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-tertiary);
}

.insight-card-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.insight-trigger-pill {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;

  &.silence {
    color: #8a5a00;
    background: rgba(245, 158, 11, 0.14);
  }

  &.test {
    color: #5b55a0;
    background: rgba(99, 102, 241, 0.12);
  }
}

.insight-time {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.insight-body {
  margin: 0;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.66;
  white-space: pre-wrap;
  word-break: break-word;
}

.insight-filter-panel {
  width: var(--insight-panel-width);
  flex-shrink: 0;
  padding: 18px 18px 14px;
  border-left: 1px solid var(--border-color);
  background: var(--bg-secondary);
  overflow-y: auto;
}

.insight-filter-header {
  margin-bottom: 14px;

  h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
  }
}

.insight-filter-widget {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  padding: 12px;
  margin-bottom: 12px;
}

.insight-widget-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

.insight-widget-count {
  margin-left: auto;
  color: var(--text-tertiary);
  font-weight: 500;
}

.insight-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  padding: 0 9px;

  input {
    min-width: 0;
    flex: 1;
    height: 34px;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
  }

  button {
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: inline-flex;
    padding: 3px;
  }
}

.insight-date-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;

  button {
    height: 34px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;

    &.active {
      border-color: var(--primary);
      color: var(--primary);
      background: rgba(91, 147, 144, 0.08);
    }
  }
}

.insight-custom-dates {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;

  input {
    height: 34px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 0 10px;
  }
}

.contact-filter {
  display: flex;
  flex-direction: column;
  min-height: 260px;
}

.insight-contact-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 420px;
  overflow-y: auto;
}

.insight-contact-row {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  padding: 7px 8px;
  cursor: pointer;
  text-align: left;

  span {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  strong {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 600;
  }

  &:hover,
  &.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
  }

  &.all {
    margin-top: 10px;
  }
}

.insight-empty-state {
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-tertiary);
  text-align: center;

  strong {
    color: var(--text-primary);
    font-size: 16px;
  }

  button {
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 7px 12px;
    cursor: pointer;
  }
}

.insight-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.insight-log-dialog {
  width: min(860px, 92vw);
  height: min(780px, 84vh);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-secondary);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.14);
  overflow: hidden;
}

.insight-log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-tertiary);

  h3 {
    margin: 0 0 4px;
    font-size: 16px;
  }

  span {
    color: var(--text-secondary);
    font-size: 12px;
  }
}

.insight-log-actions {
  display: flex;
  align-items: center;
  gap: 8px;

  button {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    min-height: 32px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;

    &:hover {
      color: var(--text-primary);
      background: var(--bg-primary);
    }

    &.close {
      width: 32px;
      padding: 0;
      justify-content: center;
    }
  }
}

.insight-log-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-primary);

  section {
    margin-bottom: 18px;
  }

  h4 {
    margin: 0 0 8px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 700;
  }

  pre {
    margin: 0;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    user-select: text;
  }
}

.insight-copy-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 1100;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(30, 30, 30, 0.88);
  color: #fff;
  font-size: 13px;
}

@media (max-width: 980px) {
  .insight-inbox-page {
    flex-direction: column;
  }

  .insight-filter-panel {
    width: auto;
    border-left: none;
    border-top: 1px solid var(--border-color);
    max-height: 42%;
  }

  .insight-card-header,
  .insight-card-actions {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}
