/* =====================================================
 * Koven 共享底座 · 设计令牌
 * 单一源：shared/web/koven-tokens.css
 * 请勿直接修改各站 shared/ 下的副本。
 * =====================================================
 *
 * 这是三站全部视觉的唯一来源。
 *
 * 【为什么用 CSS 变量而不是给每个类加 dark: 前缀】
 * 三站前端共有约 1270 行硬编码颜色类、10800 次类名使用，
 * 且这些 class 是 JS 字符串（h('div', { class: 'bg-white ...' })）而非 HTML 属性。
 * 逐个加 dark: 意味着 3000+ 处改动、三份重复、必然遗漏，
 * 而且此后每写一行 UI 都要写双份。
 *
 * 改用语义令牌后：业务代码只写 bg-surface / text-ink，
 * 深浅色切换只是把根元素上的一组变量换掉，业务代码零 dark: 前缀。
 * 以后换品牌色、加第三套主题，都只改这个文件。
 *
 * 【与 Tailwind 的关系】
 * 语义色通过 tailwind.config 注册成 bg-surface / text-ink 这样的类，
 * 因此 Tailwind 的响应式与状态变体（sm: / hover: / disabled:）依然可用。
 * 本文件必须在 Tailwind 之前加载：这样首帧就有正确的底色，不会闪白。
 */

/* -----------------------------------------------------
 * 1) 浅色（默认）
 * --------------------------------------------------- */
:root {
  color-scheme: light;

  /* 表面层级：从页面底色到浮层，明度逐级抬升。
   * 【纯中性灰】刻意不带任何色相倾向（R=G=B），不用冷调蓝灰也不用暖调。
   * 好处：账本金额的红绿、健康指标的异常色、资产分类的标签色
   * 都不会被背景的色相干扰，语义色的辨识度最高。 */
  --c-app:        #F7F7F7;   /* 页面底 */
  --c-surface:    #FFFFFF;   /* 卡片 */
  --c-elevated:   #FFFFFF;   /* 弹窗 / 下拉等浮层 */
  --c-subtle:     #F0F0F0;   /* 次级填充：表头、标签、hover 底 */
  --c-border:     #E4E4E4;
  --c-border-strong: #D0D0D0;

  /* 文字：三级对比度，同样纯中性 */
  --c-ink:        #171717;   /* 主文字 */
  --c-ink-2:      #525252;   /* 次要文字 */
  --c-muted:      #A0A0A0;   /* 弱化文字、占位符 */

  /* 品牌：唯一保留色相的强调色，用作点缀（主按钮、当前导航项、聚焦态） */
  --c-brand:      #2563EB;
  --c-brand-hover:#1D4ED8;
  --c-brand-soft: #F2F6FE;   /* 品牌色浅底，饱和度压到很低 */
  --c-on-brand:   #FFFFFF;   /* 品牌底上的文字 */
  --c-ring:       rgba(37, 99, 235, .26);  /* 聚焦光晕 */

  /* 语义 —— 这些是【功能色】，必须保留色相。
   * 中性化只针对背景与文字；语义色一旦去色就失去了「一眼看出异常」的作用。
   * 但 *-soft 底色刻意选了极低饱和度，放在纯中性界面里不会突兀。 */
  --c-success:      #059669;
  --c-success-soft: #F0FAF5;
  --c-warn:         #D97706;
  --c-warn-soft:    #FDF8EF;
  --c-danger:       #DC2626;
  --c-danger-soft:  #FDF4F4;
  --c-info:         #0284C7;
  --c-info-soft:    #F2F8FC;

  /* 语义描边：配合 *-soft 底色使用。
   * 比正色浅、比中性边框有辨识度，用来勾勒提示块的轮廓。 */
  --c-line-success: #BFE3D2;
  --c-line-warn:    #EBD9AE;
  --c-line-danger:  #EFC9C9;
  --c-line-info:    #C7DEEE;
  --c-line-brand:   #C9DAF5;

  /* 金额涨跌 —— 刻意独立于中性灰阶，绝不能并入 ink 系列。
   * 账本的盈亏色是信息本身，不是装饰。 */
  --c-up:         #DC2626;   /* 涨 / 收入（国内习惯红涨） */
  --c-down:       #059669;   /* 跌 / 支出 */

  /* 遮罩：纯黑半透明，不带色相 */
  --c-overlay:    rgba(0, 0, 0, .50);

  /* 阴影：浅色下用投影分层，用纯黑不用带蓝的深色 */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, .06);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, .08);
  --shadow-lg:  0 12px 32px rgba(0, 0, 0, .16);

  /* 圆角 */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* 字体 */
  --font-sans: "Noto Sans", "Noto Sans SC", -apple-system, BlinkMacSystemFont,
               "Segoe UI", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;

  /* 动效 */
  --t-fast: 150ms;
  --t-base: 200ms;
  --t-slow: 300ms;
  --ease:   cubic-bezier(.4, 0, .2, 1);
}

/* -----------------------------------------------------
 * 2) 深色
 * --------------------------------------------------- */
html.dark {
  color-scheme: dark;   /* 让 input / 日期选择器 / 滚动条等原生控件自动变深 */

  /* 【纯中性灰】与浅色一样不带任何色相倾向。
   * 不用纯黑 #000：OLED 上纯黑与文字反差过硬，长时间看更累；
   * 层级改用「明度递增」而不是投影 —— 深色下投影几乎不可见。 */
  --c-app:        #0F0F0F;
  --c-surface:    #1A1A1A;
  --c-elevated:   #232323;
  --c-subtle:     #272727;
  --c-border:     #383838;
  --c-border-strong: #4D4D4D;

  --c-ink:        #F2F2F2;   /* 不用纯白，降低眩光 */
  --c-ink-2:      #A8A8A8;
  --c-muted:      #6E6E6E;

  /* 品牌色在深底上必须提亮，否则对比度不足 */
  --c-brand:      #60A5FA;
  --c-brand-hover:#93C5FD;
  --c-brand-soft: #16243A;
  --c-on-brand:   #0A0A0A;
  --c-ring:       rgba(96, 165, 250, .35);

  /* 语义色同样各自提亮，不能直接复用浅色值。
   * 这些是【功能色】，必须保留色相 —— 中性化只针对背景与文字，
   * 语义色一旦去色就失去了「一眼看出异常」的作用。
   * 但 *-soft 底色的饱和度压得很低，避免在中性界面里显得突兀。 */
  --c-success:      #34D399;
  --c-success-soft: #10241C;
  --c-warn:         #FBBF24;
  --c-warn-soft:    #241C08;
  --c-danger:       #F87171;
  --c-danger-soft:  #261314;
  --c-info:         #38BDF8;
  --c-info-soft:    #0E1F2A;

  /* 深色下的语义描边要压暗，否则浅色描边在深底上会过分抢眼 */
  --c-line-success: #1F4638;
  --c-line-warn:    #4A3712;
  --c-line-danger:  #4D2124;
  --c-line-info:    #1B3D4F;
  --c-line-brand:   #21395C;

  --c-up:         #F87171;
  --c-down:       #34D399;

  /* 遮罩：纯黑半透明，不带色相 */
  --c-overlay:    rgba(0, 0, 0, .68);

  --shadow-sm:  0 1px 2px rgba(0, 0, 0, .40);
  --shadow-md:  0 4px 14px rgba(0, 0, 0, .48);
  --shadow-lg:  0 16px 40px rgba(0, 0, 0, .60);
}

/* -----------------------------------------------------
 * 3) 基础样式
 *    本节必须在 Tailwind 之前生效，保证首帧底色正确、不闪白。
 * --------------------------------------------------- */
html {
  background-color: var(--c-app);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--c-app);
  color: var(--c-ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

/* 主题切换时只过渡页面级底色。
 * 刻意不给卡片 / 按钮加过渡：大面积元素同时过渡会产生明显拖影。 */
html, body {
  transition: background-color var(--t-base) var(--ease),
              color var(--t-base) var(--ease);
}

/* 尊重系统的「减弱动画」设置 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 滚动条跟随主题 */
* {
  scrollbar-color: var(--c-border-strong) transparent;
  scrollbar-width: thin;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--c-border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--c-muted); }

/* 表单控件继承字体与主题色 */
input, select, textarea, button { font: inherit; color: inherit; }
input::placeholder, textarea::placeholder { color: var(--c-muted); opacity: 1; }

/* 统一聚焦态：可见但不刺眼 */
:focus-visible {
  outline: 2px solid var(--c-brand);
  outline-offset: 2px;
}

/* 数字等宽 —— 账本金额、指标数值纵向对齐的关键 */
.tnum, .font-mono, table td, table th {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* 移动端安全区（三站原本各写各的，这里统一） */
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
.safe-top    { padding-top:    env(safe-area-inset-top); }

/* -----------------------------------------------------
 * 4) 组件类
 *    供 koven-ui.js 使用；不依赖 Tailwind，主题切换零成本。
 * --------------------------------------------------- */

/* 按钮 */
.k-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--c-ink);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.k-btn:active { transform: translateY(1px); }
.k-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.k-btn--primary { background: var(--c-brand); color: var(--c-on-brand); }
.k-btn--primary:hover:not(:disabled) { background: var(--c-brand-hover); }

.k-btn--secondary { border-color: var(--c-border); color: var(--c-ink-2); background: var(--c-surface); }
.k-btn--secondary:hover:not(:disabled) { background: var(--c-subtle); color: var(--c-ink); }

.k-btn--ghost { color: var(--c-ink-2); }
.k-btn--ghost:hover:not(:disabled) { background: var(--c-subtle); color: var(--c-ink); }

.k-btn--danger { background: var(--c-danger); color: #fff; }
.k-btn--danger:hover:not(:disabled) { filter: brightness(1.08); }

.k-btn--sm { height: 32px; padding: 0 12px; font-size: 13px; }

/* 移动端触控目标不小于 44px */
@media (max-width: 767px) {
  .k-btn { height: 44px; }
  .k-btn--sm { height: 36px; }
}

/* 卡片 */
.k-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
/* 深色下取消投影，改用表面色自身的明度差制造层级 */
html.dark .k-card { box-shadow: none; }

/* 输入控件 */
.k-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  color: var(--c-ink);
  transition: border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
textarea.k-input { height: auto; min-height: 88px; padding: 10px 12px; line-height: 1.6; }
.k-input:focus {
  outline: none;
  border-color: var(--c-brand);
  box-shadow: 0 0 0 3px var(--c-ring);
}
.k-input:disabled { background: var(--c-subtle); color: var(--c-muted); cursor: not-allowed; }
@media (max-width: 767px) {
  /* iOS 上字号小于 16px 会触发自动放大 */
  .k-input { height: 44px; font-size: 16px; }
}

/* 提示条 */
.k-alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  border-left: 3px solid var(--c-border-strong);
  background: var(--c-subtle);
  color: var(--c-ink-2);
  font-size: 13px;
}
.k-alert--info    { border-left-color: var(--c-info);    background: var(--c-info-soft); }
.k-alert--success { border-left-color: var(--c-success); background: var(--c-success-soft); }
.k-alert--warn    { border-left-color: var(--c-warn);    background: var(--c-warn-soft); }
.k-alert--danger  { border-left-color: var(--c-danger);  background: var(--c-danger-soft); }

/* 标签 */
.k-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--c-subtle);
  color: var(--c-ink-2);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.6;
}
.k-badge--brand   { background: var(--c-brand-soft);   color: var(--c-brand); }
.k-badge--success { background: var(--c-success-soft); color: var(--c-success); }
.k-badge--warn    { background: var(--c-warn-soft);    color: var(--c-warn); }
.k-badge--danger  { background: var(--c-danger-soft);  color: var(--c-danger); }

/* 表格 */
.k-table { width: 100%; border-collapse: collapse; }
.k-table th {
  background: var(--c-subtle);
  color: var(--c-ink-2);
  font-weight: 500;
  text-align: left;
  padding: 8px 12px;
  white-space: nowrap;
}
.k-table td {
  padding: 8px 12px;
  border-top: 1px solid var(--c-border);
}
.k-table tbody tr:hover { background: var(--c-subtle); }
.k-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* 弹窗 */
.k-overlay {
  position: fixed;
  inset: 0;
  background: var(--c-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: k-fade var(--t-base) var(--ease);
}
.k-modal {
  background: var(--c-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  animation: k-rise var(--t-base) var(--ease);
}
@keyframes k-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes k-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 空状态 */
.k-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--c-muted);
}
.k-empty__icon { font-size: 32px; margin-bottom: 8px; opacity: .7; }

/* 轻提示（Toast） */
.k-toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.k-toast {
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--c-elevated);
  color: var(--c-ink);
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  line-height: 1.5;
  animation: k-toast-in var(--t-base) var(--ease);
}
.k-toast--success { border-left-color: var(--c-success); }
.k-toast--warn    { border-left-color: var(--c-warn); }
.k-toast--danger  { border-left-color: var(--c-danger); }
.k-toast--out { animation: k-toast-out 220ms var(--ease) forwards; }
@keyframes k-toast-in  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes k-toast-out { to { opacity: 0; transform: translateY(6px); } }

/* 骨架屏 */
.k-skeleton {
  background: linear-gradient(90deg, var(--c-subtle) 25%, var(--c-border) 37%, var(--c-subtle) 63%);
  background-size: 400% 100%;
  animation: k-shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes k-shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* 顶栏 */
.k-appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--c-surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--c-border);
}
/* 不支持 color-mix 的浏览器退回不透明底色 */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .k-appbar { background: var(--c-surface); }
}

/* 导航项 */
.k-nav-item {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--c-ink-2);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.k-nav-item:hover { background: var(--c-subtle); color: var(--c-ink); }
.k-nav-item--active { background: var(--c-brand); color: var(--c-on-brand); }
.k-nav-item--active:hover { background: var(--c-brand-hover); color: var(--c-on-brand); }

/* 移动端汉堡菜单：卡片式竖列，带轻微下滑入场 */
.k-mobile-nav {
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  padding: 8px;
  animation: k-slide-down var(--t-base) var(--ease);
}
.k-mobile-nav .k-nav-item { justify-content: flex-start; }
@keyframes k-slide-down {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

/* 主题切换按钮图标 */
.k-theme-icon {
  display: inline-block;
  transition: transform var(--t-slow) var(--ease), opacity var(--t-base) var(--ease);
}
.k-theme-btn:hover .k-theme-icon { transform: rotate(30deg); }
.k-header-control { height: 36px; min-width: 40px; padding: 0 12px; line-height: 1; text-align: center; }
.k-header-icon { width: 20px; height: 20px; display: block; }
.k-settings-icon { width: 18px; height: 18px; }
.k-header-tools a[href="/settings"] .k-header-icon { width: 18px; height: 18px; stroke-width: 1.7; }
.k-user-menu-trigger { display: inline-flex; align-items: center; justify-content: center; line-height: 1; list-style: none; }
.k-user-menu-trigger::-webkit-details-marker { display: none; }

/* 金额涨跌 */
.k-up   { color: var(--c-up); }
.k-down { color: var(--c-down); }

/* 打印：强制浅色，避免深色主题打出满页黑底 */
@media print {
  html, body { background: #fff !important; color: #000 !important; }
  .k-appbar, .k-btn, .k-overlay { display: none !important; }
}


/* Shared geometry for both the rendered shell and Protocol's persistent DOM. */
.k-shell-container { box-sizing: border-box; width: 100%; max-width: 1152px; margin-inline: auto; padding-inline: 16px; }
.k-header-row { min-height: 56px; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; }
.k-header-brand { color: var(--c-ink); font-size: 14px; font-weight: 600; letter-spacing: -.025em; text-decoration: none; white-space: nowrap; }
.k-header-nav { display: flex; align-items: center; justify-content: center; gap: 4px; }
.k-header-tools { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.k-header-row .k-nav-item { min-height: 36px; box-sizing: border-box; line-height: 20px; }
@media (max-width: 1023px) {
  .k-header-row { grid-template-columns: minmax(0, 1fr) auto; }
  .k-header-nav { display: none; }
}

.k-header-brand { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 380px) {
  .k-header-tools { gap: 4px; }
  .k-header-tools .k-header-control { min-width: 32px; padding-inline: 8px; }
  .k-header-tools .k-user-menu-trigger { max-width: 84px; overflow: hidden; white-space: nowrap; }
}

/* Keep the header centered when one site has a long, scrollable page. */
html { scrollbar-gutter: stable both-edges; }
