:root {
  --font-scale: 1;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --text: #172033;
  --muted: #62708a;
  --line: #d9e0ea;
  --accent: #2563eb;
  --accent-2: #16a34a;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(30, 41, 59, 0.16);
}

[data-theme="dark"] {
  --bg: #10141d;
  --panel: #171d29;
  --panel-2: #222a39;
  --text: #edf2ff;
  --muted: #9aa8bd;
  --line: #30394b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

[data-theme="contrast"] {
  --bg: #000000;
  --panel: #0b0b0b;
  --panel-2: #1d1d1d;
  --text: #ffffff;
  --muted: #d8d8d8;
  --line: #ffffff;
  --accent: #ffcc00;
  --accent-2: #00e5ff;
  --danger: #ff4d4d;
}

[data-accent="green"] { --accent: #059669; }
[data-accent="rose"] { --accent: #e11d48; }
[data-accent="violet"] { --accent: #7c3aed; }
[data-accent="amber"] { --accent: #d97706; }

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, system-ui, -apple-system, sans-serif;
  font-size: calc(16px * var(--font-scale));
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover, button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.danger {
  color: var(--danger);
}

.icon {
  width: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  min-height: 44px;
  max-height: 140px;
}

.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 520px) 1fr;
}

.auth-choice {
  min-height: 100vh;
  min-height: 100dvh;
  background: #ffffff;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.cloud-auth-photo {
  position: relative;
  width: min(100vw, 460px);
  height: 100dvh;
  max-height: 100dvh;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 16px 44px rgba(15, 23, 42, 0.12);
}

.cloud-auth-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.auth-photo-hotspot {
  position: absolute;
  left: 4%;
  width: 92%;
  height: 8%;
  border: 0;
  background: rgba(255,255,255,0.01);
  color: transparent;
  border-radius: 999px;
  padding: 0;
}

.auth-photo-hotspot:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.9);
  outline-offset: 3px;
}

.auth-photo-register { top: 59%; }
.auth-photo-login { top: 72.5%; }

.cloud-mark.small {
  width: 82px;
  height: 82px;
  margin: 0;
}

.auth-back {
  align-self: flex-start;
  min-height: 34px;
  padding: 0 10px;
}

.auth-submit {
  min-height: 48px;
  font-weight: 700;
}

.auth-panel {
  padding: 44px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.auth-visual {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(37,99,235,0.9), rgba(5,150,105,0.8)),
    url("https://images.unsplash.com/photo-1516321318423-f06f85e504b3?auto=format&fit=crop&w=1600&q=80") center/cover;
}

.auth-visual::after {
  content: "Cloud";
  position: absolute;
  left: 8vw;
  bottom: 10vh;
  color: #fff;
  font-size: 72px;
  font-weight: 800;
}

.verify-card h2 {
  margin: 0;
  font-size: 28px;
}

.code-input {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr) 300px;
  background: #efeae2;
}

.mobile-nav,
.mobile-back {
  display: none;
}

.sidebar, .details {
  background: #ffffff;
  border-color: var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar { border-right: 1px solid #d1d7db; }
.details { border-left: 1px solid var(--line); }

.topbar, .profile, .details-head {
  min-height: 62px;
  padding: 10px 14px;
  border-bottom: 1px solid #d1d7db;
  background: #f0f2f5;
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-info, .chat-title {
  min-width: 0;
  flex: 1;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #00a884;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.muted {
  color: var(--muted);
  font-size: 0.88em;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.row.wrap { flex-wrap: wrap; }

.pad {
  padding: 14px;
}

.list {
  overflow: auto;
  flex: 1;
}

.chat-item, .user-item, .media-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid #eef0f1;
  border-radius: 0;
  text-align: left;
  padding: 12px 16px;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
}

.chat-item.active {
  background: #f0f2f5;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #efeae2;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 20px 7%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  width: fit-content;
  max-width: min(720px, 78%);
  align-self: flex-start;
  background: #ffffff;
  border: 0;
  border-radius: 8px;
  padding: 7px 9px;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

.message.mine {
  align-self: flex-end;
  background: #d9fdd3;
}

.message.deleted {
  opacity: 0.62;
  font-style: italic;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78em;
  margin-bottom: 4px;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.attachment {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
}

.attachment img, .attachment video {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

.attachment a {
  display: block;
  padding: 10px;
  color: var(--text);
  text-decoration: none;
}

.composer {
  border-top: 1px solid #d1d7db;
  padding: 10px 16px;
  background: #f0f2f5;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  align-items: end;
}

.composer textarea {
  min-height: 42px;
  border: 0;
  border-radius: 22px;
  background: #ffffff;
  padding: 10px 16px;
}

.composer .primary {
  background: #00a884;
  border-color: #00a884;
  border-radius: 999px;
  min-width: 46px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.tabs button {
  border: 0;
  border-radius: 0;
}

.tabs button.active {
  color: var(--accent);
  box-shadow: inset 0 -2px var(--accent);
}

.panel-scroll {
  overflow: auto;
  flex: 1;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 0.82em;
}

.meeting {
  position: fixed;
  inset: 18px;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 10;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: 8px;
  overflow: hidden;
}

.video-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  overflow: auto;
}

.tile {
  min-height: 220px;
  background: #05070d;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile span {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(0,0,0,0.56);
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
}

.screen-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  max-width: calc(100% - 20px);
  background: rgba(37, 99, 235, 0.86);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.84em;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: grid;
  place-items: center;
  z-index: 20;
}

.dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.shortcut {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--panel-2);
}

@media (max-width: 1050px) {
  .app {
    grid-template-columns: 280px minmax(0, 1fr);
  }
  .details {
    display: none;
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .auth {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .cloud-sky {
    height: 34vh;
    min-height: 255px;
  }

  .cloud-white::before,
  .cloud-white::after {
    top: -90px;
    height: 190px;
  }

  .cloud-mark {
    width: 148px;
    height: 148px;
    margin-top: -74px;
  }

  .auth-choice-actions {
    width: min(360px, 100%);
    margin-top: 36px;
    gap: 38px;
  }

  .auth-choice-button {
    min-height: 52px;
    font-size: 34px;
  }

  .auth-panel {
    min-height: 100dvh;
    padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
    justify-content: center;
    border-right: 0;
  }

  .auth-panel h1 {
    font-size: 42px;
    margin: 0;
  }

  .auth-visual {
    display: none;
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 64px;
    height: 100dvh;
  }

  .sidebar {
    grid-row: 1;
    display: flex;
    border-right: 0;
    min-height: 0;
  }

  .main {
    grid-row: 1;
    min-height: 0;
  }

  .details {
    display: none;
  }

  .app.chat-open .sidebar {
    display: none;
  }

  .app.chat-list .main {
    display: none;
  }

  .mobile-nav {
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: var(--panel);
    border-top: 1px solid var(--line);
    gap: 6px;
  }

  .mobile-nav button {
    min-height: 48px;
    padding: 0 6px;
    font-size: 0.78em;
    border-radius: 8px;
  }

  .mobile-nav button.active {
    background: color-mix(in srgb, var(--accent) 16%, var(--panel));
    border-color: var(--accent);
  }

  .mobile-back {
    display: inline-grid;
    font-size: 26px;
  }

  .topbar {
    min-height: 60px;
    padding: 8px 10px;
  }

  .topbar button:not(.icon) {
    min-height: 36px;
    padding: 0 8px;
    font-size: 0.82em;
  }

  .messages {
    padding: 10px;
    gap: 8px;
  }

  .composer {
    grid-template-columns: 40px 40px 1fr;
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .composer .primary {
    grid-column: 1 / -1;
  }

  .message {
    width: 92%;
    padding: 9px;
  }

  .attachments {
    grid-template-columns: 1fr;
  }

  .meeting {
    inset: 0;
    border-radius: 0;
    border: 0;
  }

  .video-grid {
    grid-template-columns: 1fr;
  }

  .tile {
    min-height: 260px;
  }
}
