:root {
  color-scheme: light;
  --bg: #eef4f2;
  --surface: #ffffff;
  --surface-soft: #f5f8f7;
  --border: #dbe7e3;
  --text: #172522;
  --muted: #667a74;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --primary-soft: #dff4ef;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(24, 67, 58, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-layout {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
  align-items: center;
  gap: 5vw;
  padding: clamp(28px, 6vw, 88px);
  background:
    radial-gradient(circle at 10% 10%, rgba(15, 118, 110, .16), transparent 34%),
    radial-gradient(circle at 90% 90%, rgba(22, 163, 74, .10), transparent 30%),
    var(--bg);
}
.auth-brand { max-width: 720px; }
.brand-mark, .empty-logo {
  width: 78px; height: 78px; border-radius: 24px; display: grid; place-items: center;
  color: white; background: linear-gradient(145deg, #0f766e, #134e4a); font-size: 28px; font-weight: 900;
  box-shadow: 0 18px 35px rgba(15, 118, 110, .28);
}
.auth-brand h1 { font-size: clamp(48px, 7vw, 92px); line-height: .95; margin: 28px 0 18px; letter-spacing: -.06em; }
.auth-brand > p { max-width: 650px; color: var(--muted); font-size: clamp(18px, 2vw, 24px); line-height: 1.55; }
.feature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 580px; gap: 12px; margin-top: 34px; }
.feature-grid span { background: rgba(255,255,255,.75); border: 1px solid rgba(15,118,110,.12); padding: 14px 16px; border-radius: 15px; font-weight: 700; }

.auth-card { width: min(100%, 500px); justify-self: end; background: rgba(255,255,255,.92); border: 1px solid rgba(255,255,255,.7); box-shadow: var(--shadow); padding: 28px; border-radius: 28px; backdrop-filter: blur(18px); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-soft); padding: 5px; border-radius: 14px; margin-bottom: 24px; }
.tab { border: 0; background: transparent; border-radius: 11px; padding: 12px; color: var(--muted); font-weight: 800; }
.tab.active { background: var(--surface); color: var(--primary); box-shadow: 0 4px 16px rgba(20, 55, 48, .08); }
.auth-form { display: grid; gap: 18px; }
label { display: grid; gap: 8px; font-weight: 750; font-size: 14px; }
input, textarea { width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); outline: none; border-radius: 13px; padding: 13px 14px; transition: border-color .2s, box-shadow .2s; }
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(15,118,110,.11); }
input:disabled { background: var(--surface-soft); color: var(--muted); }
.input-prefix { display: flex; align-items: center; border: 1px solid var(--border); background: var(--surface); border-radius: 13px; overflow: hidden; }
.input-prefix:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(15,118,110,.11); }
.input-prefix span { padding-left: 14px; color: var(--muted); font-weight: 900; }
.input-prefix input { border: 0; box-shadow: none !important; padding-left: 4px; }
small { color: var(--muted); }
small[data-state="ok"] { color: #15803d; }
small[data-state="error"] { color: var(--danger); }
.primary, .danger { border: 0; border-radius: 13px; padding: 13px 18px; font-weight: 850; }
.primary { color: white; background: var(--primary); }
.primary:hover { background: var(--primary-dark); }
.danger { background: #fff0ef; color: var(--danger); }
.security-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.app-shell { height: 100%; display: grid; grid-template-columns: 380px minmax(0,1fr); background: var(--surface); }
.sidebar { min-width: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--surface); z-index: 2; }
.sidebar-header, .chat-header { min-height: 72px; display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.sidebar-header { justify-content: space-between; }
.sidebar-header > div:first-child { display: grid; }
.sidebar-header strong { font-size: 21px; letter-spacing: -.03em; }
.header-actions { display: flex; gap: 8px; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; color: var(--text); font-size: 20px; }
.icon-button:hover { background: var(--surface-soft); }
.new-chat-box { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 14px 14px 10px; }
.new-chat-box input { min-width: 0; }
.list-heading { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px 8px; color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.text-button { border: 0; background: transparent; color: var(--primary); font-weight: 800; padding: 4px; }
.conversation-list { flex: 1; overflow: auto; padding: 6px 8px 16px; }
.conversation-item { width: 100%; display: grid; grid-template-columns: 48px minmax(0,1fr) auto; gap: 11px; align-items: center; text-align: left; border: 0; border-radius: 16px; background: transparent; padding: 11px; margin-bottom: 4px; color: inherit; }
.conversation-item:hover { background: var(--surface-soft); }
.conversation-item.active { background: var(--primary-soft); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto; background: linear-gradient(145deg, #ccfbf1, #99f6e4); color: #115e59; font-weight: 900; }
.conversation-copy { min-width: 0; display: grid; grid-template-columns: minmax(0,1fr) auto; column-gap: 8px; }
.conversation-copy strong, .conversation-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy strong { font-size: 15px; }
.conversation-copy small { font-size: 11px; align-self: center; }
.conversation-copy span { grid-column: 1 / -1; margin-top: 5px; color: var(--muted); font-size: 13px; }
.unread { min-width: 23px; height: 23px; display: grid; place-items: center; border-radius: 20px; color: white; background: var(--primary); font-size: 11px; }
.list-empty { color: var(--muted); text-align: center; padding: 45px 18px; }

.chat-panel { min-width: 0; position: relative; background: #e9f0ed; }
.chat-panel::before { content: ""; position: absolute; inset: 0; opacity: .35; background-image: radial-gradient(rgba(15,118,110,.16) 1px, transparent 1px); background-size: 22px 22px; pointer-events: none; }
.empty-chat { position: relative; z-index: 1; height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; padding: 28px; }
.empty-chat .empty-logo { width: 90px; height: 90px; }
.empty-chat h2 { margin: 25px 0 8px; font-size: 28px; }
.empty-chat p { color: var(--muted); margin: 0; }
.active-chat { position: relative; z-index: 1; height: 100%; display: grid; grid-template-rows: auto minmax(0,1fr) auto auto; }
.chat-header { background: rgba(255,255,255,.92); backdrop-filter: blur(16px); }
.chat-peer { min-width: 0; display: grid; flex: 1; }
.chat-peer strong, .chat-peer small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-peer small { font-size: 11px; }
.connection-state { font-size: 11px; font-weight: 900; color: #15803d; border: 1px solid #bbf7d0; background: #f0fdf4; padding: 5px 8px; border-radius: 999px; }
.connection-state.offline { color: #a16207; border-color: #fde68a; background: #fffbeb; }
.message-list { min-height: 0; overflow-y: auto; padding: 22px clamp(14px, 4vw, 60px); display: flex; flex-direction: column; gap: 7px; scroll-behavior: smooth; }
.date-divider { align-self: center; margin: 9px 0; color: var(--muted); background: rgba(255,255,255,.86); border: 1px solid var(--border); padding: 6px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.message { max-width: min(72%, 680px); min-width: 90px; padding: 9px 11px 7px; border-radius: 16px; box-shadow: 0 3px 10px rgba(25, 55, 48, .07); }
.message.peer { align-self: flex-start; background: white; border-bottom-left-radius: 5px; }
.message.own { align-self: flex-end; background: #d8f5e8; border-bottom-right-radius: 5px; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.42; }
.message > small { display: block; margin-top: 4px; text-align: right; font-size: 10px; }
.media-holder { margin: -3px -4px 7px; min-width: 220px; min-height: 120px; border-radius: 12px; overflow: hidden; display: grid; place-items: center; background: rgba(0,0,0,.06); color: var(--muted); font-size: 12px; }
.media-holder img, .media-holder video { display: block; max-width: min(56vw, 520px); max-height: 58vh; width: auto; height: auto; border-radius: 12px; background: #111; }
.media-error { padding: 20px; color: var(--danger); }
.composer { display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 9px; align-items: end; padding: 12px clamp(12px, 3vw, 30px); background: rgba(255,255,255,.94); border-top: 1px solid var(--border); backdrop-filter: blur(14px); }
.composer textarea { min-height: 44px; max-height: 140px; resize: none; }
.send-button { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--primary); color: white; font-size: 20px; }
.upload-progress { padding: 8px 24px; text-align: center; font-size: 12px; color: var(--primary-dark); background: #dff4ef; }

.modal { border: 0; padding: 0; border-radius: 22px; width: min(92vw, 540px); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(9, 25, 22, .55); backdrop-filter: blur(4px); }
.modal-card { display: grid; gap: 17px; padding: 24px; }
.modal-card header { display: flex; align-items: center; justify-content: space-between; }
.modal-card h2 { margin: 0; font-size: 22px; }
.modal-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 4px; }
.install-help { border: 1px solid var(--border); background: var(--surface-soft); border-radius: 14px; padding: 14px; }
.install-help p { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.toast { position: fixed; z-index: 20; left: 50%; top: 18px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; min-width: 240px; max-width: min(90vw, 520px); color: white; background: #18332d; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); text-align: center; transition: .2s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast[data-type="error"] { background: #8f1d18; }
.toast[data-type="warning"] { background: #8a5808; }
.mobile-only { display: none; }

@media (max-width: 820px) {
  .auth-layout { display: block; overflow-y: auto; padding: 28px 18px; }
  .auth-brand { margin: 0 auto 28px; text-align: center; }
  .brand-mark { margin-inline: auto; }
  .auth-brand h1 { font-size: 54px; margin: 20px 0 10px; }
  .auth-brand > p { font-size: 17px; }
  .feature-grid { margin-inline: auto; }
  .auth-card { margin: 0 auto; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { width: 100%; }
  .chat-panel { position: fixed; inset: 0; z-index: 5; transform: translateX(100%); transition: transform .22s ease; }
  body.mobile-chat-open .chat-panel { transform: translateX(0); }
  .mobile-only { display: grid; }
  .message { max-width: 86%; }
  .media-holder img, .media-holder video { max-width: 76vw; }
}

@media (max-width: 480px) {
  .feature-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 20px; border-radius: 22px; }
  .new-chat-box { grid-template-columns: 1fr; }
  .new-chat-box .primary { width: 100%; }
  .chat-header { padding-inline: 10px; }
  .chat-peer small { max-width: 210px; }
  .message-list { padding-inline: 10px; }
  .composer { padding-inline: 9px; }
}
