:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --ink: #161817;
  --muted: #777b78;
  --line: #e8e9e5;
  --soft: #eff0ed;
  --green: #159987;
  --green-soft: #e4f4ef;
  --blue: #3a86c8;
  --blue-soft: #e7f1fa;
  --danger: #c95050;
  --shadow: 0 14px 42px rgba(25, 33, 29, .08);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 22px calc(118px + env(safe-area-inset-bottom));
}
.app-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.app-header h1 { margin: 0; font-size: clamp(34px, 9vw, 48px); line-height: 1.06; letter-spacing: -.055em; }
.app-header p { margin: 10px 0 0; color: var(--muted); font-size: 16px; }
.icon-button {
  width: 44px; height: 44px; display: grid; place-items: center; flex: 0 0 auto;
  border: 0; border-radius: 50%; color: var(--ink); background: transparent; cursor: pointer;
}
.icon-button:active { background: var(--soft); }
.icon-button svg { width: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.device-presence { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 32px 0 24px; }
.presence-item { display: flex; align-items: center; gap: 11px; min-width: 0; }
.presence-icon, .timeline-icon { display: grid; place-items: center; flex: 0 0 auto; border-radius: 17px; font-size: 21px; }
.presence-icon::before, .timeline-icon::before { content: ""; width: 21px; height: 14px; border: 2px solid currentColor; border-radius: 3px; }
.presence-icon::after, .timeline-icon::after { content: ""; width: 12px; height: 2px; margin-top: -12px; border-radius: 2px; background: currentColor; box-shadow: 0 3px 0 -1px currentColor; }
.presence-icon { width: 48px; height: 48px; }
.presence-item.small .presence-icon, .timeline-entry.small .timeline-icon { color: var(--green); background: var(--green-soft); }
.presence-item.gpu .presence-icon, .timeline-entry.gpu .timeline-icon { color: var(--blue); background: var(--blue-soft); }
.presence-copy { min-width: 0; }
.presence-copy strong { display: block; font-size: 16px; }
.presence-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.presence-copy span::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--green); }

.device-tabs { display: grid; grid-template-columns: repeat(3, 1fr); padding: 5px; border-radius: 19px; background: #ececea; }
.device-tabs button { min-height: 42px; border: 0; border-radius: 15px; color: #8a8d8a; background: transparent; font-weight: 650; cursor: pointer; }
.device-tabs button.active { color: var(--ink); background: var(--surface); box-shadow: 0 3px 15px rgba(31, 37, 34, .07); }
.feed-meta { display: flex; align-items: center; justify-content: space-between; margin: 16px 2px 4px; color: var(--muted); font-size: 12px; }
.feed-meta span { display: inline-flex; align-items: center; gap: 7px; }
.feed-meta i { width: 7px; height: 7px; border-radius: 50%; background: #b1b4b1; }
.feed-meta .online i { background: var(--green); }
.feed-meta .offline { color: var(--danger); }
.feed-meta .offline i { background: var(--danger); }
.feed-meta button { border: 0; padding: 8px; color: var(--muted); background: transparent; cursor: pointer; }

.conversation-feed { position: relative; }
.conversation-feed::before { content: ""; position: absolute; top: 28px; bottom: 24px; left: 25px; width: 1px; background: var(--line); }
.timeline-entry { position: relative; display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 14px; padding: 26px 0 30px; border-bottom: 1px solid var(--line); }
.timeline-entry:last-child { border-bottom: 0; }
.timeline-icon { width: 52px; height: 52px; z-index: 1; font-size: 22px; }
.entry-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 2px 0 18px; }
.entry-head strong { font-size: 18px; }
.entry-head time { color: var(--muted); font-size: 12px; }
.messages { display: grid; gap: 12px; }
.bubble { width: fit-content; max-width: min(92%, 560px); padding: 13px 15px; border-radius: 18px; line-height: 1.62; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { justify-self: end; border-bottom-right-radius: 6px; background: #eaeae8; }
.bubble.assistant { justify-self: start; border-bottom-left-radius: 6px; background: var(--surface); box-shadow: 0 7px 22px rgba(29, 35, 32, .055); }
.legacy-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.progress { width: min(280px, 100%); height: 4px; margin-top: 2px; overflow: hidden; border: 0; border-radius: 999px; background: #dedfdb; appearance: none; }
.progress::-webkit-progress-bar { border-radius: 999px; background: #dedfdb; }
.progress::-webkit-progress-value { border-radius: 999px; background: var(--green); }
.progress::-moz-progress-bar { border-radius: 999px; background: var(--green); }
.entry-status { display: inline-flex; align-items: center; gap: 7px; margin-top: 12px; color: var(--green); font-size: 13px; font-weight: 650; }
.entry-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 5px rgba(21, 153, 135, .1); }
.entry-status.attention { color: var(--danger); }
.empty-state { display: grid; gap: 7px; padding: 72px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 18px; }

.notification-dock {
  position: fixed; z-index: 8; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(calc(100% - 24px), 716px); display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 14px 13px 17px; border: 1px solid rgba(20, 30, 25, .06); border-radius: 24px;
  background: rgba(255, 255, 255, .94); box-shadow: var(--shadow); backdrop-filter: blur(18px);
}
.dock-copy { display: flex; align-items: center; gap: 12px; min-width: 0; }
.dock-copy .bell { display: grid; place-items: center; width: 34px; height: 34px; color: var(--green); font-size: 28px; }
.dock-copy strong, .dock-copy span { display: block; }
.dock-copy strong { font-size: 15px; }
.dock-copy span { max-width: 190px; margin-top: 2px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.primary, .secondary, .danger-text { min-height: 44px; border-radius: 14px; padding: 0 18px; cursor: pointer; }
.primary { border: 0; color: #fff; background: var(--green); font-weight: 750; }
.primary:disabled { opacity: .46; cursor: not-allowed; }
.secondary { border: 1px solid var(--line); color: var(--ink); background: var(--surface); font-weight: 650; }
.wide { width: 100%; }

.login-screen { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 22px; background: var(--bg); }
.login-card { width: min(390px, 100%); display: grid; gap: 15px; }
.login-mark { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 19px; color: #fff; background: var(--green); font-weight: 850; }
.login-card h1 { margin: 8px 0 0; font-size: 34px; letter-spacing: -.045em; }
.login-card p { margin: -4px 0 8px; color: var(--muted); line-height: 1.6; }
.login-card label, .device-form label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.login-card input, .device-form input { width: 100%; min-height: 50px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface); outline: none; }
.login-card input:focus, .device-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(21,153,135,.1); }
.form-message { min-height: 20px; color: var(--danger) !important; font-size: 13px; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 18; background: rgba(23, 27, 25, .28); backdrop-filter: blur(4px); }
.settings-sheet { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 760px); max-height: 88vh; overflow: auto; padding: 9px 22px calc(24px + env(safe-area-inset-bottom)); border-radius: 28px 28px 0 0; background: var(--bg); box-shadow: 0 -24px 70px rgba(24,31,27,.16); }
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 10px; border-radius: 999px; background: #d4d5d1; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px 18px; }
.sheet-head h2 { margin: 0; font-size: 28px; }
.text-button { border: 0; padding: 8px 0 8px 18px; color: var(--green); background: transparent; font-weight: 700; cursor: pointer; }
.setting-group { margin-bottom: 14px; padding: 20px; border-radius: 20px; background: var(--surface); }
.setting-group h3, .setting-group summary { margin: 0; font-size: 17px; font-weight: 750; }
.setting-group p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.advanced summary { cursor: pointer; }
.device-form { display: grid; gap: 12px; margin-top: 16px; }
.secret-output { margin-top: 14px; padding: 12px; border-radius: 12px; color: #806218; background: #fff5cf; overflow-wrap: anywhere; font-size: 12px; }
.secret-output code { display: block; margin-top: 6px; }
.registered-devices { display: grid; gap: 9px; margin-top: 14px; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.device-row strong, .device-row span { display: block; }
.device-row span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.device-row button { border: 0; padding: 8px; color: var(--muted); background: transparent; cursor: pointer; }
.danger-text { margin-top: 4px; border: 0; color: var(--danger); background: transparent; }

@media (min-width: 761px) {
  .app-shell { padding-top: 52px; }
  .settings-sheet { bottom: 18px; max-height: calc(100vh - 36px); border-radius: 28px; }
}

@media (max-width: 420px) {
  .app-shell { padding-left: 18px; padding-right: 18px; }
  .device-presence { gap: 8px; }
  .presence-icon { width: 43px; height: 43px; border-radius: 15px; }
  .presence-copy strong { font-size: 15px; }
  .timeline-entry { grid-template-columns: 46px minmax(0, 1fr); gap: 12px; }
  .timeline-icon { width: 46px; height: 46px; }
  .conversation-feed::before { left: 22px; }
}

@media (prefers-reduced-motion: no-preference) {
  .settings-sheet { animation: rise .22s ease-out; }
  @keyframes rise { from { transform: translate(-50%, 18px); opacity: .4; } }
}
