:root {
  --bg-primary: #1a0b2e;
  --bg-secondary: #2d1b4e;
  --bg-card: rgba(45, 27, 78, 0.6);
  --bg-input: rgba(30, 15, 55, 0.8);
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #a855f7;
  --accent-light: #c084fc;
  --accent-glow: rgba(168, 85, 247, 0.3);
  --border: rgba(168, 85, 247, 0.15);
  --border-active: rgba(168, 85, 247, 0.4);
  --shadow: 0 0 20px rgba(168, 85, 247, 0.15);
  --shadow-lg: 0 0 40px rgba(168, 85, 247, 0.2);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 32px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-height: 56px;
  --input-bar-height: 60px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 4px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.card:active {
  transform: scale(0.98);
  border-color: var(--border-active);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
}

.btn-primary:active {
  transform: scale(0.96);
  box-shadow: 0 0 30px var(--accent-glow);
}

.input-field {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s;
}

.input-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-field::placeholder {
  color: var(--text-muted);
}

.input-group {
  position: relative;
  width: 100%;
}

.input-group .input-field {
  padding-right: 48px;
}

.input-group .password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  color: var(--text-muted);
  transition: color 0.3s;
}

.input-group .password-toggle:hover {
  color: var(--text-secondary);
}

.safe-area-bottom {
  padding-bottom: calc(12px + var(--safe-bottom));
}

input, textarea {
  font-size: 16px;
}

body {
  overscroll-behavior-y: none;
}

@media (hover: none) {
  .btn-primary:active {
    opacity: 0.8;
  }
}

.page-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(26, 11, 46, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.page-header .logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-header .logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
}

.page-header .logo-title {
  font-size: 18px;
  font-weight: 600;
}

.page-header .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header .user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-secondary);
}

.page-header .settings-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s;
}

.page-header .settings-btn:hover {
  background: rgba(168, 85, 247, 0.1);
  border-color: var(--accent);
}

.page-header .login-btn {
  padding: 6px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  color: var(--accent);
  font-size: 14px;
  background: transparent;
  cursor: pointer;
}

.page-content {
  padding-top: calc(var(--header-height) + 16px);
  padding-bottom: calc(var(--input-bar-height) + 20px);
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 16px;
}

.agent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.agent-card:active {
  transform: scale(0.96);
  border-color: var(--border-active);
}

.agent-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-secondary);
}

.agent-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.agent-info {
  flex: 1;
}

.agent-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.agent-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.agent-arrow {
  align-self: flex-end;
  color: var(--accent);
  font-size: 18px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state .empty-text {
  font-size: 14px;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  width: 100%;
  max-width: 360px;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  padding: 24px;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-input);
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 14px;
  color: var(--text-secondary);
}

.form-group .input-field {
  font-size: 16px;
}

.agreement-section {
  margin: 16px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.checkbox-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
  line-height: 1.5;
}

.checkbox-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 3px;
  accent-color: var(--accent);
}

.checkbox-item a {
  color: var(--accent-light);
  text-decoration: underline;
}

.error-message {
  color: #ef4444;
  font-size: 13px;
  margin-top: 4px;
}

.success-message {
  color: #22c55e;
  font-size: 13px;
  margin-top: 4px;
}

.user-menu {
  position: absolute;
  top: calc(var(--header-height) + 8px);
  right: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 0;
  min-width: 160px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
}

.user-menu-item {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.2s;
}

.user-menu-item:hover {
  background: rgba(168, 85, 247, 0.1);
}

.user-menu-item-danger {
  color: #ef4444;
}

.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}