:root, :root[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e5e9f2;
  --text: #1e293b;
  --text-muted: #667085;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success-bg: #ecfdf5;
  --success-text: #059669;
  --success-dot: #10b981;
  --danger-bg: #fef2f2;
  --danger-text: #dc2626;
  --danger-dot: #ef4444;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);
}

:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #171926;
  --border: #262838;
  --text: #e6e6e6;
  --text-muted: #9aa0ab;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-light: #1e2148;
  --success-bg: #0f2b22;
  --success-text: #34d399;
  --success-dot: #34d399;
  --danger-bg: #2c1518;
  --danger-text: #f87171;
  --danger-dot: #f87171;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { overflow-x: hidden; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.15s, color 0.15s;
}

.hidden { display: none !important; }

.theme-toggle-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.theme-toggle-btn svg { width: 17px; height: 17px; }
.theme-toggle-btn:hover { border-color: var(--primary); color: var(--primary); }

.auth-theme-toggle {
  position: absolute;
  top: 1.1rem;
  right: 1.1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
:root[data-theme="dark"] .topbar { background: rgba(15, 17, 23, 0.85); }
.brand { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; color: var(--text); flex-shrink: 0; text-decoration: none; }
.brand span { color: var(--primary); }
.brand.center { text-align: center; font-size: 1.5rem; margin-bottom: 0.35rem; }
.user-info { display: flex; align-items: center; gap: 0.85rem; min-width: 0; }
.user-email {
  color: var(--text-muted);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.btn-primary {
  width: 100%;
  padding: 0.75rem;
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 6px 16px rgba(79, 70, 229, 0.25); }
.btn-primary:active { transform: translateY(1px); }

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 0.75rem;
  width: 100%;
  text-decoration: none;
  display: inline-block;
}
.btn-link:hover { text-decoration: underline; }
.btn-link:disabled { opacity: 0.5; cursor: not-allowed; }

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.1rem 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.google-btn-wrapper { display: flex; justify-content: center; }

.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  box-shadow: var(--shadow-lg);
}
.subtitle { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.subtitle.small { font-size: 0.85rem; margin-bottom: 1rem; }

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
}
.tab {
  flex: 1;
  padding: 0.55rem;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.tab.active { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: var(--shadow-sm); }

.auth-form label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--text-muted); margin: 0.85rem 0 0.35rem; }
.auth-form input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: var(--surface);
}
.auth-form .btn-primary { margin-top: 1.4rem; }

.msg { font-size: 0.85rem; margin-top: 0.75rem; min-height: 1.1em; text-align: center; }
.msg.error { color: var(--danger-text); }
.msg.success { color: var(--success-text); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  padding: 2.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  min-height: 190px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  transform: translateY(-3px);
  border-color: #c7d2fe;
  box-shadow: var(--shadow-md);
}
.card:hover .card-arrow { transform: translateX(3px); opacity: 1; }

.card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}
.card-icon svg { width: 22px; height: 22px; }

.card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  letter-spacing: -0.01em;
}
.card p {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.55;
  flex-grow: 1;
  margin-bottom: 1.1rem;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: auto;
}

.card-arrow {
  color: var(--text-muted);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
  display: flex;
}
.card-arrow svg { width: 16px; height: 16px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3.5rem 2rem;
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
}

/* Responsive */
@media (hover: none) {
  .card:hover { transform: none; }
  .card:hover .card-arrow { opacity: 0.6; }
}

@media (max-width: 640px) {
  .topbar { padding: 0.85rem 1.1rem; gap: 0.5rem; }
  .user-info { gap: 0.5rem; }
  .user-email { max-width: 110px; }
  .grid { padding: 1.25rem; gap: 0.9rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .auth-card { padding: 1.75rem 1.5rem; }
  .auth-theme-toggle { top: 0.85rem; right: 0.85rem; }
}

@media (max-width: 420px) {
  .brand { font-size: 1.05rem; }
  .brand.center { font-size: 1.3rem; }
  .user-email { display: none; }
  .grid { grid-template-columns: 1fr; padding: 1rem; gap: 0.75rem; }
  .card { min-height: 0; padding: 1.25rem; }
  .btn-ghost { padding: 0.45rem 0.75rem; font-size: 0.8rem; }
  .auth-wrapper { padding: 1rem; }
  .auth-card { padding: 1.5rem 1.25rem; }
}

/* Profile (AI keys) */
.profile-wrapper {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 2rem;
}
.profile-header { margin-bottom: 2rem; }
.back-link { display: inline-block; margin: 0 0 1rem 0; width: auto; }
.profile-header h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.5rem; }
.profile-subtitle { text-align: left; margin-bottom: 0; max-width: 560px; }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.provider-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.provider-header { display: flex; align-items: center; gap: 0.85rem; margin-bottom: 1.1rem; }
.provider-header h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.3rem; }

.brand-badge {
  color: #ffffff;
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: 50%;
  letter-spacing: 0;
}

.badge-status {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}
.badge-status.configured { background: var(--success-bg); color: var(--success-text); }
.badge-status.missing { background: var(--danger-bg); color: var(--danger-text); }

.provider-card label { display: block; font-size: 0.78rem; font-weight: 500; color: var(--text-muted); margin: 0.75rem 0 0.3rem; }
.provider-card input,
.provider-card select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
}
.provider-card input:focus,
.provider-card select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.provider-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; }
.provider-actions .btn-primary,
.provider-actions .btn-ghost { width: auto; flex: 1; padding: 0.55rem 0.9rem; font-size: 0.85rem; }

.provider-msg { text-align: left; margin-top: 0.6rem; min-height: 1em; }

@media (max-width: 640px) {
  .profile-wrapper { padding: 1.5rem 1.1rem; }
  .profile-grid { grid-template-columns: 1fr; }
}
