:root {
  --dm-bg: #eef2f0;
  --dm-panel: #ffffff;
  --dm-panel-soft: #f7faf8;
  --dm-text: #15261f;
  --dm-muted: #60736c;
  --dm-subtle: #8a9a94;
  --dm-line: #d9e4df;
  --dm-line-strong: #b9cbc4;
  --dm-brand: #1f6f54;
  --dm-brand-deep: #16523f;
  --dm-gold: #c9a24b;
  --dm-gold-soft: #f4ead1;
  --dm-danger: #b63737;
  --dm-shadow: 0 10px 28px rgba(31, 61, 51, .11);
  --dm-shadow-soft: 0 2px 12px rgba(31, 61, 51, .08);
  --dm-radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--dm-bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--dm-bg);
  color: var(--dm-text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", "PingFang TC", sans-serif;
}

button,
input {
  font: inherit;
}

.dm-shell {
  min-height: 100vh;
  padding: 24px;
}

.dm-wrap {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(420px, 1fr);
  gap: 24px;
  align-items: start;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.dm-panel,
.dm-preview-card {
  overflow: hidden;
  border: 1px solid rgba(201, 162, 75, .24);
  border-radius: var(--dm-radius);
  background: var(--dm-panel);
  box-shadow: var(--dm-shadow-soft);
}

.dm-panel {
  position: sticky;
  top: 18px;
}

.dm-panel-head,
.dm-controls,
.dm-helper-note,
.dm-actions {
  padding: 18px 20px;
}

.dm-panel-head {
  border-bottom: 1px solid var(--dm-line);
  background: linear-gradient(180deg, rgba(31, 111, 84, .08), rgba(31, 111, 84, 0));
}

.dm-h2 {
  margin: 0 0 6px;
  color: var(--dm-brand-deep);
  font-size: 21px;
  font-weight: 800;
  line-height: 1.25;
}

.dm-hint,
.dm-note,
.dm-status,
.dm-preview-meta {
  color: var(--dm-muted);
  font-size: 12px;
  line-height: 1.55;
}

.dm-hint {
  margin: 0;
}

.dm-group {
  margin-bottom: 18px;
}

.dm-group:last-child {
  margin-bottom: 0;
}

.dm-label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
  color: var(--dm-brand-deep);
  font-size: 13px;
  font-weight: 800;
}

.dm-label::before,
.dm-preview-title::before {
  display: inline-block;
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: var(--dm-gold);
  content: "";
}

.dm-tpls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dm-tpl-btn {
  min-height: 46px;
  padding: 9px 8px;
  border: 1px solid var(--dm-line);
  border-radius: var(--dm-radius);
  background: #f5f8f6;
  color: var(--dm-text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.dm-tpl-btn:hover {
  border-color: var(--dm-brand);
  box-shadow: 0 5px 12px rgba(31, 111, 84, .12);
  transform: translateY(-1px);
}

.dm-tpl-btn.active {
  border-color: var(--dm-brand);
  background: var(--dm-brand);
  color: #fff;
}

.dm-objects {
  display: grid;
  gap: 9px;
}

.dm-prop-tools {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.dm-filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.dm-prop-tools input,
.dm-prop-tools select {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--dm-line);
  border-radius: var(--dm-radius);
  background: #fff;
  color: var(--dm-text);
  outline: none;
  font-size: 14px;
}

.dm-prop-tools select {
  cursor: pointer;
  padding-right: 28px;
}

.dm-prop-tools input:focus,
.dm-prop-tools select:focus {
  border-color: var(--dm-brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 84, .12);
}

.dm-prop-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dm-mini-btn {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid rgba(31, 111, 84, .18);
  border-radius: var(--dm-radius);
  background: #eef5f1;
  color: var(--dm-brand-deep);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.dm-mini-btn:hover:not(:disabled) {
  border-color: var(--dm-brand);
  background: #e2efe9;
}

.dm-mini-btn:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.dm-prop-count {
  min-height: 18px;
  color: var(--dm-muted);
  font-size: 12px;
  line-height: 1.5;
}

.dm-obj-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--dm-line);
  border-radius: var(--dm-radius);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.dm-obj-item:hover {
  border-color: var(--dm-line-strong);
  box-shadow: 0 4px 12px rgba(31, 61, 51, .08);
}

.dm-obj-item.on {
  border-color: rgba(31, 111, 84, .5);
  background: #f0f7f3;
}

.dm-obj-item input {
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--dm-brand);
}

.dm-obj-title {
  color: var(--dm-text);
  font-weight: 800;
  line-height: 1.35;
}

.dm-obj-sub {
  margin-top: 3px;
  color: var(--dm-muted);
  font-size: 12px;
  line-height: 1.4;
}

.dm-empty {
  padding: 12px;
  border: 1px dashed var(--dm-line-strong);
  border-radius: var(--dm-radius);
  color: var(--dm-muted);
  font-size: 13px;
  text-align: center;
}

.dm-selected-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  margin-top: 10px;
}

.dm-chip {
  max-width: 100%;
  padding: 5px 9px;
  overflow: hidden;
  border: 1px solid rgba(31, 111, 84, .14);
  border-radius: 999px;
  background: #eef5f1;
  color: var(--dm-brand-deep);
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-actions {
  border-top: 1px solid var(--dm-line);
  background: #fff;
}

.dm-export {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--dm-radius);
  background: var(--dm-gold);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
  transition: filter .18s ease, transform .18s ease, box-shadow .18s ease;
}

.dm-export:hover {
  filter: brightness(1.04);
  box-shadow: 0 8px 18px rgba(201, 162, 75, .22);
  transform: translateY(-1px);
}

.dm-status {
  min-height: 19px;
  margin-top: 10px;
}

.dm-helper-note {
  border-top: 1px solid var(--dm-line);
  background: #fbfcfb;
}

.dm-note {
  margin: 0;
}

.dm-preview {
  min-width: 0;
}

.dm-preview-card {
  padding: 18px;
}

.dm-preview-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.dm-preview-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 5px;
  color: var(--dm-brand-deep);
  font-size: 19px;
  font-weight: 800;
  line-height: 1.25;
}

.dm-canvas-frame {
  display: flex;
  justify-content: center;
  padding: 18px;
  border: 1px solid rgba(31, 111, 84, .12);
  border-radius: var(--dm-radius);
  background: var(--dm-panel-soft);
}

#dm-canvas {
  display: block;
  width: min(100%, 460px);
  height: auto;
  border-radius: var(--dm-radius);
  background: #fff;
  box-shadow: var(--dm-shadow);
}

@media (min-width: 1200px) {
  .dm-wrap {
    grid-template-columns: 386px minmax(520px, 1fr);
  }

  #dm-canvas {
    width: min(100%, 500px);
  }
}

@media (max-width: 820px) {
  .dm-shell {
    padding: 12px;
    padding-bottom: 92px;
  }

  .dm-wrap {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .dm-panel {
    position: static;
  }

  .dm-preview {
    order: -1;
  }

  .dm-panel-head,
  .dm-controls,
  .dm-helper-note,
  .dm-actions,
  .dm-preview-card {
    padding: 14px;
  }

  .dm-tpls {
    grid-template-columns: 1fr;
  }

  .dm-objects {
    grid-template-columns: 1fr;
  }

  .dm-actions {
    position: fixed;
    right: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 20;
    border: 1px solid rgba(201, 162, 75, .28);
    border-radius: var(--dm-radius);
    box-shadow: 0 12px 26px rgba(21, 38, 31, .18);
  }

  .dm-helper-note {
    margin-bottom: 0;
  }

  .dm-canvas-frame {
    padding: 10px;
  }

  #dm-canvas {
    width: min(100%, 340px);
  }
}

@media (max-width: 420px) {
  .dm-shell {
    padding: 10px;
    padding-bottom: 88px;
  }

  .dm-panel-head,
  .dm-controls,
  .dm-helper-note,
  .dm-actions,
  .dm-preview-card {
    padding: 12px;
  }

  .dm-h2,
  .dm-preview-title {
    font-size: 18px;
  }

  .dm-tpl-btn {
    min-height: 42px;
  }
}

/* ===== 左欄挑選按鈕 + 已選物件列表（2026-06-20：物件/客戶改 modal 挑選，左欄縮短）===== */
.dm-pick-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--dm-line);
  border-radius: var(--dm-radius);
  background: #f5f8f6;
  color: var(--dm-text);
  cursor: pointer;
  text-align: left;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.dm-pick-btn:hover {
  border-color: var(--dm-brand);
  background: #eef5f1;
  box-shadow: 0 4px 12px rgba(31, 111, 84, .1);
}
.dm-pick-main { font-size: 15px; font-weight: 800; color: var(--dm-brand-deep); }
.dm-pick-sub { font-size: 12px; color: var(--dm-muted); }

.dm-selected-list { display: grid; gap: 6px; margin-top: 10px; }
.dm-selected-row {
  display: grid;
  gap: 1px;
  padding: 7px 10px;
  border: 1px solid var(--dm-line);
  border-left: 3px solid var(--dm-gold);
  border-radius: var(--dm-radius);
  background: #fbfcfb;
}
.dm-selected-t { font-size: 13px; font-weight: 700; line-height: 1.35; }
.dm-selected-s { font-size: 12px; color: var(--dm-muted); }

/* ===== 懸浮視窗 modal ===== */
body.dm-modal-open { overflow: hidden; }
.dm-modal[hidden] { display: none; }
.dm-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dm-modal-backdrop { position: absolute; inset: 0; background: rgba(21, 38, 31, .45); }
.dm-modal-box {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(86vh, 760px);
  border: 1px solid rgba(201, 162, 75, .3);
  border-radius: 12px;
  background: var(--dm-panel);
  box-shadow: 0 20px 50px rgba(21, 38, 31, .3);
  overflow: hidden;
}
.dm-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--dm-line);
  background: linear-gradient(180deg, rgba(31, 111, 84, .08), rgba(31, 111, 84, 0));
}
.dm-modal-title { margin: 0; font-size: 17px; font-weight: 800; color: var(--dm-brand-deep); }
.dm-modal-close {
  width: 34px; height: 34px;
  border: 1px solid var(--dm-line);
  border-radius: 8px;
  background: #fff;
  color: var(--dm-muted);
  cursor: pointer;
  font-size: 15px;
}
.dm-modal-close:hover { border-color: var(--dm-brand); color: var(--dm-brand); }
.dm-modal-body { display: grid; gap: 9px; padding: 16px 18px; overflow-y: auto; }
.dm-modal-body input[type="search"] {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--dm-line);
  border-radius: var(--dm-radius);
  outline: none;
  font-size: 14px;
}
.dm-modal-body input[type="search"]:focus { border-color: var(--dm-brand); box-shadow: 0 0 0 3px rgba(31, 111, 84, .12); }
.dm-modal-foot { padding: 14px 18px; border-top: 1px solid var(--dm-line); background: #fff; }
.dm-modal-done { font-size: 14px; }

.dm-client-search-row { display: flex; gap: 8px; align-items: center; }
.dm-client-search-row input[type="search"] { flex: 1; min-width: 0; }
.dm-client-search-row .dm-mini-btn { flex: none; white-space: nowrap; }
.dm-client-list { display: grid; gap: 8px; }
.dm-client-row {
  display: grid;
  gap: 2px;
  padding: 11px 13px;
  border: 1px solid var(--dm-line);
  border-radius: var(--dm-radius);
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.dm-client-row:hover { border-color: var(--dm-line-strong); box-shadow: 0 4px 12px rgba(31, 61, 51, .08); }
.dm-client-row.on { border-color: rgba(31, 111, 84, .5); background: #f0f7f3; }
.dm-client-name { font-size: 14px; font-weight: 800; color: var(--dm-text); }
.dm-client-sub { font-size: 12px; color: var(--dm-muted); }

@media (max-width: 820px) {
  .dm-modal { padding: 0; align-items: flex-end; }
  .dm-modal-box { width: 100%; max-height: 90vh; border-radius: 14px 14px 0 0; }
}
