/* 虾觅控制台 — Mem0 Dashboard 风格 + 全端响应式 */
:root {
    --xi-primary: #111827;
    --xi-primary-accent: #6366f1;
    --xi-primary-soft: rgba(99, 102, 241, 0.1);
    --xi-surface: #ffffff;
    --xi-surface-page: #f8fafc;
    --xi-surface-muted: #f1f5f9;
    --xi-on-surface: #0f172a;
    --xi-text-muted: #64748b;
    --xi-outline: #e2e8f0;
    --xi-outline-variant: #e2e8f0;
    --xi-sidebar-w: 260px;
    --xi-sidebar-w-collapsed: 72px;
    --xi-topbar-h: 56px;
    --xi-content-max: none;
    --accent: var(--xi-primary-accent);
    --accent-dim: #4f46e5;
    --accent-hover: #4338ca;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --bg-base: var(--xi-surface-page);
    --bg-surface: #ffffff;
    --bg-elevated: var(--xi-surface-muted);
    --border-subtle: var(--xi-outline);
    --sidebar-w: var(--xi-sidebar-w);
    --top-header-h: var(--xi-topbar-h);
    --content-max: var(--xi-content-max);
}

body.console-body {
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    background: var(--xi-surface-page);
    font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

body.console-body .app-shell.xi-shell {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    width: 100%;
}

/* —— 侧栏（Mem0：浅底 + 左指示条 active） —— */
.xi-sidebar {
    width: var(--xi-sidebar-w);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    background: var(--xi-surface);
    border-right: 1px solid var(--xi-outline);
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow: hidden;
    transition: width 0.22s ease, transform 0.25s ease;
}

.xi-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    text-decoration: none;
    color: var(--xi-on-surface);
    flex-shrink: 0;
    min-height: var(--xi-topbar-h);
    border-bottom: 1px solid var(--xi-outline);
}

.xi-sidebar-brand img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 8px;
}

.xi-sidebar-brand span {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.xi-sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 10px 12px;
    scrollbar-width: thin;
}

.xi-sidebar-scroll::-webkit-scrollbar {
    width: 4px;
}

.xi-sidebar-scroll::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.xi-nav-section {
    padding: 14px 12px 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--xi-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.xi-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 1px 0;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #334155;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    min-height: 40px;
}

.xi-nav-link .material-symbols-outlined {
    font-size: 20px;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: #64748b;
}

.xi-nav-link span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.xi-nav-link:hover {
    background: var(--xi-surface-muted);
    color: var(--xi-on-surface);
}

.xi-nav-link:hover .material-symbols-outlined {
    color: var(--xi-primary-accent);
}

.xi-nav-link.active {
    background: var(--xi-primary-soft);
    color: var(--xi-primary-accent);
    font-weight: 600;
    border-left-color: var(--xi-primary-accent);
}

.xi-nav-link.active .material-symbols-outlined {
    color: var(--xi-primary-accent);
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.xi-sidebar-foot {
    padding: 10px;
    border-top: 1px solid var(--xi-outline);
    flex-shrink: 0;
    background: var(--xi-surface);
}

.xi-plan-widget {
    margin-top: 8px;
    padding: 12px 14px;
    background: var(--xi-surface-muted);
    border: 1px solid var(--xi-outline);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.xi-plan-widget:hover {
    background: rgba(99, 102, 241, 0.06);
    border-color: rgba(99, 102, 241, 0.25);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.08);
}

.xi-plan-widget:focus-visible {
    outline: 2px solid var(--xi-primary-accent);
    outline-offset: 2px;
}

.xi-plan-widget-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.xi-plan-widget-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--xi-primary-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--xi-primary-accent);
}

.xi-plan-widget-icon .material-symbols-outlined {
    font-size: 16px;
    font-variation-settings: 'FILL' 1;
}

.xi-plan-widget-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--xi-on-surface);
}

.xi-plan-bar {
    height: 4px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.xi-plan-bar-fill {
    height: 100%;
    background: var(--xi-primary-accent);
    border-radius: 999px;
    transition: width 0.3s;
}

/* —— 主列 —— */
.xi-main-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
    background: var(--xi-surface-page);
}

.xi-topbar {
    position: sticky;
    top: 0;
    height: var(--xi-topbar-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 clamp(12px, 2vw, 24px);
    background: var(--xi-surface);
    border-bottom: 1px solid var(--xi-outline);
    z-index: 100;
}

.xi-topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.xi-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
}

.xi-breadcrumb-muted {
    color: var(--xi-text-muted);
    white-space: nowrap;
}

.xi-breadcrumb-sep {
    font-size: 16px !important;
    color: #cbd5e1;
    flex-shrink: 0;
}

.xi-breadcrumb-current {
    color: var(--xi-on-surface);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.xi-topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* 语言切换：xiami.world 风格分段 pill */
.xi-lang-switch {
    display: inline-flex;
    align-items: center;
    padding: 3px;
    gap: 2px;
    border: 1px solid var(--xi-outline);
    border-radius: 999px;
    background: var(--xi-surface-muted);
    flex-shrink: 0;
}

.xi-lang-opt {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 28px;
    padding: 0 10px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--xi-text-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.xi-lang-opt:hover {
    color: var(--xi-on-surface);
}

.xi-lang-opt.active {
    background: var(--xi-surface);
    color: var(--xi-primary-accent);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.xi-lang-toggle {
    display: none;
}

.xi-user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 8px;
    max-width: 160px;
}

.xi-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--xi-outline);
    background: var(--xi-surface-muted);
    flex-shrink: 0;
}

.xi-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--xi-on-surface);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xi-topbar-divider {
    width: 1px;
    height: 24px;
    background: var(--xi-outline);
    flex-shrink: 0;
}

.xi-btn-icon,
.xi-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 8px;
    color: var(--xi-text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.xi-sidebar-toggle {
    display: none;
    border-color: var(--xi-outline);
    background: var(--xi-surface);
}

.xi-btn-icon:hover {
    background: #fef2f2;
    color: #ef4444;
}

.xi-sidebar-toggle:hover {
    background: var(--xi-surface-muted);
    color: var(--xi-on-surface);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 190;
    opacity: 0;
    transition: opacity 0.25s ease;
}

body.sidebar-drawer-open .sidebar-backdrop {
    display: block;
    opacity: 1;
}

body.console-body .app-main {
    flex: 1 1 auto;
    overflow: visible;
    padding: 0;
    background: var(--xi-surface-page);
}

body.console-body .app-main .container {
    max-width: none;
    margin: 0;
    width: 100%;
    padding: 12px 16px 24px;
    box-sizing: border-box;
}

/* 功能区卡片（Mem0 式留白） */
body.console-body .app-main .card {
    border-radius: 12px;
    border-color: var(--xi-outline);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

/* Hub / 页内 Tab */
.xi-hub-page {
    max-width: none;
    margin: 0;
    width: 100%;
}

.xi-hub-tabs,
.xi-page-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.xi-hub-tabs {
    padding: 4px;
    background: var(--xi-surface);
    border: 1px solid var(--xi-outline);
    border-radius: 10px;
    width: fit-content;
    max-width: 100%;
}

.xi-hub-tab,
.xi-page-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--xi-text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.xi-page-tab {
    border: 1px solid var(--xi-outline);
    background: var(--xi-surface);
}

.xi-hub-tab:hover,
.xi-page-tab:hover {
    color: var(--xi-primary-accent);
    background: var(--xi-primary-soft);
}

.xi-hub-tab.active,
.xi-page-tab.active {
    background: var(--xi-primary-soft);
    color: var(--xi-primary-accent);
    font-weight: 600;
    border-color: rgba(99, 102, 241, 0.35);
}

.xi-hub-frame {
    width: 100%;
    min-height: 480px;
    height: auto;
    border: 1px solid var(--xi-outline);
    border-radius: 12px;
    background: #fff;
    display: block;
}

.xi-hub-frame--flat {
    border: none;
    border-radius: 0;
    min-height: 640px;
}

.xi-hub-page.account-center-card {
    padding: 20px 24px 24px;
}

.xi-hub-page.account-center-card .xi-hub-tabs {
    margin-bottom: 16px;
}

.xi-tab-panel {
    display: none;
}

.xi-tab-panel.active {
    display: block;
}

body.xi-embed {
    padding: 0 !important;
    background: #fff !important;
    overflow: auto !important;
    height: auto !important;
}

body.xi-embed .container {
    max-width: none;
    padding: 12px 16px 20px;
}

body.xi-embed .page-title.section-head,
body.xi-embed .billing-page-header,
body.xi-embed .usage-head {
    display: none;
}

.material-symbols-outlined {
    font-family: "Material Symbols Outlined", system-ui, sans-serif;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    line-height: 1;
    user-select: none;
}

/* 大屏：略加宽内容区 */
@media (min-width: 1440px) {
    :root {
        --xi-content-max: 1360px;
    }
}

/* 平板横屏 / 小笔记本：侧栏常驻 */
@media (min-width: 1024px) and (max-width: 1279px) {
    :root {
        --xi-sidebar-w: 240px;
    }
}

/* 平板竖屏 & 手机：抽屉侧栏 */
@media (max-width: 1023px) {
    .xi-sidebar-toggle {
        display: inline-flex;
    }

    .xi-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
    }

    body.sidebar-drawer-open .xi-sidebar {
        transform: translateX(0);
        z-index: 300;
        background: #ffffff;
        color: var(--xi-on-surface);
        box-shadow: 8px 0 32px rgba(15, 23, 42, 0.18);
        isolation: isolate;
    }

    body.sidebar-drawer-open .sidebar-backdrop {
        z-index: 280;
    }

    body.sidebar-drawer-open .xi-nav-link,
    body.sidebar-drawer-open .xi-sidebar-brand {
        color: var(--xi-on-surface);
    }

    .xi-breadcrumb-muted {
        display: none;
    }

    .xi-breadcrumb-sep {
        display: none;
    }
}

/* 手机 */
@media (max-width: 640px) {
    .xi-topbar {
        padding: 0 12px;
        background: #ffffff;
        box-shadow: 0 1px 0 var(--xi-outline);
    }

    .xi-breadcrumb-current {
        color: #0f172a;
        font-weight: 700;
        font-size: 14px;
    }

    .xi-sidebar-toggle {
        color: #0f172a;
        border-color: #94a3b8;
        background: #f8fafc;
    }

    .xi-sidebar-toggle .material-symbols-outlined {
        color: #0f172a;
        font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
    }

    .xi-lang-opt {
        color: #475569;
    }

    .xi-lang-opt.active {
        color: var(--xi-primary-accent);
        background: #ffffff;
    }

    .xi-lang-toggle span#xiLangLabel {
        display: none;
    }

    .xi-lang-toggle {
        width: 36px;
        padding: 0;
        justify-content: center;
    }

    .xi-user-name {
        display: none;
    }

    .xi-hub-tabs,
    .xi-page-tabs {
        width: 100%;
        background: #f1f5f9;
        border-color: #cbd5e1;
    }

    .xi-hub-tab,
    .xi-page-tab {
        flex: 1 1 auto;
        text-align: center;
        font-size: 13px;
        padding: 8px 10px;
        color: #334155;
        background: #ffffff;
        border-color: #cbd5e1;
    }

    .xi-hub-tab:not(.active),
    .xi-page-tab:not(.active) {
        color: #334155;
        background: transparent;
        border-color: transparent;
        font-weight: 500;
    }

    .xi-hub-tab.active,
    .xi-page-tab.active {
        color: var(--xi-primary-accent);
        background: #ffffff;
        border-color: #c7d2fe;
        font-weight: 700;
        box-shadow: 0 1px 3px rgba(99, 102, 241, 0.12);
    }

    body.console-body .app-main {
        padding: 12px;
    }

    body.console-body .app-main .card {
        padding: 16px;
    }
}

/* iPad 安全区 */
@supports (padding: max(0px)) {
    .xi-topbar {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    body.console-body .app-main {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
