/* ═══ 基础变量 ═══ */
:root {
  --primary: #2B8CFF;
  --primary-bg: #E8F2FF;
  --text: #1A1A1A;
  --text-sub: #666;
  --text-muted: #999;
  --bg: #F5F7FA;
  --border: #EAEDF0;
  --danger: #E53E3E;
  --success: #2CA56C;
  --orange: #FF9500;
  --sidebar-w: 220px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button { font-family: inherit; cursor: pointer; background: none; border: none; color: inherit; }

/* ═══ App Bar（仅移动端显示） ═══ */
.appbar { display: none; height: 56px; background: #fff; border-bottom: 1px solid var(--border); padding: 0 12px; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.hamburger { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 6px; color: #333; }
.hamburger:hover { background: #f5f5f5; }
.appbar-subject { font-weight: 600; font-size: 15px; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; }

/* ═══ 侧栏 ═══ */
.sidebar { width: var(--sidebar-w); height: 100vh; background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; left: 0; top: 0; z-index: 100; }

.subject-switcher { display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .15s; }
.subject-switcher:hover { background: #f5f8fc; }
.subject-switcher[data-count="1"] { pointer-events: none; }
.subject-switcher[data-count="1"] .subject-arrow { display: none; }
.subject-logo { width: 32px; height: 32px; border-radius: 8px; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.subject-info { flex: 1; min-width: 0; line-height: 1.3; }
.subject-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subject-role { display: inline-block; margin-top: 2px; font-size: 10px; font-weight: 500; color: var(--primary); background: var(--primary-bg); padding: 1px 6px; border-radius: 3px; }
.subject-arrow { color: #999; flex-shrink: 0; display: flex; }

.nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 20px; font-size: 14px; color: #555; text-decoration: none; transition: all .12s; }
.nav a:hover { background: #f5f8fc; color: #333; }
.nav a.active { color: var(--primary); background: #F0F6FF; font-weight: 600; }
.nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 20px; font-weight: 800; color: var(--primary); letter-spacing: -0.5px; }
.lang-switch { display: flex; gap: 2px; background: #f0f2f5; border-radius: 6px; padding: 2px; }
.lang-switch button { padding: 3px 8px; border-radius: 4px; font-size: 11px; color: #666; }
.lang-switch button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ═══ 主体下拉 ═══ */
.subject-dropdown { position: fixed; top: 0; left: var(--sidebar-w); width: 300px; background: #fff; border-radius: 0 10px 10px 0; box-shadow: 4px 0 24px rgba(0,0,0,.1); padding: 8px 0; z-index: 200; max-height: 90vh; overflow-y: auto; }
.subject-dropdown[hidden] { display: none; }
.dd-section-title { padding: 10px 16px 8px; font-size: 11px; color: #999; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.subject-list { padding: 0 8px; }
.subject-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; transition: background .15s; }
.subject-item:hover { background: #f5f8fc; }
.subject-item.current { background: var(--primary-bg); cursor: default; }
.si-logo { width: 32px; height: 32px; border-radius: 8px; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.si-info { flex: 1; min-width: 0; }
.si-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subject-item.current .si-name { color: var(--primary); }
.si-role { font-size: 11px; color: var(--text-sub); margin-top: 1px; }
.si-check { visibility: hidden; flex-shrink: 0; }
.subject-item.current .si-check { visibility: visible; }

.dd-divider { height: 1px; background: var(--border); margin: 8px 16px; }
.dd-actions { padding: 4px 8px 8px; }
.dd-action { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; width: 100%; text-align: left; font-size: 13px; color: #333; transition: background .12s; }
.dd-action:hover { background: #f5f8fc; }
.dd-action svg { color: #888; flex-shrink: 0; }

/* ═══ 主区域 ═══ */
.main-wrap { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar { height: 72px; background: #fff; border-bottom: 1px solid var(--border); padding: 0 32px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 30; }
.topbar h1 { font-size: 22px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.btn { padding: 8px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; border: 1px solid var(--border); background: #fff; color: #333; transition: all .12s; }
.btn:hover { background: #f5f8fc; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #1A7AEE; }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; transition: box-shadow .15s; }
.avatar:hover { box-shadow: 0 0 0 3px rgba(43,140,255,.2); }

/* ═══ 个人菜单 ═══ */
.user-menu { position: fixed; top: 62px; right: 24px; width: 260px; background: #fff; border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,.12); z-index: 200; overflow: hidden; }
.user-menu[hidden] { display: none; }
.user-menu-header { padding: 16px; border-bottom: 1px solid #f0f0f0; }
.um-name { font-size: 15px; font-weight: 600; }
.um-email { font-size: 12px; color: #888; margin-top: 2px; word-break: break-all; }
.user-menu-body { padding: 6px; }
.um-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px; width: 100%; text-align: left; font-size: 14px; color: #333; transition: background .12s; }
.um-item:hover { background: #f5f5f5; }
.um-item svg { width: 18px; height: 18px; color: #888; flex-shrink: 0; }
.um-item .ext { margin-left: auto; color: #bbb; font-size: 13px; }
.um-divider { height: 1px; background: #f0f0f0; margin: 4px 6px; }
.um-item.danger { color: var(--danger); }
.um-item.danger svg { color: var(--danger); }

/* ═══ 内容区 ═══ */
.content { padding: 24px 32px; }

.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab { padding: 10px 0; font-size: 14px; color: var(--text-sub); cursor: pointer; border-bottom: 2px solid transparent; transition: all .12s; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 18px; padding: 0 6px; background: #E0E4EA; color: var(--text-sub); border-radius: 9px; font-size: 11px; font-weight: 600; margin-left: 4px; }
.tab-badge.orange { background: #FFE6CC; color: var(--orange); }
.tab.active .tab-badge { background: var(--primary-bg); color: var(--primary); }

.balance-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 24px; margin-bottom: 24px; }
.balance-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.balance-label { font-size: 11px; color: var(--text-muted); letter-spacing: 0.8px; font-weight: 600; }
.balance-currency { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: #fff; }
.balance-value { font-size: 32px; font-weight: 700; margin-bottom: 4px; }
.balance-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.balance-breakdown { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px 24px; }
.balance-breakdown > div { display: flex; justify-content: space-between; font-size: 13px; }
.balance-breakdown span { color: var(--text-muted); }
.balance-breakdown strong { font-weight: 600; }

.filter-row { display: flex; gap: 12px; margin-bottom: 16px; }
.filter-row select, .filter-row input { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: #fff; }
.filter-row select { min-width: 140px; }
.filter-row input { flex: 1; max-width: 320px; }

/* ═══ 列表（桌面表格） ═══ */
.sub-accounts-list { background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.row { display: grid; grid-template-columns: 40px 2fr 1fr 1fr 1.2fr 1fr 32px; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid #F2F4F7; transition: background .1s; }
.row:last-child { border-bottom: none; }
.row:not(.header):hover { background: #FAFBFC; cursor: pointer; }
.row.header { background: #FAFBFC; font-size: 12px; color: var(--text-muted); font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase; }
.row.header:hover { cursor: default; }
.col-name strong { display: block; font-size: 14px; font-weight: 600; }
.col-name small { display: block; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.col-chev { color: var(--text-muted); text-align: right; font-size: 20px; }
.status-active { color: var(--success); font-weight: 500; }
.status-pending { color: var(--orange); font-weight: 500; }
.status-invited { color: var(--text-muted); }
.status-frozen { color: var(--danger); font-weight: 500; }

/* 遮罩 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }
.mask[hidden] { display: none; }

/* ═══════════════════════════════════════════════ */
/*  响应式断点                                     */
/* ═══════════════════════════════════════════════ */

/* 平板：侧栏默认收起，抽屉弹出 */
@media (max-width: 1023px) {
  .appbar { display: flex; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.1); }
  .main-wrap { margin-left: 0; }
  .topbar { display: none; }
  .subject-dropdown { left: 0; width: 100%; border-radius: 0; max-width: var(--sidebar-w); top: 90px; box-shadow: 4px 0 16px rgba(0,0,0,.08); }
  .user-menu { top: 60px; right: 12px; }
  .content { padding: 16px; }
}

/* 手机：表格转卡片、菜单全宽 sheet */
@media (max-width: 767px) {
  :root { --sidebar-w: 280px; }

  .topbar-actions .btn { display: none; }

  .balance-value { font-size: 26px; }
  .balance-breakdown { grid-template-columns: 1fr 1fr; gap: 8px 12px; }

  .filter-row { flex-direction: column; }
  .filter-row select, .filter-row input { width: 100%; max-width: none; }

  /* 表格 → 卡片列表 */
  .sub-accounts-list { background: transparent; border: none; }
  .row.header { display: none; }
  .row { display: grid; grid-template-columns: 1fr auto; grid-template-areas:
    "name status"
    "meta chev"; gap: 6px 12px; background: #fff; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 14px 16px; }
  .col-check { display: none; }
  .col-name { grid-area: name; }
  .col-type, .col-role, .col-created { grid-area: meta; display: inline; font-size: 12px; color: var(--text-muted); }
  .col-type::after { content: " · "; }
  .col-role::after { content: " · "; }
  .col-status { grid-area: status; justify-self: end; font-size: 12px; }
  .col-chev { grid-area: chev; justify-self: end; align-self: end; }

  /* 个人菜单在小屏改成底部 sheet */
  .user-menu { top: auto; bottom: 0; left: 0; right: 0; width: 100%; border-radius: 14px 14px 0 0; max-height: 80vh; overflow-y: auto; }
}
