:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --card-2: #fbfbfd;
  --border: #e8eaef;
  --text: #1a1d26;
  --muted: #6b7280;
  --primary: #5850ec;
  --primary-hover: #4a43d6;
  --primary-soft: #eef0fe;
  --danger: #e53e3e;
  --success: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* Topbar */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 24px;
  height: 60px; display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-icon { color: var(--primary); font-size: 1.05rem; line-height: 1; }
.brand-icon-block { display: block; text-align: center; margin: 0 auto 12px; font-size: 1.7rem; }
.topnav { display: flex; align-items: center; gap: 6px; }
.topnav > a { color: var(--muted); font-weight: 500; font-size: 0.875rem; padding: 0.45rem 0.75rem; border-radius: 0.6rem; display: inline-flex; align-items: center; gap: 0.5rem; white-space: nowrap; }
.topnav > a i { font-size: 0.9rem; opacity: 0.8; }
.topnav > a:hover { color: var(--text); background: var(--primary-soft); text-decoration: none; }
.topnav > a.active { color: var(--primary); background: var(--primary-soft); }
.nav-spacer { flex: 1 1 auto; }

/* Account pill + popover */
.user-menu { position: relative; display: flex; align-items: center; margin-left: 8px; }
.user-pill { display: inline-flex; align-items: center; gap: 9px; padding: 5px 10px 5px 6px; border-radius: 999px; background: transparent; border: 1px solid transparent; cursor: pointer; color: var(--text); font-family: var(--font); font-size: 0.88rem; font-weight: 600; transition: background .15s, border-color .15s; }
.user-pill:hover { background: var(--card-2); border-color: var(--border); }
.user-avatar { width: 30px; height: 30px; border-radius: 999px; flex-shrink: 0; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; background: var(--primary); color: #fff; font-size: 0.78rem; font-weight: 700; letter-spacing: .3px; }
.user-avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 0.88rem; color: var(--text); max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-caret { font-size: 0.7rem; color: var(--muted); transition: transform .15s; }
.user-pill[aria-expanded="true"] .user-caret { transform: rotate(180deg); }
.user-pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; min-width: 210px; padding: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 20px 45px -15px rgba(16,24,40,.35); }
.user-pop[hidden] { display: none; }
.user-pop-head { padding: 8px 10px; font-size: 0.75rem; color: var(--muted); line-height: 1.5; }
.user-pop-head strong { color: var(--text); font-size: 0.9rem; }
.user-pop-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.user-pop-item { width: 100%; text-align: left; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 0.9rem; font-weight: 600; color: var(--text); background: transparent; border: none; cursor: pointer; font-family: var(--font); }
.user-pop-item i { width: 1.05rem; text-align: center; color: var(--muted); }
.user-pop-item:hover { background: var(--card-2); }
.user-pop-item.danger { color: var(--danger); }
.user-pop-item.danger i { color: var(--danger); }
.user-pop-item.danger:hover { background: var(--danger); color: #fff; }
.user-pop-item.danger:hover i { color: #fff; }
.user-pop-item.active { background: var(--primary-soft); color: var(--primary); }
.user-pop-item.active i { color: var(--primary); }
/* The navigation links inside the popover are only used on compact viewports,
   where the avatar becomes the single menu trigger (no separate hamburger). */
.user-pop-nav { display: none; }

/* Layout */
.container { max-width: 1080px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 28px; gap: 16px; }
.page-head h1 { margin: 4px 0 2px; font-size: 1.7rem; }
.back-link { font-size: 0.85rem; }
.head-actions { display: flex; gap: 8px; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: 9px; padding: 9px 16px;
  font-size: 0.92rem; font-weight: 600; cursor: pointer; font-family: var(--font);
  transition: background .15s, border-color .15s, color .15s;
}
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f3f4f6; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: #f3f4f6; }
.btn-danger { background: #fff; color: var(--danger); border-color: #f3c2c2; }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* Flash + alerts */
.flash, .alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 16px; font-size: 0.9rem; }
.flash-success, .alert-success { background: #e7f7ee; color: #1a7f47; }
.flash-error, .alert-error { background: #fdecec; color: #c0392b; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], select, textarea {
  border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px;
  font-size: 0.95rem; font-family: var(--font); background: #fff; color: var(--text); width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(88,80,236,0.12); }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--primary); vertical-align: middle; }
.inline-fields { display: flex; gap: 12px; flex-wrap: wrap; }
.inline-fields .field { flex: 1; min-width: 160px; }

/* Auth */
.auth-wrap { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 32px; }
.auth-head { text-align: center; margin-bottom: 8px; }
.auth-head h1 { margin: 12px 0 4px; font-size: 1.4rem; }
.auth-head .brand-icon { font-size: 1.7rem; }
.auth-alt { margin-top: 16px; text-align: center; font-size: 0.85rem; }
.auth-alt .sep { color: var(--border); margin: 0 8px; }
.auth-footnote { font-size: 0.8rem; }

/* Multi-step login (password / one-time code / passkey) */
.auth-view { display: flex; flex-direction: column; gap: 14px; }
.auth-view form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.method-list { display: flex; flex-direction: column; gap: 10px; }
.method-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-family: var(--font);
  font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s;
}
.method-btn:hover { background: var(--card-2); border-color: var(--primary); }
.method-btn .method-icon { width: 1.6rem; text-align: center; color: var(--primary); font-size: 1.05rem; }
.who-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.who-row .who { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); min-width: 0; }
.who-row .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { color: var(--primary); font-size: 0.85rem; font-weight: 600; background: transparent; border: none; cursor: pointer; font-family: var(--font); padding: 0; }
.link-btn:hover { text-decoration: underline; }
.hint-text { font-size: 0.85rem; line-height: 1.5; margin: 0; }
.center-link { text-align: center; }
.code-input { letter-spacing: 0.35em; text-align: center; font-size: 1.15rem; }
.passkey-hint { text-align: center; }
.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Badges / chips */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 0.75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge-active { background: #dcfce7; color: #16803c; }
.badge-disabled { background: #fee2e2; color: #b91c1c; }
.badge-neutral { background: var(--primary-soft); color: var(--primary); }
.badge-301 { background: #fef3c7; color: #b45309; }
.badge-302 { background: #e0f2fe; color: #0369a1; }

/* Inline action buttons (used in tables) */
.copy-btn { background: var(--card-2); border: 1px solid var(--border); color: var(--muted); border-radius: 7px; padding: 5px 9px; cursor: pointer; font-size: 0.8rem; margin-left: 6px; }
.copy-btn:hover { color: var(--text); border-color: var(--primary); }
table.data-table tr:hover td { background: var(--card-2); }
.empty i { font-size: 2.2rem; opacity: 0.4; margin-bottom: 12px; display: block; }

/* Account page */
.account-profile { display: flex; align-items: center; gap: 16px; }
.account-avatar { width: 48px; height: 48px; font-size: 1.05rem; }
.account-name { margin: 0; font-weight: 600; }
.account-email { margin: 2px 0 0; font-size: 0.88rem; }

/* Passkey list */
.passkey-list { list-style: none; margin: 0 0 16px; padding: 0; }
.passkey-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.passkey-item:last-child { border-bottom: none; }
.passkey-icon { width: 36px; height: 36px; flex-shrink: 0; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--primary); }
.passkey-info { min-width: 0; flex: 1; }
.pk-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pk-name { font-size: 0.92rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-name-input { font-size: 0.92rem; font-weight: 600; padding: 4px 8px; }
.pk-meta { font-size: 0.78rem; margin-top: 2px; }
.passkey-item .copy-btn { margin-left: 0; }

/* Stat cards */
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { display: flex; flex-direction: row; align-items: center; gap: 14px; }
.stat-icon {
  width: 46px; height: 46px; border-radius: 13px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
}
.stat-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 0.82rem; color: var(--muted); }

/* Icon color tints */
.ic-violet { color: #5850ec; background: #eef0fe; }
.ic-blue   { color: #0284c7; background: #e0f2fe; }
.ic-green  { color: #16a34a; background: #dcfce7; }
.ic-amber  { color: #d97706; background: #fef3c7; }
.ic-pink   { color: #db2777; background: #fce7f3; }
.ic-teal   { color: #0d9488; background: #ccfbf1; }
.ic-indigo { color: #4f46e5; background: #e0e7ff; }
.ic-red    { color: #dc2626; background: #fee2e2; }

/* Chart */
.chart-card { margin-bottom: 22px; }
.chart-wrap { position: relative; height: 300px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.chart-head h2 { margin: 0; font-size: 1.05rem; }
.period-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.period-btn { border: none; background: #fff; padding: 6px 12px; cursor: pointer; font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.period-btn.active { background: var(--primary); color: #fff; }

/* Lists */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px; }
.list-card h2 { margin: 0 0 14px; font-size: 1.05rem; }
.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.bar-list li:last-child { border-bottom: none; }
.bl-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bl-count { color: var(--muted); font-weight: 600; flex-shrink: 0; }

/* Activity table */
table.activity { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
table.activity th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); font-size: 0.8rem; }
table.activity td { padding: 8px; border-bottom: 1px solid var(--border); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.activity tr:last-child td { border-bottom: none; }

/* Activity / data tables */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
table.data-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); font-size: 0.8rem; white-space: nowrap; }
table.data-table td { padding: 8px; border-bottom: 1px solid var(--border); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data-table tr:last-child td { border-bottom: none; }

/* Section sub-navigation */
.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 22px; border-bottom: 1px solid var(--border); padding-bottom: 2px; overflow-x: auto; }
.subnav-btn { display: inline-flex; align-items: center; gap: 8px; border: none; background: transparent; padding: 10px 14px; cursor: pointer; font-size: 0.9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.subnav-btn i { font-size: 0.95rem; opacity: 0.85; }
.subnav-btn:hover { color: var(--text); }
.subnav-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Section sub-navigation: mobile dropdown (custom, not a native select) */
.subnav-mobile { display: none; position: relative; margin-bottom: 22px; }
.subnav-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 11px;
  padding: 12px 14px; cursor: pointer; font-family: var(--font); font-size: 0.95rem;
  font-weight: 600; color: var(--text); box-shadow: var(--shadow);
}
.subnav-trigger-current { display: inline-flex; align-items: center; gap: 10px; }
.subnav-trigger-current i { color: var(--primary); font-size: 1rem; }
.subnav-chevron { color: var(--muted); transition: transform .18s ease; }
.subnav-trigger[aria-expanded="true"] .subnav-chevron { transform: rotate(180deg); }
.subnav-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, 0.16); padding: 6px; overflow: hidden;
}
.subnav-menu.open { display: block; }
.subnav-menu-item {
  width: 100%; display: flex; align-items: center; gap: 12px; border: none; background: transparent;
  padding: 11px 12px; border-radius: 8px; cursor: pointer; font-family: var(--font);
  font-size: 0.95rem; font-weight: 600; color: var(--text); text-align: left;
}
.subnav-menu-item i { width: 18px; text-align: center; color: var(--muted); font-size: 0.95rem; }
.subnav-menu-item:hover { background: #f3f4f6; }
.subnav-menu-item.active { color: var(--primary); background: #eef0fe; }
.subnav-menu-item.active i { color: var(--primary); }

/* Realtime */
.stat.realtime .stat-value { color: var(--primary); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; margin-left: 4px; vertical-align: middle; animation: livePulse 1.6s ease-in-out infinite; }
@keyframes livePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Snippet */
#snippet, pre.snippet { background: #1a1d26; color: #e2e8f0; padding: 16px; border-radius: 9px; overflow-x: auto; font-size: 0.85rem; margin: 8px 0 12px; }
#snippet code, pre.snippet code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Projects */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.project-card { display: flex; flex-direction: column; gap: 14px; color: var(--text); }
.project-card:hover { text-decoration: none; border-color: var(--primary); }
.project-card-head { display: flex; align-items: center; justify-content: space-between; }
.project-name { font-weight: 700; font-size: 1.05rem; }
.chip { background: #eef0fe; color: var(--primary); font-size: 0.75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.project-stats { display: flex; gap: 22px; flex-wrap: wrap; }
.project-stat { display: flex; align-items: center; gap: 10px; }
.project-stat .stat-icon { width: 38px; height: 38px; border-radius: 11px; font-size: 0.95rem; }
.project-stats .stat-value { font-size: 1.3rem; line-height: 1.1; }
.chip i { font-size: 0.7rem; }
.project-domain i { font-size: 0.72rem; opacity: 0.7; margin-right: 2px; }
.project-card-foot { font-size: 0.78rem; }
.new-project { margin-bottom: 22px; display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.new-project .field { flex: 1; margin-top: 0; }
.empty { text-align: center; padding: 60px 20px; }

/* Settings */
.settings { display: flex; flex-direction: column; gap: 0; margin-bottom: 22px; }
.settings-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.settings-form .field { margin-top: 0; }
.settings-form .field input { min-width: 220px; }
.settings-section { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--border); }
.settings-heading { margin: 0 0 6px; font-size: 1rem; }
.settings-section .muted { margin: 0 0 12px; font-size: 0.88rem; }
.settings-danger .settings-heading { color: var(--danger); }
.inline-form { display: flex; gap: 8px; align-items: center; }
.project-domain { font-size: 0.82rem; margin-top: -6px; }

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(16, 24, 40, 0.55); backdrop-filter: blur(1px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .15s ease, visibility .15s ease;
}
.modal-overlay.is-open { opacity: 1; visibility: visible; pointer-events: auto; }
.modal-card {
  background: var(--card); width: 100%; max-width: 440px;
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.25);
  transform: translateY(6px) scale(.98); transition: transform .15s ease;
}
.modal-overlay.is-open .modal-card { transform: translateY(0) scale(1); }
.modal-title { padding: 20px 22px 0; font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 14px 22px; color: var(--text); font-size: 0.95rem; line-height: 1.55; }
.modal-actions { padding: 0 22px 20px; display: flex; justify-content: flex-end; gap: 10px; }
.modal-confirm-field { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.modal-confirm-field label { font-size: 0.85rem; color: var(--muted); }
.modal-confirm-field input,
.modal-body input[data-role="input"] {
  width: 100%; border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 12px; font-size: 0.95rem; font-family: var(--font);
}
.modal-prompt-msg { margin-bottom: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Responsive */
@media (max-width: 900px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .container { padding: 22px 16px 64px; }
  .topbar-inner { padding: 0 16px; }
  .topnav { display: none; }
  .user-menu { margin-left: 0; }
  .user-pop-nav { display: block; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: stretch; }
  .head-actions { justify-content: flex-end; }
  .page-head h1 { font-size: 1.45rem; }
  .new-project { flex-direction: column; align-items: stretch; }
  .new-project .field, .new-project .btn { width: 100%; }
  .settings-form { flex-direction: column; align-items: stretch; }
  .settings-form .field input { min-width: 0; width: 100%; }
  .stat-value { font-size: 1.45rem; }
  .subnav { display: none; }
  .subnav-mobile { display: block; }
  .chart-wrap { height: 340px; }
  .chart-head { flex-direction: column; align-items: flex-start; gap: 10px; }
}

@media (max-width: 460px) {
  .stat-cards { grid-template-columns: 1fr; }
  .user-name { display: none; }
  .stat-icon { width: 42px; height: 42px; font-size: 1.05rem; }
}
