:root {
  color-scheme: light;
  --green: #07c160;
  --green-dark: #06ad56;
  --page: #ededed;
  --panel: #f7f7f7;
  --ink: #171717;
  --muted: #8a8a8a;
  --line: #d9d9d9;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: #dfe3e6; color: var(--ink); overscroll-behavior: none; }
button, textarea { font: inherit; }
button { border: 0; cursor: pointer; }

.app-shell {
  width: min(100%, 920px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--page);
  box-shadow: 0 0 45px #1b273322;
}

.app-header {
  z-index: 2;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: max(10px, env(safe-area-inset-top)) 22px 10px;
  background: rgba(247,247,247,.94);
  border-bottom: 1px solid #d8d8d8;
  backdrop-filter: blur(16px);
}
.transfer-icon, .empty-icon {
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--green);
  border-radius: 10px;
}
.transfer-icon { width: 44px; height: 44px; }
.transfer-icon svg { width: 28px; height: 28px; }
.transfer-icon path, .empty-icon path, #file-button path {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.title-wrap { min-width: 0; }
.title-wrap h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .02em; }
.title-wrap p { display: flex; align-items: center; gap: 6px; margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.title-wrap #room-info { overflow-wrap: anywhere; }
.title-wrap #room-info[hidden] { display: none; }
.online-dot { width: 6px; height: 6px; border-radius: 50%; background: #a9a9a9; }
.online-dot.connected { background: var(--green); box-shadow: 0 0 0 3px #07c1601a; }
.header-actions { margin-left: auto; display: flex; gap: 3px; }
.header-actions button { width: 38px; height: 38px; display: grid; place-items: center; color: #666; background: transparent; border-radius: 8px; }
.header-actions button:hover { background: #e9e9e9; }
.header-actions svg { width: 20px; height: 20px; }
.header-actions path { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#timeline {
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px 34px;
  scrollbar-width: thin;
  scrollbar-color: #c5c5c5 transparent;
}
#empty-state { min-height: 100%; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); text-align: center; }
#empty-state[hidden] { display: none; }
.empty-icon { width: 60px; height: 60px; margin-bottom: 6px; background: #d5d5d5; }
.empty-icon svg { width: 36px; }
#empty-state strong { color: #606060; font-size: 16px; font-weight: 500; }
#empty-state span { font-size: 13px; }
#load-older { display: block; margin: -8px auto 18px; padding: 7px 14px; color: #777; background: #dedede; border-radius: 15px; font-size: 12px; }
#load-older:hover { color: #444; background: #d5d5d5; }
#load-older[hidden] { display: none; }
#load-older:disabled { cursor: wait; opacity: .65; }

.date-divider { display: flex; justify-content: center; margin: 4px 0 20px; }
.date-divider span { padding: 4px 10px; color: #999; font-size: 12px; background: #e4e4e4; border-radius: 5px; }
.message-row { display: flex; flex-direction: column; align-items: flex-start; margin: 0 0 18px; animation: arrive .2s ease-out; }
.message-row.mine { align-items: flex-end; }
.message-time { margin: 0 7px 5px; color: #9a9a9a; font-size: 11px; }
.bubble { position: relative; max-width: min(76%, 570px); border-radius: 6px; box-shadow: 0 1px 1px #0000000a; }
.bubble::before { content: ""; position: absolute; top: 13px; left: -6px; width: 12px; height: 12px; background: inherit; transform: rotate(45deg); }
.mine .bubble::before { left: auto; right: -6px; }
.text-bubble { padding: 10px 13px; background: #fff; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.mine .text-bubble { background: #95ec69; }
.message-actions { display: flex; gap: 2px; margin: 4px 5px 0; opacity: 0; transition: opacity .15s; }
.message-row:hover .message-actions, .message-actions:focus-within { opacity: 1; }
.message-actions button { padding: 3px 6px; color: #888; background: transparent; border-radius: 4px; font-size: 11px; }
.message-actions button:hover { color: #444; background: #0000000a; }

.image-bubble { padding: 0; overflow: hidden; background: #ddd; cursor: zoom-in; }
.image-bubble::before { display: none; }
.image-bubble img { display: block; max-width: min(360px, 58vw); max-height: 360px; object-fit: contain; }
.file-bubble { min-width: 260px; padding: 14px 15px; display: grid; grid-template-columns:minmax(0,1fr) 48px; gap: 18px; align-items: center; color: inherit; text-decoration: none; background: #fff; }
.mine .file-bubble { background: #fff; }
.file-name { overflow: hidden; color: #222; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; }
.file-size { margin-top: 8px; color: #999; font-size: 12px; }
.file-icon { position: relative; width: 42px; height: 48px; display: grid; place-items: end center; padding-bottom: 7px; color: #fff; font-size: 9px; font-weight: 700; background: #6aa8df; border-radius: 3px; }
.file-icon::after { content:""; position:absolute; top:0; right:0; border-width: 0 0 11px 11px; border-style: solid; border-color: transparent transparent #d8ecfd transparent; }

.composer { z-index: 3; padding: 11px 18px max(10px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
#send-form { display: grid; grid-template-columns: 42px minmax(0,1fr) auto; gap: 10px; align-items: end; }
#file-button { width: 42px; height: 42px; display: grid; place-items: center; color: #555; background: transparent; border-radius: 8px; }
#file-button:hover { background: #e8e8e8; }
#file-button svg { width: 27px; height: 27px; }
#message-input { width: 100%; min-height: 42px; max-height: 126px; padding: 10px 12px; resize: none; color: var(--ink); background: #fff; border: 1px solid #d5d5d5; border-radius: 7px; line-height: 1.45; outline: none; }
#message-input:focus { border-color: #b8b8b8; }
#message-input::placeholder { color: #aaa; }
#send-button { min-width: 64px; height: 42px; padding: 0 15px; color: #fff; background: var(--green); border-radius: 6px; }
#send-button:hover:not(:disabled) { background: var(--green-dark); }
#send-button:disabled { color: #aaa; background: #e5e5e5; cursor: default; }
.composer-hint { margin: 7px 0 0 53px; color: #a0a0a0; font-size: 11px; }

#upload-list:empty { display: none; }
#upload-list { display: grid; gap: 7px; margin: 0 0 10px 52px; }
.upload-item { display: grid; grid-template-columns:minmax(0,1fr) auto auto; gap: 8px; align-items: center; padding: 8px 10px; color: #666; background: #ededed; border-radius: 6px; font-size: 12px; }
.upload-item.failed { color: #a33; background: #f7e9e9; }
.upload-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.upload-action { padding: 2px 6px; color: #777; background: transparent; border-radius: 4px; font-size: 11px; }
.upload-action:hover { background: #0000000b; }
.upload-track { grid-column: 1 / -1; height: 3px; overflow: hidden; background: #d4d4d4; border-radius: 3px; }
.upload-progress { width: 0; height: 100%; background: var(--green); transition: width .15s; }

#drop-mask { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: #171d24b8; backdrop-filter: blur(4px); }
#drop-mask[hidden] { display: none; }
#drop-mask div { padding: 32px 54px; color: #fff; border: 2px dashed #ffffffb0; border-radius: 18px; font-size: 20px; }
#image-viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 30px; border: 0; background: #101010ed; }
#image-viewer[open] { display: grid; place-items: center; }
#image-viewer::backdrop { background: transparent; }
#image-viewer img { max-width: 94vw; max-height: 90dvh; object-fit: contain; }
#viewer-close { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 20px; width: 42px; height: 42px; color: #fff; background: #ffffff18; border-radius: 50%; font-size: 30px; line-height: 1; }
#viewer-download { position: fixed; right: 20px; bottom: max(18px, env(safe-area-inset-bottom)); padding: 9px 15px; color: #fff; background: #ffffff1c; border: 1px solid #ffffff30; border-radius: 7px; text-decoration: none; font-size: 13px; }
#delete-confirm { width: min(420px, calc(100vw - 40px)); max-height: calc(100dvh - 48px); margin: auto; padding: 0; overflow: hidden; color: var(--ink); background: #fff; border: 0; border-radius: 16px; box-shadow: 0 16px 60px #0003; }
#delete-confirm::backdrop { background: #0007; }
#delete-confirm-title { margin: 0; padding: 24px 24px 12px; font-size: 18px; font-weight: 600; }
#delete-confirm-message { max-height: min(45dvh, 360px); margin: 0; padding: 0 24px 24px; overflow-y: auto; color: #666; font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid #eee; }
.confirm-actions button { min-height: 52px; padding: 14px; color: #666; background: #fff; }
.confirm-actions button + button { border-left: 1px solid #eee; }
.confirm-actions .confirm-button { color: var(--green-dark); font-weight: 600; }
.confirm-actions button:hover { background: #f7f7f7; }
.confirm-actions button:focus-visible { outline: 2px solid var(--green); outline-offset: -4px; }
#toast { position: fixed; z-index: 40; left: 50%; bottom: 120px; max-width: calc(100vw - 32px); padding: 9px 16px; color: #fff; background: #222d; border-radius: 6px; font-size: 13px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }

@keyframes arrive { from { opacity: 0; transform: translateY(5px); } }
@media (max-width: 600px) {
  .app-header { min-height: 58px; padding-left: 14px; padding-right: 14px; }
  .transfer-icon { width: 38px; height: 38px; border-radius: 8px; }
  .transfer-icon svg { width: 24px; }
  #timeline { padding: 18px 14px 26px; }
  .bubble { max-width: 84%; }
  .image-bubble img { max-width: 68vw; max-height: 310px; }
  .file-bubble { min-width: min(260px, 74vw); }
  .composer { padding-left: 8px; padding-right: 8px; }
  #send-form { grid-template-columns: 40px minmax(0,1fr) auto; gap: 7px; }
  #file-button { width: 40px; }
  #send-button { min-width: 58px; padding: 0 11px; }
  .composer-hint { margin-left: 47px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  #upload-list { margin-left: 47px; }
}
@media (hover: none) {
  .message-actions { opacity: .72; }
}
