/* ============================================================
 * responsive.css —— 移动端 / 小屏适配（集中覆盖，桌面端不受影响）
 * 断点：≤1024 平板 · ≤768 手机横屏/大屏手机 · ≤560 普通手机 · ≤380 小屏手机
 * ============================================================ */

/* ---------------- 移动端骨架开关 ---------------- */
/* 汉堡按钮：仅窄屏显示 */
.nav-toggle { display: none; }
.nav-overlay { display: none; }

/* ============ 平板与以下：≤1024px ============ */
@media (max-width: 1024px) {
  /* 顶部栏：防止 flex 子项被挤压成竖排 */
  .topbar { gap: 10px; }
  .topbar-left, .topbar-right { min-width: 0; }
  .topbar-left > span,
  .topbar-right > * { white-space: nowrap; }
  .topbar-date { flex-shrink: 0; }
}

/* ============ 手机：≤768px ============ */
@media (max-width: 768px) {
  /* --- 侧边栏改为抽屉 --- */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 244px; flex-basis: 244px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(16, 24, 40, .28);
  }
  body.nav-open .sidebar { transform: translateX(0); }

  /* 抽屉打开时显示文字与徽章（覆盖 1024px 断点里的隐藏） */
  .sidebar .brand-text,
  .sidebar .nav-group-title,
  .sidebar .nav-item span:not(.nav-icon),
  .sidebar .nav-badge,
  .sidebar .sidebar-footer { display: block; }
  .sidebar .brand { justify-content: flex-start; padding: 0 20px; }
  .sidebar .nav-item { justify-content: flex-start; padding: 9px 12px; }
  .sidebar .nav-badge { display: flex; margin-left: auto; }

  /* 遮罩层 */
  .nav-overlay {
    display: block;
    position: fixed; inset: 0; z-index: 25;
    background: rgba(16, 24, 40, .5);
    opacity: 0; visibility: hidden;
    transition: opacity .25s, visibility .25s;
  }
  body.nav-open .nav-overlay { opacity: 1; visibility: visible; }
  body.nav-open { overflow: hidden; }

  /* --- 顶部栏 --- */
  .nav-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex-shrink: 0;
    border: 1px solid var(--border); background: #fff;
    border-radius: 9px; cursor: pointer; color: var(--text-2);
  }
  .nav-toggle svg { width: 19px; height: 19px; }
  .topbar { padding: 0 14px; height: 56px; }
  .topbar-left { flex: 1; }
  .topbar-left .crumb-root, .topbar-left .crumb-sep { display: none; }
  .crumb-current { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* 手机隐藏日期，避免挤压 */
  .topbar-date { display: none; }
  .topbar-right { gap: 8px; }
  .icon-btn { width: 34px; height: 34px; }
  .user-chip { padding: 4px; }
  .user-chip .user-meta { display: none; }

  /* popover 在窄屏内收，避免超出右边界 */
  .popover { right: 12px; max-width: calc(100vw - 24px); }
  .popover.user-popover { width: min(262px, calc(100vw - 24px)); }

  /* --- 内容区 --- */
  .content { padding: 16px 14px 32px; }

  /* 页面标题：纵向排列，按钮不被挤压 */
  .page-header { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 18px; }
  .page-title { font-size: 20px; }
  .page-subtitle { line-height: 1.6; }
  .page-actions { width: 100%; display: flex; flex-wrap: wrap; }
  .page-actions .btn { flex: 1 1 auto; min-height: 38px; }

  /* 统计卡片：两列（手机单列过长的折中） */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 25px; }
  .stat-icon { width: 32px; height: 32px; }
  .stat-icon svg { width: 16px; height: 16px; }
  .stat-bottom { font-size: 10.5px; flex-wrap: wrap; }

  /* 图表行、网格：单列 */
  .chart-row, .grid-2, .grid-3 { grid-template-columns: 1fr !important; gap: 12px; }
  .panel-header { padding: 13px 14px; }
  .panel-body { padding: 14px; }
  .panel-body.tight { padding: 6px 12px !important; }
  .panel-header h2 { font-size: 14px; }

  /* 筛选栏：搜索框占满一行 */
  .filter-bar { gap: 8px; }
  .search-box { flex: 1 1 100%; }
  .filter-bar .form-select { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filter-spacer { display: none; }

  /* 表格：保持横向滚动，但缩小单元格内边距 */
  .data-table { min-width: 720px; }
  .data-table th, .data-table td { padding: 9px 11px; font-size: 12px; }

  /* 弹窗：底部弹出，圆角只保留上方 */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100% !important; width: 100%;
    max-height: 92vh; border-radius: 16px 16px 0 0;
    animation: sheetIn .25s ease;
  }
  @keyframes sheetIn { from { transform: translateY(30px); opacity: .7; } to { transform: none; opacity: 1; } }
  .modal-header { padding: 15px 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .modal-footer .btn { flex: 1; }

  /* 表单/详情：单列 */
  .form-grid, .detail-grid { grid-template-columns: 1fr; gap: 14px; }
  .form-field.span-2 { grid-column: span 1; }
  .wo-detail-head { flex-direction: column; }

  /* toast 避免贴顶遮挡 */
  #toast-box { top: 12px; width: calc(100% - 32px); }
  .toast { max-width: 100%; }
}

/* ============ 普通手机：≤560px ============ */
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 23px; }
  .stat-label { font-size: 12px; }
  .page-title { font-size: 19px; }
  .content { padding: 14px 12px 28px; }
  .donut-wrap { gap: 10px; }
  .legend { min-width: 90px; }
  .timeline { padding-left: 20px; }
}

/* ============ 小屏手机：≤380px ============ */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 21px; }
  .stat-hint { display: none; }
  .topbar { padding: 0 10px; }
  .topbar-right { gap: 6px; }
  .icon-btn { width: 32px; height: 32px; }
}

/* ============================================================
 * 登录页移动端补充（login.css 已有基础响应式，这里做细节增强）
 * ============================================================ */
@media (max-width: 560px) {
  .login-card { padding: 26px 22px 20px; border-radius: 14px; }
  .card-title { font-size: 23px; margin-bottom: 20px; }
  .login-form .input-wrap { height: 44px; margin-bottom: 13px; }
  .submit-btn { height: 44px; }
  .demo-hint { gap: 5px; }
  .demo-chip { padding: 3px 7px; }
}
@media (max-height: 700px) {
  /* 矮屏（如横屏手机）：登录卡片压缩，允许滚动兜底 */
  body:has(.login-card) { overflow-y: auto; }
  .login-stage { min-height: auto; padding-top: 18px; padding-bottom: 18px; }
  .login-card { padding-top: 20px; padding-bottom: 18px; }
}

/* ============================================================
 * 登录首页：布局/文本可编辑功能（标语 / 地图 / 横线）
 * ============================================================ */
/* 标语定位基准改为百分比左上角 + 位移；保留 translateY(-50%) 语义 */
#hero-copy.hero-copy {
  left: 15%; top: 50%;
  transform: translateY(-50%);
  pointer-events: auto;            /* 允许拖拽 */
  transition: none;
}
/* 标语入场动画结束位置用 translateY(-50%)，避免覆盖定位 */
#hero-copy.hero-copy { animation: none; }

/* 标语拖拽小手柄：默认隐藏，编辑模式显示 */
.drag-handle {
  position: absolute; top: -14px; left: -14px;
  width: 26px; height: 26px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2f7ae8, #1d5fc4);
  border: 1px solid rgba(180,230,255,.85);
  color: #fff; font-size: 13px; cursor: grab; user-select: none;
  box-shadow: 0 4px 14px rgba(0,10,40,.5); z-index: 6;
}
.layout-editing .drag-handle { display: flex; pointer-events: auto; }
.drag-handle.dragging, .scene-handle.dragging { cursor: grabbing; }

/* 画布元素拖拽控制层：默认不拦截事件 */
.scene-drag-layer { position: fixed; inset: 0; z-index: 6; pointer-events: none; display: none; }
.scene-drag-layer.active { display: block; }
.scene-handle {
  position: absolute; pointer-events: auto; touch-action: none;
  display: flex; align-items: center; justify-content: center;
  cursor: grab; user-select: none;
}
.scene-handle > span {
  opacity: 0; transition: opacity .15s;
  font-size: 11px; color: #fff; white-space: nowrap;
  padding: 4px 9px; border-radius: 14px;
  background: rgba(12,52,110,.9); border: 1px solid rgba(150,220,255,.55);
  text-shadow: 0 1px 4px rgba(0,10,40,.8);
}
.scene-handle:hover > span { opacity: 1; }
/* 地球手柄：圆形虚线圈，跟随球体 */
.globe-handle {
  border: 1.5px dashed rgba(120,220,255,.75);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(60,180,255,.08), rgba(60,180,255,0) 70%);
  box-shadow: 0 0 24px rgba(80,200,255,.18) inset;
}
/* 横线手柄：细长条，沿整行 */
.line-handle {
  left: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 1100px); height: 18px;
  border-top: 1px dashed rgba(120,220,255,.7);
  border-bottom: 1px dashed rgba(120,220,255,.35);
  background: rgba(80,200,255,.05);
}

/* 编辑模式：给可编辑元素加柔和轮廓提示 */
.layout-editing #hero-copy.hero-copy {
  outline: 1px dashed rgba(130,220,255,.5);
  outline-offset: 8px;
  border-radius: 4px;
}

/* 编辑工具条：固定在顶部栏下方居中 */
.page-edit-bar {
  position: fixed; z-index: 22; top: 74px; left: 50%; transform: translateX(-50%);
  display: none; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 24px;
  background: rgba(6,24,58,.86); border: 1px solid rgba(130,210,255,.4);
  box-shadow: 0 10px 30px rgba(0,8,30,.5); backdrop-filter: blur(8px);
}
body.layout-editing .page-edit-bar { display: flex; }
.pe-btn {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; flex-shrink: 0;
  height: 30px; padding: 0 13px; border-radius: 16px; cursor: pointer;
  border: 1px solid rgba(150,220,255,.35); background: rgba(30,100,190,.4);
  color: #e6f4ff; font-size: 12px; transition: background .15s, transform .15s;
}
.pe-btn i { font-style: normal; font-size: 13px; }
.pe-btn:hover { background: rgba(48,130,230,.7); transform: translateY(-1px); }
.pe-save { background: linear-gradient(135deg, #2f7ae8, #1d5fc4); border-color: rgba(190,235,255,.65); font-weight: 600; }
.pe-save:hover { background: linear-gradient(135deg, #3f8af5, #2f7ae8); }
/* 状态提示独立到工具条下方，避免挤占按钮导致文字竖排 */
.pe-status {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 11px; padding: 3px 10px; border-radius: 12px;
  background: rgba(6,24,58,.8); border: 1px solid rgba(130,210,255,.25);
  color: #bcd8f5;
}
.pe-status:empty { display: none; }
.pe-status.ok { color: #7ff0b0; }
.pe-status.error { color: #ff9a9a; }
.pe-status.dirty { color: #ffd479; }
.pe-status.busy { color: #9fd4ff; }

/* 文本编辑弹窗复用 editor-card 样式 */
.content-editor {
  position: fixed; inset: 0; z-index: 31;
  background: rgba(2,9,26,.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.content-editor[hidden] { display: none; }

@media (max-width: 560px) {
  .page-edit-bar { top: 62px; gap: 6px; padding: 6px 8px; max-width: 96vw; }
  .pe-btn { height: 30px; padding: 0 11px; font-size: 11.5px; }
  .pe-btn i { font-size: 12px; }
  .pe-status { font-size: 10.5px; top: calc(100% + 5px); }
  /* 不用 !important，否则会覆盖 JS 写入的行内定位，导致标语横向拖不动、刷新后位置错乱 */
  #hero-copy.hero-copy { max-width: 88vw; }
  .line-handle { width: 94vw; }
}

/* ============================================================
 * 窄屏自适应骨架（≤1280px）：由 fixed 叠层改为纵向文档流，可滚动
 *  - 顶部品牌栏 / 主舞台 / 面板 / 页脚 按自然文档流自上而下排列
 *  - 视频窗口(16:9) 与 今日重点工作 均为响应式宽度、居中、不再重叠
 * ============================================================ */
@media (max-width: 1280px) {
  html, body { height: auto; }
  body {
    min-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* 把 body 变成纵向 flex 容器，实现面板自适应堆叠与滚动 */
  body:has(#video-panel) { display: flex; flex-direction: column; }
  /* 顶部品牌栏：随文档流，排最前 */
  .login-header { position: relative; order: 0; flex: none; }
  /* 主舞台与标语：窄屏隐藏，画布背景仍在 canvas 上 */
  .login-stage { display: none !important; }
  .hero-copy { display: none !important; }
  /* 快捷图标：窄屏与视频面板争用空间，隐藏（自定义图标入口仍在页脚可编辑） */
  .quick-links { display: none !important; }
  /* 场景拖拽层：窄屏画布手柄无意义 */
  .scene-drag-layer { display: none !important; }
  /* 视频在前、今日工作在后，均居中堆叠 */
  #video-panel { order: 1; margin-top: 16px; }
  #focus-panel { order: 2; margin-bottom: 18px; }
  .login-footer { order: 3; margin-top: auto; flex: none; }
  /* 编辑工具条：窄屏按钮过多时自动换行、居中，避免溢出 */
  .page-edit-bar { flex-wrap: wrap; justify-content: center; max-width: 96vw; }
  .pe-status { text-align: center; }
}

/* 手机竖屏精细微调 */
@media (max-width: 560px) {
  .login-header { height: 58px; }
  .login-stage { padding: 4px 0 2px; }
  .footer-links { flex-wrap: wrap; justify-content: center; row-gap: 6px; }
  .footer-links .sep { display: none; }
  .login-footer { height: auto; padding: 10px 0 14px; gap: 7px; }
}
