* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef2f7;
  color: #1f2937;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

.topbar,
.detail-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.topbar h1,
.detail-topbar h1 {
  margin: 0;
  font-size: 20px;
}

.topbar {
  align-items: flex-start;
}

.topbar-tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  flex: 1;
}

.tool-group {
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid #dbe3ee;
  border-radius: 10px;
  background: #fff;
}

.tool-group-title {
  font-size: 12px;
  color: #64748b;
  margin-right: 2px;
}

.refresh-meta {
  font-size: 13px;
  color: #334155;
}

.countdown-pill {
  margin-left: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #f8fafc;
  padding: 2px 8px;
  font-size: 12px;
  color: #475569;
}

.refresh-btn {
  border: 0;
  border-radius: 8px;
  background: #0ea5e9;
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}

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

.section-title {
  margin: 0;
  font-size: 16px;
  color: #334155;
}

.mark-all-handled-btn {
  border: 0;
  border-radius: 8px;
  background: #0f766e;
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

.mark-all-handled-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.dashboard {
  margin-bottom: 20px;
  padding: 14px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #dbe3ee;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.status-card {
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
}

.status-card.ok {
  border-color: #86efac;
  background: #f0fdf4;
}

.status-card.down {
  border-color: #fca5a5;
  background: #fef2f2;
}

.status-name {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 4px;
}

.status-value {
  font-size: 15px;
  font-weight: 600;
}

.status-meta {
  margin-top: 6px;
  font-size: 12px;
  color: #64748b;
  word-break: break-all;
}

.status-meta a {
  color: #2563eb;
}

.activity-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.activity-panel {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px;
  background: #f8fafc;
}

.activity-panel h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.activity-table th,
.activity-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 6px 4px;
  text-align: left;
  vertical-align: top;
}

.activity-table th {
  color: #64748b;
  font-weight: 600;
}

.detail-cell {
  max-width: 220px;
  word-break: break-word;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.empty-inline {
  color: #94a3b8;
  font-size: 13px;
  padding: 8px 0;
}

.pending-actions {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  background: #eff6ff;
}

.pending-actions-title {
  font-size: 12px;
  font-weight: 600;
  color: #1d4ed8;
  margin-bottom: 6px;
}

.pending-actions-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pending-actions-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 0;
}

.pending-label {
  font-weight: 600;
  color: #0f172a;
}

.pending-time {
  color: #334155;
}

.pending-note {
  color: #64748b;
}

.archive-search-form {
  width: 100%;
}

.archive-search-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.archive-search-row input {
  min-width: 240px;
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}

.archive-search-row button {
  border: 0;
  border-radius: 8px;
  background: #2f7cf6;
  color: #fff;
  padding: 8px 14px;
  cursor: pointer;
}

.archive-overview-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

.archive-overview-card {
  border-radius: 10px;
  border: 1px solid #dbe3ee;
  background: #f8fafc;
  padding: 10px;
}

.archive-k {
  font-size: 12px;
  color: #64748b;
}

.archive-v {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 700;
}

.archive-warning {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid #fcd34d;
  background: #fffbeb;
  border-radius: 8px;
  color: #92400e;
  font-size: 13px;
}

.archive-panels {
  margin-top: 12px;
}

.archive-overview-grid.compact {
  margin-top: 4px;
}

.archive-inline-links {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.archive-warning-text {
  font-size: 12px;
  color: #b45309;
}

.archive-ok-text {
  font-size: 12px;
  color: #166534;
}

.auto-backfill-status-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.auto-backfill-meta {
  color: #64748b;
  font-size: 12px;
}

.auto-backfill-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.auto-backfill-actions form {
  margin: 0;
}

.auto-backfill-actions button {
  border: 0;
  border-radius: 8px;
  background: #2f7cf6;
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
}

.auto-backfill-actions button.secondary {
  background: #64748b;
}

.auto-backfill-actions button.danger {
  background: #dc2626;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid #cbd5e1;
  color: #334155;
  background: #f8fafc;
}

.status-badge.success {
  border-color: #86efac;
  color: #166534;
  background: #f0fdf4;
}

.status-badge.failed {
  border-color: #fca5a5;
  color: #991b1b;
  background: #fef2f2;
}

.status-badge.running {
  border-color: #93c5fd;
  color: #1d4ed8;
  background: #eff6ff;
}

.status-badge.stopped {
  border-color: #fcd34d;
  color: #92400e;
  background: #fffbeb;
}

.archive-result-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #dbe3ee;
  padding: 14px;
}

.archive-snippet {
  margin-top: 8px;
  color: #334155;
  line-height: 1.5;
  word-break: break-word;
}

.pagination {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.page-current {
  color: #64748b;
  font-size: 13px;
}

.filter-form {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-form input,
.filter-form select {
  width: 320px;
  max-width: 60vw;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.filter-form input[type="date"] {
  width: 170px;
}

.filter-form select {
  width: 130px;
}

.date-sep {
  color: #64748b;
  font-size: 13px;
}

.filter-form button {
  border: 0;
  border-radius: 8px;
  background: #2f7cf6;
  color: #fff;
  padding: 8px 14px;
  cursor: pointer;
}

.action-link {
  display: inline-block;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  text-decoration: none;
  padding: 7px 12px;
  font-size: 13px;
}

.inline-action-form {
  display: inline;
  margin: 0;
}

.danger-link-btn {
  display: inline-block;
  border-radius: 8px;
  border: 1px solid #fecaca;
  background: #fff;
  color: #b91c1c;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}

.danger-link-btn:hover {
  background: #fef2f2;
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
  }

  .topbar-tools {
    width: 100%;
    align-items: stretch;
  }

  .tool-group,
  .filter-form {
    justify-content: flex-start;
  }
}

.note-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.date-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.date-title {
  margin: 4px 2px;
  font-size: 14px;
  color: #475569;
}

.note-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  border: 1px solid #dbe3ee;
}

.note-link {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}

.handled-form {
  flex-shrink: 0;
}

.handled-form button {
  border: 0;
  border-radius: 8px;
  background: #2f7cf6;
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
}

.note-card.handled .handled-form button {
  background: #64748b;
}

.note-card.handled {
  background: #f8fafc;
  border-color: #e2e8f0;
}

.note-card.handled .chat-title,
.meta.handled h1,
.meta.handled div {
  color: #94a3b8;
}

.note-card.handled .line2,
.note-card.handled .time {
  color: #94a3b8;
}

.handled-badge {
  margin-left: 8px;
  font-size: 12px;
  color: #64748b;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 1px 8px;
}

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

.line1 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.line1 .chat-title {
  vertical-align: middle;
}

.line1 .handled-badge {
  vertical-align: middle;
}

.note-card .time {
  margin-left: 10px;
}

.note-card a {
  text-decoration: none;
  color: inherit;
}

.note-card:hover {
  border-color: #9fc1f7;
}

.note-id {
  color: #64748b;
  margin-right: 8px;
}

.chat-title {
  font-weight: 600;
}

.line2 {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: #64748b;
  font-size: 13px;
}

.time {
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
}

.back-link {
  color: #2f7cf6;
  text-decoration: none;
  min-width: 74px;
}

.meta {
  flex: 1;
}

.meta div {
  color: #64748b;
  font-size: 13px;
}

.chat-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 24px;
}

.msg-row {
  display: flex;
}

.msg-row.incoming {
  justify-content: flex-start;
}

.msg-row.outgoing {
  justify-content: flex-end;
}

.msg-bubble {
  max-width: min(78%, 720px);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #dbe3ee;
}

.msg-row.outgoing .msg-bubble {
  background: #dff6d8;
  border-color: #b7e2ad;
}

.msg-bubble.mentioned {
  box-shadow: inset 3px 0 0 #f59e0b;
}

.msg-bubble.target-msg {
  box-shadow: inset 4px 0 0 #16a34a;
  border-color: #86efac;
}

.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  margin-bottom: 6px;
}

.sender {
  font-weight: 600;
}

.msg-id {
  color: #64748b;
}

.reply-preview {
  display: block;
  text-decoration: none;
  color: inherit;
  border-left: 3px solid #7aa7f2;
  background: #f3f7ff;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 8px;
}

.reply-preview.missing {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.reply-sender {
  font-size: 12px;
  color: #2f7cf6;
  font-weight: 600;
}

.reply-text {
  font-size: 13px;
  color: #475569;
  margin-top: 2px;
}

.msg-text {
  white-space: normal;
  line-height: 1.5;
  word-break: break-word;
}

.msg-actions {
  margin-top: 8px;
}

.copy-btn {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.copy-btn:hover {
  border-color: #94a3b8;
}

.msg-time {
  margin-top: 8px;
  text-align: right;
  color: #64748b;
  font-size: 12px;
}

.media-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.media-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.media-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.media-preview-btn {
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  display: inline-block;
}

.media-preview-btn img {
  max-width: 260px;
  max-height: 260px;
  border-radius: 8px;
  border: 1px solid #dbe3ee;
  display: block;
}

.media-preview-btn:hover img {
  border-color: #9fc1f7;
}

.media-video {
  max-width: min(100%, 420px);
  max-height: 280px;
  border-radius: 8px;
  border: 1px solid #dbe3ee;
  background: #000;
}

.media-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.88);
}

.media-viewer.hidden,
.media-viewer .hidden {
  display: none;
}

.media-viewer:not(.hidden) {
  display: flex;
}

.media-viewer-close {
  position: absolute;
  top: 16px;
  right: 20px;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.media-viewer-body {
  max-width: min(96vw, 1080px);
  max-height: 92vh;
}

.media-viewer-body img,
.media-viewer-body video {
  max-width: min(96vw, 1080px);
  max-height: 92vh;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}

.media-viewer-body video {
  background: #000;
}

.copy-media-btn {
  font-size: 11px;
  padding: 3px 8px;
}

.media-link {
  display: inline-block;
  text-decoration: none;
}

.media-link img {
  max-width: 260px;
  max-height: 260px;
  border-radius: 8px;
  border: 1px solid #dbe3ee;
}

.media-link.file {
  color: #2f7cf6;
}

.media-failed {
  font-size: 12px;
  color: #ef4444;
}

.media-cleared {
  font-size: 12px;
  color: #b45309;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.media-cleared a {
  color: #2563eb;
}

.media-cleared-hint {
  color: #64748b;
}

.empty {
  background: #fff;
  border: 1px solid #dbe3ee;
  border-radius: 12px;
  padding: 16px;
  color: #64748b;
}

.cache-hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: #64748b;
  line-height: 1.5;
}

.cache-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #475569;
}

.cache-category-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 12px 0;
}

.cache-check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #334155;
}

.cache-range-meta {
  margin: 0 0 10px;
  font-size: 13px;
  color: #64748b;
}

.cache-detail-list {
  margin-top: 10px;
  font-size: 13px;
  color: #475569;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cache-clean-form {
  margin-top: 14px;
}

.cache-clean-form button.danger {
  border: 0;
  border-radius: 8px;
  background: #dc2626;
  color: #fff;
  padding: 8px 14px;
  cursor: pointer;
}

.cache-banner {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.cache-banner.ok {
  background: #ecfdf5;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.cache-notes {
  margin: 0;
  padding-left: 18px;
  color: #475569;
  font-size: 13px;
  line-height: 1.6;
}

.archive-sub {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}
