/* ==========================================================================
   内部任务协作管理系统 — 全局样式
   --------------------------------------------------------------------------
   设计取向：内部业务系统，不追求视觉冲击，优先保证
     - 信息密度：主管一天要看几十条任务，行高与留白都要克制
     - 状态可读性：一眼能分清"待分派 / 待查询 / 可执行 / 已终结"
     - 弱依赖：手写 CSS，不引入 Bootstrap（说明书 7.6 的要求）
   ========================================================================== */

:root {
    --c-primary: #2563eb;
    --c-primary-dark: #1d4ed8;
    --c-primary-soft: #eff6ff;
    --c-success: #16a34a;
    --c-success-soft: #dcfce7;
    --c-danger: #dc2626;
    --c-danger-soft: #fee2e2;
    --c-warn: #d97706;
    --c-warn-soft: #fef3c7;

    --c-text: #111827;
    --c-text-sub: #4b5563;
    --c-text-mute: #9ca3af;
    --c-border: #e5e7eb;
    --c-border-strong: #d1d5db;
    --c-bg: #f6f7f9;
    --c-surface: #ffffff;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow: 0 1px 3px rgba(16, 24, 40, .1), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .1);
    --topbar-h: 56px;
}

* { box-sizing: border-box; }

/* hidden 属性必须真正隐藏。某些 display 规则（如 flex）会覆盖浏览器的默认样式，
   导致 hidden 失效——复制用的隐藏 textarea 一旦可见就会破坏布局。 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 14px;
    line-height: 1.6;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
                 "Noto Sans CJK SC", sans-serif;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   顶栏与导航
   -------------------------------------------------------------------------- */

.topbar {
    height: var(--topbar-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--c-text);
    white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--c-primary); }

.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: var(--radius);
    color: var(--c-text-sub);
    font-weight: 500;
    white-space: nowrap;
}
.nav-link:hover { background: var(--c-bg); color: var(--c-text); text-decoration: none; }
.nav-link.active { background: var(--c-primary-soft); color: var(--c-primary-dark); font-weight: 600; }
.nav-link .ico { font-size: 15px; }

.userbox { display: flex; align-items: center; gap: 8px; }

.chip {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    font-size: 12px;
    color: var(--c-text-sub);
    white-space: nowrap;
}
.chip-role { background: var(--c-primary-soft); border-color: #bfdbfe; color: var(--c-primary-dark); }

/* --------------------------------------------------------------------------
   布局
   -------------------------------------------------------------------------- */

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.page-title { font-size: 20px; font-weight: 700; margin: 0; }
.page-sub { color: var(--c-text-mute); font-size: 13px; margin: 4px 0 0; }

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--c-border);
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.footer {
    text-align: center;
    color: var(--c-text-mute);
    font-size: 12px;
    padding: 24px 20px 32px;
}

.muted { color: var(--c-text-mute); }
.text-sub { color: var(--c-text-sub); }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* --------------------------------------------------------------------------
   表格
   -------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table.data th,
table.data td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}

table.data th {
    background: #fafbfc;
    font-weight: 600;
    color: var(--c-text-sub);
    white-space: nowrap;
    font-size: 12px;
    letter-spacing: .02em;
}

table.data tbody tr:hover { background: #fafbfc; }
table.data tbody tr:last-child td { border-bottom: none; }

table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty {
    text-align: center;
    color: var(--c-text-mute);
    padding: 48px 20px;
}

/* --------------------------------------------------------------------------
   状态标签
   -------------------------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.7;
}

.badge-pending       { background: var(--c-warn-soft);   color: #92400e; }
.badge-querying      { background: var(--c-primary-soft); color: #1e40af; }
.badge-ready         { background: var(--c-success-soft); color: #166534; }
.badge-installed     { background: var(--c-success);      color: #fff; }
.badge-not-installed { background: var(--c-danger-soft);  color: #991b1b; }
.badge-rejected      { background: #e5e7eb;               color: #374151; }

/* --------------------------------------------------------------------------
   按钮
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--c-border-strong);
    background: var(--c-surface);
    color: var(--c-text);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    transition: background .12s, border-color .12s, transform .06s;
    font-family: inherit;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-dark); border-color: var(--c-primary-dark); }

.btn-success { background: var(--c-success); border-color: var(--c-success); color: #fff; }
.btn-success:hover { background: #15803d; border-color: #15803d; }

.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--c-text-sub); }
.btn-ghost:hover { background: var(--c-bg); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 14px 20px; font-size: 16px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }

/* --------------------------------------------------------------------------
   表单
   -------------------------------------------------------------------------- */

.form-row { margin-bottom: 16px; }

.form-row label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--c-text-sub);
    margin-bottom: 6px;
}

.form-row .req { color: var(--c-danger); margin-left: 2px; }
.form-row .hint { font-size: 12px; color: var(--c-text-mute); margin-top: 4px; }

input[type=text],
input[type=password],
input[type=date],
input[type=datetime-local],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    transition: border-color .12s, box-shadow .12s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

textarea { resize: vertical; min-height: 84px; line-height: 1.6; }

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 16px;
    border-top: 1px solid var(--c-border);
    margin-top: 20px;
    flex-wrap: wrap;
}

.form-narrow { max-width: 560px; }

.radio-group { display: flex; gap: 10px; flex-wrap: wrap; }

.radio-card {
    flex: 1;
    min-width: 140px;
    position: relative;
    display: block;
    border: 2px solid var(--c-border);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color .12s, background .12s;
}
.radio-card:hover { border-color: var(--c-border-strong); }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card .rc-title { font-weight: 600; }
.radio-card .rc-desc { font-size: 12px; color: var(--c-text-mute); margin-top: 2px; }
.radio-card:has(input:checked) { border-color: var(--c-primary); background: var(--c-primary-soft); }

.filter-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.filter-bar .filter-item { min-width: 150px; }
.filter-bar .filter-item label { font-size: 12px; }
.filter-bar .filter-actions { display: flex; gap: 8px; padding-bottom: 1px; }

/* --------------------------------------------------------------------------
   外勤列表顶部的搜索 / 任务状态筛选
   --------------------------------------------------------------------------
   外勤基本是手机单手操作，因此这一块刻意不用 .filter-bar：
   关键是"不折行"——输入框吃掉剩余宽度，按钮保持固定宽度，
   整行高度与输入框对齐（也方便对齐 44px 的触控目标）。
   -------------------------------------------------------------------------- */

.field-search { padding: 12px 14px; }
.field-search .fs-row { display: flex; gap: 8px; align-items: center; }
.field-search .fs-row + .fs-row { margin-top: 10px; }
.field-search input[type=search],
.field-search select { flex: 1; min-width: 0; }
.field-search .fs-label {
    font-size: 13px;
    color: var(--c-text-sub);
    white-space: nowrap;
}
.field-search .fs-tip {
    margin-top: 10px;
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 13px;
    color: var(--c-text-sub);
}
.field-search .fs-clear { white-space: nowrap; }

/* --------------------------------------------------------------------------
   提示条（flash）
   -------------------------------------------------------------------------- */

.flash {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid transparent;
}
.flash-success { background: var(--c-success-soft); border-color: #86efac; color: #14532d; }
.flash-error   { background: var(--c-danger-soft);  border-color: #fca5a5; color: #7f1d1d; }

.form-error {
    background: var(--c-danger-soft);
    border: 1px solid #fca5a5;
    color: #7f1d1d;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

.notice {
    background: var(--c-warn-soft);
    border: 1px solid #fcd34d;
    color: #78350f;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
}

/* --------------------------------------------------------------------------
   统计卡片
   -------------------------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stat {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}
.stat .stat-label { font-size: 12px; color: var(--c-text-mute); }
.stat .stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}
.stat.is-primary .stat-value { color: var(--c-primary); }
.stat.is-warn    .stat-value { color: var(--c-warn); }
.stat.is-success .stat-value { color: var(--c-success); }
.stat.is-danger  .stat-value { color: var(--c-danger); }
.stat.is-mute    .stat-value { color: var(--c-text-mute); }

/* 安装率进度条 */
.rate-bar {
    height: 6px;
    background: #eef0f3;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 6px;
    min-width: 80px;
}
.rate-bar > span { display: block; height: 100%; background: var(--c-success); }

/* --------------------------------------------------------------------------
   详情描述列表
   -------------------------------------------------------------------------- */

.dl { display: grid; grid-template-columns: 110px 1fr; gap: 10px 16px; font-size: 13px; }
.dl dt { color: var(--c-text-mute); }
.dl dd { margin: 0; color: var(--c-text); word-break: break-word; }

.section-block { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--c-border); }
.section-block:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.section-title { font-size: 13px; font-weight: 700; color: var(--c-text-sub); margin-bottom: 10px; }

/* --------------------------------------------------------------------------
   登录 / 注册
   -------------------------------------------------------------------------- */

.auth-wrap {
    /* 减去顶栏高度，避免登录页出现多余的纵向滚动条 */
    min-height: calc(100vh - var(--topbar-h));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px 56px;
    background: linear-gradient(160deg, #f8fafc 0%, #eef2ff 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
    padding: 32px 28px;
}

.auth-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.auth-sub { color: var(--c-text-mute); font-size: 13px; margin: 0 0 24px; }
.auth-foot { text-align: center; margin-top: 20px; font-size: 13px; color: var(--c-text-sub); }

/* --------------------------------------------------------------------------
   单列展示（外勤手机端复用）
   -------------------------------------------------------------------------- */

.task-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    display: block;
    color: inherit;
    margin-bottom: 12px;
}
.task-card:hover { text-decoration: none; border-color: var(--c-border-strong); }
.task-card .tc-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 8px;
}
.task-card .tc-name { font-weight: 700; font-size: 15px; }
.task-card .tc-line { font-size: 13px; color: var(--c-text-sub); }
.task-card .tc-foot { margin-top: 12px; display: flex; gap: 8px; }

/* --------------------------------------------------------------------------
   响应式：窄屏下把多列网格压成单列
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .container { padding: 14px; }
    .topbar { gap: 10px; padding: 0 12px; }
    .nav { gap: 2px; }
    .nav-link { padding: 6px 8px; font-size: 13px; }
    .nav-link .ico { display: none; }
}

/* --------------------------------------------------------------------------
   Toast 提示（由 app.js 动态插入）
   -------------------------------------------------------------------------- */

.tm-toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translate(-50%, 12px);
    max-width: min(90vw, 420px);
    padding: 12px 20px;
    border-radius: 10px;
    background: #111827;
    color: #fff;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .24);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
    z-index: 9999;
    text-align: center;
    word-break: break-word;
}

.tm-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.tm-toast[data-type="success"] { background: #15803d; }
.tm-toast[data-type="error"]   { background: #b91c1c; }

/* 外勤在手机上使用，toast 抬高一些避免被浏览器底栏遮挡 */
body.mobile .tm-toast { bottom: 56px; font-size: 15px; }

@media print {
    .topbar, .footer, .btn, .filter-bar, .form-actions, .tm-toast { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border-color: #ccc; }
}
