:root {
  color-scheme: light;
  --ink: #0b0b0c;
  --muted: #6f6f74;
  --faint: #a8a8ad;
  --line: #d8d8dc;
  --line-strong: #0b0b0c;
  --panel: #ffffff;
  --soft: #f3f3f4;
  --soft-strong: #e9e9eb;
  --accent: #d71920;
  --accent-strong: #a70f15;
  --accent-soft: #ffe5e6;
  --warn: #d71920;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.12);
  font-family: "Avenir Next", "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle, rgba(11, 11, 12, 0.12) 1px, transparent 1.4px) 0 0 / 18px 18px,
    linear-gradient(180deg, #f8f8f8 0%, #eeeeef 100%);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.auth-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 22px;
  padding: 28px;
}

.brand {
  width: min(440px, 100%);
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.brand-mark {
  width: 58px;
  height: 58px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle, #fff 1.8px, transparent 2px) 0 0 / 9px 9px,
    var(--ink);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-weight: 900;
  font-size: 27px;
}

.brand h1,
.brand p,
.conversation-header h2,
.conversation-header p {
  margin: 0;
}

.brand h1 {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 31px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.brand p,
.conversation-header p,
#meUsername {
  color: var(--muted);
}

.brand p {
  margin-top: 5px;
  font-size: 14px;
}

.auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.94);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 10px 10px 0 var(--ink);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--soft-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab {
  min-width: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  font-weight: 800;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: #8f8f94;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(215, 25, 32, 0.18);
}

.primary {
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 12px 16px;
  font-weight: 900;
}

.primary:hover {
  background: var(--accent-strong);
}

.primary:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

.chat-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 370px) minmax(0, 1fr);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.76)),
    radial-gradient(circle, rgba(11, 11, 12, 0.1) 1px, transparent 1.4px) 0 0 / 18px 18px;
}

.sidebar {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  background: rgba(255, 255, 255, 0.96);
  border-right: 2px solid var(--ink);
}

.sidebar-header,
.conversation-header {
  min-height: 72px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid var(--ink);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
}

.sidebar-header div,
.conversation-header div {
  min-width: 0;
}

#meName,
#meUsername {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#meName,
.conversation-header h2 {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.icon-button,
.tool-button,
.remove-file {
  display: grid;
  place-items: center;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.icon-button:hover {
  background: var(--ink);
  color: #fff;
}

.new-chat {
  padding: 14px;
  display: grid;
  gap: 10px;
  border-bottom: 2px solid var(--ink);
  background:
    linear-gradient(135deg, rgba(215, 25, 32, 0.06), transparent 45%),
    #fff;
}

.conversation-list {
  overflow-y: auto;
  padding: 8px;
}

.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.conversation-item:hover {
  background: var(--soft);
  border-color: var(--line);
}

.conversation-item.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.conversation-item.active span {
  color: #d9d9dd;
}

.avatar {
  width: 44px;
  height: 44px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.85) 1.4px, transparent 1.7px) 0 0 / 7px 7px,
    var(--accent);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-weight: 900;
  text-transform: uppercase;
}

.conversation-item strong,
.conversation-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item strong {
  font-weight: 900;
}

.conversation-item span {
  color: var(--muted);
  font-size: 13px;
}

.conversation {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.conversation-header h2 {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.messages {
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  max-width: 360px;
  margin: auto;
  padding: 18px;
  border: 1px dashed var(--faint);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.message {
  max-width: min(680px, 82%);
  display: grid;
  gap: 5px;
}

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

.message-meta {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  padding: 0 4px;
}

.bubble {
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  padding: 11px 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.42;
  box-shadow: 4px 4px 0 rgba(11, 11, 12, 0.14);
}

.message.mine .bubble {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.message.mine .message-meta {
  text-align: right;
}

.message.mine .attachment audio {
  filter: invert(1);
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-top: 2px solid var(--ink);
  background: rgba(255, 255, 255, 0.94);
}

.composer-tools {
  min-height: 48px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.tool-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.tool-button:hover {
  background: var(--ink);
  color: #fff;
}

.tool-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tool-button.recording {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.composer-main {
  position: relative;
  min-width: 0;
  display: grid;
  gap: 8px;
}

.emoji-panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  z-index: 10;
  width: min(280px, 82vw);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 10px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 8px 8px 0 var(--ink);
}

.emoji-choice {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-size: 20px;
}

.emoji-choice:hover {
  border-color: var(--ink);
  background: #fff;
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pending-file {
  max-width: 280px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 7px 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.pending-file span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-file {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
}

.composer textarea {
  min-height: 48px;
  max-height: 150px;
  resize: none;
}

.message-text + .attachment,
.attachment + .attachment {
  margin-top: 9px;
}

.attachment img {
  display: block;
  max-width: min(420px, 100%);
  max-height: 360px;
  border: 1px solid currentColor;
  border-radius: 8px;
  object-fit: contain;
}

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

.attachment-file a,
.attachment a {
  color: inherit;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.admin-shell {
  align-items: center;
  justify-content: center;
}

.admin-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.admin-list {
  display: grid;
  gap: 12px;
}

.admin-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
}

.admin-row strong,
.admin-row span {
  display: block;
}

.admin-row span {
  color: var(--muted);
  font-size: 0.86rem;
}

@media (max-width: 760px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 2px solid var(--ink);
  }

  .conversation-list {
    display: flex;
    overflow-x: auto;
  }

  .conversation-item {
    min-width: 230px;
  }

  .conversation {
    min-height: 62vh;
  }

  .messages {
    padding: 16px;
  }

  .message {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: 1fr auto;
  }

  .composer-tools {
    grid-column: 1 / -1;
    min-height: 40px;
  }
}
