/**
 * RADEXEL Design System - Content Panel (Split-View)
 *
 * Full split-view panel: chat pushes left, panel fills right half.
 * Inspired by Gemini Canvas / ChatGPT Artifacts.
 *
 * Layout flow:
 *   Closed:  [LeftSidebar] [   Content Area (1fr)  ] [RightSidebar]
 *   Open:    [LeftSidebar] [Chat (1fr)] [Panel (1fr)]  (RightSidebar hidden)
 *
 * Features:
 * - Tab bar for multiple documents
 * - Markdown rendering + iframe embed
 * - Drag resize from left edge
 * - Mobile: full-screen overlay
 * - ESC to close
 * - Smooth grid transition
 */

/* ==========================================================================
   Grid Integration — .app-body states
   ========================================================================== */

.app-body.panel-open {
  grid-template-columns: var(--left-sidebar-width) 1fr 1fr 0px;
}

.app-body.panel-open.left-collapsed {
  grid-template-columns: 0px 1fr 1fr 0px;
}

/* Hide right sidebar smoothly when panel is open */
.app-body.panel-open .right-sidebar {
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  border-left: none;
}


/* ==========================================================================
   Panel Container (Grid child, NOT fixed)
   ========================================================================== */

.content-panel {
  display: none;
  flex-direction: column;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  overflow: hidden;
  min-width: 0;
  position: relative;
}

.content-panel--open {
  display: flex;
}


/* ==========================================================================
   Resize Handle
   ========================================================================== */

.content-panel__resize {
  position: absolute;
  top: 0;
  left: -3px;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 2;
  transition: background 0.15s;
}

.content-panel__resize:hover,
.content-panel__resize:active {
  background: var(--color-primary, #2C5CA3);
  opacity: 0.3;
}


/* ==========================================================================
   Header (Tabs + Actions)
   ========================================================================== */

.content-panel__header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  padding: 0 var(--space-2, 8px) 0 0;
  border-bottom: 1px solid var(--color-border-light, #e5e7eb);
  flex-shrink: 0;
  min-height: 44px;
  background: var(--color-surface);
}


/* Tab Bar */
.content-panel__tab-bar {
  display: flex;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.content-panel__tab-bar::-webkit-scrollbar {
  display: none;
}

.content-panel__tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--color-text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.content-panel__tab:hover {
  color: var(--color-text);
  background: var(--color-surface-hover, rgba(0,0,0,0.03));
}

.content-panel__tab--active {
  color: var(--color-primary, #2C5CA3);
  border-bottom-color: var(--color-primary, #2C5CA3);
  font-weight: 600;
}

.content-panel__tab-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.content-panel__tab-title {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-panel__tab-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 15px;
  color: var(--color-text-muted);
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  margin-left: 2px;
}

.content-panel__tab-x:hover {
  background: var(--color-danger-light, #fee2e2);
  color: var(--color-danger, #ef4444);
}


/* Header Actions */
.content-panel__actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.content-panel__action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md, 6px);
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.content-panel__action-btn:hover {
  background: var(--color-surface-hover, rgba(0,0,0,0.05));
  color: var(--color-text);
}

.content-panel__close-btn:hover {
  background: var(--color-danger-light, #fee2e2);
  color: var(--color-danger, #ef4444);
}


/* ==========================================================================
   Body (Content)
   ========================================================================== */

.content-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5, 20px);
}

.content-panel__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm, 14px);
}


/* Rendered Markdown */
.content-panel__rendered {
  font-size: var(--font-size-base, 15px);
  line-height: var(--line-height-relaxed, 1.7);
  color: var(--color-text);
}

.content-panel__rendered h1 {
  font-size: 1.5em;
  font-weight: 700;
  margin: 0 0 0.6em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--color-border-light, #e5e7eb);
}

.content-panel__rendered h2 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 1em 0 0.5em;
}

.content-panel__rendered h3 {
  font-size: 1.1em;
  font-weight: 600;
  margin: 1em 0 0.4em;
}

.content-panel__rendered p {
  margin: 0 0 0.75em;
}

.content-panel__rendered ul,
.content-panel__rendered ol {
  padding-left: 1.5em;
  margin: 0 0 0.75em;
}

.content-panel__rendered li {
  margin-bottom: 0.25em;
}

.content-panel__rendered ul li { list-style: disc; }
.content-panel__rendered ol li { list-style: decimal; }

.content-panel__rendered blockquote {
  margin: 0.5em 0;
  padding: 0.5em 1em;
  border-left: 3px solid var(--color-primary, #2C5CA3);
  background: var(--color-bg-secondary, #f8f9fa);
  color: var(--color-text-secondary);
  border-radius: 0 var(--radius-sm, 4px) var(--radius-sm, 4px) 0;
}

.content-panel__rendered code:not(pre code) {
  padding: 0.15em 0.35em;
  font-size: 0.9em;
  background: var(--color-bg-tertiary, #f0f0f0);
  border-radius: var(--radius-sm, 4px);
  font-family: var(--font-mono, monospace);
}

.content-panel__rendered pre {
  margin: 0.5em 0;
  padding: var(--space-4, 16px);
  background: #1E1E2E;
  color: #CDD6F4;
  border-radius: var(--radius-md, 8px);
  font-family: var(--font-mono, monospace);
  font-size: var(--font-size-sm, 13px);
  line-height: 1.6;
  overflow-x: auto;
}

.content-panel__rendered pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.content-panel__rendered table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.9em;
}

.content-panel__rendered th,
.content-panel__rendered td {
  padding: 0.5em 0.75em;
  border: 1px solid var(--color-border, #d1d5db);
  text-align: left;
}

.content-panel__rendered th {
  background: var(--color-bg-secondary, #f8f9fa);
  font-weight: 600;
}

.content-panel__rendered img {
  max-width: 100%;
  border-radius: var(--radius-md, 8px);
}

.content-panel__rendered hr {
  border: none;
  border-top: 1px solid var(--color-border-light, #e5e7eb);
  margin: 1em 0;
}

.content-panel__rendered a {
  color: var(--color-primary, #2C5CA3);
  text-decoration: none;
}

.content-panel__rendered a:hover {
  text-decoration: underline;
}

.content-panel__pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: var(--space-4, 16px);
  background: var(--color-bg-secondary, #f8f9fa);
  border-radius: var(--radius-md, 8px);
  font-family: var(--font-mono, monospace);
  font-size: var(--font-size-sm, 13px);
  line-height: 1.6;
  color: var(--color-text);
}


/* ==========================================================================
   Tool Card Open Button (integrated into chat.css cards)
   ========================================================================== */

.tool-card__open-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--color-primary, #2C5CA3);
  background: color-mix(in srgb, var(--color-primary, #2C5CA3) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-primary, #2C5CA3) 20%, transparent);
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.tool-card__open-btn:hover {
  background: color-mix(in srgb, var(--color-primary, #2C5CA3) 15%, transparent);
  border-color: color-mix(in srgb, var(--color-primary, #2C5CA3) 35%, transparent);
}

.tool-card__open-btn svg {
  width: 12px;
  height: 12px;
}


/* ==========================================================================
   Iframe Embed Mode
   ========================================================================== */

.content-panel__body--embed {
  padding: 0;
  overflow: hidden;
}

.content-panel__iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--color-surface);
}


/* ==========================================================================
   Dark Mode
   ========================================================================== */

[data-theme="dark"] .content-panel {
  background: var(--color-surface);
  border-color: var(--color-border);
}

[data-theme="dark"] .content-panel__header {
  background: var(--color-surface);
  border-color: var(--color-border);
}

[data-theme="dark"] .content-panel__tab:hover {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .content-panel__rendered blockquote {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .content-panel__rendered th {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .content-panel__pre {
  background: rgba(255, 255, 255, 0.05);
}


/* ==========================================================================
   Mobile (Full-screen Overlay)
   ========================================================================== */

@media (max-width: 1024px) {
  /* On mobile, panel becomes a full-screen overlay instead of grid split */
  .content-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-modal, 100);
    border-left: none;
  }

  .content-panel--open {
    display: flex;
  }

  .content-panel__resize {
    display: none;
  }

  /* Reset grid — don't split on mobile */
  .app-body.panel-open {
    grid-template-columns: var(--left-sidebar-width) 1fr var(--right-sidebar-width);
  }
  .app-body.panel-open.left-collapsed {
    grid-template-columns: 0px 1fr var(--right-sidebar-width);
  }
  .app-body.panel-open .right-sidebar {
    opacity: 1;
    pointer-events: auto;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .content-panel__body {
    padding: var(--space-3, 12px);
  }

  .content-panel__rendered {
    font-size: var(--font-size-sm, 14px);
  }
}
