/* ============================================================
   DHDMS-OS — 应用通用组件样式（表格/表单/树/面板/标签页/代码块/状态灯）
   供 apps/ 下各应用页面复用（应用 iframe 内独立加载）
   ============================================================ */

/* ---------------- 面板 ---------------- */
.ap-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.ap-panel-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.ap-panel-title::before {
  content: ""; width: 4px; height: 14px; border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
}
.ap-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.ap-spacer { flex: 1; }

/* ---------------- 按钮 ---------------- */
.ap-btn {
  padding: 7px 14px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12.5px;
  transition: background .15s, border-color .15s, filter .15s;
}
.ap-btn:hover { background: var(--hover-bg); border-color: var(--accent); }
.ap-btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border: none; color: #fff; font-weight: 600;
}
.ap-btn.primary:hover { filter: brightness(1.12); }
.ap-btn.danger { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); color: var(--danger); }
.ap-btn.danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.ap-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- 输入控件 ---------------- */
.ap-input, .ap-select, .ap-textarea {
  padding: 7px 11px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12.5px;
  outline: none;
}
.ap-input:focus, .ap-select:focus, .ap-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.ap-input.sm { padding: 5px 9px; font-size: 12px; }
.ap-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.ap-field > label { font-size: 12px; color: var(--muted); }

/* ---------------- 表格 ---------------- */
.ap-table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 9px; }
.ap-table {
  width: 100%; border-collapse: collapse;
  font-size: 12.5px;
}
.ap-table th {
  position: sticky; top: 0; z-index: 1;
  padding: 9px 12px;
  background: var(--titlebar-bg-active);
  color: var(--muted);
  text-align: left; font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ap-table td {
  padding: 8px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  vertical-align: top;
}
.ap-table tbody tr:hover { background: var(--hover-bg); }
.ap-table tbody tr:last-child td { border-bottom: none; }
.ap-table .num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------------- 树 ---------------- */
.ap-tree { font-size: 12.5px; user-select: none; }
.ap-tree-node { line-height: 1.7; }
.ap-tree-row {
  display: flex; align-items: center; gap: 5px;
  padding: 2px 6px; border-radius: 6px;
  cursor: pointer; white-space: nowrap;
}
.ap-tree-row:hover { background: var(--hover-bg); }
.ap-tree-row.selected { background: var(--accent-glow); color: var(--accent); }
.ap-tree-caret {
  width: 14px; height: 14px; flex: 0 0 14px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); transition: transform .15s;
}
.ap-tree-caret.open { transform: rotate(90deg); }
.ap-tree-caret.leaf { visibility: hidden; }
.ap-tree-children { padding-left: 18px; }
.ap-tree-icon { flex: 0 0 auto; color: var(--muted); }

/* ---------------- 标签页 ---------------- */
.ap-tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  overflow-x: auto;
}
.ap-tab {
  padding: 8px 16px;
  background: transparent; color: var(--muted);
  border: none; border-bottom: 2px solid transparent;
  font-size: 13px; white-space: nowrap;
}
.ap-tab:hover { color: var(--text); background: var(--hover-bg); border-radius: 8px 8px 0 0; }
.ap-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------------- 代码块 ---------------- */
.ap-code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap; word-break: break-all;
  overflow: auto;
  max-height: 420px;
}
.ap-code.lg { max-height: none; }
.ap-json-key { color: #7ec8ff; }
.ap-json-str { color: #9be39b; }
.ap-json-num { color: #ffb86b; }
.ap-json-bool { color: #ff79c6; }

/* ---------------- 状态灯 ---------------- */
.ap-status-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}
.ap-status-dot.ok { background: #2ecc71; box-shadow: 0 0 6px rgba(46,204,113,0.7); }
.ap-status-dot.warn { background: #f1c40f; box-shadow: 0 0 6px rgba(241,196,15,0.7); }
.ap-status-dot.err { background: #e74c3c; box-shadow: 0 0 6px rgba(231,76,60,0.7); }
.ap-status-dot.off { background: var(--muted); }

.ap-badge {
  display: inline-block; padding: 2px 9px;
  font-size: 11px; border-radius: 999px;
  background: var(--accent-glow); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.ap-badge.gray { background: var(--hover-bg); color: var(--muted); border-color: var(--border); }
.ap-badge.red { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.ap-badge.green { background: rgba(46,204,113,0.13); color: #2ecc71; border-color: rgba(46,204,113,0.4); }

/* ---------------- 网格/布局 ---------------- */
.ap-grid { display: grid; gap: 12px; }
.ap-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.ap-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.ap-grid.side { grid-template-columns: 260px 1fr; }
.ap-grid.side-wide { grid-template-columns: 340px 1fr; }
.ap-split { display: flex; gap: 12px; height: 100%; }
.ap-split > .ap-split-left { flex: 0 0 280px; overflow: auto; }
.ap-split > .ap-split-right { flex: 1; overflow: auto; min-width: 0; }

/* ---------------- 应用页骨架 ---------------- */
.app-root {
  height: 100%; overflow: auto;
  padding: 16px;
  background: var(--bg);
}
.app-root.no-scroll { overflow: hidden; }
.app-header {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.app-header h2 { font-size: 17px; font-weight: 700; }
.app-header p { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------------- 消息提示 ---------------- */
.ap-toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 999;
  max-width: 380px; padding: 11px 16px;
  background: var(--window-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  animation: ap-toast-in .25s ease;
}
.ap-toast.error { border-left-color: var(--danger); }
.ap-toast.warn { border-left-color: #f1c40f; }
@keyframes ap-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.ap-empty {
  padding: 40px 20px; text-align: center; color: var(--muted); font-size: 12.5px;
}
.ap-loading { padding: 40px; text-align: center; color: var(--muted); font-size: 12.5px; }
.ap-loading::after {
  content: ""; display: block; width: 22px; height: 22px; margin: 10px auto 0;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: ap-spin .8s linear infinite;
}
@keyframes ap-spin { to { transform: rotate(360deg); } }
