/**
 * 「定时任务」页。容器 #scheduledTaskView 与知识库列表、图谱、统计、插件·技能·规则互斥显隐（NavigationManager.setViewMode），
 * 几何与 .plugin-market-view 同一套（高度写死成视口高度、显隐只靠 body 类，理由见 plugin-market.css 文件头）；
 * 下面按「还有 30px 备案栏」扣的高度与窄屏下外边距，桌面端（藏了备案栏）在 desktop.css 里与其它全局视图一起还回来。
 * 卡片、工具条、网格、空态、网页版引导直接复用插件 / 技能页的类，这里只补定时任务独有的几样。
 * 颜色一律取 --kb-* / 语义变量，不写色值。加载在 plugin-market.css、skill-market.css 之后。
 */

.scheduled-task-view {
    display: none;
    flex-direction: column;
    height: calc(var(--kb-vh, 100dvh) - var(--kb-topbar-height, 64px) - 30px);
    min-height: 0;
    background: var(--bg-primary);
}

@media (display-mode: standalone) {
    .scheduled-task-view {
        height: calc(var(--kb-vh, 100dvh) - var(--kb-topbar-height, 64px));
    }
}

body.pwa-mode .scheduled-task-view {
    height: calc(var(--kb-vh, 100dvh) - var(--kb-topbar-height, 64px));
}

body.kb-scheduled-mode .scheduled-task-view {
    display: flex !important;
}

body.kb-scheduled-mode .knowledge-area,
body.kb-scheduled-mode .mobile-search-bar,
body.kb-scheduled-mode .mobile-pagination-bar {
    display: none !important;
}

/* 网页版：下载引导在内容区里水平垂直居中（引导块本身的样式在 skill-market.css） */
.scheduled-task-view--web {
    overflow-y: auto;
}

/*
 * 手机 / 平板经电脑管理：骨架是 .remote-control-scroll > .remote-control-page（remote-control.css），
 * 与「插件·技能·规则」「远程控制」两页同一套边距、同一个滚动容器，标题随内容一起滚。
 * tab 行与工具条（搜索 + 新建）的整页间距在 plugin-market.css / skill-market.css 里与另两页共用一份，
 * 这里只补卡片单列（与另两页的单栏列表一致）。
 */
.scheduled-task-view--remote .scheduled-task-grid {
    grid-template-columns: minmax(0, 1fr);
}

/* ---------------- 分组 ---------------- */

.scheduled-task-viewport {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.scheduled-task-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 10px;
    color: var(--kb-ink-soft);
    font-size: 0.875rem;
    font-weight: 600;
}


.scheduled-task-empty {
    display: flex;
    justify-content: center;
    padding: 24px 0 8px;
}

/* ---------------- 任务卡片 ---------------- */

.scheduled-task-card,
.scheduled-task-example {
    -webkit-tap-highlight-color: transparent;
}

.scheduled-task-card {
    cursor: pointer;
}

.scheduled-task-card.is-disabled .plugin-card-name,
.scheduled-task-card.is-disabled .scheduled-task-prompt {
    color: var(--kb-ink-muted);
}

.scheduled-task-card.is-highlight {
    border-color: var(--kb-accent);
    box-shadow: 0 0 0 3px var(--kb-accent-soft);
}

.scheduled-task-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.scheduled-task-card-head .plugin-card-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scheduled-task-prompt {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.scheduled-task-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    color: var(--kb-ink-muted);
    font-size: 0.75rem;
}

.scheduled-task-schedule {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--kb-ink-soft);
}

.scheduled-task-next {
    white-space: nowrap;
}

.scheduled-task-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scheduled-task-status--succeeded {
    color: var(--color-success-dark);
}

.scheduled-task-status--failed {
    color: var(--color-error);
}

.scheduled-task-status--missed,
.scheduled-task-status--skipped {
    color: var(--color-warning-dark);
}

.scheduled-task-status--running {
    color: var(--kb-accent);
}

.scheduled-task-status--running i {
    animation: scheduled-task-spin 1s linear infinite;
}

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

.scheduled-task-open {
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--kb-accent);
    font: inherit;
    cursor: pointer;
}

/*
 * 下面所有 :hover 都只给真鼠标：@media (any-hover: hover) 挡掉纯触摸设备，
 * :not(:where(html[data-kb-pointer="touch"] *)) 挡掉「iPad 接了触控板但这一下是手指」——
 * 否则在手机 / 平板上滚动列表时手指扫过的卡片会黏住高亮（docs/mobile-reading-V2.8.2.md「触摸交互」）
 */
@media (any-hover: hover) {
    .scheduled-task-open:hover:not(:where(html[data-kb-pointer="touch"] *)) {
        color: var(--kb-accent-strong);
        text-decoration: underline;
    }
}

/* 菜单挂在 body 上，要压在页面之上但低于弹框（弹框在更高层） */
.scheduled-task-menu {
    z-index: 1500;
}

/* ---------------- 示例 ---------------- */

.scheduled-task-section-title small {
    margin-left: 4px;
    color: var(--kb-ink-muted);
    font-size: 0.75rem;
    font-weight: 400;
}

/* 与任务卡片同一个网格、同一套 .plugin-card 外形；只把边框换成虚线表达「还不是你的任务」 */
.scheduled-task-example {
    border-style: dashed;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.scheduled-task-example:focus-visible:where(html:not(.kb-focus-pointer) *) {
    border-style: solid;
    border-color: var(--kb-accent);
    background: var(--kb-accent-soft);
    outline: none;
}

@media (any-hover: hover) {
    .scheduled-task-example:hover:not(:where(html[data-kb-pointer="touch"] *)) {
        border-style: solid;
        border-color: var(--kb-accent);
        background: var(--kb-accent-soft);
    }
}

.scheduled-task-example-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.scheduled-task-example-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--kb-accent-soft);
    color: var(--kb-accent);
    font-size: 1.125rem;
}

@media (any-hover: hover) {
    .scheduled-task-example:hover:not(:where(html[data-kb-pointer="touch"] *)) .scheduled-task-example-icon {
        background: var(--kb-paper-panel);
    }
}

.scheduled-task-example-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scheduled-task-example-use {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 2px;
    padding: 2px 10px;
    border: 1px solid var(--kb-paper-line);
    border-radius: 999px;
    color: var(--kb-ink-soft);
    font-size: 0.75rem;
    line-height: 20px;
}

@media (any-hover: hover) {
    .scheduled-task-example:hover:not(:where(html[data-kb-pointer="touch"] *)) .scheduled-task-example-use {
        border-color: var(--kb-accent);
        background: var(--kb-accent);
        color: var(--text-inverse);
    }
}

/* 「…」按钮平时不抢眼，悬停 / 聚焦才出底色 */
.scheduled-task-card .scheduled-task-more {
    background: transparent;
    color: var(--kb-ink-muted);
}

.scheduled-task-card .scheduled-task-more:focus-visible:where(html:not(.kb-focus-pointer) *),
.scheduled-task-card .scheduled-task-more[aria-expanded="true"] {
    background: var(--kb-active-bg, var(--kb-accent-soft));
    color: var(--kb-ink);
}

@media (any-hover: hover) {
    .scheduled-task-card .scheduled-task-more:hover:not(:where(html[data-kb-pointer="touch"] *)) {
        background: var(--kb-active-bg, var(--kb-accent-soft));
        color: var(--kb-ink);
    }
}

/* ---------------- 表单与运行记录（弹框内） ---------------- */

.scheduled-task-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.scheduled-task-zone-offset {
    white-space: nowrap;
}

.scheduled-task-form [hidden] {
    display: none !important;
}

/* ---------------- 运行时间选择器 ---------------- */

.scheduled-time-field {
    position: relative;
}

.utils-dialog .scheduled-time-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 0;
    font-weight: 400;
    line-height: 1.5;
    text-align: left;
    cursor: pointer;
}

.scheduled-time-trigger i {
    color: var(--kb-ink-muted);
    font-size: 1.0625rem;
    line-height: 1;
}

.scheduled-time-trigger[aria-expanded="true"] i {
    color: var(--kb-accent);
}

.scheduled-time-panel {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 20;
    display: flex;
    gap: 4px;
    margin-top: 4px;
    padding: 4px;
    border: 1px solid var(--kb-paper-line);
    border-radius: 10px;
    background: var(--kb-paper-panel);
    box-shadow: var(--kb-paper-shadow);
    animation: ai-popover-in 0.12s ease-out;
}

.scheduled-time-column {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 64px;
    height: 216px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
}

.scheduled-time-column::-webkit-scrollbar {
    display: none;
}

.utils-dialog .scheduled-time-option {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--kb-ink);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    font-weight: 400;
    line-height: 1;
}

.utils-dialog .scheduled-time-option:hover,
.utils-dialog .scheduled-time-option:focus-visible:where(html:not(.kb-focus-pointer) *) {
    background: var(--kb-active-bg);
    outline: none;
}

.utils-dialog .scheduled-time-option.is-selected {
    background: var(--kb-accent);
    color: var(--text-inverse);
    font-weight: 600;
}

/* 与 mobile.css 给 input / select 的窄屏尺寸对齐，否则同一行里「运行时间」比「重复」矮一截 */
@media (max-width: 1023px) {
    .utils-dialog .scheduled-time-trigger {
        min-height: 44px;
        font-size: 16px;
    }

    .utils-dialog .scheduled-time-option {
        min-height: 44px;
    }

    .scheduled-time-column {
        height: 230px;
    }
}

.scheduled-task-runs {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.scheduled-task-run {
    display: grid;
    grid-template-columns: 64px 130px 72px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--kb-paper-line);
    color: var(--kb-ink);
    font-size: 0.8125rem;
}

.scheduled-task-run-time,
.scheduled-task-run-trigger {
    color: var(--kb-ink-soft);
}

.scheduled-task-run-error {
    overflow: hidden;
    color: var(--kb-ink-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.scheduled-task-runs-more {
    align-self: center;
}

.scheduled-task-runs-more[hidden] {
    display: none;
}

@media (max-width: 1023px) {
    body.kb-scheduled-mode .mobile-main-content {
        margin-top: var(--kb-topbar-height, 64px) !important;
        margin-bottom: calc(30px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.kb-scheduled-mode.pwa-mode .mobile-main-content {
        margin-bottom: 0 !important;
    }

    .scheduled-task-view {
        height: calc(var(--kb-vh, 100dvh) - var(--kb-topbar-height, 64px) - 30px - env(safe-area-inset-bottom, 0px));
    }

    body.pwa-mode .scheduled-task-view {
        height: calc(var(--kb-vh, 100dvh) - var(--kb-topbar-height, 64px));
    }

    .scheduled-task-toolbar {
        flex-wrap: wrap;
    }

    /* 窄屏整页一起滚：工具条与说明不再悬在列表上方，与「插件技能」「远程控制」两页一致 */
    .scheduled-task-view {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .scheduled-task-view .scheduled-task-viewport {
        flex: none;
        min-height: auto;
        overflow: visible;
    }

    .scheduled-task-run {
        grid-template-columns: 56px minmax(0, 1fr) auto;
    }

    .scheduled-task-run-trigger,
    .scheduled-task-run-error {
        display: none;
    }
}
