/* ===== Canvas Panel ===== */
/* Side panel for previewing agent-generated artifacts (HTML, code, CSV, etc.) */

.inbox-main.canvas-open {
  flex-direction: row;
}

.canvas-open .inbox-detail {
  flex: 1;
  min-width: 0;
}

.canvas-panel {
  width: 480px;
  max-width: 45%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-subtle);
  height: 100%;
  animation: canvasSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.canvas-panel-hidden {
  display: none !important;
}

@keyframes canvasSlideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Layout: wide — panel takes ~65% */
.canvas-layout-wide .canvas-panel {
  width: 65%;
  max-width: 65%;
}

/* Layout: full — panel takes 100%, chat hidden */
.canvas-layout-full .canvas-panel {
  width: 100%;
  max-width: 100%;
  border-left: none;
}

.canvas-layout-full .inbox-detail {
  display: none;
}

.canvas-fullscreen-btn {
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
}

/* Native browser fullscreen */
.canvas-panel:fullscreen {
  width: 100%;
  max-width: 100%;
  border-left: none;
  border-radius: 0;
}

/* ----- Header ----- */

.canvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.canvas-header-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canvas-header-title svg {
  flex-shrink: 0;
  color: var(--gold-primary);
}

.canvas-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.canvas-layout-toggles {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 2px;
}

.canvas-layout-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.canvas-layout-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* Active layout indicator */
.canvas-layout-side .canvas-layout-btn:nth-child(1),
.canvas-layout-wide .canvas-layout-btn:nth-child(2),
.canvas-layout-full .canvas-layout-btn:nth-child(3) {
  color: var(--gold-primary);
  background: var(--bg-elevated);
}

/* Default (no layout class = side) */
.canvas-open:not(.canvas-layout-wide):not(.canvas-layout-full) .canvas-layout-btn:nth-child(1) {
  color: var(--gold-primary);
  background: var(--bg-elevated);
}

.canvas-close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.canvas-close-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

/* ----- Body ----- */

.canvas-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
}

.canvas-body::-webkit-scrollbar { width: 6px; }
.canvas-body::-webkit-scrollbar-track { background: transparent; }
.canvas-body::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 3px; }

/* ----- Footer ----- */

.canvas-footer {
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.canvas-footer-left,
.canvas-footer-right {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.canvas-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-secondary);
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.canvas-tool-btn:hover {
  border-color: var(--gold-primary);
  color: var(--gold-primary);
}

.canvas-zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 2px;
}

.canvas-zoom-controls .canvas-tool-btn {
  border: none;
  padding: 0.25rem 0.375rem;
  border-radius: 4px;
  background: transparent;
}

.canvas-zoom-level {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 36px;
  text-align: center;
  user-select: none;
}

/* ----- Renderers ----- */

.canvas-iframe {
  width: 100%;
  height: 100%;
  min-height: 400px;
  border: none;
  border-radius: 8px;
  background: #fff;
}

.canvas-svg-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #fff;
  border-radius: 8px;
  min-height: 200px;
}

.canvas-svg-container svg {
  max-width: 100%;
  max-height: 100%;
}

.canvas-code-wrapper {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
}

.canvas-code-lang {
  position: absolute;
  top: 0.5rem;
  left: 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.125rem 0.375rem;
  background: var(--bg-elevated);
  border-radius: 3px;
}

.canvas-code-copy {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  opacity: 0;
}

.canvas-code-wrapper:hover .canvas-code-copy {
  opacity: 1;
}

.canvas-code-copy:hover {
  border-color: var(--gold-primary);
  color: var(--gold-primary);
}

.canvas-code-wrapper pre {
  margin: 0;
  padding: 2.5rem 1rem 1rem;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.canvas-code-wrapper code {
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  color: var(--text-secondary);
}

.canvas-csv-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.canvas-csv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.canvas-csv-table th {
  background: var(--bg-base);
  font-weight: 600;
  color: var(--text-primary);
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.canvas-csv-table td {
  padding: 0.375rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.canvas-csv-table tr:hover td {
  background: color-mix(in srgb, var(--gold-primary) 5%, transparent);
}

.canvas-markdown {
  padding: 0.5rem;
}

.canvas-image-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.canvas-image {
  max-width: 100%;
  max-height: 600px;
  border-radius: 8px;
  object-fit: contain;
}

.canvas-pdf-container {
  height: 100%;
  min-height: 500px;
  display: flex;
  flex-direction: column;
}

.canvas-pdf-embed {
  width: 100%;
  flex: 1;
  min-height: 500px;
  border: none;
  border-radius: 8px;
}

.canvas-pdf-fallback {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
  text-align: center;
  gap: 0.75rem;
}

.canvas-pdf-fallback p {
  margin: 0;
  font-size: 0.875rem;
}

.canvas-pdf-open-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gold-primary);
  background: var(--bg-base);
  border: 1px solid var(--gold-primary);
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.15s ease;
}

.canvas-pdf-open-link:hover {
  background: color-mix(in srgb, var(--gold-primary) 10%, transparent);
}

/* ----- Loading & Fallback ----- */

.canvas-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  height: 100%;
}

.canvas-loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--gold-primary);
  border-radius: 50%;
  animation: canvasSpin 0.6s linear infinite;
}

@keyframes canvasSpin {
  to { transform: rotate(360deg); }
}

.canvas-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  text-align: center;
  gap: 0.75rem;
}

.canvas-fallback p {
  margin: 0;
  font-size: 0.875rem;
}

.canvas-fallback-hint {
  font-size: 0.8125rem;
  opacity: 0.7;
}

/* Canvas overlay — hidden on desktop, visible on tablet/mobile */
.canvas-overlay {
  display: none;
}

/* ----- Artifact Chips ----- */

.artifact-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-top: 0.75rem;
}

.artifact-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-align: left;
  width: 100%;
}

.artifact-chip:hover {
  border-color: var(--gold-primary);
  color: var(--text-primary);
  background: var(--bg-hover);
}

.artifact-chip-icon {
  flex-shrink: 0;
  color: var(--gold-primary);
}

.artifact-chip-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.artifact-chip-size {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.artifact-chip-arrow {
  flex-shrink: 0;
  opacity: 0.5;
  transition: transform 0.15s ease;
}

.artifact-chip:hover .artifact-chip-arrow {
  transform: translateX(2px);
  opacity: 1;
  color: var(--gold-primary);
}

/* ----- Inline Widgets ----- */

.inline-widgets {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.inline-widgets:empty {
  display: none;
}

.inline-widget {
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-base);
}

.inline-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.inline-widget-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.inline-widget-expand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.inline-widget-expand:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.inline-widget-frame {
  display: block;
  width: 100%;
  height: 400px;
  border: none;
  background: var(--bg-base);
}

/* Widget loading skeleton */
.widget-loading-skeleton {
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.widget-loading-bar {
  height: 12px;
  border-radius: 6px;
  background: var(--bg-hover, #e5e7eb);
  animation: widget-shimmer 1.5s ease-in-out infinite;
  width: 100%;
}

.widget-loading-bar-short {
  width: 55%;
  animation-delay: 0.15s;
}

.widget-loading-bar-medium {
  width: 78%;
  animation-delay: 0.3s;
}

.widget-loading-text {
  color: var(--text-secondary);
  font-style: italic;
}

@keyframes widget-shimmer {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ----- Tablet: canvas as slide-over ----- */
@media (max-width: 1279px) and (min-width: 641px) {
  .canvas-layout-toggles { display: none; }

  .canvas-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    width: 480px;
    max-width: 85%;
    z-index: 100;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
  }

  .canvas-open .inbox-detail {
    flex: 1;
  }

  .canvas-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .canvas-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ----- Mobile: canvas full-screen ----- */
@media (max-width: 640px) {
  .canvas-layout-toggles { display: none; }

  .canvas-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    z-index: 100;
    border-left: none;
    border-radius: 0;
  }
}
