/* ============================================================
   Sabaidi · 设计系统（Web / Android / iOS 共用）
   桌面优先：先按大屏排版，窄屏在 app.css 里收敛成移动布局
   ============================================================ */

:root {
  /* ---- 表面与文字 ---- */
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --panel-3: #eef2f8;
  --line: #e4e8f0;
  --line-2: #d3dae6;
  --ink: #0d1119;
  --ink-2: #4d5768;
  --ink-3: #8892a4;

  /* ---- 品牌 ---- */
  --brand: #3b5bdb;
  --brand-2: #1f7ae0;
  --brand-soft: #eef2ff;
  --brand-ink: #ffffff;
  --brand-grad: linear-gradient(135deg, #4468f0 0%, #12a5c4 100%);

  /* ---- 语义色 ---- */
  --ok: #0e9f6e;
  --ok-soft: #e7f8f1;
  --warn: #b45309;
  --warn-soft: #fff6e5;
  --err: #d92d20;
  --err-soft: #fdecea;
  --target: #0e7490;

  /* ---- 排版 ---- */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
          "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
          "Noto Sans Lao", "Noto Sans Lao UI", "Lao UI", sans-serif;
  --font-lao: "Noto Sans Lao", "Noto Sans Lao UI", "Lao UI",
              "Phetsarath OT", "DokChampa", var(--font);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* ---- 形状 ---- */
  --r-xs: 8px;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 18px;
  --r-xl: 24px;

  --shadow-xs: 0 1px 2px rgba(13, 17, 25, .05);
  --shadow-sm: 0 1px 3px rgba(13, 17, 25, .07), 0 1px 2px rgba(13, 17, 25, .04);
  --shadow: 0 4px 12px rgba(13, 17, 25, .06), 0 12px 32px rgba(13, 17, 25, .08);
  --shadow-lg: 0 24px 60px rgba(13, 17, 25, .18);

  /* ---- 结构尺寸 ---- */
  --rail-w: 208px;
  --aside-w: 304px;
  --tap: 44px;
  --dock-h: 92px;

  color-scheme: light;
}

/* 深色：跟随系统，或设置里强制 */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] { color-scheme: dark;
    --bg: #0a0d13; --panel: #111621; --panel-2: #151b27; --panel-3: #1c2431;
    --line: #232b39; --line-2: #303a4b;
    --ink: #e8edf5; --ink-2: #9ca8bb; --ink-3: #6d7a8f;
    --brand: #6d8cff; --brand-2: #4fa8ff; --brand-soft: #16203a; --brand-ink: #08111f;
    --brand-grad: linear-gradient(135deg, #4a6cf5 0%, #18a8c9 100%);
    --ok: #3ddc97; --ok-soft: #10281f;
    --warn: #f0b429; --warn-soft: #2a2110;
    --err: #ff6b61; --err-soft: #2c1514;
    --target: #67c4d8;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.5);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
    --shadow: 0 6px 18px rgba(0,0,0,.45), 0 18px 40px rgba(0,0,0,.5);
    --shadow-lg: 0 26px 64px rgba(0,0,0,.62);
  }
}

:root[data-theme="dark"] { color-scheme: dark;
  --bg: #0a0d13; --panel: #111621; --panel-2: #151b27; --panel-3: #1c2431;
  --line: #232b39; --line-2: #303a4b;
  --ink: #e8edf5; --ink-2: #9ca8bb; --ink-3: #6d7a8f;
  --brand: #6d8cff; --brand-2: #4fa8ff; --brand-soft: #16203a; --brand-ink: #08111f;
  --brand-grad: linear-gradient(135deg, #4a6cf5 0%, #18a8c9 100%);
  --ok: #3ddc97; --ok-soft: #10281f;
  --warn: #f0b429; --warn-soft: #2a2110;
  --err: #ff6b61; --err-soft: #2c1514;
  --target: #67c4d8;
  --shadow-xs: 0 1px 2px rgba(0,0,0,.5);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
  --shadow: 0 6px 18px rgba(0,0,0,.45), 0 18px 40px rgba(0,0,0,.5);
  --shadow-lg: 0 26px 64px rgba(0,0,0,.62);
}

/* ---------------- 基础 ---------------- */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden 属性要能压住组件自己的 display，否则 .field/.notice 这类块元素会「藏不住」 */
[hidden] { display: none !important; }

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

body { min-height: 100vh; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: color-mix(in srgb, var(--brand) 22%, transparent); }

:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand) 70%, transparent);
  outline-offset: 2px;
}

/* 语言标记：老挝文用专门的字体栈，避免回退成泰文字形 */
.lo, [lang="lo"] { font-family: var(--font-lao); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.spacer { flex: 1 1 auto; }

.ic { width: 18px; height: 18px; flex: 0 0 auto; display: block; }

kbd {
  display: inline-block; min-width: 20px; padding: 1px 6px;
  font-family: var(--font-mono); font-size: 11.5px; line-height: 18px;
  text-align: center; color: var(--ink-2);
  background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 6px;
}

/* ---------------- 按钮 ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 14px;
  font-size: 13.5px; font-weight: 560; line-height: 1;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: background .15s, border-color .15s, transform .06s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: var(--line-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn .ic { width: 16px; height: 16px; }

.btn-primary {
  color: var(--brand-ink);
  background: var(--brand-grad);
  border-color: transparent;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--brand) 30%, transparent),
              0 6px 18px color-mix(in srgb, var(--brand) 22%, transparent);
}
.btn-primary:hover { filter: brightness(1.06); background: var(--brand-grad); border-color: transparent; }

.btn-soft {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 18%, transparent);
}
.btn-soft:hover { background: color-mix(in srgb, var(--brand) 12%, var(--panel)); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--panel-3); color: var(--ink); border-color: transparent; }

.btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 28%, var(--line)); background: var(--panel); }
.btn-danger:hover { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }

.btn-sm { min-height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn-icon { width: 36px; min-height: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; min-height: 30px; }
.btn-block { width: 100%; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------------- 徽标 / 标签 ---------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 7px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  color: var(--ink-2);
  background: var(--panel-3);
  border-radius: 999px;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge.ok { color: var(--ok); background: var(--ok-soft); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.err { color: var(--err); background: var(--err-soft); }
.badge.accent { color: var(--brand); background: var(--brand-soft); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 30px; padding: 0 11px;
  font-size: 12.5px; font-weight: 500;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: color .15s, background .15s, border-color .15s;
}
.chip .ic { width: 13px; height: 13px; opacity: 0; transition: opacity .12s; }
.chip[aria-pressed="true"] {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 24%, transparent);
}
.chip[aria-pressed="true"] .ic { opacity: 1; }
.chip:hover { border-color: var(--line-2); color: var(--ink-2); }

/* ---------------- 表单 ---------------- */

.field { display: block; margin-bottom: 14px; }
.field > .label,
.label {
  display: block; margin-bottom: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
}
.field > .hint,
.hint {
  display: block; margin-top: 5px;
  font-size: 11.5px; line-height: 1.6; color: var(--ink-3);
}
.hint.warn { color: var(--warn); }
.hint code, .field code {
  padding: 1px 4px; font-family: var(--font-mono); font-size: 11px;
  background: var(--panel-3); border-radius: 4px;
}

.input, .select, .textarea {
  display: block; width: 100%;
  min-height: 38px; padding: 8px 11px;
  font-size: 13.5px; color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.select {
  appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.7; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-2); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--brand) 55%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }

input[type="range"] {
  width: 100%; height: 22px; padding: 0; background: transparent; border: 0;
  accent-color: var(--brand);
}

/* 开关 */
.switch {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; cursor: pointer;
}
.switch .sw-text { flex: 1 1 auto; min-width: 0; }
.switch .sw-title { display: block; font-size: 13px; font-weight: 560; }
.switch .sw-desc { display: block; font-size: 11.5px; color: var(--ink-3); line-height: 1.5; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: relative; flex: 0 0 auto;
  width: 40px; height: 23px; border-radius: 999px;
  background: var(--line-2); transition: background .18s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-xs);
  transition: transform .18s;
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(17px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }

/* 展开面板 */
details {
  margin-top: 6px;
  border-top: 1px dashed var(--line);
  padding-top: 6px;
}
details > summary {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 0; cursor: pointer; list-style: none;
  font-size: 12.5px; font-weight: 560; color: var(--ink-2);
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s;
}
details[open] > summary::before { transform: rotate(90deg); }
details > summary:hover { color: var(--ink); }
details[open] > summary { margin-bottom: 6px; }

/* ---------------- 卡片 / 提示条 ---------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px;
  font-size: 12.5px; line-height: 1.65; color: var(--ink-2);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.notice .ic { width: 16px; height: 16px; margin-top: 1px; color: var(--ink-3); }
.notice.warn { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 22%, transparent); }
.notice.warn .ic { color: var(--warn); }
.notice strong { color: var(--ink); }
.notice.warn strong { color: var(--warn); }

/* ---------------- 弹层 ---------------- */

.modal {
  position: fixed; inset: 0; z-index: 90;
  display: none; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(9, 12, 20, .45);
  backdrop-filter: blur(3px);
}
.modal.show { display: flex; }
.sheet {
  width: min(380px, 100%);
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
}
.sheet h3 { font-size: 16px; margin-bottom: 8px; }

/* ---------------- Toast ---------------- */

#toasts {
  position: fixed; z-index: 120; left: 50%; bottom: 22px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: min(520px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  padding: 10px 15px;
  font-size: 13px; font-weight: 500; line-height: 1.5;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, var(--line)); }
.toast.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, var(--line)); }
.toast.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, var(--line)); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* ---------------- 滚动条 ---------------- */

* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--line-2); border-radius: 999px;
  border: 3px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
