:root {
  --bg: #f5f5f7;
  --cell: #ffffff;
  --cell-alt: #f9f9fb;
  --line: #e5e5ea;
  --muted: #6e6e73;
  --active: #007aff;
  --blue: #007aff;
  --blue-press: #0051c6;
  --highlight-blue: #e2f0ff;
  
  /* ✅ 按钮颜色变量 */
  --btn-default: #3C78D7; /* RGB(60, 120, 215) */
  --btn-active: #1890FF;
  --btn-hover: #40a9ff;

  /* 行高 / 列宽 / 隔行色，由显示设置控制 */
  --pad: 6px;
  --colScale: 1;
  --zebra: #e2f0ff;

  --font-main: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui,
    "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-weight: normal; /* ✅ 优化：字体粗细设置 */

  --w-phone: 120px; /* ✅ 优化：电话号码列宽设置为200px的3/5（120px） */
  --w-owner: 165px; /* ✅ 优化：所属人列宽165px */
  --w-real: 185px; /* ✅ 优化：微信实名人列宽185px */
  --w-wx: 130px;
  --w-xhs: 160px;
  --w-note: 220px;
  --w-cat: 90px;
  --w-actions: 110px;
}

/* =========================
 * Pearl dashboard visual refresh
 * ========================= */

:root {
  --pearl-surface: #f2f5f7;
  --pearl-white: #ffffff;
  --pearl-primary: #005da7;
  --pearl-primary-bright: #208bee;
  --pearl-primary-soft: #e8f3ff;
  --pearl-outline: #c0c7d5;
  --pearl-outline-soft: rgba(192, 199, 213, 0.6);
  --pearl-text: #1a1c1e;
  --pearl-muted: #404753;
  --pearl-shadow: 0 10px 30px rgba(0, 93, 167, 0.08);
  --pearl-shadow-soft: 0 4px 20px rgba(99, 155, 213, 0.1);
  --success-green: #30d158;
  --font-main: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

body {
  background: var(--pearl-surface);
  color: var(--pearl-text);
}

.app-sidebar {
  display: none;
}

.mobile-sidebar-toggle {
  display: none;
}

.sidebar-nav-item,
.sidebar-add,
.sidebar-logout {
  font-family: inherit;
}

.app-topbar {
  border-bottom: 1px solid var(--pearl-outline-soft);
}

.controls-panel,
.data-panel,
#panelCategories {
  border: 1px solid rgba(192, 199, 213, 0.62);
  box-shadow: var(--pearl-shadow-soft);
}

input,
select,
button {
  border-color: var(--pearl-outline);
}

input:focus,
select:focus {
  border-color: var(--pearl-primary-bright);
  box-shadow: 0 0 0 3px rgba(32, 139, 238, 0.12);
}

.cloud-status,
.save-status {
  border: 1px solid rgba(32, 139, 238, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.cloud-status {
  background: #f0f8ff;
  color: var(--pearl-primary);
}

#cloudDot {
  background: var(--success-green);
  box-shadow: 0 0 0 3px rgba(48, 209, 88, 0.12);
}

.save-status {
  background: #edf6ff;
  color: var(--pearl-primary);
}

.save-status.success {
  background: #eaf8ef;
  color: #137333;
  border-color: rgba(48, 209, 88, 0.25);
}

.save-status.warning {
  background: #fff8e8;
  color: #8a5a00;
  border-color: rgba(245, 166, 35, 0.25);
}

.save-status.error {
  background: #fff0f0;
  color: #ba1a1a;
  border-color: rgba(186, 26, 26, 0.22);
}

.large-text-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 35, 50, 0.26);
  backdrop-filter: blur(8px);
}

.large-text-editor-panel {
  width: min(720px, calc(100vw - 32px));
  max-height: min(78vh, 680px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid rgba(192, 199, 213, 0.72);
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 253, 0.95)),
    #fff;
  box-shadow: 0 22px 60px rgba(0, 52, 100, 0.22);
  padding: 18px;
}

.large-text-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.large-text-editor-title {
  color: var(--pearl-primary);
  font-size: 18px;
  font-weight: 850;
}

.large-text-editor-subtitle {
  margin-top: 4px;
  color: #657081;
  font-size: 12px;
}

.large-text-editor-close {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  background: #fff !important;
  color: #405062 !important;
  box-shadow: none;
}

.large-text-editor-input {
  width: 100%;
  min-height: 240px;
  max-height: 48vh;
  resize: vertical;
  border: 1px solid var(--pearl-outline);
  border-radius: 16px;
  background: #fff;
  color: var(--pearl-text);
  font: 15px/1.7 var(--font-main);
  padding: 14px 16px;
  white-space: pre-wrap;
}

.large-text-editor-input:focus {
  outline: none;
  border-color: var(--pearl-primary-bright);
  box-shadow: 0 0 0 3px rgba(32, 139, 238, 0.12);
}

.large-text-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.large-text-editor-actions button {
  min-width: 92px;
}

.toolbar-focus-pulse {
  animation: toolbarPulse 0.9s ease;
}

@keyframes toolbarPulse {
  0% { box-shadow: 0 0 0 0 rgba(32, 139, 238, 0.0); }
  40% { box-shadow: 0 0 0 4px rgba(32, 139, 238, 0.12); }
  100% { box-shadow: 0 0 0 0 rgba(32, 139, 238, 0.0); }
}

@media (min-width: 1024px) {
  body {
    min-height: 100vh;
  }

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    display: flex;
    width: 256px;
    flex-direction: column;
    padding: 18px 10px 22px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(242, 245, 247, 0.96));
    border-right: 1px solid var(--pearl-outline-soft);
    box-shadow: 8px 0 28px rgba(0, 93, 167, 0.06);
  }

  .sidebar-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px 22px;
  }

  .sidebar-avatar {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border-radius: 999px;
    background: linear-gradient(145deg, #d7e9ff, #ffffff 58%, #c7ddf6);
    color: var(--pearl-primary);
    font-weight: 800;
    box-shadow: 0 8px 20px rgba(0, 93, 167, 0.14);
  }

  .sidebar-profile-text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
  }

  .sidebar-app-version {
    display: inline-flex;
    align-items: center;
    align-self: center;
    min-height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(32, 139, 238, 0.12);
    color: var(--pearl-primary);
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0;
    white-space: nowrap;
  }

  .sidebar-user-name {
    overflow: hidden;
    color: var(--pearl-primary);
    font-size: 16px;
    font-weight: 800;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar-cloud-line {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    color: var(--pearl-muted);
    font-size: 12px;
    line-height: 1.2;
  }

  .sidebar-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--success-green);
  }

  .sidebar-nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 7px;
  }

  .sidebar-nav-item,
  .sidebar-add,
  .sidebar-logout {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    min-height: 48px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0;
    transition: background .18s ease, border-color .18s ease, color .18s ease, transform .15s ease, box-shadow .18s ease;
  }

  .sidebar-nav-item {
    gap: 12px;
    padding: 0 18px;
    background: transparent !important;
    color: #263241;
  }

  .sidebar-sub-item {
    min-height: 40px;
    padding-left: 34px;
    font-size: 13px;
    font-weight: 680;
    color: #506070;
  }

  .sidebar-danger-item {
    margin-top: 4px;
    color: #a61919;
  }

  .sidebar-danger-item:hover,
  .sidebar-danger-item.active {
    background: #fff2f2 !important;
    border-color: rgba(186, 26, 26, 0.2);
    color: #a61919;
    box-shadow: none;
  }

  .sidebar-nav-item:hover,
  .sidebar-nav-item.active {
    background: linear-gradient(135deg, #a9d2ff, #78b8f3) !important;
    color: #06395f;
    box-shadow: 0 8px 20px rgba(32, 139, 238, 0.16);
  }

  .sidebar-icon {
    display: grid;
    width: 22px;
    place-items: center;
    color: currentColor;
    font-size: 19px;
    line-height: 1;
  }

  .sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 18px;
    border-top: 1px solid var(--pearl-outline-soft);
  }

  .sidebar-add {
    justify-content: center;
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
    color: #fff;
    border-color: transparent;
    box-shadow: 0 10px 22px rgba(0, 93, 167, 0.22);
  }

  .sidebar-add:hover {
    background: linear-gradient(135deg, #2c9bff, var(--pearl-primary)) !important;
  }

  .sidebar-logout {
    justify-content: flex-start;
    padding: 0 18px;
    background: transparent !important;
    color: #263241;
  }

  .sidebar-logout:hover {
    background: rgba(0, 93, 167, 0.08) !important;
    color: var(--pearl-primary);
  }

  .wrap {
    max-width: none;
    min-height: 100vh;
    margin: 0 0 0 256px;
    padding: 0 32px 44px;
  }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 66px;
    margin: 0 -32px 28px;
    padding: 0 32px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(16px);
    box-shadow: 0 1px 0 rgba(192, 199, 213, 0.35);
  }

  #appTitle {
    color: var(--pearl-primary);
    font-size: 24px;
    font-weight: 800;
  }

  .topbar .top-right {
    gap: 12px;
  }

  #currentUserName {
    color: var(--pearl-muted) !important;
    font-weight: 650;
  }

  #btnLogout {
    height: 34px !important;
    padding: 0 14px !important;
    border: 1px solid transparent !important;
    background: transparent !important;
    color: var(--pearl-primary) !important;
    font-weight: 750;
  }

  .controls-panel {
    padding: 20px;
    border-radius: 20px;
    background:
      linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(242, 247, 252, 0.9)),
      var(--pearl-white);
  }

  .filter-toolbar {
    display: grid;
    grid-template-columns: minmax(280px, 1.45fr) auto minmax(150px, 0.7fr) minmax(170px, 0.7fr) minmax(150px, 0.7fr);
    gap: 14px;
    align-items: center;
    margin-bottom: 20px;
  }

  .action-toolbar {
    align-items: center;
    gap: 14px;
    margin-bottom: 0;
    padding-top: 10px;
    border-top: 1px solid rgba(192, 199, 213, 0.45);
    border-radius: 14px;
  }

  .search-wrapper {
    min-width: 0;
  }

  #q,
  .toolbar select {
    height: 46px;
    border-radius: 14px;
    border-color: var(--pearl-outline);
    background: rgba(255, 255, 255, 0.82);
    color: var(--pearl-text);
    font-size: 15px;
    box-shadow: inset 0 1px 2px rgba(0, 93, 167, 0.04);
  }

  #q {
    padding-left: 16px;
  }

  .toolbar button,
  button.primary,
  button.ghost,
  button.function-btn {
    min-height: 44px;
    height: 44px;
    border-radius: 13px;
    padding: 0 18px;
    font-weight: 750;
    letter-spacing: 0;
  }

  button.primary,
  #btnAdd {
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
    border-color: transparent !important;
    color: #fff !important;
    box-shadow: 0 10px 22px rgba(0, 93, 167, 0.22);
  }

  button.primary:hover,
  #btnAdd:hover {
    background: linear-gradient(135deg, #2d9cff, var(--pearl-primary)) !important;
  }

  button.ghost,
  button.function-btn {
    background: #fff !important;
    border-color: rgba(32, 139, 238, 0.46) !important;
    color: var(--pearl-primary) !important;
    box-shadow: 0 4px 12px rgba(0, 93, 167, 0.06);
  }

  button.ghost:hover:not(.active),
  button.function-btn:hover:not(.active),
  button.ghost:focus,
  button.function-btn:focus,
  button.ghost:focus-visible,
  button.function-btn:focus-visible,
  button.ghost:not(:active):not(.active):not(:hover),
  button.function-btn:not(:active):not(.active):not(:hover) {
    background: #fff !important;
    border-color: rgba(32, 139, 238, 0.56) !important;
    color: var(--pearl-primary) !important;
  }

  #btnDeleteData,
  .btn-danger {
    background: #fff0f0 !important;
    border-color: rgba(186, 26, 26, 0.22) !important;
    color: #ba1a1a !important;
    box-shadow: none;
  }

  #btnDeleteData:hover,
  .btn-danger:hover {
    background: #ffe3e3 !important;
  }

  #btnSearchMode {
    background: #edf6ff !important;
    border-color: rgba(32, 139, 238, 0.18) !important;
    color: var(--pearl-primary) !important;
    box-shadow: none;
  }

  .cloud-history-panel {
    border-color: var(--pearl-outline-soft);
    background: #fff;
    box-shadow: var(--pearl-shadow-soft);
  }

  .data-panel {
    margin-top: 18px;
    padding: 0;
    overflow: hidden;
    border-radius: 22px;
    background: var(--pearl-white);
  }

  .table-wrap {
    border-radius: 22px;
    background: #fff;
  }

  table {
    border-radius: 22px;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
  }

  thead,
  thead tr {
    background: #eef3f7;
  }

  th {
    height: 58px;
    color: #1f2a37;
    font-size: 14px;
    font-weight: 800;
  }

  td {
    height: 62px;
    color: var(--pearl-text);
    font-size: 14px;
  }

  th,
  td {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(192, 199, 213, 0.38);
  }

  tbody.zebra tr:nth-child(even) td {
    background: #fff;
  }

  tbody tr:hover td {
    background: linear-gradient(135deg, #ffffff, rgba(32, 139, 238, 0.045));
  }

  th.col-phone,
  td.col-phone {
    width: 142px;
    min-width: 142px;
    max-width: 142px;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap !important;
    word-break: keep-all;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  th.col-owner,
  td.col-owner,
  th.col-real,
  td.col-real {
    width: 96px !important;
    min-width: 96px !important;
    max-width: 96px !important;
  }

  th.col-note,
  td.col-note {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  td.col-cat select {
    height: 34px;
    border-radius: 10px;
    background: #eef3f7;
    border-color: transparent;
    color: #263241;
    font-weight: 650;
  }

  .actions-container .btn-mini,
  .actions-extra .btn-mini {
    height: 28px;
    min-height: 28px;
    border-radius: 999px;
    padding: 0 9px;
  }
}

@media (max-width: 1023px) {
  .app-sidebar {
    display: none !important;
  }

  .wrap {
    margin: 0 auto;
  }
}

/* 基础 */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: var(--font-main);
  font-weight: var(--font-weight); /* ✅ 优化：应用字体粗细设置 */
  -webkit-font-smoothing: antialiased;
  /* ✅ 移除移动端点击高亮 */
  -webkit-tap-highlight-color: transparent;
}

body {
  color: #111;
}

/* iOS 安全区顶部背景，确保独立模式与Safari状态栏视觉融合 */
@media (max-width: 768px) {
  .wrap {
    padding-top: 0; /* ✅ 移除 wrap 的 padding-top，避免与 topbar 的 padding-top 叠加 */
    padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
  }

  .panel {
    max-height: none !important;
    overflow: visible;
  }
  
  /* ✅ 确保 topbar 在所有手机型号下都紧贴状态栏 */
  .topbar {
    padding-top: calc(env(safe-area-inset-top) + 2px) !important;
  }
}

/* ✅ 修复：添加到主屏幕后（standalone 模式）调整间距，避免双重间距 */
@media (max-width: 768px) and (display-mode: standalone) {
  .wrap {
    padding-top: 0 !important; /* standalone 模式下，topbar 已经有 padding-top，不需要 wrap 的 */
  }
  
  /* standalone 模式下，确保 topbar 紧贴状态栏下方（统一所有iPhone型号） */
  .topbar {
    padding-top: calc(env(safe-area-inset-top) + 2px) !important;
  }
}

/* ✅ 修复：小屏幕 standalone 模式下的 topbar 间距 */
@media (max-width: 480px) and (display-mode: standalone) {
  .wrap {
    padding-top: 0 !important;
  }
  
  /* standalone 模式下，确保 topbar 紧贴状态栏下方（统一所有iPhone型号） */
  .topbar {
    padding-top: calc(env(safe-area-inset-top) + 2px) !important;
  }
}

/* 容器 */

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 10px 24px;
}

/* 顶部栏 */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px 10px;
  position: relative;
  z-index: 1;
  background: #ffffff;
}

.topbar .top-left {
  flex: 0 1 auto;
  min-width: 0;
}

.topbar .top-right {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  flex-shrink: 0;
}

#currentUserName {
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

#appTitle {
  font-size: 20px;
  font-weight: 650;
  margin: 0;
  margin-left: 2px; /* ✅ 向右移动2px */
}

/* ✅ 版本号样式（桌面端） */
#appVersion {
  font-size: 12px;
  color: #999;
  font-weight: normal;
  margin-left: 8px;
  vertical-align: baseline;
}

.app-version-pill {
  display: inline-flex;
  align-items: center;
  align-self: center;
  padding: 2px 7px;
  border: 1px solid rgba(32, 139, 238, 0.22);
  border-radius: 999px;
  background: rgba(230, 244, 255, 0.72);
  color: #4d6b86 !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  line-height: 1.2;
  white-space: nowrap;
}

/* ✅ 数据统计栏样式（桌面端和通用） */
.data-stats-bar,
#dataStatsBar.data-stats-bar,
div#dataStatsBar {
  background: #ffffff;
  padding: 4px 12px;
  font-size: 12px;
  color: #007aff;
  font-weight: normal;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.data-stats-bar span,
#dataStatsBar span {
  margin: 0 4px;
  color: #007aff;
  font-weight: normal;
}

.data-stats-bar .stats-separator,
#dataStatsBar .stats-separator {
  color: #ccc;
  margin: 0 8px;
}

.cloud-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  background: #f2f2f7;
  color: #111;
}

.save-status {
  display: none;
  align-items: center;
  max-width: 180px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef6ff;
  color: #1264a3;
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-status.show {
  display: inline-flex;
}

.save-status.success {
  background: #eaf8ef;
  color: #1f7a3a;
}

.save-status.warning {
  background: #fff6e5;
  color: #9a5b00;
}

.save-status.error {
  background: #ffecec;
  color: #b42318;
}

.save-status.info {
  background: #eef6ff;
  color: #1264a3;
}

#cloudDot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #30d158;
}

#cloudText {
  white-space: nowrap;
}

/* 面板 */

.panel {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
  padding: 10px 12px;
  margin-bottom: 10px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* 工具栏 */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.toolbar:last-child {
  margin-bottom: 0;
}

.toolbar-wrap {
  flex-wrap: wrap;
}

.status {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* 输入控件 */

input,
select,
button {
  font-family: inherit;
  font-size: 14px;
  line-height: 1.2;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 6px 12px;
  height: 32px;
  background: #ffffff;
  color: #111;
  outline: none;
  vertical-align: middle;
}

input::placeholder {
  color: #b0b0b8;
}

input:focus,
select:focus {
  border-color: var(--active);
  box-shadow: 0 0 0 1px rgba(0, 122, 255, 0.2);
}

/* ✅ 按钮失去焦点时不显示高亮 */
button:focus-visible {
  outline: none;
}

/* 下拉菜单统一白底 */

table select,
.m-detail-value select {
  background-color: #ffffff;
}

/* 文本输入宽度 */

#q {
  min-width: 220px;
  flex: 1 1 180px;
}

/* 搜索框清除按钮 */
.search-wrapper {
  position: relative;
  flex: 1 1 180px;
  min-width: 220px;
}

#clearSearch {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  display: none;
  color: #999;
  font-size: 20px;
  line-height: 1;
  user-select: none;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

#clearSearch:hover {
  background: #f0f0f0;
  color: #333;
}

#clearSearch.show {
  display: flex;
}

/* 标签式控件 */

.label-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #333;
}

/* ✅ 显示设置面板布局优化 */
#panelView .view-settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
  box-sizing: border-box;
}

#panelView .view-settings-row:last-child {
  margin-bottom: 0;
}

#panelView .view-settings-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #333;
  box-sizing: border-box;
  min-width: 0;
}

/* 2列布局：每个占50%减去gap */
#panelView .view-settings-item-2col {
  flex: 1 1 calc(50% - 4px);
  min-width: 120px;
  max-width: calc(50% - 4px);
}

/* 3列布局：每个占33.333%减去gap */
#panelView .view-settings-item-3col {
  flex: 1 1 calc(33.333% - 6px);
  min-width: 90px;
  max-width: calc(33.333% - 6px);
}

/* 确保输入框和选择框不会超出容器 */
#panelView .view-settings-item input,
#panelView .view-settings-item select {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* 按钮行样式 */
#panelView .view-settings-buttons {
  justify-content: center;
  gap: 12px;
}

#panelView .view-settings-btn {
  flex: 0 0 auto;
  min-width: 100px;
}

/* ✅ 按钮基础样式 */

button {
  cursor: pointer;
  transition: background-color .2s ease, color .2s ease, transform .15s ease, opacity .2s ease;
  position: relative;
}

button:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ✅ 功能按钮统一样式 - 默认蓝色 RGB(60, 120, 215) */
button.ghost,
button.function-btn {
  background: var(--btn-default) !important; /* RGB(60, 120, 215) */
  border-color: transparent;
  color: #fff;
  font-weight: 500;
}

/* ✅ 按钮激活状态（有active类时） */
button.ghost.active,
button.function-btn.active {
  background: var(--btn-active) !important;
  box-shadow: 0 2px 8px rgba(24, 144, 255, 0.3);
}

/* ✅ 按钮悬停状态（仅在鼠标悬停时） */
button.ghost:hover:not(.active),
button.function-btn:hover:not(.active) {
  background: var(--btn-hover) !important;
}

/* ✅ 按钮点击瞬间的状态 */
button.ghost:active:not(.active),
button.function-btn:active:not(.active) {
  background: var(--btn-active) !important;
}

/* ✅ 按钮失去焦点时恢复默认背景色（最高优先级） */
button.ghost:not(:active):not(.active):not(:hover),
button.function-btn:not(:active):not(.active):not(:hover) {
  background: var(--btn-default) !important;
}

/* ✅ 按钮失去焦点时恢复默认背景色，不显示高亮 */
button.ghost:focus,
button.function-btn:focus,
button.ghost:focus-visible,
button.function-btn:focus-visible {
  background: var(--btn-default) !important;
  outline: none;
  box-shadow: none;
  border-color: transparent;
}

/* ✅ 手机端：按钮点击后立即恢复默认背景色 */
@media (max-width: 768px) {
  /* ✅ 强制所有非激活状态的按钮使用默认背景色 */
  button.ghost,
  button.function-btn {
    background: var(--btn-default) !important;
  }
  
  button.ghost.active,
  button.function-btn.active {
    background: var(--btn-active) !important;
  }
  
  button.ghost:active,
  button.function-btn:active {
    background: var(--btn-default) !important;
  }
  
  button.ghost:hover:not(.active),
  button.function-btn:hover:not(.active) {
    background: var(--btn-hover) !important;
  }
  
  /* ✅ 失去焦点时强制恢复默认背景色 */
  button.ghost:not(:focus):not(.active):not(:hover):not(:active),
  button.function-btn:not(:focus):not(.active):not(:hover):not(:active) {
    background: var(--btn-default) !important;
  }
}

/* ✅ 主操作按钮（新增一行） */
button.primary {
  background: #1990FF;
  color: #fff;
  border-color: transparent;
  font-weight: 500;
}

button.primary:hover {
  background: #1478d7;
}

button.primary.active {
  background: #1990FF;
  box-shadow: 0 2px 8px rgba(25, 144, 255, 0.3);
}

button.primary:active {
  background: #1478d7;
}

/* ✅ iOS风格导入导出按钮 */
#menuImport,
#menuExport,
#menuClearAll,
#menuDeleteEmpty {
  display: block;
  width: auto;
  min-width: 100px;
  height: 36px;
  padding: 0 16px;
  text-align: center;
  margin: 4px 8px;
  background: rgb(32, 139, 238) !important; /* ✅ 优化：背景颜色改为 RGB(32, 139, 238) */
  color: #ffffff !important;
  border: none;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 500;
  line-height: 36px;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
}

#menuImport:hover,
#menuExport:hover,
#menuClearAll:hover,
#menuDeleteEmpty:hover {
  background: rgb(24, 120, 220) !important; /* ✅ 优化：hover 状态颜色稍深 */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  transform: translateY(-1px);
}

#menuImport:active,
#menuExport:active,
#menuClearAll:active,
#menuDeleteEmpty:active {
  background: rgb(20, 100, 200) !important; /* ✅ 优化：active 状态颜色更深 */
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

#importExportMenu,
#deleteDataMenu {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  border-top: none !important;
}

/* chip */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f2f2f7;
}

.colorDot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

/* 云端快照列表 */

.cloud-history-panel {
  margin-top: 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 4px 6px;
  max-height: 220px;
  overflow-y: auto;
  font-size: 13px;
}

.cloud-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 10px;
  cursor: pointer;
  gap: 10px;
  transition: background 0.15s ease;
}

.cloud-item + .cloud-item {
  margin-top: 2px;
}

.cloud-item:hover {
  background: #f2f6ff;
}

.cloud-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cloud-item-name {
  font-weight: 500;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cloud-item-meta {
  font-size: 11px;
  color: var(--muted);
}

.cloud-item-time {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.cloud-item.latest {
  background: #e6f3ff !important;
  border: 1px solid #1990FF;
}

.cloud-item.latest:hover {
  background: #d0e7ff !important;
}

.cloud-item-latest-badge {
  display: inline-block;
  background: #1990FF;
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 500;
}

/* 分类列表 */

#catList {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* 确保分类设置面板样式与其他面板一致 */
#panelCategories {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
  padding: 10px 12px;
  margin-bottom: 10px;
}

#panelCategories .toolbar {
  margin-bottom: 12px;
}

/* 分类行：强制垂直排列（所有屏幕尺寸） */
.cat-row {
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  border: 1px solid #e5e5ea;
  background: white;
  transition: background 0.15s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  align-items: stretch !important;
}

.cat-row:hover {
  background: #f5f5f7;
}

/* 第一排：序号、分类名称、颜色（强制水平排列） */
.cat-row-main {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 10px !important;
  width: 100% !important;
  flex-wrap: nowrap !important;
  box-sizing: border-box !important;
  order: 1 !important;
}

/* 序号：固定宽度，不收缩 */
.cat-index {
  font-size: 14px;
  color: #666;
  font-weight: 600;
  min-width: 35px;
  width: 35px;
  flex: 0 0 35px;
  flex-shrink: 0;
  text-align: center;
}

/* 分类名称：占据剩余空间 */
.cat-name {
  flex: 1 1 auto !important;
  min-width: 0;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 8px;
  outline: none;
  border: 1px solid #e5e5ea;
  background: #f9f9fb;
  transition: all 0.2s ease;
}

.cat-name:focus {
  background: white;
  border-color: #1990FF;
  box-shadow: 0 0 0 2px rgba(25, 144, 255, 0.1);
}

/* 颜色选择器：固定在右侧 */
.cat-color-input {
  position: relative;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  flex-shrink: 0;
}

.cat-color-preview {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  border: 2px solid #e5e5ea;
  display: block;
  pointer-events: none;
  box-sizing: border-box;
}

.cat-color-picker {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  margin: 0;
  padding: 0;
  border: none;
  z-index: 1;
}

/* 第二排：上移、下移、删除按钮（强制水平排列） */
.cat-actions {
  display: flex !important;
  flex-direction: row !important;
  gap: 8px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  margin-top: 0 !important;
  order: 2 !important;
}

.cat-actions button {
  flex: 1 1 0% !important;
  min-width: 0;
  padding: 8px 12px;
  font-size: 13px;
  white-space: nowrap;
  text-align: center;
  border-radius: 8px;
  font-weight: 500;
}

/* 移动端优化 */
@media (max-width: 768px) {
  .cat-row {
    padding: 10px;
    gap: 8px;
    flex-direction: column !important; /* 确保垂直排列 */
  }
  
  /* 第一排：序号、分类名称、颜色（水平排列） */
  .cat-row-main {
    display: flex !important;
    flex-direction: row !important; /* 确保水平排列 */
    align-items: center;
    gap: 8px;
    width: 100%;
    flex-wrap: nowrap;
  }
  
  /* 序号：固定宽度，不收缩 */
  .cat-index {
    font-size: 13px;
    min-width: 30px;
    width: 30px;
    flex: 0 0 30px !important;
    flex-shrink: 0 !important;
    text-align: center;
  }
  
  /* 分类名称：占据剩余空间 */
  .cat-name {
    flex: 1 1 auto !important;
    min-width: 0;
    font-size: 13px;
    padding: 6px 8px;
  }
  
  /* 颜色选择器：固定在右侧 */
  .cat-color-input {
    width: 36px;
    height: 36px;
    flex: 0 0 36px !important;
    flex-shrink: 0 !important;
  }
  
  /* 第二排：上移、下移、删除按钮（水平排列） */
  .cat-actions {
    display: flex !important;
    flex-direction: row !important; /* 确保水平排列 */
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
  }
  
  /* 按钮：平均分配宽度 */
  .cat-actions button {
    flex: 1 1 0% !important;
    min-width: 0;
    padding: 6px 8px;
    font-size: 12px;
    white-space: nowrap;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .cat-row {
    padding: 8px;
    gap: 6px;
    flex-direction: column !important; /* 确保垂直排列 */
  }
  
  /* 第一排：序号、分类名称、颜色（水平排列） */
  .cat-row-main {
    display: flex !important;
    flex-direction: row !important; /* 确保水平排列 */
    align-items: center;
    gap: 6px;
    width: 100%;
    flex-wrap: nowrap;
  }
  
  /* 序号：小屏幕优化 */
  .cat-index {
    font-size: 12px;
    min-width: 28px;
    width: 28px;
    flex: 0 0 28px !important;
    flex-shrink: 0 !important;
    text-align: center;
  }
  
  /* 分类名称：占据剩余空间 */
  .cat-name {
    flex: 1 1 auto !important;
    min-width: 0;
    font-size: 12px;
    padding: 5px 6px;
  }
  
  /* 颜色选择器：固定在右侧 */
  .cat-color-input {
    width: 32px;
    height: 32px;
    flex: 0 0 32px !important;
    flex-shrink: 0 !important;
  }
  
  /* 第二排：上移、下移、删除按钮（水平排列） */
  .cat-actions {
    display: flex !important;
    flex-direction: row !important; /* 确保水平排列 */
    gap: 4px;
    width: 100%;
    box-sizing: border-box;
  }
  
  /* 按钮：平均分配宽度 */
  .cat-actions button {
    flex: 1 1 0% !important;
    min-width: 0;
    padding: 5px 6px;
    font-size: 11px;
    white-space: nowrap;
    text-align: center;
  }
  
  /* 确保所有元素在小屏幕上都能正常显示 */
  .cat-row-main,
  .cat-actions {
    overflow: visible;
  }
  
  .cat-name {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* 桌面表格 */

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--cell-alt);
}

thead tr {
  background: var(--cell-alt);
}

th,
td {
  padding: var(--pad) 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.2s ease;
}

th {
  font-weight: 500;
  color: #555;
}

/* 隔行着色（桌面） */

tbody.zebra tr:nth-child(even) td {
  background: var(--zebra);
}

/* hover 行 */

tbody tr:hover td {
  background: #e9f3ff;
}

/* 列宽 */

th.col-phone,
td.col-phone {
  width: calc(var(--w-phone) * var(--colScale));
}

th.col-owner,
td.col-owner {
  width: 55px !important; /* ✅ 优化：固定宽度55px，不受colScale影响 */
  min-width: 55px !important;
  max-width: 55px !important;
}

th.col-real,
td.col-real {
  width: 55px !important; /* ✅ 优化：固定宽度55px，不受colScale影响 */
  min-width: 55px !important;
  max-width: 55px !important;
}

th.col-wx,
td.col-wx {
  width: calc(var(--w-wx) * var(--colScale));
}

/* ✅ 小红书名称：桌面左对齐，显示12个汉字 */
th.col-xhs,
td.col-xhs {
  width: calc(var(--w-xhs) * var(--colScale));
  text-align: left; /* ✅ 优化：改为左对齐 */
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th.col-platforms,
td.col-platforms {
  width: 150px;
  min-width: 150px;
  max-width: 150px;
  overflow: hidden;
}

/* ✅ 备注列：宽度与小红书名称列一致 */
th.col-note,
td.col-note {
  width: calc(var(--w-xhs) * var(--colScale)); /* ✅ 优化：与小红书名称列宽度一致 */
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

th.col-cat,
td.col-cat {
  width: calc(var(--w-cat) * var(--colScale));
  min-width: 140px; /* ✅ 优化：确保分类下拉按钮完整显示 */
}

th.col-act,
td.col-act {
  width: calc(var(--w-actions) * var(--colScale));
  min-width: 120px; /* ✅ 优化：确保操作按钮完整显示 */
  overflow: visible; /* ✅ 优化：防止按钮被截断 */
  white-space: nowrap; /* ✅ 优化：防止按钮换行 */
}

/* 表格内联编辑 */

td[contenteditable="true"] {
  cursor: text;
}

td[contenteditable="true"]:focus-visible {
  outline: 2px solid rgba(0, 122, 255, 0.35);
  outline-offset: -2px;
  background: #ffffff !important;
}

/* ✅ 分类单元格 - 增强可点击性 */

td.col-cat select {
  width: 100%;
  min-width: 80px; /* ✅ 优化：增加最小宽度，确保至少显示2个中文字 */
  max-width: 100%; /* ✅ 优化：限制最大宽度，防止溢出 */
  font-size: 13px;
  height: 32px;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.5;
  box-sizing: border-box; /* ✅ 优化：确保padding不会导致溢出 */
}

td.col-cat select:hover {
  border-color: var(--btn-active);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}

td.col-cat select:focus {
  border-color: var(--btn-active);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
  outline: none;
}

/* 操作列（桌面） */

.actions-container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow: visible; /* ✅ 优化：防止按钮被截断 */
  white-space: nowrap; /* ✅ 优化：防止按钮换行 */
}

.actions-extra {
  display: inline-flex;
  gap: 4px;
  margin-left: 4px;
}

.actions-extra.hidden {
  display: none;
}

.actions-container .btn-mini,
.actions-extra .btn-mini {
  padding: 2px 6px;
  height: 24px;
  font-size: 12px;
  border-radius: 999px;
  overflow: visible; /* ✅ 优化：防止按钮文字被截断 */
  white-space: nowrap; /* ✅ 优化：防止按钮文字换行 */
  text-overflow: clip; /* ✅ 优化：不使用省略号，直接显示完整文字 */
}

/* ✅ 删除按钮改为普通样式 */
.btn-danger {
  background: var(--btn-default);
  border-color: transparent;
  color: #fff;
}

.btn-danger:hover {
  background: #ff4d4f;
}

.btn-danger:active {
  background: #d9363e;
}

/* 桌面 / 手机显示切换 */

.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

/* 手机版折叠列表卡片 */

.m-row {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card-bg, #fff);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.2s ease, transform 0.1s ease;
  color: #111;
  /* ✅ 移除点击时的边框变化 */
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}

.m-row:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

/* ✅ 移除所有焦点和激活状态下的边框变化和轮廓 */
.m-row:focus,
.m-row:focus-visible,
.m-row:focus-within,
.m-row:active {
  outline: none !important;
  border: 1px solid var(--line) !important; /* 保持原有边框，不改变颜色或宽度 */
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important; /* 保持原有阴影 */
  -webkit-tap-highlight-color: transparent !important;
}

.m-row:active {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08) !important; /* 点击时使用hover的阴影 */
  border: 1px solid var(--line) !important; /* 确保点击时边框不变 */
}

/* ✅ 确保内部按钮获得焦点时，父元素不显示额外边框 */
.m-row:focus-within {
  border: 1px solid var(--line) !important;
  outline: none !important;
}

/* 卡片头 */

.m-row-header {
  width: 100%;
  border: none;
  background: transparent;
  padding: 16px 18px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  color: inherit;
  height: auto;
  border-radius: 0;
  /* ✅ 移除所有焦点样式，防止点击时出现焦点轮廓 */
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.m-row:hover .m-row-header {
  background: transparent; /* ✅ 取消悬停时的蓝色背景 */
  color: inherit; /* ✅ 保持原色 */
}

/* ✅ 确保 .m-phone 不受悬停效果影响，保持原色 */
.m-row:hover .m-row-header .m-phone {
  color: inherit; /* 继承父元素颜色，但可以通过其他方式覆盖 */
}

.m-row:active .m-row-header,
.m-row-header:active {
  background: transparent; /* ✅ 取消点击时的蓝色背景 */
  color: inherit; /* ✅ 保持原色 */
  outline: none !important; /* ✅ 确保点击时没有焦点轮廓 */
}

/* ✅ 移除所有焦点状态下的样式 */
.m-row-header:focus,
.m-row-header:focus-visible,
.m-row-header:focus-within {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}

/* 头部主行：手机号 + 小红书名称 */

.m-main-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

.m-phone {
  font-size: 20px;
  font-weight: 600;
  flex: 0 0 auto;
  pointer-events: none; /* ✅ 取消鼠标悬停效果 */
  color: #111 !important; /* ✅ 强制保持原色，不受父元素悬停影响 */
}

/* ✅ 小红书名称：移动端右对齐，尽量完整显示 */
.m-xhs {
  font-size: 14px;
  color: #333;
  max-width: none; /* ✅ 移除宽度限制，尽量完整显示 */
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  margin-left: auto;
  text-align: right;
  flex: 1 1 auto;
}

/* 头部第二行：所属人标签 + 分类 pill */

.m-meta-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  width: 100%;
  padding-left: 0; /* ✅ 优化：移除左边距，确保与电话号左对齐 */
}

.m-owner {
  padding: 2px 8px 2px 0; /* ✅ 优化：移除左边距，确保与电话号左对齐 */
  border-radius: 999px;
  background: transparent; /* ✅ 优化：背景色调整为透明，与表格背景一致 */
  color: #333;
  font-size: 14px;
}

/* ✅ 分类 pill - 根据分类颜色动态设置，右对齐 */
.m-cat-pill {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(0, 122, 255, 0.09);
  transition: background 0.3s ease;
  margin-left: auto;
  text-align: right;
}

.platform-preview-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 34px;
  padding: 4px 0;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  color: inherit;
  cursor: pointer;
}

.platform-preview-trigger {
  justify-content: flex-start;
  overflow: hidden;
}

.platform-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 84px;
  padding: 3px 8px;
  border: 1px solid rgba(32, 139, 238, 0.22);
  border-radius: 999px;
  background: #edf6ff;
  color: var(--pearl-primary);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.platform-chip.is-empty {
  border-color: rgba(192, 199, 213, 0.54);
  background: #f6f8fb;
  color: #7a8494;
}

.platform-chip.is-more {
  background: #fff;
  color: #405062;
}

.mobile-platform-section {
  margin: 10px 0;
  padding: 12px;
  border: 1px solid rgba(192, 199, 213, 0.5);
  border-radius: 16px;
  background: #f7fbff;
}

.mobile-platform-section.platform-dirty,
.m-row.platform-modified .mobile-platform-section {
  border-color: rgba(255, 159, 10, 0.42);
  background: #fffaf0;
}

.mobile-platform-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--pearl-primary);
  font-size: 14px;
  font-weight: 850;
}

.mobile-platform-open {
  width: auto !important;
  min-width: 76px !important;
  min-height: 30px !important;
  height: 30px !important;
  padding: 0 10px !important;
  border: 1px solid rgba(32, 139, 238, 0.32) !important;
  border-radius: 999px !important;
  background: #fff !important;
  color: var(--pearl-primary) !important;
  font-size: 12px !important;
  font-weight: 800 !important;
  box-shadow: none !important;
}

.mobile-platform-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mobile-platform-item {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(192, 199, 213, 0.48);
  border-radius: 13px;
  background: #fff;
}

.mobile-platform-item.is-filled {
  border-color: rgba(32, 139, 238, 0.28);
  background: #edf6ff;
}

.mobile-platform-label {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-platform-label {
  color: var(--pearl-primary);
  font-size: 12px;
  font-weight: 850;
}

.mobile-platform-input {
  width: 100%;
  min-height: 34px;
  margin-top: 5px;
  padding: 6px 8px;
  border: 1px solid rgba(192, 199, 213, 0.54) !important;
  border-radius: 10px !important;
  background: #fff !important;
  color: #263241;
  font-size: 13px;
}

.mobile-platform-input[readonly] {
  background: rgba(255, 255, 255, 0.72) !important;
}

.mobile-platform-item.is-empty .mobile-platform-input::placeholder {
  color: #8a94a3;
}

.mobile-platform-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.mobile-platform-status {
  min-width: 0;
  color: #7a4d00;
  font-size: 12px;
  font-weight: 800;
}

.mobile-platform-save {
  width: auto !important;
  min-width: 104px !important;
  min-height: 34px !important;
  height: 34px !important;
  padding: 0 12px !important;
  border-color: rgba(32, 139, 238, 0.32) !important;
  color: var(--pearl-primary) !important;
}

.platform-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 5200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 32, 48, 0.26);
  backdrop-filter: blur(8px);
}

.platform-preview-panel {
  width: min(860px, calc(100vw - 96px));
  min-height: 360px;
  max-height: min(76vh, 620px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid rgba(192, 199, 213, 0.72);
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 253, 0.95)),
    #fff;
  box-shadow: 0 22px 60px rgba(0, 52, 100, 0.22);
  padding: 18px;
}

.platform-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.platform-preview-title {
  color: var(--pearl-primary);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 850;
}

.platform-preview-subtitle {
  margin-top: 4px;
  color: #657081;
  font-size: 12px;
  line-height: 1.45;
}

.platform-preview-close {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  background: #fff !important;
  color: #405062 !important;
  box-shadow: none;
}

.platform-preview-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.platform-preview-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid rgba(192, 199, 213, 0.54);
  border-radius: 14px;
  background: #fff;
}

.platform-preview-row.is-filled {
  border-color: rgba(32, 139, 238, 0.26);
  background: #f0f8ff;
}

.platform-preview-label {
  color: var(--pearl-primary);
  font-weight: 850;
}

.platform-preview-input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid rgba(192, 199, 213, 0.54) !important;
  border-radius: 11px !important;
  background: #fff !important;
  color: #263241;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.platform-preview-input[readonly] {
  background: rgba(255, 255, 255, 0.72) !important;
}

.platform-preview-panel.platform-dirty {
  border-color: rgba(255, 159, 10, 0.38);
}

.platform-preview-row.is-empty .platform-preview-input::placeholder {
  color: #8a94a3;
}

.platform-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.platform-preview-actions button {
  min-width: 120px;
}

.platform-manager-modal {
  position: fixed;
  inset: 0;
  z-index: 5300;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 32, 48, 0.28);
  backdrop-filter: blur(8px);
}

.platform-manager-panel {
  width: min(720px, calc(100vw - 48px));
  max-height: min(80vh, 680px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  border: 1px solid rgba(192, 199, 213, 0.72);
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 253, 0.95)),
    #fff;
  box-shadow: 0 22px 60px rgba(0, 52, 100, 0.22);
  padding: 18px;
}

.platform-manager-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.platform-manager-title {
  color: var(--pearl-primary);
  font-size: 20px;
  font-weight: 850;
}

.platform-manager-subtitle {
  margin-top: 4px;
  color: #657081;
  font-size: 12px;
  line-height: 1.45;
}

.platform-manager-close {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  background: #fff !important;
  color: #405062 !important;
  box-shadow: none;
}

.platform-manager-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 10px;
}

.platform-manager-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.platform-manager-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 76px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(192, 199, 213, 0.48);
  border-radius: 14px;
  background: #fff;
}

.platform-manager-delete {
  border-color: rgba(186, 26, 26, 0.22) !important;
  color: #a61919 !important;
}

.platform-manager-delete:disabled {
  opacity: 0.45;
}

.platform-manager-note {
  padding: 10px 12px;
  border-radius: 14px;
  background: #f6f8fb;
  color: #657081;
  font-size: 12px;
  line-height: 1.5;
}

.platform-preview-note {
  padding: 10px 12px;
  border-radius: 14px;
  background: #f6f8fb;
  color: #657081;
  font-size: 12px;
  line-height: 1.5;
}

.import-export-modal {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(18, 38, 56, 0.22);
}

.import-export-panel {
  width: min(420px, 100%);
  border: 1px solid rgba(192, 199, 213, 0.62);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.99), rgba(246, 250, 254, 0.96));
  box-shadow: 0 22px 52px rgba(0, 64, 116, 0.18);
  padding: 16px;
}

.import-export-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.import-export-title {
  color: #15324a;
  font-size: 20px;
  font-weight: 850;
}

.import-export-subtitle {
  margin-top: 4px;
  color: #657081;
  font-size: 13px;
  line-height: 1.4;
}

.import-export-close {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(32, 139, 238, 0.24);
  border-radius: 12px;
  background: #edf6ff;
  color: var(--pearl-primary);
  font-size: 20px;
  line-height: 1;
}

.import-export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.import-export-actions button {
  min-height: 44px;
  border-radius: 13px;
  font-weight: 850;
}

@media (max-width: 520px) {
  .import-export-actions {
    grid-template-columns: 1fr;
  }
}

.ai-assistant-panel[hidden] {
  display: none !important;
}

.ai-assistant-panel {
  display: grid;
  gap: 16px;
  max-width: min(1180px, 100%);
}

.ai-hero,
.ai-card {
  border: 1px solid rgba(192, 199, 213, 0.62);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(255,255,255,0.99), rgba(246,250,254,0.96));
  box-shadow: 0 14px 34px rgba(0, 93, 167, 0.08);
}

.ai-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
}

.ai-eyebrow {
  margin: 0 0 6px;
  color: var(--pearl-primary);
  font-size: 12px;
  font-weight: 850;
}

.ai-hero h2,
.ai-card h3 {
  margin: 0;
  color: #15324a;
  letter-spacing: 0;
}

.ai-hero h2 {
  font-size: 26px;
}

.ai-hero p,
.ai-card p,
.ai-safe-note {
  margin: 5px 0 0;
  color: #657081;
  line-height: 1.5;
}

.ai-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
}

.ai-card {
  min-width: 0;
  padding: 16px;
}

.ai-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

#aiUserInput {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 1px solid rgba(192, 199, 213, 0.72);
  border-radius: 15px;
  background: #fff;
  padding: 12px 14px;
  color: #263241;
  font: inherit;
  box-sizing: border-box;
}

.ai-actions,
.ai-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.ai-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 13px;
}

.ai-examples button,
.ai-status-pill {
  border: 1px solid rgba(32, 139, 238, 0.24);
  border-radius: 999px;
  background: #edf6ff;
  color: var(--pearl-primary);
  font-size: 12px;
  font-weight: 800;
}

.ai-examples button {
  min-height: 32px;
  padding: 0 11px;
}

.ai-status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  white-space: nowrap;
}

.ai-status-pill.success {
  border-color: rgba(48, 209, 88, 0.35);
  background: rgba(48, 209, 88, 0.12);
  color: #177a32;
}

.ai-status-pill.warning,
.ai-status-pill.error {
  border-color: rgba(255, 59, 48, 0.28);
  background: rgba(255, 59, 48, 0.08);
  color: #b42318;
}

.ai-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ai-settings-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: #506070;
  font-size: 12px;
  font-weight: 800;
}

.ai-settings-grid input,
.ai-settings-grid select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid rgba(192, 199, 213, 0.72);
  border-radius: 12px;
  background: #fff;
  padding: 0 10px;
  color: #263241;
  box-sizing: border-box;
}

.ai-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: #405062;
  font-size: 13px;
  font-weight: 750;
}

.ai-result-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(192, 199, 213, 0.46);
}

.ai-result-toolbar > div:first-child {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: #657081;
  font-size: 13px;
}

.ai-result-toolbar strong {
  color: var(--pearl-primary);
}

.ai-results-empty {
  padding: 28px 10px;
  color: #7a8494;
  text-align: center;
}

.ai-results-list {
  display: grid;
  gap: 10px;
  margin-top: 13px;
}

.ai-result-item {
  min-width: 0;
  border: 1px solid rgba(192, 199, 213, 0.48);
  border-radius: 15px;
  background: #fff;
  padding: 13px;
}

.ai-result-item.ai-result-warning {
  border-color: rgba(255, 149, 0, 0.35);
  background: rgba(255, 248, 235, 0.78);
}

.ai-confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.ai-result-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-result-main strong {
  color: var(--pearl-primary);
  font-family: var(--font-mono);
  font-size: 16px;
  white-space: nowrap;
}

.ai-result-main span {
  min-width: 0;
  overflow: hidden;
  color: #405062;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-result-fields,
.ai-result-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.ai-result-fields span,
.ai-result-reasons span {
  max-width: 100%;
  border-radius: 999px;
  padding: 5px 8px;
  background: #f4f7fa;
  color: #506070;
  font-size: 12px;
}

.ai-result-reasons span {
  background: #edf6ff;
  color: var(--pearl-primary);
  font-weight: 800;
}

.ai-result-note {
  margin: 10px 0 0;
  border-radius: 12px;
  background: #f7f9fc;
  padding: 9px 10px;
  color: #405062;
}

.ai-summary-panel {
  margin-top: 14px;
  border: 1px solid rgba(32, 139, 238, 0.22);
  border-radius: 15px;
  background: #f0f8ff;
  padding: 14px;
  color: #263241;
}

.ai-summary-panel pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  font: inherit;
}

@media (max-width: 1024px) {
  .ai-grid {
    grid-template-columns: 1fr;
  }

  .ai-result-toolbar {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .ai-assistant-panel {
    gap: 12px;
  }

  .ai-hero,
  .ai-card {
    border-radius: 16px;
    padding: 13px;
  }

  .ai-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .ai-hero h2 {
    font-size: 22px;
  }

  .ai-settings-grid {
    grid-template-columns: 1fr;
  }

  .ai-actions > button,
  .ai-result-actions > button {
    flex: 1 1 140px;
  }
}

@media (max-width: 767px) {
  .platform-preview-modal {
    display: flex;
    align-items: flex-end;
    justify-content: stretch;
    padding: 12px;
  }

  .platform-preview-panel {
    width: 100%;
    min-height: 0;
    max-height: 86vh;
    border-radius: 18px;
    padding: 15px;
  }

  .platform-preview-list {
    grid-template-columns: 1fr;
  }

  .platform-preview-note {
    margin-top: auto;
  }

  .platform-manager-modal {
    align-items: flex-end;
    padding: 12px;
  }

  .platform-manager-panel {
    width: 100%;
    max-height: 86vh;
    border-radius: 18px;
    padding: 15px;
  }

  .platform-manager-add,
  .platform-manager-row {
    grid-template-columns: 1fr;
  }
}

/* 下拉箭头 */

.m-arrow {
  font-size: 14px;
  transform-origin: center;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.m-row.open .m-arrow {
  transform: rotate(180deg);
}

/* 手机详情区域 */

.m-row-details {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0 18px;
  border-top: 1px solid var(--line);
  background: #fff;
  transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
}

.m-row.open .m-row-details {
  max-height: 1200px; /* ✅ 增加最大高度以容纳所有内容（包括新增的 textarea 和底部按钮） */
  opacity: 1;
  padding: 10px 18px 22px; /* ✅ 增加下方padding 12px -> 22px (+10px) */
}

.m-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center; /* ✅ 优化：改为 center 确保垂直对齐 */
  gap: 10px; /* ✅ 优化：增加间距，提高可读性 */
  margin-bottom: 1px; /* ✅ 优化：每组和下方的高度距离改为1px */
  min-height: 44px; /* ✅ 优化：设置最小高度，确保对齐一致 */
}

.m-detail-label {
  font-size: 13px; /* ✅ 优化：稍微增大字体，提高可读性 */
  color: var(--muted);
  flex: 0 0 85px; /* ✅ 优化：稍微增加宽度，确保文字完整显示 */
  padding-top: 0; /* ✅ 优化：移除 padding-top，确保对齐 */
  line-height: 1.6; /* ✅ 优化：增加行高，与输入框对齐 */
  display: flex; /* ✅ 优化：使用 flex 确保垂直居中 */
  align-items: center; /* ✅ 优化：垂直居中对齐 */
}

.m-detail-value {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  border-radius: 10px;
  padding: 4px 8px;
  background: transparent; /* ✅ 优化：删除灰色背景 */
  transition: background 0.2s ease;
}

/* ✅ 备注输入框设为2行高度，可调整大小 */
.m-detail-value[data-field="note1"] {
  min-height: 42px;
  resize: vertical;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* 手机端可编辑文本 */

.m-detail-value[contenteditable="true"] {
  cursor: text;
}

.m-detail-value[contenteditable="true"]:focus-visible {
  outline: 2px solid rgba(0, 122, 255, 0.35);
  background: #ffffff !important;
}

/* ✅ 移动端输入框样式 */
.m-input,
.m-textarea {
  width: 100%;
  padding: 3px 12px; /* ✅ 优化：上下内边距改为3px */
  border: 1px solid #e5e5ea;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #ffffff;
  transition: all 0.2s ease;
  box-sizing: border-box;
  line-height: 24px; /* ✅ 优化：内容区域高度22-25px，设置为24px */
}

/* ✅ 统一小红书名称输入框大小 - 使用 textarea */
.m-textarea[data-field="xhs_name"] {
  min-height: 50px;
  line-height: 24px;
  padding: 8px 12px;
  resize: vertical;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.m-input:focus,
.m-textarea:focus {
  outline: none;
  border-color: #1990FF;
  box-shadow: 0 0 0 3px rgba(25, 144, 255, 0.1);
  background: #ffffff;
}

.m-textarea {
  resize: vertical;
  min-height: 50px;
  line-height: 24px; /* ✅ 优化：内容区域高度22-25px，设置为24px */
}

/* ✅ 移动端分类选择器增强 */
.m-detail-value select {
  width: 100%;
  padding: 3px 12px; /* ✅ 优化：上下内边距改为3px */
  border: 1px solid #e5e5ea;
  border-radius: 10px;
  font-size: 14px;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 45px; /* ✅ 优化：高度设置为45px */
  height: 45px; /* ✅ 优化：固定高度45px */
  line-height: 24px; /* ✅ 优化：内容区域高度22-25px，设置为24px */
  box-sizing: border-box; /* ✅ 优化：确保内边距计算正确 */
}

.m-detail-value select:hover {
  border-color: var(--btn-active);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}

.m-detail-value select:focus {
  border-color: var(--btn-active);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
  outline: none;
}

/* ✅ 卡片修改状态标识 */
.m-row.modified {
  border-color: #ff9f0a;
  box-shadow: 0 0 0 2px rgba(255, 159, 10, 0.15);
}

.m-row.modified .m-row-header {
  background: #fff9f0;
}

/* 底部操作区域（手机）*/

.m-actions {
  border-top: 1px solid var(--line);
  padding: 6px 12px 10px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  background: #ffffff; /* ✅ 改为白色背景 */
  flex-wrap: wrap; /* ✅ 允许按钮换行 */
  min-height: 50px; /* ✅ 增加最小高度，确保有足够空间 */
}

.m-actions button {
  height: 26px;
  padding: 2px 12px; /* ✅ 稍微减少内边距以适应小屏幕 */
  font-size: 12px;
  min-width: 50px; /* ✅ 稍微减少最小宽度 */
  flex: 0 0 auto; /* ✅ 防止按钮被压缩 */
}

/* 小屏优化 */

@media (max-width: 1024px) {
  .wrap {
    padding: 10px 8px 20px;
  }
}

@media (max-width: 768px) {
  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: block;
  }

  .panel {
    border-radius: 12px;
    padding: 12px 10px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  .topbar {
    padding-top: calc(env(safe-area-inset-top) + 2px) !important; /* ✅ 统一所有手机型号，紧贴状态栏 */
    padding-bottom: 6px;
    padding-left: 10px;
    padding-right: 10px;
    position: static;
    top: auto;
    z-index: auto;
    flex-wrap: wrap;
  }

  .topbar .top-left {
    flex: 1;
    min-width: 0;
  }

  .topbar .top-right {
    display: flex !important;
    align-items: center;
    flex-wrap: nowrap;
    gap: 4px;
    flex-shrink: 0;
    min-width: 0;
  }

  .topbar .top-right #currentUserName {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    font-size: 12px;
    margin-right: 6px;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    flex-shrink: 0;
    min-width: 60px;
    text-align: right;
  }

  .topbar .top-right #btnLogout {
    font-size: 12px;
    padding: 3px 10px;
    height: auto;
  }

  .topbar .top-right #cloudStatus {
    font-size: 11px;
    padding: 3px 8px;
  }

  /* ✅ 确保手机端（768px）最新快照高亮和标记正常显示 */
  .cloud-item.latest {
    background: #e6f3ff !important;
    border: 1px solid #1990FF !important;
  }

  .cloud-item-latest-badge {
    display: inline-block !important;
    background: #1990FF !important;
    color: white !important;
    font-size: 10px !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    margin-left: 6px !important;
    font-weight: 500 !important;
    white-space: nowrap !important;
  }

  /* ✅ 手机端新增号码模态框样式优化 */
  .add-number-modal {
    padding: 10px !important;
  }

  .add-number-modal > div {
    max-width: 100% !important;
    max-height: 95vh !important;
    padding: 15px !important;
  }

  .wrap {
    padding-top: 0 !important; /* ✅ 移除 wrap 的 padding-top，避免与 topbar 的 padding-top 叠加，统一所有手机型号 */
    padding-bottom: calc(env(safe-area-inset-bottom) + 24px) !important;
  }

  /* ✅ 确保 topbar 紧贴状态栏下方（统一所有iPhone型号，无空白间距） */
  .topbar {
    margin-top: 0;
    padding-top: calc(env(safe-area-inset-top) + 2px) !important;
  }

  #appTitle {
    font-size: 18px;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  /* ✅ 版本号样式（移动端） */
  #appVersion {
    font-size: 11px !important;
    margin-left: 6px !important;
  }

  /* ✅ 数据统计栏样式（移动端）- 使用ID选择器提高优先级 */
  #dataStatsBar.data-stats-bar,
  div#dataStatsBar,
  .data-stats-bar#dataStatsBar {
    font-size: 11px !important;
    padding: 3px 10px !important;
    color: #007aff !important; /* ✅ 确保移动端也是蓝色 */
    font-weight: normal !important; /* ✅ 确保不是粗体 */
    text-align: center !important; /* ✅ 确保居中对齐 */
    background: #ffffff !important; /* ✅ 确保白色背景 */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    line-height: 1.4 !important;
  }
  
  /* ✅ 数据统计栏内的所有元素样式（移动端）- 使用更具体的选择器 */
  #dataStatsBar.data-stats-bar span,
  #dataStatsBar.data-stats-bar #totalDataCount,
  #dataStatsBar.data-stats-bar #statsVersion,
  #dataStatsBar.data-stats-bar .stats-separator,
  div#dataStatsBar span,
  div#dataStatsBar #totalDataCount,
  div#dataStatsBar #statsVersion,
  div#dataStatsBar .stats-separator {
    color: #007aff !important;
    font-weight: normal !important;
    font-size: 11px !important;
    line-height: 1.4 !important;
    margin: 0 4px !important;
    display: inline-block !important;
  }
  
  /* ✅ 分隔符特殊样式 */
  #dataStatsBar .stats-separator {
    color: #ccc !important;
    margin: 0 8px !important;
  }

  /* ✅ 优化：手机端字体默认粗体 */
  body {
    font-weight: bold !important;
  }

  .toolbar {
    gap: 6px;
    margin-bottom: 8px;
  }

  .toolbar:last-child {
    margin-bottom: 0;
  }

  input,
  select,
  button {
    font-size: 13px;
    height: 32px;
    padding: 6px 10px;
    border-radius: 8px;
  }

  /* 防止手机端点击输入框时自动放大 */
  #q {
    font-size: 16px !important;
    padding: 8px 36px 8px 12px;
    height: 36px;
  }

  /* 防止手机端列表输入框自动放大 - 所有输入框字体至少16px */
  .m-input,
  .m-textarea,
  .m-detail-value[contenteditable="true"] {
    font-size: 16px !important;
    line-height: 1.5;
  }

  .m-detail-value select {
    font-size: 16px !important;
  }

  /* 调整输入框padding以适应16px字体 */
  .m-input {
    padding: 8px 12px;
    min-height: 44px;
  }

  .m-textarea {
    padding: 8px 12px;
    line-height: 1.5;
  }

  .m-detail-value[contenteditable="true"] {
    padding: 8px 12px;
    min-height: 44px;
  }

  .search-wrapper {
    min-width: 0;
    flex: 1 1 100%;
    margin-bottom: 6px;
  }

  /* 按钮在手机端优化 */
  .toolbar button {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    padding: 6px 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 下拉框在手机端优化 */
  .toolbar select {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    padding: 6px 10px;
  }

  /* 第一行工具栏：搜索和筛选 - 重新布局 */
  .toolbar:first-of-type {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* 搜索框和搜索按钮在同一行 */
  .toolbar:first-of-type .search-wrapper {
    flex: 1 1 calc(100% - 140px);
    min-width: 0;
    margin-bottom: 0;
    order: 1;
  }

  .toolbar:first-of-type #btnSearchMode {
    flex: 0 0 130px;
    white-space: nowrap;
    margin-bottom: 0;
    order: 2;
  }

  /* 三个下拉框在同一行，放在搜索行下面 */
  .toolbar:first-of-type select {
    flex: 1 1 calc(33.333% - 4px);
    min-width: 0;
    margin-bottom: 0;
    order: 3;
  }

  /* 第二行工具栏：按钮网格布局 - 4列，2行 */
  .toolbar:nth-of-type(2) {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .toolbar:nth-of-type(2) button,
  .toolbar:nth-of-type(2) > div {
    width: 100%;
    max-width: 100%;
    flex: 1 1 100%;
  }

  th,
  td {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .wrap {
    padding-top: 0 !important; /* ✅ 移除 wrap 的 padding-top，避免与 topbar 的 padding-top 叠加，统一所有手机型号 */
    padding-left: 6px !important;
    padding-right: 6px !important;
    padding-bottom: calc(env(safe-area-inset-bottom) + 16px) !important;
  }

  /* ✅ 确保 topbar 紧贴状态栏下方（统一所有iPhone型号，无空白间距） */
  .topbar {
    padding-top: calc(env(safe-area-inset-top) + 2px) !important;
    padding-left: 8px;
    padding-right: 8px;
  }

  .panel {
    border-radius: 10px;
    padding: 10px 8px;
    margin-bottom: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  .topbar .top-right #currentUserName {
    font-size: 11px;
    margin-right: 4px;
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    min-width: 50px;
    text-align: right;
  }

  .topbar .top-right #btnLogout {
    font-size: 11px;
    padding: 2px 8px;
  }

  .topbar .top-right #cloudStatus {
    font-size: 10px;
    padding: 2px 6px;
  }

  /* ✅ 确保手机端最新快照高亮和标记正常显示 */
  .cloud-item.latest {
    background: #e6f3ff !important;
    border: 1px solid #1990FF !important;
  }

  .cloud-item-latest-badge {
    display: inline-block !important;
    background: #1990FF !important;
    color: white !important;
    font-size: 10px !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    margin-left: 6px !important;
    font-weight: 500 !important;
    white-space: nowrap !important;
  }

  /* ✅ 数据统计栏样式（小屏幕移动端）- 确保所有安卓设备正确显示 */
  #dataStatsBar.data-stats-bar,
  div#dataStatsBar,
  .data-stats-bar#dataStatsBar {
    font-size: 11px !important;
    padding: 3px 10px !important;
    color: #007aff !important;
    font-weight: normal !important;
    text-align: center !important;
    background: #ffffff !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    line-height: 1.4 !important;
  }
  
  #dataStatsBar.data-stats-bar span,
  #dataStatsBar.data-stats-bar #totalDataCount,
  #dataStatsBar.data-stats-bar #statsVersion,
  #dataStatsBar.data-stats-bar .stats-separator,
  div#dataStatsBar span,
  div#dataStatsBar #totalDataCount,
  div#dataStatsBar #statsVersion,
  div#dataStatsBar .stats-separator {
    color: #007aff !important;
    font-weight: normal !important;
    font-size: 11px !important;
    line-height: 1.4 !important;
    margin: 0 4px !important;
    display: inline-block !important;
  }
  
  #dataStatsBar .stats-separator {
    color: #ccc !important;
    margin: 0 8px !important;
  }

  .cloud-item-name {
    white-space: normal !important;
    word-break: break-word !important;
  }
  
  /* ✅ 小屏幕手机端设置页面布局优化 */
  #panelView .view-settings-row {
    gap: 6px;
    margin-bottom: 10px;
  }
  
  #panelView .view-settings-item-2col {
    flex: 1 1 calc(50% - 3px) !important;
    min-width: 100px !important;
    max-width: calc(50% - 3px) !important;
  }
  
  #panelView .view-settings-item-3col {
    flex: 1 1 calc(33.333% - 4px) !important;
    min-width: 80px !important;
    max-width: calc(33.333% - 4px) !important;
  }
  
  #panelView .view-settings-buttons {
    justify-content: center;
    gap: 8px;
  }
  
  #panelView .view-settings-btn {
    flex: 0 0 auto;
    min-width: 100px;
  }

  /* ✅ 手机端新增号码模态框样式优化 */
  .add-number-modal {
    padding: 10px !important;
  }

  .add-number-modal > div {
    max-width: 100% !important;
    max-height: 95vh !important;
    padding: 15px !important;
  }

  .toolbar {
    gap: 6px;
    margin-bottom: 8px;
  }

  .toolbar:last-child {
    margin-bottom: 0;
  }

  /* 搜索框在小手机上全宽 */
  .search-wrapper {
    width: 100%;
    margin-bottom: 8px;
    min-width: 0;
  }

  #q {
    min-width: 0;
    width: 100%;
    font-size: 16px !important;
    padding: 8px 36px 8px 12px;
    height: 36px;
  }

  /* 小手机上确保所有输入框字体至少16px */
  .m-input,
  .m-textarea,
  .m-detail-value[contenteditable="true"] {
    font-size: 16px !important;
    line-height: 1.5;
  }

  .m-detail-value select {
    font-size: 16px !important;
  }

  /* 调整输入框padding以适应16px字体 */
  .m-input {
    padding: 8px 12px;
    min-height: 44px;
  }

  .m-textarea {
    padding: 8px 12px;
    line-height: 1.5;
  }

  .m-detail-value[contenteditable="true"] {
    padding: 8px 12px;
    min-height: 44px;
  }

  /* 按钮在小手机上优化 - 4列网格布局，2行 */
  .toolbar:nth-of-type(2) {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .toolbar button {
    font-size: 11px;
    padding: 6px 8px;
    height: 32px;
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 第二行工具栏按钮：4列布局 */
  .toolbar:nth-of-type(2) button,
  .toolbar:nth-of-type(2) > div {
    width: 100%;
    max-width: 100%;
    flex: 1 1 100%;
  }

  /* 下拉框在小手机上优化 */
  .toolbar select {
    font-size: 11px;
    padding: 6px 8px;
    height: 32px;
    width: 100%;
    margin-bottom: 6px;
  }

  .toolbar select:last-child {
    margin-bottom: 0;
  }

  /* 第一行工具栏：搜索和筛选 - 重新布局 */
  .toolbar:first-of-type {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* 搜索框和搜索按钮在同一行 */
  .toolbar:first-of-type .search-wrapper {
    flex: 1 1 calc(100% - 120px);
    min-width: 0;
    margin-bottom: 0;
    order: 1;
  }

  .toolbar:first-of-type #btnSearchMode {
    flex: 0 0 110px;
    white-space: nowrap;
    margin-bottom: 0;
    order: 2;
    font-size: 11px;
    padding: 6px 8px;
  }

  /* 三个下拉框在同一行 */
  .toolbar:first-of-type select {
    flex: 1 1 calc(33.333% - 4px);
    min-width: 0;
    margin-bottom: 0;
    order: 3;
  }

  /* 标签式控件优化 */
  .label-inline {
    font-size: 11px;
    flex: 1 1 100%;
    margin-bottom: 8px;
    min-width: 0;
  }

  .label-inline:last-child {
    margin-bottom: 0;
  }

  .label-inline input[type="range"],
  .label-inline input[type="color"],
  .label-inline input[type="checkbox"] {
    flex-shrink: 0;
  }
  
  /* ✅ 手机端设置页面布局优化 - 使用新的view-settings样式 */
  #panelView .view-settings-row {
    gap: 6px;
    margin-bottom: 10px;
  }
  
  #panelView .view-settings-item-2col {
    flex: 1 1 calc(50% - 3px) !important;
    min-width: 100px !important;
    max-width: calc(50% - 3px) !important;
  }
  
  #panelView .view-settings-item-3col {
    flex: 1 1 calc(33.333% - 4px) !important;
    min-width: 80px !important;
    max-width: calc(33.333% - 4px) !important;
  }
  
  #panelView .view-settings-buttons {
    justify-content: center;
    gap: 8px;
  }
  
  #panelView .view-settings-btn {
    flex: 0 0 auto;
    min-width: 100px;
  }
  
  /* ✅ 手机端按钮取消点击时不高亮 */
  button.ghost:active,
  button.function-btn:active {
    background: var(--btn-default) !important;
  }
}

/* ✅ 小屏幕手机端（480px）设置页面布局优化 */
@media (max-width: 480px) {
  /* ✅ 小屏幕手机端设置页面布局优化 - 使用新的view-settings样式 */
  #panelView .view-settings-row {
    gap: 6px;
    margin-bottom: 10px;
  }
  
  #panelView .view-settings-item-2col {
    flex: 1 1 calc(50% - 3px) !important;
    min-width: 90px !important;
    max-width: calc(50% - 3px) !important;
  }
  
  #panelView .view-settings-item-3col {
    flex: 1 1 calc(33.333% - 4px) !important;
    min-width: 70px !important;
    max-width: calc(33.333% - 4px) !important;
  }
  
  #panelView .view-settings-buttons {
    justify-content: center;
    gap: 8px;
  }
  
  #panelView .view-settings-btn {
    flex: 0 0 auto;
    min-width: 100px;
  }
  
  /* ✅ 小屏幕手机端：按钮取消点击时不高亮 */
  button.ghost:active,
  button.function-btn:active {
    background: var(--btn-default) !important;
  }
  
  button.ghost:not(.active),
  button.function-btn:not(.active) {
    background: var(--btn-default) !important;
  }
  
  /* ✅ 确保按钮失去焦点时恢复默认背景色 */
  button.ghost:not(:focus):not(.active):not(:hover),
  button.function-btn:not(:focus):not(.active):not(:hover) {
    background: var(--btn-default) !important;
  }

  .cloud-status {
    font-size: 11px;
    padding: 3px 6px;
  }

  .save-status {
    max-width: 120px;
    font-size: 11px;
    padding: 3px 8px;
  }

  .m-phone {
    font-size: 18px;
  }
}

/* Final pearl desktop overrides. Keep at file end so older rules cannot win. */
@media (min-width: 1024px) {
  html,
  body {
    background: var(--pearl-surface) !important;
    color: var(--pearl-text);
  }

  .app-sidebar {
    display: flex !important;
  }

  .wrap {
    max-width: none !important;
    margin-left: 256px !important;
    padding: 0 32px 44px !important;
  }

  .app-topbar {
    margin: 0 -32px 28px !important;
    border-radius: 0 !important;
  }

  .controls-panel,
  .data-panel {
    border-top-left-radius: 20px !important;
    border-top-right-radius: 20px !important;
  }

  .action-toolbar {
    display: flex !important;
    flex-wrap: wrap;
  }

  .filter-toolbar {
    display: grid !important;
  }

  #btnAdd,
  button.primary {
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
    color: #fff !important;
  }

  #btnSaveCloud,
  #btnLoadCloud,
  #btnCategories,
  #btnView,
  #btnAdmin,
  #btnImportExport {
    background: #fff !important;
    border-color: rgba(32, 139, 238, 0.46) !important;
    color: var(--pearl-primary) !important;
  }

  #btnDeleteData {
    background: #fff0f0 !important;
    border-color: rgba(186, 26, 26, 0.22) !important;
    color: #ba1a1a !important;
  }

  #grid .col-phone {
    font-family: var(--font-mono);
    white-space: nowrap !important;
    word-break: keep-all !important;
  }

  .data-panel .table-wrap {
    overflow-x: auto;
  }
}

/* Mobile pearl dashboard refresh */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 767px) {
  html,
  body {
    background: var(--pearl-surface) !important;
    color: var(--pearl-text);
  }

  body {
    padding-bottom: calc(env(safe-area-inset-bottom) + 76px);
  }

  .app-sidebar {
    display: none !important;
  }

  .wrap {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0 14px calc(env(safe-area-inset-bottom) + 92px) !important;
  }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 62px;
    margin: 0 -14px 12px;
    padding: calc(env(safe-area-inset-top) + 6px) 14px 10px !important;
    border-bottom: 1px solid rgba(192, 199, 213, 0.56);
    background: rgba(255, 255, 255, 0.94) !important;
    backdrop-filter: blur(14px);
    box-shadow: 0 6px 20px rgba(0, 93, 167, 0.06);
  }

  .topbar .top-left {
    min-width: 84px;
  }

  #appTitle {
    color: var(--pearl-primary);
    font-size: 19px;
    font-weight: 850;
    letter-spacing: 0;
  }

  .topbar .top-right {
    flex: 1;
    justify-content: flex-end;
    gap: 6px;
    overflow: hidden;
  }

  #currentUserName {
    max-width: 92px;
    color: var(--pearl-muted) !important;
    font-size: 12px !important;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #btnLogout {
    min-width: auto;
    height: 30px !important;
    padding: 0 8px !important;
    border-color: transparent !important;
    background: transparent !important;
    color: var(--pearl-primary) !important;
    font-size: 12px !important;
    box-shadow: none !important;
  }

  .cloud-status,
  .save-status {
    min-height: 26px;
    border-radius: 999px;
    border: 1px solid rgba(32, 139, 238, 0.14);
    background: #edf6ff !important;
    color: var(--pearl-primary) !important;
    font-size: 11px !important;
    line-height: 1.2;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
  }

  .save-status {
    max-width: 120px;
  }

  .controls-panel {
    margin-bottom: 12px;
    padding: 14px;
    border: 1px solid rgba(192, 199, 213, 0.62);
    border-radius: 18px !important;
    background:
      linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 253, 0.92)),
      #fff !important;
    box-shadow: var(--pearl-shadow-soft);
  }

  .filter-toolbar {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
  }

  .filter-toolbar .search-wrapper {
    grid-column: 1 / -1;
    width: 100%;
    margin: 0;
  }

  #q {
    width: 100%;
    height: 44px;
    border-radius: 14px;
    border-color: var(--pearl-outline);
    background: #fff;
    color: var(--pearl-text);
    font-size: 16px !important;
    box-shadow: inset 0 1px 2px rgba(0, 93, 167, 0.04);
  }

  #btnSearchMode,
  #filterOwner,
  #filterWxReal,
  #sortBy {
    width: 100%;
    height: 40px;
    margin: 0;
    border-radius: 12px;
    font-size: 12px !important;
  }

  #sortBy {
    grid-column: 1 / -1;
  }

  .action-toolbar {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(192, 199, 213, 0.45);
  }

  .action-toolbar > div,
  .action-toolbar > button {
    width: 100%;
  }

  .action-toolbar button {
    width: 100%;
    height: 40px;
    min-height: 40px;
    padding: 0 8px;
    border-radius: 12px;
    font-size: 12px !important;
    font-weight: 760;
    white-space: nowrap;
  }

  #btnAdd {
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
    color: #fff !important;
    box-shadow: 0 8px 18px rgba(0, 93, 167, 0.2);
  }

  #btnSaveCloud,
  #btnLoadCloud {
    background: #fff !important;
    border-color: rgba(32, 139, 238, 0.5) !important;
    color: var(--pearl-primary) !important;
  }

  #btnImportExport,
  #btnCategories,
  #btnView,
  #btnAdmin {
    background: #f7fbff !important;
    border-color: rgba(32, 139, 238, 0.28) !important;
    color: var(--pearl-primary) !important;
  }

  #btnDeleteData {
    background: #fff7f7 !important;
    border-color: rgba(186, 26, 26, 0.18) !important;
    color: #a61919 !important;
  }

  .data-panel {
    margin-top: 12px;
    padding: 0 !important;
    border: none;
    background: transparent !important;
    box-shadow: none;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: block !important;
  }

  #mobileList {
    display: flex !important;
    flex-direction: column;
    gap: 12px;
  }

  .m-row {
    overflow: hidden;
    margin: 0;
    border: 1px solid rgba(192, 199, 213, 0.66) !important;
    border-radius: 18px;
    background: #fff !important;
    box-shadow: 0 8px 24px rgba(0, 93, 167, 0.08);
  }

  .m-row-header {
    padding: 15px 16px;
    background: linear-gradient(135deg, #fff, rgba(32, 139, 238, 0.035)) !important;
  }

  .m-main-line {
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
  }

  .m-phone {
    max-width: 58%;
    color: #111827 !important;
    font-family: var(--font-mono);
    font-size: 20px !important;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .m-xhs {
    color: var(--pearl-muted);
    font-size: 13px;
    font-weight: 650;
  }

  .m-meta-line {
    color: var(--pearl-muted);
  }

  .m-owner {
    color: var(--pearl-muted);
    font-size: 13px;
  }

  .m-cat-pill {
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(32, 139, 238, 0.1);
    color: var(--pearl-primary);
    font-size: 12px;
    font-weight: 750;
  }

  .m-row-details {
    background: #fbfdff;
    border-top-color: rgba(192, 199, 213, 0.5);
  }

  .m-row.open .m-row-details {
    padding: 12px 14px 16px;
  }

  .m-detail-row {
    display: grid;
    grid-template-columns: 34% minmax(0, 1fr);
    gap: 10px;
    min-height: 42px;
    padding: 7px 0;
    border-bottom: 1px solid rgba(192, 199, 213, 0.28);
  }

  .m-detail-row:last-child {
    border-bottom: 0;
  }

  .m-detail-label {
    color: #657081;
    font-size: 12px;
    font-weight: 760;
  }

  .m-detail-value {
    justify-content: flex-end;
    color: var(--pearl-text);
    font-size: 14px;
    font-weight: 650;
    text-align: right;
  }

  .m-detail-value[data-field="note1"],
  .m-textarea {
    border-radius: 12px;
    background: #f2f5f7;
    text-align: left;
  }

  .m-input,
  .m-textarea,
  .m-detail-value select {
    border-color: rgba(192, 199, 213, 0.74);
    border-radius: 12px;
    background: #fff;
  }

  .m-edit-actions,
  .m-actions {
    gap: 8px !important;
  }

  .m-edit-actions button,
  .m-actions button {
    min-height: 38px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 760;
  }

  .m-actions .btn-danger {
    background: #fff7f7 !important;
    border-color: rgba(186, 26, 26, 0.18) !important;
    color: #a61919 !important;
  }

  .mobile-bottom-nav {
    position: fixed;
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom) + 10px);
    left: 12px;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    min-height: 58px;
    padding: 7px;
    border: 1px solid rgba(192, 199, 213, 0.72);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 10px 30px rgba(0, 93, 167, 0.16);
    backdrop-filter: blur(16px);
  }

  .mobile-bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 13px;
    background: transparent !important;
    color: var(--pearl-muted) !important;
    font-size: 11px;
    font-weight: 760;
    box-shadow: none;
  }

  .mobile-bottom-nav button:active {
    background: var(--pearl-primary-soft) !important;
    color: var(--pearl-primary) !important;
  }

  .mobile-nav-icon {
    font-size: 17px;
    line-height: 1;
  }
}

/* Round 2 layout corrections: desktop containment and cleaner mobile hierarchy. */
@media (min-width: 1024px) {
  .wrap {
    width: calc(100vw - 256px) !important;
    max-width: calc(100vw - 256px) !important;
    overflow-x: hidden;
  }

  .controls-panel,
  .data-panel,
  #panelCategories {
    max-width: 100%;
    min-width: 0;
  }

  .filter-toolbar {
    display: grid !important;
    grid-template-columns: minmax(260px, 2fr) minmax(132px, 0.8fr) repeat(3, minmax(150px, 1fr));
    gap: 12px;
    width: 100%;
    min-width: 0;
  }

  .filter-toolbar > * {
    min-width: 0;
  }

  .filter-toolbar .search-wrapper {
    min-width: 0;
  }

  .filter-toolbar select,
  .filter-toolbar button,
  .filter-toolbar input {
    min-width: 0;
    max-width: 100%;
  }

  .action-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 10px;
    width: 100%;
    min-width: 0;
  }

  .action-toolbar > button,
  .action-toolbar > div {
    flex: 0 1 auto;
    min-width: 0;
  }

  .action-toolbar button {
    max-width: 100%;
    padding-inline: 14px;
  }

  #btnDeleteData {
    margin-left: auto;
  }

  .data-panel {
    max-width: 100%;
    overflow: hidden;
  }

  .data-panel .table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  #grid {
    min-width: 1040px;
    width: max(100%, 1040px);
  }

  th.col-phone,
  td.col-phone {
    width: 128px !important;
    min-width: 128px !important;
    max-width: 128px !important;
  }

  th.col-owner,
  td.col-owner,
  th.col-real,
  td.col-real {
    width: 92px !important;
    min-width: 92px !important;
    max-width: 92px !important;
  }

  th.col-wx,
  td.col-wx,
  th.col-xhs,
  td.col-xhs {
    width: 142px !important;
    min-width: 142px !important;
    max-width: 142px !important;
  }

  th.col-platforms,
  td.col-platforms {
    width: 150px !important;
    min-width: 150px !important;
    max-width: 150px !important;
  }

  th.col-note,
  td.col-note {
    width: 168px !important;
    min-width: 168px !important;
    max-width: 168px !important;
  }

  th.col-cat,
  td.col-cat {
    width: 136px !important;
    min-width: 136px !important;
    max-width: 136px !important;
  }

  th.col-act,
  td.col-act {
    width: 148px !important;
    min-width: 148px !important;
    max-width: 148px !important;
    padding-inline: 10px;
  }

  .actions-container,
  .actions-extra {
    gap: 3px;
  }

  .actions-container .btn-mini,
  .actions-extra .btn-mini {
    height: 26px;
    min-height: 26px;
    padding: 0 7px;
    font-size: 11px;
  }
}

@media (min-width: 1024px) and (max-width: 1359px) {
  .filter-toolbar {
    grid-template-columns: minmax(260px, 1fr) minmax(132px, 160px) repeat(2, minmax(150px, 1fr));
  }

  #sortBy {
    grid-column: span 2;
  }

  #btnDeleteData {
    margin-left: 0;
  }
}

@media (max-width: 767px) {
  body {
    overflow-x: hidden;
    padding-bottom: 0;
  }

  .wrap {
    overflow-x: hidden;
    padding: 0 12px calc(env(safe-area-inset-bottom) + 22px) !important;
  }

  .app-topbar {
    margin-inline: -12px;
  }

  .controls-panel {
    padding: 14px !important;
    border-radius: 18px !important;
  }

  .filter-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 9px !important;
    margin-bottom: 14px !important;
  }

  .filter-toolbar .search-wrapper,
  #btnSearchMode,
  #sortBy {
    grid-column: 1 / -1;
  }

  .filter-toolbar .search-wrapper {
    order: 1;
  }

  #btnSearchMode {
    order: 2;
  }

  #filterOwner {
    order: 3;
  }

  #filterWxReal {
    order: 4;
  }

  #sortBy {
    order: 5;
  }

  #q,
  #btnSearchMode,
  #filterOwner,
  #filterWxReal,
  #sortBy {
    height: 42px !important;
    min-height: 42px !important;
    border-radius: 14px !important;
  }

  .action-toolbar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    padding-top: 13px !important;
  }

  #btnAdd,
  #btnSaveCloud,
  #btnLoadCloud {
    height: 42px !important;
    min-height: 42px !important;
    font-size: 13px !important;
  }

  #btnAdd {
    grid-column: span 1;
  }

  #btnSaveCloud {
    grid-column: span 1;
  }

  #btnLoadCloud {
    grid-column: 1 / -1;
  }

  #btnImportExport,
  #btnCategories,
  #btnView,
  #btnAdmin,
  #btnDeleteData {
    height: 36px !important;
    min-height: 36px !important;
    border-radius: 12px !important;
    font-size: 12px !important;
    box-shadow: none !important;
  }

  #btnDeleteData {
    background: transparent !important;
    border-style: dashed !important;
    color: #a61919 !important;
  }

  .mobile-bottom-nav {
    display: none !important;
  }

  #mobileList {
    gap: 10px;
  }

  .m-row {
    border-radius: 16px;
    box-shadow: 0 6px 18px rgba(0, 93, 167, 0.07);
  }

  .m-row-header {
    padding: 13px 14px;
  }

  .m-phone {
    max-width: 55%;
    font-size: 19px !important;
    white-space: nowrap !important;
  }

  .m-xhs {
    min-width: 0;
    max-width: 42%;
  }

  .m-meta-line {
    gap: 6px;
  }

  .m-row.open .m-row-details {
    padding: 10px 13px 14px;
  }
}

/* Round 3 desktop containment fixes for 1024-1440px widths. */
@media (min-width: 1024px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
  }

  .wrap {
    box-sizing: border-box !important;
    width: calc(100vw - 256px) !important;
    max-width: calc(100vw - 256px) !important;
    min-width: 0 !important;
    margin-left: 256px !important;
    padding-left: clamp(16px, 2vw, 32px) !important;
    padding-right: clamp(16px, 2vw, 32px) !important;
    overflow-x: hidden !important;
  }

  .app-topbar {
    box-sizing: border-box !important;
    max-width: calc(100% + (2 * clamp(16px, 2vw, 32px))) !important;
    min-width: 0 !important;
    overflow: hidden;
  }

  .panel,
  .controls-panel,
  .data-panel,
  #panelCategories {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden;
  }

  .controls-panel > *,
  .data-panel > *,
  .toolbar > *,
  .filter-toolbar > *,
  .action-toolbar > * {
    min-width: 0 !important;
    max-width: 100%;
    box-sizing: border-box;
  }

  .filter-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: stretch !important;
    gap: 10px !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .filter-toolbar .search-wrapper {
    flex: 2 1 320px !important;
    min-width: min(320px, 100%) !important;
    max-width: 100% !important;
  }

  #btnSearchMode {
    flex: 0 1 170px !important;
    max-width: 180px !important;
    min-width: 132px !important;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #filterOwner,
  #filterWxReal,
  #sortBy {
    flex: 1 1 170px !important;
    min-width: 150px !important;
    max-width: 100% !important;
  }

  .filter-toolbar input,
  .filter-toolbar select,
  .filter-toolbar button {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .action-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .action-toolbar > button,
  .action-toolbar > div {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .action-toolbar button {
    width: auto !important;
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
    white-space: nowrap !important;
  }

  #btnDeleteData {
    margin-left: 0 !important;
  }

  .data-panel {
    overflow: hidden !important;
  }

  .data-panel .table-wrap {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden;
  }

  #grid {
    min-width: 1190px;
    width: max(100%, 1190px) !important;
    max-width: none !important;
  }
}

@media (min-width: 1024px) and (max-width: 1320px) {
  .filter-toolbar .search-wrapper {
    flex: 1 1 100% !important;
  }

  #btnSearchMode,
  #filterOwner,
  #filterWxReal,
  #sortBy {
    flex: 1 1 180px !important;
    max-width: none !important;
  }

  .action-toolbar button {
    height: 40px !important;
    min-height: 40px !important;
    font-size: 12px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
}

@media (min-width: 1024px) and (max-width: 1120px) {
  .wrap {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .controls-panel {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  #btnSearchMode,
  #filterOwner,
  #filterWxReal,
  #sortBy {
    flex-basis: calc(50% - 5px) !important;
    min-width: 0 !important;
  }
}

/* Round 4: prevent the 769-1023px range from falling back to the old hybrid layout. */
@media (min-width: 768px) and (max-width: 1023px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    background: var(--pearl-surface) !important;
  }

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    display: flex !important;
    width: 224px;
    flex-direction: column;
    padding: 16px 10px 20px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(242, 245, 247, 0.98));
    border-right: 1px solid var(--pearl-outline-soft);
    box-shadow: 8px 0 24px rgba(0, 93, 167, 0.06);
  }

  .sidebar-profile {
    gap: 10px;
    padding: 0 10px 18px;
  }

  .sidebar-avatar {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    font-size: 15px;
  }

  .sidebar-user-name {
    font-size: 15px;
  }

  .sidebar-nav {
    gap: 7px;
  }

  .sidebar-nav-item {
    min-height: 42px;
    padding: 0 12px;
    font-size: 14px;
  }

  .sidebar-add {
    min-height: 44px;
    font-size: 14px;
  }

  .sidebar-logout {
    min-height: 38px;
    font-size: 13px;
  }

  .wrap {
    box-sizing: border-box !important;
    width: calc(100vw - 224px) !important;
    max-width: calc(100vw - 224px) !important;
    min-width: 0 !important;
    margin: 0 0 0 224px !important;
    padding: 0 clamp(12px, 1.8vw, 20px) 32px !important;
    overflow-x: hidden !important;
    background: var(--pearl-surface) !important;
  }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    box-sizing: border-box !important;
    min-height: 64px;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 18px !important;
    padding: 12px clamp(12px, 1.8vw, 20px) !important;
    border-bottom: 1px solid rgba(192, 199, 213, 0.58);
    border-radius: 0 !important;
    background: rgba(255, 255, 255, 0.96) !important;
    box-shadow: 0 6px 20px rgba(0, 93, 167, 0.05);
    backdrop-filter: blur(14px);
    overflow: hidden !important;
  }

  .topbar .top-left,
  .topbar .top-right {
    min-width: 0;
  }

  .topbar .top-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 7px;
  }

  #appTitle {
    color: var(--pearl-primary);
    font-size: 20px;
    font-weight: 850;
    letter-spacing: 0;
  }

  #currentUserName {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cloud-status,
  .save-status {
    max-width: 150px;
    min-height: 28px;
    border-radius: 999px;
    font-size: 12px !important;
  }

  .panel,
  .controls-panel,
  .data-panel,
  #panelCategories {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden;
  }

  .controls-panel {
    margin-bottom: 18px;
    padding: 14px !important;
    border: 1px solid rgba(192, 199, 213, 0.62);
    border-radius: 20px !important;
    background:
      linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 253, 0.92)),
      #fff !important;
    box-shadow: var(--pearl-shadow-soft);
  }

  .filter-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: stretch !important;
    gap: 10px !important;
    width: 100% !important;
    min-width: 0 !important;
    margin-bottom: 12px !important;
  }

  .filter-toolbar > *,
  .action-toolbar > * {
    box-sizing: border-box;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .filter-toolbar .search-wrapper {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  #btnSearchMode,
  #filterOwner,
  #filterWxReal,
  #sortBy {
    flex: 1 1 calc(50% - 5px) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 42px !important;
    min-height: 42px !important;
    border-radius: 14px !important;
  }

  .filter-toolbar input,
  .filter-toolbar select,
  .filter-toolbar button {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  #q {
    height: 44px !important;
    border-radius: 15px !important;
    background: #fff !important;
  }

  .action-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 9px !important;
    width: 100% !important;
    min-width: 0 !important;
    padding-top: 12px !important;
    border-top: 1px solid rgba(192, 199, 213, 0.45);
  }

  .action-toolbar > button,
  .action-toolbar > div {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .action-toolbar button {
    width: auto !important;
    max-width: 100% !important;
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 10px !important;
    border-radius: 12px !important;
    font-size: 12px !important;
    white-space: nowrap !important;
  }

  #btnAdd {
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
    color: #fff !important;
    box-shadow: 0 8px 18px rgba(0, 93, 167, 0.18);
  }

  #btnSaveCloud,
  #btnLoadCloud,
  #btnCategories,
  #btnView,
  #btnAdmin,
  #btnImportExport {
    background: #fff !important;
    border-color: rgba(32, 139, 238, 0.46) !important;
    color: var(--pearl-primary) !important;
  }

  #btnDeleteData {
    margin-left: 0 !important;
    background: #fff7f7 !important;
    border-color: rgba(186, 26, 26, 0.18) !important;
    color: #a61919 !important;
  }

  .data-panel {
    overflow: hidden !important;
    border: 1px solid rgba(192, 199, 213, 0.62);
    border-radius: 20px !important;
    background: #fff !important;
    box-shadow: var(--pearl-shadow-soft);
  }

  .desktop-only {
    display: block !important;
  }

  .mobile-only {
    display: none !important;
  }

  .data-panel .table-wrap {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  #grid {
    min-width: 1040px;
    width: max(100%, 1040px) !important;
    max-width: none !important;
  }
}

@media (min-width: 768px) and (max-width: 900px) {
  .app-sidebar {
    width: 208px;
  }

  .wrap {
    width: calc(100vw - 208px) !important;
    max-width: calc(100vw - 208px) !important;
    margin-left: 208px !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .sidebar-nav-item {
    padding: 0 10px;
    font-size: 13px;
  }

  .sidebar-icon {
    width: 20px;
  }

  .controls-panel {
    padding: 12px !important;
  }

  #btnSearchMode,
  #filterOwner,
  #filterWxReal,
  #sortBy {
    flex-basis: 100% !important;
  }
}

@media (max-width: 767px) {
  .large-text-editor-modal {
    align-items: end;
    padding: 12px;
  }

  .large-text-editor-panel {
    width: 100%;
    max-height: 86vh;
    border-radius: 18px;
    padding: 15px;
  }

  .large-text-editor-input {
    min-height: 280px;
    max-height: 56vh;
    font-size: 16px;
  }

  .large-text-editor-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .app-sidebar {
    display: none !important;
  }

  .wrap {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
  }
}

/* Collapsed desktop sidebar: keep a slim rail visible and expand on click. */
@media (min-width: 768px) {
  :root {
    --sidebar-collapsed-width: 72px;
    --sidebar-expanded-width: 256px;
  }

  body:not(.sidebar-expanded) .app-sidebar {
    width: var(--sidebar-collapsed-width) !important;
    padding: 16px 8px 18px !important;
    cursor: pointer;
    overflow: hidden;
  }

  body:not(.sidebar-expanded) .wrap {
    width: calc(100vw - var(--sidebar-collapsed-width)) !important;
    max-width: calc(100vw - var(--sidebar-collapsed-width)) !important;
    margin-left: var(--sidebar-collapsed-width) !important;
  }

  body.sidebar-expanded .app-sidebar {
    width: var(--sidebar-expanded-width) !important;
    cursor: default;
  }

  body.sidebar-expanded .wrap {
    width: calc(100vw - var(--sidebar-expanded-width)) !important;
    max-width: calc(100vw - var(--sidebar-expanded-width)) !important;
    margin-left: var(--sidebar-expanded-width) !important;
  }

  body.sidebar-expanded .sidebar-add,
  body.sidebar-expanded .sidebar-logout {
    position: static !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: none !important;
    visibility: visible !important;
  }

  body.sidebar-expanded .sidebar-nav-item {
    display: inline-flex !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    opacity: 1 !important;
    transform: none !important;
    visibility: visible !important;
  }

  body.sidebar-expanded .sidebar-sub-item {
    padding-left: 34px !important;
  }

  .app-sidebar,
  .wrap {
    transition: width 180ms ease, max-width 180ms ease, margin-left 180ms ease;
  }

  body:not(.sidebar-expanded) .sidebar-profile {
    justify-content: center;
    padding: 0 0 18px !important;
  }

  body:not(.sidebar-expanded) .sidebar-app-version,
  body:not(.sidebar-expanded) .sidebar-profile-text,
  body:not(.sidebar-expanded) .sidebar-nav-item span:not(.sidebar-icon),
  body:not(.sidebar-expanded) .sidebar-add,
  body:not(.sidebar-expanded) .sidebar-logout {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    transform: translateX(-8px);
    visibility: hidden;
  }

  body:not(.sidebar-expanded) .sidebar-avatar {
    width: 42px !important;
    height: 42px !important;
    flex: 0 0 42px !important;
  }

  body:not(.sidebar-expanded) .sidebar-nav {
    align-items: center;
    gap: 10px;
  }

  body:not(.sidebar-expanded) .sidebar-nav-item {
    justify-content: center;
    width: 48px !important;
    min-width: 48px !important;
    height: 48px !important;
    min-height: 48px !important;
    padding: 0 !important;
    border-radius: 16px !important;
  }

  body:not(.sidebar-expanded) .sidebar-icon {
    width: auto !important;
    font-size: 17px;
  }

  body:not(.sidebar-expanded) .sidebar-sub-item {
    padding-left: 0 !important;
  }

  body:not(.sidebar-expanded) .sidebar-danger-item {
    color: #a61919;
  }

  body:not(.sidebar-expanded) .sidebar-bottom {
    align-items: center;
    border-top: 1px solid rgba(192, 199, 213, 0.52);
    padding-top: 14px;
  }

  body:not(.sidebar-expanded) .sidebar-bottom::before {
    content: "+";
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd);
    color: #fff;
    font-size: 22px;
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(0, 93, 167, 0.18);
  }

  .controls-panel {
    padding-bottom: 14px !important;
  }

  .action-toolbar {
    display: none !important;
  }

  .filter-toolbar {
    margin-bottom: 0 !important;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --sidebar-expanded-width: 224px;
  }
}

@media (min-width: 768px) and (max-width: 900px) {
  :root {
    --sidebar-expanded-width: 208px;
    --sidebar-collapsed-width: 64px;
  }

  body:not(.sidebar-expanded) .sidebar-nav-item,
  body:not(.sidebar-expanded) .sidebar-bottom::before {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    border-radius: 14px !important;
  }
}

/* Center the page title in the app bar while keeping account/status actions on the right. */
@media (min-width: 768px) {
  .app-topbar {
    position: sticky !important;
    justify-content: center !important;
  }

  .app-topbar .top-left {
    position: absolute;
    left: 50%;
    min-width: 0 !important;
    transform: translateX(-50%);
    pointer-events: none;
  }

  .app-topbar #appTitle {
    margin: 0;
    text-align: center;
    white-space: nowrap;
  }

  .app-topbar .top-right {
    margin-left: auto;
  }
}

/* Compact mobile controls: keep all functions while minimizing vertical space. */
@media (max-width: 767px) {
  #mobileList .m-detail-row {
    grid-template-columns: 30% minmax(0, 1fr) !important;
    gap: 8px !important;
    min-height: 38px !important;
    padding: 5px 0 !important;
  }

  #mobileList .m-detail-label {
    font-size: 11px !important;
  }

  #mobileList .m-input,
  #mobileList .m-detail-value select {
    min-height: 44px !important;
    height: 44px !important;
    padding: 7px 10px !important;
    border-radius: 12px !important;
    font-size: 14px !important;
  }

  #mobileList .m-textarea {
    min-height: 72px !important;
    height: 72px !important;
    padding: 8px 10px !important;
    border-radius: 12px !important;
    font-size: 14px !important;
  }

  #mobileList .mobile-platform-section {
    margin: 8px 0 !important;
    padding: 10px !important;
    border-radius: 14px !important;
  }

  #mobileList .mobile-platform-section-head {
    margin-bottom: 8px !important;
  }

  #mobileList .mobile-platform-grid {
    gap: 7px !important;
  }

  #mobileList .mobile-platform-item {
    padding: 7px 8px !important;
    border-radius: 12px !important;
  }

  #mobileList .mobile-platform-input {
    min-height: 36px !important;
    height: 36px !important;
    margin-top: 4px !important;
    padding: 6px 8px !important;
    font-size: 13px !important;
  }

  #mobileList .mobile-platform-actions {
    margin-top: 8px !important;
  }

  #mobileList .m-edit-actions {
    margin-top: 8px !important;
    padding: 9px 0 4px !important;
  }

  #mobileList .m-edit-actions button {
    min-height: 38px !important;
  }

  .controls-panel {
    margin: 8px 0 10px !important;
    padding: 10px !important;
    border-radius: 16px !important;
  }

  .filter-toolbar {
    display: grid !important;
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
    gap: 8px !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .action-toolbar::-webkit-scrollbar {
    display: none;
  }

  .filter-toolbar .search-wrapper {
    grid-column: 1 / 5 !important;
    width: auto !important;
    min-width: 0 !important;
  }

  #q {
    height: 38px !important;
    min-height: 38px !important;
    border-radius: 14px !important;
    font-size: 14px !important;
    padding-left: 12px !important;
  }

  #clearSearch {
    top: 50%;
    transform: translateY(-50%);
  }

  #btnSearchMode,
  #filterOwner,
  #filterWxReal,
  #sortBy {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 12px !important;
    border-radius: 14px !important;
    font-size: 12px !important;
    white-space: nowrap !important;
  }

  #btnSearchMode {
    grid-column: 5 / 7 !important;
  }

  #filterOwner,
  #filterWxReal,
  #sortBy {
    grid-row: auto !important;
  }

  #filterOwner {
    grid-column: 1 / 3 !important;
    grid-row: 2 !important;
  }

  #filterWxReal {
    grid-column: 3 / 5 !important;
    grid-row: 2 !important;
  }

  #sortBy {
    grid-column: 5 / 7 !important;
    grid-row: 2 !important;
  }

  .action-toolbar {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    margin-top: 8px !important;
    padding-top: 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid rgba(192, 199, 213, 0.38) !important;
    scrollbar-width: none;
  }

  .action-toolbar > button,
  .action-toolbar > div {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: auto !important;
  }

  .action-toolbar button,
  #btnAdd,
  #btnSaveCloud,
  #btnLoadCloud,
  #btnImportExport,
  #btnCategories,
  #btnView,
  #btnAdmin,
  #btnDeleteData {
    width: auto !important;
    min-width: 86px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 12px !important;
    border-radius: 13px !important;
    font-size: 12px !important;
    white-space: nowrap !important;
  }

  #btnAdd {
    min-width: 94px !important;
  }

  #btnDeleteData {
    min-width: 82px !important;
  }

  #mobileList .m-row:nth-child(odd) {
    background: #ffffff !important;
  }

  #mobileList .m-row:nth-child(odd) .m-row-header {
    background: linear-gradient(135deg, #ffffff, rgba(32, 139, 238, 0.025)) !important;
  }

  #mobileList .m-row:nth-child(even) {
    background: #eaf5ff !important;
    border-color: rgba(32, 139, 238, 0.22) !important;
  }

  #mobileList .m-row:nth-child(even) .m-row-header {
    background: linear-gradient(135deg, #eaf5ff, #dceeff) !important;
  }

  #mobileList .m-row:nth-child(even) .m-row-details {
    background: #f4f9ff !important;
  }
}

/* Mobile top spacing cleanup: remove the blank white strip above filters. */
@media (max-width: 767px) {
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(15, 32, 48, 0.28);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  body.sidebar-expanded::after {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sidebar-toggle {
    display: inline-grid !important;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    place-items: center;
    gap: 4px;
    padding: 9px;
    border: 1px solid rgba(32, 139, 238, 0.22) !important;
    border-radius: 13px;
    background: rgba(255, 255, 255, 0.84) !important;
    box-shadow: 0 6px 16px rgba(0, 93, 167, 0.1);
  }

  .mobile-sidebar-toggle span {
    display: block;
    width: 17px;
    height: 2px;
    border-radius: 999px;
    background: var(--pearl-primary);
  }

  body.sidebar-expanded .mobile-sidebar-toggle span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  body.sidebar-expanded .mobile-sidebar-toggle span:nth-child(2) {
    opacity: 0;
  }

  body.sidebar-expanded .mobile-sidebar-toggle span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .app-sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    z-index: 50 !important;
    display: flex !important;
    width: min(82vw, 292px) !important;
    height: 100dvh !important;
    min-height: 100vh !important;
    flex-direction: column;
    padding: calc(env(safe-area-inset-top) + 16px) 14px calc(env(safe-area-inset-bottom) + 18px) !important;
    border-right: 1px solid rgba(192, 199, 213, 0.62);
    border-radius: 0 22px 22px 0;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(242, 247, 252, 0.98)),
      var(--pearl-white) !important;
    box-shadow: 16px 0 36px rgba(0, 93, 167, 0.16);
    transform: translateX(-105%);
    transition: transform 190ms ease;
    overflow: hidden auto;
    -webkit-overflow-scrolling: touch;
  }

  body.sidebar-expanded .app-sidebar {
    transform: translateX(0);
  }

  .sidebar-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 6px 16px;
    border-bottom: 1px solid rgba(192, 199, 213, 0.48);
  }

  .sidebar-avatar {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pearl-primary-bright), var(--pearl-primary));
    color: #fff;
    font-weight: 850;
  }

  .sidebar-profile-text {
    min-width: 0;
  }

  .sidebar-user-name {
    overflow: hidden;
    color: var(--pearl-text);
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar-cloud-line {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    color: var(--pearl-muted);
    font-size: 12px;
  }

  .sidebar-profile-text {
    display: none !important;
  }

  .sidebar-nav {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 8px;
    padding: 16px 0;
  }

  .sidebar-nav-item,
  .sidebar-add,
  .sidebar-logout {
    display: inline-flex !important;
    align-items: center;
    justify-content: flex-start;
    width: 100% !important;
    min-height: 44px;
    gap: 10px;
    padding: 0 14px;
    border: 1px solid transparent !important;
    border-radius: 15px;
    background: transparent !important;
    color: #263241;
    font-size: 14px;
    font-weight: 750;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: static !important;
    transform: none !important;
    visibility: visible !important;
  }

  .sidebar-nav-item.active,
  .sidebar-nav-item:hover {
    background: var(--pearl-primary-soft) !important;
    border-color: rgba(32, 139, 238, 0.18) !important;
    color: var(--pearl-primary);
  }

  .sidebar-sub-item {
    padding-left: 34px;
    min-height: 40px;
    font-size: 13px;
  }

  .sidebar-danger-item {
    color: #a61919;
  }

  .sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid rgba(192, 199, 213, 0.48);
  }

  .sidebar-add {
    justify-content: center;
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
    color: #fff !important;
    box-shadow: 0 8px 18px rgba(0, 93, 167, 0.18);
  }

  .sidebar-logout {
    justify-content: center;
    color: var(--pearl-primary);
  }

  #dataStatsBar,
  #dataStatsBar.data-stats-bar,
  div#dataStatsBar,
  .data-stats-bar#dataStatsBar {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    visibility: hidden !important;
  }

  .app-topbar {
    position: sticky !important;
    min-height: 44px !important;
    margin: 0 0 4px !important;
    padding: calc(env(safe-area-inset-top) + 4px) 4px 4px !important;
    border-bottom: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
  }

  .app-topbar .top-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0 !important;
  }

  .app-topbar .top-right {
    gap: 4px !important;
  }

  .controls-panel {
    margin-top: 4px !important;
  }

  .controls-panel .action-toolbar {
    display: none !important;
  }
}

/* Pearl subpage refresh: shared shell for admin, settings, snapshots and utility pages. */
html:has(body.subpage-shell),
body.subpage-shell {
  background: var(--pearl-surface) !important;
  color: var(--pearl-text);
  font-family: var(--font-main);
}

body.subpage-shell .admin-wrap,
body.subpage-shell .admin-container,
body.subpage-shell .approval-container,
body.subpage-shell .permission-container,
body.subpage-shell > .container,
body.subpage-shell .login-container {
  box-sizing: border-box;
}

body.subpage-shell .admin-wrap {
  max-width: none !important;
  padding: 18px !important;
}

body.subpage-shell .admin-container,
body.subpage-shell .approval-container,
body.subpage-shell .permission-container,
body.subpage-shell > .container {
  width: min(100%, 1180px) !important;
  max-width: 1180px !important;
  margin: 0 auto !important;
  padding: 18px !important;
}

body.subpage-shell .admin-header,
body.subpage-shell .approval-container > .header,
body.subpage-shell .permission-container > .header,
body.subpage-shell .login-container,
body.subpage-shell .add-form,
body.subpage-shell .user-stats,
body.subpage-shell .stats,
body.subpage-shell .stats-bar,
body.subpage-shell .tabs,
body.subpage-shell .search-box,
body.subpage-shell .grant-form,
body.subpage-shell .settings-section,
body.subpage-shell .add-user-form,
body.subpage-shell .user-table,
body.subpage-shell .user-table-container,
body.subpage-shell .permission-container .panel,
body.subpage-shell .admin-wrap > .panel,
body.subpage-shell .snapshot-card,
body.subpage-shell .change-item,
body.subpage-shell .category-card,
body.subpage-shell .preview-content,
body.subpage-shell .confirm-content {
  border: 1px solid rgba(192, 199, 213, 0.62) !important;
  border-radius: 18px !important;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 253, 0.92)),
    var(--pearl-white) !important;
  box-shadow: var(--pearl-shadow-soft) !important;
}

body.subpage-shell .admin-header,
body.subpage-shell .approval-container > .header,
body.subpage-shell .permission-container > .header {
  gap: 12px;
  margin-bottom: 18px !important;
  padding: 16px 18px !important;
}

body.subpage-shell .admin-header h1,
body.subpage-shell .approval-container > .header h1,
body.subpage-shell .permission-container > .header h1 {
  color: var(--pearl-primary) !important;
  font-size: 24px !important;
  font-weight: 850 !important;
  letter-spacing: 0;
}

body.subpage-shell .nav,
body.subpage-shell .tabs {
  gap: 10px !important;
  padding: 10px !important;
  margin-bottom: 16px !important;
}

body.subpage-shell .nav button,
body.subpage-shell .tab,
body.subpage-shell .settings-btn,
body.subpage-shell .pagination button,
body.subpage-shell .action-btn,
body.subpage-shell .btn-small,
body.subpage-shell .btn-move,
body.subpage-shell .btn-add,
body.subpage-shell .btn-secondary,
body.subpage-shell .btn-primary-danger,
body.subpage-shell .btn-danger-small,
body.subpage-shell button.primary,
body.subpage-shell button.ghost {
  min-height: 38px;
  border-radius: 13px !important;
  font-weight: 750 !important;
  letter-spacing: 0;
}

body.subpage-shell .nav button,
body.subpage-shell .tab,
body.subpage-shell button.ghost,
body.subpage-shell .settings-btn.ghost,
body.subpage-shell .pagination button,
body.subpage-shell .btn-small,
body.subpage-shell .btn-move,
body.subpage-shell .btn-secondary {
  border: 1px solid rgba(32, 139, 238, 0.38) !important;
  background: var(--pearl-white) !important;
  color: var(--pearl-primary) !important;
}

body.subpage-shell .nav button.active,
body.subpage-shell .tab.active,
body.subpage-shell button.primary,
body.subpage-shell .btn-add,
body.subpage-shell .btn-load,
body.subpage-shell .btn-submit {
  border-color: transparent !important;
  background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
  color: #fff !important;
  box-shadow: 0 8px 18px rgba(0, 93, 167, 0.18);
}

body.subpage-shell .btn-submit {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  line-height: 1 !important;
}

body.subpage-shell .btn-delete,
body.subpage-shell .btn-danger-small,
body.subpage-shell .btn-primary-danger,
body.subpage-shell .btn-reject,
body.subpage-shell .btn-revoke {
  border-color: rgba(186, 26, 26, 0.22) !important;
  background: #fff4f4 !important;
  color: #a61919 !important;
}

body.subpage-shell input,
body.subpage-shell select,
body.subpage-shell textarea {
  max-width: 100%;
  border: 1px solid var(--pearl-outline) !important;
  border-radius: 13px !important;
  background: var(--pearl-white) !important;
  color: var(--pearl-text);
  box-sizing: border-box;
}

body.subpage-shell .search-box,
body.subpage-shell .grant-form,
body.subpage-shell .add-form-row,
body.subpage-shell .form-row,
body.subpage-shell .settings-row {
  min-width: 0;
}

body.subpage-shell .search-box input,
body.subpage-shell .search-box select,
body.subpage-shell .grant-form input,
body.subpage-shell .grant-form select,
body.subpage-shell .form-row input,
body.subpage-shell .form-row select,
body.subpage-shell .settings-item input,
body.subpage-shell .settings-item select {
  min-height: 40px;
}

body.subpage-shell .stat-card,
body.subpage-shell .stat-item {
  border: 1px solid rgba(192, 199, 213, 0.48) !important;
  border-radius: 16px !important;
  background: var(--pearl-white) !important;
  box-shadow: none !important;
}

body.subpage-shell .stat-card .number,
body.subpage-shell .stat-number,
body.subpage-shell .user-stats .number {
  color: var(--pearl-primary) !important;
  font-weight: 850 !important;
}

body.subpage-shell .user-table,
body.subpage-shell .user-table-container,
body.subpage-shell .permission-container .panel {
  overflow-x: auto !important;
}

body.subpage-shell table {
  border-collapse: separate !important;
  border-spacing: 0;
}

body.subpage-shell th {
  background: #eef5fb !important;
  color: #263241 !important;
  font-weight: 800 !important;
}

body.subpage-shell td,
body.subpage-shell th {
  border-bottom-color: rgba(192, 199, 213, 0.42) !important;
}

body.subpage-shell tr:hover {
  background: rgba(232, 243, 255, 0.68) !important;
}

body.subpage-shell .snapshot-grid,
body.subpage-shell .category-list,
body.subpage-shell #changesList {
  min-width: 0;
}

body.subpage-shell .snapshot-card,
body.subpage-shell .change-item,
body.subpage-shell .category-card {
  border-color: rgba(192, 199, 213, 0.62) !important;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

body.subpage-shell .snapshot-card:hover,
body.subpage-shell .category-card:hover,
body.subpage-shell .change-item:hover {
  border-color: rgba(32, 139, 238, 0.42) !important;
  box-shadow: 0 10px 24px rgba(0, 93, 167, 0.1) !important;
}

body.subpage-shell .snapshot-badge,
body.subpage-shell .badge,
body.subpage-shell .summary-badge {
  border-radius: 999px !important;
  font-weight: 750 !important;
}

body.subpage-shell .empty-state,
body.subpage-shell .loading-state,
body.subpage-shell .loading {
  border: 1px dashed rgba(32, 139, 238, 0.22);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--pearl-muted);
}

body.subpage-shell .settings-section-title {
  color: var(--pearl-primary) !important;
  border-bottom-color: rgba(192, 199, 213, 0.5) !important;
  font-weight: 850 !important;
}

body.subpage-shell .settings-buttons {
  border-top-color: rgba(192, 199, 213, 0.5) !important;
  background: rgba(242, 245, 247, 0.86) !important;
}

body.subpage-shell .admin-wrap > .panel iframe {
  border-radius: 0 0 18px 18px;
  background: var(--pearl-surface) !important;
}

/* Unified management-center shell and subpage layouts. */
body.subpage-shell .admin-wrap {
  display: grid !important;
  grid-template-columns: 236px minmax(0, 1fr) !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  grid-template-areas:
    "header header"
    "nav panel" !important;
  gap: 14px !important;
  width: 100% !important;
  max-width: none !important;
  height: 100dvh !important;
  min-height: 720px !important;
  margin: 0 !important;
  padding: 16px !important;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(242, 245, 247, 0.96)),
    var(--pearl-surface) !important;
  overflow: hidden !important;
}

body.subpage-shell .admin-wrap > .admin-header {
  grid-area: header !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  min-height: 64px !important;
  margin: 0 !important;
  padding: 12px 16px !important;
  border-radius: 18px !important;
}

body.subpage-shell .admin-wrap > .admin-header > div:first-child {
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
  min-width: 0 !important;
}

body.subpage-shell .admin-wrap > .admin-header h1 {
  margin: 0 !important;
  color: var(--pearl-primary) !important;
  font-size: 22px !important;
  line-height: 1.15 !important;
  white-space: nowrap !important;
}

body.subpage-shell #adminTotalDataCount,
body.subpage-shell #adminStatsVersion {
  display: inline-flex !important;
  align-items: center !important;
  min-height: 28px !important;
  padding: 0 10px !important;
  border: 1px solid rgba(32, 139, 238, 0.18) !important;
  border-radius: 999px !important;
  background: rgba(237, 246, 255, 0.72) !important;
  color: #4d6b86 !important;
  font-size: 12px !important;
  font-weight: 800 !important;
}

body.subpage-shell .admin-wrap > .admin-header span[style*="color: #ccc"] {
  display: none !important;
}

body.subpage-shell .admin-wrap > .admin-header > div:last-child {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex: 0 0 auto !important;
}

body.subpage-shell .admin-wrap > .nav {
  grid-area: nav !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 8px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 12px !important;
  overflow-y: auto !important;
  border: 1px solid rgba(192, 199, 213, 0.62) !important;
  border-radius: 18px !important;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 253, 0.92)),
    var(--pearl-white) !important;
  box-shadow: var(--pearl-shadow-soft) !important;
}

body.subpage-shell .admin-wrap > .nav button {
  justify-content: flex-start !important;
  width: 100% !important;
  min-height: 44px !important;
  padding: 0 13px !important;
  border-radius: 14px !important;
  text-align: left !important;
  white-space: normal !important;
}

body.subpage-shell .admin-wrap > .panel {
  grid-area: panel !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  border-radius: 18px !important;
}

body.subpage-shell .admin-wrap > .panel iframe {
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 18px !important;
  background: var(--pearl-surface) !important;
}

body.subpage-shell:not(:has(.admin-wrap)) {
  min-height: 100dvh !important;
  padding: 14px !important;
  overflow-x: hidden !important;
}

body.subpage-shell:not(:has(.admin-wrap)) > .stats,
body.subpage-shell:not(:has(.admin-wrap)) > .stats-bar,
body.subpage-shell:not(:has(.admin-wrap)) > .tabs,
body.subpage-shell:not(:has(.admin-wrap)) > .search-box,
body.subpage-shell:not(:has(.admin-wrap)) > #snapshotGrid,
body.subpage-shell:not(:has(.admin-wrap)) > #changesList,
body.subpage-shell:not(:has(.admin-wrap)) > .settings-section,
body.subpage-shell:not(:has(.admin-wrap)) > .settings-buttons {
  width: min(100%, 1180px) !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

body.subpage-shell .approval-container,
body.subpage-shell .permission-container,
body.subpage-shell .admin-container,
body.subpage-shell > .container {
  display: grid !important;
  gap: 14px !important;
}

body.subpage-shell .approval-container > .header,
body.subpage-shell .permission-container > .header,
body.subpage-shell .admin-container > .admin-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  margin-bottom: 0 !important;
}

body.subpage-shell .approval-container > .header > div,
body.subpage-shell .permission-container > .header > div,
body.subpage-shell .admin-container > .admin-header > div {
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
}

body.subpage-shell .approval-container .stats,
body.subpage-shell .admin-container .user-stats,
body.subpage-shell > .stats,
body.subpage-shell > .stats-bar {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 12px !important;
  margin-bottom: 0 !important;
}

body.subpage-shell .tabs {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  overflow: visible !important;
}

body.subpage-shell .tab {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 38px !important;
  padding: 0 14px !important;
}

body.subpage-shell .search-box {
  display: grid !important;
  grid-template-columns: minmax(240px, 1fr) minmax(180px, 260px) !important;
  gap: 10px !important;
  margin-bottom: 0 !important;
}

body.subpage-shell .grant-form,
body.subpage-shell .form-row,
body.subpage-shell .add-form-row,
body.subpage-shell .settings-row {
  gap: 10px !important;
}

body.subpage-shell .grant-form {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}

body.subpage-shell .permission-container .panel,
body.subpage-shell .user-table,
body.subpage-shell .user-table-container {
  padding: 16px !important;
}

body.subpage-shell .permission-table,
body.subpage-shell .user-table table,
body.subpage-shell .user-table-container table,
body.subpage-shell .preview-table {
  min-width: 760px !important;
}

body.subpage-shell .snapshot-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
  gap: 12px !important;
}

body.subpage-shell .change-item {
  padding: 14px !important;
}

body.subpage-shell .settings-section {
  padding: 16px !important;
}

body.subpage-shell .settings-row {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

body.subpage-shell .settings-item label,
body.subpage-shell .add-form-row label {
  min-width: 0 !important;
}

body.subpage-shell .settings-item label {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
}

body.subpage-shell .settings-item input[type="range"] {
  min-width: 120px !important;
}

@media (max-width: 1100px) {
  body.subpage-shell .admin-wrap {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto minmax(0, 1fr) !important;
    grid-template-areas:
      "header"
      "nav"
      "panel" !important;
    min-height: 100dvh !important;
  }

  body.subpage-shell .admin-wrap > .nav {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    height: auto !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
  }

  body.subpage-shell .admin-wrap > .nav button {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 132px !important;
    justify-content: center !important;
    text-align: center !important;
    white-space: nowrap !important;
  }

  body.subpage-shell .approval-container .stats,
  body.subpage-shell .admin-container .user-stats,
  body.subpage-shell > .stats,
  body.subpage-shell > .stats-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 767px) {
  body.subpage-shell .admin-wrap,
  body.subpage-shell .admin-container,
  body.subpage-shell .approval-container,
  body.subpage-shell .permission-container,
  body.subpage-shell > .container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px !important;
  }

  body.subpage-shell .admin-header,
  body.subpage-shell .approval-container > .header,
  body.subpage-shell .permission-container > .header {
    align-items: stretch !important;
    flex-direction: column !important;
    border-radius: 16px !important;
    gap: 10px !important;
  }

  body.subpage-shell .admin-header h1,
  body.subpage-shell .approval-container > .header h1,
  body.subpage-shell .permission-container > .header h1 {
    font-size: 20px !important;
  }

  body.subpage-shell .nav,
  body.subpage-shell .tabs,
  body.subpage-shell .search-box,
  body.subpage-shell .grant-form,
  body.subpage-shell .form-row,
  body.subpage-shell .settings-row,
  body.subpage-shell .add-form-row {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  body.subpage-shell .admin-wrap {
    height: auto !important;
    min-height: 100dvh !important;
    overflow: visible !important;
  }

  body.subpage-shell .admin-wrap > .panel {
    min-height: 70dvh !important;
  }

  body.subpage-shell .admin-wrap > .nav {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    overflow: visible !important;
  }

  body.subpage-shell .admin-wrap > .nav button {
    width: 100% !important;
    min-width: 0 !important;
    white-space: normal !important;
  }

  body.subpage-shell .search-box input,
  body.subpage-shell .search-box select,
  body.subpage-shell .grant-form .form-group,
  body.subpage-shell .settings-item,
  body.subpage-shell .form-row input,
  body.subpage-shell .form-row select,
  body.subpage-shell .add-form input[type="text"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  body.subpage-shell .search-box input,
  body.subpage-shell .grant-form .form-group,
  body.subpage-shell .settings-item-2col,
  body.subpage-shell .settings-item-3col {
    grid-column: 1 / -1;
  }

  body.subpage-shell .stats,
  body.subpage-shell .user-stats,
  body.subpage-shell .stats-bar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  body.subpage-shell .approval-container .stats,
  body.subpage-shell .admin-container .user-stats,
  body.subpage-shell > .stats,
  body.subpage-shell > .stats-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  body.subpage-shell .snapshot-grid {
    grid-template-columns: 1fr !important;
  }

  body.subpage-shell .snapshot-actions,
  body.subpage-shell .card-row-2,
  body.subpage-shell .settings-buttons {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  body.subpage-shell .user-table,
  body.subpage-shell .user-table-container,
  body.subpage-shell .permission-container .panel {
    padding: 12px !important;
  }
}

@media (max-width: 520px) {
  body.subpage-shell:not(:has(.admin-wrap)) {
    padding: 10px !important;
  }

  body.subpage-shell .admin-wrap {
    padding: 10px !important;
    gap: 10px !important;
  }

  body.subpage-shell .admin-wrap > .admin-header > div:last-child,
  body.subpage-shell .approval-container > .header > div,
  body.subpage-shell .permission-container > .header > div,
  body.subpage-shell .admin-container > .admin-header > div {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100% !important;
  }

  body.subpage-shell .admin-wrap > .admin-header button,
  body.subpage-shell .approval-container > .header button,
  body.subpage-shell .permission-container > .header button,
  body.subpage-shell .admin-container > .admin-header button {
    width: 100% !important;
  }

  body.subpage-shell .nav,
  body.subpage-shell .tabs,
  body.subpage-shell .search-box,
  body.subpage-shell .grant-form,
  body.subpage-shell .form-row,
  body.subpage-shell .settings-row,
  body.subpage-shell .add-form-row,
  body.subpage-shell .settings-buttons {
    grid-template-columns: 1fr !important;
  }

  body.subpage-shell .approval-container .stats,
  body.subpage-shell .admin-container .user-stats,
  body.subpage-shell > .stats,
  body.subpage-shell > .stats-bar {
    grid-template-columns: 1fr 1fr !important;
  }

  body.subpage-shell .stat-card,
  body.subpage-shell .stat-item {
    padding: 12px !important;
  }
}

/* Final AI assistant overrides: keep the assistant polished after global mobile rules. */
#aiAssistantPanel.ai-assistant-panel {
  display: grid !important;
  gap: 12px !important;
  width: 100% !important;
  max-width: min(1180px, 100%) !important;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

#aiAssistantPanel[hidden] {
  display: none !important;
}

#aiAssistantPanel .ai-hero,
#aiAssistantPanel .ai-card {
  border: 1px solid rgba(192, 199, 213, 0.62) !important;
  border-radius: 18px !important;
  background: linear-gradient(145deg, rgba(255,255,255,0.99), rgba(246,250,254,0.96)) !important;
  box-shadow: 0 14px 34px rgba(0, 93, 167, 0.08) !important;
}

#aiAssistantPanel .ai-hero {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 12px !important;
  padding: 12px 16px !important;
}

#aiAssistantPanel .ai-grid {
  display: grid !important;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr) !important;
  gap: 16px !important;
}

#aiAssistantPanel .ai-card {
  min-width: 0 !important;
  padding: 16px !important;
}

#aiAssistantPanel .ai-card-head {
  display: flex !important;
  align-items: flex-start !important;
  justify-content: space-between !important;
  gap: 12px !important;
  margin-bottom: 12px !important;
}

#aiAssistantPanel .ai-hero h2,
#aiAssistantPanel .ai-card h3 {
  margin: 0 !important;
  color: #15324a !important;
  line-height: 1.2 !important;
  letter-spacing: 0 !important;
}

#aiAssistantPanel .ai-hero h2 {
  font-size: 22px !important;
  line-height: 1.15 !important;
}

#aiAssistantPanel .ai-hero p,
#aiAssistantPanel .ai-card p,
#aiAssistantPanel .ai-safe-note {
  margin: 3px 0 0 !important;
  color: #657081 !important;
  font-size: 14px !important;
  line-height: 1.35 !important;
}

#aiAssistantPanel #aiUserInput {
  width: 100% !important;
  min-height: 112px !important;
  resize: vertical !important;
  border: 1px solid rgba(192, 199, 213, 0.72) !important;
  border-radius: 15px !important;
  background: #fff !important;
  padding: 12px 14px !important;
  color: #263241 !important;
  font: inherit !important;
  box-sizing: border-box !important;
}

#aiAssistantPanel .ai-actions,
#aiAssistantPanel .ai-result-actions {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 10px !important;
  margin-top: 12px !important;
}

#aiAssistantPanel .ai-actions button,
#aiAssistantPanel .ai-result-actions button,
#aiAssistantPanel #btnAiBackToNumbers {
  width: auto !important;
  min-width: 0 !important;
  min-height: 40px !important;
  height: auto !important;
  padding: 0 16px !important;
  border-radius: 13px !important;
  font-size: 14px !important;
  font-weight: 800 !important;
  white-space: nowrap !important;
}

#aiAssistantPanel .ai-examples {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
  margin-top: 13px !important;
}

#aiAssistantPanel .ai-examples button {
  width: auto !important;
  min-width: 0 !important;
  min-height: 32px !important;
  height: auto !important;
  padding: 0 11px !important;
  border: 1px solid rgba(32, 139, 238, 0.24) !important;
  border-radius: 999px !important;
  background: #edf6ff !important;
  color: var(--pearl-primary) !important;
  font-size: 12px !important;
  font-weight: 800 !important;
}

#aiAssistantPanel .ai-settings-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 10px !important;
}

#aiAssistantPanel .ai-settings-card.is-collapsed {
  align-self: start !important;
  padding: 12px 14px !important;
}

#aiAssistantPanel .ai-settings-card.is-collapsed .ai-card-head {
  align-items: center !important;
  margin-bottom: 8px !important;
}

#aiAssistantPanel .ai-settings-card.is-collapsed .ai-card-head p {
  display: none !important;
}

#aiAssistantPanel .ai-settings-summary {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px !important;
  min-height: 36px !important;
  padding: 8px 10px !important;
  border: 1px solid rgba(32, 139, 238, 0.18) !important;
  border-radius: 13px !important;
  background: rgba(237, 246, 255, 0.72) !important;
}

#aiAssistantPanel .ai-settings-summary[hidden],
#aiAssistantPanel .ai-settings-body[hidden] {
  display: none !important;
}

#aiAssistantPanel #aiSettingsSummaryText {
  min-width: 0 !important;
  overflow: hidden !important;
  color: #405062 !important;
  font-size: 13px !important;
  font-weight: 800 !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

#aiAssistantPanel #btnAiEditSettings {
  flex: 0 0 auto !important;
  min-height: 32px !important;
  height: 32px !important;
  padding: 0 12px !important;
  border-radius: 11px !important;
  font-size: 12px !important;
}

#aiAssistantPanel .ai-settings-grid label {
  display: grid !important;
  gap: 6px !important;
  min-width: 0 !important;
  color: #506070 !important;
  font-size: 12px !important;
  font-weight: 800 !important;
}

#aiAssistantPanel .ai-settings-grid input,
#aiAssistantPanel .ai-settings-grid select {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  min-height: 40px !important;
  height: 40px !important;
  border: 1px solid rgba(192, 199, 213, 0.72) !important;
  border-radius: 12px !important;
  background: #fff !important;
  padding: 0 10px !important;
  color: #263241 !important;
  font-size: 14px !important;
  box-sizing: border-box !important;
}

#aiAssistantPanel .ai-checkbox {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  margin-top: 12px !important;
  color: #405062 !important;
  font-size: 13px !important;
  font-weight: 750 !important;
}

#aiAssistantPanel .ai-checkbox input {
  width: auto !important;
  min-height: 0 !important;
}

#aiAssistantPanel .ai-result-toolbar {
  display: flex !important;
  align-items: flex-start !important;
  justify-content: space-between !important;
  gap: 14px !important;
  padding-bottom: 12px !important;
  border-bottom: 1px solid rgba(192, 199, 213, 0.46) !important;
}

#aiAssistantPanel .ai-result-toolbar > div:first-child {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 10px !important;
  color: #657081 !important;
  font-size: 13px !important;
}

#aiAssistantPanel .ai-results-empty {
  padding: 28px 10px !important;
  color: #7a8494 !important;
  text-align: center !important;
}

@media (max-width: 1024px) {
  #aiAssistantPanel .ai-grid {
    grid-template-columns: 1fr !important;
  }

  #aiAssistantPanel .ai-result-toolbar {
    flex-direction: column !important;
  }
}

@media (max-width: 767px) {
  #aiAssistantPanel.ai-assistant-panel {
    gap: 12px !important;
  }

  #aiAssistantPanel .ai-hero,
  #aiAssistantPanel .ai-card {
    border-radius: 16px !important;
    padding: 11px 12px !important;
  }

  #aiAssistantPanel .ai-hero {
    align-items: stretch !important;
    flex-direction: column !important;
  }

  #aiAssistantPanel .ai-hero h2 {
    font-size: 21px !important;
  }

  #aiAssistantPanel .ai-settings-grid {
    grid-template-columns: 1fr !important;
  }

  #aiAssistantPanel .ai-actions button,
  #aiAssistantPanel .ai-result-actions button {
    flex: 1 1 140px !important;
  }
}

/* Final sidebar correction: keep the same pearl rail style through the iPad/narrow desktop range. */
.app-sidebar .sidebar-profile-text {
  display: none !important;
}

.app-sidebar .sidebar-app-version {
  display: inline-flex !important;
  align-items: center !important;
  align-self: center !important;
  min-height: 20px !important;
  padding: 0 7px !important;
  border-radius: 999px !important;
  background: rgba(32, 139, 238, 0.12) !important;
  color: var(--pearl-primary) !important;
  font-size: 11px !important;
  font-weight: 850 !important;
  line-height: 1.2 !important;
  letter-spacing: 0 !important;
  white-space: nowrap !important;
}

.app-sidebar .sidebar-profile {
  justify-content: center !important;
}

@media (min-width: 768px) {
  .app-sidebar {
    box-sizing: border-box !important;
    display: flex !important;
    flex-direction: column !important;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(242, 247, 252, 0.98)),
      var(--pearl-white) !important;
    border-right: 1px solid rgba(192, 199, 213, 0.62) !important;
    box-shadow: 10px 0 30px rgba(0, 93, 167, 0.08) !important;
  }

  .app-sidebar .sidebar-profile {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    justify-content: flex-start !important;
    padding: 0 0 18px !important;
    border-bottom: 1px solid rgba(192, 199, 213, 0.48) !important;
  }

  .app-sidebar .sidebar-avatar {
    display: grid !important;
    width: 42px !important;
    height: 42px !important;
    flex: 0 0 42px !important;
    place-items: center !important;
    border-radius: 50% !important;
    background: linear-gradient(145deg, #d7e9ff, #ffffff 58%, #c7ddf6) !important;
    color: var(--pearl-primary) !important;
    font-size: 15px !important;
    font-weight: 850 !important;
    box-shadow: 0 8px 20px rgba(0, 93, 167, 0.14) !important;
  }

  .app-sidebar .sidebar-app-version {
    display: inline-flex !important;
  }

  body:not(.sidebar-expanded) .app-sidebar .sidebar-profile {
    justify-content: center !important;
    gap: 0 !important;
  }

  body:not(.sidebar-expanded) .app-sidebar .sidebar-app-version {
    display: none !important;
  }

  body.sidebar-expanded .sidebar-nav,
  body.sidebar-expanded .sidebar-bottom {
    width: 100% !important;
    min-width: 0 !important;
  }

  body.sidebar-expanded .sidebar-nav-item,
  body.sidebar-expanded .sidebar-add,
  body.sidebar-expanded .sidebar-logout {
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    border: 1px solid transparent !important;
    background: transparent !important;
    color: #263241 !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: static !important;
    transform: none !important;
    visibility: visible !important;
  }

  body.sidebar-expanded .sidebar-nav-item.active,
  body.sidebar-expanded .sidebar-nav-item:hover {
    background: linear-gradient(135deg, #a9d2ff, #78b8f3) !important;
    border-color: rgba(32, 139, 238, 0.18) !important;
    color: #06395f !important;
    box-shadow: 0 8px 20px rgba(32, 139, 238, 0.16) !important;
  }

  body.sidebar-expanded .sidebar-danger-item {
    color: #a61919 !important;
  }

  body.sidebar-expanded .sidebar-danger-item.active,
  body.sidebar-expanded .sidebar-danger-item:hover {
    background: #fff2f2 !important;
    border-color: rgba(186, 26, 26, 0.2) !important;
    color: #a61919 !important;
    box-shadow: none !important;
  }

  body.sidebar-expanded .sidebar-add {
    justify-content: center !important;
    background: linear-gradient(135deg, var(--pearl-primary-bright), #0069bd) !important;
    color: #fff !important;
    box-shadow: 0 10px 22px rgba(0, 93, 167, 0.22) !important;
  }

  body.sidebar-expanded .sidebar-logout {
    justify-content: flex-start !important;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  body.sidebar-expanded .app-sidebar {
    width: var(--sidebar-expanded-width) !important;
    padding: 16px 10px 18px !important;
    border-radius: 0 !important;
    overflow: hidden auto !important;
  }

  body.sidebar-expanded .wrap {
    box-sizing: border-box !important;
    width: calc(100vw - var(--sidebar-expanded-width)) !important;
    max-width: calc(100vw - var(--sidebar-expanded-width)) !important;
    min-width: 0 !important;
    margin-left: var(--sidebar-expanded-width) !important;
    overflow-x: hidden !important;
  }

  body.sidebar-expanded .sidebar-nav {
    gap: 7px !important;
  }

  body.sidebar-expanded .sidebar-nav-item,
  body.sidebar-expanded .sidebar-add,
  body.sidebar-expanded .sidebar-logout {
    min-height: 42px !important;
    padding: 0 12px !important;
    border-radius: 14px !important;
    gap: 10px !important;
    font-size: 13px !important;
    font-weight: 760 !important;
    letter-spacing: 0 !important;
  }

  body.sidebar-expanded .sidebar-sub-item {
    padding-left: 32px !important;
  }

  body.sidebar-expanded .sidebar-icon {
    width: 20px !important;
    flex: 0 0 20px !important;
    font-size: 16px !important;
  }

  body.sidebar-expanded .sidebar-bottom {
    gap: 8px !important;
    padding-top: 14px !important;
  }
}

/* Keep the centered title and version on one horizontal line. */
@media (min-width: 768px) {
  .app-topbar .top-left {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-direction: row !important;
    gap: 20px !important;
    width: auto !important;
    max-width: min(420px, calc(100% - 360px)) !important;
    white-space: nowrap !important;
  }

  .app-topbar #appTitle,
  .app-topbar #appVersion {
    flex: 0 0 auto !important;
    margin: 0 !important;
  }
}

/* Match the expanded desktop sidebar spacing to the mobile drawer rhythm. */
@media (min-width: 1024px) {
  body.sidebar-expanded .app-sidebar {
    padding: 28px 16px 28px !important;
  }

  body.sidebar-expanded .app-sidebar .sidebar-profile {
    padding: 0 0 28px !important;
    margin-bottom: 20px !important;
    border-bottom: 1px solid rgba(192, 199, 213, 0.56) !important;
  }

  body.sidebar-expanded .app-sidebar .sidebar-avatar {
    width: 54px !important;
    height: 54px !important;
    flex-basis: 54px !important;
    font-size: 20px !important;
    box-shadow: 0 14px 30px rgba(0, 93, 167, 0.14) !important;
  }

  body.sidebar-expanded .app-sidebar .sidebar-app-version {
    font-size: 12px !important;
    padding: 0 7px !important;
  }

  body.sidebar-expanded .sidebar-nav {
    gap: 12px !important;
    padding: 0 0 18px !important;
  }

  body.sidebar-expanded .sidebar-nav-item,
  body.sidebar-expanded .sidebar-add,
  body.sidebar-expanded .sidebar-logout {
    min-height: 54px !important;
    padding: 0 22px !important;
    border-radius: 20px !important;
    gap: 14px !important;
    font-size: 16px !important;
    font-weight: 820 !important;
  }

  body.sidebar-expanded .sidebar-sub-item {
    padding-left: 52px !important;
  }

  body.sidebar-expanded .sidebar-icon {
    width: 24px !important;
    flex: 0 0 24px !important;
    font-size: 20px !important;
  }

  body.sidebar-expanded .sidebar-bottom {
    gap: 16px !important;
    padding-top: 22px !important;
    border-top: 1px solid rgba(192, 199, 213, 0.56) !important;
  }

  body.sidebar-expanded .sidebar-add {
    min-height: 58px !important;
    justify-content: center !important;
  }

  body.sidebar-expanded .sidebar-logout {
    justify-content: center !important;
    color: var(--pearl-primary) !important;
  }
}

/* Force visible spacing between desktop sidebar rows, including adjacent active pills. */
@media (min-width: 1024px) {
  body.sidebar-expanded .sidebar-nav {
    gap: 0 !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item {
    margin: 0 0 14px !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-sub-item {
    margin-bottom: 18px !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item:last-child {
    margin-bottom: 0 !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item.active + .sidebar-nav-item,
  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item:hover + .sidebar-nav-item {
    margin-top: 2px !important;
  }
}

/* Adaptive sidebar rhythm: proportional spacing that still fits all actions on common desktop heights. */
@media (min-width: 1024px) {
  :root {
    --desktop-sidebar-pad-x: clamp(10px, 0.85vw, 16px);
    --desktop-sidebar-pad-y: clamp(14px, 2.1vh, 24px);
    --desktop-sidebar-avatar: clamp(42px, 5.4vh, 54px);
    --desktop-sidebar-row: clamp(40px, 4.9vh, 50px);
    --desktop-sidebar-radius: clamp(14px, 1.4vw, 18px);
    --desktop-sidebar-gap: clamp(6px, 1.05vh, 10px);
    --desktop-sidebar-sub-gap: clamp(8px, 1.2vh, 12px);
    --desktop-sidebar-font: clamp(13px, 1.25vw, 15px);
  }

  body.sidebar-expanded .app-sidebar {
    padding: var(--desktop-sidebar-pad-y) var(--desktop-sidebar-pad-x) !important;
  }

  body.sidebar-expanded .app-sidebar .sidebar-profile {
    padding: 0 0 clamp(12px, 1.8vh, 20px) !important;
    margin-bottom: clamp(12px, 1.8vh, 18px) !important;
  }

  body.sidebar-expanded .app-sidebar .sidebar-avatar {
    width: var(--desktop-sidebar-avatar) !important;
    height: var(--desktop-sidebar-avatar) !important;
    flex-basis: var(--desktop-sidebar-avatar) !important;
    font-size: clamp(16px, 2vh, 20px) !important;
  }

  body.sidebar-expanded .sidebar-nav {
    gap: 0 !important;
    padding: 0 0 clamp(8px, 1.4vh, 14px) !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item {
    margin: 0 0 var(--desktop-sidebar-gap) !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-sub-item {
    margin-bottom: var(--desktop-sidebar-sub-gap) !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item:last-child {
    margin-bottom: 0 !important;
  }

  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item.active + .sidebar-nav-item,
  body.sidebar-expanded .sidebar-nav > .sidebar-nav-item:hover + .sidebar-nav-item {
    margin-top: 0 !important;
  }

  body.sidebar-expanded .sidebar-nav-item,
  body.sidebar-expanded .sidebar-add,
  body.sidebar-expanded .sidebar-logout {
    min-height: var(--desktop-sidebar-row) !important;
    padding: 0 clamp(14px, 1.4vw, 20px) !important;
    border-radius: var(--desktop-sidebar-radius) !important;
    gap: clamp(10px, 1vw, 13px) !important;
    font-size: var(--desktop-sidebar-font) !important;
    font-weight: 800 !important;
  }

  body.sidebar-expanded .sidebar-sub-item {
    padding-left: clamp(34px, 3.2vw, 46px) !important;
  }

  body.sidebar-expanded .sidebar-icon {
    width: clamp(20px, 1.7vw, 23px) !important;
    flex-basis: clamp(20px, 1.7vw, 23px) !important;
    font-size: clamp(16px, 1.6vw, 19px) !important;
  }

  body.sidebar-expanded .sidebar-bottom {
    gap: clamp(8px, 1.2vh, 12px) !important;
    padding-top: clamp(12px, 1.8vh, 18px) !important;
  }

  body.sidebar-expanded .sidebar-add {
    min-height: clamp(44px, 5vh, 52px) !important;
  }

  body:not(.sidebar-expanded) .app-sidebar {
    padding: clamp(14px, 2vh, 20px) 8px !important;
  }

  body:not(.sidebar-expanded) .sidebar-profile {
    padding-bottom: clamp(12px, 1.8vh, 18px) !important;
  }

  body:not(.sidebar-expanded) .sidebar-app-version {
    display: none !important;
  }

  body:not(.sidebar-expanded) .sidebar-nav {
    gap: clamp(6px, 1vh, 10px) !important;
  }

  body:not(.sidebar-expanded) .sidebar-nav-item,
  body:not(.sidebar-expanded) .sidebar-bottom::before {
    width: clamp(44px, 5vh, 50px) !important;
    min-width: clamp(44px, 5vh, 50px) !important;
    height: clamp(44px, 5vh, 50px) !important;
    min-height: clamp(44px, 5vh, 50px) !important;
    border-radius: clamp(14px, 1.4vw, 16px) !important;
  }
}

/* AI settings now sits as a compact strip directly under the AI assistant header. */
#aiAssistantPanel > .ai-settings-card {
  display: grid !important;
  gap: 0 !important;
  padding: 10px 14px !important;
  cursor: pointer !important;
}

#aiAssistantPanel .ai-hero > div:first-child {
  display: flex !important;
  align-items: baseline !important;
  gap: 12px !important;
  min-width: 0 !important;
}

#aiAssistantPanel .ai-hero .ai-eyebrow,
#aiAssistantPanel .ai-hero h2,
#aiAssistantPanel .ai-hero p {
  flex: 0 0 auto !important;
  margin: 0 !important;
  white-space: nowrap !important;
}

#aiAssistantPanel .ai-hero > div:first-child > p:last-child {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

#aiAssistantPanel > .ai-settings-card .ai-card-head {
  align-items: center !important;
  margin-bottom: 0 !important;
}

#aiAssistantPanel > .ai-settings-card .ai-card-head > div {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  min-width: 0 !important;
}

#aiAssistantPanel > .ai-settings-card .ai-card-head h3 {
  flex: 0 0 auto !important;
  font-size: 16px !important;
}

#aiAssistantPanel > .ai-settings-card .ai-card-head p {
  margin: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

#aiAssistantPanel > .ai-settings-card.is-collapsed {
  grid-template-columns: minmax(0, auto) minmax(260px, 1fr) !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 10px 14px !important;
}

#aiAssistantPanel > .ai-settings-card.is-collapsed .ai-card-head {
  min-width: 0 !important;
}

#aiAssistantPanel > .ai-settings-card.is-collapsed .ai-card-head p {
  display: none !important;
}

#aiAssistantPanel > .ai-settings-card.is-collapsed .ai-settings-summary {
  min-height: 34px !important;
  padding: 6px 8px !important;
}

#aiAssistantPanel > .ai-settings-card:not(.is-collapsed) .ai-settings-body {
  margin-top: 12px !important;
  cursor: default !important;
}

#aiAssistantPanel > .ai-settings-card .ai-settings-body,
#aiAssistantPanel > .ai-settings-card input,
#aiAssistantPanel > .ai-settings-card select,
#aiAssistantPanel > .ai-settings-card label,
#aiAssistantPanel > .ai-settings-card .ai-actions {
  cursor: default !important;
}

#aiAssistantPanel .ai-grid {
  grid-template-columns: 1fr !important;
}

#aiAssistantPanel .ai-query-card {
  width: 100% !important;
}

#aiAssistantPanel .ai-query-compose {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 34%) !important;
  align-items: stretch !important;
  gap: 14px !important;
}

#aiAssistantPanel .ai-query-side {
  display: flex !important;
  min-width: 0 !important;
  flex-direction: column !important;
  justify-content: flex-start !important;
  gap: 10px !important;
}

#aiAssistantPanel .ai-query-side .ai-actions,
#aiAssistantPanel .ai-query-side .ai-examples {
  margin-top: 0 !important;
}

#aiAssistantPanel .ai-query-side .ai-actions {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 8px !important;
}

#aiAssistantPanel .ai-query-side .ai-actions button {
  width: 100% !important;
  min-height: 40px !important;
  padding: 0 10px !important;
}

#aiAssistantPanel .ai-query-side .ai-examples {
  display: flex !important;
  align-content: flex-start !important;
  align-items: flex-start !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
}

#aiAssistantPanel .ai-query-side .ai-examples button {
  flex: 0 1 auto !important;
}

#aiAssistantPanel .ai-summary-panel {
  margin-top: 12px !important;
  padding: 12px 14px !important;
  border-color: rgba(32, 139, 238, 0.18) !important;
  border-radius: 14px !important;
  background: rgba(240, 248, 255, 0.72) !important;
  color: #263241 !important;
}

#aiAssistantPanel .ai-summary-panel h3 {
  margin: 0 0 8px !important;
  color: #15324a !important;
  font-size: 16px !important;
  font-weight: 850 !important;
  line-height: 1.25 !important;
}

#aiAssistantPanel .ai-summary-panel pre {
  margin: 0 !important;
  color: #405062 !important;
  font-family: var(--font-main) !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  line-height: 1.55 !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
}

#aiAssistantPanel .ai-summary-panel pre::selection {
  background: rgba(32, 139, 238, 0.2) !important;
  color: #15324a !important;
}

@media (max-width: 767px) {
  #aiAssistantPanel .ai-hero > div:first-child {
    align-items: flex-start !important;
    flex-direction: column !important;
    gap: 2px !important;
  }

  #aiAssistantPanel .ai-hero .ai-eyebrow,
  #aiAssistantPanel .ai-hero h2,
  #aiAssistantPanel .ai-hero p {
    white-space: normal !important;
  }

  #aiAssistantPanel > .ai-settings-card.is-collapsed {
    grid-template-columns: 1fr !important;
  }

  #aiAssistantPanel > .ai-settings-card .ai-card-head {
    align-items: flex-start !important;
  }

  #aiAssistantPanel > .ai-settings-card .ai-card-head > div {
    align-items: flex-start !important;
    flex-direction: column !important;
    gap: 2px !important;
  }

  #aiAssistantPanel .ai-query-compose {
    grid-template-columns: 1fr !important;
  }

  #aiAssistantPanel .ai-query-side .ai-actions {
    display: flex !important;
    flex-wrap: wrap !important;
  }

  #aiAssistantPanel .ai-summary-panel pre {
    font-size: 12.5px !important;
    line-height: 1.5 !important;
  }
}

/* Final sidebar navigation alignment: one icon column and one text column at every size. */
.app-sidebar .sidebar-nav {
  --sidebar-icon-col: 28px;
  --sidebar-text-gap: 12px;
  --sidebar-item-pad-x: 14px;
}

.app-sidebar .sidebar-nav-item {
  display: grid !important;
  grid-template-columns: var(--sidebar-icon-col) minmax(0, 1fr) !important;
  align-items: center !important;
  justify-items: stretch !important;
  column-gap: var(--sidebar-text-gap) !important;
  padding-left: var(--sidebar-item-pad-x) !important;
  padding-right: var(--sidebar-item-pad-x) !important;
  text-align: left !important;
}

.app-sidebar .sidebar-nav-item > .sidebar-icon {
  display: grid !important;
  width: var(--sidebar-icon-col) !important;
  min-width: var(--sidebar-icon-col) !important;
  max-width: var(--sidebar-icon-col) !important;
  height: 1em !important;
  place-items: center !important;
  justify-self: center !important;
  flex: 0 0 var(--sidebar-icon-col) !important;
  font-family: var(--font-main) !important;
  font-size: 16px !important;
  font-weight: 850 !important;
  line-height: 1 !important;
  text-align: center !important;
}

.app-sidebar .sidebar-nav-item > span:not(.sidebar-icon) {
  display: block !important;
  min-width: 0 !important;
  overflow: hidden !important;
  justify-self: start !important;
  text-align: left !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

body.sidebar-expanded .app-sidebar .sidebar-sub-item {
  padding-left: var(--sidebar-item-pad-x) !important;
  padding-right: var(--sidebar-item-pad-x) !important;
  font-size: inherit !important;
}

body.sidebar-expanded .app-sidebar .sidebar-nav-item,
body.sidebar-expanded .app-sidebar .sidebar-add,
body.sidebar-expanded .app-sidebar .sidebar-logout {
  justify-content: stretch !important;
}

body.sidebar-expanded .app-sidebar .sidebar-add,
body.sidebar-expanded .app-sidebar .sidebar-logout {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
}

@media (min-width: 768px) and (max-width: 1023px) {
  .app-sidebar .sidebar-nav {
    --sidebar-icon-col: 26px;
    --sidebar-text-gap: 10px;
    --sidebar-item-pad-x: 14px;
  }
}

@media (min-width: 1024px) {
  .app-sidebar .sidebar-nav {
    --sidebar-icon-col: clamp(26px, 2vw, 30px);
    --sidebar-text-gap: clamp(10px, 1vw, 12px);
    --sidebar-item-pad-x: clamp(14px, 1.4vw, 18px);
  }
}

body:not(.sidebar-expanded) .app-sidebar .sidebar-nav-item {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
}

body:not(.sidebar-expanded) .app-sidebar .sidebar-nav-item > .sidebar-icon {
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
  flex-basis: auto !important;
}

/* Management center nav: keep the four entries in one horizontal row with equal sizing. */
body.subpage-shell .admin-wrap > .nav {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: stretch !important;
  gap: 10px !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

body.subpage-shell .admin-wrap > .nav::-webkit-scrollbar {
  height: 0 !important;
}

body.subpage-shell .admin-wrap > .nav button {
  flex: 1 0 120px !important;
  min-width: 120px !important;
  max-width: none !important;
  min-height: 44px !important;
  padding: 0 12px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0 !important;
  white-space: nowrap !important;
  text-align: center !important;
  font-size: 13px !important;
  font-weight: 750 !important;
  line-height: 1.1 !important;
  box-sizing: border-box !important;
}

@media (max-width: 767px) {
  body.subpage-shell .admin-wrap > .nav {
    gap: 8px !important;
    padding: 8px !important;
  }

  body.subpage-shell .admin-wrap > .nav button {
    flex-basis: 120px !important;
    min-height: 42px !important;
    padding: 0 10px !important;
    font-size: 13px !important;
  }
}

/* Collapsed main sidebar: the version badge must not take space in the slim rail. */
body:not(.sidebar-expanded):not(.admin-with-sidebar) .app-sidebar #sidebarAppVersion,
body:not(.sidebar-expanded):not(.admin-with-sidebar) .app-sidebar .sidebar-app-version {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  position: absolute !important;
  width: 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  max-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

body:not(.sidebar-expanded):not(.admin-with-sidebar) .app-sidebar .sidebar-profile {
  justify-content: center !important;
  gap: 0 !important;
}

/* Narrow desktop/tablet sidebar: avoid the oversized desktop rhythm around 768-1180px. */
@media (min-width: 768px) and (max-width: 1180px) {
  :root {
    --sidebar-expanded-width: clamp(172px, 17.5vw, 196px);
    --sidebar-collapsed-width: clamp(60px, 6vw, 68px);
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar {
    width: var(--sidebar-expanded-width) !important;
    padding: clamp(14px, 1.8vh, 18px) 8px clamp(14px, 1.9vh, 18px) !important;
    overflow: hidden auto !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .wrap {
    width: calc(100vw - var(--sidebar-expanded-width)) !important;
    max-width: calc(100vw - var(--sidebar-expanded-width)) !important;
    margin-left: var(--sidebar-expanded-width) !important;
  }

  body:not(.sidebar-expanded):not(.admin-with-sidebar) .app-sidebar {
    width: var(--sidebar-collapsed-width) !important;
    padding: clamp(14px, 1.8vh, 18px) 8px clamp(14px, 1.9vh, 18px) !important;
  }

  body:not(.sidebar-expanded):not(.admin-with-sidebar) .wrap {
    width: calc(100vw - var(--sidebar-collapsed-width)) !important;
    max-width: calc(100vw - var(--sidebar-collapsed-width)) !important;
    margin-left: var(--sidebar-collapsed-width) !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-profile {
    gap: 8px !important;
    padding: 0 0 clamp(12px, 1.5vh, 15px) !important;
    margin-bottom: clamp(10px, 1.4vh, 13px) !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-avatar {
    width: clamp(36px, 4.2vh, 42px) !important;
    height: clamp(36px, 4.2vh, 42px) !important;
    flex-basis: clamp(36px, 4.2vh, 42px) !important;
    font-size: clamp(14px, 1.5vh, 16px) !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-app-version {
    min-height: 18px !important;
    padding: 0 6px !important;
    font-size: 10.5px !important;
    font-weight: 800 !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-nav {
    --sidebar-icon-col: 20px;
    --sidebar-text-gap: 8px;
    --sidebar-item-pad-x: 10px;
    gap: clamp(5px, 0.75vh, 7px) !important;
    padding: 0 0 clamp(8px, 1.2vh, 11px) !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-nav-item,
  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-add,
  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-logout {
    min-height: clamp(36px, 4.2vh, 40px) !important;
    border-radius: 13px !important;
    font-size: clamp(12px, 1.18vw, 13.5px) !important;
    font-weight: 700 !important;
    line-height: 1.1 !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-icon {
    font-size: clamp(14px, 1.45vw, 16px) !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-nav-item.active,
  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-nav-item:hover {
    border-color: rgba(32, 139, 238, 0.22) !important;
    background: linear-gradient(135deg, rgba(169, 210, 255, 0.82), rgba(120, 184, 243, 0.78)) !important;
    box-shadow: 0 5px 14px rgba(32, 139, 238, 0.13) !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-danger-item {
    margin-top: 0 !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-bottom {
    gap: clamp(7px, 1vh, 9px) !important;
    padding-top: clamp(10px, 1.4vh, 13px) !important;
  }

  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-add,
  body.sidebar-expanded:not(.admin-with-sidebar) .app-sidebar .sidebar-logout {
    min-height: clamp(38px, 4.4vh, 42px) !important;
    padding: 0 10px !important;
    font-size: clamp(12px, 1.16vw, 13px) !important;
    white-space: nowrap !important;
  }
}
