:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --text: #16202a;
  --muted: #667280;
  --line: #d9e0e7;
  --primary: #1f7a6d;
  --primary-dark: #155e54;
  --accent: #b34b4b;
  --soft: #f6f8fa;
  --shadow: 0 20px 60px rgba(22, 32, 42, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 122, 109, 0.16), transparent 36%),
    linear-gradient(315deg, rgba(179, 75, 75, 0.14), transparent 34%),
    var(--bg);
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 64px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 122, 109, 0.12);
}

form button,
.composer button {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

form button:hover,
.composer button:hover {
  background: var(--primary-dark);
}

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 28px;
  padding: 28px 20px;
  background: #17242f;
  color: #fff;
}

.sidebar .muted {
  color: #c6d0d8;
}

.sidebar h1 {
  font-size: 24px;
}

nav {
  display: grid;
  gap: 8px;
  align-content: start;
}

.nav-button,
.ghost-button {
  min-height: 42px;
  border-radius: 6px;
  padding: 0 14px;
  text-align: left;
  background: transparent;
  color: #dce4ea;
}

.nav-button.active,
.nav-button:hover,
.ghost-button:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
}

.chat-panel,
.users-panel {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--panel);
}

.users-panel {
  grid-template-rows: auto auto 1fr;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--text);
  font-size: 20px;
}

.icon-button:hover {
  background: #e8edf1;
}

.messages {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 24px 28px;
  background: #f8fafb;
}

.empty-state {
  margin: auto;
  color: var(--muted);
}

.message {
  width: min(720px, 100%);
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.message.favorite {
  border-color: rgba(179, 75, 75, 0.38);
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.message-meta {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.message-meta strong {
  color: var(--text);
}

.favorite-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-size: 18px;
}

.favorite-btn.active {
  color: var(--accent);
  background: rgba(179, 75, 75, 0.1);
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.attachment {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--primary-dark);
  background: var(--soft);
  text-decoration: none;
}

.attachment span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-image {
  max-width: min(420px, 100%);
  max-height: 320px;
  border-radius: 6px;
  border: 1px solid var(--line);
  object-fit: contain;
  background: #fff;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 16px 28px 22px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-picker span {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--soft);
  cursor: pointer;
}

.file-name {
  min-width: 0;
  flex: 1;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error {
  min-height: 20px;
  margin: 0;
  color: var(--accent);
  font-size: 14px;
}

.user-form {
  display: grid;
  grid-template-columns: 1fr 1fr 160px auto;
  align-items: end;
  gap: 12px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
}

.users-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding: 24px 28px;
  background: #f8fafb;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr 120px 180px;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

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

  .sidebar {
    min-height: auto;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 10px;
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  }

  .sidebar h1 {
    font-size: 20px;
  }

  .sidebar .eyebrow {
    display: none;
  }

  .sidebar .muted {
    margin-top: 4px;
    font-size: 12px;
  }

  .sidebar nav {
    grid-column: 1 / 2;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .nav-button,
  .ghost-button {
    text-align: center;
    min-height: 38px;
    padding: 0 10px;
  }

  .ghost-button {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    width: 62px;
  }

  .chat-panel,
  .users-panel {
    min-height: 0;
    height: auto;
  }

  .topbar,
  .messages,
  .composer,
  .user-form,
  .users-list {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    min-height: 66px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .topbar h2 {
    font-size: 19px;
    margin-bottom: 2px;
  }

  .topbar .muted {
    font-size: 12px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .messages {
    gap: 10px;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .message {
    width: 100%;
    padding: 12px;
  }

  .message-meta {
    font-size: 12px;
  }

  .favorite-btn {
    width: 32px;
    height: 32px;
  }

  .attachment-image {
    max-width: 100%;
    max-height: 260px;
  }

  .composer {
    gap: 8px;
    padding-top: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  textarea {
    min-height: 54px;
    max-height: 128px;
  }

  .composer-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .file-picker {
    min-width: 0;
  }

  .file-picker span {
    width: 100%;
    justify-content: center;
    min-height: 40px;
  }

  .file-name {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 12px;
  }

  .composer-actions button {
    min-width: 88px;
    min-height: 40px;
  }

  .user-form,
  .user-row {
    grid-template-columns: 1fr;
  }

  .user-form {
    gap: 10px;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .users-list {
    padding-top: 14px;
    padding-bottom: 14px;
  }
}

@media (max-width: 380px) {
  .sidebar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar,
  .messages,
  .composer,
  .user-form,
  .users-list {
    padding-left: 10px;
    padding-right: 10px;
  }

  .sidebar h1 {
    font-size: 18px;
  }
}
