/* ===================== Nexus ===================== */
:root {
  --bg: #0a0c12;
  --surface: #12151f;
  --surface-2: #1a1e2b;
  --surface-3: #232838;
  --border: #252a3a;
  --text: #e9ecf5;
  --muted: #8b93a7;
  --faint: #5d6478;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-soft: rgba(124, 92, 255, .14);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, .13);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .13);
  --danger: #ff5d6c;
  --danger-soft: rgba(255, 93, 108, .13);
  --grad: linear-gradient(135deg, #7c5cff 0%, #22d3ee 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .55);
  --radius: 18px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5fa;
    --surface: #ffffff;
    --surface-2: #eef0f7;
    --surface-3: #e3e6f0;
    --border: #e1e4ee;
    --text: #131726;
    --muted: #5c6479;
    --faint: #9299ab;
    --accent: #6a47ff;
    --accent-soft: rgba(106, 71, 255, .1);
    --ok: #0f9f6e;
    --ok-soft: rgba(15, 159, 110, .1);
    --warn: #b7791f;
    --warn-soft: rgba(183, 121, 31, .12);
    --danger: #e0394a;
    --danger-soft: rgba(224, 57, 74, .1);
    --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 8px 24px rgba(20, 24, 40, .07);
    --shadow-lg: 0 20px 60px rgba(20, 24, 40, .18);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.02em; }
p { margin: 0; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Ambient glow */
.glow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.glow::before, .glow::after {
  content: ""; position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%; filter: blur(90px); opacity: .22;
}
.glow::before { background: #7c5cff; top: -30vmax; left: -15vmax; animation: drift 22s ease-in-out infinite alternate; }
.glow::after { background: #22d3ee; bottom: -35vmax; right: -20vmax; animation: drift 26s ease-in-out infinite alternate-reverse; }
@media (prefers-color-scheme: light) { .glow::before, .glow::after { opacity: .13; } }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.1); } }

/* Brand */
.logo { width: 34px; height: 34px; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 6px 20px rgba(124, 92, 255, .3); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: transparent; color: #fff; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.btn.lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: 13px; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.sm { width: 32px; }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--faint); }
.input {
  height: 44px; width: 100%; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2);
  padding: 0 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 80px; padding: 10px 14px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group { position: relative; display: flex; }
.input-group .input { padding-right: 84px; }
.input-group .addon { position: absolute; right: 6px; top: 6px; display: flex; gap: 4px; }
.input-group .addon .btn { height: 32px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.alert { padding: 10px 14px; border-radius: 11px; font-size: 14px; background: var(--danger-soft); color: var(--danger); margin-bottom: 14px; display: none; }
.alert.show { display: block; animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- Login ---------- */
.login-wrap { position: relative; z-index: 1; min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; padding: 34px 30px 28px; backdrop-filter: blur(14px); background: color-mix(in srgb, var(--surface) 82%, transparent); }
.login-head { text-align: center; margin-bottom: 26px; }
.login-head .logo { width: 56px; height: 56px; margin: 0 auto 14px; display: block; }
.login-head h1 { font-size: 28px; font-weight: 800; }
.login-head p { color: var(--muted); margin-top: 6px; font-size: 14px; }
.login-foot { text-align: center; color: var(--faint); font-size: 13px; margin-top: 18px; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-btn { display: flex; align-items: center; gap: 9px; padding: 4px 10px 4px 4px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.user-btn:hover { background: var(--surface-2); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--grad); color: #fff; flex: none; text-transform: uppercase;
}
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }
.menu {
  position: absolute; right: 28px; top: 62px; min-width: 230px; padding: 6px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); display: none;
}
.menu.open { display: block; animation: pop .15s ease; }
.menu .who { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu .who b { display: block; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; background: none; border-radius: 9px; cursor: pointer; font-size: 14px; text-align: left; }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu .danger { color: var(--danger); }

main.container { position: relative; z-index: 1; max-width: 1120px; margin: 0 auto; padding: 40px 28px 80px; }
.fade { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- Home ---------- */
.hero { margin-bottom: 34px; }
.hero .eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 10px; }
.hero h1 { font-size: 40px; font-weight: 800; }
.hero p { color: var(--muted); font-size: 16px; margin-top: 10px; max-width: 560px; }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.app-tile {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 14px; padding: 22px; min-height: 210px;
  transition: transform .2s, box-shadow .2s, border-color .2s; cursor: pointer;
}
.app-tile::after {
  content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 100% 0%, var(--tile) 0%, transparent 55%); opacity: .14; pointer-events: none; transition: opacity .2s;
}
.app-tile:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--tile) 50%, var(--border)); }
.app-tile:hover::after { opacity: .26; }
.app-icon {
  width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; font-size: 28px; font-weight: 700; color: #fff;
  background: var(--tile); box-shadow: 0 8px 22px color-mix(in srgb, var(--tile) 40%, transparent);
}
.app-tile h3 { font-size: 20px; }
.app-tile p { color: var(--muted); font-size: 14px; flex: 1; }
.app-foot { display: flex; align-items: center; justify-content: space-between; }
.app-open { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; color: var(--text); }
.app-tile:hover .app-open .ic { transform: translateX(3px); }
.app-open .ic { transition: transform .2s; }
.coming { border-style: dashed; box-shadow: none; background: transparent; cursor: default; align-items: center; justify-content: center; text-align: center; color: var(--faint); }
.coming:hover { transform: none; box-shadow: none; border-color: var(--border); }
.coming::after { display: none; }
.foot-note { text-align: center; color: var(--faint); font-size: 13px; margin-top: 40px; }

/* ---------- Admin ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { font-size: 32px; font-weight: 800; }
.page-head p { color: var(--muted); margin-top: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat { padding: 18px 20px; }
.stat .lbl { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat .val { font-size: 30px; font-weight: 800; letter-spacing: -.03em; margin-top: 2px; }
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; }
.tab { border: 0; background: none; padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; display: inline-flex; gap: 8px; align-items: center; }
.tab.active { background: var(--surface-2); color: var(--text); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search { position: relative; flex: 1; max-width: 320px; min-width: 200px; }
.toolbar .search .ic { position: absolute; left: 12px; top: 13px; color: var(--faint); }
.toolbar .search .input { padding-left: 38px; height: 42px; }

.list { overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .name { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .meta { color: var(--muted); font-size: 13px; text-align: right; min-width: 130px; }
.list-row .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.list-row .app-icon { width: 44px; height: 44px; font-size: 21px; border-radius: 12px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.cred-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; font-size: 14px; white-space: pre-wrap; word-break: break-word; margin: 6px 0 16px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.switch { position: relative; width: 42px; height: 24px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: 99px; cursor: pointer; transition: background .2s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.inline-label { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.preview { display: flex; justify-content: center; padding: 18px; background: var(--surface-2); border-radius: 14px; margin-bottom: 16px; }
.preview .app-tile { width: 100%; max-width: 320px; min-height: 0; cursor: default; }
.preview .app-tile:hover { transform: none; }

/* ---------- Modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(5, 6, 12, .6); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; animation: fadeIn .15s; }
.modal { width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto; padding: 26px; position: relative; animation: pop .18s ease; }
.modal h2 { font-size: 20px; margin-bottom: 6px; }
.modal .desc { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.modal-x { position: absolute; top: 14px; right: 14px; }
#toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: .25s; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); color: #fff; }

/* Per-person app access */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px;
  background: color-mix(in srgb, var(--tile) 16%, transparent); border: 1px solid color-mix(in srgb, var(--tile) 35%, transparent);
}
.check-list { display: flex; flex-direction: column; gap: 8px; }
.check-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; background: var(--surface-2); }
.check-item:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check-item input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.check-item .app-icon { width: 36px; height: 36px; font-size: 18px; border-radius: 10px; }
.check-item .grow { flex: 1; min-width: 0; font-size: 14px; }

@media (max-width: 760px) {
  .topbar { padding: 12px 16px; }
  .menu { right: 16px; top: 58px; }
  main.container { padding: 26px 16px 60px; }
  .hero h1 { font-size: 30px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 12px 14px; }
  .stat .val { font-size: 24px; }
  .user-btn .uname { display: none; }
  .list-row { flex-wrap: wrap; }
  .list-row .meta { text-align: left; min-width: 0; width: 100%; order: 3; }
  .list-row .actions { width: 100%; justify-content: flex-start; order: 4; }
  .row { flex-direction: column; gap: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
