:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #111827;
  --primary-contrast: #ffffff;
  --danger: #dc2626;
  --admin: #7c3aed;
  --visitor-bubble: #f3f4f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #ffffff 0, var(--bg) 46%);
  color: var(--text);
}

button, input, textarea { font: inherit; }

.app-shell {
  min-height: 100vh;
  padding: 28px 16px;
  display: grid;
  place-items: center;
}

.chat-card {
  width: min(960px, 100%);
  height: min(820px, calc(100vh - 56px));
  min-height: 620px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

h1 { margin: 0 0 5px; font-size: 22px; }
.topbar p { margin: 0; color: var(--muted); font-size: 13px; }
.top-actions, .admin-actions { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #374151;
}
.badge.admin { color: #6d28d9; background: #ede9fe; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); color: var(--primary-contrast); }
.btn.secondary { background: #f3f4f6; color: #111827; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: #fee2e2; color: #b91c1c; }
.file-btn { display: inline-flex; align-items: center; }

.admin-panel {
  padding: 12px 24px;
  background: #faf8ff;
  border-bottom: 1px solid #ede9fe;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.admin-panel-title { color: #6d28d9; font-size: 13px; font-weight: 800; }
.hidden { display: none !important; }

.notice {
  margin: 12px 24px 0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  background: #eff6ff;
  color: #1d4ed8;
}
.notice.error { background: #fef2f2; color: #b91c1c; }
.notice.success { background: #ecfdf5; color: #047857; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fcfcfd;
}

.empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
}

.message {
  max-width: min(76%, 680px);
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-self: flex-start;
}
.message.admin { align-self: flex-end; }
.message-meta { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.message.admin .message-meta { justify-content: flex-end; }
.message-name { font-weight: 800; color: #374151; }
.role-tag { font-size: 10px; border-radius: 999px; padding: 2px 6px; background: #ede9fe; color: #6d28d9; font-weight: 800; }
.message-bubble {
  background: var(--visitor-bubble);
  border: 1px solid var(--line);
  padding: 11px 13px;
  border-radius: 6px 16px 16px 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}
.message.admin .message-bubble {
  background: #111827;
  color: #fff;
  border-color: #111827;
  border-radius: 16px 6px 16px 16px;
}
.expire { font-size: 11px; color: #9ca3af; }

.composer {
  border-top: 1px solid var(--line);
  padding: 16px 20px 18px;
  background: #fff;
}
.composer-row { display: flex; align-items: center; gap: 12px; margin-bottom: 9px; }
.nickname-input { width: 180px; }
.char-count { margin-left: auto; font-size: 12px; color: var(--muted); }
input, textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 11px;
  background: #fff;
  padding: 10px 12px;
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus { border-color: #6b7280; box-shadow: 0 0 0 3px rgba(17, 24, 39, .06); }
textarea { resize: none; line-height: 1.5; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 11px; }

.dialog {
  border: 0;
  padding: 0;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,.22);
}
.dialog::backdrop { background: rgba(17,24,39,.38); backdrop-filter: blur(3px); }
.dialog-card { width: min(390px, calc(100vw - 32px)); padding: 22px; }
.dialog-title { font-size: 18px; font-weight: 850; margin-bottom: 6px; }
.dialog-card p { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 680px) {
  .app-shell { padding: 0; }
  .chat-card { height: 100vh; min-height: 100vh; border-radius: 0; border: 0; }
  .topbar { padding: 16px; align-items: flex-start; }
  .topbar p { max-width: 210px; }
  .top-actions { justify-content: flex-end; }
  .admin-panel { padding: 10px 16px; align-items: flex-start; flex-direction: column; }
  .messages { padding: 18px 14px; }
  .message { max-width: 88%; }
  .composer { padding: 12px; }
  .hint { display: none; }
  .nickname-input { width: 145px; }
}
