/* Mọi selector nằm dưới .dc để dùng được cả trong trang PWA lẫn shadow root của widget ws-board. */
.dc {
  --dc-bg: #f4f5f7;
  --dc-panel: #ffffff;
  --dc-text: #1c1e21;
  --dc-muted: #6b7280;
  --dc-border: #e3e5e8;
  --dc-accent: #2563eb;
  --dc-accent-text: #ffffff;
  --dc-peer-bubble: #ffffff;
  --dc-warn: #b45309;
  --dc-online: #16a34a;

  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--dc-bg);
  color: var(--dc-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  border-radius: 10px;
}
.dc *, .dc *::before, .dc *::after { box-sizing: border-box; }
.dc--fill { height: 100%; border-radius: 0; }
/* Khung là container để màn hình PIN co theo chiều cao khung (widget thấp hơn màn hình điện thoại). */
.dc { container-type: size; container-name: dc; }

/* Giao diện tối: .dc--dark luôn tối, .dc (auto) tối theo hệ điều hành, .dc--light luôn sáng. */
.dc.dc--dark {
  --dc-bg: #17181c;
  --dc-panel: #202227;
  --dc-text: #e8e9ec;
  --dc-muted: #9097a3;
  --dc-border: #2e3138;
  --dc-accent: #3b82f6;
  --dc-peer-bubble: #2a2d34;
  --dc-warn: #f59e0b;
  --dc-online: #22c55e;
}
@media (prefers-color-scheme: dark) {
  .dc:not(.dc--light) {
    --dc-bg: #17181c;
    --dc-panel: #202227;
    --dc-text: #e8e9ec;
    --dc-muted: #9097a3;
    --dc-border: #2e3138;
    --dc-accent: #3b82f6;
    --dc-peer-bubble: #2a2d34;
    --dc-warn: #f59e0b;
    --dc-online: #22c55e;
  }
}

.dc :where(button) { font: inherit; color: inherit; cursor: pointer; }
.dc :where(button):disabled { cursor: default; opacity: 0.5; }

/* ---- PIN ---- */
.dc-pin {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px;
  outline: none;
}
.dc-pin-title { font-size: 18px; font-weight: 600; color: var(--dc-muted); }
.dc-pin-dots { display: flex; gap: 14px; }
.dc-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--dc-muted);
}
.dc-dot--on { background: var(--dc-text); border-color: var(--dc-text); }
.dc-pin-msg { min-height: 20px; color: var(--dc-muted); font-size: 14px; text-align: center; }
.dc-pad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  gap: 12px;
}
.dc-key {
  width: 64px; height: 64px; border-radius: 50%;
  border: none;
  background: var(--dc-panel);
  font-size: 24px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.dc-key:active:not(:disabled) { background: var(--dc-border); }
@container dc (max-height: 520px) {
  .dc-pin { gap: 10px; padding: 12px; }
  .dc-pad { grid-template-columns: repeat(3, 52px); gap: 8px 14px; }
  .dc-key { width: 52px; height: 52px; font-size: 20px; }
}
.dc-key--back { display: flex; align-items: center; justify-content: center; background: transparent; box-shadow: none; }

/* ---- chat ---- */
.dc-chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.dc-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--dc-panel);
  border-bottom: 1px solid var(--dc-border);
}
.dc-presence { width: 10px; height: 10px; border-radius: 50%; background: var(--dc-muted); flex: none; }
.dc-presence--on { background: var(--dc-online); }
.dc-head-text { flex: 1; min-width: 0; }
.dc-peer { font-weight: 600; }
.dc-status { font-size: 12px; color: var(--dc-muted); }
.dc-status--warn { color: var(--dc-warn); }
.dc-lock {
  border: 1px solid var(--dc-border); background: transparent;
  border-radius: 6px; padding: 4px 10px; font-size: 13px;
}

.dc-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dc-more, .dc-day, .dc-unread {
  align-self: center;
  font-size: 12px;
  color: var(--dc-muted);
  padding: 4px 8px;
}
.dc-day { margin-top: 6px; }
.dc-unread {
  align-self: stretch;
  text-align: center;
  color: var(--dc-accent);
  border-top: 1px solid var(--dc-accent);
  margin-top: 6px;
}
.dc-row { display: flex; }
.dc-row--mine { justify-content: flex-end; }
.dc-bubble {
  max-width: 80%;
  padding: 6px 10px;
  border-radius: 14px;
  background: var(--dc-peer-bubble);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}
.dc-bubble--mine { background: var(--dc-accent); color: var(--dc-accent-text); }
.dc-bubble--pending { background: var(--dc-accent); color: var(--dc-accent-text); opacity: 0.6; }
.dc-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.dc-meta { font-size: 11px; opacity: 0.7; text-align: right; }
.dc-seen { align-self: flex-end; font-size: 11px; color: var(--dc-muted); padding-right: 4px; }

.dc-warn {
  padding: 4px 12px;
  font-size: 12px;
  color: var(--dc-warn);
  background: var(--dc-panel);
  border-top: 1px solid var(--dc-border);
}
.dc-compose {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px;
  background: var(--dc-panel);
  border-top: 1px solid var(--dc-border);
}
.dc-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  overflow-y: hidden;
  line-height: 1.4;
  padding: 8px 12px;
  border: 1px solid var(--dc-border);
  border-radius: 18px;
  background: var(--dc-bg);
  color: var(--dc-text);
  font: inherit;
  font-size: 16px; /* iOS phóng to trang nếu ô nhập dưới 16px */
  outline: none;
}
.dc-input:focus { border-color: var(--dc-accent); }
.dc-send {
  border: none; border-radius: 18px;
  padding: 8px 14px;
  background: var(--dc-accent); color: var(--dc-accent-text);
  font-weight: 600;
}

/* Chỉ cho PWA. --app-h do main.tsx đặt theo visualViewport để khung chat co lại khi bàn phím iOS mở. */
html, body { margin: 0; height: 100%; }
body {
  background: #f4f5f7;
  overflow: hidden;
  overscroll-behavior: none;
}
@media (prefers-color-scheme: dark) { body { background: #17181c; } }
#app {
  height: var(--app-h, 100dvh);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
}
