:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e4e9;
  --accent: #3461eb;
  --accent-hover: #2a4fc4;
  --danger: #c23b3b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.card h1 {
  margin: 0 0 20px;
  font-size: 1.3rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type='text'],
input[type='password'],
input[type='url'],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 14px;
  font-family: inherit;
}

textarea {
  resize: vertical;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  cursor: pointer;
}

.checkbox-label input[type='checkbox'] {
  width: auto;
  margin: 0;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 500;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #eceef2;
  color: var(--text);
}

.btn-link {
  background: none;
  color: var(--accent);
  padding: 4px 0;
  font-size: 0.85rem;
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: -6px 0 10px;
}

.success-text {
  color: #1b7a3d;
  font-size: 0.9rem;
}

.app-shell {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px;
}

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

.app-topbar h1 {
  font-size: 1.2rem;
  margin: 0;
}

.app-topbar .actions {
  display: flex;
  gap: 8px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.panel h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

#editor {
  background: #fff;
  min-height: 300px;
}

.editor-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

#status-text {
  color: var(--muted);
  font-size: 0.85rem;
}

.links-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.links-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.links-list a {
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.links-list a:hover {
  text-decoration: underline;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.modal-large {
  max-width: 560px;
}

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

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-wrap: wrap;
}

.chat-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.chat-info .chat-name {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.chat-info .chat-preview {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 360px;
}

.chat-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-pending {
  background: #fff1cc;
  color: #8a6400;
}

.badge-whitelisted {
  background: #d7f0dd;
  color: #1b7a3d;
}

.badge-blocked {
  background: #f6d7d7;
  color: var(--danger);
}

.chat-messages {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  padding-right: 4px;
}

.chat-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.chat-bubble.in {
  background: #eceef2;
}

.chat-bubble.out {
  background: var(--accent);
  color: #fff;
}

.chat-bubble-row {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}

.chat-bubble-row.in {
  align-self: flex-start;
}

.chat-bubble-row.out {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.bubble-delete-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.bubble-delete-btn:hover {
  color: var(--danger);
}

#print-area {
  display: none;
}

@media print {
  body > *:not(#print-area) {
    display: none !important;
  }

  #print-area {
    display: block;
    font-family: -apple-system, Arial, sans-serif;
    color: #1f2430;
    line-height: 1.5;
  }

  #print-area h1 {
    font-size: 1.3rem;
  }

  #print-area h2 {
    font-size: 1.1rem;
    border-bottom: 1px solid #ccc;
    padding-bottom: 4px;
    margin-top: 28px;
  }

  #print-area section {
    break-inside: avoid;
  }

  #print-area .note {
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 6px;
  }

  #print-area p.in {
    color: #333;
  }

  #print-area p.out {
    color: #3461eb;
  }
}
