<script setup lang="ts">
// Floating cosmetic-tweaks panel. Lives in the bottom-right corner. Quick
// theme + density toggle without leaving the page. The env badge is NOT
// here — it's derived from the hostname (see useEnv) so the operator can
// trust it as a real environment signal, not a sticker they flipped.

const { state, setTheme, setDensity } = useTweaks()
const open = ref(false)
</script>

<template>
  <div class="tweaks-root">
    <button class="trigger" :class="{ on: open }" type="button" :title="open ? 'Close tweaks' : 'Open tweaks'" @click="open = !open">
      <UiIcon :name="open ? 'x' : 'shield'" :size="14" />
    </button>

    <Transition name="tweaks">
      <div v-if="open" class="panel" role="dialog" aria-label="Cosmetic tweaks">
        <header>
          <Eyebrow>Tweaks</Eyebrow>
          <button class="x" type="button" aria-label="Close" @click="open = false">
            <UiIcon name="x" :size="11" />
          </button>
        </header>

        <section>
          <label class="row-label">Theme</label>
          <div class="seg">
            <button :class="{ on: state.theme === 'dark' }" type="button" @click="setTheme('dark')">Dark</button>
            <button :class="{ on: state.theme === 'light' }" type="button" @click="setTheme('light')">Light</button>
          </div>
        </section>

        <section>
          <label class="row-label">Density</label>
          <div class="seg">
            <button :class="{ on: state.density === 'comfy' }" type="button" @click="setDensity('comfy')">Comfy</button>
            <button :class="{ on: state.density === 'compact' }" type="button" @click="setDensity('compact')">Compact</button>
          </div>
        </section>

        <footer>
          <Mono dim>// cosmetic only — saved to localStorage</Mono>
        </footer>
      </div>
    </Transition>
  </div>
</template>

<style scoped>
.tweaks-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
}

.trigger {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.trigger:hover { color: var(--text); border-color: var(--border-hi); }
.trigger.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.panel {
  position: absolute;
  right: 0;
  bottom: 44px;
  width: 260px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.32);
}

header { display: flex; justify-content: space-between; align-items: center; }
.x {
  width: 22px;
  height: 22px;
  border: 0;
  background: transparent;
  color: var(--text-mute);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.x:hover { background: var(--surface); color: var(--text); }

section { display: flex; flex-direction: column; gap: 6px; }
.row-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-mute);
  font-weight: 500;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--text); color: var(--bg); }

footer { padding-top: 4px; border-top: 1px dashed var(--border); }

.tweaks-enter-active, .tweaks-leave-active { transition: opacity 0.12s, transform 0.12s; }
.tweaks-enter-from, .tweaks-leave-to { opacity: 0; transform: translateY(4px); }
</style>
