:root {
  --ink: #14202b;
  --muted: #64717f;
  --line: #d7e0e7;
  --green: #d7ff4f;
  --deep: #123044;
  --teal: #176b87;
  --coral: #ff6f61;
  --aqua: #2ec4b6;
  --bg: #f2f6f8;
  --paper: #ffffff;
  --accent: var(--coral);
  --accent-soft: #fff1ee;
}

:root[data-accent="aqua"] {
  --accent: #2ec4b6;
  --accent-soft: #e8fbf8;
}

:root[data-accent="violet"] {
  --accent: #8b5cf6;
  --accent-soft: #f3efff;
}

:root[data-accent="gold"] {
  --accent: #d89b00;
  --accent-soft: #fff6d8;
}

:root[data-theme="dark"] {
  --ink: #ecf4f8;
  --muted: #a8b7c3;
  --line: #29495d;
  --deep: #071722;
  --teal: #2ec4b6;
  --bg: #0b1822;
  --paper: #102434;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #123044 0 42%, #176b87 42% 58%, var(--bg) 58% 100%);
}

:root[data-theme="dark"] body {
  background: linear-gradient(160deg, #06131d 0 44%, #123044 44% 62%, #0b1822 62% 100%);
}

button, input { font: inherit; }

.shell {
  width: min(1120px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  place-items: center;
}

.auth {
  width: min(440px, 100%);
  display: grid;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
}

.logo {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green);
  color: var(--deep);
  font-weight: 800;
  font-size: 24px;
}

.logo-img {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .18);
}

.logo-img.small {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  box-shadow: none;
}

h1, p { margin: 0; }
h1 { font-size: 30px; }
.brand p { opacity: .86; margin-top: 3px; }

.panel, .chat {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .16);
}

.panel {
  border-radius: 8px;
  padding: 22px;
}

.auth-login .panel { border-top: 4px solid var(--aqua); }
.auth-register .panel { border-top: 4px solid var(--accent); }
.chat-mode { background: linear-gradient(160deg, #123044 0 120px, #f2f6f8 120px 100%); }

.sidebar button {
  border: 1px solid var(--line);
  background: #f6faf8;
  color: var(--ink);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
}

form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 13px 14px;
  color: var(--ink);
  outline: none;
}

.terms-check {
  grid-template-columns: 18px 1fr;
  align-items: start;
  color: var(--ink);
  line-height: 1.35;
}

.terms-check input {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.terms-box {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #f8fbfa;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.terms-box summary {
  color: var(--teal);
  cursor: pointer;
  font-weight: 700;
}

.terms-box p { margin-top: 8px; }
input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(18, 140, 126, .14); }

.primary {
  border: 0;
  border-radius: 6px;
  padding: 13px 16px;
  background: var(--accent);
  color: var(--deep);
  font-weight: 800;
  cursor: pointer;
}

.secondary {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 13px 16px;
  background: #f6faf8;
  color: var(--deep);
  font-weight: 800;
}

.home-panel {
  display: grid;
  gap: 12px;
}

.link-button {
  display: block;
  text-align: center;
  text-decoration: none;
}

.switch-link {
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.switch-link a {
  color: var(--teal);
  font-weight: 700;
}

.notice { min-height: 20px; margin-top: 14px; color: #b3261e; font-size: 14px; }

.site-footer {
  width: min(1120px, calc(100vw - 28px));
  margin: -72px auto 20px;
  min-height: 52px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, .9);
  color: var(--deep);
  box-shadow: 0 10px 28px rgba(18, 48, 68, .12);
}

.site-footer img {
  width: 144px;
  height: auto;
}

.site-footer strong {
  color: var(--coral);
  font-size: 13px;
}

.site-footer span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chat-footer {
  margin-top: -18px;
}

.chat {
  width: 100%;
  height: min(820px, calc(100vh - 96px));
  min-height: 560px;
  display: grid;
  grid-template-columns: 330px 1fr;
  border-radius: 8px;
  overflow: hidden;
}

.sidebar {
  background: #f8fbfa;
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px;
}

.compact { color: var(--ink); }
.compact h1 { font-size: 22px; }
.compact p { color: var(--muted); font-size: 13px; }

.room-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

#rooms { display: grid; gap: 10px; }

.sidebar-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.room-item {
  width: 100%;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.room-item.active {
  border-color: color-mix(in srgb, var(--accent) 44%, transparent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.room-item strong,
.room-item small {
  display: block;
}

.room-item small {
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--teal), var(--accent));
  color: white;
  font-weight: 800;
  font-size: 14px;
}

.sidebar-footer {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dev-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: white;
  color: var(--deep);
  text-align: center;
  text-decoration: none;
  font-weight: 800;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer button {
  min-width: 0;
  font-size: 12px;
  font-weight: 800;
}

.dev-shell {
  width: min(980px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 28px 0;
}

.admin-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 28px 0;
}

.admin-page {
  display: grid;
  gap: 16px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 16px;
}

.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: white;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .1);
}

.admin-card h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.admin-form {
  grid-template-columns: 1fr 58px auto;
  align-items: center;
}

.admin-table {
  display: grid;
  gap: 10px;
}

.user-admin-row {
  display: grid;
  grid-template-columns: 200px 110px 1fr 150px 86px;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbfd;
}

.admin-password {
  padding: 10px;
  font-size: 13px;
}

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

.user-admin-row small {
  display: block;
  color: var(--muted);
}

.user-admin-row button {
  border: 0;
  border-radius: 6px;
  padding: 10px;
  background: var(--deep);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag-check {
  display: inline-flex;
  grid-template-columns: auto;
  align-items: center;
  gap: 5px;
  font-size: 12px;
}

.tag-check input {
  width: 14px;
  height: 14px;
}

.tag-check span,
.tag-badge {
  border: 1px solid var(--tag-color);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--tag-color);
  background: white;
  font-size: 11px;
}

.role-doc {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 8px 12px;
}

.role-badge {
  display: inline-flex;
  margin-left: 6px;
  border-radius: 999px;
  padding: 2px 7px;
  color: white;
  font-size: 10px;
  vertical-align: middle;
}

.role-adm { background: #b3261e; }
.role-mod { background: #176b87; }
.role-membro { background: #64717f; }

.dev-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.dev-nav a {
  border: 1px solid rgba(255, 255, 255, .36);
  border-radius: 6px;
  padding: 9px 12px;
  color: white;
  text-decoration: none;
  font-weight: 800;
}

.dev-page {
  display: grid;
  gap: 14px;
}

.dev-brand {
  color: white;
  margin-bottom: 6px;
}

.dev-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: white;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .1);
}

.dev-card h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.dev-card p,
.dev-card li {
  color: #33413d;
  line-height: 1.55;
}

.dev-card ul,
.dev-card ol {
  margin: 10px 0 0;
  padding-left: 22px;
}

.dev-card pre {
  overflow: auto;
  border-radius: 6px;
  padding: 12px;
  background: #eef6f2;
  color: var(--deep);
}

.new-room,
.room-form button {
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: 6px;
  padding: 10px;
  background: var(--accent-soft);
  color: var(--deep);
  font-weight: 800;
  cursor: pointer;
}

.room-form {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.room-form input {
  padding: 10px;
  font-size: 13px;
}

.online-list {
  display: grid;
  gap: 8px;
}

.online-user {
  display: grid;
  grid-template-columns: 10px 1fr;
  column-gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 13px;
}

.online-user small {
  grid-column: 2;
  color: var(--muted);
}

.online-user.muted {
  display: block;
  color: var(--muted);
}

.online-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--aqua);
  box-shadow: 0 0 0 3px rgba(46, 196, 182, .18);
}

.search {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: white;
  color: var(--teal);
  font-weight: 700;
}

.room {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at 12px 12px, color-mix(in srgb, var(--accent) 12%, transparent) 2px, transparent 3px) 0 0 / 34px 34px,
    #edf3f6;
}

:root[data-theme="dark"] .room {
  background:
    radial-gradient(circle at 12px 12px, color-mix(in srgb, var(--accent) 16%, transparent) 2px, transparent 3px) 0 0 / 34px 34px,
    #0d1e2b;
}

.room header {
  min-height: 78px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  background: #f7fbf9;
  border-bottom: 1px solid var(--line);
}

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

.compact-avatar {
  width: 42px;
  height: 42px;
}

.room-title div { display: grid; gap: 4px; min-width: 0; }
.room header span { color: var(--muted); font-size: 13px; }

.room-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.header-logout {
  border: 0;
  border-radius: 6px;
  padding: 9px 12px;
  background: var(--accent);
  color: var(--deep);
  font-weight: 800;
  cursor: pointer;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.bubble {
  max-width: min(620px, 82%);
  border-radius: 8px 8px 8px 2px;
  padding: 10px 12px;
  background: white;
  border: 1px solid rgba(216, 225, 221, .7);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .05);
}

.bubble.mine {
  align-self: flex-end;
  border-radius: 8px 8px 2px 8px;
  background: #fff0cc;
  border-color: #f1d994;
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.text {
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.chat-media {
  display: block;
  max-width: 100%;
  margin-bottom: 8px;
}

.image-media {
  max-height: 320px;
  border-radius: 7px;
  object-fit: contain;
  background: rgba(255, 255, 255, .5);
}

.empty-state {
  margin: auto;
  width: min(360px, 100%);
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, .65);
  color: var(--muted);
  text-align: center;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 12px;
  padding: 14px 18px;
  background: #f7fbf9;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  z-index: 5;
  min-height: 118px;
}

.composer input[name="body"] {
  min-height: 46px;
  background: var(--paper);
  border: 2px solid color-mix(in srgb, var(--accent) 26%, var(--line));
  color: var(--ink);
}

.attach-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.attach-button {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

#attachmentName {
  color: var(--muted);
  font-size: 13px;
}

.composer button {
  border: 0;
  border-radius: 6px;
  background: var(--deep);
  color: white;
  font-weight: 800;
  cursor: pointer;
  min-height: 46px;
  min-width: 78px;
}

.theme-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
}

.theme-controls button,
.theme-controls select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
}

:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .chat,
:root[data-theme="dark"] .admin-card,
:root[data-theme="dark"] .dev-card,
:root[data-theme="dark"] .site-footer,
:root[data-theme="dark"] .room header,
:root[data-theme="dark"] .sidebar,
:root[data-theme="dark"] .composer,
:root[data-theme="dark"] .room-item,
:root[data-theme="dark"] .room-form,
:root[data-theme="dark"] .bubble,
:root[data-theme="dark"] .dev-link,
:root[data-theme="dark"] .attach-button {
  background-color: var(--paper);
  color: var(--ink);
}

:root[data-theme="dark"] input,
:root[data-theme="dark"] select {
  background: #0b1822;
  color: var(--ink);
  border-color: var(--line);
}

:root[data-theme="dark"] .bubble.mine {
  background: color-mix(in srgb, var(--accent) 28%, #102434);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
}

:root[data-theme="dark"] .dev-card p,
:root[data-theme="dark"] .dev-card li {
  color: var(--muted);
}

.composer button:disabled {
  cursor: progress;
  opacity: .72;
}

@media (max-width: 760px) {
  body { background: var(--deep); }
  .shell { width: 100%; min-height: 100vh; }
  .auth { width: calc(100vw - 28px); }
  .chat {
    height: 100vh;
    min-height: 100vh;
    border-radius: 0;
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
  .room header { padding: 12px 14px; min-height: 68px; }
  .room-actions span { display: none; }
  .messages { padding: 14px; }
  .bubble { max-width: 90%; }
  .composer { grid-template-columns: 1fr 78px; padding: 10px; min-height: 108px; }
  .site-footer { margin: 10px auto; width: calc(100vw - 20px); }
  .chat-footer { display: none; }
  .admin-grid,
  .user-admin-row,
  .admin-form { grid-template-columns: 1fr; }
}

@supports not (color: color-mix(in srgb, red, blue)) {
  .room-item.active {
    border-color: var(--accent);
  }

  .new-room,
  .room-form button {
    border-color: var(--accent);
  }

  .room {
    background: #edf3f6;
  }

  .empty-state {
    border-color: var(--accent);
  }

  .composer input[name="body"] {
    border-color: var(--accent);
  }
}

@media (min-width: 1400px) {
  .shell {
    width: min(1320px, calc(100vw - 48px));
  }

  .chat {
    grid-template-columns: 360px 1fr;
  }

  .admin-shell {
    width: min(1320px, calc(100vw - 48px));
  }
}

@media (max-width: 1180px) {
  .shell,
  .site-footer {
    width: calc(100vw - 24px);
  }

  .chat {
    grid-template-columns: 290px 1fr;
  }

  .sidebar {
    padding: 14px;
  }

  .sidebar-footer {
    grid-template-columns: 1fr;
  }

  .user-admin-row {
    grid-template-columns: 180px 105px 1fr;
  }

  .user-admin-row .admin-password,
  .user-admin-row button {
    grid-column: auto;
  }
}

@media (max-width: 980px) {
  .shell {
    min-height: auto;
    padding: 18px 0;
  }

  .site-footer {
    margin: 12px auto;
  }

  .chat {
    height: calc(100vh - 24px);
    min-height: 540px;
    grid-template-columns: 260px 1fr;
  }

  .room header {
    padding: 12px 14px;
  }

  .room-actions span {
    display: none;
  }

  .admin-grid,
  .password-form {
    grid-template-columns: 1fr;
  }

  .admin-form {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 720px) and (min-width: 761px) {
  .shell {
    min-height: auto;
    padding: 10px 0;
  }

  .chat {
    height: calc(100vh - 20px);
    min-height: 500px;
  }

  .sidebar {
    gap: 10px;
    padding: 12px;
  }

  .room header {
    min-height: 62px;
    padding: 10px 14px;
  }

  .messages {
    padding: 14px;
  }

  .composer {
    min-height: 96px;
    padding: 10px 12px;
  }

  .chat-footer {
    display: none;
  }
}

@media (max-width: 760px) {
  body {
    min-width: 320px;
  }

  h1 {
    font-size: 25px;
  }

  .brand {
    padding: 0 10px;
  }

  .panel {
    padding: 18px;
  }

  .room-title {
    gap: 8px;
  }

  .compact-avatar {
    width: 36px;
    height: 36px;
    font-size: 12px;
  }

  .room-title strong {
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-logout {
    padding: 8px 10px;
  }

  .attach-row {
    gap: 6px;
  }

  .attach-button {
    padding: 7px 9px;
  }

  .theme-controls {
    width: 100%;
    justify-content: center;
    margin-left: 0;
  }

  .site-footer img {
    width: 120px;
  }

  .dev-shell,
  .admin-shell {
    width: calc(100vw - 20px);
    padding: 18px 0;
  }

  .dev-card,
  .admin-card {
    padding: 16px;
  }

  .dev-card pre {
    font-size: 12px;
  }
}

@media (max-width: 420px) {
  .composer {
    grid-template-columns: 1fr 68px;
    gap: 8px;
  }

  .composer button {
    min-width: 64px;
    padding: 0 8px;
  }

  .bubble {
    max-width: 96%;
  }

  .meta {
    flex-direction: column;
    gap: 4px;
  }

  .site-footer {
    padding: 10px;
  }
}
