/*
 * Desktop workspace for the admin (public/dashboard/js/workspace.js).
 *
 * On a wide screen the admin opens like an installed program: a title bar
 * with menus, the header as a toolbar, the open screens as tabs, the sidebar
 * as an icon rail, a status bar, and only the screen itself scrolls. This is
 * the only layout on a wide screen; phones and narrow windows keep the
 * template as it was. Everything here is scoped to html.ws.
 */

#ws-titlebar, #ws-tabs, #ws-status, #ws-frames { display: none; }

@media (min-width: 992px) {
    html.ws body {
        font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
        background: #eef0f3; overflow: hidden;
        --ws-top: 32px;           /* title bar (+ announcement bar, set by JS) */
        --ws-head: 48px;          /* toolbar */
        --ws-tabs: 31px;
        --ws-status: 24px;
    }

    /* Title bar and menus */
    html.ws #ws-titlebar {
        display: flex; position: fixed; top: 0; left: 0; right: 0; height: 32px; z-index: 1040;
        align-items: center; gap: 2px; padding: 0 8px;
        background: #1f2a44; color: #e2e8f0; font-size: 13px; user-select: none;
    }
    #ws-titlebar .ws-brand { display: inline-flex; align-items: center; gap: 6px; padding: 0 10px 0 2px; font-weight: 600; color: #fff; white-space: nowrap; text-decoration: none; }
    #ws-titlebar .ws-brand img { height: 18px; width: auto; border-radius: 3px; background: #fff; }
    #ws-titlebar .ws-page { margin-left: auto; color: #94a3b8; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
    #ws-menubar { display: flex; align-items: stretch; height: 100%; }
    .ws-mi { position: relative; display: flex; }
    .ws-top { background: none; border: 0; padding: 0 10px; margin: 4px 0; color: #e2e8f0; font-size: 13px; border-radius: 4px; cursor: default; }
    .ws-top:hover, .ws-mi.open > .ws-top, .ws-top:focus-visible { background: rgba(255,255,255,.14); outline: none; }
    .ws-mi.current > .ws-top { color: #7dd3fc; }
    .ws-drop {
        position: absolute; top: calc(100% - 2px); left: 0; min-width: 240px; max-height: calc(100vh - 60px); overflow-y: auto;
        background: #fff; color: #1e293b; border: 1px solid #c5ccd5; border-radius: 6px;
        box-shadow: 0 12px 28px rgba(15,23,42,.22); padding: 4px; display: none; z-index: 1050;
    }
    .ws-mi.open > .ws-drop { display: block; }
    .ws-head { padding: 6px 10px 2px; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #64748b; }
    .ws-head:not(:first-child) { border-top: 1px solid #eef0f3; margin-top: 4px; padding-top: 8px; }
    .ws-link { display: block; padding: 5px 10px 5px 14px; font-size: 13px; border-radius: 4px; color: #1e293b !important; white-space: nowrap; text-decoration: none !important; }
    .ws-link:hover, .ws-link:focus { background: #e0f2fe; color: #0369a1 !important; outline: none; }
    .ws-link.current { font-weight: 600; color: #0369a1 !important; }
    .ws-badge { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 9px; background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; }

    /* The rail shows icons only; an open module's submenu waits for hover. */
    html.ws .pcoded-navbar.navbar-collapsed:not(:hover) .pcoded-submenu { display: none !important; }
    html.ws .pcoded-header .header-profile .dropdown-toggle span { color: #334155 !important; }

    /* The template's fixed parts move down under the title bar. */
    html.ws .site-announcement { top: 32px !important; z-index: 1035 !important; }
    html.ws .pcoded-header { top: var(--ws-top) !important; min-height: var(--ws-head); height: var(--ws-head); }
    html.ws .pcoded-navbar { top: var(--ws-top) !important; height: calc(100vh - var(--ws-top) - var(--ws-status)) !important; }
    html.ws .pcoded-navbar .navbar-wrapper { height: 100%; }

    /* Toolbar (the template's header) */
    html.ws .pcoded-header {
        background: linear-gradient(#fafbfc, #eef1f4) !important; border-bottom: 1px solid #c5ccd5; box-shadow: none !important;
    }
    html.ws .pcoded-header .topbar-title,
    html.ws .pcoded-header .header-clock { display: none !important; }
    html.ws .pcoded-header, html.ws .pcoded-header a,
    html.ws .pcoded-header .header-right > li > a,
    html.ws .pcoded-header .header-right > li > .dropdown-toggle { color: #334155 !important; }
    .ws-tools { display: none; align-items: center; gap: 2px; margin-left: 4px; }
    html.ws .ws-tools { display: inline-flex; }
    .ws-tools button { display: inline-flex; align-items: center; gap: 6px; height: 30px; min-width: 30px; justify-content: center; padding: 0 6px; border-radius: 4px; color: #334155; font-size: 13px; border: 1px solid transparent; background: none; }
    .ws-tools button:hover { background: #fff; border-color: #c5ccd5; }
    .ws-tools .ws-sep { width: 1px; height: 20px; background: #c5ccd5; margin: 0 4px; }
    .ws-tools .ws-go { padding: 0 10px; border-color: #c5ccd5; background: #fff; color: #64748b; min-width: 170px; justify-content: flex-start; }

    /* Tabs and the screen: the only part that scrolls */
    html.ws #ws-tabs {
        display: flex; position: fixed; left: 0; right: 0; top: calc(var(--ws-top) + var(--ws-head)); height: var(--ws-tabs); z-index: 1020;
        align-items: flex-end; gap: 2px; padding: 4px 8px 0;
        background: #e2e6eb; border-bottom: 1px solid #c5ccd5; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
    }
    /* The screen fills exactly the space between the tabs and the status bar.
       The template gives it the old header's padding (with a stronger rule,
       hence the long selector), an announcement margin and a full-window
       minimum height; any of those would push its end under the status bar. */
    html.ws .pcoded-main-container,
    html.ws .pcoded-header.headerpos-fixed ~ .pcoded-main-container {
        position: fixed !important; left: 0; right: 0; top: calc(var(--ws-top) + var(--ws-head) + var(--ws-tabs)); bottom: var(--ws-status);
        height: auto !important; min-height: 0 !important; max-height: none !important;
        margin-top: 0 !important; padding-top: 0 !important; overflow: auto; background: #eef0f3;
    }
    html.ws .pcoded-main-container .pcoded-content { padding: 12px 16px !important; }
    .ws-tab {
        display: inline-flex; align-items: center; gap: 6px; max-width: 210px; flex: none;
        padding: 4px 6px 4px 12px; font-size: 12.5px; color: #475569 !important; text-decoration: none !important;
        background: #edf0f3; border: 1px solid #c5ccd5; border-bottom: none; border-radius: 6px 6px 0 0;
    }
    .ws-tab:hover { background: #f7f8fa; color: #0f172a !important; }
    .ws-tab.active { background: #eef0f3; color: #0f172a !important; font-weight: 600; position: relative; top: 1px; padding-bottom: 5px; box-shadow: inset 0 2px 0 #0ea5e9; }
    .ws-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .ws-tab .ws-x { width: 18px; height: 18px; border: 0; background: none; border-radius: 4px; line-height: 16px; padding: 0; text-align: center; color: #94a3b8; font-size: 15px; flex: none; }
    .ws-tab .ws-x:hover { background: #cbd5e1; color: #0f172a; }
    .ws-tab.pinned { padding-right: 12px; }

    .ws-tab.loading span::before {
        content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 6px; vertical-align: -1px;
        border: 2px solid #94a3b8; border-top-color: transparent; border-radius: 50%; animation: ws-spin .8s linear infinite;
    }

    /* Live tabs: each screen in a frame laid over the screen area (left set by JS) */
    html.ws #ws-frames {
        display: block; visibility: hidden; position: fixed; right: 0; z-index: 1010; background: #eef0f3;
        top: calc(var(--ws-top) + var(--ws-head) + var(--ws-tabs)); bottom: var(--ws-status);
    }
    html.ws #ws-frames.on { visibility: visible; }
    #ws-frames iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #eef0f3; visibility: hidden; }
    html.ws #ws-frames.on iframe.on { visibility: visible; }

    /* Flatter, denser panels */
    html.ws-framed .pcoded-main-container .card,
    html.ws .pcoded-main-container .card { border-radius: 6px; box-shadow: 0 0 0 1px #d6dbe1 !important; border: 0; margin-bottom: 14px; }
    html.ws-framed .pcoded-main-container .card .card-header,
    html.ws .pcoded-main-container .card .card-header { padding: 10px 16px; background: #f8fafc; border-bottom: 1px solid #e2e6eb; }
    html.ws-framed .pcoded-main-container .card .card-block,
    html.ws-framed .pcoded-main-container .card .card-body,
    html.ws .pcoded-main-container .card .card-block,
    html.ws .pcoded-main-container .card .card-body { padding: 14px 16px; }
    html.ws-framed .pcoded-main-container .page-header,
    html.ws .pcoded-main-container .page-header { margin-bottom: 10px; padding: 0; background: none; box-shadow: none; }

    /* Status bar */
    html.ws #ws-status {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--ws-status); z-index: 1030;
        align-items: center; gap: 16px; padding: 0 12px; font-size: 12px; color: #475569;
        background: #e2e6eb; border-top: 1px solid #c5ccd5; user-select: none;
    }
    #ws-status .ws-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #10b981; margin-right: 6px; }
    #ws-status[data-conn="offline"] .ws-dot { background: #dc2626; }
    #ws-status[data-conn="offline"] .ws-conn { color: #b91c1c; font-weight: 600; }
    #ws-status .ws-spacer { margin-left: auto; }
    #ws-status button { background: none; border: 0; padding: 0 6px; border-radius: 3px; color: #475569; font-size: 12px; }
    #ws-status button:hover { background: #d5dbe2; }
    #ws-status kbd { font: 11px ui-monospace, monospace; padding: 0 4px; border: 1px solid #c5ccd5; border-bottom-width: 2px; border-radius: 3px; background: #f8fafc; color: #334155; }
    #ws-status .ws-ask { display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 10px; border-radius: 10px; background: #16293f; color: #fff; font-weight: 600; }
    #ws-status .ws-ask:hover { background: #1f3a58; }
    #ws-status .ws-ask.unread::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; }

    /* "Ask PAX" lives in the status bar here, so nothing floats over the
       screen; its window opens just above the bar. */
    html.ws #pax-chat { bottom: calc(var(--ws-status, 24px) + 8px); }
    html.ws #pax-chat-toggle { display: none !important; }
    html.ws #pax-chat-panel { max-height: calc(100vh - 140px); }
}

@keyframes ws-spin { to { transform: rotate(360deg); } }

/* A screen inside a tab: its content only; the window around it has the rest. */
html.ws-framed .pcoded-navbar, html.ws-framed .pcoded-header, html.ws-framed .site-announcement,
html.ws-framed .loader-bg, html.ws-framed #pax-chat { display: none !important; }
html.ws-framed body { background: #eef0f3; font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
html.ws-framed .pcoded-main-container,
html.ws-framed .pcoded-navbar ~ .pcoded-main-container,
html.ws-framed .pcoded-header ~ .pcoded-main-container,
html.ws-framed .pcoded-header.headerpos-fixed ~ .pcoded-main-container {
    position: static !important; margin: 0 !important; padding: 0 !important; left: 0 !important;
    width: auto !important; min-height: 0 !important; background: #eef0f3;
}
html.ws-framed .pcoded-main-container .pcoded-content { padding: 12px 16px !important; }

/* "Two screens are already open" */
.ws-confirm { width: min(460px, 92vw); margin: auto; padding: 20px 22px 16px; border: 0; border-radius: 10px; box-shadow: 0 24px 60px rgba(0,0,0,.3); color: #1e293b; font-family: "Segoe UI", system-ui, sans-serif; }
.ws-confirm::backdrop { background: rgba(15,23,42,.45); }
.ws-confirm h3 { margin: 0 0 8px; font-size: 16px; font-weight: 700; color: #0f172a; }
.ws-confirm p { margin: 0 0 16px; font-size: 14px; line-height: 1.5; color: #475569; }
.ws-confirm-row { display: flex; justify-content: flex-end; gap: 8px; }
.ws-btn { padding: 7px 14px; border-radius: 6px; border: 1px solid #c5ccd5; background: #fff; color: #334155; font-size: 13px; font-weight: 600; cursor: pointer; }
.ws-btn:hover { background: #f1f5f9; }
.ws-btn.primary { background: #16293f; border-color: #16293f; color: #fff; }
.ws-btn.primary:hover { background: #1f3a58; }
.ws-notice {
    position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 1065; max-width: min(560px, 92vw);
    padding: 9px 14px; border-radius: 8px; background: #16293f; color: #fff; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

/* "Go to…" box (Ctrl+K) */
#ws-palette { position: fixed; inset: 0; z-index: 1060; background: rgba(15,23,42,.45); display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; }
#ws-palette.open { display: flex; }
#ws-palette .ws-pal { width: min(560px, 92vw); background: #fff; border-radius: 10px; box-shadow: 0 24px 60px rgba(0,0,0,.3); overflow: hidden; }
#ws-palette input { width: 100%; border: 0; border-bottom: 1px solid #e2e6eb; padding: 14px 16px; font-size: 15px; outline: none; }
#ws-palette ul { list-style: none; margin: 0; padding: 4px; max-height: 50vh; overflow-y: auto; }
#ws-palette li a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: 6px; color: #1e293b; text-decoration: none; font-size: 14px; }
#ws-palette li a small { color: #94a3b8; }
#ws-palette li a.sel { background: #e0f2fe; color: #0369a1; }
#ws-palette .ws-empty { padding: 14px 16px; color: #94a3b8; font-size: 14px; }

@media print {
    #ws-titlebar, #ws-tabs, #ws-status, #ws-palette, #ws-frames, .ws-notice { display: none !important; }
    html.ws .pcoded-main-container { position: static !important; overflow: visible !important; }
    html.ws body { overflow: visible !important; }
}
