/* 报表门户样式（零依赖，不引外网字体 / 图标）
   布局对齐老版：左侧报表区自适应铺满，右侧是可收起的模板面板（操作栏在面板顶部） */

:root {
  --border: #e3e6eb;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #23262b;
  --muted: #7b838e;
  --primary: #2b6cb0;
  --primary-dark: #235a94;
  --danger: #c0392b;
  --active-bg: #eaf2fb;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ---------------- 整体：左报表 + 右面板 ---------------- */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.viewer {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--panel);
}

.viewer iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--panel);
}

/* 注意：.placeholder 设了 display:flex，会盖掉浏览器对 hidden 属性的 display:none，
   必须显式处理，否则 placeholder.hidden = true 无效、占位层会一直遮住 iframe */
.placeholder[hidden] { display: none; }

/* 收起后的“展开”标签 */
.handle {
  display: none;
  position: absolute;
  top: 12px;
  right: 0;
  z-index: 5;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: 4px 0 0 4px;
  background: var(--panel);
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
}

body.sidebar-collapsed .handle { display: block; }
body.sidebar-collapsed .sidebar { display: none; }

/* ---------------- 右侧模板面板 ---------------- */
.sidebar {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

.sidebar-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-head h2 { margin: 0; font-size: 14px; }

.factory { color: var(--muted); font-size: 12px; }

.count { color: var(--muted); font-size: 12px; }

.collapse {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
}

.collapse:hover { text-decoration: underline; }

.sidebar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

/* ---------------- 按钮 ---------------- */
.btn {
  padding: 5px 12px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; background: var(--primary); }

.btn.ghost { background: #fff; color: var(--primary); }
.btn.ghost:hover { background: var(--active-bg); }
.btn.ghost:disabled { background: #fff; }

/* 未解锁 / 已解锁的显示控制：用 body.unlocked 切换（不用 hidden 属性，
   因为 .lock 与 .admin-actions 设了 display，会盖掉浏览器对 hidden 的 display:none） */
.lock {
  display: none;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  background: #fff7e6;
  color: #a86a00;
  font-size: 12px;
}

.admin-actions { display: none; }

body.unlocked .admin-actions { display: flex; }
body.unlocked .lock { display: inline-flex; }
body.unlocked #btn-unlock { display: none; }

.link {
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0 0 0 6px;
}

/* ---------------- 模板列表 ---------------- */
.template-list {
  flex: 1 1 auto;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
}

.template-item {
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.template-item:hover { background: var(--active-bg); }
.template-item.active { background: var(--active-bg); box-shadow: inset 2px 0 0 var(--primary); }

.template-item .name { display: block; word-break: break-all; }
.template-item .meta { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.empty { margin: 16px; color: var(--muted); text-align: center; }

/* ---------------- 轻提示 ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  max-width: 70vw;
  padding: 9px 16px;
  border-radius: 4px;
  background: #23262b;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
  z-index: 30;
}

.toast.error { background: var(--danger); }

/* ---------------- 口令弹框 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
  z-index: 40;
}

.modal[hidden] { display: none; }

.modal-box {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .25);
}

.modal-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.modal-close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal-body { padding: 16px; }

.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
}

.input:focus { outline: none; border-color: var(--primary); }

.error { margin: 8px 0 0; color: var(--danger); font-size: 13px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* ---------------- 窄屏（手机 / 小窗）：面板移到下方 ---------------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { flex: 0 0 45%; border-left: 0; border-top: 1px solid var(--border); }
  body.sidebar-collapsed .sidebar { display: none; }
  .handle { top: auto; bottom: 12px; }
}
