:root {
  color-scheme: light;
  --primary: #5b5ef7;
  --primary-dark: #4648da;
  --primary-soft: #eef0ff;
  --accent: #8b5cf6;
  --surface: #ffffff;
  --surface-soft: #f6f7fb;
  --border: #e7e9f2;
  --text: #1e2340;
  --muted: #7a819f;
  --danger: #ef466f;
  --success: #25b983;
  --shadow: 0 24px 70px rgba(38, 43, 88, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #eef0f8; color: var(--text); }
body { min-height: 100vh; min-height: 100dvh; overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); text-align: center; padding: 32px 12px; }

.loading-screen {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; color: white;
  background: radial-gradient(circle at 40% 30%, #596cff 0, #2738aa 42%, #151a54 100%);
}
.loading-screen strong { font-size: 27px; letter-spacing: .18em; margin-left: .18em; }
.loading-screen > span { font-size: 14px; opacity: .72; }

.brand-orb {
  width: 76px; height: 76px; border-radius: 28px; display: grid; place-items: center;
  color: white; background: linear-gradient(145deg, #33d8f1, #5577f6 54%, #bd65e8);
  border: 1px solid rgba(255,255,255,.62); box-shadow: inset 0 1px 12px rgba(255,255,255,.55), 0 14px 34px rgba(62,73,218,.32);
}
.brand-orb span { font-weight: 800; font-size: 29px; text-shadow: 0 2px 9px rgba(34,35,102,.38); }
.brand-orb-large { width: 118px; height: 118px; border-radius: 42px; }
.brand-orb-large span { font-size: 44px; }
.brand-orb-small { width: 46px; height: 46px; border-radius: 16px; margin: 20px auto 30px; }
.brand-orb-small span { font-size: 18px; }

.auth-screen { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(360px, 46%) 1fr; }
.auth-art { position: relative; display: grid; place-items: center; overflow: hidden; background: radial-gradient(circle at 50% 36%, #5f72ff, #2d3eb2 48%, #171c58 100%); }
.star-field, .star-field::before, .star-field::after { position: absolute; inset: 0; content: ""; background-image: radial-gradient(#fff 1px, transparent 1.5px), radial-gradient(#b9d8ff 1px, transparent 1.5px); background-position: 0 0, 42px 37px; background-size: 82px 82px; opacity: .25; }
.star-field::before { transform: scale(1.4) rotate(17deg); opacity: .18; }
.star-field::after { transform: scale(.75) rotate(-9deg); opacity: .22; }
.auth-brand { position: relative; z-index: 1; text-align: center; color: white; }
.auth-brand .brand-orb { margin: 0 auto 28px; }
.auth-brand h1 { font-size: 48px; margin: 0 0 12px; letter-spacing: .18em; margin-left: .18em; }
.auth-brand p { margin: 0; opacity: .75; letter-spacing: .08em; }
.auth-panel { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; overflow: auto; padding: 38px 24px; background: var(--surface-soft); }
.auth-card { width: min(440px, 100%); padding: 36px 38px; background: var(--surface); border: 1px solid rgba(225,227,239,.9); border-radius: 28px; box-shadow: var(--shadow); }
.mobile-brand { display: none; align-items: center; gap: 14px; margin-bottom: 24px; }
.mobile-brand .brand-orb { width: 56px; height: 56px; border-radius: 20px; }
.mobile-brand .brand-orb span { font-size: 22px; }
.mobile-brand strong, .mobile-brand small { display: block; }
.mobile-brand strong { font-size: 22px; }
.mobile-brand small { color: var(--muted); margin-top: 2px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 14px; background: var(--surface-soft); }
.auth-tabs button { border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 10px; font-weight: 650; }
.auth-tabs button.active { color: var(--primary); background: white; box-shadow: 0 5px 18px rgba(40,45,95,.08); }
.form-heading { margin: 28px 0 22px; }
.form-heading h2 { font-size: 26px; margin: 0 0 7px; }
.form-heading p { color: var(--muted); margin: 0; }
.auth-form { display: flex; flex-direction: column; gap: 15px; }
.auth-form label { display: grid; gap: 7px; font-size: 13px; font-weight: 650; color: #555d7c; }
.auth-form input { height: 48px; width: 100%; padding: 0 14px; color: var(--text); border: 1px solid var(--border); border-radius: 12px; outline: none; background: #fbfbfd; transition: .18s; }
.auth-form input:focus, .search-wrap input:focus, .composer textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,94,247,.11); background: white; }
.agreement { display: flex !important; grid-template-columns: auto 1fr; align-items: center; font-weight: 500 !important; }
.agreement input { width: 18px; height: 18px; accent-color: var(--primary); }
.primary-button, .danger-button { border: 0; border-radius: 13px; min-height: 48px; font-weight: 700; }
.primary-button { color: white; background: linear-gradient(135deg, var(--primary), #a347f4); box-shadow: 0 12px 26px rgba(91,94,247,.24); }
.primary-button:hover { filter: brightness(1.04); transform: translateY(-1px); }
.primary-button:disabled { opacity: .58; cursor: wait; transform: none; }
.form-error { min-height: 18px; margin: -3px 0 0; font-size: 13px; color: var(--danger); }

.app-screen { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 86px minmax(300px, 350px) minmax(420px, 1fr); background: var(--surface); }
.nav-rail { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: #f7f8fc; }
.nav-rail nav { display: grid; gap: 10px; padding: 0 11px; }
.nav-button { position: relative; border: 0; display: grid; justify-items: center; gap: 4px; padding: 11px 4px; color: #8b91aa; background: transparent; border-radius: 15px; font-size: 12px; }
.nav-button .nav-icon { font-size: 21px; line-height: 1; }
.nav-button.active { color: var(--primary); background: var(--primary-soft); }
.nav-button .badge { position: absolute; top: 7px; right: 11px; min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; color: white; background: var(--danger); border: 2px solid #f7f8fc; border-radius: 20px; font-size: 10px; font-style: normal; }
.rail-profile { margin: auto auto 20px; border: 0; padding: 0; background: transparent; }
.avatar { width: 46px; height: 46px; flex: none; display: grid; place-items: center; overflow: hidden; border-radius: 50%; color: white; font-weight: 750; background: linear-gradient(135deg, #6ec6f1, #6476e9); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.list-panel { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: #fbfbfd; }
.list-header { display: flex; align-items: center; justify-content: space-between; min-height: 86px; padding: 17px 20px 12px; }
.list-header h1 { font-size: 23px; margin: 0 0 3px; }
.list-header p { margin: 0; color: var(--success); font-size: 12px; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 13px; color: var(--primary); background: white; font-size: 22px; display: grid; place-items: center; }
.icon-button:hover { background: var(--primary-soft); }
.search-wrap { margin: 0 16px 12px; display: flex; align-items: center; gap: 9px; padding: 0 12px; height: 44px; border: 1px solid var(--border); border-radius: 13px; background: white; color: #999fb5; }
.search-wrap input { min-width: 0; flex: 1; height: 100%; border: 0; outline: none; background: transparent; color: var(--text); }
.list-content { flex: 1; overflow: auto; overscroll-behavior: contain; padding: 2px 10px 20px; }
.list-row { width: 100%; border: 0; display: flex; align-items: center; gap: 12px; padding: 11px; text-align: left; color: inherit; background: transparent; border-radius: 15px; }
.list-row:hover, .list-row.active { background: var(--primary-soft); }
.list-row-body { min-width: 0; flex: 1; }
.row-line { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.row-line strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.row-line time { flex: none; color: #a0a6bc; font-size: 11px; }
.row-sub { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.row-sub p { min-width: 0; flex: 1; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.unread { min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 5px; color: white; background: var(--primary); border-radius: 20px; font-size: 11px; }
.online-dot { width: 9px; height: 9px; margin-left: -19px; margin-top: 34px; border: 2px solid white; border-radius: 50%; background: var(--success); }
.section-caption { margin: 16px 10px 7px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.loading-list { display: grid; place-items: center; min-height: 160px; color: var(--muted); }

.content-panel { min-width: 0; position: relative; display: flex; background: linear-gradient(180deg, #fafbff, #f5f7fc); }
.empty-state { margin: auto; text-align: center; }
.empty-orb { width: 96px; height: 96px; display: grid; place-items: center; margin: auto; color: white; background: linear-gradient(145deg, #8bdcf0, #6979f7, #ad66e7); border-radius: 36px; font-size: 38px; box-shadow: 0 24px 55px rgba(75,85,203,.2); }
.empty-state h2 { margin: 22px 0 7px; font-size: 20px; }
.empty-state p { margin: 0; color: var(--muted); }
.chat-view { width: 100%; min-height: 0; display: flex; flex-direction: column; }
.chat-header { min-height: 74px; display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.92); backdrop-filter: blur(16px); }
.avatar-large { width: 46px; height: 46px; }
.chat-heading { min-width: 0; flex: 1; }
.chat-heading h2 { margin: 0 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.chat-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.message-list { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding: 24px clamp(18px, 4vw, 62px); }
.message { max-width: min(72%, 680px); display: flex; gap: 9px; align-items: flex-end; }
.message.mine { align-self: flex-end; flex-direction: row-reverse; }
.message.theirs { align-self: flex-start; }
.message .avatar { width: 32px; height: 32px; font-size: 12px; }
.bubble-wrap { min-width: 0; }
.sender { margin: 0 0 4px 4px; color: var(--muted); font-size: 11px; }
.bubble { padding: 10px 13px; border-radius: 17px 17px 17px 5px; color: var(--text); background: white; border: 1px solid var(--border); box-shadow: 0 4px 14px rgba(52,56,96,.05); overflow-wrap: anywhere; white-space: pre-wrap; }
.mine .bubble { color: white; background: linear-gradient(135deg, #6165fa, #7d58ed); border: 0; border-radius: 17px 17px 5px 17px; }
.bubble img { display: block; max-width: min(340px, 100%); max-height: 360px; border-radius: 11px; }
.bubble a { color: inherit; text-decoration: underline; }
.message-meta { margin: 4px 5px 0; color: #a1a6b9; font-size: 10px; }
.mine .message-meta { text-align: right; }
.date-separator { align-self: center; margin: 9px 0; padding: 5px 10px; color: var(--muted); background: rgba(225,228,239,.72); border-radius: 14px; font-size: 11px; }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 13px 20px max(13px, env(safe-area-inset-bottom)); background: white; border-top: 1px solid var(--border); }
.composer textarea { min-height: 44px; max-height: 132px; flex: 1; resize: none; outline: none; padding: 11px 14px; color: var(--text); border: 1px solid var(--border); border-radius: 15px; background: #f8f9fc; line-height: 1.45; }
.send-button { width: 44px; height: 44px; flex: none; border: 0; border-radius: 15px; color: white; background: linear-gradient(135deg, var(--primary), var(--accent)); font-size: 18px; }
.send-button:disabled { opacity: .5; cursor: wait; }

.profile-view { width: 100%; overflow: auto; padding: 42px 24px; }
.profile-card { width: min(540px, 100%); margin: 0 auto; padding: 34px; text-align: center; border: 1px solid var(--border); border-radius: 24px; background: white; box-shadow: 0 16px 48px rgba(48,53,98,.08); }
.avatar-profile { width: 92px; height: 92px; margin: 0 auto 18px; font-size: 28px; }
.profile-card h2 { margin: 0 0 6px; }
.profile-card > p { color: var(--muted); margin: 0 0 26px; }
.profile-card dl { margin: 0 0 26px; text-align: left; }
.profile-card dl div { display: flex; justify-content: space-between; gap: 20px; padding: 13px 2px; border-bottom: 1px solid var(--border); }
.profile-card dt { color: var(--muted); }
.profile-card dd { margin: 0; max-width: 70%; text-align: right; overflow-wrap: anywhere; }
.danger-button { width: 100%; color: var(--danger); background: #fff0f3; }
.danger-button:hover { background: #ffe4ea; }

.dialog { width: min(540px, calc(100% - 28px)); max-height: min(680px, calc(100vh - 40px)); padding: 0; border: 0; border-radius: 24px; color: var(--text); background: transparent; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(21,24,53,.46); backdrop-filter: blur(4px); }
.dialog-card { display: flex; flex-direction: column; max-height: inherit; background: white; border-radius: 24px; overflow: hidden; }
.dialog-card header { display: flex; justify-content: space-between; align-items: center; padding: 22px 22px 16px; }
.dialog-card h2 { margin: 0 0 4px; font-size: 20px; }
.dialog-card header p { margin: 0; color: var(--muted); font-size: 13px; }
.dialog-card .search-wrap { flex: none; }
.search-results { min-height: 180px; overflow: auto; padding: 0 12px 20px; }
.toast { position: fixed; z-index: 200; left: 50%; bottom: 28px; transform: translate(-50%, 16px); max-width: min(88vw, 460px); padding: 11px 16px; color: white; background: rgba(28,31,55,.92); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.18); opacity: 0; pointer-events: none; transition: .22s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-nav, .mobile-only { display: none; }

@media (max-width: 900px) {
  .auth-screen { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-panel { background: radial-gradient(circle at 30% 0, #e9ebff, #f8f8fc 48%); }
  .mobile-brand { display: flex; }
  .app-screen { grid-template-columns: 74px minmax(280px, 330px) minmax(360px, 1fr); }
}

@media (max-width: 680px) {
  body { background: white; }
  .auth-panel { padding: 22px 16px; align-items: start; }
  .auth-card { padding: 25px 20px; margin-top: max(18px, env(safe-area-inset-top)); border-radius: 24px; box-shadow: none; }
  .app-screen { display: block; position: relative; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .nav-rail { display: none; }
  .list-panel { height: 100%; border: 0; }
  .content-panel { position: fixed; z-index: 20; inset: 0 0 calc(64px + env(safe-area-inset-bottom)); display: none; }
  .content-panel.mobile-open { display: flex; }
  .mobile-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--border); background: rgba(255,255,255,.96); backdrop-filter: blur(16px); }
  .mobile-nav-button { border: 0; display: grid; place-items: center; align-content: center; gap: 3px; color: #9096aa; background: transparent; font-size: 11px; }
  .mobile-nav-button span { font-size: 20px; }
  .mobile-nav-button.active { color: var(--primary); }
  .mobile-only { display: grid; }
  .chat-header { padding-top: max(12px, env(safe-area-inset-top)); }
  .message-list { padding: 18px 12px; }
  .message { max-width: 88%; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .profile-view { padding: max(30px, env(safe-area-inset-top)) 14px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
