/**
 * Preview panel styles — AionUi measured values: tab bar 36px + 1px bottom
 * border, tabs max-width 180px (padding 0 10, gap 6, 12px title), toolbar
 * 32px (padding 0 10), 32px overflow fades, 40px split-pane headers.
 */

.panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--aion-bg-1);
}

/* ── tab bar ────────────────────────────────────────────────────────────── */

.tabBar {
  position: relative;
  /* Above third-party skin fixed decoration layers (z-index ~20) so the tab
     bar buttons and the close buttons stay clickable (issue #169). Low
     enough to stay below overlays/dialogs (1000+). */
  z-index: 30;
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  height: 36px;
  background: var(--aion-bg-2);
  border-bottom: 1px solid var(--aion-bg-3);
}

.tabScroll {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.tabScroll::-webkit-scrollbar {
  display: none;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  max-width: 180px;
  height: 100%;
  flex-shrink: 0;
  cursor: pointer;
  transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  border-right: 1px solid transparent;
}

.tabActive {
  background: var(--aion-bg-1);
  color: var(--aion-text-primary);
}

.tabInactive {
  color: var(--aion-text-secondary);
}

.tabInactive:hover {
  background: var(--aion-bg-3);
}

.tab:active {
  background: var(--aion-bg-active);
}

.tab:focus-visible {
  box-shadow: inset 0 0 0 2px var(--aion-primary);
}

.tabTitle {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.tabFavicon {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  object-fit: contain;
}

.tabDot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  flex-shrink: 0;
}

.tabDotDirty {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  flex-shrink: 0;
  background: var(--aion-primary);
}

.tabDotAgent {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  flex-shrink: 0;
  background: var(--aion-success);
  animation: aionui-pulse 1.6s ease-in-out infinite;
}

@keyframes aionui-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.tabClose {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
  color: var(--aion-text-secondary);
  transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.tabClose:hover {
  background: var(--aion-bg-3);
  color: var(--aion-text-primary);
}

.tabClose:active {
  background: var(--aion-bg-active);
}

.tabClose:focus-visible {
  box-shadow: inset 0 0 0 2px var(--aion-primary);
}

.tabPlus {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: 0 4px;
  border-radius: 4px;
  color: var(--aion-text-secondary);
  cursor: pointer;
  align-self: center;
  flex-shrink: 0;
  transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.tabPlus:hover {
  background: var(--aion-bg-3);
  color: var(--aion-text-primary);
}

.tabPlus:active {
  background: var(--aion-bg-active);
}

.tabPlus:focus-visible {
  box-shadow: inset 0 0 0 2px var(--aion-primary);
}

.tabBarRight {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  flex-shrink: 0;
}



.panelCollapse,
.panelMaximize {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  color: var(--aion-text-secondary);
  cursor: pointer;
  transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.panelCollapse:hover,
.panelMaximize:hover {
  background: var(--aion-bg-3);
  color: var(--aion-text-primary);
}

.panelCollapse:active,
.panelMaximize:active {
  background: var(--aion-bg-active);
}

.panelCollapse:focus-visible,
.panelMaximize:focus-visible {
  box-shadow: inset 0 0 0 2px var(--aion-primary);
}

.tabFade {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  pointer-events: none;
  z-index: 2;
}

.tabFadeLeft {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  pointer-events: none;
  z-index: 2;
  left: 0;
  background: linear-gradient(90deg, var(--aion-bg-2) 0%, transparent 100%);
}

.tabFadeRight {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  pointer-events: none;
  z-index: 2;
  right: 0;
  background: linear-gradient(270deg, var(--aion-bg-2) 0%, transparent 100%);
}

.noTabs {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 0 10px;
  font-size: 12px;
  color: var(--aion-text-tertiary);
}

/* ── toolbar ────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 32px;
  padding: 0 10px;
  flex-shrink: 0;
  background: var(--aion-bg-2);
  border-bottom: 1px solid var(--aion-bg-3);
  overflow-x: auto;
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.toolbarSpacer {
  flex: 1;
}

.toolbarBtn {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--aion-text-secondary);
  font-size: 12px;
  font-family: var(--aion-font-sans);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1), color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbarBtn:hover {
  background: var(--aion-bg-3);
  color: var(--aion-text-primary);
}

.toolbarBtn:active {
  background: var(--aion-bg-active);
  color: var(--aion-text-primary);
}

.toolbarBtn:focus-visible {
  outline: 2px solid var(--aion-primary);
  outline-offset: 2px;
}

.toolbarBtn:disabled {
  opacity: 0.4;
  cursor: default;
}

.toolbarBtn:disabled:hover {
  background: transparent;
  color: var(--aion-text-secondary);
}

.toolbarBtnActive {
  color: var(--aion-brand);
  background: var(--aion-aou-2);
  border-bottom: 4px solid var(--aion-brand);
}

.toolbarBtnWarn {
  color: var(--aion-warning);
}

/* ── content region ─────────────────────────────────────────────────────── */

.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Markdown viewer. */
.mdViewer {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px 32px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--aion-text-primary);
  word-wrap: break-word;
}

.mdViewer h1 {
  font-size: 24px;
  font-weight: 600;
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--aion-bg-3);
  line-height: 1.3;
}

.mdViewer h1:first-child {
  margin-top: 4px;
}

.mdViewer h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 22px 0 10px;
  line-height: 1.3;
}

.mdViewer h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 18px 0 8px;
  line-height: 1.3;
}

.mdViewer h4,
.mdViewer h5,
.mdViewer h6 {
  font-size: 15px;
  font-weight: 600;
  margin: 14px 0 6px;
  line-height: 1.3;
}

.mdViewer p {
  margin: 8px 0;
}

.mdViewer ul,
.mdViewer ol {
  margin: 8px 0;
  padding-left: 24px;
}

.mdViewer li {
  margin: 3px 0;
}

.mdViewer code {
  font-family: var(--aion-font-mono);
  font-size: 0.9em;
  background: var(--aion-bg-2);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--aion-text-primary);
}

.mdViewer pre {
  margin: 10px 0;
  padding: 12px 14px;
  background: var(--aion-bg-2);
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.5;
}

.mdViewer pre code {
  background: transparent;
  padding: 0;
  font-size: 13px;
  color: var(--aion-text-primary);
}

/* ── mermaid diagrams ──────────────────────────────────────────────────── */

/* Container that replaces a claimed ```mermaid code block; the hidden <pre>
   stays as the fallback source. Wide diagrams scroll inside the panel. */
.mermaidBlock {
  margin: 10px 0;
  padding: 12px 14px;
  background: var(--aion-bg-2);
  border: 1px solid var(--aion-bg-3);
  border-radius: 6px;
  overflow-x: auto;
  text-align: center;
}

.mermaidBlock svg {
  max-width: 100%;
  height: auto;
}

/* Render-in-progress placeholder pulse before the SVG lands. */
.mermaidBlock[data-mermaid-state='pending'],
.mermaidBlock[data-mermaid-state='rendering'] {
  min-height: 40px;
  opacity: 0.6;
}

.mdViewer blockquote {
  margin: 10px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--aion-bg-3);
  color: var(--aion-text-secondary);
}

.mdViewer blockquote p {
  margin: 4px 0;
}

.mdViewer a {
  color: var(--aion-primary);
  text-decoration: none;
}

.mdViewer a:hover {
  text-decoration: underline;
}

.mdViewer hr {
  border: none;
  border-top: 1px solid var(--aion-bg-3);
  margin: 20px 0;
}

.mdViewer table {
  border-collapse: collapse;
  margin: 10px 0;
  width: 100%;
  font-size: 14px;
}

.mdViewer th,
.mdViewer td {
  border: 1px solid var(--aion-bg-3);
  padding: 6px 10px;
  text-align: left;
}

.mdViewer th {
  background: var(--aion-bg-2);
  font-weight: 600;
}

.mdViewer img {
  max-width: 100%;
  border-radius: 4px;
}

/* Code viewer (CodeBlock draws its own frame/padding). */
.codeViewer {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0;
}

/* Diff viewer. */
.diffViewer {
  flex: 1;
  min-height: 0;
  overflow: auto;
  font-family: var(--aion-font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  padding: 4px 0 16px;
}

.diffLine {
  display: flex;
  white-space: pre;
  padding: 0 12px;
  min-height: 20px;
}

.diffLineAdd {
  background: color-mix(in srgb, var(--aion-success) 12%, transparent);
  color: var(--aion-text-primary);
}

.diffLineDel {
  background: color-mix(in srgb, var(--aion-danger) 12%, transparent);
  color: var(--aion-text-primary);
}

.diffLineHunk {
  background: color-mix(in srgb, var(--aion-primary) 10%, transparent);
  color: var(--aion-text-secondary);
}

.diffLineMeta {
  color: var(--aion-text-tertiary);
}

/* CSV table. */
.csvViewer {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.csvTable {
  border-collapse: collapse;
  font-size: 13px;
  font-family: var(--aion-font-mono);
}

.csvTable th,
.csvTable td {
  border: 1px solid var(--aion-bg-3);
  padding: 4px 10px;
  white-space: nowrap;
  max-width: 480px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.csvTable th {
  background: var(--aion-bg-2);
  font-weight: 600;
  position: sticky;
  top: 0;
}

/* Image viewer. */
.imageViewer {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 16px;
  background: var(--aion-bg-base);
}

.imageViewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 2px;
}

.imageMeta {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--aion-text-tertiary);
  background: var(--aion-bg-2);
  border-radius: 9999px;
  padding: 2px 10px;
}

/* PDF viewer. */
.pdfViewer {
  flex: 1;
  min-height: 0;
  border: none;
  background: var(--aion-bg-base);
}

/* URL viewer. */
.urlBar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  flex-shrink: 0;
  background: var(--aion-bg-2);
  border-bottom: 1px solid var(--aion-bg-3);
}

.urlInput {
  flex: 1;
  min-width: 0;
  height: 24px;
  border: none;
  outline: none;
  background: var(--aion-bg-base);
  color: var(--aion-text-primary);
  font-size: 12px;
  border-radius: 4px;
  padding: 0 8px;
  font-family: var(--aion-font-sans);
}

.urlInput:focus-visible {
  box-shadow: inset 0 0 0 2px var(--aion-primary);
}

.urlFrame {
  flex: 1;
  min-height: 0;
  border: none;
  background: var(--aion-bg-base);
  width: 100%;
}

/* Unsupported / error placeholders. */
.placeholder {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--aion-text-secondary);
  font-size: 13px;
  padding: 24px;
  text-align: center;
}

.placeholderTitle {
  font-size: 14px;
  font-weight: 500;
  color: var(--aion-text-primary);
}

.placeholderMeta {
  font-size: 12px;
  color: var(--aion-text-tertiary);
}

.placeholderError {
  color: var(--aion-danger);
  font-size: 12px;
}

/* Split screen: editor | preview. */
.splitPane {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

.splitPaneLeft {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.splitPaneRight {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.splitHeader {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  flex-shrink: 0;
  background: var(--aion-bg-2);
  font-size: 12px;
  color: var(--aion-text-secondary);
  border-bottom: 1px solid var(--aion-bg-3);
}

.splitBody {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* The split drag handle (React-rendered). */
.splitHandle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
  z-index: 20;
  cursor: col-resize;
  touch-action: none;
}

.splitHandle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  border-radius: 9999px;
  background: var(--aion-bg-3);
  opacity: 0.9;
  transition: width 0.15s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.splitHandle:hover::after,
.splitHandle:active::after {
  width: 6px;
  background: var(--aion-brand);
}

/* Text editor (textarea-based, syntax-free but fast). */
.textEditor {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  background: var(--aion-bg-base);
  color: var(--aion-text-primary);
  font-family: var(--aion-font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 12px 14px;
  tab-size: 2;
}

.textEditor:focus-visible {
  box-shadow: inset 0 0 0 2px var(--aion-primary);
}

/* Save-state banner. */
.saveBanner {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 5;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--aion-bg-2);
  border: 1px solid var(--aion-bg-3);
  color: var(--aion-text-secondary);
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saveBannerError {
  color: var(--aion-danger);
  border-color: var(--aion-danger);
}

.truncatedNote {
  font-size: 12px;
  color: var(--aion-warning);
  padding: 6px 20px;
  background: color-mix(in srgb, var(--aion-warning) 10%, transparent);
  flex-shrink: 0;
}
