:root {
  --bg: #eef3f9;
  --panel: #ffffff;
  --line: #e2e9f1;
  --text: #334155;
  --muted: #94a3b8;
  --blue: #5d8fc7;
  --blue-deep: #4276ad;
  --owner: #d9ebfb;
  --shadow: 0 8px 26px rgba(52, 78, 108, .07);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* login */
.login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 22px;
  background: radial-gradient(circle at 50% 0%, #fff, #eaf1fa 55%, #e6edf6);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: rgba(255,255,255,.92);
  border: 1px solid #e1e8f2;
  border-radius: 22px;
  padding: 30px 24px;
  box-shadow: 0 20px 60px rgba(55, 85, 120, .12);
  text-align: center;
}
.brand {
  width: 62px; height: 62px; border-radius: 50%; margin: 0 auto 14px;
  background: linear-gradient(145deg, #9cc6ed, #5c91cb);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700;
}
.login h1 { margin: 0 0 6px; font-size: 23px; }
.login p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login input {
  width: 100%; height: 46px; border: 1px solid #dce4ee; border-radius: 12px;
  background: #f8fafc; padding: 0 14px; outline: none; font-size: 16px;
}
.login input:focus { border-color: #9dbbe0; background: #fff; }
.login button {
  width: 100%; height: 46px; border: 0; border-radius: 12px; margin-top: 12px;
  background: var(--blue); color: #fff; font-size: 15px; font-weight: 600;
}
.error { min-height: 20px; margin-top: 10px; color: #c15050; font-size: 12px; line-height: 1.5; }

/* shell */
.app-shell {
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
.topbar {
  height: 64px; flex: 0 0 64px; display: flex; align-items: center; gap: 10px;
  padding: 0 16px; padding-top: env(safe-area-inset-top);
  background: rgba(255,255,255,.88); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px); position: relative; z-index: 5;
}
.avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(145deg, #a9cff0, #5d94ce); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.head-main { min-width: 0; flex: 1; }
.name { font-weight: 650; font-size: 15px; }
.status { margin-top: 3px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; color: #748092; font-size: 22px; padding: 6px; }

.page { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page-chat { position: relative; }
.messages {
  flex: 1; overflow-y: auto; padding: 16px 14px 24px;
  scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
}
.msg { display: flex; gap: 8px; margin-bottom: 14px; align-items: flex-start; }
.msg.owner { justify-content: flex-end; }
.msg-avatar {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%; overflow: hidden;
  background: #d8e8f7; color: #fff; display: flex; align-items: center;
  justify-content: center; font-size: 11px; margin-top: 2px;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg.owner .msg-avatar { display: none; }
.bubble {
  max-width: min(78%, 520px); padding: 10px 13px; border-radius: 15px 15px 15px 5px;
  background: var(--panel); color: #3c4656; font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; box-shadow: 0 3px 12px rgba(60, 80, 110, .05);
}
.msg.owner .bubble { background: var(--owner); border-radius: 15px 15px 5px 15px; }
.bubble img { display: block; max-width: 100%; max-height: 320px; border-radius: 9px; cursor: zoom-in; }
.meta-time { margin-top: 5px; color: #a3adb8; font-size: 10px; }
.msg.owner .meta-time { text-align: right; }
.typing {
  padding: 0 18px 6px; color: #9aa5b2; font-size: 11px;
  display: flex; align-items: center; gap: 4px;
}
.typing span { width: 4px; height: 4px; border-radius: 50%; background: #9aa5b2; animation: blink 1.1s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%,80%,100% { opacity:.25; } 40% { opacity:1; } }
.composer {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.92); border-top: 1px solid var(--line); backdrop-filter: blur(12px);
}
.tool {
  width: 36px; height: 36px; flex: 0 0 36px; border: 1px solid #e0e6ee;
  background: #f8fafc; border-radius: 10px; color: #718096; font-size: 22px; line-height: 1;
}
.composer textarea {
  flex: 1; min-height: 38px; max-height: 130px; resize: none;
  border: 1px solid #e0e7ef; background: #f7f9fc; border-radius: 12px;
  padding: 9px 11px; outline: none; line-height: 1.45; font-size: 16px;
}
.composer textarea:focus { border-color: #a9c3e0; background: #fff; }
.send {
  height: 38px; flex: 0 0 auto; border: 0; border-radius: 11px;
  background: var(--blue); color: #fff; padding: 0 16px; font-weight: 600;
}
.sleep {
  height: 100%; min-height: 260px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: #8290a2; gap: 6px; font-size: 14px;
}
.sleep-mark {
  width: 58px; height: 58px; border-radius: 50%; background: #dfe8f3; color: #7896b7;
  display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; margin-bottom: 6px;
}
.sleep-sub { color: #a5afbb; font-size: 12px; }

/* moments */
.section-head {
  flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 18px 18px 12px;
}
.section-head h2 { margin: 0; font-size: 18px; }
.section-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.mini-btn {
  border: 1px solid #e0e7ef; background: #fff; color: #6b7a8c;
  border-radius: 9px; padding: 7px 11px; font-size: 12px;
}
.moments-list { flex: 1; overflow-y: auto; padding: 4px 16px 26px; }
.moment-card {
  position: relative; margin: 10px 0 16px; padding: 17px 15px 14px;
  background: #fff7cf; border-radius: 6px;
  box-shadow: 0 7px 18px rgba(83,72,45,.09);
  transform: rotate(-.45deg);
}
.moment-card:nth-child(3n+2) { background: #e6f4de; transform: rotate(.4deg); }
.moment-card:nth-child(3n) { background: #fee4da; transform: rotate(-.1deg); }
.moment-card::before {
  content: ''; position: absolute; top: -5px; left: 50%; width: 54px; height: 11px;
  transform: translateX(-50%) rotate(-2deg); background: rgba(255,255,255,.5);
  border: 1px solid rgba(140,125,90,.07); border-radius: 2px;
}
.moment-meta { display: flex; justify-content: space-between; color: rgba(90,76,48,.58); font-size: 10px; margin-bottom: 8px; }
.moment-text { font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; color: #4a4439; }
.moment-images { display: grid; grid-template-columns: repeat(2,1fr); gap: 6px; margin-top: 10px; }
.moment-images.single { grid-template-columns: 1fr; }
.moment-images img { width: 100%; height: 120px; object-fit: cover; border-radius: 5px; cursor: zoom-in; }
.moment-images.single img { height: auto; max-height: 260px; object-fit: contain; }
.empty { padding: 50px 20px; text-align: center; color: #9aa5b2; font-size: 13px; }

/* workbench */
.workbench-content { flex: 1; overflow-y: auto; padding: 2px 16px 30px; }
.loading { padding: 30px 4px; color: #9aa5b2; font-size: 13px; }
.wb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.wb-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.wb-card.wide { grid-column: 1 / -1; }
.wb-label { color: #94a3b8; font-size: 10px; letter-spacing: .03em; }
.wb-value { margin-top: 7px; font-size: 20px; font-weight: 650; color: #354357; }
.wb-value small { font-size: 11px; font-weight: 400; color: #9aa5b2; }
.wb-line { margin-top: 8px; color: #7b8797; font-size: 11px; line-height: 1.55; }
.wb-bar { height: 5px; border-radius: 5px; background: #edf2f8; overflow: hidden; margin-top: 9px; }
.wb-bar i { display: block; height: 100%; background: linear-gradient(90deg,#8bb8e3,#5d8fc7); border-radius: 5px; }
.wb-list { margin: 8px 0 0; padding: 0; list-style: none; }
.wb-list li {
  display: flex; justify-content: space-between; gap: 10px; padding: 6px 0;
  border-top: 1px dashed #edf1f6; color: #647286; font-size: 12px;
}
.wb-list li:first-child { border-top: 0; }
.wb-list b { font-weight: 600; color: #405065; }
.wb-status { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: #647286; }
.wb-dot { width: 7px; height: 7px; border-radius: 50%; background: #9aa5b2; }
.wb-dot.up { background: #4eb680; }
.wb-dot.down { background: #d07b7b; }
.wb-log {
  margin-top: 8px; max-height: 170px; overflow: auto; background: #f7fafc;
  border-radius: 8px; padding: 9px; color: #8491a1; font-size: 10px; line-height: 1.6;
  white-space: pre-wrap;
}

/* bottom nav */
.bottom-nav {
  flex: 0 0 auto; display: flex; align-items: stretch;
  padding: 0 12px calc(5px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.94); border-top: 1px solid var(--line);
  backdrop-filter: blur(14px); position: relative; z-index: 8;
}
.nav-item {
  flex: 1; border: 0; background: transparent; color: #94a3b8;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 0 4px; font-size: 10px;
}
.nav-item.active { color: var(--blue-deep); font-weight: 600; }
.nav-icon { font-size: 18px; line-height: 1.1; }

/* viewer */
.viewer {
  position: fixed; inset: 0; z-index: 30; background: rgba(8,12,18,.9);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.viewer button {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.16); color: #fff; font-size: 24px;
}

@media (min-width: 700px) {
  .messages { padding-left: 28px; padding-right: 28px; }
  .section-head { padding-left: 26px; padding-right: 26px; }
  .workbench-content { padding-left: 26px; padding-right: 26px; }
  .moments-list { padding-left: 26px; padding-right: 26px; }
  .wb-grid { grid-template-columns: repeat(3, 1fr); }
  .wb-card.wide { grid-column: span 2; }
}
