:root {
  --bg: #eef2f7;
  --bg-accent: radial-gradient(circle at top left, rgba(255,255,255,0.95), rgba(230,236,244,0.85) 45%, rgba(220,228,239,0.65) 100%);
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: rgba(255, 255, 255, 0.88);
  --panel-2: rgba(248, 250, 253, 0.75);
  --border: rgba(255, 255, 255, 0.7);
  --border-soft: rgba(214, 221, 232, 0.85);
  --text: #111827;
  --muted: #667085;
  --primary: #0a84ff;
  --primary-contrast: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #d9ecff;
  --danger: #ff3b30;
  --shadow-soft: 0 20px 50px rgba(16, 24, 40, 0.08);
  --shadow-card: 0 16px 40px rgba(15, 23, 42, 0.08);
  --overlay: rgba(8, 15, 25, 0.78);
  --icon-bg: rgba(255, 255, 255, 0.72);
  --icon-border: rgba(214, 221, 232, 0.9);
  --composer-height: 84px;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-accent: radial-gradient(circle at top left, rgba(42,50,67,0.9), rgba(22,28,38,0.92) 45%, rgba(10,14,20,0.98) 100%);
  --panel: rgba(22, 28, 38, 0.82);
  --panel-strong: rgba(26, 33, 44, 0.92);
  --panel-2: rgba(15, 20, 28, 0.78);
  --border: rgba(62, 76, 95, 0.45);
  --border-soft: rgba(50, 63, 81, 0.75);
  --text: #edf2f7;
  --muted: #99a6b8;
  --primary: #5ac8fa;
  --primary-contrast: #06131b;
  --bubble-in: rgba(35, 45, 60, 0.95);
  --bubble-out: rgba(24, 78, 119, 0.92);
  --danger: #ff6b60;
  --shadow-soft: 0 20px 50px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 20px 50px rgba(0, 0, 0, 0.32);
  --overlay: rgba(0, 0, 0, 0.84);
  --icon-bg: rgba(28, 37, 48, 0.92);
  --icon-border: rgba(62, 76, 95, 0.72);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg-accent);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  backdrop-filter: saturate(1.1);
}

body.modal-open {
  overflow: hidden;
}

.shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px;
  min-height: 100vh;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
}

.auth-card {
  max-width: 430px;
  margin: 48px auto;
  padding: 18px;
}

.auth-topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.auth-content {
  padding: 8px 8px 10px;
}

.workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  height: calc(100vh - 36px);
  min-height: calc(100vh - 36px);
}

.sidebar,
.chat-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(24px) saturate(1.15);
  -webkit-backdrop-filter: blur(24px) saturate(1.15);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  position: relative;
}

.sidebar-header,
.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-panel-header {
  justify-content: flex-start;
  gap: 10px;
  flex-shrink: 0;
}

.chat-title {
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-list {
  overflow-y: auto;
  padding: 10px;
  min-height: 0;
}

.chat-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
  border-radius: 22px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

:root[data-theme="dark"] .chat-item {
  background: rgba(255, 255, 255, 0.03);
}

.chat-item:active {
  transform: scale(0.99);
}

.chat-item.active {
  background: rgba(10, 132, 255, 0.14);
  border-color: rgba(10, 132, 255, 0.22);
}

:root[data-theme="dark"] .chat-item.active {
  background: rgba(90, 200, 250, 0.15);
  border-color: rgba(90, 200, 250, 0.24);
}

.chat-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-item-name {
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.chat-item-text {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  word-break: break-word;
}

.unread-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(255, 59, 48, 0.24);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px calc(var(--composer-height) + 26px);
  background: var(--panel-2);
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: min(78%, 540px);
  margin-bottom: 14px;
}

.msg.left {
  margin-right: auto;
}

.msg.right {
  margin-left: auto;
}

.meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  padding: 0 4px;
  word-break: break-word;
}

.bubble {
  padding: 12px 14px;
  border-radius: 20px;
  line-height: 1.45;
  background: var(--bubble-in);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
  word-break: break-word;
}

.msg.right .bubble {
  background: var(--bubble-out);
}

.bubble-text {
  white-space: pre-wrap;
}

.attachment {
  margin-top: 10px;
}

.image-preview-button {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
  width: 100%;
  text-align: left;
}

.chat-image {
  display: block;
  max-width: 280px;
  width: 100%;
  height: auto;
  border-radius: 16px;
}

.file-box {
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.52);
}

:root[data-theme="dark"] .file-box {
  background: rgba(255, 255, 255, 0.03);
}

.file-name {
  font-weight: 600;
  margin-bottom: 8px;
  word-break: break-word;
}

.attachment-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(10, 132, 255, 0.12);
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

:root[data-theme="dark"] .attachment-link {
  background: rgba(90, 200, 250, 0.14);
  color: #8bdfff;
}

.message-form {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-soft);
  background: var(--panel-strong);
  backdrop-filter: blur(24px) saturate(1.15);
  -webkit-backdrop-filter: blur(24px) saturate(1.15);
}

.composer-shell {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: end;
  gap: 10px;
}

.password-field {
  position: relative;
  margin-bottom: 14px;
}

.password-field input[type="password"],
.password-field input[type="text"] {
  padding-right: 56px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
}

textarea {
  width: 100%;
  min-height: 44px;
  height: 44px;
  max-height: 160px;
  resize: none;
  overflow-y: auto;
  padding: 11px 14px;
  border: 1px solid var(--border-soft);
  border-radius: 22px;
  font-size: 16px;
  line-height: 1.35;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  outline: none;
  -webkit-overflow-scrolling: touch;
}

:root[data-theme="dark"] textarea {
  background: rgba(255, 255, 255, 0.04);
}

textarea::placeholder,
input::placeholder {
  color: var(--muted);
}

input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  outline: none;
}

:root[data-theme="dark"] input[type="password"],
:root[data-theme="dark"] input[type="text"] {
  background: rgba(255, 255, 255, 0.04);
}

input[type="file"] {
  display: none;
}

button {
  border: 0;
  cursor: pointer;
  font-family: inherit;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  border-radius: 18px;
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  box-shadow: 0 10px 24px rgba(10, 132, 255, 0.22);
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--icon-bg);
  color: var(--text);
  border: 1px solid var(--icon-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 0;
}

.icon-svg {
  width: 20px;
  height: 20px;
  display: block;
}

.file-picker,
.send-button {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid var(--icon-border);
  background: var(--icon-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 0;
}

.file-picker {
  cursor: pointer;
}

.send-button {
  background: var(--primary);
  border-color: transparent;
  color: var(--primary-contrast);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.lightbox.hidden {
  display: none;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.lightbox-content {
  position: relative;
  z-index: 1;
  width: min(96vw, 1200px);
  max-height: 92vh;
  margin: 4vh auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.lightbox-image {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 22px;
  box-shadow: var(--shadow-soft);
}

.lightbox-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.hidden {
  display: none;
}

.empty-state {
  color: var(--muted);
  padding: 24px 12px;
  text-align: center;
  font-size: 15px;
}

.error {
  color: var(--danger);
  min-height: 20px;
  margin-top: 10px;
  font-size: 14px;
}

@media (max-width: 900px) {
  .shell {
    padding: 0;
    height: 100vh;
  }

  .workspace {
    display: block;
    height: 100vh;
    min-height: 100vh;
  }

  .sidebar,
  .chat-panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    height: 100vh;
    min-height: 100vh;
  }

  .mobile-hidden {
    display: none;
  }

  .msg {
    max-width: 90%;
  }

  .messages {
    padding: 14px 12px calc(var(--composer-height) + 24px);
  }

  .message-form {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .chat-image {
    max-width: 100%;
  }

  .lightbox-content {
    width: 100vw;
    margin: 0;
    min-height: 100vh;
    justify-content: center;
    padding: 16px;
  }

  .lightbox-image {
    max-height: 72vh;
  }
}
