.account-appearance { padding: 8px 0 20px; margin-bottom: 16px; border-bottom: 1px solid #ddd; }
.account-appearance textarea { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; }
.appearance-preview { min-height: 112px; display: flex; align-items: center; margin: 12px 0; }
.appearance-preview img { object-fit: contain; background: #eee; border-radius: 6px; }
.appearance-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.appearance-actions button { width: auto; margin: 0; }
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --line: #e2e8f0;
  --danger: #dc2626;
  --pos: #16a34a;
  --neg: #dc2626;
  --sticky-tabs-top: calc(env(safe-area-inset-top) + 64px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 {
  font-size: 18px; margin: 0; flex: 1; font-weight: 600;
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .back { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; padding: 0 4px; }
.topbar .sub {
  font-size: 12px; opacity: .85; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.content { flex: 1; padding: 16px; padding-bottom: 24px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px; margin-bottom: 14px;
}
h2 { font-size: 16px; margin: 0 0 12px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 16px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 44px; }
button {
  font-size: 15px; font-weight: 600; padding: 12px 14px; border-radius: 10px;
  border: none; background: var(--brand); color: #fff; cursor: pointer; width: 100%;
  margin-top: 12px;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: #e2e8f0; color: var(--ink); }
button.ghost { background: none; color: var(--brand); width: auto; padding: 6px 8px; margin: 0; }
button.danger { background: var(--danger); }
button.small { width: auto; padding: 7px 12px; font-size: 13px; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { margin-top: 0; }
.muted { color: var(--muted); font-size: 13px; }
.setting-toggle { display: flex; align-items: center; gap: 12px; margin: 14px 0 4px; color: var(--ink); }
.setting-toggle .grow { min-width: 0; }
.setting-title { display: block; font-size: 14px; font-weight: 600; }
.setting-note { display: block; margin-top: 2px; line-height: 1.3; }
.setting-toggle input[type="checkbox"] { width: 22px; height: 22px; padding: 0; margin: 0; flex: 0 0 auto; accent-color: var(--brand); }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 18px; }
.center { text-align: center; }
.hidden { display: none !important; }
.link { color: var(--brand); cursor: pointer; text-decoration: underline; background: none; border: none; font-size: 14px; }

.list-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 4px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; }
.list-item .title { font-weight: 600; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0; text-transform: uppercase;
}

/* group banner */
.group-banner {
  position: relative;
  height: 140px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: flex-end;
}
.group-banner .label {
  color: #fff; font-weight: 700; font-size: 20px; padding: 12px 16px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .65);
}
.group-banner .edit {
  position: absolute; top: 10px; right: 10px; width: auto; margin: 0;
  background: rgba(0, 0, 0, .45); color: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; font-weight: 600;
}

/* tabs */
.tabs-wrap {
  position: sticky; top: var(--sticky-tabs-top); z-index: 15;
  background: var(--card); border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 8px rgba(15, 23, 42, .08);
}
.tabs {
  display: flex; overflow-x: auto; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  width: auto; flex: 1 0 auto; min-width: max-content; background: none; color: var(--muted);
  border: none; border-bottom: 2px solid transparent; white-space: nowrap;
  border-radius: 0; margin: 0; padding: 12px 11px; font-weight: 600; font-size: 14px;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-scroll-indicator {
  position: absolute; top: 0; bottom: 0; width: 28px; z-index: 2; pointer-events: none;
  display: flex; align-items: center; justify-content: center; color: var(--brand);
  font-size: 22px; font-weight: 700; opacity: 0; transition: opacity .15s ease;
}
.tab-scroll-left { left: 0; background: linear-gradient(90deg, var(--card) 45%, rgba(255,255,255,0)); }
.tab-scroll-right { right: 0; background: linear-gradient(270deg, var(--card) 45%, rgba(255,255,255,0)); }
.tabs-wrap.can-scroll-left .tab-scroll-left,
.tabs-wrap.can-scroll-right .tab-scroll-right { opacity: 1; }
@media (max-width: 380px) {
  .tabs button { padding-left: 9px; padding-right: 9px; font-size: 13px; }
}

/* chat */
.context-meter {
  margin: 10px 12px 0; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--muted); font-size: 12px;
}
.context-meter.warn { background: #fffbeb; border-color: #f59e0b; color: #7c2d12; }
.context-meter.in-modal { margin: 10px 0; }
.chat-search {
  position: sticky; top: calc(var(--sticky-tabs-top) + 45px); z-index: 14;
  display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: rgba(241, 245, 249, .96); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.chat-search input { flex: 1 1 auto; min-width: 0; height: 36px; padding: 7px 10px; font-size: 14px; }
.chat-search button { margin: 0; }
.chat-search .small { padding: 8px 10px; min-height: 36px; }
.chat-search-status { flex: 0 0 48px; text-align: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.chat-search-clear { flex: 0 0 auto; }
.event.search-match { scroll-margin-top: calc(var(--sticky-tabs-top) + 110px); }
.event.search-match > .bubble,
.event.search-match .recap { box-shadow: 0 0 0 2px #f59e0b; }
.event.search-current > .bubble,
.event.search-current .recap { box-shadow: 0 0 0 3px var(--brand), 0 4px 14px rgba(15, 118, 110, .24); }
.chat { display: flex; flex-direction: column; gap: 8px; padding: 12px 12px 132px; }
.otto-responding {
  position: fixed; z-index: 18; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 72px);
  transform: translateX(-50%); display: flex; align-items: center; gap: 7px;
  max-width: calc(100vw - 24px); padding: 7px 11px; border: 1px solid #ddd6fe;
  border-radius: 999px; background: #f5f3ff; color: #5b21b6;
  box-shadow: 0 3px 12px rgba(15, 23, 42, .14); font-size: 12px; font-weight: 600;
}
.otto-responding-dots { display: flex; gap: 3px; align-items: center; }
.otto-responding-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  animation: otto-dot 1.1s infinite ease-in-out; opacity: .35;
}
.otto-responding-dots span:nth-child(2) { animation-delay: .15s; }
.otto-responding-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes otto-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30% { transform: translateY(-3px); opacity: 1; }
}
.chat-history-actions { display: flex; justify-content: center; padding: 2px 0 8px; }
.chat-history-actions button { margin: 0; }
.chat-notice {
  align-self: center; max-width: 92%; background: #fffbeb; border: 1px solid #fde68a;
  color: #92400e; border-radius: 999px; padding: 6px 12px; font-size: 12px;
}
.event { max-width: 85%; }
.event.system { align-self: center; max-width: 100%; text-align: center; }
.event.system .bubble {
  background: #e2e8f0; color: var(--muted); font-size: 13px; padding: 6px 12px;
  border-radius: 999px; display: inline-block;
}
.event.msg.mine { align-self: flex-end; }
.event.msg .bubble {
  background: #fff; border: 1px solid var(--line); padding: 9px 12px; border-radius: 14px;
}
.event.msg.mine .bubble { background: var(--brand); color: #fff; border-color: var(--brand); }
.event .who { font-size: 12px; color: var(--muted); margin: 0 6px 2px; }
.event.msg.bot { align-self: flex-start; max-width: 90%; }
.event.msg.bot .who { color: #6d28d9; font-weight: 600; }
.event.msg.bot .bubble { background: #f5f3ff; border-color: #ddd6fe; color: #3b0764; }
.event .bubble .chat-link {
  color: #0369a1; font-weight: 600; text-decoration: underline;
  text-decoration-thickness: 1px; text-underline-offset: 2px; overflow-wrap: anywhere;
}
.event.msg.mine .bubble .chat-link { color: #fff; }
.event .bubble .chat-link:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.bot-img { display: block; width: 100%; max-width: 320px; height: auto; border-radius: 14px; margin-top: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.chat-img { display: block; width: 100%; max-width: 320px; height: auto; border-radius: 14px; margin-top: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.zoomable-img { cursor: zoom-in; }
.zoomable-img:focus-visible { outline: 3px solid rgba(37,99,235,.45); outline-offset: 3px; }
.event.msg.mine .chat-img { margin-left: auto; }
.recap { max-width: 320px; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.recap img { display: block; width: 100%; height: auto; }
.recap-cap { padding: 7px 11px; font-size: 12px; color: var(--muted); text-align: left; }
.event .time { font-size: 10px; opacity: .6; margin-top: 2px; }
.event.compacted .bubble { border-style: dashed; }
.context-marker {
  display: inline-block; margin-top: 4px; padding: 3px 7px; border-radius: 999px;
  background: #f8fafc; border: 1px dashed #cbd5e1; color: var(--muted); font-size: 10px;
}
.context-compacted-event .bubble { background: #eef2ff; color: #3730a3; }

.composer {
  position: fixed; bottom: 0; left: 0; right: 0; max-width: 640px; margin: 0 auto;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  display: flex; gap: 8px; align-items: flex-end;
}
.composer button { width: auto; margin: 0; }
.composer .composer-icon { width: 42px; height: 42px; flex: 0 0 42px; padding: 0; }
.composer .composer-icon.active { background: #ccfbf1; color: var(--brand-dark); }
.composer .composer-send { min-height: 42px; flex: 0 0 auto; }
.composer-field {
  flex: 1 1 auto; min-width: 0; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 5px 8px; display: flex; flex-direction: column; gap: 5px;
}
.composer-field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(15, 118, 110, .14); }
.composer-field textarea {
  min-height: 30px; max-height: 120px; padding: 5px 2px; border: 0; border-radius: 0;
  resize: vertical; background: transparent; line-height: 1.35;
}
.composer-field textarea:focus { outline: none; }
.composer-attachment {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  border-bottom: 1px solid var(--line); padding: 1px 2px 6px;
}
.composer-attachment img { width: 34px; height: 34px; border-radius: 7px; object-fit: cover; flex: 0 0 auto; background: #f8fafc; }
.composer-attachment-text { min-width: 0; flex: 1 1 auto; line-height: 1.2; }
.composer-attachment-title { font-size: 12px; font-weight: 700; color: var(--brand-dark); }
.composer-attachment-name { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-attachment-remove {
  width: 28px; height: 28px; flex: 0 0 28px; padding: 0; border-radius: 999px;
  background: #e2e8f0; color: var(--ink); font-size: 14px; line-height: 1;
}
@media (max-width: 380px) {
  .composer { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .composer .composer-icon { width: 38px; height: 38px; flex-basis: 38px; }
  .composer .composer-send { padding-left: 10px; padding-right: 10px; }
}

.balance-row { display: flex; justify-content: space-between; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.amt-pos { color: var(--pos); font-weight: 600; }
.amt-neg { color: var(--neg); font-weight: 600; }
.transfer { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 10px; padding: 12px; margin-bottom: 8px; }

.fact-item { align-items: flex-start; cursor: default; }
.fact-avatar { width: 30px; height: 30px; font-size: 12px; background: #334155; }
.fact-text { line-height: 1.35; font-weight: 500; }
.timer-list { margin-bottom: 12px; }
.timer-item { align-items: flex-start; cursor: default; }
.timer-kind {
  width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center;
  border-radius: 8px; background: #e0f2fe; color: #075985; font-size: 13px; font-weight: 800;
}
.timer-prompt { line-height: 1.35; font-weight: 600; overflow-wrap: anywhere; }
.timer-schedule { margin-top: 3px; line-height: 1.35; }
.timer-fired { margin-top: 2px; font-size: 11px; }

.diary-picker select { margin-top: 4px; }
.diary-day-meta { margin-top: 8px; }
.diary-entry h2 { margin-bottom: 6px; }
.diary-entry-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.diary-entry-head .grow { flex: 1; min-width: 0; }
.diary-entry-head button { width: auto; margin: 0; flex: 0 0 auto; }
.diary-image-frame { margin: 0; min-width: 0; }
.diary-inline-image { margin: 14px 0 16px; }
.diary-inline-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0 16px; }
.diary-img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #f8fafc; }
.diary-image-frame figcaption { margin-top: 4px; font-size: 12px; line-height: 1.25; }
.diary-body { margin-top: 14px; line-height: 1.55; font-size: 15px; }
.diary-body p { margin: 0 0 12px; }
.diary-body p:last-child { margin-bottom: 0; }
.diary-status { margin-top: 10px; min-height: 18px; }
@media (max-width: 460px) {
  .diary-entry-head { display: block; }
  .diary-entry-head button { margin-top: 10px; }
}
.compact-card { margin-top: 12px; }
.compaction-review textarea { min-height: 160px; font-size: 14px; }
.compaction-event { padding: 10px 0; border-bottom: 1px solid var(--line); }
.compaction-event:last-child { border-bottom: none; }
.compaction-body { margin-top: 4px; font-size: 14px; line-height: 1.35; white-space: pre-wrap; }

.split-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.split-row .name { flex: 1; }
.split-row input { width: 110px; }

.fab-bar { display: flex; gap: 8px; position: fixed; bottom: calc(env(safe-area-inset-bottom) + 16px); left: 16px; right: 16px; max-width: 608px; margin: 0 auto; }
.fab-bar button { box-shadow: 0 4px 12px rgba(0,0,0,.18); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  max-height: 92vh; overflow-y: auto;
}
.modal h2 { display: flex; justify-content: space-between; align-items: center; }
.image-viewer-full {
  position: fixed; inset: 0; z-index: 80; background: rgba(2, 6, 23, .96); color: #fff;
  display: flex; flex-direction: column; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.image-viewer-toolbar { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.image-viewer-title { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; opacity: .86; }
.image-viewer-actions { display: flex; gap: 8px; align-items: center; }
.image-viewer-action {
  width: auto; margin: 0; border-radius: 999px; padding: 8px 11px;
  border: 1px solid rgba(255,255,255,.24); background: rgba(255,255,255,.12); color: #fff;
  font-size: 13px; text-decoration: none; line-height: 1.1;
}
.image-viewer-action:hover { background: rgba(255,255,255,.2); }
.image-viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.image-viewer-img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }
@media (max-width: 430px) {
  .image-viewer-title { display: none; }
  .image-viewer-toolbar, .image-viewer-actions { gap: 6px; }
  .image-viewer-action { padding: 8px 9px; font-size: 12px; }
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 100; transition: opacity .3s; box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.banner {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.banner button { width: auto; margin: 0; }

.message-actions { display: grid; gap: 8px; }
.message-actions button { margin: 0; }
.event .message-menu { width: 36px; height: 32px; padding: 0; margin: 0; font-size: 24px; align-self: flex-start; }
.otto-replay-modal { width: min(960px, calc(100vw - 24px)); max-width: 960px; }
.otto-replay-content, .otto-replay-columns section { min-width: 0; }
.otto-replay-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.otto-replay-columns .bubble, .replay-image-prompt { white-space: pre-wrap; overflow-wrap: anywhere; }
.replay-json { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; max-height: 360px; overflow: auto; }
.otto-replay-modal h3 { font-size: 16px; margin: 16px 0 8px; }
.otto-profile-settings { padding: 16px 0; border-bottom: 1px solid var(--border, #ddd); }
.otto-profile-settings h2 { font-size: 18px; }
@media (max-width: 640px) {
  .otto-replay-columns { grid-template-columns: minmax(0, 1fr); gap: 8px; }
}
