/* 轻量后台 demo —— 自定义样式（配合 Pico.css，shadcn 风格：小而精致） */

/* 全局基准字号调小，整体更紧凑 */
html {
  font-size: 14px;
}

[x-cloak] {
  /* biome-ignore lint(complexity/noImportantStyles): x-cloak 必须压过一切 display 规则，防止 Alpine 初始化前闪现 */
  display: none !important;
}

:root {
  --sidebar-w: 208px;
  --sidebar-w-collapsed: 56px;
  --topbar-h: 52px;
  /* 正文色快照：Pico 会在 button 元素上把 --pico-color 重定义为主按钮白字，
     按钮里要显示普通文字（如幽灵按钮 / 下拉菜单项）须用 --text，不能直接用 --pico-color */
  --text: var(--pico-color);
  --pico-spacing: 1rem;
  --pico-border-radius: 0.5rem;
  --pico-font-weight: 400;
  /* 更紧凑的表单控件内边距 */
  --pico-form-element-spacing-vertical: 0.5rem;
  --pico-form-element-spacing-horizontal: 0.75rem;
}

/* ---------- 主题色预设（Ant Design 风格，在顶栏用户下拉切换） ---------- */
/* --accent-rgb 是 --accent 的十进制三元组，供 rgba(var(--accent-rgb), α) 做主题色
   透明底色 / 焦点环。不用 color-mix()：它是 2023 年特性（Chrome 111 / Safari 16.2 /
   Firefox 113），而预乘混 transparent 的结果与 rgba 完全等价。改 --accent 必须同步改
   --accent-rgb（同步翻转暗色 neutral 的两处亦然） */
:root {
  --accent: #3f6fd6;
  --accent-hover: #2f57b0;
  --accent-inverse: #fff;
  --accent-rgb: 63, 111, 214;
} /* 拂晓蓝（默认） */
:root[data-accent="geekblue"] {
  --accent: #4256c4;
  --accent-hover: #3140a0;
  --accent-inverse: #fff;
  --accent-rgb: 66, 86, 196;
}
:root[data-accent="cyan"] {
  --accent: #2f9c9c;
  --accent-hover: #237e7e;
  --accent-inverse: #fff;
  --accent-rgb: 47, 156, 156;
}
:root[data-accent="green"] {
  --accent: #63a343;
  --accent-hover: #4f8532;
  --accent-inverse: #fff;
  --accent-rgb: 99, 163, 67;
}
:root[data-accent="purple"] {
  --accent: #7d57c4;
  --accent-hover: #6544a6;
  --accent-inverse: #fff;
  --accent-rgb: 125, 87, 196;
}
:root[data-accent="magenta"] {
  --accent: #d75a97;
  --accent-hover: #b8437a;
  --accent-inverse: #fff;
  --accent-rgb: 215, 90, 151;
}
:root[data-accent="volcano"] {
  --accent: #e8683e;
  --accent-hover: #c9542c;
  --accent-inverse: #fff;
  --accent-rgb: 232, 104, 62;
}
:root[data-accent="neutral"] {
  --accent: #18181b;
  --accent-hover: #27272a;
  --accent-inverse: #fafafa;
  --accent-rgb: 24, 24, 27;
}

/* 把主题色映射到 Pico 主色变量（各主题作用域各写一份以覆盖 Pico 默认值） */
:root:not([data-theme="dark"]),
:root[data-theme="dark"] {
  --pico-primary: var(--accent);
  --pico-primary-background: var(--accent);
  --pico-primary-hover: var(--accent-hover);
  --pico-primary-hover-background: var(--accent-hover);
  --pico-primary-inverse: var(--accent-inverse);
  --pico-primary-focus: rgba(var(--accent-rgb), 0.3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pico-primary: var(--accent);
    --pico-primary-background: var(--accent);
    --pico-primary-hover: var(--accent-hover);
    --pico-primary-hover-background: var(--accent-hover);
    --pico-primary-inverse: var(--accent-inverse);
    --pico-primary-focus: rgba(var(--accent-rgb), 0.3);
  }
}
/* 中性色在暗色下翻转为近白 */
@media (prefers-color-scheme: dark) {
  :root[data-accent="neutral"]:not([data-theme="light"]) {
    --accent: #fafafa;
    --accent-hover: #e4e4e7;
    --accent-inverse: #18181b;
    --accent-rgb: 250, 250, 250;
  }
}
:root[data-theme="dark"][data-accent="neutral"] {
  --accent: #fafafa;
  --accent-hover: #e4e4e7;
  --accent-inverse: #18181b;
  --accent-rgb: 250, 250, 250;
}

/* 柔和的中性边框与次要文字（shadcn 质感，仅亮色）。
   注意 theme=auto 时 data-theme 属性会被整体移除，:not([data-theme="dark"]) 挡不住
   「auto + 系统深色」，会把亮色 muted 值漏进深色界面 —— 因此只命中两种浅色场景：
   显式浅色，以及「auto + 系统浅色」（深色让位给 Pico 自带的深色 token） */
:root[data-theme="light"] {
  --pico-muted-border-color: #e4e4e7;
  --pico-muted-color: #71717a;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --pico-muted-border-color: #e4e4e7;
    --pico-muted-color: #71717a;
  }
}

/* 内容区底色：比顶栏/卡片底色暗一档，让卡片有浮起感。
   浅色为浅灰；深色取 Pico 深色页面底色（#13161f），同样比卡片底(#181c25)暗一档，
   作用域与 Pico 同款：默认浅色，显式深色 + 「auto 且系统深色」时切换 */
:root {
  --content-bg: #f6f7f8;
}
:root[data-theme="dark"] {
  --content-bg: #13161f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --content-bg: #13161f;
  }
}

/* ---------- 按钮统一规范（shadcn 小尺寸） ---------- */
button:not([rel="prev"]),
[role="button"],
input[type="submit"],
input[type="button"],
input[type="reset"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: auto;
  vertical-align: middle;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  border-radius: 0.5rem;
  --pico-font-size: 13px;
}
/* 小尺寸按钮（表格行内操作、退出等） */
.btn-sm,
button.btn-sm {
  padding: 3px 10px;
  font-size: 12px;
}
/* 行内操作按钮之间的间距 */
.row-actions button + button {
  margin-left: 0.4rem;
}

/* 去掉「鼠标点击后」按钮 border 外的聚焦环：Pico 对按钮用的是 :focus（一点击就出现
   0 0 0 2px 的主题色光晕）。仅在 :focus-visible 不匹配时把 --pico-box-shadow 还原回
   普通值（Pico 靠重定义该变量画环）；键盘 Tab 聚焦仍匹配 :focus-visible，光晕保留，
   不损失无障碍 */
:is(
  button,
  [role="button"],
  [role="group"],
  input:is([type="submit"], [type="button"], [type="reset"])
):focus:not(:focus-visible) {
  --pico-box-shadow: var(
    --pico-button-hover-box-shadow,
    0 0 0 rgba(0, 0, 0, 0)
  );
}

/** 移除input/select/textarea 的默认transition **/
input,
select,
textarea {
  transition: none;
}

/**
 * 移除按钮及文件选择器的默认过渡效果
 */
[role="button"],
[type="button"],
[type="file"]::file-selector-button,
[type="reset"],
[type="submit"],
button {
  transition: none;
}

/* ---------- 图标（Lucide sprite，见 index.html 内联定义） ---------- */
/* 描边图标在同等像素下比 emoji 显得略小，默认尺寸给到 16px；
   颜色不加声明，跟随 currentColor（所在文字色/主题色） */
.icon {
  width: 16px;
  height: 16px;
  display: block;
  flex-shrink: 0;
}

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 340px;
}
.login-card hgroup {
  text-align: center;
  margin-bottom: 1.25rem;
}
.login-card .hint {
  text-align: center;
  margin-top: 0.5rem;
}
.login-card button[type="submit"] {
  width: 100%;
  margin-top: 0.25rem;
}
.err {
  color: var(--pico-del-color, #c62828);
  margin: 0.25rem 0;
}
.ok {
  color: #2e7d32;
  margin: 0.25rem 0;
}

/* ---------- 布局 ---------- */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* 顶部贯穿横条 */
.topbar {
  display: flex;
  align-items: stretch;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--pico-muted-border-color);
  background: var(--pico-card-background-color);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  border-right: 1px solid var(--pico-muted-border-color);
  overflow: hidden;
  white-space: nowrap;
}
.topbar .brand-logo {
  color: var(--pico-primary);
  flex-shrink: 0;
}
.topbar .brand-logo .icon {
  width: 18px;
  height: 18px;
}
.topbar .brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--pico-primary);
}
.topbar .page-title {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* 主体：侧边栏 + 内容 */
.body {
  display: flex;
  flex: 1;
  min-height: 0;
}
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--pico-card-background-color);
  border-right: 1px solid var(--pico-muted-border-color);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}
.sidebar nav {
  flex: 1;
  padding: 0.5rem;
}
.sidebar nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.7rem;
  font-size: 13px;
  border-radius: var(--pico-border-radius);
  text-decoration: none;
  color: var(--pico-color);
  margin-bottom: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}
.sidebar nav a .nav-icon {
  flex-shrink: 0;
}
.sidebar nav a:hover {
  background: rgba(var(--accent-rgb), 0.14);
  color: var(--pico-primary);
}
.sidebar nav a.active,
.sidebar nav a.active:hover {
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}
.side-foot {
  padding: 0.6rem;
  /* border-top: 1px solid var(--pico-muted-border-color); */
}
button.collapse-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  height: 32px;
  justify-content: flex-start;
  padding: 0.45rem 0.7rem;
  font-size: 13px;
  font-weight: 400;
  color: var(--pico-muted-color);
  background: transparent;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  white-space: nowrap;
  overflow: hidden;
}
button.collapse-btn:hover {
  color: var(--text);
  background: rgba(var(--accent-rgb), 0.08);
}
.collapse-btn .chevron {
  flex-shrink: 0;
}
.collapse-btn .chevron .icon {
  width: 14px;
  height: 14px;
}

/* 收起态：侧边栏变成图标 rail（宽度收成图标档 token） */
.shell.sidebar-collapsed {
  --sidebar-w: var(--sidebar-w-collapsed);
}
.sidebar-collapsed .brand-name,
.sidebar-collapsed .sidebar nav a .nav-label,
.sidebar-collapsed .collapse-btn .nav-label {
  display: none;
}
.sidebar-collapsed .topbar .brand,
.sidebar-collapsed .sidebar nav a,
.sidebar-collapsed button.collapse-btn {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
  gap: 0;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0 1.25rem;
}

/* 用户下拉菜单 */
.user-menu {
  position: relative;
}
.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 4px 10px;
  margin: 0;
  width: auto;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: var(--pico-border-radius);
  cursor: pointer;
}
/* 悬停与侧边栏导航同款：主题色淡底 + 主题色文字（深浅色自适应） */
.user-trigger:hover {
  background: rgba(var(--accent-rgb), 0.14);
  color: var(--pico-primary);
}
.user-trigger .user-icon .icon {
  width: 15px;
  height: 15px;
}
.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  min-width: 250px;
  padding: 6px;
  background: var(--pico-background-color);
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.user-dropdown .user-meta {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 6px 8px 8px;
}
.user-meta .meta-label {
  font-size: 12px;
  color: var(--pico-muted-color);
}
.user-meta .meta-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.user-dropdown hr {
  margin: 0 0 6px;
  border: none;
  border-top: 1px solid var(--pico-muted-border-color);
}
.user-dropdown .menu-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.45rem;
  width: 100%;
  padding: 6px 8px;
  margin: 0;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.user-dropdown .menu-item:hover {
  background: rgba(var(--accent-rgb), 0.14);
  color: var(--pico-primary);
}
.user-dropdown .menu-item .icon {
  width: 14px;
  height: 14px;
}

/* 用户下拉 · 外观偏好（主题/主题色是个人设置，见 app.js 的 prefs） */
.user-dropdown .pref-block {
  padding: 2px 4px 8px;
}
.user-dropdown .pref-block + .pref-block {
  padding-top: 0;
}
.user-dropdown .pref-label {
  display: block;
  padding: 0 4px 6px;
  font-size: 12px;
  color: var(--pico-muted-color);
}
/* 主题三选一分段控件（跟随系统/浅色/深色），选中态与侧栏导航同款主题色淡底 */
.theme-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.theme-seg button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  padding: 7px 2px 6px;
  font-size: 11px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 6px;
  cursor: pointer;
}
.theme-seg button:hover,
.theme-seg button.active {
  color: var(--pico-primary);
  background: rgba(var(--accent-rgb), 0.12);
  border-color: rgba(var(--accent-rgb), 0.45);
}
.theme-seg button.active {
  background: rgba(var(--accent-rgb), 0.16);
}
.theme-seg button .icon {
  width: 15px;
  height: 15px;
}
/* 主题色圆点（22px 一行刚好放下 8 个预设） */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 4px;
}
button.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  background: var(--sw);
  border: 2px solid var(--pico-card-background-color);
  box-shadow: 0 0 0 1px var(--pico-muted-border-color);
  cursor: pointer;
  transition:
    box-shadow 0.15s ease,
    transform 0.1s ease;
}
button.swatch:hover {
  transform: scale(1.1);
}
button.swatch.active {
  box-shadow: 0 0 0 2px var(--sw);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 1.25rem;
  background-color: var(--content-bg);
}

/* ---------- 统计卡片 ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.card {
  margin: 0;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.card small {
  color: var(--pico-muted-color);
  font-size: 12px;
}
.card strong {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.card.accent {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
}
.card.accent small {
  color: var(--pico-primary-inverse);
  opacity: 0.85;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* 柱状图 */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 0.8rem;
  height: 200px;
  padding-top: 1rem;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 0.4rem;
}
.bar {
  width: 100%;
  max-width: 40px;
  background: var(--pico-primary);
  border-radius: 4px 4px 0 0;
  position: relative;
  transition: height 0.4s ease;
  min-height: 4px;
}
.bar::after {
  content: attr(data-val);
  position: absolute;
  top: -1.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  white-space: nowrap;
  color: var(--pico-muted-color);
  opacity: 0;
  transition: opacity 0.2s;
}
.bar-col:hover .bar::after {
  opacity: 1;
}

/* 分类分布 */
.dist {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding-top: 1rem;
}
.dist-row {
  display: grid;
  grid-template-columns: 3rem 1fr 2rem;
  align-items: center;
  gap: 0.6rem;
}
.dist-track {
  background: var(--pico-secondary-background);
  border-radius: 1rem;
  height: 0.8rem;
  overflow: hidden;
}
.dist-fill {
  height: 100%;
  background: var(--pico-primary);
  border-radius: 1rem;
  transition: width 0.4s ease;
}

/* ---------- 数据表格 ---------- */
.toolbar {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.toolbar .search {
  flex: 1;
  min-width: 200px;
  margin: 0;
}
.toolbar select {
  width: auto;
  margin: 0;
}
.toolbar button {
  width: auto;
  margin: 0;
  white-space: nowrap;
}
table {
  font-size: 13px;
}
th {
  font-size: 12px;
  font-weight: 600;
  color: var(--pico-muted-color);
  text-transform: none;
}
.readonly-tip {
  color: var(--pico-muted-color);
  font-size: 12px;
}

/* ---------- 设置 ---------- */
.settings-card {
  max-width: 480px;
}
.settings-card form > label {
  margin-bottom: 1.1rem;
}
/* 动作区：与表单内容明显分隔 */
.settings-card .form-actions {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--pico-muted-border-color);
}
.settings-card .form-actions button {
  margin: 0;
}
/* ---------- SweetAlert2 弹窗 / 提示 ---------- */
/* 中央确认框：简洁的淡入 + 轻微上浮 */
.swal2-popup.swal2-show {
  animation: swal-in 0.18s ease-out;
}
.swal2-popup.swal2-hide {
  animation: swal-out 0.14s ease-in;
}
.swal2-container.swal2-backdrop-show {
  animation: swal-backdrop 0.18s ease-out;
}
@keyframes swal-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes swal-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: scale(0.98);
  }
}
@keyframes swal-backdrop {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 右上角 toast：从右侧丝滑滑入（覆盖 SweetAlert 默认的左右摇动画） */
.swal2-container .swal2-toast.swal2-show {
  animation: toast-in 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}
.swal2-container .swal2-toast.swal2-hide {
  animation: toast-out 0.18s ease-in;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes toast-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* ---------- 原生弹窗（新增 / 编辑商品）---------- */
/* 遮罩层颜色/透明度：改最后一个数字（0~1）即不透明度 */
dialog.app-modal {
  --pico-modal-overlay-background-color: rgba(24, 24, 27, 0.65);
  /* 背景模糊：改 blur() 里的值，越大越糊；不要模糊写 none */
  --pico-modal-overlay-backdrop-filter: blur(2px);
}
dialog.app-modal article {
  max-width: 480px;
}
dialog.app-modal footer {
  display: flex;
  gap: 0.8rem;
  justify-content: flex-end;
}
dialog.app-modal footer button {
  margin: 0;
}
/* 进入动画：遮罩淡入 + 卡片轻微上浮 */
dialog.app-modal[open] {
  animation: modal-overlay 0.18s ease-out;
}
dialog.app-modal[open] > article {
  animation: modal-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modal-overlay {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes modal-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog.app-modal[open],
  dialog.app-modal[open] > article,
  .swal2-popup.swal2-show,
  .swal2-popup.swal2-hide,
  .swal2-container.swal2-backdrop-show,
  .swal2-container .swal2-toast.swal2-show,
  .swal2-container .swal2-toast.swal2-hide {
    animation: none;
  }
}
