*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg: #f4f4f5;
  --color-surface: #ffffff;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-text: #18181b;
  --color-muted: #71717a;
  --color-bubble-own: #2563eb;
  --color-bubble-own-text: #ffffff;
  --color-bubble-partner: #e4e4e7;
  --color-bubble-partner-text: #18181b;
  --color-error: #dc2626;
  --color-notice: #f59e0b;
  --radius: 0.5rem;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid #e4e4e7;
  padding: 0.75rem 1.5rem;
}

.site-title {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
}

.content {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card h1 { font-size: 1.25rem; }

.notice {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

.error {
  color: var(--color-error);
  font-size: 0.875rem;
}

/* Forms */
label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d4d4d8;
  border-radius: var(--radius);
  font-size: 1rem;
  width: 100%;
}

input:focus, textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.checkbox-label {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: normal;
}

.btn-primary {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  align-self: flex-start;
}

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

/* Conversation */
.conversation-header {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
}

.conversation-header h1 { font-size: 1rem; color: var(--color-muted); }
.partner-info { font-size: 0.9rem; margin-top: 0.25rem; }

.message-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  max-height: calc(100vh - 280px);
  padding: 0.5rem 0;
}

.bubble {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  word-break: break-word;
}

.bubble-own {
  align-self: flex-end;
  background: var(--color-bubble-own);
  color: var(--color-bubble-own-text);
  border-bottom-right-radius: 0.25rem;
}

.bubble-partner {
  align-self: flex-start;
  background: var(--color-bubble-partner);
  color: var(--color-bubble-partner-text);
  border-bottom-left-radius: 0.25rem;
}

.bubble-sender {
  font-size: 0.75rem;
  font-weight: 600;
  color: #2563eb;
  margin-bottom: 0.2rem;
}

.bubble-body { font-size: 0.9375rem; line-height: 1.4; }
.bubble-body a { color: inherit; text-decoration: underline; }

.bubble-time {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-top: 0.25rem;
  align-self: flex-end;
}

.message-form {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message-input {
  resize: vertical;
  min-height: 4rem;
}

/* Admin */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
}

.btn-secondary {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  background: #f4f4f5;
  color: var(--color-text);
  border: 1px solid #d4d4d8;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  align-self: flex-start;
}
.btn-secondary:hover { background: #e4e4e7; }

.btn-danger {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-danger:hover { background: #b91c1c; }

.btn-small {
  padding: 0.25rem 0.625rem;
  background: var(--color-surface);
  border: 1px solid #d4d4d8;
  border-radius: var(--radius);
  font-size: 0.75rem;
  cursor: pointer;
}
.btn-small:hover { background: #f4f4f5; }

.link-small { font-size: 0.75rem; }

.pairs-list { display: flex; flex-direction: column; gap: 1rem; }

.pair-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid #e4e4e7;
  overflow: hidden;
}

.pair-archived { opacity: 0.6; }

.pair-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.75rem 1rem;
  background: #f9f9f9;
  border-bottom: 1px solid #e4e4e7;
}
.pair-label { font-weight: 600; font-size: 0.9rem; }
.pair-meta { font-size: 0.75rem; color: var(--color-muted); }

.pair-groups { padding: 0.5rem 1rem; display: flex; flex-direction: column; gap: 0.375rem; }

.group-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
  flex-wrap: wrap;
}
.group-name { font-weight: 500; min-width: 12rem; }
.group-email { color: var(--color-muted); flex: 1; }
.group-seen { font-size: 0.75rem; color: var(--color-muted); }

.pair-actions {
  padding: 0.5rem 1rem 0.75rem;
  border-top: 1px solid #f0f0f0;
}

.group-fields {
  border: 1px solid #e4e4e7;
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.group-fields legend { font-weight: 600; font-size: 0.875rem; padding: 0 0.25rem; }

.import-result {
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.error-list { margin-top: 0.5rem; padding-left: 1.25rem; color: var(--color-error); font-size: 0.875rem; }
