:root {
  --bg: #edf4ee;
  --panel: #ffffff;
  --panel-strong: #fffdfa;
  --ink: #23313a;
  --muted: #69767c;
  --line: #c8d7cc;
  --accent: #5f7f68;
  --accent-dark: #486351;
  --accent-soft: #dcebdd;
  --shadow: 0 18px 50px rgba(55, 92, 67, 0.10);
  --radius: 22px;
  --mono: Consolas, "Courier New", monospace;
  --sans: "Open Sans", Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(166, 201, 172, 0.30), transparent 28%),
    radial-gradient(circle at right 20%, rgba(118, 158, 126, 0.20), transparent 30%),
    linear-gradient(180deg, #f4faf4 0%, #eaf3eb 100%);
  min-height: 100vh;
}

body.logged-out {
  overflow: hidden;
}

body.logged-out #appView {
  display: none !important;
}

body.logged-in #loginView {
  display: none !important;
}

.shell {
  width: min(1400px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 252, 247, 0.98));
  border: 1px solid rgba(200, 215, 204, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel {
  width: min(460px, 100%);
  margin: 8vh auto 0;
  display: grid;
  gap: 20px;
}

body.logged-out .shell {
  width: 100vw;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

body.logged-out .login-panel {
  width: min(620px, 100%);
  margin: 0;
  position: relative;
  z-index: 2;
}

.welcome-grid {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.welcome-card {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(215, 204, 188, 0.85);
}

.welcome-card strong {
  display: block;
  margin-bottom: 6px;
}

.welcome-card p {
  margin: 0;
  color: var(--muted);
}

.brand h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  letter-spacing: 0.02em;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
}

.intro,
.hint,
.meta,
.thread-preview,
.annotation-meta {
  color: var(--muted);
}

.topbar-copy,
.section-copy {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 58ch;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.95rem;
}

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

input,
textarea,
select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #f2f8f2;
  padding: 14px 16px;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 13px 20px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
  box-shadow: 0 10px 24px rgba(81, 101, 93, 0.18);
}

button.ghost {
  background: #f5fbf5;
  color: var(--accent-dark);
  border: 1px solid var(--line);
}

button.small {
  padding: 8px 12px;
}

.hidden {
  display: none !important;
}

.error {
  min-height: 1.2em;
  color: #a12929;
  margin: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 24px;
  padding: 8px 4px 0;
}

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

.badge,
.pill {
  border-radius: 999px;
  background: var(--accent-soft);
  padding: 8px 12px;
  color: var(--accent-dark);
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.sidebar,
.content-column,
.composer-column,
.thread-column {
  display: grid;
  gap: 20px;
}

.composer-column {
  width: min(520px, 100%);
}

.thread-column {
  min-width: 0;
}

.composer-panel {
  position: sticky;
  top: 24px;
  border-top: 4px solid rgba(95, 127, 104, 0.24);
}

.thread-column #threadDetail {
  min-height: calc(100vh - 170px);
  border-top: 4px solid rgba(95, 127, 104, 0.24);
}

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

.section-head h2,
.thread-title {
  margin: 0;
}

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

.thread-card {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  text-align: left;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.thread-card:hover {
  transform: translateY(-1px);
  border-color: rgba(181, 77, 54, 0.45);
  box-shadow: 0 12px 32px rgba(62, 37, 18, 0.09);
}

.thread-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(181, 77, 54, 0.15);
}

.thread-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.composer-panel {
  padding: 28px;
}

.title-field input {
  font-size: 1rem;
  font-weight: 600;
}

.muted-field {
  opacity: 0.68;
}

.muted-field input {
  background: #e9f1ea;
}

.message-box textarea {
  min-height: 170px;
  border-width: 1px;
  border-color: #b8ccb9;
  border-radius: 18px;
  padding: 18px 18px;
  font-size: 1.02rem;
  line-height: 1.5;
  background: #f8fcf8;
}

.composer-bar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
}

.composer-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.composer-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.attach-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 94px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid #b7cab8;
  background: #f7fbf7;
  color: var(--accent-dark);
  font-weight: 700;
  cursor: pointer;
}

.attach-chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.send-button {
  min-width: 110px;
  border: 0;
}

.extras-panel {
  border: 1px dashed #bfd1c1;
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(244, 250, 244, 0.98);
}

.extras-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent-dark);
}

.extras-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.extras-full {
  grid-column: 1 / -1;
}

.tip-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.tip-strip span {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(247, 212, 198, 0.55);
  color: var(--accent-dark);
  font-size: 0.88rem;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 280px;
  color: var(--muted);
  text-align: center;
  gap: 10px;
}

.empty-illustration {
  padding: 14px 18px;
  border-radius: 999px;
  background: rgba(220, 235, 221, 0.95);
  color: var(--accent-dark);
  font-weight: 700;
}

.thread-view {
  display: grid;
  gap: 18px;
}

.message-stream {
  display: grid;
  gap: 14px;
}

.message-title {
  margin: 0 0 10px;
}

.entry,
.annotation {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.98);
}

.entry {
  box-shadow: 0 10px 26px rgba(79, 60, 35, 0.05);
}

.entry-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.entry-head strong {
  display: block;
}

.rich-text a {
  color: var(--accent-dark);
}

.media img,
.media video {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 18px;
  margin-top: 12px;
  background: #eef5ee;
}

.attachment-link {
  display: inline-block;
  margin-top: 12px;
}

.code-shell {
  margin-top: 12px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #d7d2c8;
}

.code-head {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: #5a7560;
  color: #f8f5ef;
  font-size: 0.86rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.code-table {
  width: 100%;
  border-collapse: collapse;
  background: #2d3f33;
  color: #eff4f2;
  font-family: var(--mono);
  font-size: 0.92rem;
}

.code-table td {
  vertical-align: top;
  padding: 0;
}

.line-no {
  width: 54px;
  text-align: right;
  color: #9fc0b5;
  border-right: 1px solid rgba(159, 192, 181, 0.18);
  user-select: none;
}

.line-no button {
  width: 100%;
  background: transparent;
  color: inherit;
  border-radius: 0;
  padding: 8px 10px;
  text-align: right;
}

.line-no button:hover,
.line-no button.selected {
  background: rgba(159, 192, 181, 0.16);
  transform: none;
}

.line-code {
  padding: 8px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.annotation-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.annotation-list-wrap h4,
.thread-view h3 {
  margin: 0 0 10px;
}

.inline-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

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

.admin-user {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.72);
}

pre {
  margin: 12px 0 0;
  padding: 14px;
  border-radius: 16px;
  background: #2d3f33;
  color: #f0f5f1;
  overflow-x: auto;
}

code {
  font-family: var(--mono);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .composer-panel {
    position: static;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 16px, 100%);
    padding-top: 12px;
  }

  .panel {
    padding: 18px;
    border-radius: 20px;
  }

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

  .composer-bar,
  .extras-grid {
    grid-template-columns: 1fr;
  }

  .attach-chip,
  .send-button {
    width: 100%;
  }
}
