/* Workspace (session iframe pages): Chat With Excel, Smart Editor, Document
   assistant. Light Apple-style chrome on the site design tokens (site.css). */

.workspace {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px); /* below the site header rendered by Layout */
    margin-top: 60px;
    background: var(--surface-alt, #f5f5f7);
    overflow: hidden;
    /* The workspace markup sits outside .app-page, so the type system must be
       applied here (otherwise the browser serif default leaks in). */
    font-family: var(--font-text, -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif);
    color: var(--ink, #1d1d1f);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.workspace-simple { height: 100vh; margin-top: 0; } /* Layout_Simple has no fixed header */

body.ws-page { overflow: hidden; }
body.ws-dragging { cursor: col-resize; user-select: none; }

/* ---------- topbar ---------- */

.ws-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--surface, #fff);
    border-bottom: 1px solid var(--line, #e3e3e8);
    padding: 10px 20px;
    flex-shrink: 0;
}

.ws-topbar-info { display: flex; align-items: center; gap: 12px; min-width: 0; }

.ws-topbar-title {
    font-size: 15px;
    font-weight: 650;
    color: var(--ink, #1d1d1f);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ws-topbar-sub {
    font-size: 12px;
    color: var(--ink-4, #86868b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ws-topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.ws-close {
    border: none;
    background: transparent;
    color: var(--ink-3, #6e6e73);
    font-size: 18px;
    line-height: 1;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
}
.ws-close:hover { background: var(--surface-alt, #f5f5f7); color: var(--ink, #1d1d1f); }

/* ---------- split layout ---------- */

.ws-split { display: flex; flex: 1; min-height: 0; }

.ws-viewer-pane {
    width: 58%;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    background: var(--surface, #fff);
    border-right: 1px solid var(--line, #e3e3e8);
    min-height: 0;
}

.ws-pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--line-soft, #ededf0);
    flex-shrink: 0;
}

.ws-pane-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-4, #86868b);
}

.ws-sheet { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-3, #6e6e73); }
.ws-sheet select {
    font: inherit;
    font-size: 12.5px;
    color: var(--ink, #1d1d1f);
    border: 1px solid var(--line-strong, #d2d2d7);
    border-radius: 8px;
    padding: 5px 8px;
    background: var(--surface, #fff);
    max-width: 180px;
}

.ws-viewer { flex: 1; min-height: 0; position: relative; }
.ws-viewer-error { padding: 24px; font-size: 13.5px; color: var(--ink-3, #6e6e73); }

.ws-resize {
    width: 6px;
    cursor: col-resize;
    flex-shrink: 0;
    background: transparent;
    position: relative;
}
.ws-resize::after {
    content: '';
    position: absolute;
    inset: 0 2px;
    border-radius: 2px;
    background: var(--line, #e3e3e8);
    opacity: 0;
    transition: opacity 0.15s ease;
}
.ws-resize:hover::after, body.ws-dragging .ws-resize::after { opacity: 1; }

/* ---------- chat pane ---------- */

.ws-chat-pane {
    flex: 1;
    min-width: 340px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface-alt, #f5f5f7);
}

.ws-single { display: flex; flex: 1; min-height: 0; justify-content: center; }
.ws-single .ws-chat-pane { max-width: 860px; width: 100%; }

.ws-chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.ws-messages {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.ws-message { display: flex; gap: 10px; max-width: 100%; }
.ws-message-user { justify-content: flex-end; }

.ws-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface, #fff);
    border: 1px solid var(--line, #e3e3e8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ws-bubble { max-width: 86%; min-width: 0; }
.ws-message-user .ws-bubble {
    background: var(--green, #107c41);
    color: #fff;
    border-radius: 16px 16px 4px 16px;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.ws-message-assistant .ws-bubble {
    background: var(--surface, #fff);
    border: 1px solid var(--line, #e3e3e8);
    border-radius: 16px 16px 16px 4px;
    padding: 12px 16px;
    font-size: 13.5px;
    color: var(--ink-2, #424245);
    line-height: 1.62;
    overflow-wrap: break-word;
}

.ws-bubble-content > :first-child { margin-top: 0; }
.ws-bubble-content > :last-child { margin-bottom: 0; }
.ws-bubble-content h1, .ws-bubble-content h2, .ws-bubble-content h3, .ws-bubble-content h4 {
    font-size: 14.5px;
    font-weight: 650;
    color: var(--ink, #1d1d1f);
    margin: 14px 0 6px;
}
.ws-bubble-content table { border-collapse: collapse; margin: 10px 0; font-size: 12.5px; max-width: 100%; display: block; overflow-x: auto; }
.ws-bubble-content th, .ws-bubble-content td { border: 1px solid var(--line, #e3e3e8); padding: 5px 9px; }
.ws-bubble-content th { background: var(--surface-alt, #f5f5f7); font-weight: 600; }
.ws-bubble-content ul, .ws-bubble-content ol { padding-left: 20px; margin: 8px 0; }
.ws-bubble-content code {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 12px;
    background: var(--surface-alt, #f5f5f7);
    border-radius: 5px;
    padding: 1.5px 5px;
}
.ws-bubble-content pre {
    position: relative;
    background: #fbfbfd;
    border: 1px solid var(--line-soft, #ededf0);
    border-radius: 10px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 10px 0;
}
.ws-bubble-content pre code { background: none; padding: 0; font-size: 12px; line-height: 1.6; }

.ws-copy {
    position: absolute;
    top: 7px;
    right: 7px;
    border: 1px solid var(--line, #e3e3e8);
    background: var(--surface, #fff);
    color: var(--ink-3, #6e6e73);
    font-size: 11px;
    font-weight: 600;
    border-radius: 7px;
    padding: 3px 9px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.ws-bubble-content pre:hover .ws-copy { opacity: 1; }

/* welcome bubble extras */
.ws-bubble-content .ws-welcome h3 { margin: 0 0 6px; }
.ws-bubble-content .ws-welcome p { margin: 0 0 10px; color: var(--ink-3, #6e6e73); }
.ws-bubble-content .ws-welcome ul { margin: 0; }

.ws-suggestions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.ws-suggestion {
    text-align: left;
    font: inherit;
    font-size: 13px;
    color: var(--ink-2, #424245);
    background: var(--surface-alt, #f5f5f7);
    border: 1px solid var(--line, #e3e3e8);
    border-radius: 10px;
    padding: 9px 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.ws-suggestion:hover { border-color: var(--green, #107c41); background: var(--green-tint, #f2faf6); }

.ws-summary { margin-top: 10px; }

/* typing indicator */
.ws-typing { display: inline-flex; gap: 4px; vertical-align: middle; }
.ws-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-4, #86868b);
    animation: wsTyping 1.2s infinite ease-in-out;
}
.ws-typing i:nth-child(2) { animation-delay: 0.15s; }
.ws-typing i:nth-child(3) { animation-delay: 0.3s; }
.ws-typing-text { margin-left: 8px; font-size: 12.5px; color: var(--ink-4, #86868b); }
@keyframes wsTyping {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
    40% { transform: translateY(-3px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .ws-typing i { animation: none; }
}

/* errors + sources */
.ws-error {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    color: #b42318;
    font-size: 13px;
}
.ws-error p { margin: 0; flex: 1; }
.ws-retry {
    border: 1px solid var(--line-strong, #d2d2d7);
    background: var(--surface, #fff);
    color: var(--ink, #1d1d1f);
    font-size: 12px;
    font-weight: 600;
    border-radius: 980px;
    padding: 4px 14px;
    cursor: pointer;
}
.ws-retry:hover { border-color: var(--green, #107c41); color: var(--green, #107c41); }

.ws-sources { margin-top: 12px; border-top: 1px solid var(--line-soft, #ededf0); padding-top: 10px; }
.ws-sources-title {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-4, #86868b);
    margin-bottom: 6px;
}
.ws-sources a {
    display: block;
    font-size: 12.5px;
    color: var(--green, #107c41);
    text-decoration: none;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ws-sources a:hover { text-decoration: underline; }

/* ---------- input row ---------- */

.ws-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 20px 16px;
    background: var(--surface-alt, #f5f5f7);
    border-top: 1px solid var(--line-soft, #ededf0);
    flex-shrink: 0;
}

.ws-input-row textarea {
    flex: 1;
    resize: none;
    font: inherit;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--ink, #1d1d1f);
    background: var(--surface, #fff);
    border: 1px solid var(--line-strong, #d2d2d7);
    border-radius: 14px;
    padding: 10px 14px;
    max-height: 150px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ws-input-row textarea:focus {
    border-color: var(--green, #107c41);
    box-shadow: 0 0 0 3px rgba(16, 124, 65, 0.12);
}

.ws-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--green, #107c41);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.ws-send:hover { background: var(--green-deep, #0d6a37); }
.ws-send:disabled { opacity: 0.55; cursor: default; }
.ws-send.is-busy svg { animation: wsPulse 1s infinite ease-in-out; }
@keyframes wsPulse { 50% { opacity: 0.4; } }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
    .ws-split { flex-direction: column; }
    .ws-viewer-pane { width: 100% !important; height: 44vh; border-right: none; border-bottom: 1px solid var(--line, #e3e3e8); }
    .ws-resize { display: none; }
    .ws-bubble { max-width: 94%; }
}
