:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #66717f;
  --line: #dce3ea;
  --accent: #176b87;
  --accent-strong: #124e63;
  --mine: #ddf2e8;
  --other: #ffffff;
  --shadow: 0 18px 45px rgba(23, 32, 42, 0.12);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #171c23;
  --ink: #edf3f8;
  --muted: #98a5b3;
  --line: #293340;
  --accent: #46a6bd;
  --accent-strong: #62bfd5;
  --mine: #153d35;
  --other: #202832;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, system-ui, -apple-system, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.login-page {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(23, 107, 135, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(103, 144, 120, 0.16), transparent 40%),
    var(--bg);
}

.login-panel {
  width: min(100%, 380px);
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 800;
}

.brand-mark.small {
  width: 40px;
  height: 40px;
}

.login-panel h1 {
  margin: 18px 0 24px;
  font-size: 28px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.login-form input {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
}

.login-form button,
.composer button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.login-form button:hover,
.composer button:hover {
  background: var(--accent-strong);
}

.form-error {
  margin: 0;
  color: #b12a34;
}

:root[data-theme="dark"] .form-error {
  color: #ff8c95;
}

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  padding: 22px;
  background: #101820;
  color: #fff;
}

:root[data-theme="dark"] .sidebar {
  background: #090d12;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-row h1,
.topbar h2 {
  margin: 0;
  font-size: 20px;
}

.brand-row p,
.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.sidebar .brand-row p {
  color: #aab6c2;
}

.tabs {
  display: grid;
  gap: 8px;
  margin-top: 30px;
}

.tab,
.ghost-button {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  text-align: left;
}

.tab.active {
  background: #f1f7fa;
  color: var(--ink);
}

:root[data-theme="dark"] .tab.active {
  background: #22303b;
  color: var(--ink);
}

.theme-toggle {
  width: 100%;
  min-height: 42px;
  margin-bottom: 8px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  text-align: left;
}

.theme-toggle.floating {
  position: fixed;
  top: 18px;
  right: 18px;
  width: auto;
  min-width: 82px;
  margin: 0;
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  text-align: center;
}

.theme-toggle.topbar-theme {
  width: auto;
  min-width: 82px;
  margin: 0;
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  text-align: center;
  flex: 0 0 auto;
}

.view {
  display: none;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.view.active {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 18px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.message {
  display: flex;
  margin-bottom: 14px;
}

.message.mine {
  justify-content: flex-end;
}

.bubble {
  width: fit-content;
  max-width: min(720px, 78%);
  padding: 11px 13px;
  background: var(--other);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(23, 32, 42, 0.05);
}

.message.mine .bubble {
  background: var(--mine);
}

.meta {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.message-text {
  margin: 0 0 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-status {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  text-align: right;
}

.typing-indicator {
  min-height: 24px;
  padding: 0 24px 8px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  background: var(--bg);
}

.attachment {
  display: grid;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
}

.attachment img,
.attachment video {
  display: block;
  width: min(420px, 100%);
  max-height: 420px;
  border-radius: 8px;
  object-fit: contain;
  background: #0c1116;
}

.attachment audio {
  width: min(420px, 100%);
}

.attachment span,
.media-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  word-break: break-word;
}

.file-card {
  min-width: 220px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  font-weight: 700;
  word-break: break-word;
}

:root[data-theme="dark"] .file-card,
:root[data-theme="dark"] .file-pick {
  background: #111820;
}

.composer {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 92px;
  gap: 10px;
  padding: 14px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.file-pick {
  display: grid;
  width: 46px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}

.file-pick input {
  display: none;
}

.composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 13px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.selected-file {
  padding: 0 20px 12px 74px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.media-view {
  overflow: hidden;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  overflow: auto;
  padding: 20px;
  min-height: 0;
}

.media-card {
  min-width: 0;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.media-card .attachment img,
.media-card .attachment video {
  width: 100%;
  height: 170px;
  object-fit: cover;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
}

.lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(5, 9, 13, 0.84);
  z-index: 20;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-content img {
  max-width: 94vw;
  max-height: 88vh;
  border-radius: 8px;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: #111820;
  color: #fff;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}

@media (max-width: 780px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    padding: 12px;
    min-width: 0;
  }

  .topbar {
    min-height: 68px;
    padding: 12px 14px;
  }

  .tabs {
    display: flex;
    margin-top: 12px;
  }

  .tab,
  .ghost-button {
    text-align: center;
  }

  .messages {
    padding: 14px;
  }

  .typing-indicator {
    padding: 0 14px 8px;
  }

  .bubble {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: 44px minmax(0, 1fr) 74px;
    padding: 10px;
  }
}
