:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --paper: #f2f6fb;
  --card: rgba(255, 255, 255, .84);
  --line: rgba(30, 64, 110, .12);
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --sky: #93c5fd;
  --mist: #e5edf7;
  --danger: #b33f36;
  --shadow: 0 24px 70px rgba(30, 64, 110, .14);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--paper); overflow-x: hidden; }
button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.ambient { position: fixed; border-radius: 999px; filter: blur(1px); pointer-events: none; z-index: -1; }
.ambient-a { width: 36rem; height: 36rem; left: -14rem; top: -17rem; background: radial-gradient(circle, rgba(147, 197, 253, .52), rgba(147, 197, 253, 0) 67%); }
.ambient-b { width: 40rem; height: 40rem; right: -18rem; bottom: -20rem; background: radial-gradient(circle, rgba(37, 99, 235, .2), rgba(37, 99, 235, 0) 67%); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 3rem 1.5rem; }
.login-card { width: min(100%, 31rem); padding: 3.4rem; border: 1px solid rgba(255,255,255,.8); border-radius: 2rem; background: var(--card); backdrop-filter: blur(22px); box-shadow: var(--shadow); }
.brand-mark { display: flex; align-items: end; gap: .26rem; width: 2.6rem; height: 2.6rem; padding: .55rem; border-radius: .85rem; background: var(--blue); box-shadow: 0 8px 20px rgba(37,99,235,.25); }
.brand-mark span { display: block; flex: 1; border-radius: 99px; background: var(--sky); }
.brand-mark span:nth-child(1) { height: 42%; }
.brand-mark span:nth-child(2) { height: 82%; }
.brand-mark span:nth-child(3) { height: 60%; }
.brand-mark.compact { width: 2.45rem; height: 2.45rem; flex: 0 0 auto; }
.eyebrow { margin: 1.5rem 0 .8rem; font-size: .7rem; font-weight: 800; letter-spacing: .18em; color: var(--blue); }
.login-card h1 { margin: 0; font-size: clamp(2rem, 5vw, 2.7rem); line-height: 1.15; letter-spacing: -.045em; }
.login-copy { margin: 1.15rem 0 2rem; color: var(--muted); line-height: 1.75; }
.login-form { display: grid; gap: 1rem; }
.login-form label, .settings-dialog label { display: grid; gap: .45rem; }
.login-form label > span, .settings-dialog label > span { font-size: .78rem; font-weight: 700; color: #3d4b63; }
input, textarea { border: 1px solid var(--line); outline: none; color: var(--ink); background: rgba(255,255,255,.72); transition: border-color .2s, box-shadow .2s, background .2s; }
input:focus, textarea:focus { border-color: rgba(37,99,235,.55); box-shadow: 0 0 0 4px rgba(37,99,235,.1); background: #fff; }
.login-form input { width: 100%; height: 3.2rem; padding: 0 1rem; border-radius: .9rem; }
.primary-button { min-height: 3.2rem; padding: .8rem 1.1rem; border: 0; border-radius: .9rem; display: flex; align-items: center; justify-content: center; gap: .8rem; color: #fff; background: var(--blue); font-weight: 750; cursor: pointer; box-shadow: 0 10px 24px rgba(37,99,235,.22); transition: transform .18s, background .18s; }
.primary-button:hover { transform: translateY(-1px); background: var(--blue-dark); }
.primary-button:disabled { cursor: wait; opacity: .65; transform: none; }
.primary-button svg { width: 1.1rem; fill: none; stroke: currentColor; stroke-width: 1.8; }
.form-error { margin: 0; padding: .75rem .9rem; border-radius: .75rem; background: rgba(179,63,54,.09); color: var(--danger); font-size: .82rem; }
.privacy-note { margin: 1.4rem 0 0; text-align: center; color: var(--muted); font-size: .72rem; }
.privacy-note span { display: inline-block; width: .42rem; height: .42rem; margin-right: .35rem; border-radius: 50%; background: var(--sky); box-shadow: 0 0 0 4px rgba(147,197,253,.25); }

.app-shell { min-height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.app-header { position: sticky; top: 0; z-index: 20; height: 4.8rem; padding: 0 max(1.25rem, calc((100vw - 58rem) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(242,246,251,.84); backdrop-filter: blur(20px); }
.brand-row, .header-actions { display: flex; align-items: center; gap: .85rem; }
.app-name { margin: 0; font-size: .92rem; font-weight: 800; letter-spacing: -.02em; }
.connection-status { margin: .12rem 0 0; display: flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .68rem; }
.connection-status span { width: .45rem; height: .45rem; border-radius: 50%; background: #d49f41; }
.connection-status.online span { background: #40a26f; }
.user-chip { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; padding: .42rem .72rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .72rem; white-space: nowrap; background: rgba(255,255,255,.5); }
.icon-button, .attach-button, .send-button, .message-action { display: grid; place-items: center; border: 0; cursor: pointer; }
.icon-button { width: 2.35rem; height: 2.35rem; border-radius: 50%; background: transparent; }
.icon-button:hover { background: rgba(23,32,51,.07); }
.icon-button svg, .message-action svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.feed { overflow-y: auto; padding: 1.5rem max(1.25rem, calc((100vw - 58rem) / 2)) 2rem; scroll-behavior: smooth; }
.feed-top { display: flex; justify-content: center; min-height: 1rem; }
.quiet-button { padding: .5rem .85rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.55); cursor: pointer; font-size: .75rem; }
.quiet-button:hover { color: var(--blue); border-color: rgba(37,99,235,.3); }
.message-list { display: grid; gap: 1rem; align-items: end; }
.date-separator { display: flex; align-items: center; gap: .8rem; margin: 1rem 0 .15rem; color: #87908c; font-size: .67rem; }
.date-separator::before, .date-separator::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.message { position: relative; width: fit-content; max-width: min(86%, 46rem); justify-self: end; padding: .72rem; border: 1px solid rgba(255,255,255,.84); border-radius: 1.2rem 1.2rem .35rem 1.2rem; background: rgba(255,255,255,.86); box-shadow: 0 10px 30px rgba(30,64,110,.08); animation: enter .28s ease both; }
.message-text { min-width: min(12rem, 60vw); max-width: 38rem; }
.message-image { padding: .42rem; }
.message-file { padding: .72rem .78rem; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
.message-text { margin: 0; white-space: pre-wrap; word-break: break-word; line-height: 1.65; font-size: .94rem; }
.message-meta { margin-top: .72rem; display: flex; align-items: center; justify-content: flex-end; gap: .45rem; color: #89918e; font-size: .65rem; }
.message-actions { display: flex; gap: .2rem; margin-left: .25rem; }
.message-action { width: 1.8rem; height: 1.8rem; border-radius: 50%; color: var(--muted); background: transparent; }
.message-action:hover { color: var(--blue); background: rgba(37,99,235,.08); }
.message-action.danger:hover { color: var(--danger); background: rgba(179,63,54,.08); }
.image-frame { position: relative; display: block; width: fit-content; max-width: 100%; overflow: hidden; border-radius: .9rem; background: transparent; }
.image-open { display: block; max-width: 100%; padding: 0; border: 0; border-radius: inherit; background: transparent; cursor: zoom-in; }
.image-frame img { display: block; width: auto; height: auto; max-width: min(100%, 42rem); max-height: min(46vh, 27rem); object-fit: contain; border-radius: inherit; }
.download-fab { position: absolute; right: .65rem; bottom: .65rem; width: 2.45rem; height: 2.45rem; display: grid; place-items: center; border-radius: 50%; color: #fff; background: rgba(18,37,31,.78); backdrop-filter: blur(8px); box-shadow: 0 7px 20px rgba(0,0,0,.22); }
.download-fab:hover { background: var(--blue); }
.download-fab svg { width: 1.05rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.file-card { display: grid; grid-template-columns: auto minmax(5rem,max-content) auto; align-items: center; gap: .72rem; width: fit-content; max-width: min(100%, 42rem); min-width: 0; }
.file-icon { width: 3rem; height: 3rem; display: grid; place-items: center; border-radius: .9rem; color: var(--blue); background: rgba(37,99,235,.09); }
.file-icon svg { width: 1.45rem; fill: none; stroke: currentColor; stroke-width: 1.5; }
.file-details { min-width: 0; }
.file-name { max-width: min(25rem, 48vw); margin: 0; overflow: hidden; text-overflow: ellipsis; font-size: .88rem; font-weight: 750; white-space: nowrap; }
.file-size { margin: .25rem 0 0; color: var(--muted); font-size: .7rem; }
.download-button { display: inline-flex; align-items: center; gap: .4rem; padding: .58rem .72rem; border-radius: .72rem; color: #fff; background: var(--blue); text-decoration: none; font-size: .72rem; font-weight: 700; }
.download-button:hover { background: var(--blue-dark); }
.download-button svg { width: .9rem; fill: none; stroke: currentColor; stroke-width: 1.8; }
.empty-state { min-height: 62vh; display: grid; place-items: center; align-content: center; text-align: center; color: var(--muted); }
.empty-state h2 { margin: 1.15rem 0 .45rem; color: var(--ink); font-size: 1.25rem; }
.empty-state p { width: min(28rem, 90%); margin: 0; line-height: 1.7; font-size: .85rem; }
.empty-orbit { width: 4.4rem; height: 4.4rem; padding: .7rem; border: 1px solid rgba(37,99,235,.2); border-radius: 50%; animation: orbit 9s linear infinite; }
.empty-orbit span { display: block; width: 1rem; height: 1rem; border-radius: 50%; background: var(--sky); box-shadow: 0 0 0 8px rgba(147,197,253,.22); }
@keyframes orbit { to { transform: rotate(360deg); } }

.upload-tray { padding: .75rem max(1.25rem, calc((100vw - 58rem) / 2)); display: grid; gap: .45rem; border-top: 1px solid var(--line); background: rgba(242,246,251,.94); }
.upload-item { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .35rem .8rem; align-items: center; }
.upload-name { overflow: hidden; text-overflow: ellipsis; font-size: .75rem; font-weight: 650; white-space: nowrap; }
.upload-status { color: var(--muted); font-size: .67rem; }
.progress { grid-column: 1 / -1; height: .28rem; overflow: hidden; border-radius: 99px; background: rgba(37,99,235,.1); }
.progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--blue); transition: width .2s; }
.retry-upload { border: 0; color: var(--blue); background: none; cursor: pointer; font-size: .7rem; font-weight: 700; }

.composer-wrap { position: sticky; bottom: 0; z-index: 15; padding: .8rem max(1rem, calc((100vw - 58rem) / 2)) calc(.75rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(242,246,251,.86); backdrop-filter: blur(20px); }
.composer { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .65rem; align-items: end; padding: .5rem; border: 1px solid rgba(30,64,110,.14); border-radius: 1.3rem; background: rgba(255,255,255,.88); box-shadow: 0 12px 35px rgba(30,64,110,.09); }
.attach-button, .send-button { width: 2.55rem; height: 2.55rem; border-radius: .9rem; }
.attach-button { color: var(--blue); background: rgba(37,99,235,.08); }
.attach-button:hover { background: rgba(37,99,235,.14); }
.send-button { color: #fff; background: var(--blue); }
.send-button:hover { background: var(--blue-dark); }
.attach-button svg, .send-button svg { width: 1.15rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.text-input-wrap { display: flex; min-height: 2.55rem; }
.text-input-wrap textarea { width: 100%; max-height: 9rem; padding: .65rem .25rem; resize: none; overflow-y: auto; border: 0; background: transparent; box-shadow: none; line-height: 1.35; }
.composer-hint { margin: .45rem 0 0; text-align: center; color: #929996; font-size: .62rem; }

.drop-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 2rem; background: rgba(17,37,78,.56); backdrop-filter: blur(8px); }
.drop-overlay > div { width: min(30rem, 100%); min-height: 16rem; display: grid; place-items: center; align-content: center; gap: .65rem; border: 2px dashed rgba(255,255,255,.7); border-radius: 2rem; color: #fff; background: rgba(37,99,235,.7); }
.drop-overlay svg { width: 2.7rem; fill: none; stroke: var(--sky); stroke-width: 1.5; }
.drop-overlay strong { font-size: 1.4rem; }
.drop-overlay span { opacity: .75; font-size: .8rem; }

.settings-dialog { width: min(92vw, 30rem); padding: 0; border: 1px solid rgba(255,255,255,.82); border-radius: 1.4rem; color: var(--ink); background: #f8fbff; box-shadow: var(--shadow); }
.settings-dialog::backdrop { background: rgba(23,32,51,.4); backdrop-filter: blur(5px); }
.settings-dialog form { padding: 1.6rem; display: grid; gap: 1.2rem; }
.settings-dialog header { display: flex; justify-content: space-between; align-items: start; }
.settings-dialog header .eyebrow { margin: 0 0 .3rem; }
.settings-dialog h2 { margin: 0; font-size: 1.45rem; }
.settings-dialog label { grid-template-columns: minmax(0,1fr) auto; align-items: center; }
.settings-dialog label > small { grid-column: 1; color: var(--muted); font-size: .67rem; }
.number-field { grid-column: 2; grid-row: 1 / span 2; display: flex; align-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: .75rem; background: #fff; }
.number-field input { width: 5rem; height: 2.65rem; padding: 0 .6rem; border: 0; text-align: right; box-shadow: none; }
.number-field b { padding-right: .65rem; color: var(--muted); font-size: .68rem; }

.library-dialog { width: min(94vw, 72rem); height: min(90vh, 52rem); padding: 0; border: 0; border-radius: 1.4rem; color: var(--ink); background: #f8fbff; box-shadow: var(--shadow); }
.library-dialog::backdrop, .image-viewer::backdrop { background: rgba(9,16,30,.72); backdrop-filter: blur(6px); }
.library-panel { height: 100%; display: grid; grid-template-rows: auto auto minmax(0,1fr) auto; padding: 1.3rem; }
.dialog-header { display: flex; align-items: start; justify-content: space-between; }
.dialog-header .eyebrow { margin: 0 0 .25rem; }
.dialog-header h2 { margin: 0; font-size: 1.45rem; }
.library-tabs { display: flex; gap: .45rem; padding: 1rem 0; }
.library-tabs button { padding: .52rem .9rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: #fff; cursor: pointer; }
.library-tabs button.active { color: #fff; border-color: var(--blue); background: var(--blue); }
.library-grid { min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill,minmax(9rem,1fr)); grid-auto-rows: 10rem; gap: .32rem; align-content: start; border-radius: .9rem; }
.library-tile { position: relative; min-width: 0; overflow: hidden; border: 0; border-radius: .45rem; color: inherit; background: var(--mist); cursor: pointer; }
.library-tile > img { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform .2s; }
.library-tile:hover > img { transform: scale(1.035); }
.library-file-tile { display: grid; place-items: center; align-content: center; gap: .55rem; padding: .75rem; text-decoration: none; }
.library-file-tile svg { width: 2rem; height: 2rem; fill: none; stroke: var(--blue); stroke-width: 1.5; }
.library-file-tile strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .74rem; }
.library-file-tile small { color: var(--muted); font-size: .63rem; }
.library-tile-download { position: absolute; right: .35rem; bottom: .35rem; width: 1.9rem; height: 1.9rem; display: grid; place-items: center; border-radius: 50%; color: #fff; background: rgba(12,26,48,.76); }
.library-tile-download svg { width: .85rem; fill: none; stroke: currentColor; stroke-width: 1.8; }
.library-empty { place-self: center; color: var(--muted); }
.library-more { justify-self: center; margin-top: .9rem; }

.image-viewer { width: 100vw; max-width: none; height: 100vh; max-height: none; margin: 0; padding: 0; border: 0; color: #fff; background: rgba(5,10,20,.96); }
.image-viewer[open] { display: grid; grid-template-columns: auto minmax(0,1fr) auto; grid-template-rows: auto minmax(0,1fr); }
.viewer-toolbar { grid-column: 1 / -1; display: flex; align-items: center; gap: .55rem; min-width: 0; padding: calc(.65rem + env(safe-area-inset-top)) max(.8rem,env(safe-area-inset-right)) .65rem max(.8rem,env(safe-area-inset-left)); background: rgba(5,10,20,.76); }
.viewer-toolbar > div { min-width: 0; flex: 1; display: grid; }
.viewer-toolbar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }
.viewer-toolbar span { color: rgba(255,255,255,.62); font-size: .65rem; }
.viewer-tool, .viewer-nav { display: grid; place-items: center; border: 0; color: #fff; background: rgba(255,255,255,.1); cursor: pointer; }
.viewer-tool { width: 2.4rem; height: 2.4rem; border-radius: 50%; }
.viewer-tool svg, .viewer-nav svg { width: 1.15rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.viewer-stage { min-width: 0; min-height: 0; overflow: auto; display: grid; place-items: center; touch-action: pan-x pan-y pinch-zoom; }
.viewer-stage img { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }
.viewer-nav { align-self: center; width: 2.8rem; height: 4.6rem; z-index: 2; background: transparent; }
.viewer-nav:disabled { opacity: .18; cursor: default; }

.toast-region { position: fixed; z-index: 200; right: 1rem; top: 1rem; display: grid; gap: .55rem; pointer-events: none; }
.toast { max-width: min(24rem, calc(100vw - 2rem)); padding: .8rem 1rem; border: 1px solid rgba(255,255,255,.65); border-radius: .85rem; color: #fff; background: rgba(23,32,51,.92); box-shadow: 0 10px 30px rgba(0,0,0,.18); animation: toast-in .25s ease both; font-size: .78rem; }
.toast.error { background: rgba(139,45,39,.94); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 640px) {
  .login-shell { padding: 1rem; }
  .login-card { padding: 2rem 1.35rem; border-radius: 1.5rem; }
  .app-header { height: 4.25rem; padding-inline: 1rem; }
  .header-actions { gap: .35rem; }
  #library-button { color: #fff; background: var(--blue); box-shadow: 0 6px 15px rgba(37,99,235,.24); }
  #library-button:hover { background: var(--blue-dark); }
  .user-chip { display: none; }
  .feed { padding: 1rem .85rem 1.5rem; }
  .message { max-width: 96%; border-radius: 1.05rem 1.05rem .3rem 1.05rem; }
  .message-text { min-width: min(10rem, 58vw); }
  .image-frame img { max-height: 43vh; }
  .file-card { grid-template-columns: auto minmax(4rem,max-content) auto; }
  .file-name { max-width: 42vw; }
  .download-button span { display: none; }
  .download-button { width: 2.35rem; height: 2.35rem; padding: 0; justify-content: center; border-radius: 50%; }
  .composer-wrap { padding-inline: .65rem; }
  .composer-hint { display: none; }
  .settings-dialog form { padding: 1.25rem; }
  .library-dialog { width: 100vw; height: 100vh; max-height: none; border-radius: 0; }
  .library-panel { padding: calc(.9rem + env(safe-area-inset-top)) .65rem calc(.65rem + env(safe-area-inset-bottom)); }
  .library-grid { grid-template-columns: repeat(3,minmax(0,1fr)); grid-auto-rows: 31vw; gap: .22rem; }
  .viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.2); }
  .viewer-prev { left: 0; }
  .viewer-next { right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
