:root {
  --accent: #5B5FEF;
  --accent-dark: #4448c9;
  --accent-light: #eeeeff;
  --bg: #faf9fc;
  --card: #ffffff;
  --ink: #1a1a2e;
  --ink-soft: #6b6b7d;
  --ink-faint: #a3a3b3;
  --border: #e6e5ef;
  --danger: #e5484d;
  --danger-light: #fdeceb;
  --success: #2fa86f;
  --warn: #f5a623;
  --warn-light: #fff6e6;
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

button, input, textarea {
  font-family: inherit;
  font-size: 15px;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.center-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
}

.brand-name {
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
}

.card-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}

.card-sub {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin: 0 0 20px;
  line-height: 1.5;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  background: #fff;
}

.field .hint {
  font-size: 12px;
  color: var(--ink-faint);
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 20px;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-outline { background: transparent; color: var(--ink); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: var(--danger-light); color: var(--danger); }

.btn-sm { padding: 8px 16px; font-size: 13px; width: auto; }

.link-row {
  text-align: center;
  margin-top: 16px;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.link-row a { color: var(--accent); font-weight: 700; }

.error-msg {
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

.error-msg.visible { display: block; }

.notice {
  background: var(--warn-light);
  color: #8a5a00;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.5;
}

/* App shell */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 90px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--ink-faint);
  cursor: pointer;
  position: relative;
}

.tab-btn.active { color: var(--accent); }
.tab-btn .tab-icon { font-size: 20px; }
.tab-btn .tab-label { font-size: 10.5px; font-weight: 600; }

.tab-badge {
  position: absolute;
  top: 0;
  right: 22%;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Avatar */
.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-sm { width: 40px; height: 40px; font-size: 15px; }
.avatar-lg { width: 96px; height: 96px; font-size: 32px; }

/* QR section */
.qr-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
}

.qr-canvas-wrap {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 16px;
  display: inline-block;
  margin: 16px 0;
  border: 1px solid var(--border);
}

/* List items */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.list-item-info { flex: 1; min-width: 0; }
.list-item-name { font-weight: 700; font-size: 14.5px; }
.list-item-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-faint);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state .empty-title { font-weight: 700; color: var(--ink-soft); margin-bottom: 4px; }
.empty-state .empty-desc { font-size: 13px; }

.minor-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
}

/* Chat */
.chat-screen { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 18px; font-size: 14.5px; line-height: 1.4; word-wrap: break-word; }
.bubble-them { background: var(--card); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble-me { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--card); }
.chat-input-row input { flex: 1; }
.chat-send-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; border: none; flex-shrink: 0; cursor: pointer; font-size: 17px; }

.loading-center { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--ink-faint); font-size: 14px; }

/* Install / notification banners */
.install-banner {
  background: var(--accent-light);
  color: var(--accent-dark);
  padding: 12px 40px 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}

.install-banner strong { display: block; margin-bottom: 2px; }

.install-banner-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 6px;
  line-height: 1;
}

.install-banner-btn {
  display: inline-block;
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
