/* ========== OCC Bot — shared app shell ========== */
:root {
    --primary-color: #00838e;
    --primary-dark: #006570;
    --bg-color: #f7f7f8;
    --card-bg: #ffffff;
    --text-color: #333;
    --text-muted: #666;
    --border-color: #e0e0e0;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;

    --app-bar-bg: #ffffff;
    --toolbar-bg: rgba(255, 255, 255, 0.78);
    --radius-card: 12px;
    --radius-pill: 14px;
    --shadow-card: 0 1px 6px rgba(0, 0, 0, 0.05);
    --chat-bubble-size: 56px;
    /* Outer-content max-width used to center the app-bar, page-header and contextual
       toolbar so they align with the per-page .container. Pages with a narrower
       reading column (e.g. knowledge_detail.html) can override this on :root. */
    --shell-content-max: 1400px;
    /* Entity colors — used wherever a card or pill represents one type while
       the page itself is about the other type. document_detail uses
       --knowledge-color on its kref pills / side panel; knowledge_detail uses
       --document-color on its linked-documents cards. */
    --knowledge-color: #6f42c1;
    --knowledge-color-soft: rgba(111, 66, 193, 0.08);
    --document-color: #1e88e5;
    --document-color-soft: rgba(30, 136, 229, 0.08);
}

html, body {
    background: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', -apple-system, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
}

/* ===== App bar ===== */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 60;
    flex-shrink: 0; /* chat.html's flex-column body must not squash the bar */
    background: var(--app-bar-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 9px 0;
    font-size: 13px;
}
.app-bar .app-bar-inner {
    max-width: var(--shell-content-max);
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 18px;
}
.app-bar .brand {
    color: var(--primary-color);
    font-weight: 700;
    text-decoration: none;
    letter-spacing: -0.2px;
    margin-right: 8px;
}
.app-bar .nav { display: flex; gap: 4px; align-items: center; }
.app-bar .nav a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 7px;
    transition: background 120ms, color 120ms;
}
.app-bar .nav a:hover { background: #f0f0f2; color: var(--text-color); }
.app-bar .nav a.is-active {
    color: var(--primary-color);
    font-weight: 500;
    background: rgba(0, 131, 142, 0.08);
}
.app-bar .right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 28px;  /* reserve space so the layout doesn't jump when /auth/me returns */
}
.app-bar .auth-user {
    color: var(--text-muted);
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-bar .auth-logout {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 7px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
    transition: background 120ms, color 120ms, border-color 120ms;
}
.app-bar .auth-logout:hover {
    background: #f0f0f2;
    color: var(--text-color);
    border-color: #c8c8cd;
}

/* ===== Page header (per-page hero used by admin pages) ===== */
.page-header {
    max-width: var(--shell-content-max);
    margin: 0 auto;
    padding: 22px 20px 14px;
}
.page-header h1 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.4px;
    line-height: 1.2;
    color: #1a1a1a;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}
.page-header h1 i {
    color: var(--primary-color);
    font-size: 22px;
    width: 28px;
    text-align: center;
}
.page-header .back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 10px;
}
.page-header .back-link:hover { text-decoration: underline; }

/* ===== Contextual toolbar slot ===== */
.dd-toolbar {
    position: sticky;
    /* Sits below the app-bar; shell.js keeps --app-bar-height in sync with
       the bar's real height (it shrinks at <=767px). */
    top: var(--app-bar-height, 42px);
    z-index: 55;
    background: var(--toolbar-bg);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 0;
    min-height: 0;
    flex-shrink: 0; /* chat.html's flex-column body must not squash the toolbar */
}
.dd-toolbar:empty {
    display: none;
}
.dd-toolbar-inner {
    max-width: var(--shell-content-max);
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* ===== Chat bubble + overlay ===== */
.occ-chat-bubble {
    position: fixed;
    bottom: 20px;
    left: 20px;        /* moved to the left — opens the left chat drawer */
    right: auto;
    width: var(--chat-bubble-size);
    height: var(--chat-bubble-size);
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    border: 0;
    cursor: pointer;
    /* Shadow tracks --primary-color via color-mix so pages that override the
       primary (e.g. knowledge_detail.html → purple) get a matching glow
       instead of the default teal. */
    box-shadow: 0 6px 16px color-mix(in srgb, var(--primary-color) 32%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    z-index: 90;
    transition: transform 140ms ease, box-shadow 140ms ease;
}
.occ-chat-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px color-mix(in srgb, var(--primary-color) 40%, transparent);
}
.occ-chat-bubble[hidden] { display: none; }

/* ===== Chat drawer (left overlay) ===== */
.occ-chat-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    opacity: 0;
    visibility: hidden;
    transition: opacity 200ms ease, visibility 200ms ease;
    z-index: 95;
}
.occ-chat-scrim.visible {
    opacity: 1;
    visibility: visible;
}
.occ-chat-drawer {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: clamp(340px, 33vw, 440px);
    max-width: 100vw;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    box-shadow: 6px 0 28px rgba(0, 0, 0, 0.14);
    /* A transform here also makes this the containing block for the chat's own
       position:fixed overlays (settings sidebar, Pasta-CC / clarification modals),
       so they stay inside the drawer instead of covering the whole viewport. */
    transform: translateX(-101%);
    transition: transform 260ms cubic-bezier(0.25, 0.1, 0.25, 1),
                width 260ms cubic-bezier(0.25, 0.1, 0.25, 1);
    z-index: 96;
    display: flex;
    flex-direction: column;
}
.occ-chat-drawer.open { transform: translateX(0); }

/* Expanded ("ecrã inteiro") — grow the drawer to fill the viewport in place
   instead of navigating away, so the live chat instance (and its conversation)
   is preserved. */
.occ-chat-drawer.occ-chat-drawer--expanded {
    width: 100vw;
    border-right: 0;
}

.occ-chat-drawer-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--app-bar-bg);
}
.occ-chat-drawer-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-color);
}
.occ-chat-drawer-title i { color: var(--primary-color); }
.occ-chat-drawer-actions { display: inline-flex; gap: 2px; }
.occ-chat-drawer-btn {
    width: 30px;
    height: 30px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    border-radius: 7px;
    cursor: pointer;
    font-size: 13px;
    transition: background 120ms, color 120ms;
}
.occ-chat-drawer-btn:hover { background: #f0f0f2; color: var(--primary-color); }
.occ-chat-drawer-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    position: relative;
}
.occ-chat-drawer-root {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    position: relative;
}
.occ-chat-drawer-btn.is-active {
    background: rgba(0, 131, 142, 0.10);
    color: var(--primary-color);
}

/* "Conversas" history panel — slides over the chat area inside the drawer.
   List rows reuse the class-based styles from css/history-rail.css. */
.occ-chat-drawer-history {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.25, 0.1, 0.25, 1);
    box-shadow: 6px 0 20px rgba(0, 0, 0, 0.08);
}
.occ-chat-drawer-history.open { transform: translateX(0); }
.occ-chat-drawer-history-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 10px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}
.occ-chat-drawer-history-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

/* Resize handle on the drawer's right edge. */
.occ-chat-drawer-resize {
    position: absolute;
    top: 0;
    right: -4px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 3;
    touch-action: none;
}
.occ-chat-drawer-resize::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 3px;
    width: 3px;
    height: 44px;
    margin-top: -22px;
    border-radius: 3px;
    background: var(--border-color);
    opacity: 0;
    transition: opacity 120ms, background 120ms;
}
.occ-chat-drawer:hover .occ-chat-drawer-resize::after,
.occ-chat-drawer-resize:focus-visible::after,
.occ-chat-drawer.is-resizing .occ-chat-drawer-resize::after {
    opacity: 1;
}
.occ-chat-drawer-resize:hover::after,
.occ-chat-drawer-resize:focus-visible::after,
.occ-chat-drawer.is-resizing .occ-chat-drawer-resize::after {
    background: var(--primary-color);
}
.occ-chat-drawer-resize:focus-visible { outline: none; }
/* No width animation while dragging — it would lag behind the pointer. */
.occ-chat-drawer.is-resizing { transition: transform 260ms cubic-bezier(0.25, 0.1, 0.25, 1); }
.occ-chat-drawer.occ-chat-drawer--expanded .occ-chat-drawer-resize { display: none; }
body.occ-chat-drawer-resizing { user-select: none; cursor: col-resize; }
body.occ-chat-drawer-resizing iframe { pointer-events: none; }

@media (max-width: 767px) {
    .occ-chat-drawer { width: 100vw !important; }
    /* Drawer is already full-width here, so "expand" / resize have no effect — hide them. */
    .occ-chat-drawer-btn[data-act="expand"],
    .occ-chat-drawer-resize { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .occ-chat-drawer,
    .occ-chat-drawer-history { transition: none; }
}

/* ===== Responsive ===== */
@media (max-width: 767px) {
    .app-bar { padding: 8px 0; font-size: 12px; }
    .app-bar .app-bar-inner { padding: 0 14px; gap: 10px; }
    .app-bar .nav { gap: 2px; overflow-x: auto; }
    .app-bar .nav a { padding: 5px 8px; }
    .app-bar .auth-user { max-width: 120px; }
    .dd-toolbar-inner { padding: 0 14px; }
    .page-header { padding: 18px 14px 10px; }
    .page-header h1 { font-size: 20px; }
    .occ-chat-bubble {
        width: 48px;
        height: 48px;
        font-size: 19px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .occ-chat-bubble, .app-bar .nav a { transition: none !important; }
}
