/* ============================================================
   Moonwhisper Finance — "nocturnal control room" design system
   Dark canvas · purple accent · glass cards · mono figures
   ============================================================ */

:root {
  /* surfaces */
  --ink:        #0f0d17;
  --ink-2:      #14111e;
  --surface:    #1b1828;
  --surface-2:  #221e33;
  --surface-3:  #2a2540;
  --line:        rgba(181,128,255,.13);
  --line-strong: rgba(181,128,255,.24);

  /* text */
  --text:     #ece9f6;
  --text-dim: #b4adca;
  --muted:    #8b84a3;

  /* brand */
  --purple:        #b580ff;
  --purple-2:      #9a6cf0;
  --purple-bright: #cdb2ff;
  --glow:          rgba(181,128,255,.30);

  /* semantic */
  --ok:     #5fe3ad;  --ok-bg:     rgba(95,227,173,.12);
  --danger: #ff6f86;  --danger-bg: rgba(255,111,134,.12);
  --warn:   #ffce73;  --warn-bg:   rgba(255,206,115,.12);

  /* type */
  --font-display: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --font-body:    "Hanken Grotesk", system-ui, -apple-system, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, "SFMono-Regular", monospace;

  --radius:   16px;
  --radius-sm: 10px;
  --shadow:   0 18px 40px -22px rgba(0,0,0,.85);
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- atmospheric background --- */
.bg-atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 600px at 88% -8%, rgba(181,128,255,.16), transparent 60%),
    radial-gradient(700px 500px at -6% 12%, rgba(122,86,210,.12), transparent 55%),
    radial-gradient(1200px 800px at 50% 120%, rgba(95,70,160,.10), transparent 60%),
    var(--ink);
}
.bg-atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(181,128,255,.05) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at 50% 35%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 50% 35%, #000 0%, transparent 78%);
}

a { color: var(--purple-bright); text-decoration: none; }
a:hover { color: var(--purple); }

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -.01em; color: var(--text); line-height: 1.15; }
h1 { font-size: 1.7rem; margin: 0 0 .35rem; }
h2 { font-size: 1.15rem; margin: 0 0 .9rem; }

/* ============================================================
   App shell — sidebar + content
   ============================================================ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 1.1rem .85rem 1rem;
  background: linear-gradient(180deg, rgba(34,30,51,.72), rgba(20,17,30,.72));
  border-right: 1px solid var(--line);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: .65rem; padding: .35rem .5rem 1.1rem; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  background: radial-gradient(circle at 35% 30%, rgba(181,128,255,.30), rgba(181,128,255,.06));
  border: 1px solid var(--line-strong);
  box-shadow: 0 0 22px -6px var(--glow);
  flex: none;
}
.brand-mark img { width: 30px; height: 30px; object-fit: contain; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.06rem; color: var(--text); letter-spacing: -.01em; }
.brand-sub { font-size: .66rem; letter-spacing: .22em; text-transform: uppercase; color: var(--purple); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: .25rem; }
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500; font-size: .92rem;
  transition: background .16s, color .16s;
}
.nav-link svg { width: 19px; height: 19px; flex: none; opacity: .9; }
.nav-link:hover { background: rgba(181,128,255,.08); color: var(--text); }
.nav-link.active { background: linear-gradient(90deg, rgba(181,128,255,.20), rgba(181,128,255,.06)); color: var(--purple-bright); }
.nav-link.active::before {
  content: ""; position: absolute; left: -.85rem; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; border-radius: 0 3px 3px 0;
  background: var(--purple); box-shadow: 0 0 12px var(--glow);
}

.sidebar-foot { margin-top: auto; padding-top: .75rem; }
.user-card {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(20,17,30,.5);
}
.user-avatar {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  font-family: var(--font-display); font-weight: 800; font-size: .95rem; color: #fff;
  background: linear-gradient(135deg, var(--purple), var(--purple-2));
  box-shadow: 0 0 16px -4px var(--glow);
}
.user-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.user-name { font-size: .85rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0; flex: none;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  color: var(--muted); cursor: pointer; transition: all .15s; box-shadow: none;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); transform: none; box-shadow: none; }

.content { flex: 1; margin-left: var(--sidebar-w); min-width: 0; }
.content-inner { max-width: 1180px; margin: 0 auto; padding: 2.2rem 2.4rem 4rem; }

/* page-load stagger */
.content-inner > * { animation: rise .5s cubic-bezier(.2,.7,.3,1) both; }
.content-inner > *:nth-child(2){ animation-delay:.04s } .content-inner > *:nth-child(3){ animation-delay:.08s }
.content-inner > *:nth-child(4){ animation-delay:.12s } .content-inner > *:nth-child(5){ animation-delay:.16s }
.content-inner > *:nth-child(n+6){ animation-delay:.2s }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .content-inner > * { animation: none; } }

/* ============================================================
   Cards, grids, stats
   ============================================================ */
.card {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
  margin-bottom: 1.3rem;
  box-shadow: var(--shadow);
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.1rem; margin-bottom: 1.3rem; }
.grid .card { margin-bottom: 0; }

.muted { color: var(--muted); }
.muted-label { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

.stat { font-family: var(--font-mono); font-weight: 700; font-size: 1.95rem; letter-spacing: -.02em; color: var(--text); margin-top: .35rem; }
.stat.pos { color: var(--ok); } .stat.neg { color: var(--danger); }

a.card { display: block; transition: transform .16s, border-color .16s, box-shadow .16s; }
a.card:hover { transform: translateY(-3px); border-color: var(--line-strong); box-shadow: 0 22px 44px -22px rgba(0,0,0,.9), 0 0 0 1px var(--line-strong); }
a.card h2 { color: var(--purple-bright); }

/* ============================================================
   Tables
   ============================================================ */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.card { padding: .3rem 1.2rem; overflow: hidden; }
th {
  text-align: left; padding: .85rem .55rem;
  font: 600 .7rem/1 var(--font-body); letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
td { padding: .82rem .55rem; border-bottom: 1px solid var(--line); color: var(--text-dim); vertical-align: middle; }
tbody tr { transition: background .14s; }
tbody tr:hover td { background: rgba(181,128,255,.045); }
tbody tr:last-child td { border-bottom: 0; }
th.right, td.right { text-align: right; }
td.right { font-family: var(--font-mono); font-weight: 600; color: var(--text); letter-spacing: -.01em; }
td.right.pos { color: var(--ok); } td.right.neg { color: var(--danger); }
td .muted { color: var(--muted); }

/* compact buttons / links inside table rows */
td.actions { white-space: nowrap; }
td .inline { display: inline; }
td button {
  padding: .34rem .6rem; font-size: .8rem; font-weight: 600;
  background: rgba(181,128,255,.10); color: var(--purple-bright);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: none;
}
td button:hover { background: rgba(181,128,255,.2); color: #fff; box-shadow: none; transform: none; }
td.actions a { font-size: .82rem; font-weight: 600; padding: .1rem .25rem; }

/* ============================================================
   Forms & buttons
   ============================================================ */
.form label { display: block; margin-bottom: 1rem; font-size: .82rem; font-weight: 600; color: var(--text-dim); }
.form input, .form select {
  display: block; width: 100%; margin-top: .4rem;
  padding: .6rem .7rem;
  font-family: var(--font-body); font-size: .95rem; color: var(--text);
  background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.form input::placeholder { color: #5d566f; }
.form input:focus, .form select:focus {
  outline: none; border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(181,128,255,.18);
}
.form select { appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 1rem center, right .75rem center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

button {
  font-family: var(--font-body); font-weight: 600; font-size: .9rem;
  color: #fff; cursor: pointer;
  background: linear-gradient(135deg, var(--purple), var(--purple-2));
  border: 0; padding: .6rem 1.05rem; border-radius: var(--radius-sm);
  box-shadow: 0 10px 24px -12px var(--glow);
  transition: transform .14s, box-shadow .14s, filter .14s;
}
button:hover { transform: translateY(-1px); box-shadow: 0 14px 30px -12px var(--glow); filter: brightness(1.05); }
button:active { transform: translateY(0); }
.btn-block { width: 100%; padding: .7rem; margin-top: .4rem; }
.inline { display: inline; }

/* ============================================================
   Badges, flashes, page header rows
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .55rem; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  border: 1px solid var(--line-strong);
}
.badge-role { color: var(--purple-bright); background: rgba(181,128,255,.12); }
.badge-ok { color: var(--ok); background: var(--ok-bg); border-color: rgba(95,227,173,.3); }
.badge-warn { color: var(--warn); background: var(--warn-bg); border-color: rgba(255,206,115,.3); }
.badge-danger { color: var(--danger); background: var(--danger-bg); border-color: rgba(255,111,134,.3); }
.badge-muted { color: var(--muted); background: rgba(139,132,163,.1); }

.flash { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-size: .9rem; font-weight: 500; border: 1px solid transparent; }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(255,111,134,.3); }
.flash-ok { background: var(--ok-bg); color: var(--ok); border-color: rgba(95,227,173,.3); }

.actions { display: flex; gap: .55rem; align-items: center; }
.right { text-align: right; }
.pos { color: var(--ok); } .neg { color: var(--danger); }

/* a page header row */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; }
.page-head h1 { margin: 0; }

/* ============================================================
   Auth / login
   ============================================================ */
.auth-main { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.auth-card {
  display: grid; grid-template-columns: 1.05fr 1fr;
  width: 100%; max-width: 940px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: 22px; overflow: hidden;
  box-shadow: 0 40px 90px -40px #000;
}
.auth-brand {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem 2rem;
  background: linear-gradient(160deg, rgba(122,86,210,.28), rgba(20,17,30,.2));
  border-right: 1px solid var(--line);
}
.auth-brand-glow { position: absolute; width: 360px; height: 360px; top: -60px; right: -90px; border-radius: 50%;
  background: radial-gradient(circle, var(--glow), transparent 65%); filter: blur(10px); }
.auth-mascot { position: relative; width: 132px; height: auto; filter: drop-shadow(0 14px 30px rgba(0,0,0,.5)); animation: float 6s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.auth-wordmark { position: relative; display: flex; flex-direction: column; align-items: center; line-height: .92; margin-top: 1.1rem; }
.auth-word-1, .auth-word-2 { font-family: var(--font-display); font-weight: 800; letter-spacing: .02em; color: var(--text); }
.auth-word-1 { font-size: 2rem; }
.auth-word-2 { font-size: 2rem; color: var(--purple); }
.auth-tagline { position: relative; margin: 1rem 0 0; text-align: center; color: var(--text-dim); font-size: .88rem; max-width: 18rem; }

.auth-form-side { padding: 3rem 2.6rem; display: flex; flex-direction: column; justify-content: center; }
.auth-title { margin: 0; }
.auth-subtitle { margin: .2rem 0 1.6rem; color: var(--muted); font-size: .92rem; }
.auth-main h1 { font-size: 2rem; }

/* ============================================================
   Responsive — collapse sidebar to an icon rail
   ============================================================ */
@media (max-width: 1040px) {
  :root { --sidebar-w: 74px; }
  .brand-text, .nav-link span, .user-meta { display: none; }
  .brand { justify-content: center; padding: .35rem 0 1.1rem; }
  .nav-link { justify-content: center; padding: .65rem 0; }
  .user-card { justify-content: center; padding: .45rem; }
  .content-inner { padding: 1.6rem 1.3rem 3rem; }
}
@media (max-width: 720px) {
  .auth-card { grid-template-columns: 1fr; max-width: 420px; }
  .auth-brand { padding: 2.2rem 1.5rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .auth-form-side { padding: 2rem 1.6rem 2.4rem; }
  h1 { font-size: 1.45rem; }
}
