/* NESTORA Aurora layer: aurora backdrop + spatial depth + glass surfaces.
   Loads LAST (after mobile.css). It changes surfaces, light and depth only; layout rules stay in app.css and mobile.css.
   Strict CSP: no inline styles. Pointer light and parallax come from spatial.js through CSS variables.

   Depth model (nearest to the viewer last):
     0  aurora sky          body::before / body::after
     1  glass-1  resting    panels, stats, sidebar, footer
     2  glass-2  raised     topbar, property cards, auth card, tab dock
     3  glass-3  floating   drawer, toasts, hero search tray                                  */

@property --lit { syntax: "<number>"; inherits: false; initial-value: 0; }

/* ---------- Tokens ---------- */
:root {
  /* Aurora colours as RGB triplets so alpha can be mixed: rgb(var(--au-1) / .3) */
  --au-1: 99 56 207;    /* signal violet, the brand */
  --au-2: 214 220 232;   /* mist gray */
  --au-3: 150 120 235;   /* lavender */
  --au-4: 176 186 204;    /* mist slate */
  --au-k: .72;          /* aurora strength: calmer on light */

  --bg: #e8ebf1;
  --glass-1: rgb(250 251 254 / .52);
  --glass-2: rgb(250 251 254 / .68);
  --glass-3: rgb(250 251 254 / .82);
  --glass-hi: rgb(255 255 255 / .85);          /* inner top highlight */
  --rim-top: rgb(255 255 255 / .95);
  --rim-side: rgb(255 255 255 / .55);
  --rim-bottom: rgb(255 255 255 / .26);
  --glass-blur-1: 20px;
  --glass-blur-2: 28px;
  --glass-blur-3: 38px;
  --glass-sat: 1.7;
  --lit-color: 255 255 255;
  --lit-k: .55;

  --panel: var(--glass-1);
  --panel-strong: var(--glass-2);
  --panel-border: rgb(255 255 255 / .6);
  --field: rgb(255 255 255 / .82);

  --glow: 0 10px 28px -6px rgb(var(--au-1) / .45);
  --shadow-sm: 0 1px 2px rgb(30 30 64 / .06), 0 4px 14px rgb(30 30 64 / .06);
  --shadow:    0 2px 4px rgb(30 30 64 / .05), 0 14px 36px -4px rgb(30 30 64 / .13), 0 40px 70px -30px rgb(var(--au-1) / .22);
  --shadow-lg: 0 6px 14px rgb(30 30 64 / .08), 0 30px 64px -8px rgb(30 30 64 / .22), 0 60px 110px -40px rgb(var(--au-3) / .22);
}

:root[data-theme="dark"] {
  --au-k: 1;
  --bg: #0c0b13;
  --glass-1: rgb(26 24 40 / .50);
  --glass-2: rgb(32 30 48 / .62);
  --glass-3: rgb(40 37 58 / .82);
  --glass-hi: rgb(255 255 255 / .09);
  --rim-top: rgb(255 255 255 / .22);
  --rim-side: rgb(255 255 255 / .09);
  --rim-bottom: rgb(255 255 255 / .03);
  --lit-color: 200 185 245;
  --lit-k: .12;

  --panel: var(--glass-1);
  --panel-strong: var(--glass-2);
  --panel-border: rgb(255 255 255 / .09);
  --field: rgb(14 12 24 / .62);

  --glow: 0 10px 30px -6px rgb(var(--au-1) / .5);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .45), 0 6px 16px rgb(0 0 0 / .25);
  --shadow:    0 2px 4px rgb(0 0 0 / .35), 0 16px 40px -4px rgb(0 0 0 / .45), 0 40px 80px -30px rgb(var(--au-1) / .18);
  --shadow-lg: 0 8px 18px rgb(0 0 0 / .45), 0 32px 70px -8px rgb(0 0 0 / .6), 0 60px 120px -40px rgb(var(--au-3) / .2);
}

::selection { background: rgb(var(--au-1) / .3); }

/* ---------- Aurora sky (depth 0) ---------- */
body { background-color: var(--bg); background-image: none; }
body::before, body::after { content: ""; position: fixed; z-index: -1; pointer-events: none; }

/* Drifting glow field */
body::before {
  inset: -30% -20% auto -20%; height: 130vh;
  background:
    radial-gradient(38% 52% at 16% 32%, rgb(var(--au-1) / calc(.60 * var(--au-k))), transparent 72%),
    radial-gradient(34% 48% at 50% 10%, rgb(var(--au-2) / calc(.44 * var(--au-k))), transparent 72%),
    radial-gradient(36% 52% at 86% 30%, rgb(var(--au-3) / calc(.42 * var(--au-k))), transparent 72%),
    radial-gradient(28% 38% at 68% 72%, rgb(var(--au-4) / calc(.24 * var(--au-k))), transparent 72%);
  animation: au-drift 54s ease-in-out infinite alternate;
}
/* Vertical curtains: two uneven ray patterns, faded toward the bottom */
body::after {
  inset: 0 -6% auto -6%; height: 72vh;
  background:
    repeating-linear-gradient(96deg, transparent 0 58px, rgb(var(--au-1) / calc(.20 * var(--au-k))) 104px, rgb(var(--au-2) / calc(.12 * var(--au-k))) 132px, transparent 188px),
    repeating-linear-gradient(101deg, transparent 0 131px, rgb(var(--au-3) / calc(.12 * var(--au-k))) 190px, transparent 262px);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / .55) 42%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, rgb(0 0 0 / .55) 42%, transparent 100%);
  transform-origin: 50% 0;
  animation: au-sway 38s ease-in-out infinite alternate;
}
@keyframes au-drift {
  from { transform: translate3d(-2%, 0, 0) rotate(-1.5deg); }
  to   { transform: translate3d(3%, 4%, 0) rotate(1.5deg); }
}
@keyframes au-sway {
  from { transform: translateX(-1.5%) skewX(-3deg); opacity: .8; }
  to   { transform: translateX(1.5%) skewX(3deg); opacity: 1; }
}

/* ---------- Glass recipe (depth 1) ---------- */
.panel, .stat, .footer {
  background-color: var(--glass-1);
  -webkit-backdrop-filter: blur(var(--glass-blur-1)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur-1)) saturate(var(--glass-sat));
}
.nav-user { background-color: var(--glass-1); }  /* lives inside the blurred sidebar: no second blur */
/* Directional rim light: bright top edge, soft bottom edge */
.panel, .stat, .nav-user, .footer, .card, .auth-card, .alert, .chip, .icon-btn, .pagination a, .pagination span, .role-picker label {
  border-color: var(--rim-top) var(--rim-side) var(--rim-bottom) var(--rim-side);
}
/* Pointer light: spatial.js writes --mx/--my; hover raises --lit (animated through @property) */
.panel, .stat:not(.stat-accent), .card, .auth-card, .nav-user {
  background-image: radial-gradient(300px circle at var(--mx, 50%) var(--my, -30%), rgb(var(--lit-color) / calc(var(--lit) * var(--lit-k))), transparent 65%);
  transition: --lit .4s var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.panel:hover, .stat:hover, .card:hover, .auth-card:hover, .nav-user:hover { --lit: 1; }
.panel { box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow); }
.stat:not(.stat-accent) { box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-sm); }
.stat-accent { box-shadow: var(--glow), inset 0 1px 0 rgb(255 255 255 / .28); }
.nav-user { box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-sm); }
.footer { border: 1px solid; border-radius: var(--radius-lg); box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-sm); }
.panel-sunken { box-shadow: inset 0 1px 3px rgb(30 30 64 / .08); }

/* ---------- Raised glass (depth 2) ---------- */
.topbar {
  background: var(--glass-2);
  -webkit-backdrop-filter: blur(var(--glass-blur-2)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur-2)) saturate(var(--glass-sat));
  border-bottom-color: var(--rim-bottom);
  box-shadow: inset 0 -1px 0 rgb(var(--au-1) / .22), 0 10px 30px -14px rgb(30 30 64 / .28);
}
.card { background-color: var(--glass-2); box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-sm); }
.card:hover { box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-lg); }
.card-badges .badge-muted { background: rgb(255 255 255 / .78); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.card-badges .badge-verified { box-shadow: 0 4px 14px -4px rgb(var(--au-trust) / .6), inset 0 1px 0 rgb(255 255 255 / .3); }
.fav-btn { -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.chip, .icon-btn, .pagination a, .pagination span {
  background-color: var(--glass-2);
  box-shadow: inset 0 1px 0 var(--glass-hi);
}
.icon-btn:hover, .btn-secondary:hover { background-color: var(--glass-3); }
.btn-secondary { background-color: var(--glass-2); box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-sm); }

/* ---------- Floating glass (depth 3) ---------- */
.alert {
  background: var(--glass-3);
  -webkit-backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
  box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-lg);
}

/* ---------- Controls ---------- */
.btn-primary {
  background: linear-gradient(135deg, #7d57e6 0%, #4b27a8 100%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .28), var(--glow);
}
.btn-primary:hover { background: linear-gradient(135deg, #6a43d4 0%, #3d1f8a 100%); }
:root[data-theme="dark"] .btn-primary { background: linear-gradient(135deg, #b79cff 0%, #9a78f2 100%); }
:root[data-theme="dark"] .btn-primary:hover { background: linear-gradient(135deg, #c4adff 0%, #a98bff 100%); }
.btn-gold { box-shadow: inset 0 1px 0 rgb(255 255 255 / .4), 0 10px 26px -8px rgb(var(--au-4) / .55); }
.input, .field input[type="text"], .field input[type="email"], .field input[type="password"], .field input[type="number"],
.field input[type="date"], .field input[type="url"], .field input[type="tel"], .field select, .field textarea, select.input {
  box-shadow: inset 0 1px 2px rgb(30 30 64 / .08);
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 4px rgb(var(--au-1) / .22), 0 8px 24px -8px rgb(var(--au-1) / .35);
}
.nav-link[aria-current="page"] {
  background: var(--glass-3);
  box-shadow: inset 0 1px 0 var(--glass-hi), 0 0 0 1px rgb(var(--au-1) / .28), 0 8px 22px -8px rgb(var(--au-1) / .5);
}
.avatar { box-shadow: inset 0 1px 0 rgb(255 255 255 / .35), 0 0 0 2px rgb(255 255 255 / .55), 0 6px 16px -4px rgb(var(--au-1) / .5); }
:root[data-theme="dark"] .avatar { box-shadow: inset 0 1px 0 rgb(255 255 255 / .3), 0 0 0 2px rgb(255 255 255 / .12), 0 6px 18px -4px rgb(var(--au-1) / .55); }

/* ---------- Night-sky panels: hero and auth side share one recipe ---------- */
.hero, .auth-side,
:root[data-theme="dark"] .hero {
  background:
    radial-gradient(70% 90% at 12% 110%, rgb(var(--au-1) / .40), transparent 70%),
    linear-gradient(160deg, #03151b 0%, #062a2c 52%, #0b2230 100%);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgb(255 255 255 / .16);
}
.hero::before, .auth-side::before {
  inset: -20% -10% 0 -10%;
  background:
    radial-gradient(34% 55% at 20% 38%, rgb(var(--au-1) / .62), transparent 72%),
    radial-gradient(30% 50% at 52% 14%, rgb(var(--au-2) / .46), transparent 72%),
    radial-gradient(34% 55% at 84% 34%, rgb(var(--au-3) / .46), transparent 72%),
    radial-gradient(26% 36% at 78% 86%, rgb(var(--au-4) / .30), transparent 72%);
  animation: au-drift 40s ease-in-out infinite alternate;
  translate: calc(var(--px, 0) * -16px) calc(var(--py, 0) * -10px);
  transition: translate .3s ease-out;
}
.hero::after, .auth-side::after {
  content: ""; position: absolute; inset: -5% -8% 30% -8%; pointer-events: none;
  background:
    repeating-linear-gradient(97deg, transparent 0 44px, rgb(var(--au-2) / .22) 84px, rgb(var(--au-1) / .16) 108px, transparent 150px),
    repeating-linear-gradient(103deg, transparent 0 109px, rgb(var(--au-3) / .16) 160px, transparent 226px);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 92%);
  mask-image: linear-gradient(to bottom, #000 0%, transparent 92%);
  animation: au-sway 30s ease-in-out infinite alternate;
  translate: calc(var(--px, 0) * 10px) calc(var(--py, 0) * 6px);
  transition: translate .3s ease-out;
}
.hero > *, .auth-side > * { position: relative; z-index: 1; }
.hero .eyebrow { color: #d5dbe8; }

/* Hero: search tray and stats float closer to the viewer */
.hero-search {
  background: rgb(255 255 255 / .12);
  border-color: rgb(255 255 255 / .55) rgb(255 255 255 / .22) rgb(255 255 255 / .12) rgb(255 255 255 / .22);
  -webkit-backdrop-filter: blur(var(--glass-blur-3)) saturate(1.8);
  backdrop-filter: blur(var(--glass-blur-3)) saturate(1.8);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .4), 0 28px 60px -20px rgb(0 0 0 / .55);
  translate: calc(var(--px, 0) * 6px) calc(var(--py, 0) * 4px);
  transition: translate .3s ease-out;
}
.hero-stats { gap: var(--s-4); }
.hero-stats div {
  min-width: 150px; padding: 14px 20px; border-radius: 20px; color: rgb(255 255 255 / .82);
  background: rgb(255 255 255 / .09); border: 1px solid; border-color: rgb(255 255 255 / .35) rgb(255 255 255 / .14) rgb(255 255 255 / .08) rgb(255 255 255 / .14);
  -webkit-backdrop-filter: blur(var(--glass-blur-2)) saturate(1.6); backdrop-filter: blur(var(--glass-blur-2)) saturate(1.6);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .22), 0 18px 36px -18px rgb(0 0 0 / .6);
  transition: translate .3s ease-out;
}
.hero-stats div:nth-child(1) { translate: calc(var(--px, 0) * 10px) calc(var(--py, 0) * 7px); }
.hero-stats div:nth-child(2) { translate: calc(var(--px, 0) * 14px) calc(var(--py, 0) * 9px); }
.hero-stats div:nth-child(3) { translate: calc(var(--px, 0) * 18px) calc(var(--py, 0) * 11px); }

/* ---------- Auth (replaces the neumorphic card with glass) ---------- */
.auth-shell, :root[data-theme="dark"] .auth-shell { background: transparent; }
.auth-card {
  background-color: var(--glass-2);
  -webkit-backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
  box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-lg);
}
.auth-card .field input, .auth-card .field select { background: var(--field); box-shadow: inset 0 1px 2px rgb(30 30 64 / .1); border-color: var(--field-border); }
.auth-card .field input:focus, .auth-card .field select:focus { border-color: var(--brand-500); box-shadow: 0 0 0 4px rgb(var(--au-1) / .22); }
.auth-card .btn-primary { box-shadow: inset 0 1px 0 rgb(255 255 255 / .28), var(--glow); }
.role-picker label {
  background: var(--glass-2); border: 1.5px solid; box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-sm);
}
.role-picker label:has(input:checked) {
  border-color: var(--brand-500); background: linear-gradient(135deg, rgb(var(--au-1) / .16), rgb(var(--au-2) / .10)), var(--glass-2);
  box-shadow: 0 0 0 4px rgb(var(--au-1) / .16), var(--shadow-sm);
}

/* ---------- Spatial motion: property cards tilt toward the pointer ---------- */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .cards .card, .cards .card:hover {
    transform: perspective(1100px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(var(--lift, 0px));
    transition: --lit .4s var(--ease), transform .16s ease-out, box-shadow var(--dur) var(--ease);
  }
  .cards .card:hover { --lift: -5px; will-change: transform; }
}

/* ---------- Desktop sidebar: a floating glass pane ---------- */
@media (min-width: 761px) {
  .has-sidebar .sidebar {
    margin: 14px 0 14px 18px; top: calc(var(--topbar-h) + 14px); height: calc(100vh - var(--topbar-h) - 28px);
    border-radius: var(--radius-lg); border: 1px solid; border-color: var(--rim-top) var(--rim-side) var(--rim-bottom) var(--rim-side);
    background: var(--glass-1);
    -webkit-backdrop-filter: blur(var(--glass-blur-1)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur-1)) saturate(var(--glass-sat));
    box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-sm);
  }
}

/* ---------- Phone: glass drawer and floating tab dock ---------- */
@media (max-width: 760px) {
  body::after { height: 52vh; }
  .sidebar, .has-sidebar .sidebar {
    background: var(--glass-3);
    -webkit-backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
    border-right: 1px solid var(--rim-side);
  }
  .tabbar {
    left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right));
    bottom: calc(10px + env(safe-area-inset-bottom)); height: var(--tabbar-h); padding: 6px;
    border: 1px solid; border-color: var(--rim-top) var(--rim-side) var(--rim-bottom) var(--rim-side); border-radius: 26px;
    background: var(--glass-2);
    -webkit-backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
    backdrop-filter: blur(var(--glass-blur-3)) saturate(var(--glass-sat));
    box-shadow: inset 0 1px 0 var(--glass-hi), var(--shadow-lg);
  }
  .tabbar [aria-current="page"] { color: var(--brand-700); background: rgb(var(--au-1) / .16); box-shadow: inset 0 1px 0 var(--glass-hi); }
  body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
  .has-tabbar .form-actions { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
  .alerts { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
  .hero-stats div { min-width: 0; flex: 1 1 calc(50% - var(--s-4)); padding: 12px 14px; }
  .hero-stats div:nth-child(n) { translate: none; }
  .hero-search { translate: none; }
}

/* ---------- Fallbacks: keep text legible when glass cannot be drawn ---------- */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass-1: rgb(255 255 255 / .88); --glass-2: rgb(255 255 255 / .92); --glass-3: rgb(255 255 255 / .96); }
  :root[data-theme="dark"] { --glass-1: rgb(26 24 40 / .94); --glass-2: rgb(32 30 48 / .96); --glass-3: rgb(40 37 58 / .98); }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  :root { --glass-1: rgb(255 255 255 / .94); --glass-2: rgb(255 255 255 / .97); --glass-3: #fff; --rim-side: rgb(20 40 50 / .25); --rim-bottom: rgb(20 40 50 / .25); }
  :root[data-theme="dark"] { --glass-1: rgb(26 24 40 / .96); --glass-2: rgb(32 30 48 / .98); --glass-3: rgb(40 37 58); --rim-side: rgb(255 255 255 / .22); --rim-bottom: rgb(255 255 255 / .22); }
  .panel, .stat, .footer, .topbar, .card, .alert, .auth-card, .tabbar, .sidebar, .hero-search, .hero-stats div {
    -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
  }
  body::after { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  body::before, body::after, .hero::before, .hero::after, .auth-side::before, .auth-side::after { animation: none; }
  .hero::before, .hero::after, .auth-side::before, .auth-side::after, .hero-search, .hero-stats div { translate: none !important; transition: none; }
  .panel, .stat, .card, .auth-card, .nav-user { transition: box-shadow var(--dur) var(--ease); }
}
@media print {
  body::before, body::after, .hero::before, .hero::after, .auth-side::before, .auth-side::after { display: none; }
  .panel, .card, .stat { background-image: none !important; }
}
