/* ─── Reset & Base ───────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f23;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e4e4f0;
  --text-dim: #8888a8;
  --text-muted: #555570;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.25);
  --green: #00d68f;
  --green-bg: rgba(0, 214, 143, 0.12);
  --red: #ff6b6b;
  --red-bg: rgba(255, 107, 107, 0.12);
  --yellow: #ffd93d;
  --yellow-bg: rgba(255, 217, 61, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.light {
  --bg: #f0f0f8;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --border: rgba(0, 0, 0, 0.08);
  --text: #1a1a2e;
  --text-dim: #555580;
  --text-muted: #999;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.15);
  --green-bg: rgba(0, 214, 143, 0.1);
  --red-bg: rgba(255, 107, 107, 0.08);
  --yellow-bg: rgba(255, 217, 61, 0.1);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* ─── App Container ──────────────────────────────────────────────── */
.app {
  max-width: 540px;
  margin: 0 auto;
  padding: 0 16px 100px;
}

/* ─── Header ─────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 16px 0 12px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(15, 15, 35, 0.8);
}

.light .header {
  background: rgba(240, 240, 248, 0.85);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 8px;
}

.logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: -2px;
}

/* ─── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
  backdrop-filter: blur(10px);
  transition: background 0.2s;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.card-title svg {
  color: var(--accent);
  flex-shrink: 0;
}

/* ─── Badge ──────────────────────────────────────────────────────── */
.badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  min-width: 22px;
  text-align: center;
}

.badge-company {
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 11px;
  border: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Select ─────────────────────────────────────────────────────── */
.select-wrapper {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  min-width: 0;
}

select {
  display: block;
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  padding: 12px 16px;
  font-size: 14px;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color 0.2s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238888a8' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

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

.btn-primary:hover:not(:disabled) {
  background: #5a4bd4;
}

.btn-check {
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: white;
  width: 100%;
  padding: 16px;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius);
  margin-top: 16px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: all 0.2s;
}

.btn-check:hover:not(:disabled) {
  box-shadow: 0 6px 30px rgba(108, 92, 231, 0.4);
  transform: translateY(-1px);
}

.btn-check:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-check:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.btn-refresh {
  width: 44px;
  height: 44px;
}

/* ─── Form ───────────────────────────────────────────────────────── */
.add-form {
  margin-bottom: 16px;
}

.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

input[type="text"] {
  flex: 1;
  padding: 12px 14px;
  font-size: 14px;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s;
  min-width: 0;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

#nameInput {
  flex: 0.8;
}

#boidInput {
  flex: 1.2;
}

/* ─── People List ────────────────────────────────────────────────── */
.people-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.person-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  animation: slideIn 0.2s ease;
}

.person-item:hover {
  border-color: rgba(108, 92, 231, 0.3);
}

.person-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.person-info {
  flex: 1;
  min-width: 0;
}

.person-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person-boid {
  font-size: 11px;
  color: var(--text-dim);
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.5px;
}

.person-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.person-remove:hover {
  color: var(--red);
  background: var(--red-bg);
}

.empty-state {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Results ────────────────────────────────────────────────────── */
.results-card {
  animation: slideIn 0.3s ease;
}

.stats-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.stat {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.stat-allotted {
  background: var(--green-bg);
}

.stat-not {
  background: var(--red-bg);
}

.stat-error {
  background: var(--yellow-bg);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
}

.stat-allotted .stat-value {
  color: var(--green);
}

.stat-not .stat-value {
  color: var(--red);
}

.stat-error .stat-value {
  color: var(--yellow);
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  animation: slideIn 0.3s ease;
}

.result-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.result-allotted .result-icon {
  background: var(--green-bg);
}

.result-not .result-icon {
  background: var(--red-bg);
}

.result-error .result-icon {
  background: var(--yellow-bg);
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-msg {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-boid {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ─── Loading ────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 35, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(8px);
}

.light .loading-overlay {
  background: rgba(240, 240, 248, 0.92);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 20px;
}

.loading-overlay p {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.loading-sub {
  font-size: 12px !important;
  color: var(--text-dim) !important;
  font-weight: 400 !important;
  margin-top: 4px;
}

/* ─── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ─── iOS Install Banner ─────────────────────────────────────────── */
.ios-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  z-index: 400;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
  transform: translateY(100%);
  animation: slideUpBanner 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards 2s;
}

.light .ios-install-banner {
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
}

.ios-install-content {
  flex: 1;
}

.ios-install-content p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
}

.ios-install-content svg {
  display: inline-block;
  vertical-align: middle;
  margin: 0 4px;
  color: var(--accent);
}

.ios-install-close {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ─── Animations ─────────────────────────────────────────────────── */
@keyframes slideUpBanner {
  to {
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .form-row {
    flex-direction: column;
  }

  #nameInput,
  #boidInput {
    flex: 1;
  }

  .stats-bar {
    gap: 4px;
  }

  .stat {
    padding: 8px 4px;
  }

  .stat-value {
    font-size: 18px;
  }
}