:root {
    --home-bg: #f4f6fb;
    --home-border: #e4e8f0;
    --home-ink: #1f2937;
    --home-brand: #1f3864;
    --home-accent: #2e75b6;
}

body {
    background: var(--home-bg);
    color: var(--home-ink);
}

/* 顶栏 */
.app-topbar {
    background: #fff;
    border-bottom: 1px solid var(--home-border);
    min-height: 64px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-topbar .container-xl {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: 64px;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    color: var(--home-brand);
    font-weight: 600;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #1f3864, #2e75b6);
    color: #fff;
    font-weight: 700;
    font-size: 17px;
    box-shadow: 0 6px 16px rgba(46, 117, 182, .35);
}

.brand-mark-lg {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    font-size: 26px;
}

.brand-text {
    font-size: 16px;
    letter-spacing: .02em;
}

/* 登录页 */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 20% 10%, #e8eefb 0%, #f4f6fb 45%, #eef2f9 100%);
    padding: 2rem 1rem;
}

.login-shell {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-brand {
    margin-bottom: 1.5rem;
}

.login-brand h1 {
    font-size: 1.6rem;
    margin: 1rem 0 .35rem;
    color: var(--home-brand);
}

.login-card {
    text-align: left;
    border: 1px solid var(--home-border);
    box-shadow: 0 18px 48px rgba(31, 56, 100, .12);
}

.login-foot {
    margin-top: 1.25rem;
    color: #94a3b8;
    font-size: 12px;
    letter-spacing: .08em;
}

/* 工作台头部 */
.page-body {
    padding-top: 1.75rem;
    padding-bottom: 2.5rem;
}

.page-header .page-actions {
    margin-left: auto;
}

/* 极简工作台 */
.home-body {
    background: var(--home-bg);
}

.home-shell {
    position: relative;
    z-index: 1;
    max-width: 1180px;
    margin: 0 auto;
    padding: 1.25rem 1rem 3rem;
}

.home-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.25rem;
}

.home-tools {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-left: auto;
}

.home-tool,
.home-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--home-border);
    border-radius: 50%;
    background: #fff;
    color: var(--home-brand);
    text-decoration: none;
}

.home-tool:hover,
.home-avatar:hover {
    background: rgba(46, 117, 182, .08);
    color: var(--home-brand);
}

/* 壁纸层与预设 */
.wallpaper-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.wallpaper-layer img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wallpaper-layer::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(244, 246, 251, .68);
}

.wallpaper-aurora { background: linear-gradient(135deg, #e0f2fe 0%, #ede9fe 50%, #fce7f3 100%); }
.wallpaper-mist { background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%); }
.wallpaper-mint { background: linear-gradient(135deg, #ecfdf5 0%, #ccfbf1 100%); }
.wallpaper-sunset { background: linear-gradient(135deg, #fff7ed 0%, #ffe4e6 100%); }
.wallpaper-paper { background: linear-gradient(135deg, #faf7f2 0%, #f1e9dc 100%); }
.wallpaper-ocean { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 55%, #e0f2fe 100%); }

.wallpaper-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .6rem;
}

.wallpaper-choice {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding: .4rem;
    border: 1px solid var(--home-border);
    border-radius: 10px;
    font-size: 12px;
    cursor: pointer;
}

.wallpaper-choice:has(input:checked) {
    border-color: var(--home-accent);
    box-shadow: 0 0 0 2px rgba(46, 117, 182, .15);
}

.wallpaper-choice input {
    margin: 0;
    accent-color: var(--home-accent);
}

.wallpaper-swatch {
    display: block;
    width: 100%;
    height: 52px;
    border: 1px solid rgba(0, 0, 0, .04);
    border-radius: 8px;
}

/* 链接图标墙（无卡片外框） */
.link-item {
    position: relative;
    border-radius: 14px;
    transition: background-color .15s ease;
}

.link-item:hover,
.link-item:focus-within {
    background: rgba(46, 117, 182, .07);
}

.link-item-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .55rem;
    width: 100%;
    padding: .75rem .35rem .7rem;
    color: inherit;
    text-align: center;
    text-decoration: none;
}

.link-item-main:hover {
    color: inherit;
}

.link-item-main:hover .link-icon {
    transform: translateY(-1px);
}

.link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: #eef3fa;
    overflow: hidden;
    transition: transform .15s ease;
}

.link-icon img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.link-icon-letter {
    color: #fff;
    font-size: 23px;
    font-weight: 700;
}

.tile-color-0 { background: linear-gradient(135deg, #2e75b6, #4f9be0); }
.tile-color-1 { background: linear-gradient(135deg, #0f766e, #14b8a6); }
.tile-color-2 { background: linear-gradient(135deg, #b45309, #f59e0b); }
.tile-color-3 { background: linear-gradient(135deg, #9d174d, #ec4899); }
.tile-color-4 { background: linear-gradient(135deg, #4c1d95, #8b5cf6); }
.tile-color-5 { background: linear-gradient(135deg, #166534, #22c55e); }
.tile-color-6 { background: linear-gradient(135deg, #991b1b, #ef4444); }
.tile-color-7 { background: linear-gradient(135deg, #1e3a8a, #3b82f6); }

.link-name {
    display: -webkit-box;
    max-width: 100%;
    color: var(--home-ink);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
    overflow: hidden;
    word-break: break-word;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* 空状态 */
.empty-state {
    margin: 2rem auto 0;
    max-width: 520px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: #fff;
    border: 1px dashed #cbd8ea;
    border-radius: 16px;
}

.empty-mark {
    font-size: 2.5rem;
    color: #2e75b6;
    margin-bottom: .75rem;
}

.empty-state h3 {
    margin-bottom: .5rem;
}

.empty-state p {
    margin-bottom: 1.25rem;
}

/* 表单页 */
.form-narrow {
    max-width: 720px;
}

.form-label.required::after {
    content: " *";
    color: #dc2626;
}

.current-icon {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-top: .75rem;
}

.current-icon img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 6px;
    background: #f1f5fb;
    padding: 2px;
}

/* 错误页 */
.error-shell {
    max-width: 520px;
    margin: 12vh auto 0;
    padding: 2rem;
    text-align: center;
}

.error-code {
    font-size: 4rem;
    font-weight: 700;
    line-height: 1;
    color: #2e75b6;
    margin-bottom: .5rem;
}

.error-shell h1 {
    font-size: 1.5rem;
    margin-bottom: .75rem;
}

.error-shell p {
    margin-bottom: 1.5rem;
}

@media (max-width: 575.98px) {
    .home-shell {
        padding: 1rem .75rem 3rem;
    }

    .home-toolbar {
        gap: .5rem;
    }

    .home-tools {
        gap: .25rem;
    }

    .wallpaper-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ===== 移动端适配 ===== */
html {
    -webkit-text-size-adjust: 100%;
}

@media (max-width: 767.98px) {
    .container-xl,
    .home-shell {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .form-control,
    .form-select,
    textarea.form-control {
        font-size: 16px;
    }

    .login-body {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .page-header {
        flex-wrap: wrap;
        gap: .5rem;
    }

    .page-header .page-actions {
        margin-left: 0;
    }
}

@media (max-width: 575.98px) {
    .home-tool,
    .home-avatar {
        width: 38px;
        height: 38px;
    }

    .home-tools {
        gap: .2rem;
    }

    .home-shell {
        padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    }

    .wallpaper-swatch {
        height: 46px;
    }
}

@media (max-width: 420px) {
    #wallpaperModal .modal-footer {
        flex-wrap: wrap;
        gap: .4rem;
    }

    #wallpaperModal .modal-footer .btn-primary {
        flex: 1 1 100%;
    }

    #wallpaperModal .modal-footer .btn-link {
        flex: 1 1 auto;
    }

    .form-narrow .card-footer {
        flex-wrap: wrap;
        gap: .5rem;
    }

    .form-narrow .card-footer .btn-primary {
        flex: 1 1 100%;
    }
}

/* 用户管理：平板/手机改为卡片，避免 8 列表格被压扁 */
@media (max-width: 991.98px) {
    .admin-users-table thead {
        display: none;
    }

    .admin-users-table,
    .admin-users-table tbody,
    .admin-users-table tr,
    .admin-users-table td {
        display: block;
        width: 100%;
    }

    .admin-users-table tr {
        margin: 0 0 1rem;
        padding: .75rem 1rem;
        background: #fff;
        border: 1px solid var(--home-border);
        border-radius: 12px;
    }

    .admin-users-table td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
        padding: .35rem 0;
        border: 0;
        text-align: left;
    }

    .admin-users-table td::before {
        content: attr(data-label);
        flex: 0 0 5.5rem;
        color: #94a3b8;
        font-weight: 500;
    }

    .admin-users-table td.admin-user-actions {
        display: block;
        margin-top: .35rem;
        padding-top: .6rem;
        border-top: 1px dashed var(--home-border);
    }

    .admin-users-table td.admin-user-actions::before {
        display: none;
    }

    .admin-user-actions > div {
        justify-content: flex-start !important;
    }

    .admin-user-actions .btn {
        min-height: 36px;
    }

    .admin-user-actions input[type="password"] {
        width: 130px;
    }
}

@media (max-width: 767.98px) {
    .card-header {
        flex-wrap: wrap;
        gap: .35rem;
    }

    .card-header .card-actions {
        margin-left: 0;
        width: 100%;
    }
}

/* 头像 */
.home-avatar {
    overflow: hidden;
    padding: 0;
}

.home-avatar img,
.topbar-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.topbar-avatar {
    display: inline-flex;
    width: 22px;
    height: 22px;
    margin-right: .35rem;
    overflow: hidden;
    vertical-align: middle;
}

.avatar-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 96px;
    height: 96px;
    overflow: hidden;
    border-radius: 50%;
    background: #eef3fa;
    color: #94a3b8;
    font-size: 2.5rem;
    flex: 0 0 96px;
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

@media (max-width: 420px) {
    .avatar-preview {
        width: 76px;
        height: 76px;
        flex-basis: 76px;
        font-size: 2rem;
    }
}

/* 链接管理页 */
.manage-link {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--home-border);
}

.manage-link:last-child {
    border-bottom: 0;
}

.manage-link > .link-icon {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    margin: 0;
}

.manage-link > .link-icon img {
    width: 28px;
    height: 28px;
}

.manage-link > .link-icon-letter {
    font-size: 18px;
}

.manage-link-body {
    flex: 1;
    min-width: 0;
}

.manage-link-body .fw-semibold {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.manage-link-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    flex-wrap: wrap;
}

@media (max-width: 575.98px) {
    .manage-link {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .manage-link-body {
        flex: 1 1 calc(100% - 60px);
    }

    .manage-link-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* 拖拽排序 */
.link-cell {
    cursor: grab;
    user-select: none;
}

.link-sortable-chosen {
    cursor: grabbing;
}

.link-sortable-ghost {
    opacity: .25;
}

.link-sortable-fallback {
    z-index: 1050;
    opacity: .95;
    box-shadow: 0 14px 32px rgba(31, 56, 100, .18);
}
