* {
  box-sizing: border-box;
}

/* Utility class for hiding elements */
.hidden {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

.banner {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 1.5rem 2rem;
  text-align: center;
}

.banner h1 {
  margin: 0 0 0.5rem 0;
  font-size: 1.8rem;
}

.banner-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.engine-status {
  font-size: 0.85rem;
  color: #94a3b8;
  padding: 0.35rem 0.75rem;
  background: #0f172a;
  border-radius: 6px;
  border: 1px solid #475569;
}

.cache-toggle {
  padding: 0.5rem 1rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s;
}

.cache-toggle:hover:not(:disabled) {
  background: #2563eb;
}

.cache-toggle:disabled {
  background: #475569;
  cursor: not-allowed;
  opacity: 0.6;
}

.diagnostics-toggle {
  padding: 0.5rem 1rem;
  background: #64748b;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s;
}

.diagnostics-toggle:hover {
  background: #475569;
}

/* Diagnostics Panel Modal */
.diagnostics-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.95);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.diagnostics-panel.hidden {
  display: none;
}

.diagnostics-content {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.3);
}

.diagnostics-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid #334155;
  background: #0f172a;
}

.diagnostics-header h3 {
  margin: 0;
  font-size: 1.3rem;
}

.diagnostics-body {
  padding: 1.5rem;
}

.diagnostics-body section {
  margin-bottom: 2rem;
}

.diagnostics-body section:last-child {
  margin-bottom: 0;
}

.diagnostics-body h4 {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  color: #3b82f6;
}

.diagnostics-body dl {
  margin: 0;
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 0.75rem;
}

.diagnostics-body dt {
  font-weight: 600;
  color: #94a3b8;
}

.diagnostics-body dd {
  margin: 0;
  color: #e2e8f0;
  word-break: break-all;
}

.diagnostics-button {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s;
}

.diagnostics-button:hover {
  background: #2563eb;
}

.diagnostics-button:disabled {
  background: #475569;
  cursor: not-allowed;
  opacity: 0.6;
}

.danger-button {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: #dc2626;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s;
}

.danger-button:hover {
  background: #b91c1c;
}

.danger-button:disabled {
  background: #475569;
  cursor: not-allowed;
  opacity: 0.6;
}

main {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.panels {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-bottom: 2rem;
}

.panel {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 12px 20px rgba(15, 23, 42, 0.25);
}

.panel h2 {
  margin-top: 0;
  font-size: 1.3rem;
  border-bottom: 1px solid #334155;
  padding-bottom: 0.5rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.panel-header h2 {
  border: none;
  padding-bottom: 0;
}

.search {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.search input {
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e2e8f0;
}

.search input:focus {
  outline: 2px solid #3b82f6;
}

.panel ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.panel li {
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.panel li:last-child {
  border-bottom: none;
}

.panel dl {
  margin: 0;
}

.panel dt {
  font-weight: 600;
  margin-top: 0.5rem;
}

.panel dd {
  margin: 0;
  color: #94a3b8;
}

.notice {
  background: rgba(59, 130, 246, 0.12);
  border-left: 3px solid #3b82f6;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.code-block {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 1rem;
  color: #cbd5f5;
  overflow-x: auto;
}

footer {
  text-align: center;
  padding: 1rem;
  border-top: 1px solid #334155;
  color: #94a3b8;
}
.meta-line {
  color: #94a3b8;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1rem;
}

.message-list li {
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 1rem;
  background: #0f172a;
}

.message-list h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.1rem;
}

.message-meta-line {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-bottom: 0.5rem;
}

.message-snippet {
  white-space: pre-line;
  line-height: 1.4;
}

/* Three-Pane Viewer Layout */
.three-pane-viewer {
  display: grid;
  grid-template-columns: 250px 1fr 1fr;
  gap: 1rem;
  margin: 2rem 0;
  height: 600px;
}

.thread-pane,
.message-pane,
.detail-pane {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-header {
  padding: 1rem;
  border-bottom: 1px solid #334155;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pane-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.pane-header input {
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 0.9rem;
}

.pane-header input:focus {
  outline: 2px solid #3b82f6;
}

.thread-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}

/* Clusterize virtual scrolling containers */
.clusterize-scroll {
  flex: 1;
  overflow-y: auto;
  /* Override vendor CSS default of max-height: 400px */
  max-height: none !important;
}

/* Higher specificity to override .message-pane .message-list (0,2,0) and .thread-list (0,1,0) */
.clusterize-scroll .thread-list.clusterize-content,
.clusterize-scroll .message-list.clusterize-content {
  list-style: none;
  padding: 0;
  margin: 0;
  /* Override list overflow/flex when inside Clusterize wrapper */
  overflow-y: visible !important;
  flex: none !important;
}

/* Reset styles for Clusterize spacing rows to prevent height calculation issues */
.clusterize-extra-row {
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  cursor: default !important;
}

.clusterize-extra-row:hover {
  background: transparent !important;
}

.thread-list li {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #334155;
  cursor: pointer;
  transition: background 0.15s;
}

.thread-list li:hover {
  background: #0f172a;
}

.thread-list li.active {
  background: #1e3a5f;
  border-left: 3px solid #3b82f6;
}

.message-pane {
  display: flex;
  flex-direction: column;
}

.message-pane .message-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.detail-pane .pane-header {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.clear-button {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.clear-button:hover {
  background: #334155;
  color: #e2e8f0;
}

.message-detail {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.message-detail .placeholder {
  color: #94a3b8;
  text-align: center;
  padding: 2rem;
}

@media (max-width: 1024px) {
  .three-pane-viewer {
    grid-template-columns: 200px 1fr;
    height: 500px;
  }

  .detail-pane {
    grid-column: 1 / -1;
    height: 400px;
  }
}

@media (max-width: 768px) {
  .three-pane-viewer {
    grid-template-columns: 1fr;
    height: auto;
  }

  .thread-pane,
  .message-pane,
  .detail-pane {
    height: 400px;
  }
}

/* Skeleton Loading Screens */
.skeleton {
  background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: 4px;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1rem;
  margin: 0.5rem 0;
}

.skeleton-text.short {
  width: 60%;
}

.skeleton-text.medium {
  width: 80%;
}

.skeleton-text.long {
  width: 100%;
}

.skeleton-heading {
  height: 1.5rem;
  width: 50%;
  margin: 1rem 0;
}

.skeleton-list-item {
  height: 3rem;
  margin: 0.5rem 0;
  border-radius: 8px;
}

.skeleton-panel {
  padding: 1rem;
}

.loading-state {
  display: block;
}

.loading-state.hidden {
  display: none;
}

/* Warning Banner for Cross-Origin Isolation */
.warning-banner {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #78350f;
  padding: 1.5rem;
  margin: 1rem 0;
  border-radius: 8px;
  border-left: 4px solid #92400e;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

.warning-banner strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: #78350f;
}

.warning-banner p {
  margin: 0.5rem 0;
  color: #92400e;
  line-height: 1.6;
}

.warning-banner details {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

.warning-banner summary {
  cursor: pointer;
  font-weight: 600;
  color: #78350f;
  user-select: none;
}

.warning-banner summary:hover {
  text-decoration: underline;
}

.warning-banner ul {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
  color: #92400e;
}

.warning-banner li {
  margin: 0.5rem 0;
  line-height: 1.6;
}

.warning-banner code {
  background: rgba(0, 0, 0, 0.1);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9em;
  color: #78350f;
  font-weight: 600;
}
