/* ============================================================
   keypad-lite 网页配置器 样式
   ============================================================ */
* { box-sizing: border-box; }

:root {
  --accent: #3498db;
  --accent-dark: #1a5276;
  --border: #bdc3c7;
  --text: #2c3e50;
  --muted: #909090;
  --key-bg: #f0f0f0;
}

html, body {
  margin: 0;
  height: 100%;
}
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: #f7f9fa;
  display: flex;
  flex-direction: column;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---- 浏览器支持提示条 ---- */
.banner {
  display: none;
  background: #fdecea;
  color: #c0392b;
  border-bottom: 1px solid #f5b7b1;
  padding: 8px 12px;
  font-size: 13px;
}
.banner.show { display: block; }

/* ---- 工具栏 ---- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  background: #fff;
  border-bottom: 1px solid #d5d8dc;
  padding: 6px 10px;
}
.toolbar .brand {
  font-weight: 700;
  margin-right: 8px;
}
.tb-sep {
  width: 1px;
  height: 22px;
  background: #d5d8dc;
  margin: 0 4px;
}
button.tb, .toolbar button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 13px;
}
button.tb:hover, .toolbar button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-dark); }
button.tb:disabled, .toolbar button:disabled { opacity: 0.45; cursor: default; }
.toolbar select, .toolbar input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 4px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
.toolbar select:disabled, .toolbar input:disabled { opacity: 0.45; }
.toolbar label { color: #555; }
.toolbar .duty { display: inline-flex; align-items: center; }
.toolbar #max-duty { width: 56px; }

/* ---- 主区 ---- */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;         /* 配置区整体水平居中，不铺满超宽屏 */
  padding: 6px;
  gap: 6px;
}
.panel-grid { flex: 0 0 auto; }
.panel-palette { flex: 1 1 auto; min-height: 240px; display: flex; flex-direction: column; }

/* ---- 键盘网格 ---- */
.grid-card, .palette-card {
  background: #fff;
  border: 1px solid #d5d8dc;
  border-radius: 8px;
  width: 100%;
  max-width: 760px;            /* 两卡同宽、居中：键区不用铺满，面板按键变窄 */
}
.grid-card { padding: 8px; }

.layer-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.layer-tab {
  border: 1px solid var(--border);
  background: #f0f3f5;
  border-radius: 6px 6px 0 0;
  padding: 5px 16px;
  cursor: pointer;
  color: #555;
}
.layer-tab.active { background: #fff; border-bottom-color: #fff; color: var(--text); font-weight: 600; }

.keyboard-grid {
  display: grid;
  gap: 5px;
  justify-content: center;     /* 键行较短时整块在卡片内水平居中 */
}
.key {
  background: var(--key-bg);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 13px;
  padding: 2px;
  white-space: pre-line;
  min-width: 0;
  user-select: none;
}
.key:hover { border-color: var(--accent); background: #e8f4fd; }
.key.selected { background: var(--accent); border: 3px solid var(--accent-dark); color: #fff; font-weight: 700; }
.key.empty { background: #fafafa; color: #cfcfcf; border: 2px dashed #e4e4e4; font-weight: 400; }
.key.empty.selected { background: var(--accent); border: 3px solid var(--accent-dark); color: #fff; }

.grid-placeholder {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 40px 0;
}

.mod-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #555;
}

/* ---- 键码面板 ---- */
.palette-card { display: flex; flex-direction: column; min-height: 0; }
.palette-tabs { display: flex; gap: 2px; overflow-x: auto; }
.palette-tab {
  border: none;
  background: transparent;
  padding: 6px 12px;
  cursor: pointer;
  color: #555;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.palette-tab.active { color: var(--accent-dark); font-weight: 600; border-bottom-color: var(--accent); }
.palette-panel {
  flex: 1;
  overflow: auto;
  padding: 8px;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(10, minmax(58px, 1fr));
  gap: 4px;
  align-content: start;
}
.palette-key {
  background: #fff;
  color: var(--text);
  border: 1px solid #d5d8dc;
  border-radius: 5px;
  padding: 4px 2px;
  font-size: 12px;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-key:hover:not(:disabled) { background: #d4e6f1; border-color: var(--accent); }
.palette-key:disabled { opacity: 0.45; cursor: default; }
.palette-key.warn { border-color: #f0b429; }  /* 预留：可高亮警示类条目 */

/* ---- 状态栏 ---- */
.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px;
  border-top: 1px solid #d5d8dc;
  background: #fff;
  font-size: 12px;
  color: #555;
}
.statusbar .spacer { flex: 1; }
.statusbar #dirty-flag { color: #c0392b; font-weight: 700; }
.statusbar #fw-text { color: #7f8c8d; }

/* ---- 通用按钮小工具在宏编辑器内 ---- */
.buttons {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
button.mini, .buttons button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
}
button.mini:hover:not(:disabled), .buttons button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}
button.mini:disabled, .buttons button:disabled { opacity: 0.45; cursor: default; }

/* ============================================================
   遮罩 / 弹窗（宏编辑器、LT 对话框、通用确认）
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.show { display: flex; }
.modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  max-width: 96vw;
  max-height: 92vh;
  overflow: hidden;
}
.modal-header {
  padding: 10px 14px;
  border-bottom: 1px solid #d5d8dc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
}
.modal-header .x {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: #888;
}
.modal-body { padding: 12px; overflow: auto; }

/* LT 对话框 */
.lt-modal { width: 420px; }
.lt-preview {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  padding: 10px 0;
  white-space: pre-line;
  margin: 8px 0;
  background: #f4f6f8;
  border-radius: 8px;
}
.lt-hint { color: #7f8c8d; font-size: 12px; }

/* 确认对话框 */
.confirm-modal { width: 420px; }
.confirm-text { white-space: pre-line; margin: 4px 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.modal-actions button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 5px;
  padding: 6px 16px;
  cursor: pointer;
}
.modal-actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-actions button.danger { background: #c0392b; border-color: #c0392b; color: #fff; }

/* ============================================================
   宏编辑器
   ============================================================ */
.macro-modal { width: 980px; height: 640px; }
.macro-body { display: flex; flex-direction: column; padding: 10px; min-height: 0; }
.macro-split {
  flex: 1;
  display: flex;
  min-height: 0;
  gap: 10px;
}
.macro-left { width: 240px; display: flex; flex-direction: column; }
.macro-left h4, .macro-right h4 { margin: 0 0 6px; font-size: 13px; }
.macro-slot-list {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.macro-slot {
  padding: 6px 10px;
  cursor: pointer;
  border-bottom: 1px solid #eef0f2;
}
.macro-slot:hover { background: #eef7fd; }
.macro-slot.active { background: var(--accent); color: #fff; }
.macro-slot .empty { color: #bdc3c7; }
.macro-right { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.macro-table-wrap { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 6px; min-height: 120px; }
table.macro-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.macro-table th, .macro-table td {
  border-bottom: 1px solid #e5e8eb;
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
}
.macro-table th { background: #f4f6f8; position: sticky; top: 0; }
.macro-table td.row-select { width: 40px; text-align: center; }
.macro-table tr:hover { background: #f2f7fb; }
.macro-table tr.sel { background: #d4e6f1; }
.macro-summary { margin-top: 6px; font-size: 12px; color: #555; }
.macro-summary.over { color: #c0392b; font-weight: 700; }
.macro-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* 键选择器 */
.picker-modal { width: 760px; height: 520px; }
.picker-body { display: flex; flex-direction: column; min-height: 0; }
.picker-panel { flex: 1; overflow: auto; min-height: 0; display: grid; grid-template-columns: repeat(8, minmax(80px, 1fr)); gap: 4px; align-content: start; padding: 8px; }

/* 提示 toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: rgba(30, 42, 54, .9);
  color: #fff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 90;
  max-width: 80vw;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

@media (max-width: 900px) {
  .palette-panel { grid-template-columns: repeat(5, 1fr); }
  .macro-modal { width: 96vw; height: 90vh; }
}
