/* ==========================================================================
   CNCService 主样式 —— 移动优先
   规范：1rem = 16px；颜色变量集中在 :root，改主题只改这里
   ========================================================================== */
:root {
    --brand: #1d4ed8;
    --brand-dark: #1e3a8a;
    --brand-light: #eff6ff;
    --accent: #0f766e;
    --danger: #dc2626;
    --warn: #ea8c00;
    --ok: #0d9488;
    --text: #1f2937;
    --text-2: #6b7280;
    --text-3: #9ca3af;
    --line: #e5e7eb;
    --bg: #f4f6fb;
    --card: #ffffff;
    --radius: 12px;
    --shadow: 0 2px 10px rgba(30, 41, 59, .06);
    --shadow-lg: 0 10px 30px rgba(30, 41, 59, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
                 "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
input, select, textarea, button { font-family: inherit; font-size: 15px; }

/* ---------------- 顶部栏 ---------------- */
.topbar {
    position: sticky; top: 0; z-index: 50;
    height: 54px;
    background: linear-gradient(135deg, var(--brand-dark), var(--brand));
    color: #fff;
    display: flex; align-items: center;
    padding: 0 14px;
    box-shadow: 0 2px 8px rgba(30, 58, 138, .25);
}
.topbar .logo {
    width: 30px; height: 30px; border-radius: 8px;
    background: rgba(255, 255, 255, .18);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; margin-right: 9px;
}
.topbar .title { font-size: 16px; font-weight: 600; letter-spacing: .5px; flex: 1;
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who { font-size: 12px; opacity: .9; text-align: right; line-height: 1.3; }
.topbar .who b { display: block; font-size: 13px; font-weight: 600; }
.topbar .back { color: #fff; font-size: 20px; margin-right: 10px; line-height: 1; }

/* ---------------- 底部 tabbar ---------------- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff;
    border-top: 1px solid var(--line);
    display: flex;
    box-shadow: 0 -2px 10px rgba(30, 41, 59, .05);
}
.tabbar a {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-3); font-size: 11px; gap: 2px;
}
.tabbar a .ico { font-size: 19px; line-height: 1; }
.tabbar a.active { color: var(--brand); font-weight: 600; }

.main {
    padding: 12px 12px calc(72px + env(safe-area-inset-bottom));
    max-width: 900px; margin: 0 auto;
}
.main.no-tab { padding-bottom: 24px; }

/* ---------------- 卡片 ---------------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 12px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
}
.card-head h3 { font-size: 15px; }
.card-head .more { font-size: 13px; color: var(--text-3); }

/* ---------------- 统计格 ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-grid.two { grid-template-columns: repeat(2, 1fr); }
.stat-grid.three { grid-template-columns: repeat(3, 1fr); }
.stat {
    background: #fff; border-radius: 10px; padding: 12px 8px; text-align: center;
    box-shadow: var(--shadow);
}
.stat .n { font-size: 22px; font-weight: 700; line-height: 1.2; color: var(--brand); }
.stat .l { font-size: 11px; color: var(--text-3); margin-top: 3px; }
.stat.warn .n { color: var(--warn); }
.stat.danger .n { color: var(--danger); }
.stat.ok .n { color: var(--ok); }

/* ---------------- 列表 ---------------- */
.list { display: flex; flex-direction: column; }
.item {
    display: block;
    padding: 12px 0;
    border-bottom: 1px solid #f1f3f7;
}
.item:last-child { border-bottom: none; }
.item .row1 { display: flex; align-items: center; gap: 8px; }
.item .t { font-size: 15px; font-weight: 600; flex: 1;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 12.5px; color: var(--text-2); margin-top: 5px; line-height: 1.55; }
.item .meta { font-size: 12px; color: var(--text-3); margin-top: 6px;
              display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- 徽章 ---------------- */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11.5px; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.badge.gray  { background: #f1f5f9; color: #64748b; }
.badge.red   { background: #fef2f2; color: var(--danger); }
.badge.orange{ background: #fff7ed; color: var(--warn); }
.badge.blue  { background: #eff6ff; color: var(--brand); }
.badge.green { background: #f0fdfa; color: var(--ok); }
.badge.purple{ background: #f5f3ff; color: #7c3aed; }

/* ---------------- 表单 ---------------- */
.form-row { margin-bottom: 14px; }
.form-row > label {
    display: block; font-size: 13px; color: var(--text-2);
    margin-bottom: 6px; font-weight: 500;
}
.form-row > label .req { color: var(--danger); margin-left: 2px; }
.input, select.input, textarea.input {
    width: 100%; height: 44px;
    border: 1px solid var(--line); border-radius: 10px;
    padding: 0 12px; background: #fbfcfe; color: var(--text);
    outline: none; transition: .15s;
}
textarea.input { height: auto; min-height: 88px; padding: 10px 12px; line-height: 1.6; resize: vertical; }
.input:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(29, 78, 216, .1); }
.input[readonly] { background: #f8fafc; color: var(--text-2); }
.hint { font-size: 12px; color: var(--text-3); margin-top: 5px; }

/* 分段选择 */
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg input { display: none; }
.seg label {
    flex: 1; min-width: 72px; text-align: center;
    padding: 10px 8px; border-radius: 10px;
    border: 1px solid var(--line); background: #fbfcfe;
    font-size: 13.5px; color: var(--text-2); cursor: pointer;
}
.seg input:checked + label {
    border-color: var(--brand); background: var(--brand-light);
    color: var(--brand); font-weight: 600;
}

/* ---------------- 按钮 ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    height: 44px; padding: 0 20px; border-radius: 10px;
    border: 1px solid var(--line); background: #fff; color: var(--text);
    font-size: 15px; font-weight: 500; cursor: pointer; gap: 6px;
}
.btn-block { width: 100%; }
.btn-primary {
    background: linear-gradient(135deg, var(--brand), #2563eb);
    color: #fff; border: none;
    box-shadow: 0 4px 14px rgba(29, 78, 216, .25);
}
.btn-primary:active { transform: translateY(1px); }
.btn-ghost { border-color: var(--brand); color: var(--brand); background: #fff; }
.btn-danger { border-color: #fecaca; color: var(--danger); background: #fff; }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-bar { display: flex; gap: 10px; margin-top: 16px; }
.btn-bar .btn { flex: 1; }

/* ---------------- 表格（桌面端） ---------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tb { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
table.tb th {
    text-align: left; color: var(--text-3); font-weight: 500;
    padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
    background: #fafbfd;
}
table.tb td { padding: 11px 10px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
table.tb tr:last-child td { border-bottom: none; }
table.tb tr:hover td { background: #fafcff; }

/* ---------------- 详情 ---------------- */
.kv { display: flex; padding: 9px 0; border-bottom: 1px dashed #eef1f6; font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv .k { width: 92px; flex: 0 0 92px; color: var(--text-3); font-size: 13px; }
.kv .v { flex: 1; word-break: break-all; }
.kv .v.mono { font-family: ui-monospace, Consolas, monospace; }

/* ---------------- 提示条 ---------------- */
.alert { border-radius: 10px; padding: 11px 13px; font-size: 13.5px; margin-bottom: 12px; line-height: 1.6; }
.alert.err  { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert.ok   { background: #f0fdfa; color: #0f766e; border: 1px solid #99f6e4; }
.alert.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert.warn { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

/* ---------------- 空状态 ---------------- */
.empty { text-align: center; color: var(--text-3); padding: 40px 0; font-size: 14px; }
.empty .ico { font-size: 34px; display: block; margin-bottom: 10px; opacity: .5; }

/* ---------------- 登录页 ---------------- */
.login-wrap {
    min-height: 100vh; display: flex; flex-direction: column;
    background: linear-gradient(160deg, #1e3a8a 0%, #1d4ed8 45%, #3b82f6 100%);
    padding: 0 22px;
}
.login-head { padding: 64px 0 34px; color: #fff; text-align: center; }
.login-head .mark {
    width: 62px; height: 62px; margin: 0 auto 16px;
    border-radius: 18px; background: rgba(255, 255, 255, .16);
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 700; letter-spacing: 1px;
    border: 1px solid rgba(255, 255, 255, .25);
}
.login-head h1 { font-size: 21px; letter-spacing: 1px; }
.login-head p { margin: 8px 0 0; font-size: 13px; opacity: .8; }
.login-card {
    background: #fff; border-radius: 18px; padding: 22px 18px 20px;
    box-shadow: var(--shadow-lg);
}
.login-card .form-row > label { font-size: 12.5px; }
.login-foot { text-align: center; color: rgba(255, 255, 255, .7); font-size: 12px; padding: 26px 0 30px; }

/* ---------------- 签字板 ---------------- */
.sign-box {
    border: 1px dashed #c7d2fe; border-radius: 12px;
    background: #fbfdff; overflow: hidden; position: relative;
}
.sign-box canvas { display: block; width: 100%; height: 200px; touch-action: none; background: #fbfdff; }
.sign-tip {
    position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
    text-align: center; color: #c7d2fe; font-size: 14px; pointer-events: none;
}
.sign-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------------- 打印 ---------------- */
@media print {
    .topbar, .tabbar, .btn-bar, .no-print, .sign-actions { display: none !important; }
    body { background: #fff; font-size: 12pt; }
    .main { padding: 0; max-width: none; }
    .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; margin-bottom: 10px; }
    .print-title { display: block !important; text-align: center; margin-bottom: 12px; }
    .print-title h2 { font-size: 18pt; letter-spacing: 4px; }
}
.print-title { display: none; }

/* ---------------- 桌面端 ---------------- */
@media (min-width: 768px) {
    body { font-size: 14px; }
    .main { padding: 18px 18px 90px; }
    .tabbar { display: none; }
    .main { max-width: 1180px; }
    .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
    .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
    .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
    .form-grid .full { grid-column: 1 / -1; }
}

/* ---------------- 照片上传 ---------------- */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}
.photo-item {
    position: relative;
    padding-top: 100%;
    border-radius: 10px;
    overflow: hidden;
    background: #f1f5f9;
    border: 1px solid var(--line);
}
.photo-item img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.photo-item .del {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 14px;
    line-height: 22px;
    text-align: center;
    cursor: pointer;
    user-select: none;
}
.photo-item .del:active { background: rgba(220, 38, 38, .85); }
.photo-add {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    border: 1px dashed #c7d2fe;
    border-radius: 10px;
    color: var(--brand);
    background: #fbfdff;
    font-size: 14px;
    cursor: pointer;
}
.photo-add:active { background: #eef4ff; }
.photo-view {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.photo-view a { display: block; padding-top: 100%; position: relative; border-radius: 10px; overflow: hidden; background: #f1f5f9; }
.photo-view img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
