:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --line: #e3e7ec;
  --ink: #14202b;
  --muted: #6b7785;
  --brand: #128c7e;
  --brand-dark: #0b6f63;
  --brand-soft: #e6f5f2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --warn-soft: #fff4e5;
  --warn-ink: #8a4b00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 32, 43, 0.06), 0 8px 24px rgba(20, 32, 43, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.05rem;
}

h2 {
  font-size: 1rem;
}

a {
  color: var(--brand-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

.small {
  font-size: 0.82rem;
}

.center {
  text-align: center;
}

/* ------------------------------------------------------------------ login */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #dff3ef 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 14px;
}

.login-card h1 {
  font-size: 1.25rem;
  text-align: center;
}

.login-card .muted {
  text-align: center;
  margin: -8px 0 4px;
}

.logo {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: 0 auto 6px;
  border-radius: 14px;
  background: var(--brand-soft);
  font-size: 22px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

input,
textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.14);
}

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

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 9px 14px;
}

button.primary {
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

button.primary:hover {
  background: var(--brand-dark);
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

button.ghost:hover {
  background: #f5f7f9;
}

/* ------------------------------------------------------------------ shell */

.shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.sidebar-head .muted {
  display: block;
  margin-top: 2px;
}

.list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.list .empty {
  padding: 18px 12px;
}

.item a {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
}

.item a:hover {
  background: #f5f7f9;
  text-decoration: none;
}

.item.active a {
  background: var(--brand-soft);
}

.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e8edf2;
  color: #47576a;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.avatar.big {
  width: 44px;
  height: 44px;
  font-size: 0.85rem;
  background: var(--brand);
  color: #fff;
}

.item-body {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.item-top,
.item-bottom {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.item-top .name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-top .time {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.item-bottom .preview {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chip {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.chip.on {
  background: #e1f7ef;
  color: #0a6b5c;
}

.chip.off {
  background: #fdf0e3;
  color: var(--warn-ink);
}

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.sidebar-foot form {
  margin: 0;
}

/* --------------------------------------------------------------- banners */

.banner {
  margin: 10px 12px;
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.35;
}

.banner.warn {
  background: var(--warn-soft);
  color: var(--warn-ink);
}

.banner.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.banner.ok {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

/* ---------------------------------------------------------------- thread */

.thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #eff1f0;
  background-image: radial-gradient(rgba(20, 32, 43, 0.05) 1px, transparent 1px);
  background-size: 18px 18px;
}

.thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.thread-head form {
  margin: 0;
}

.thread-id {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.thread-id h2 {
  font-size: 0.98rem;
}

.thread-id .muted {
  display: block;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.messages .center {
  margin-top: 24px;
}

.row {
  display: flex;
}

.row.out {
  justify-content: flex-end;
}

.bubble {
  max-width: min(560px, 78%);
  padding: 8px 11px 6px;
  border-radius: 12px;
  box-shadow: 0 1px 1px rgba(20, 32, 43, 0.08);
}

.bubble.in {
  background: var(--bubble-in);
  border-top-left-radius: 4px;
}

.bubble.out {
  background: var(--bubble-out);
  border-top-right-radius: 4px;
}

.bubble.human {
  background: #dbeafe;
}

.bubble .text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
}

.bubble .meta {
  margin-top: 3px;
  font-size: 0.68rem;
  color: rgba(20, 32, 43, 0.5);
  text-align: right;
}

/* --------------------------------------------------------------- compose */

.compose {
  display: grid;
  gap: 8px;
  padding: 12px 18px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.compose textarea {
  width: 100%;
}

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

.thread-empty {
  margin: auto;
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.thread-empty h2 {
  color: var(--ink);
  margin-bottom: 4px;
}

.thread-empty .logo {
  width: 56px;
  height: 56px;
  font-size: 26px;
  margin-bottom: 14px;
}

/* ------------------------------------------------------------ responsive */

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

  .sidebar {
    max-height: 38vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
