/* ---------- Tokens ---------- */
:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-hover: #f5f5f4;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-faint: #a8a29e;
  --icon-bg: #f5f5f4;
  --icon-img-bg: #f5f5f4;
  --app-plate: #ffffff;
  --shadow: 0 1px 2px rgba(28, 25, 23, .05);
  --shadow-lift: 0 8px 24px rgba(28, 25, 23, .10);
  --danger: #dc2626;
  --accent: #2f6fde;
  --accent-ui: var(--accent);
  --accent-soft: color-mix(in srgb, var(--accent-ui) 14%, transparent);
  --av-bg-l: 92%; --av-bg-s: 55%; --av-fg-l: 34%; --av-fg-s: 45%;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  /* Appearance knobs (set from settings, per device) */
  --s: 1;       /* size */
  --sp: 1;      /* spacing */
  --fs: 15px;   /* font size */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131313; --surface: #1c1c1c; --surface-hover: #252525;
    --border: #2a2a2a; --border-strong: #3a3a3a;
    --text: #ededec; --text-muted: #9a9a98; --text-faint: #6b6b69;
    --icon-bg: #262626; --icon-img-bg: #ececea; --app-plate: #ececea;
    --shadow: none; --shadow-lift: 0 8px 24px rgba(0, 0, 0, .45);
    --accent-ui: color-mix(in srgb, var(--accent) 70%, white);
    --av-bg-l: 24%; --av-bg-s: 28%; --av-fg-l: 78%; --av-fg-s: 55%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131313; --surface: #1c1c1c; --surface-hover: #252525;
  --border: #2a2a2a; --border-strong: #3a3a3a;
  --text: #ededec; --text-muted: #9a9a98; --text-faint: #6b6b69;
  --icon-bg: #262626; --icon-img-bg: #ececea; --app-plate: #ececea;
  --shadow: none; --shadow-lift: 0 8px 24px rgba(0, 0, 0, .45);
  --accent-ui: color-mix(in srgb, var(--accent) 70%, white);
  --av-bg-l: 24%; --av-bg-s: 28%; --av-fg-l: 78%; --av-fg-s: 55%;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--fs)/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.page { max-width: 1120px; margin: 0 auto; padding: 24px 24px 96px; }

/* ---------- Header ---------- */
.header { display: flex; align-items: center; gap: 8px; height: 36px; }
.wordmark { font-size: 15px; font-weight: 600; letter-spacing: .08em; color: var(--text-muted); }
.save-state { font-size: 12px; color: var(--text-faint); margin-right: auto; margin-left: 4px; transition: opacity .3s; }
.save-state.error { color: var(--danger); }
.hbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  font-size: 13px; color: var(--text-muted); cursor: pointer;
}
.hbtn:hover { color: var(--text); border-color: var(--border-strong); }
.hbtn.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.hbtn.square { width: 32px; padding: 0; justify-content: center; }

/* ---------- Search ---------- */
.search { position: relative; margin: calc(40px * var(--sp)) auto calc(36px * var(--sp)); max-width: 620px; }
.search input {
  width: 100%; height: 50px; padding: 0 48px 0 46px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  box-shadow: var(--shadow); font-size: 16px; outline: none;
}
.search input:focus { border-color: var(--accent-ui); box-shadow: 0 0 0 3px var(--accent-soft); }
.search > svg { position: absolute; left: 16px; top: 16px; color: var(--text-faint); }
.search kbd { position: absolute; right: 14px; top: 13px; font: 12px/22px var(--font); padding: 0 7px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-faint); }
.search-hint { text-align: center; color: var(--text-muted); font-size: 13px; margin: calc(-22px * var(--sp)) 0 calc(24px * var(--sp)); min-height: 18px; }

/* ---------- Sections ---------- */
.section { margin-bottom: calc(28px * var(--sp)); }
.section-head { display: flex; align-items: center; gap: 8px; min-height: 26px; margin-bottom: calc(10px * var(--sp)); font-size: 13px; color: var(--text-muted); user-select: none; }
.section-head .sname { font-weight: 600; letter-spacing: .02em; }
.section-head .count { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.section-head .collapse { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; cursor: pointer; color: inherit; }
.section-head .chev { transition: transform .15s; color: var(--text-faint); }
.section.collapsed .chev { transform: rotate(-90deg); }
.section.collapsed .grid { display: none; }
.section-head .grip { display: none; cursor: grab; color: var(--text-faint); letter-spacing: -2px; }
.editing .section-head .grip { display: inline-flex; }
.section.special .sname { color: var(--text); }
.empty-home { text-align: center; color: var(--text-muted); padding: 60px 0; }

/* ---------- Bookmark (shared) ---------- */
.bm { position: relative; display: flex; align-items: center; min-width: 0; color: var(--text); transition: background .12s, border-color .12s, box-shadow .12s, transform .12s; }
.bm:focus-visible, .bm.selected { outline: none; border-color: var(--accent-ui) !important; box-shadow: 0 0 0 3px var(--accent-soft) !important; }
.ic { flex: none; display: grid; place-items: center; overflow: hidden; font-weight: 600; background: var(--icon-bg); }
.ic img { object-fit: contain; display: block; }
.ic.has-img { background: var(--icon-img-bg); }
.ic.avatar { background: hsl(var(--h) var(--av-bg-s) var(--av-bg-l)); color: hsl(var(--h) var(--av-fg-s) var(--av-fg-l)); }
.tx { min-width: 0; display: flex; flex-direction: column; }
.nm { max-width: 100%; font-size: var(--fs); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nt { max-width: 100%; font-size: calc(var(--fs) * .8); color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.no-notes .nt { display: none; }
.badge { flex: none; margin-left: auto; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 5px; background: var(--icon-bg); color: var(--text-faint); }
.bm.is-hidden { opacity: .42; }
.edit-btn { display: none; }
.editing .bm { cursor: grab; }
.editing .edit-btn {
  display: grid; place-items: center; position: absolute; top: -7px; right: -7px; z-index: 2;
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-muted); cursor: pointer; font-size: 12px; padding: 0;
}
.editing .edit-btn:hover { color: var(--text); border-color: var(--text-muted); }
.bm.dragging { opacity: .3; }
.bm.drop-before::before { content: ""; position: absolute; left: -6px; top: 10%; bottom: 10%; width: 3px; border-radius: 2px; background: var(--accent-ui); }
.grid.drop-target { outline: 2px dashed var(--accent-soft); outline-offset: 6px; border-radius: 10px; }
.section.dragging-section { opacity: .35; }
.add-bm {
  display: flex; align-items: center; justify-content: center; gap: 4px; min-width: 0;
  border: 1px dashed var(--border-strong); border-radius: calc(10px * var(--s)); background: none;
  color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 0 calc(12px * var(--s)); min-height: calc(34px * var(--s));
}
.add-bm:hover { color: var(--text); border-color: var(--text-muted); }
.new-group { display: none; margin: 4px 0 0; }
.editing .new-group { display: block; }
.dashed-btn { border: 1px dashed var(--border-strong); background: none; border-radius: 10px; padding: 8px 14px; color: var(--text-muted); cursor: pointer; }
.dashed-btn:hover { color: var(--text); border-color: var(--text-muted); }

/* ---------- Style: 小方块 (row) ---------- */
.style-row .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(196px * var(--s)), 1fr)); gap: calc(10px * var(--sp)); }
.style-row .bm { height: calc(58px * var(--s)); padding: 0 calc(12px * var(--s)); gap: calc(11px * var(--s)); background: var(--surface); border: 1px solid var(--border); border-radius: calc(12px * var(--s)); box-shadow: var(--shadow); }
.style-row .bm:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.style-row .ic { width: calc(30px * var(--s)); height: calc(30px * var(--s)); border-radius: calc(8px * var(--s)); font-size: calc(14px * var(--s)); }
.style-row .ic img { width: calc(20px * var(--s)); height: calc(20px * var(--s)); }
.style-row .add-bm { height: calc(58px * var(--s)); }

/* ---------- Style: 胶囊 (chip) ---------- */
.style-chip .grid { display: flex; flex-wrap: wrap; gap: calc(6px * var(--sp)); }
.style-chip .bm { height: calc(34px * var(--s)); padding: 0 calc(12px * var(--s)) 0 calc(8px * var(--s)); gap: calc(8px * var(--s)); background: var(--surface); border: 1px solid var(--border); border-radius: calc(9px * var(--s)); box-shadow: var(--shadow); }
.style-chip .bm:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.style-chip .ic { width: calc(20px * var(--s)); height: calc(20px * var(--s)); border-radius: calc(5px * var(--s)); font-size: calc(11px * var(--s)); }
.style-chip .ic.has-img { background: transparent; }
.style-chip .ic img { width: calc(16px * var(--s)); height: calc(16px * var(--s)); }
.style-chip .nt { display: none; }
.style-chip .nm { font-size: calc(var(--fs) * .93); }
.style-chip .badge { margin-left: 2px; }
:root[data-theme="dark"] .style-chip .ic.has-img { background: var(--icon-img-bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .style-chip .ic.has-img { background: var(--icon-img-bg); } }

/* ---------- Style: 大方块 (tile) ---------- */
.style-tile .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(118px * var(--s)), 1fr)); gap: calc(12px * var(--sp)); }
.style-tile .bm { flex-direction: column; justify-content: center; height: calc(112px * var(--s)); gap: calc(8px * var(--s)); padding: calc(10px * var(--s)) calc(8px * var(--s)); text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: calc(14px * var(--s)); box-shadow: var(--shadow); }
.style-tile .bm:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.style-tile .ic { width: calc(44px * var(--s)); height: calc(44px * var(--s)); border-radius: calc(12px * var(--s)); font-size: calc(18px * var(--s)); }
.style-tile .ic img { width: calc(28px * var(--s)); height: calc(28px * var(--s)); }
.style-tile .tx { align-items: center; max-width: 100%; }
.style-tile .badge { position: absolute; top: 6px; right: 6px; margin: 0; }
.style-tile .add-bm { height: calc(112px * var(--s)); }

/* ---------- Style: App 图标 ---------- */
.style-app .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(88px * var(--s)), 1fr)); gap: calc(16px * var(--sp)) calc(8px * var(--sp)); }
.style-app .bm { flex-direction: column; gap: calc(8px * var(--s)); padding: calc(6px * var(--s)) 2px; text-align: center; border-radius: 12px; }
.style-app .ic { width: calc(58px * var(--s)); height: calc(58px * var(--s)); border-radius: calc(16px * var(--s)); font-size: calc(24px * var(--s)); background: var(--app-plate); box-shadow: 0 1px 3px rgba(0, 0, 0, .08), inset 0 0 0 1px var(--border); transition: transform .15s, box-shadow .15s; }
.style-app .ic.avatar { box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.style-app .ic img { width: calc(36px * var(--s)); height: calc(36px * var(--s)); }
.style-app .bm:hover .ic { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.style-app .tx { align-items: center; max-width: 100%; }
.style-app .nm { font-size: calc(var(--fs) * .86); font-weight: 400; }
.style-app .nt { display: none; }
.style-app .badge { position: absolute; top: 0; right: 8px; margin: 0; }
.style-app .add-bm { height: calc(84px * var(--s)); flex-direction: column; }
.style-app.editing .edit-btn { right: calc(50% - 36px * var(--s)); }

/* ---------- Style: 纯图标 ---------- */
.style-icon .grid { display: flex; flex-wrap: wrap; gap: calc(10px * var(--sp)); }
.style-icon .bm { width: calc(50px * var(--s)); height: calc(50px * var(--s)); justify-content: center; background: var(--surface); border: 1px solid var(--border); border-radius: calc(13px * var(--s)); box-shadow: var(--shadow); }
.style-icon .bm:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.style-icon .ic { width: calc(30px * var(--s)); height: calc(30px * var(--s)); border-radius: calc(8px * var(--s)); font-size: calc(14px * var(--s)); }
.style-icon .ic.has-img { background: transparent; }
.style-icon .ic img { width: calc(24px * var(--s)); height: calc(24px * var(--s)); }
:root[data-theme="dark"] .style-icon .ic.has-img { background: var(--icon-img-bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .style-icon .ic.has-img { background: var(--icon-img-bg); } }
.style-icon .tx, .style-icon .badge { display: none; }
.style-icon .bm:hover::after {
  content: attr(data-name); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 5;
  padding: 3px 8px; border-radius: 6px; background: var(--text); color: var(--bg); font-size: 12px; white-space: nowrap; pointer-events: none;
}
.style-icon .add-bm { width: calc(50px * var(--s)); height: calc(50px * var(--s)); padding: 0; }
.style-icon .add-bm span { display: none; }

/* ---------- Style: 文字列表 ---------- */
.style-list .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(280px * var(--s)), 1fr)); column-gap: calc(24px * var(--sp)); row-gap: calc(2px * var(--sp)); }
.style-list .bm { height: calc(38px * var(--s)); padding: 0 calc(8px * var(--s)); gap: calc(10px * var(--s)); border-radius: 8px; }
.style-list .bm:hover { background: var(--surface-hover); }
.style-list .ic { width: calc(20px * var(--s)); height: calc(20px * var(--s)); border-radius: 5px; font-size: calc(11px * var(--s)); }
.style-list .ic.has-img { background: transparent; }
.style-list .ic img { width: calc(16px * var(--s)); height: calc(16px * var(--s)); }
:root[data-theme="dark"] .style-list .ic.has-img { background: var(--icon-img-bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .style-list .ic.has-img { background: var(--icon-img-bg); } }
.style-list .tx { flex-direction: row; align-items: baseline; gap: 8px; }
.style-list .nt { flex: 0 1 auto; }
.style-list .add-bm { height: calc(38px * var(--s)); justify-content: flex-start; }
.style-list.editing .edit-btn { top: 50%; transform: translateY(-50%); right: 4px; }

/* ---------- Layout: 左右分栏 ---------- */
.layout-columns #sections { display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(232px * var(--s)), 1fr)); gap: calc(30px * var(--sp)) calc(26px * var(--sp)); align-items: start; }
.layout-columns .section { margin: 0; }
.layout-columns .section.special { grid-column: 1 / -1; }
.layout-columns.style-row .section:not(.special) .grid,
.layout-columns.style-list .section:not(.special) .grid { grid-template-columns: 1fr; }
.layout-columns.style-tile .section:not(.special) .grid { grid-template-columns: repeat(auto-fill, minmax(calc(96px * var(--s)), 1fr)); }
.layout-columns.style-app .section:not(.special) .grid { grid-template-columns: repeat(auto-fill, minmax(calc(74px * var(--s)), 1fr)); }

/* ---------- Settings drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: 340px; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lift);
  padding: 20px 20px 28px; transform: translateX(105%); transition: transform .2s ease; font-size: 14px;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer .sub { color: var(--text-faint); font-size: 12px; margin: 0 0 18px; }
.set { margin-bottom: 20px; }
.set-label { display: flex; justify-content: space-between; color: var(--text-muted); font-size: 13px; margin-bottom: 8px; }
.set-label output { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.seg { display: flex; background: var(--icon-bg); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--text-muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.style-picks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.style-picks button { border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 10px 4px 8px; cursor: pointer; font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.style-picks button.on { border-color: var(--accent-ui); color: var(--text); box-shadow: 0 0 0 2px var(--accent-soft); }
.style-picks svg { color: var(--text-faint); }
.style-picks button.on svg { color: var(--accent-ui); }
input[type="range"] { width: 100%; accent-color: var(--accent-ui); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; }
.swatches button.on { box-shadow: 0 0 0 2px var(--text); }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--border); cursor: pointer; }
.toggle input { width: 36px; height: 20px; appearance: none; background: var(--border-strong); border-radius: 10px; position: relative; cursor: pointer; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked { background: var(--accent-ui); }
.toggle input:checked::after { transform: translateX(16px); }
.reset { margin-top: 14px; width: 100%; height: 36px; border: 1px solid var(--border); background: none; border-radius: 9px; cursor: pointer; color: var(--text-muted); }
.reset:hover { color: var(--text); }
.x-btn { width: 30px; height: 30px; border: 0; background: none; border-radius: 8px; cursor: pointer; color: var(--text-muted); font-size: 18px; }
.x-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ---------- Manage page ---------- */
.mg-head { display: flex; align-items: center; gap: 12px; margin: 24px 0 18px; }
.mg-head h1 { font-size: 20px; margin: 0; }
.mg { display: grid; grid-template-columns: 230px 1fr; gap: 20px; align-items: start; }
.mg-groups { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px; position: sticky; top: 16px; }
.mg-group { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 8px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text-muted); }
.mg-group:hover { background: var(--surface-hover); color: var(--text); }
.mg-group.active { background: var(--accent-soft); color: var(--text); font-weight: 500; }
.mg-group.drop { box-shadow: inset 0 0 0 2px var(--accent-ui); }
.mg-group .gname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-group .count { color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.mg-group .grip { cursor: grab; color: var(--text-faint); letter-spacing: -2px; font-size: 12px; width: 12px; }
.mg-group .gbtn { display: none; border: 0; background: none; cursor: pointer; color: var(--text-faint); padding: 2px 3px; font-size: 12px; border-radius: 5px; }
.mg-group:hover .gbtn { display: inline-block; }
.mg-group .gbtn:hover { color: var(--text); background: var(--bg); }
.mg-group.dragging { opacity: .35; }
.mg-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.mg-newgroup { width: 100%; margin-top: 6px; }
.mg-main { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; min-width: 0; }
.mg-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.mg-toolbar .sel { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin-right: 4px; }
.tb-btn, .tb-select { height: 32px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 0 10px; font-size: 13px; cursor: pointer; color: var(--text); }
.tb-btn:disabled, .tb-select:disabled { opacity: .45; cursor: default; }
.tb-btn.danger { color: var(--danger); }
.tb-btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.spacer { flex: 1; }
.mg-filter { height: 32px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; background: var(--bg); width: 160px; font-size: 13px; }
.mg-filter:focus { outline: none; border-color: var(--accent-ui); }
.mg-row { display: grid; grid-template-columns: 22px 24px minmax(0, 1.3fr) minmax(0, 1fr) 96px 56px 30px; align-items: center; gap: 10px; min-height: 48px; padding: 6px 12px; border-bottom: 1px solid var(--border); font-size: 14px; cursor: pointer; }
.mg-row:last-child { border-bottom: 0; }
.mg-row:hover { background: var(--surface-hover); }
.mg-row.checked { background: var(--accent-soft); }
.mg-row.dragging { opacity: .35; }
.mg-row .ic { width: 24px; height: 24px; border-radius: 6px; font-size: 11px; }
.mg-row .ic img { width: 16px; height: 16px; }
.mg-row .rname { min-width: 0; }
.mg-row .rname b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-row .rname small { display: block; color: var(--text-faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-row .rurl { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-row .rgroup { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-row .rstate { font-size: 12px; color: var(--text-faint); }
.mg-row .redit { border: 0; background: none; cursor: pointer; color: var(--text-faint); border-radius: 6px; height: 26px; }
.mg-row .redit:hover { color: var(--text); background: var(--bg); }
.mg-row input[type="checkbox"], .sel input { width: 16px; height: 16px; accent-color: var(--accent-ui); cursor: pointer; }
.mg-empty { padding: 40px; text-align: center; color: var(--text-muted); }
.mg-tip { color: var(--text-faint); font-size: 12px; padding: 10px 12px; }

/* ---------- Dialogs ---------- */
dialog { width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 40px); border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 22px; box-shadow: var(--shadow-lift); }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
dialog h2 { margin: 0 0 16px; font-size: 17px; }
dialog p.msg { margin: -6px 0 16px; color: var(--text-muted); font-size: 14px; }
.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-muted); }
.field input, .field select, .field textarea, .dlg-input { display: block; width: 100%; margin-top: 5px; height: 38px; padding: 0 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--text); font-size: 15px; }
.field textarea { height: 180px; padding: 10px 11px; resize: vertical; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.field input:focus, .field select:focus, .field textarea:focus, .dlg-input:focus { outline: none; border-color: var(--accent-ui); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 4px 0 10px; cursor: pointer; }
.check input { accent-color: var(--accent-ui); width: 16px; height: 16px; }
.icon-edit { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; flex-wrap: wrap; }
.icon-edit .ic { width: 40px; height: 40px; border-radius: 10px; font-size: 17px; }
.icon-edit .ic img { width: 26px; height: 26px; }
.mini-btn { height: 30px; padding: 0 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; font-size: 12.5px; cursor: pointer; color: var(--text-muted); }
.mini-btn:hover { color: var(--text); border-color: var(--border-strong); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.dialog-actions button { height: 36px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.dialog-actions .primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.dialog-actions .danger { color: var(--danger); }
.dialog-actions .danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.dialog-actions .left { margin-right: auto; }
.form-error { color: var(--danger); font-size: 13px; margin: 0 0 8px; }
.batch-table { border: 1px solid var(--border); border-radius: 10px; max-height: 50vh; overflow: auto; margin-bottom: 8px; }
.batch-row { display: grid; grid-template-columns: 22px 24px minmax(0, 1fr) minmax(0, 1.2fr) 120px; gap: 10px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.batch-row:last-child { border-bottom: 0; }
.batch-row .ic { width: 24px; height: 24px; border-radius: 6px; font-size: 11px; }
.batch-row input[type="text"], .batch-row select { height: 30px; border: 1px solid var(--border); border-radius: 7px; padding: 0 8px; background: var(--bg); font-size: 13px; width: 100%; }
.batch-row .burl { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.batch-row.dup { opacity: .5; }
.batch-note { font-size: 12px; color: var(--text-faint); margin: 0 0 8px; }

/* ---------- Toast, save state, banner ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow-lift); opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .page { padding: 14px 16px 90px; }
  .hbtn .lbl { display: none; }
  .hbtn { width: 34px; padding: 0; justify-content: center; }
  .search { margin: 16px 0 24px; }
  .search kbd { display: none; }
  .search-hint { margin: -14px 0 18px; }
  .style-row .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .style-row .bm { padding: 0 10px; gap: 9px; }
  .style-row .nm { font-size: calc(var(--fs) * .93); }
  .style-tile .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .style-app .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .style-list .grid { grid-template-columns: 1fr; }
  .bm.local-only .badge { display: none; }
  .layout-columns #sections { grid-template-columns: 1fr; }
  .drawer { width: 100%; top: auto; max-height: 82vh; border-left: 0; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; transform: translateY(105%); }
  .mg { grid-template-columns: 1fr; }
  .mg-groups { position: static; display: flex; overflow-x: auto; gap: 4px; padding: 6px; }
  .mg-group { flex: none; }
  .mg-group .grip, .mg-group .gbtn, .mg-sep { display: none !important; }
  .mg-newgroup { width: auto; margin: 0; flex: none; }
  .mg-row { grid-template-columns: 22px 24px minmax(0, 1fr) 30px; }
  .mg-row .rurl, .mg-row .rgroup, .mg-row .rstate { display: none; }
  .mg-filter { width: 100%; order: 10; }
  .batch-row { grid-template-columns: 22px minmax(0, 1fr) 100px; }
  .batch-row .ic, .batch-row .burl { display: none; }
  }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.banner { margin: 16px auto 0; max-width: 620px; padding: 10px 14px; border-radius: 10px; font-size: 14px; background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.banner button { border: 1px solid currentColor; background: none; color: inherit; border-radius: 7px; padding: 3px 10px; cursor: pointer; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border-strong); border-top-color: var(--text-muted); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login gate ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: min(340px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.gate-logo { border-radius: 11px; margin-bottom: 4px; }
.gate-card h1 { margin: 0; font-size: 20px; letter-spacing: .08em; }
.gate-sub { margin: 0 0 8px; color: var(--text-muted); font-size: 14px; line-height: 1.6; }
.gate-input { width: 100%; height: 46px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-size: 16px; outline: none; }
.gate-input:focus { border-color: var(--accent-ui); box-shadow: 0 0 0 3px var(--accent-soft); }
.gate-btn { width: 100%; height: 46px; border: 0; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 15px; font-weight: 500; cursor: pointer; }
.gate-btn:disabled { opacity: .5; cursor: default; }
.gate .form-error { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Account section in settings ---------- */
.drawer-section { font-size: 13px; font-weight: 600; margin: 0 0 4px; color: var(--text); }
.account-title { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--border); }
.sessions { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.session { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; }
.session .who { flex: 1; min-width: 0; }
.session .who b { font-weight: 500; }
.session .who small { display: block; color: var(--text-faint); font-size: 12px; }
.session .tag { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent-ui); margin-left: 6px; }
.account-actions { display: flex; gap: 8px; }
.danger-text { color: var(--danger); }
