/* Agent Fox Client - Split Panel Mode
 * Merged from split-layout.css and post-ai-chat.css
 * ============================================= */

/* =========================================
   CSS Variables
   ========================================= */
:root {
  --split-panel-width: 420px;
  --split-panel-min-width: 250px;
  --split-panel-max-width: 800px;
  --split-divider-width: 6px;
  --split-header-height: 56px;
  --split-admin-bar-height: 0px;
  --split-mobile-height: 50vh;
  --split-transition-duration: 300ms;
  --split-border-color: #e9ecef;
  --split-divider-color: #e9ecef;
  --split-divider-hover-color: #007bff;
  --split-panel-bg: #ffffff;
  --split-shadow: -2px 0 12px rgba(0, 0, 0, 0.08);
}

/* Admin bar compensation */
body.admin-bar {
  --split-admin-bar-height: 32px;
}

@media screen and (max-width: 782px) {
  body.admin-bar {
    --split-admin-bar-height: 46px;
  }
}

/* =========================================
   1. Panel Base Styles
   ========================================= */
.agent-fox-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background: var(--container-bg, #fff);
}

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

/* =========================================
   2. Panel Header
   ========================================= */
.agent-fox-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    min-height: var(--split-header-height, 56px);
    border-bottom: 1px solid #eee;
    background: var(--container-bg, #fff);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.agent-fox-panel__header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color, #333);
    letter-spacing: 0.2px;
}

.agent-fox-panel__close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--muted-text, #6c757d);
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}

.agent-fox-panel__close:hover {
    color: var(--text-color, #333);
    transform: translateX(2px);
}

.agent-fox-panel__close .close-icon--desktop {
    display: block;
}

.agent-fox-panel__close .close-icon--mobile {
    display: none;
}

/* =========================================
   3. Panel Body
   ========================================= */
.agent-fox-panel__body {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.agent-fox-panel .agent-fox-chat-container {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--container-bg, #fff);
}

.agent-fox-panel .agent-fox-messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    background: var(--background-color, #fafafa);
}

/* =========================================
   4. Input Area
   ========================================= */
.agent-fox-panel .agent-fox-input {
    flex-shrink: 0;
    padding: 0.5rem;
    background: var(--container-bg, #fff);
    border-top: 1px solid var(--border-color, #e9ecef);
}

.agent-fox-panel #agent-fox-split-form {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.agent-fox-panel #agent-fox-split-input {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color, #e9ecef);
    border-radius: 12px;
    font-size: 1rem;
    resize: none;
    height: 44px;
    transition: border-color 160ms, box-shadow 160ms;
    background: #ffffff;
}

.agent-fox-panel #agent-fox-split-input::placeholder {
    color: var(--muted-text, #6c757d);
}

.agent-fox-panel #agent-fox-split-input:focus {
    outline: none;
    border-color: var(--primary-color, #007bff);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
}

/* =========================================
   5. Buttons
   ========================================= */
.agent-fox-panel #agent-fox-split-submit {
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background-color 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: var(--primary-color, #007bff);
    color: white;
}

.agent-fox-panel #agent-fox-split-submit:hover:not(:disabled) {
    background: #0056b3;
}

.agent-fox-panel #agent-fox-split-submit:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
    box-shadow: none;
}

.agent-fox-panel #agent-fox-split-stop {
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--error, #dc2626);
    color: white;
}

.agent-fox-panel #agent-fox-split-stop:hover {
    background: #b91c1c;
}

/* =========================================
   6. Desktop Split Layout (CSS Grid)
   ========================================= */
@media screen and (min-width: 769px) {
  .split-layout-wrapper {
    display: grid;
    grid-template-columns: 1fr var(--split-divider-width) var(--split-panel-width);
    grid-template-rows: 1fr;
    min-height: calc(100vh - var(--split-admin-bar-height));
    width: 100%;
    position: relative;
    transition: grid-template-columns var(--split-transition-duration) ease;
  }

  .split-layout-wrapper.split-layout-collapsed {
    grid-template-columns: 1fr 0 0;
  }

  .split-layout-wrapper.split-layout-collapsed .split-divider,
  .split-layout-wrapper.split-layout-collapsed .split-panel-container {
    display: none;
    width: 0;
    overflow: hidden;
  }

  .split-layout-content {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .split-layout-content > * {
    max-width: 100%;
  }

  /* Divider */
  .split-divider {
    grid-column: 2;
    grid-row: 1;
    width: var(--split-divider-width);
    background: var(--split-divider-color);
    cursor: col-resize;
    position: relative;
    transition: background-color 0.2s ease;
    user-select: none;
    touch-action: none;
  }

  .split-divider:hover,
  .split-divider.dragging {
    background: var(--split-divider-hover-color);
  }

  .split-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    background: currentColor;
    opacity: 0.3;
    border-radius: 2px;
    transition: opacity 0.2s;
  }

  .split-divider:hover::before,
  .split-divider.dragging::before {
    opacity: 0.6;
  }

  .split-divider::after {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    right: -8px;
    bottom: 0;
    cursor: col-resize;
  }

  /* Panel container */
  .split-panel-container {
    grid-column: 3;
    grid-row: 1;
    position: sticky;
    top: var(--split-admin-bar-height);
    height: calc(100vh - var(--split-admin-bar-height));
    overflow: hidden;
    background: var(--split-panel-bg);
    box-shadow: var(--split-shadow);
    display: flex;
    flex-direction: column;
  }

  .split-panel-container .agent-fox-panel {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    width: 100% !important;
    height: 100% !important;
    z-index: auto !important;
    box-shadow: none !important;
    transform: none !important;
    display: flex !important;
    flex-direction: column;
  }

  .split-layout-wrapper .agent-fox-backdrop {
    display: none !important;
  }
}

/* =========================================
   7. Mobile Layout
   ========================================= */
@media screen and (max-width: 768px) {
  .split-layout-wrapper {
    display: block;
    width: 100%;
  }

  .split-divider {
    display: none !important;
  }

  .split-panel-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 10%;
    background: var(--split-panel-bg, #fff);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 99999;
    display: none;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }

  body.split-layout-mobile-open .split-panel-container {
    display: flex !important;
    transform: translateY(0);
  }

  .split-panel-container .agent-fox-panel {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    height: 100% !important;
    z-index: auto !important;
    transform: none !important;
    display: flex !important;
    flex-direction: column;
    border-radius: 0;
    box-shadow: none;
  }

  .split-layout-wrapper.split-layout-collapsed .split-panel-container {
    display: none;
  }

  /* Mobile backdrop */
  .agent-fox-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 10%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99998;
  }

  body.split-layout-mobile-open .agent-fox-backdrop {
    display: block !important;
  }

  /* Mobile header adjustments */
  .agent-fox-panel__header {
    padding: 0.75rem 1rem;
  }

  .agent-fox-panel__header h3 {
    font-size: 1rem;
  }

  .agent-fox-panel__close .close-icon--desktop {
    display: none;
  }

  .agent-fox-panel__close .close-icon--mobile {
    display: block;
  }

  .agent-fox-panel__close:hover {
    transform: translateY(2px);
  }

  /* Prevent iOS auto-zoom */
  .agent-fox-panel #agent-fox-split-input {
    font-size: 16px !important;
  }
}

/* =========================================
   8. Drag Resize States
   ========================================= */
body.split-resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

body.split-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

body.split-resizing iframe {
  pointer-events: none !important;
}

.split-layout-wrapper.resizing {
  will-change: grid-template-columns;
}

/* =========================================
   9. Toggle Button (collapsed state)
   ========================================= */
.split-toggle-btn {
  position: fixed;
  right: 16px;
  bottom: 80px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--split-divider-hover-color, #007bff);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background-color 0.2s;
}

.split-toggle-btn:hover {
  transform: scale(1.05);
  background: #0056b3;
}

.split-layout-wrapper:not(.split-layout-collapsed) ~ .split-toggle-btn,
body.split-layout-mobile-open .split-toggle-btn {
  display: none;
}

body:has(.floating-toolbar) .split-toggle-btn {
  display: none;
}

/* =========================================
   10. Animations & Transitions
   ========================================= */
@media (prefers-reduced-motion: reduce) {
  .split-layout-wrapper,
  .split-divider,
  .split-panel-container,
  .split-toggle-btn {
    transition: none !important;
  }
}

.split-panel-container {
  transition: opacity var(--split-transition-duration) ease;
}

.split-layout-collapsed .split-panel-container {
  opacity: 0;
}

/* =========================================
   11. Print Styles
   ========================================= */
@media print {
  .split-layout-wrapper {
    display: block !important;
  }

  .split-divider,
  .split-panel-container,
  .split-toggle-btn,
  .agent-fox-panel,
  .agent-fox-backdrop {
    display: none !important;
  }

  .split-layout-content {
    width: 100% !important;
  }
}

/* =========================================
   12. Floating Toolbar Position Adjustment
   ========================================= */
@media screen and (min-width: 769px) {
  /* Position adjustment - applied immediately without transition on page load */
  .split-layout-wrapper:not(.split-layout-collapsed) ~ .floating-toolbar,
  body:has(.split-layout-wrapper:not(.split-layout-collapsed)) .floating-toolbar {
    right: calc(var(--split-panel-width, 420px) + var(--split-divider-width, 6px) + 30px);
  }

  /* Transition only enabled after page is ready - prevents unwanted animation on navigation */
  body.split-transitions-ready .floating-toolbar {
    transition: right var(--split-transition-duration, 0.3s) ease;
  }
}
