/* ===== Design Tokens ===== */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #181b24;
  --bg-card: #1e2230;
  --bg-input: #262b3d;
  --bg-hover: #2d3348;

  --text-primary: #e8eaed;
  --text-secondary: #9aa0b0;
  --text-muted: #6b7280;

  --border: #2d3348;
  --border-focus: #6c8cff;

  --accent: #6c8cff;
  --accent-hover: #5a7aff;
  --accent-soft: rgba(108, 140, 255, 0.12);

  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);

  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition: 0.2s ease;
}

/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  padding: 24px 16px 64px;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 16px 0 8px;
}

.header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6c8cff, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ===== Card ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ===== Label & Input ===== */
.label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.92rem;
  resize: vertical;
  min-height: 100px;
  transition: border-color var(--transition);
}

.textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}

.textarea::placeholder {
  color: var(--text-muted);
}

.name-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.name-count {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-ghost:active {
  transform: scale(0.97);
}

.btn-full {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  font-size: 0.95rem;
}

/* ===== Mode Switch ===== */
.mode-switch {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: all var(--transition);
  flex: 1;
  min-width: 160px;
}

.radio-label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text-primary);
}

.radio-label input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* ===== Option Rows ===== */
.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.option-row .label {
  margin-bottom: 0;
}

.input-number {
  width: 90px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.92rem;
  text-align: center;
  transition: border-color var(--transition);
}

.input-number:focus {
  outline: none;
  border-color: var(--border-focus);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* ===== Custom Names Block ===== */
.custom-names-block {
  padding: 12px 0 4px;
  border-top: 1px solid var(--border);
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Result ===== */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.result-title-block h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.drag-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.result-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.result-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== Group Card ===== */
.group-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  animation: fadeInUp 0.35s ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 8px 16px;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

/* Editable group name */
.group-title-input {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  transition: all var(--transition);
  min-width: 0;
}

.group-title-input:hover {
  border-color: var(--border);
}

.group-title-input:focus {
  outline: none;
  background: var(--bg-input);
  border-color: var(--border-focus);
}

.group-badge {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.group-members {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 48px;
  transition: background var(--transition), border-color var(--transition);
  border: 2px dashed transparent;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Drag over highlight */
.group-members.drag-over {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.group-members:empty::before {
  content: 'Kéo thành viên vào đây';
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
  padding: 8px;
}

/* Member item */
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  font-size: 0.9rem;
  color: var(--text-primary);
  border-radius: 6px;
  cursor: grab;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  user-select: none;
}

.member-item::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  transition: background var(--transition);
}

.member-item:hover {
  background: var(--bg-hover);
}

.member-item:active {
  cursor: grabbing;
}

.member-item.dragging {
  opacity: 0.4;
  background: var(--accent-soft);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 9999;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ===== Utilities ===== */
.hidden {
  display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 560px) {
  .header h1 { font-size: 1.4rem; }
  .card { padding: 16px; }
  .mode-switch { flex-direction: column; }
  .radio-label { min-width: auto; }
  .result-header { flex-direction: column; align-items: stretch; }
  .result-actions { justify-content: flex-start; }
  .btn { font-size: 0.82rem; padding: 8px 12px; }
  .drag-hint { font-size: 0.72rem; }
}