/* ========== 基础重置 ========== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --c-brand: #2563eb;
    --c-brand-light: #3b82f6;
    --c-brand-bg: #eff6ff;
    --c-green: #16a34a;
    --c-red: #dc2626;
    --c-orange: #ea580c;
    --c-text: #1e293b;
    --c-text2: #64748b;
    --c-text3: #94a3b8;
    --c-bg: #f1f5f9;
    --c-white: #ffffff;
    --c-border: #e2e8f0;
    --c-border2: #cbd5e1;
    --r: 8px;
    --r-lg: 14px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    line-height: 1.5;
    font-size: 15px;
}

/* ========== 顶部栏 ========== */
.header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--c-white);
    border-bottom: 1px solid var(--c-border);
    position: relative;
    z-index: 100;
    flex-wrap: wrap;
}

.header-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--c-text);
    white-space: nowrap;
    margin-right: 4px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
}

.office-select {
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--r);
    font-size: 14px;
    color: var(--c-text);
    background: var(--c-white);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    cursor: pointer;
    min-width: 140px;
}

.office-select:focus { outline: none; border-color: var(--c-brand); }

/* ========== 按钮 ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--r);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .15s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .7; }

.btn-sm { padding: 6px 10px; font-size: 13px; }

.btn-primary { background: var(--c-brand); color: #fff; }
.btn-green { background: var(--c-green); color: #fff; }
.btn-red { background: var(--c-red); color: #fff; }
.btn-ghost {
    background: transparent;
    color: var(--c-text2);
    border: 1px solid var(--c-border);
}
.btn-ghost:active { background: var(--c-bg); }

/* ========== 主内容区 ========== */
.main-content {
    height: calc(100vh - 52px);
    height: calc(100dvh - 52px);
    overflow: hidden;
}

.view { display: none; height: 100%; }
.view.active { display: flex; flex-direction: column; }

/* ========== 工具栏 ========== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--c-white);
    border-bottom: 1px solid var(--c-border);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.toolbar-hint {
    margin-left: auto;
    font-size: 13px;
    color: var(--c-text3);
}

.zoom-ctrl {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--c-bg);
    padding: 2px 6px;
    border-radius: var(--r);
}
.zoom-ctrl span {
    font-size: 12px;
    color: var(--c-text2);
    min-width: 36px;
    text-align: center;
    font-weight: 600;
}

.chk-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--c-text2);
    cursor: pointer;
}
.chk-label input { width: 16px; height: 16px; accent-color: var(--c-brand); }

/* ========== 画布 ========== */
.layout-canvas {
    flex: 1;
    position: relative;
    overflow: auto;
    background: var(--c-white);
    background-image: radial-gradient(circle, #e2e8f0 1px, transparent 1px);
    background-size: 20px 20px;
    cursor: grab;
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}
.layout-canvas:active { cursor: grabbing; }

.layout-canvas-inner {
    position: relative;
    width: 4000px;
    height: 4000px;
}

/* ========== 工位卡片 ========== */
.ws-card {
    position: absolute;
    width: 110px;
    padding: 10px 8px;
    background: var(--c-white);
    border: 2px solid var(--c-brand);
    border-radius: var(--r);
    text-align: center;
    cursor: move;
    user-select: none;
    touch-action: none;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    transition: box-shadow .15s;
}
.ws-card:active { box-shadow: 0 4px 12px rgba(0,0,0,.12); }

.ws-card.dragging { opacity: .85; z-index: 999; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.ws-card.delete-mode { border-color: var(--c-red); animation: shake .4s infinite; }

.ws-name { font-size: 14px; font-weight: 600; color: var(--c-text); line-height: 1.3; }
.ws-owner { font-size: 12px; color: var(--c-text2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-badges { display: flex; gap: 3px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }
.ws-badge {
    width: 8px; height: 8px; border-radius: 50%;
}
.ws-badge.computer { background: #22c55e; }
.ws-badge.monitor { background: #3b82f6; }
.ws-badge.laptop { background: #f59e0b; }
.ws-badge.printer { background: #a855f7; }
.ws-badge.phone { background: #06b6d4; }
.ws-badge.custom { background: #f97316; }

.ws-photo-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: #f59e0b;
    border-radius: 50%;
}

@keyframes shake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* ========== 报表视图 ========== */
#reportView.active {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    gap: 16px;
}

.rpt-title { font-size: 20px; font-weight: 700; }
.rpt-subtitle { font-size: 13px; color: var(--c-text2); margin-top: 2px; }

.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.stat-box {
    background: var(--c-white);
    border: 1px solid var(--c-border);
    border-radius: var(--r);
    padding: 14px 10px;
    text-align: center;
}
.stat-num { font-size: 26px; font-weight: 700; color: var(--c-brand); }
.stat-lbl { font-size: 12px; color: var(--c-text2); margin-top: 2px; }

.rpt-section {
    background: var(--c-white);
    border: 1px solid var(--c-border);
    border-radius: var(--r);
    overflow: hidden;
}
.rpt-section-title {
    font-size: 15px;
    font-weight: 600;
    padding: 12px 14px;
    border-bottom: 1px solid var(--c-border);
    background: #f8fafc;
}

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--c-border); }
.tbl th { background: #f8fafc; font-weight: 600; color: var(--c-text2); font-size: 12px; }
.tbl tr:last-child td { border-bottom: none; }

.tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ========== 弹窗 ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0,0,0,.4);
}
.modal.active { display: flex; justify-content: center; align-items: flex-end; }

/* 资产弹窗和相机弹窗叠在工位弹窗上方 */
#assetModal { z-index: 2100; }
#cameraModal { z-index: 2200; }

.modal-box {
    background: var(--c-white);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    display: flex;
    flex-direction: column;
    animation: slideUp .25s ease;
    overflow: hidden;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-hd {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
}
.modal-hd h3 { font-size: 16px; font-weight: 600; }
.modal-close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--c-bg);
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--c-text2);
}

.modal-bd {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px;
    touch-action: pan-y;
}

.modal-ft {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--c-border);
    background: #fafbfc;
    flex-shrink: 0;
}
.modal-ft .btn { flex: 1; padding: 10px; }

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .modal-ft { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* ========== 表单 ========== */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--c-text2); margin-bottom: 4px; }
.field-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--r);
    font-size: 15px;
    color: var(--c-text);
    background: var(--c-white);
    -webkit-appearance: none;
}
.field-input:focus { outline: none; border-color: var(--c-brand); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea.field-input { resize: vertical; min-height: 64px; }
select.field-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ========== 照片区 ========== */
.photo-box {
    border: 2px dashed var(--c-border2);
    border-radius: var(--r);
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 8px;
    background: #fafbfc;
}
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-box .placeholder { color: var(--c-text3); font-size: 13px; }

.photo-btns { display: flex; gap: 6px; }

/* ========== 工位编辑布局 ========== */
.ws-edit-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

/* ========== 资产列表 ========== */
.assets-hd {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-top: 14px;
    border-top: 1px solid var(--c-border);
}
.assets-hd h4 { font-size: 15px; font-weight: 600; }

.asset-list { display: flex; flex-direction: column; gap: 8px; }

.asset-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--c-bg);
    border-radius: var(--r);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.asset-row:active { background: #e2e8f0; }

.asset-ico {
    width: 36px;
    height: 36px;
    border-radius: var(--r);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.asset-ico.computer { background: #dcfce7; }
.asset-ico.monitor { background: #dbeafe; }
.asset-ico.laptop { background: #fef3c7; }
.asset-ico.printer { background: #f3e8ff; }
.asset-ico.phone { background: #cffafe; }
.asset-ico.custom { background: #ffedd5; }

.asset-meta { flex: 1; min-width: 0; }
.asset-meta-type { font-size: 14px; font-weight: 600; }
.asset-meta-desc { font-size: 12px; color: var(--c-text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.asset-arrow { color: var(--c-text3); font-size: 18px; }

.empty-tip { text-align: center; padding: 24px; color: var(--c-text3); font-size: 14px; }

/* ========== 相机 ========== */
#cameraVideo { width: 100%; border-radius: var(--r); }
.cam-btns { display: flex; justify-content: center; gap: 10px; margin-top: 12px; }

/* ========== PDF隐藏渲染容器 ========== */
#pdfContainer {
    position: fixed;
    left: -9999px;
    top: 0;
    width: 800px;
    background: #fff;
    font-size: 14px;
    color: #1e293b;
    line-height: 1.6;
    padding: 40px;
}
#pdfContainer h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
#pdfContainer .pdf-date { text-align: center; color: #64748b; font-size: 13px; margin-bottom: 24px; }
#pdfContainer h2 { font-size: 16px; margin: 20px 0 8px; padding-bottom: 6px; border-bottom: 2px solid #e2e8f0; }
#pdfContainer table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
#pdfContainer th, #pdfContainer td { padding: 8px 10px; border: 1px solid #e2e8f0; font-size: 13px; text-align: left; }
#pdfContainer th { background: #f1f5f9; font-weight: 600; }
#pdfContainer .ws-section { margin-bottom: 20px; page-break-inside: avoid; }
#pdfContainer .ws-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; color: #334155; }
#pdfContainer .ws-photo { width: 120px; height: 90px; object-fit: cover; border-radius: 4px; border: 1px solid #e2e8f0; }
#pdfContainer .asset-photo-sm { width: 60px; height: 45px; object-fit: cover; border-radius: 3px; }

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .header { padding: 8px 12px; gap: 8px; }
    .header-title { font-size: 15px; }
    .header-actions { gap: 6px; }
    .office-select { min-width: 0; flex: 1; font-size: 13px; padding: 6px 28px 6px 10px; }
    .btn { padding: 7px 10px; font-size: 13px; }
    .btn-sm { padding: 5px 8px; font-size: 12px; }

    .toolbar { padding: 8px 12px; gap: 6px; }
    .toolbar-hint { display: none; }

    .ws-card { width: 80px; padding: 6px 4px; }
    .ws-name { font-size: 12px; }
    .ws-owner { font-size: 10px; }
    .ws-badges { margin-top: 4px; }
    .ws-badge { width: 6px; height: 6px; }

    .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-box { padding: 10px 6px; }
    .stat-num { font-size: 20px; }
    .stat-lbl { font-size: 11px; }

    #reportView.active { padding: 12px; gap: 12px; }
    .rpt-title { font-size: 17px; }

    .tbl th, .tbl td { padding: 8px 8px; font-size: 12px; }

    .modal-box { max-height: 92vh; max-height: 92dvh; max-width: 100%; }
    .modal-bd { padding: 12px; }
    .modal-ft { padding: 10px 12px; }

    .ws-edit-grid { grid-template-columns: 1fr; gap: 12px; }
    .photo-box { height: 100px; }

    .field { margin-bottom: 10px; }
    .field-input { padding: 9px 10px; font-size: 14px; }
}

@media (max-width: 480px) {
    .tbl th, .tbl td { padding: 6px 6px; font-size: 11px; }
}

/* 触摸设备 */
@media (hover: none) {
    .ws-card:active { box-shadow: 0 4px 12px rgba(0,0,0,.12); }
}

/* 打印样式 */
@media print {
    .header, .toolbar { display: none !important; }
    #layoutView { display: none !important; }
    #reportView { display: block !important; overflow: visible !important; }
}
