.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --chat-user-bg: #dcf8c6;
  --chat-admin-bg: #ffffff;
  --chat-header-bg: #075e54;
  --chat-header-text: #ffffff;
  --chat-input-bg: #f0f0f0;
}

.chat-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-login-main {
  padding: 3rem 0 4rem;
}

.chat-login-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 2rem;
}

.chat-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  padding: 1.5rem;
}

.chat-panel h2 {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
}

.chat-panel p {
  color: var(--muted);
  margin-top: 0;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.chat-form label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.chat-form input[type="text"] {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  margin-bottom: 0.75rem;
}

.chat-form .hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -0.35rem 0 0.75rem;
}

.chat-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.2rem;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.chat-btn-primary {
  background: var(--accent);
  color: #fff;
}

.chat-btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.chat-btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.chat-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-message {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.95rem;
}

.chat-message.error {
  background: #fdecea;
  color: #8a2a1f;
}

.chat-message.success {
  background: #e8f5e9;
  color: #1b5e20;
}

.chat-new-panel {
  display: none;
}

.chat-new-panel.is-open {
  display: block;
}

/* ── Chat room (LINE-like) ── */
.chat-room {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  min-height: calc(100vh - 4rem);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #e5ddd5;
  box-shadow: 0 8px 32px rgba(31, 26, 23, 0.08);
}

.chat-room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--chat-header-bg);
  color: var(--chat-header-text);
}

.chat-room-title {
  min-width: 0;
}

.chat-room-title h1 {
  margin: 0;
  font-size: 1.05rem;
  font-family: inherit;
}

.chat-room-title p {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  opacity: 0.85;
}

.chat-status {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.18);
}

.chat-status.continuation {
  background: rgba(255, 255, 255, 0.22);
}

.chat-status.ordered {
  background: #f9a825;
  color: #1f1a17;
}

.chat-status.completion {
  background: #66bb6a;
  color: #fff;
}

.chat-order-btn {
  flex-shrink: 0;
  padding: 0.45rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.chat-order-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
}

.chat-order-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background:
    linear-gradient(rgba(229, 221, 213, 0.92), rgba(229, 221, 213, 0.92)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cdc4' fill-opacity='0.35'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-bubble-row {
  display: flex;
}

.chat-bubble-row.user {
  justify-content: flex-end;
}

.chat-bubble-row.admin {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: min(78%, 420px);
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 0.95rem;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.chat-bubble-row.user .chat-bubble {
  background: var(--chat-user-bg);
  border-bottom-right-radius: 4px;
}

.chat-bubble-row.admin .chat-bubble {
  background: var(--chat-admin-bg);
  border-bottom-left-radius: 4px;
}

.chat-bubble-time {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: right;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

.chat-compose {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--chat-input-bg);
  border-top: 1px solid var(--line);
}

.chat-compose textarea {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  resize: vertical;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  font: inherit;
}

.chat-send-btn {
  align-self: flex-end;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 999px;
  background: var(--chat-header-bg);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.chat-send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-back-link:hover {
  color: var(--accent);
}

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

  .chat-room {
    min-height: calc(100vh - 2rem);
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .chat-room-header {
    flex-wrap: wrap;
  }
}

/* ── Admin panel ── */
.chat-admin-page {
  background: var(--bg);
}

.chat-admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.chat-admin-login-panel {
  width: min(420px, 100%);
}

.chat-admin-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
}

.chat-admin-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.chat-admin-header p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-admin-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  min-height: 0;
}

.chat-admin-sidebar {
  border-right: 1px solid var(--line);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-admin-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}

.chat-admin-tab {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.chat-admin-tab.active {
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.chat-admin-room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.chat-admin-room-item {
  width: 100%;
  display: grid;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.chat-admin-room-item:hover,
.chat-admin-room-item.is-active {
  background: color-mix(in srgb, var(--accent) 8%, var(--paper));
}

.chat-admin-room-item-id {
  font-weight: 700;
  color: var(--ink);
}

.chat-admin-room-item-status {
  display: inline-block;
  width: fit-content;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: #ececec;
}

.chat-admin-room-item-status.continuation {
  background: #e3f2fd;
  color: #1565c0;
}

.chat-admin-room-item-status.ordered {
  background: #fff3e0;
  color: #e65100;
}

.chat-admin-room-item-status.completion {
  background: #e8f5e9;
  color: #2e7d32;
}

.chat-admin-room-item-preview {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-admin-room-item-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.chat-admin-empty {
  padding: 1rem;
  color: var(--muted);
  text-align: center;
}

.chat-admin-main {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.chat-admin-placeholder {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
}

.chat-admin-room {
  flex: 1;
  min-height: 0;
  max-width: none;
  margin: 0;
}

.chat-admin-room-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-family: inherit;
}

.chat-admin-room-actions {
  display: flex;
  gap: 0.5rem;
}

.chat-admin-page-message {
  margin: 0 1.25rem 1rem;
}

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

  .chat-admin-sidebar {
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .chat-admin-room {
    min-height: 50vh;
  }
}
