/* ==========================================================================
   设计令牌
   颜色取自 slate / blue 色阶，层次靠明度差而非分割线堆叠。
   间距、圆角、阴影都成比例，避免各处随手写数值导致视觉不齐。
   ========================================================================== */
:root {
  /* 中性色 */
  --bg:            #f7f8fa;
  --panel:         #ffffff;
  --panel-sunken:  #f8fafc;
  --border:        #e6e8ec;
  --border-strong: #d3d7de;
  --text:          #0f172a;
  --text-soft:     #334155;
  --muted:         #64748b;
  --muted-soft:    #94a3b8;

  /* 主色 */
  --primary:       #2563eb;
  --primary-hover: #1d4ed8;
  --primary-weak:  #eff6ff;
  --primary-weak-2:#dbeafe;

  /* 语义色 */
  --success:       #15803d;
  --success-bg:    #f0fdf4;
  --success-bg-2:  #dcfce7;
  --warn:          #b45309;
  --warn-bg:       #fffbeb;
  --warn-bg-2:     #fef3c7;
  --danger:        #dc2626;
  --danger-bg:     #fef2f2;
  --danger-bg-2:   #fee2e2;

  /* 圆角 */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;
  --r-full: 999px;
  --radius: var(--r);           /* 兼容旧用法 */

  /* 阴影：多层叠加比单层更接近真实光照 */
  --shadow-xs: 0 1px 2px rgb(15 23 42 / .04);
  --shadow-sm: 0 1px 3px rgb(15 23 42 / .06), 0 1px 2px -1px rgb(15 23 42 / .04);
  --shadow-md: 0 4px 12px -2px rgb(15 23 42 / .08), 0 2px 6px -2px rgb(15 23 42 / .04);
  --shadow-lg: 0 16px 40px -8px rgb(15 23 42 / .16), 0 4px 12px -4px rgb(15 23 42 / .08);

  --t: 150ms cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
               "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 统一焦点样式：键盘可见、鼠标不打扰 */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

svg { display: block; flex: none; }

.layout { display: flex; min-height: 100vh; }

/* ==========================================================================
   侧边栏
   ========================================================================== */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 18px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 5px rgb(37 99 235 / .3);
}

#nav { display: flex; flex-direction: column; gap: 1px; }

#nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-soft);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--t), color var(--t);
}
#nav a svg { color: var(--muted-soft); transition: color var(--t); }
#nav a:hover { background: var(--panel-sunken); color: var(--text); }
#nav a:hover svg { color: var(--muted); }
#nav a.active {
  background: var(--primary-weak);
  color: var(--primary);
  font-weight: 600;
}
#nav a.active svg { color: var(--primary); }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 12px;
}

/* ==========================================================================
   主区域
   ========================================================================== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 28px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: rgb(255 255 255 / .85);
  backdrop-filter: saturate(180%) blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
  margin: 0;
}
.page-actions { display: flex; gap: 8px; }

.view { padding: 24px 28px 40px; }

/* ==========================================================================
   卡片 / 统计
   ========================================================================== */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
  overflow-x: auto;
}

.card + .card { margin-top: 16px; }

.card-title {
  font-size: 14px;
  font-weight: 650;
  margin: 0 0 14px;
  letter-spacing: -.01em;
}

/* 固定列数，避免 auto-fill 算出 5 列把 6 个卡片挤成 5+1 的孤行 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 1280px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 15px 17px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--t), transform var(--t);
}
.stat:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }

.page-intro { margin-bottom: 18px; }
.intro-hello { font-size: 22px; font-weight: 680; margin: 0; letter-spacing: -.02em; }
.intro-sub { margin: 3px 0 0; font-size: 13.5px; color: var(--muted); }

.stat-head { display: flex; align-items: center; gap: 7px; }

.stat-icon {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--panel-sunken);
  color: var(--muted);
}
.stat-primary .stat-icon { background: var(--primary-weak); color: var(--primary); }
.stat-success .stat-icon { background: var(--success-bg-2); color: var(--success); }
.stat-danger  .stat-icon { background: var(--danger-bg-2);  color: var(--danger); }

.stat-primary .stat-value { color: var(--primary); }
.stat-danger  .stat-value { color: var(--danger); }

.stat-label {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}
.stat-value {
  font-size: 25px;
  font-weight: 680;
  margin-top: 5px;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* ==========================================================================
   表格
   ========================================================================== */
table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 550;
  font-size: 11.5px;
  letter-spacing: .03em;
  text-transform: uppercase;
  background: var(--panel-sunken);
  white-space: nowrap;
}
th:first-child { border-top-left-radius: var(--r-sm); }
th:last-child  { border-top-right-radius: var(--r-sm); }

tbody tr { transition: background var(--t); }
tbody tr:hover { background: var(--panel-sunken); }
tbody tr:last-child td { border-bottom: none; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }

.empty {
  padding: 52px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}
.empty-icon { margin: 0 auto 14px; color: var(--muted-soft); opacity: .7; }
.empty-title { margin: 0; font-size: 14.5px; font-weight: 600; color: var(--text-soft); }
.empty-hint { margin: 6px auto 0; max-width: 340px; font-size: 13px; color: var(--muted); line-height: 1.6; }

/* ==========================================================================
   按钮
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text-soft);
  padding: 7px 13px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 550;
  font-family: inherit;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background var(--t), border-color var(--t), box-shadow var(--t), transform var(--t);
}
.btn:hover { background: var(--panel-sunken); border-color: var(--muted-soft); }
.btn:active { transform: translateY(.5px); box-shadow: none; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgb(37 99 235 / .24);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--panel-sunken); border-color: transparent; color: var(--text); }

.btn-link {
  border: none;
  background: none;
  color: var(--primary);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 550;
  font-family: inherit;
  transition: background var(--t), color var(--t);
}
.btn-link:hover { background: var(--primary-weak); }
.btn-link.danger { color: var(--danger); }
.btn-link.danger:hover { background: var(--danger-bg); }
.btn-link.done { color: var(--success); }
.btn-link.done:hover { background: var(--success-bg); }

/* ==========================================================================
   标签
   ========================================================================== */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
  line-height: 1.6;
}
.tag-success { background: var(--success-bg-2); color: var(--success); }
.tag-warn    { background: var(--warn-bg-2);    color: var(--warn); }
.tag-danger  { background: var(--danger-bg-2);  color: var(--danger); }
.tag-muted   { background: #eef1f5;             color: var(--muted); }

/* ==========================================================================
   表单
   ========================================================================== */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

input[type=text], input[type=number], input[type=date],
input[type=email], input[type=password], select, textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 7px 11px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  transition: border-color var(--t), box-shadow var(--t);
}
input::placeholder, textarea::placeholder { color: var(--muted-soft); }

input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover { border-color: var(--muted-soft); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(37 99 235 / .12);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 30px;
}

.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-inline { flex-direction: row; align-items: center; gap: 10px; }
.form-inline label { margin: 0; }
.cell-select select { padding: 3px 24px 3px 8px; font-size: 12px; background-position: right 6px center; }

/* ==========================================================================
   弹窗
   ========================================================================== */
[hidden] { display: none !important; }

.modal-mask {
  position: fixed; inset: 0;
  background: rgb(15 23 42 / .45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fade-in 160ms ease;
}

.modal {
  background: var(--panel);
  border-radius: var(--r-lg);
  width: 480px;
  max-width: 100%;
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-in 180ms cubic-bezier(.2, .9, .3, 1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 15.5px; font-weight: 650; letter-spacing: -.01em; }

.modal-close {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted-soft);
  font-size: 20px;
  line-height: 1;
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  transition: background var(--t), color var(--t);
}
.modal-close:hover { background: var(--panel-sunken); color: var(--text); }

.modal-body { padding: 18px; overflow: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--panel-sunken);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

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

/* ==========================================================================
   提示
   ========================================================================== */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--r-full);
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  animation: toast-in 220ms cubic-bezier(.2, .9, .3, 1);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px) }
  to   { opacity: 1; transform: translate(-50%, 0) }
}

/* ==========================================================================
   登录
   ========================================================================== */
.auth-mask {
  position: fixed; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1100px 520px at 50% -10%, #eaf1fe 0%, transparent 62%),
    var(--bg);
  z-index: 300;
  padding: 24px;
}

.auth-box {
  width: 372px;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 30px 28px 22px;
  box-shadow: var(--shadow-md);
}

.auth-brand {
  width: 40px; height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgb(37 99 235 / .28);
}

.auth-title { font-size: 21px; font-weight: 680; margin: 0 0 6px; letter-spacing: -.02em; }
.auth-sub { font-size: 13.5px; color: var(--muted); margin: 0 0 22px; line-height: 1.5; }
.auth-box .form-row input { padding: 9px 12px; font-size: 14px; }
.auth-submit { width: 100%; padding: 10px; margin-top: 6px; font-size: 14px; }

.auth-error {
  display: flex;
  gap: 8px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-bg-2);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.auth-note {
  font-size: 13px;
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success-bg-2);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  margin-top: 14px;
  line-height: 1.5;
}

.auth-switch { margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center; }

/* ==========================================================================
   账号与同步状态
   ========================================================================== */
.account {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  margin-bottom: 4px;
  border-radius: var(--r-sm);
  background: var(--panel-sunken);
}

.account-avatar {
  flex: none;
  width: 26px; height: 26px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 650;
  text-transform: uppercase;
}

.account-mail {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-dot {
  flex: none;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted-soft);
  transition: background var(--t);
}
.sync-synced  { background: #22c55e; }
.sync-saving  { background: #f59e0b; animation: pulse 1.1s ease-in-out infinite; }
.sync-error   { background: var(--danger); }
.sync-offline { background: #cbd5e1; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ==========================================================================
   提醒条
   ========================================================================== */
.alert {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--warn-bg-2);
  border-left: 3px solid #f59e0b;
  border-radius: var(--r-sm);
  background: var(--warn-bg);
}
.alert-text { flex: 1; font-size: 13px; color: var(--warn); font-weight: 500; }
.alert .btn { flex: none; background: var(--panel); }

/* ==========================================================================
   每周排课
   ========================================================================== */
.schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
  gap: 7px;
}

.schedule-day {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  background: var(--panel);
  transition: border-color var(--t), background var(--t), box-shadow var(--t);
}
.schedule-day:hover { border-color: var(--muted-soft); background: var(--panel-sunken); }
.schedule-day.is-on {
  border-color: var(--primary);
  background: var(--primary-weak);
  box-shadow: 0 0 0 1px var(--primary) inset;
}

.schedule-day input[type=checkbox] { margin: 0; cursor: pointer; accent-color: var(--primary); width: 15px; height: 15px; }
.schedule-name { flex: none; width: 30px; font-size: 13px; font-weight: 500; }
.schedule-day input[type=number] { width: 62px; margin-left: auto; padding: 4px 8px; text-align: right; }
.schedule-day input[type=number]:disabled { background: var(--panel-sunken); color: var(--muted-soft); cursor: not-allowed; }
.schedule-unit { flex: none; font-size: 12px; color: var(--muted); }
.schedule-summary { font-size: 13px; }

/* 生成预览：条数可能很多，独立滚动，不把弹窗撑爆 */
.preview-list {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  margin-top: 10px;
}
.preview-list td { padding: 7px 11px; font-size: 13px; }
.preview-list tr:last-child td { border-bottom: none; }

/* 数据冲突选择 */
.conflict-table { margin: 14px 0; }
.conflict-table th, .conflict-table td { padding: 9px 11px; font-size: 13px; }
.conflict-keep-local { width: 100%; margin-top: 6px; }

/* ==========================================================================
   年月分组折叠
   ========================================================================== */
.toolbar-gap { flex: 1; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > table { margin: 0; }

.group-row { cursor: pointer; user-select: none; }
.group-row > td { padding: 0; }

.group-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  transition: background var(--t);
}

.caret {
  flex: none;
  width: 0; height: 0;
  margin-left: 2px;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  color: var(--muted-soft);
  transition: transform var(--t);
}
.is-open > td .caret { transform: rotate(90deg); }

.group-label { font-weight: 650; letter-spacing: -.01em; }
.group-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.group-meta {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 16px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.group-hours { color: var(--muted); }
.group-fee { min-width: 88px; text-align: right; font-weight: 650; }

/* 年：主分隔，靠字号与留白拉开层级 */
.group-year > td { border-bottom: 1px solid var(--border); }
.group-year .group-line { padding: 14px; }
.group-year .group-label { font-size: 15px; }
.group-year .group-fee { color: var(--text); }
.group-year:not(:first-child) > td { border-top: 8px solid var(--bg); }
.group-row.group-year:hover .group-line { background: var(--panel-sunken); }

/* 今日课程：当天要处理的事，绿色最醒目 */
.group-today > td { border-bottom: 1px solid var(--border); }
.group-today .group-line {
  padding: 13px 14px;
  background: var(--success-bg-2);
  box-shadow: inset 3px 0 0 var(--success);
}
.group-today .group-label { font-size: 14px; color: var(--success); }
.group-today .caret { color: var(--success); }
.group-row.group-today:hover .group-line { background: #cbf3d6; }

/* 即将上课：置顶，主色区别于按年月归档的历史 */
.group-future > td { border-bottom: 1px solid var(--border); }
.group-future .group-line {
  padding: 13px 14px;
  background: var(--primary-weak);
  box-shadow: inset 3px 0 0 var(--primary);
}
.group-future .group-label { font-size: 14px; color: var(--primary); }
.group-future .caret { color: var(--primary); }
.group-row.group-future:hover .group-line { background: var(--primary-weak-2); }

/* 月：次级，浅底 + 缩进 */
.group-month > td { border-bottom: 1px solid var(--border); }
.group-month .group-line {
  padding-left: 30px;
  background: var(--panel-sunken);
  box-shadow: inset 2px 0 0 var(--border-strong);
}
.group-month .group-label { font-size: 13px; font-weight: 600; }
.group-month.is-open .group-line { box-shadow: inset 2px 0 0 var(--primary); }
.group-row.group-month:hover .group-line { background: var(--primary-weak); }

.grouped tbody tr[data-id] > td:first-child { padding-left: 30px; }

/* ==========================================================================
   星期标注
   ========================================================================== */
.weekday { color: var(--muted); font-size: 12px; margin-left: 5px; white-space: nowrap; }
.weekday:empty { margin-left: 0; }

/* ==========================================================================
   学生查询页（家长打开专属链接看到的页面）
   ========================================================================== */
.share-page { background: var(--bg); }

.share-wrap {
  max-width: 620px;
  margin: 0 auto;
  padding: 28px 18px 44px;
}

.share-head { margin-bottom: 20px; }
.share-head h1 { font-size: 26px; font-weight: 680; margin: 0; letter-spacing: -.02em; }
.share-head p { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; }

/* 四个关键数字：家长最想看的就是这些 */
.share-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.share-metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 13px 14px;
  box-shadow: var(--shadow-xs);
}
.share-metric-label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.share-metric-value {
  display: block;
  margin-top: 4px;
  font-size: 19px;
  font-weight: 680;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.share-metric-value small { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.share-metric-danger  { background: var(--danger-bg);  border-color: var(--danger-bg-2); }
.share-metric-danger .share-metric-value  { color: var(--danger); }
.share-metric-success { background: var(--success-bg); border-color: var(--success-bg-2); }
.share-metric-success .share-metric-value { color: var(--success); }

.share-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-xs);
}
.share-card h2 {
  font-size: 14px;
  font-weight: 650;
  margin: 0 0 10px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.share-count { font-size: 12px; font-weight: 500; color: var(--muted); }

.share-list { list-style: none; margin: 0; padding: 0; }
.share-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.share-list li:last-child { border-bottom: none; }
.share-list li:first-child { padding-top: 2px; }

.share-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.share-date { font-weight: 600; font-variant-numeric: tabular-nums; }
.share-meta { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.share-none { margin: 6px 0; color: var(--muted); font-size: 13px; }

.share-empty { text-align: center; padding: 44px 22px; color: var(--muted); }
.share-empty svg { margin: 0 auto 14px; color: var(--muted-soft); }
.share-empty h2 { display: block; font-size: 16px; color: var(--text); margin: 0 0 6px; }
.share-empty p { margin: 0; font-size: 13.5px; line-height: 1.6; }

.share-foot {
  margin-top: 22px;
  text-align: center;
  font-size: 12px;
  color: var(--muted-soft);
}

.share-loading { text-align: center; padding: 80px 20px; color: var(--muted); font-size: 13.5px; }
.spinner {
  width: 26px; height: 26px;
  margin: 0 auto 14px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* 分享链接弹窗 */
.share-box { margin: 12px 0 10px; }
.share-box input {
  width: 100%;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel-sunken);
  cursor: text;
}
.share-note { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

@media (max-width: 560px) {
  .share-wrap { padding: 20px 14px 36px; }
  .share-summary { grid-template-columns: repeat(2, 1fr); }
  .share-head h1 { font-size: 22px; }
}

/* ==========================================================================
   窄屏 / 手机
   ≤900px：侧边栏收起为底部标签栏，表格改成卡片
   ≤640px：更紧凑的细节调整
   ========================================================================== */
@media (max-width: 900px) {
  .layout { flex-direction: column; }

  /* 让 aside 本身消失，nav 和账号区各自参与外层布局，
     这样导航能单独固定到屏幕底部 */
  .sidebar { display: contents; }
  .brand { display: none; }

  /* 顺序：主内容 → 账号/导入导出 → （固定在屏底的导航） */
  .main { order: 1; }

  #nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    flex-direction: row;
    gap: 0;
    background: rgb(255 255 255 / .92);
    backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--border);
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
  }
  #nav a {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    text-align: center;
    padding: 6px 2px;
    font-size: 10.5px;
    font-weight: 550;
    border-radius: var(--r-sm);
  }
  #nav a.active { background: transparent; }
  #nav a svg { width: 21px; height: 21px; }

  .sidebar-footer {
    order: 2;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 16px;
    margin-bottom: 68px;
  }
  .sidebar-footer .btn { flex: 1; }
  .account { order: -1; width: 100%; margin-bottom: 0; }

  .topbar { padding: 0 16px; height: 54px; }
  .topbar h1 { font-size: 16px; }
  .view { padding: 16px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 20px; }

  .form-grid { grid-template-columns: 1fr; }
  .schedule-grid { grid-template-columns: 1fr 1fr; }

  /* 弹窗贴到屏幕底部，更像原生的底部抽屉 */
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%;
    max-height: 88vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    animation: sheet-in 240ms cubic-bezier(.2, .9, .3, 1);
  }
  .modal-footer {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    border-radius: 0;
  }
  @keyframes sheet-in { from { transform: translateY(100%) } to { transform: none } }

  /* 触摸目标放大到手指点得准的尺寸 */
  .btn { padding: 9px 15px; }
  .btn-link { padding: 8px 8px; }
  #nav a, .btn, .btn-link { -webkit-tap-highlight-color: transparent; }

  /* iOS 在 font-size < 16px 的输入框上会自动放大页面 */
  input, select, textarea { font-size: 16px; }

  /* ---- 表格改成卡片：每行一张卡，格子里用 data-label 标明字段 ---- */
  .card { padding: 0; background: none; border: none; box-shadow: none; }
  .card-title { padding: 0 2px; }

  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }

  tbody tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r);
    margin-bottom: 10px;
    padding: 5px 0;
    overflow: hidden;
    box-shadow: var(--shadow-xs);
  }
  tbody tr:hover { background: var(--panel); }
  tbody tr:last-child td { border-bottom: none; }

  td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    border: none;
    padding: 3px 13px;
    text-align: right;
  }
  td::before {
    content: attr(data-label);
    flex: none;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    text-align: left;
  }
  td.num { text-align: right; }
  td:empty { display: none; }

  /* 操作列独占一行，按钮排开 */
  td.actions {
    justify-content: flex-end;
    gap: 2px;
    border-top: 1px solid var(--border);
    margin-top: 5px;
    padding-top: 7px;
  }
  td.actions::before { display: none; }

  /* ---- 课时页的年月分组行仍然是整行标题，不能变成卡片 ---- */
  .grouped tbody tr.group-row {
    border: none;
    border-radius: 0;
    margin: 0 0 7px;
    padding: 0;
    background: none;
    box-shadow: none;
  }
  .grouped tbody tr.group-row > td {
    display: block;
    padding: 0;
    text-align: left;
    border: none;
    margin: 0;
  }
  .grouped tbody tr.group-row > td::before { display: none; }
  .group-line { border-radius: var(--r-sm); }
  .group-meta { gap: 10px; }
  .group-fee { min-width: 0; }
  .grouped tbody tr[data-id] { margin-left: 10px; width: calc(100% - 10px); }
  .grouped tbody tr[data-id] > td:first-child { padding-left: 13px; }

  /* ---- 课时记录：整条压缩成 3~4 行，一屏能多看几条 ---- */
  .grouped tbody tr[data-id] {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 3px 10px;
    padding: 11px 13px;
  }
  .grouped tbody tr[data-id] > td {
    display: flex;
    align-items: baseline;
    gap: 4px;
    width: auto;
    flex: none;
    padding: 0;
    border: none;
    margin: 0;
    text-align: left;
  }
  .grouped tbody tr[data-id] > td::before { font-size: 11px; }
  /* 没内容的格子（比如空备注）连标签一起收掉 */
  .grouped tbody tr[data-id] > td:empty { display: none; }

  /* 高度为 0 的占位块，把它之后的内容顶到第二行去 */
  .grouped tbody tr[data-id]::before {
    content: '';
    order: 3;
    flex: 1 0 100%;
    height: 0;
    margin: 0;
  }

  /* 第一行：日期占满左侧把学生挤到最右 */
  .grouped tbody tr[data-id] > td:nth-child(1) { flex: 1 1 auto; font-weight: 650; }
  .grouped tbody tr[data-id] > td:nth-child(2) { font-weight: 650; }
  .grouped tbody tr[data-id] > td:nth-child(1)::before,
  .grouped tbody tr[data-id] > td:nth-child(2)::before { display: none; }

  /* 第二行：状态 + 课时/单价/金额，小字 */
  .grouped tbody tr[data-id] > td:nth-child(6) { order: 3; }
  .grouped tbody tr[data-id] > td:nth-child(6)::before { display: none; }
  .grouped tbody tr[data-id] > td:nth-child(3),
  .grouped tbody tr[data-id] > td:nth-child(4),
  .grouped tbody tr[data-id] > td:nth-child(5) { order: 4; font-size: 12px; color: var(--muted); }
  .grouped tbody tr[data-id] > td:nth-child(5) { color: var(--text); }

  /* 备注与操作各占一行 */
  .grouped tbody tr[data-id] > td:nth-child(7) {
    order: 5; flex: 1 1 100%;
    font-size: 12px; color: var(--muted);
  }
  .grouped tbody tr[data-id] > td.actions {
    order: 6; flex: 1 1 100%;
    justify-content: flex-end;
    border-top: 1px solid var(--border);
    margin-top: 5px;
    padding-top: 5px;
  }

  /* ---- 工具栏：两个一行，日期区单独一行 ---- */
  .toolbar { gap: 8px; }
  .toolbar select, .toolbar input[type=text] { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .toolbar input[type=date] { flex: 1 1 0; min-width: 0; }
  .date-sep { flex: none; color: var(--muted); }
  .toolbar #f-reset { flex: none; }
  .toolbar .stat-label { flex: 1 1 100%; }
  .toolbar-gap { display: none; }

  .alert { flex-wrap: wrap; }
  .alert-text { flex: 1 1 100%; }

  /* ---- 弹窗里的小表格列少，保持表格形态更紧凑 ---- */
  .preview-list table, .conflict-table { display: table; }
  .preview-list tbody, .conflict-table tbody { display: table-row-group; }
  .preview-list thead, .conflict-table thead { display: table-header-group; }
  .preview-list tr, .conflict-table tr {
    display: table-row;
    background: none;
    border: none;
    border-radius: 0;
    margin: 0;
    padding: 0;
    width: auto;
    box-shadow: none;
  }
  .preview-list td, .preview-list th,
  .conflict-table td, .conflict-table th {
    display: table-cell;
    width: auto;
    text-align: left;
    padding: 7px 9px;
    border-bottom: 1px solid var(--border);
    margin: 0;
  }
  .preview-list td::before, .conflict-table td::before { display: none; }
  .preview-list td.num, .conflict-table td.num, .conflict-table th.num { text-align: right; }
  .preview-list { max-height: 46vh; }

  /* 空态在卡片化后需要自己的底 */
  .empty {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 40px 20px;
  }
}

/* 手机竖屏：两列排课勾选框也放不下了，改单列 */
@media (max-width: 640px) {
  .schedule-grid { grid-template-columns: 1fr; }
  .auth-box { padding: 26px 20px 18px; }
  .card-flush { margin: 0 -4px; }
}

@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  #nav a { font-size: 10px; }
  .view { padding: 12px; }
}

/* 尊重系统的减少动效设置 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
