:root {
  --ink: #17221e;
  --green: #147651;
  --green-dark: #0b5037;
  --mint: #e8f5ee;
  --line: #dbe5df;
  --muted: #728079;
  --cream: #f8f5ec;
  --card: #fffffff2;
  --bg: #eaf2ed;
  --bad: #b4453a;
  --warn: #8d6512;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.5 "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0, #fff 0, transparent 28rem),
    linear-gradient(135deg, var(--cream), var(--bg));
}
body.theme-dark {
  --ink: #e8ecf1;
  --green: #7dffb3;
  --green-dark: #b8f5d2;
  --mint: #1a2a22;
  --line: #243044;
  --muted: #8b97a8;
  --cream: #0e1116;
  --card: #161b24;
  --bg: #0e1116;
  --bad: #ff8b8b;
  --warn: #f0c36a;
  background: #0e1116;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.topbar {
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 88%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand b {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--green); color: #fff; font-size: 18px;
}
.brand span { display: flex; flex-direction: column; }
.brand small, .live-note, .health { color: var(--muted); font-size: 12px; }
.live-note { margin: 0 auto 0 8px; }
.health { margin-left: auto; }
.health.ok { color: var(--green); }
.health.bad { color: var(--bad); }
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 64px); }
.nav {
  padding: 16px 12px 32px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px;
}
.nav p {
  margin: 14px 10px 6px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
}
.nav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 9px 12px;
  border-radius: 10px;
}
.nav button:hover, .nav button.active {
  background: var(--mint);
  color: var(--green-dark);
}
main { padding: 22px 28px 48px; min-width: 0; }
.page-head small { color: var(--green); font-weight: 800; letter-spacing: .12em; }
.page-head h1 { margin: 6px 0 8px; font-size: 28px; letter-spacing: -.03em; }
.page-head p { margin: 0 0 18px; color: var(--muted); max-width: 52rem; }
.content { display: grid; gap: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card, .workspace-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
}
.card b { display: block; font-size: 26px; margin-top: 8px; }
.card small, .workspace-card small, .muted { color: var(--muted); }
.row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.thumb {
  width: 88px; height: 66px; object-fit: cover; border-radius: 8px; background: #13221b;
}
.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}
.tag.bad { background: #fdecea; color: var(--bad); }
.tag.warn { background: #fff4d9; color: var(--warn); }
.list { display: grid; gap: 10px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
textarea, input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: inherit;
}
body.theme-dark textarea, body.theme-dark input[type="text"] { background: #10161d; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button, .primary {
  border: 1px solid #cbe2d5;
  background: var(--mint);
  color: var(--green);
  border-radius: 8px;
  padding: 7px 10px;
}
.primary { background: var(--green); color: #fff; border-color: var(--green); }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; }
#detail {
  width: min(880px, 92vw);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: var(--card);
  color: var(--ink);
}
#detail::backdrop { background: #10231b70; }
#detail header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
#detail-close {
  width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--mint); color: var(--muted);
}
#detail-body { padding: 16px; display: grid; gap: 12px; }
#detail-body img { max-width: 100%; border-radius: 10px; background: #13221b; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav p { width: 100%; margin: 8px 8px 0; }
  .live-note { display: none; }
  main { padding: 16px; }
}

.family-workspace { display: grid; gap: 14px; }
.family-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.95fr) minmax(300px, 1.45fr);
  gap: 14px;
  align-items: stretch;
  min-height: 58vh;
}
.family-list-panel,
.family-thread-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.family-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.family-panel-head h3 {
  margin: 0 0 4px;
  font-size: 16px;
  letter-spacing: -.02em;
}
.family-panel-head .muted,
.family-refresh-note { margin: 0; font-size: 12px; }
.family-list {
  padding: 10px 12px 14px;
  gap: 8px;
  overflow: auto;
  max-height: 62vh;
}
.family-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: color-mix(in srgb, var(--mint) 35%, transparent);
  border-radius: 12px;
  padding: 12px 14px;
  color: inherit;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.family-item:hover {
  border-color: color-mix(in srgb, var(--green) 35%, var(--line));
  background: var(--mint);
}
.family-item.active {
  border-color: var(--green);
  background: var(--mint);
  box-shadow: inset 3px 0 0 var(--green);
}
.family-item-body strong { display: block; margin-bottom: 4px; }
.family-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 18px;
  max-height: 62vh;
  overflow: auto;
  scroll-behavior: auto;
}
.family-msg {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  max-width: 92%;
}
.family-msg-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.family-msg p {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.family-msg.user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--green) 12%, var(--card));
  border-color: color-mix(in srgb, var(--green) 28%, var(--line));
}
.family-msg.assistant {
  align-self: flex-start;
  background: color-mix(in srgb, var(--mint) 70%, var(--card));
}
.family-msg.system {
  align-self: center;
  max-width: 100%;
  background: transparent;
  color: var(--muted);
  border-style: dashed;
}
body.theme-dark .family-item {
  background: color-mix(in srgb, var(--mint) 55%, transparent);
}
body.theme-dark .family-msg.user {
  background: color-mix(in srgb, var(--green) 18%, var(--card));
}
@media (max-width: 860px) {
  .family-grid { grid-template-columns: 1fr; }
  .family-list, .family-thread { max-height: 42vh; }
}



/* Family chat dialog (phone-like) */
.family-thread-panel { background: #eef3ef; }
body.theme-dark .family-thread-panel { background: color-mix(in srgb, var(--card) 92%, #000); }
.family-thread {
  flex: 1;
  gap: 8px;
  padding: 14px 14px 10px;
  background: transparent;
}
.family-msg {
  border: 0;
  background: transparent;
  padding: 0;
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.family-msg.user { align-self: flex-end; align-items: flex-end; }
.family-msg.assistant { align-self: flex-start; align-items: flex-start; }
.family-msg.system { align-self: center; align-items: center; max-width: 92%; }
.family-msg-meta { margin: 0 4px; gap: 6px; }
.family-msg-who { font-size: 11px; color: var(--muted); }
.family-msg-bubble {
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 1px 0 color-mix(in srgb, #000 4%, transparent);
}
.family-msg.user .family-msg-bubble {
  background: color-mix(in srgb, var(--green) 22%, #fff);
  border-color: color-mix(in srgb, var(--green) 35%, var(--line));
  border-bottom-right-radius: 6px;
}
.family-msg.assistant .family-msg-bubble {
  background: #fff;
  border-bottom-left-radius: 6px;
}
.family-msg.system .family-msg-bubble {
  background: transparent;
  border-style: dashed;
  box-shadow: none;
  color: var(--muted);
}
body.theme-dark .family-msg-bubble { background: var(--card); }
body.theme-dark .family-msg.user .family-msg-bubble {
  background: color-mix(in srgb, var(--green) 28%, var(--card));
}
.family-composer {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: var(--card);
}
.family-composer select,
.family-composer textarea,
.family-composer button {
  font: inherit;
}
.family-composer select {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg, #f7faf8);
  padding: 0 8px;
}
.family-composer textarea {
  resize: none;
  min-height: 40px;
  max-height: 120px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  line-height: 1.35;
  background: #fff;
}
body.theme-dark .family-composer textarea,
body.theme-dark .family-composer select {
  background: color-mix(in srgb, var(--card) 80%, #000);
  color: inherit;
}
.family-composer button {
  height: 40px;
  min-width: 72px;
  border: 0;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.family-composer button:disabled {
  opacity: 0.55;
  cursor: default;
}
@media (max-width: 860px) {
  .family-composer { grid-template-columns: 1fr; }
}

.family-msg-img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  width: auto;
  height: auto;
  border-radius: 10px;
  margin: 0 0 8px;
  object-fit: contain;
  background: color-mix(in srgb, var(--mint) 35%, #fff);
}
