/* =====================================================================
   惠利得 · 设计系统基础层
   所有页面共用：设计令牌、应用外壳（侧边栏 + 顶栏）、基础元素。
   页面专属样式见 app.css（生图工作台）、hy-tools.css（功能页）、hy-pages.css（图库/记录页）。
   ===================================================================== */

:root {
    /* 中性色 */
    --hy-bg: #f6f6f7;
    --hy-surface: #ffffff;
    --hy-subtle: #fafafa;
    --hy-muted-bg: #f3f3f5;
    --hy-hover: #f0f0f2;
    --hy-border: #e6e6ea;
    --hy-border-strong: #d4d4da;
    --hy-text: #18181b;
    --hy-text-2: #3f3f46;
    --hy-muted: #71717a;
    --hy-faint: #a1a1aa;

    /* 品牌色：朱砂 */
    --hy-brand: #e54d2e;
    --hy-brand-hover: #cf3f21;
    --hy-brand-ink: #b8391c;
    --hy-brand-soft: #fff2ee;
    --hy-brand-soft-2: #ffe4db;
    --hy-brand-ring: rgba(229, 77, 46, .16);

    /* 语义色 */
    --hy-success: #16a34a;
    --hy-success-ink: #15803d;
    --hy-success-soft: #effbf3;
    --hy-warn: #d97706;
    --hy-warn-ink: #b45309;
    --hy-warn-soft: #fff8eb;
    --hy-danger: #dc2626;
    --hy-danger-ink: #b91c1c;
    --hy-danger-soft: #fef2f2;
    --hy-info: #2563eb;
    --hy-info-ink: #1d4ed8;
    --hy-info-soft: #eff5ff;

    /* 尺寸 */
    --hy-radius-xs: 4px;
    --hy-radius-sm: 6px;
    --hy-radius: 8px;
    --hy-radius-lg: 12px;
    --hy-sidebar-w: 236px;
    --hy-topbar-h: 52px;

    --hy-shadow-xs: 0 1px 2px rgba(24, 24, 27, .05);
    --hy-shadow-sm: 0 1px 2px rgba(24, 24, 27, .04), 0 1px 3px rgba(24, 24, 27, .06);
    --hy-shadow: 0 4px 12px rgba(24, 24, 27, .06), 0 1px 3px rgba(24, 24, 27, .05);
    --hy-shadow-lg: 0 16px 48px rgba(24, 24, 27, .16), 0 2px 6px rgba(24, 24, 27, .06);

    --hy-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei UI", "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
    --hy-mono: "JetBrains Mono", "SF Mono", "Cascadia Code", Consolas, monospace;
}

/* ---------------------------------------------------------------------
   基础
   --------------------------------------------------------------------- */
html { -webkit-text-size-adjust: 100%; }
.hy-brand-mark, .auth-logo { font-weight: 700; font-size: 21px; line-height: 1; letter-spacing: 0; flex-shrink: 0; }
.hy-brand-text { min-width: 0; }
.hy-brand-name { white-space: nowrap; letter-spacing: 0; }

body {
    font-family: var(--hy-font);
    background: var(--hy-bg);
    color: var(--hy-text);
    font-size: 13.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--hy-brand-soft-2); color: var(--hy-text); }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: #d9d9de;
    border-radius: 999px;
    border: 3px solid transparent;
    background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: #bdbdc4; }

:focus-visible { outline: 2px solid var(--hy-brand); outline-offset: 2px; }

/* ---------------------------------------------------------------------
   应用外壳：侧边栏
   --------------------------------------------------------------------- */
.hy-has-sidebar { padding-left: var(--hy-sidebar-w); }

.hy-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 300;
    width: var(--hy-sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--hy-surface);
    border-right: 1px solid var(--hy-border);
    font-family: var(--hy-font);
}

.hy-brand {
    height: var(--hy-topbar-h);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    border-bottom: 1px solid var(--hy-border);
    color: var(--hy-text);
    text-decoration: none;
}
.hy-brand-mark {
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--hy-brand);
    color: #fff;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .12), 0 1px 2px rgba(229, 77, 46, .35);
}
.hy-brand-mark svg { width: 17px; height: 17px; display: block; }
.hy-brand-text { display: grid; line-height: 1.15; min-width: 0; }
.hy-brand-name { font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.hy-brand-sub { font-size: 11px; color: var(--hy-muted); font-weight: 500; letter-spacing: .2px; }

.hy-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 10px 16px;
    scrollbar-width: thin;
}
.hy-nav-group + .hy-nav-group { margin-top: 14px; }
.hy-nav-label {
    padding: 0 10px 6px;
    color: var(--hy-faint);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .6px;
}
.hy-nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 32px;
    padding: 0 10px;
    border-radius: var(--hy-radius);
    color: var(--hy-text-2);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background .12s, color .12s;
}
.hy-nav-item + .hy-nav-item { margin-top: 1px; }
.hy-nav-item svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    color: var(--hy-muted);
    transition: color .12s;
}
.hy-nav-item:hover { background: var(--hy-hover); color: var(--hy-text); }
.hy-nav-item:hover svg { color: var(--hy-text-2); }
.hy-nav-item.is-active {
    background: var(--hy-brand-soft);
    color: var(--hy-brand-ink);
    font-weight: 600;
}
.hy-nav-item.is-active svg { color: var(--hy-brand); }
.hy-nav-item.is-active::before {
    content: "";
    position: absolute;
    left: -10px;
    top: 7px;
    bottom: 7px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--hy-brand);
}
.hy-nav-item[hidden] { display: none; }
.hy-nav-tag {
    margin-left: auto;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--hy-muted-bg);
    color: var(--hy-muted);
    font-size: 10.5px;
    font-weight: 600;
}

.hy-sidebar-foot {
    flex: 0 0 auto;
    padding: 10px;
    border-top: 1px solid var(--hy-border);
    display: flex;
    align-items: center;
    gap: 6px;
}
.hy-search-btn,
.hy-collapse-btn {
    height: 32px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--hy-border);
    border-radius: var(--hy-radius);
    background: var(--hy-subtle);
    color: var(--hy-muted);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
}
.hy-search-btn { flex: 1 1 auto; min-width: 0; padding: 0 8px 0 10px; }
.hy-search-btn span { flex: 1 1 auto; text-align: left; white-space: nowrap; }
.hy-collapse-btn { flex: 0 0 32px; justify-content: center; padding: 0; }
.hy-search-btn:hover,
.hy-collapse-btn:hover { background: var(--hy-hover); border-color: var(--hy-border-strong); color: var(--hy-text); }
.hy-search-btn svg,
.hy-collapse-btn svg { width: 15px; height: 15px; flex: 0 0 auto; }
kbd {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 5px;
    border: 1px solid var(--hy-border);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--hy-surface);
    color: var(--hy-muted);
    font-family: var(--hy-font);
    font-size: 10.5px;
    font-weight: 500;
    white-space: nowrap;
}

/* 桌面端折叠为图标栏 */
@media (min-width: 961px) {
    .hy-collapsed { --hy-sidebar-w: 64px; }
    .hy-collapsed .hy-brand { justify-content: center; padding: 0; }
    .hy-collapsed .hy-brand-text,
    .hy-collapsed .hy-nav-label,
    .hy-collapsed .hy-nav-item span,
    .hy-collapsed .hy-search-btn span,
    .hy-collapsed .hy-search-btn kbd { display: none; }
    .hy-collapsed .hy-nav { padding: 10px 12px 16px; }
    .hy-collapsed .hy-nav-group + .hy-nav-group { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--hy-border); }
    .hy-collapsed .hy-nav-item { justify-content: center; padding: 0; height: 36px; }
    .hy-collapsed .hy-nav-item.is-active::before { left: -12px; }
    .hy-collapsed .hy-sidebar-foot { flex-direction: column; padding: 10px 12px; }
    .hy-collapsed .hy-search-btn { width: 40px; flex: 0 0 auto; justify-content: center; padding: 0; }
    .hy-collapsed .hy-collapse-btn { width: 40px; flex-basis: auto; }
    .hy-collapsed .hy-collapse-btn svg { transform: scaleX(-1); }
}
.hy-sidebar,
.hy-has-sidebar { transition: none; }

/* 快速跳转面板 */
.hy-palette { position: fixed; inset: 0; z-index: 2000; display: none; }
.hy-palette.is-open { display: block; }
.hy-palette-backdrop { position: absolute; inset: 0; background: rgba(24, 24, 27, .28); }
.hy-palette-card {
    position: relative;
    width: min(560px, calc(100vw - 32px));
    margin: 12vh auto 0;
    border: 1px solid var(--hy-border);
    border-radius: var(--hy-radius-lg);
    background: var(--hy-surface);
    box-shadow: var(--hy-shadow-lg);
    overflow: hidden;
    font-family: var(--hy-font);
    animation: hy-pop .14s ease-out;
}
@keyframes hy-pop { from { opacity: 0; transform: translateY(-6px) scale(.985); } to { opacity: 1; transform: none; } }
.hy-palette-search {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border-bottom: 1px solid var(--hy-border);
}
.hy-palette-search svg { width: 18px; height: 18px; color: var(--hy-faint); flex: 0 0 auto; }
.hy-palette-search input {
    flex: 1 1 auto;
    height: 50px;
    border: 0 !important;
    outline: 0;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    font: inherit;
    font-size: 15px;
    color: var(--hy-text);
}
.hy-palette-list { max-height: min(420px, 56vh); overflow-y: auto; padding: 6px; }
.hy-palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    padding: 0 10px;
    border-radius: var(--hy-radius);
    color: var(--hy-text-2);
    text-decoration: none;
    font-size: 13.5px;
}
.hy-palette-item svg { width: 16px; height: 16px; color: var(--hy-muted); flex: 0 0 auto; }
.hy-palette-item small { margin-left: auto; color: var(--hy-faint); font-size: 12px; }
.hy-palette-item.is-active { background: var(--hy-brand-soft); color: var(--hy-brand-ink); }
.hy-palette-item.is-active svg { color: var(--hy-brand); }
.hy-palette-empty { padding: 28px 12px; text-align: center; color: var(--hy-muted); }
.hy-palette-foot {
    display: flex;
    gap: 16px;
    padding: 9px 14px;
    border-top: 1px solid var(--hy-border);
    background: var(--hy-subtle);
    color: var(--hy-muted);
    font-size: 11.5px;
}
.hy-palette-foot span { display: inline-flex; align-items: center; gap: 4px; }

/* Ctrl+Enter 触发时的按钮反馈 */
.hy-flash { animation: hy-flash .45s ease-out; }
@keyframes hy-flash { 0% { box-shadow: 0 0 0 0 rgba(229, 77, 46, .45); } 100% { box-shadow: 0 0 0 10px rgba(229, 77, 46, 0); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------------------------------------------------------------
   应用外壳：顶栏
   --------------------------------------------------------------------- */
.hy-topbar {
    position: sticky;
    top: 0;
    z-index: 200;
    height: var(--hy-topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    background: rgba(255, 255, 255, .86);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--hy-border);
    font-family: var(--hy-font);
}
.hy-menu-btn {
    display: none;
    width: 32px;
    height: 32px;
    padding: 0;
    place-items: center;
    border: 1px solid var(--hy-border);
    border-radius: var(--hy-radius);
    background: var(--hy-surface);
    color: var(--hy-text-2);
    cursor: pointer;
}
.hy-menu-btn svg { width: 16px; height: 16px; }

.hy-crumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 13px;
    color: var(--hy-muted);
}
.hy-crumbs b { color: var(--hy-text); font-weight: 600; white-space: nowrap; }
.hy-crumbs .hy-crumb-sep { color: var(--hy-border-strong); }

.hy-topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 旧的用户徽标 / 退出按钮统一改造成顶栏控件（保留原 id / class 以兼容脚本） */
.hy-topbar .local-user-badge,
.hy-topbar .badge,
.hy-topbar .hy-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    max-width: 320px;
    padding: 0 12px 0 4px;
    border: 1px solid var(--hy-border);
    border-radius: 999px;
    background: var(--hy-surface);
    color: var(--hy-text-2);
    font-size: 12.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: none;
}
.hy-topbar .local-user-badge::before,
.hy-topbar .badge::before {
    content: "";
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b8391c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='8' r='4'/><path d='M4 21c0-4 3.6-7 8-7s8 3 8 7'/></svg>") center / 14px no-repeat,
        var(--hy-brand-soft);
}
.hy-topbar .btn-logout,
.hy-topbar .logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--hy-border);
    border-radius: var(--hy-radius);
    background: var(--hy-surface);
    color: var(--hy-text-2);
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--hy-shadow-xs);
    transition: background .12s, border-color .12s, color .12s;
}
.hy-topbar .btn-logout:hover,
.hy-topbar .logout:hover {
    background: var(--hy-hover);
    border-color: var(--hy-border-strong);
    color: var(--hy-text);
}
.hy-topbar .btn-logout svg,
.hy-topbar .logout svg { width: 14px; height: 14px; }

.hy-scrim { display: none; }

/* 旧顶栏不再使用 */
body > .header,
.page-shell > .header,
.shell > .header { display: none !important; }

/* ---------------------------------------------------------------------
   响应式外壳
   --------------------------------------------------------------------- */
@media (max-width: 960px) {
    .hy-has-sidebar { padding-left: 0; }
    .hy-sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease, box-shadow .2s ease;
    }
    .hy-nav-open .hy-sidebar { transform: none; box-shadow: var(--hy-shadow-lg); }
    .hy-nav-open .hy-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 250;
        background: rgba(24, 24, 27, .32);
    }
    .hy-menu-btn { display: inline-grid; }
    .hy-topbar { padding: 0 16px; }
    .hy-topbar .local-user-badge,
    .hy-topbar .badge { max-width: 180px; }
}

@media (max-width: 560px) {
    .hy-sidebar-foot kbd { display: none; }
    .hy-crumbs .hy-crumb-group,
    .hy-crumbs .hy-crumb-sep { display: none; }
    .hy-topbar .btn-logout span,
    .hy-topbar .logout span { display: none; }
}
