:root {
  --bg: #008080;
  --win: #c0c0c0;
  --win-soft: #d4d0c8;
  --win-dark: #808080;
  --win-light: #ffffff;
  --text: #000000;
  --link: #0000aa;
  --title-start: #000080;
  --title-end: #1084d0;
  --danger: #990000;
  --font: Tahoma, Verdana, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.35;
}

a {
  color: var(--link);
}

input,
textarea,
button {
  font: inherit;
}

.desktop {
  max-width: 980px;
  margin: 24px auto;
  padding: 0 10px;
}

.window {
  background: var(--win);
  border-top: 2px solid var(--win-light);
  border-left: 2px solid var(--win-light);
  border-right: 2px solid #000;
  border-bottom: 2px solid #000;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.titlebar {
  background: linear-gradient(90deg, var(--title-start), var(--title-end));
  color: #fff;
  padding: 5px 8px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.titlebtn {
  width: 18px;
  height: 16px;
  background: var(--win);
  border-top: 1px solid var(--win-light);
  border-left: 1px solid var(--win-light);
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  color: #000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  flex-shrink: 0;
}

.content {
  padding: 12px;
}

.toolbar {
  border: 1px solid var(--win-dark);
  background: var(--win-soft);
  padding: 6px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status {
  color: #111;
  font-size: 12px;
}

.panel {
  background: var(--win-soft);
  border-top: 1px solid var(--win-light);
  border-left: 1px solid var(--win-light);
  border-right: 1px solid var(--win-dark);
  border-bottom: 1px solid var(--win-dark);
  padding: 10px;
}

label,
.field-label {
  display: block;
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: #222;
}

.text-input,
textarea {
  width: 100%;
  padding: 6px;
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-right: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-light);
  background: #fff;
}

.text-input:focus,
textarea:focus {
  outline: 1px dotted #000;
  outline-offset: -2px;
}

.btn95 {
  padding: 5px 12px;
  background: var(--win-soft);
  border-top: 1px solid var(--win-light);
  border-left: 1px solid var(--win-light);
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
  cursor: pointer;
}

.btn95:active {
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-right: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-light);
}

.btn95:disabled,
.htmx-request .send-btn {
  opacity: 0.6;
  cursor: not-allowed;
}

#error-banner {
  min-height: 18px;
  color: #222;
  margin: 2px 0 10px;
  font-size: 12px;
}

#error-banner.visible {
  color: var(--danger);
}

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

.thread-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 10px;
  min-height: 64dvh;
}

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

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40dvh;
  overflow-y: auto;
}

.thread-item {
  display: block;
  text-align: left;
  width: 100%;
  padding: 6px 8px;
  background: #fff;
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-right: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-light);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.thread-item.active {
  background: #d7ecff;
}

.thread-item-title {
  display: block;
  font-weight: 700;
  margin-bottom: 2px;
}

.thread-item-meta {
  display: block;
  font-size: 11px;
  color: #333;
}

.new-thread-form {
  display: grid;
  gap: 6px;
}

.chat-main {
  display: grid;
  gap: 10px;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.empty-state {
  background: #fff;
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-right: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-light);
  padding: 10px;
  font-size: 12px;
  color: #333;
}

.chat-panel {
  background: #fff;
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-right: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-light);
  padding: 10px;
}

#message-list {
  min-height: min(58dvh, 560px);
  max-height: min(58dvh, 560px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-right: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-light);
}

.message {
  width: 100%;
  padding: 7px 8px;
  border-bottom: 1px solid #c9c9c9;
  background: #fff;
}

.message:nth-child(even) {
  background: #f1f1f1;
}

.message:last-child {
  border-bottom: 0;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.message-author {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.2px;
}

.message.user .message-author {
  color: #000080;
}

.message.bot .message-author {
  color: #0a5f2d;
}

.message-time {
  font-size: 11px;
  color: #4d4d4d;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  color: #111;
}

.input-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.input-bar textarea {
  min-height: 72px;
  max-height: 220px;
  resize: vertical;
  margin: 0;
}

.send-btn {
  min-width: 88px;
  height: 34px;
  white-space: nowrap;
}

.auth-shell {
  min-height: calc(100dvh - 48px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-window {
  width: min(440px, 100%);
}

.auth-subtitle {
  margin-bottom: 10px;
  font-size: 12px;
  color: #111;
}

.auth-error {
  margin-bottom: 10px;
  padding: 8px;
  font-size: 12px;
  background: #f7d9d9;
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-right: 1px solid var(--win-light);
  border-bottom: 1px solid var(--win-light);
  color: var(--danger);
}

.auth-form {
  display: grid;
  gap: 8px;
}

.auth-form .btn95 {
  justify-self: start;
  margin-top: 4px;
}

@media (max-width: 720px) {
  .desktop {
    margin: 10px auto;
    padding: 0 6px;
  }

  .content {
    padding: 8px;
  }

  .thread-layout {
    grid-template-columns: 1fr;
  }

  #message-list {
    min-height: 50dvh;
    max-height: 50dvh;
  }

  .input-bar {
    grid-template-columns: 1fr;
  }

  .send-btn {
    width: 100%;
  }
}
