/* ==========================================================================
   托管班管理系统 —— 样式表（移动优先 / 浅色主题）
   ========================================================================== */

:root {
  --primary:      #2b7de9;
  --primary-600:  #1f68cc;
  --primary-50:   #eef4ff;
  --primary-100:  #dbe7ff;

  --bg:           #f4f6fa;
  --card:         #ffffff;
  --text:         #1f2937;
  --text-2:       #4b5563;
  --muted:        #6b7280;
  --border:       #e5e9f0;
  --border-strong:#d3dae5;

  --ok:     #16a34a;
  --ok-bg:  #e9f9ef;
  --warn:   #d97706;
  --warn-bg:#fef6e7;
  --danger: #dc2626;
  --danger-bg:#fef0f0;
  --info:   #64748b;
  --info-bg:#f1f5f9;
  --purple: #7c5cff;
  --purple-bg:#f1eeff;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.14);
  --sidebar-w: 216px;
  --tabbar-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button { font-family: inherit; }

/* ============================ 布局骨架 ============================ */

.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  display: none;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
}
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #34c9a3);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex: 0 0 auto;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text small { color: var(--muted); font-size: 11px; }

.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); font-size: 14.5px; font-weight: 500;
  cursor: pointer; margin-bottom: 2px; border: none; background: none;
  width: 100%; text-align: left;
}
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary-50); color: var(--primary); font-weight: 600; }
.nav-badge {
  margin-left: auto; background: var(--primary); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 20px; font-weight: 600;
}

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 14px;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 17px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-50); color: var(--primary);
  padding: 5px 11px; border-radius: 20px; font-size: 13px; font-weight: 600;
  white-space: nowrap;
}

.icon-btn {
  border: none; background: none; font-size: 20px; line-height: 1;
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg); }

.view { padding: 16px 14px calc(var(--tabbar-h) + 26px); flex: 1; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: var(--tabbar-h);
  background: rgba(255,255,255,.96);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-item {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 11px; padding: 0;
}
.tab-item .ico { font-size: 20px; line-height: 1; }
.tab-item.active { color: var(--primary); font-weight: 600; }

.drawer-mask {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(15,23,42,.42);
}

@media (min-width: 900px) {
  .sidebar { display: flex; }
  .only-mobile { display: none !important; }
  .view { padding: 20px 24px 40px; }
  .page-title { font-size: 19px; }
  .topbar { height: 62px; padding: 0 24px; }
}

@media (max-width: 899px) {
  .sidebar.drawer-open {
    display: flex; position: fixed; left: 0; top: 0; z-index: 50;
    height: 100dvh; box-shadow: var(--shadow-lg);
    animation: slideIn .18s ease;
  }
  .drawer-mask.show { display: block; }
  @keyframes slideIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
}

/* ============================ 通用组件 ============================ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card.pad-0 { padding: 0; overflow: hidden; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.card-head h3 { font-size: 15px; }
.card-head .sub { font-size: 12px; color: var(--muted); font-weight: 400; }

.section-title {
  font-size: 13px; font-weight: 600; color: var(--muted);
  letter-spacing: .3px; margin: 20px 2px 10px;
}
.section-title:first-child { margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 15px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: #fff; color: var(--text-2);
  font-size: 14px; font-weight: 500; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-danger { background: #fff; border-color: #f3c2c2; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #128a3f; }
.btn-sm { height: 31px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { margin-bottom: 14px; }
.field > label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

input[type=text], input[type=password], input[type=date], input[type=tel],
input[type=number], input[type=search], input[type=time], select, textarea {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: #fff; color: var(--text); font-size: 15px;
  outline: none; transition: border-color .12s, box-shadow .12s;
  font-family: inherit;
}
textarea { height: auto; min-height: 74px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(43,125,233,.13);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%236b7280' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* 状态徽标 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; line-height: 1.7;
  background: var(--info-bg); color: var(--info); white-space: nowrap;
}
.badge-ok     { background: var(--ok-bg);     color: var(--ok); }
.badge-warn   { background: var(--warn-bg);   color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info   { background: var(--info-bg);   color: var(--info); }
.badge-muted  { background: #f3f4f6;          color: #9ca3af; }
.badge-purple { background: var(--purple-bg); color: var(--purple); }

/* 表格式网格 */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.stat .k { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat .v { font-size: 25px; font-weight: 700; line-height: 1.1; }
.stat .u { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat.ok .v     { color: var(--ok); }
.stat.warn .v   { color: var(--warn); }
.stat.danger .v { color: var(--danger); }
.stat.primary .v{ color: var(--primary); }

/* 进度条 */
.progress { height: 7px; background: #eef1f6; border-radius: 20px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 20px; transition: width .3s; }

/* 空状态 */
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .ico { font-size: 38px; margin-bottom: 10px; opacity: .55; }
.empty p { margin: 0 0 14px; font-size: 14px; }

.loading { text-align: center; padding: 50px 0; color: var(--muted); font-size: 14px; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 表格 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td {
  padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.tbl th {
  background: #fafbfd; font-size: 12.5px; font-weight: 600; color: var(--muted);
  position: sticky; top: 0;
}
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: #fafbfd; }
table.tbl td.wrap { white-space: normal; min-width: 180px; }
.tbl-actions { display: flex; gap: 6px; }

/* 学生点名卡片 */
.roster-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: #fff;
}
.roster-item:last-child { border-bottom: none; }
.roster-item.done { background: #fcfefd; }
.roster-main { flex: 1; min-width: 0; }
.roster-name { font-weight: 600; font-size: 15.5px; display: flex; align-items: center; gap: 7px; }
.roster-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.seg { display: flex; gap: 4px; background: #f1f4f9; padding: 3px; border-radius: 10px; }
.seg button {
  border: none; background: none; cursor: pointer;
  padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 600;
  color: var(--muted); white-space: nowrap;
}
.seg button.active[data-s="已到"] { background: var(--ok); color: #fff; }
.seg button.active[data-s="迟到"] { background: var(--warn); color: #fff; }
.seg button.active[data-s="请假"] { background: var(--info); color: #fff; }
.seg button.active[data-s="缺勤"] { background: var(--danger); color: #fff; }

/* 用餐开关 */
.meal-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-strong); background: #fff;
  border-radius: 20px; padding: 4px 11px 4px 8px;
  font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer;
  white-space: nowrap;
}
.meal-toggle .dot {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: #fff; flex: 0 0 auto;
  position: relative;
}
.meal-toggle.on { background: var(--warn-bg); border-color: #f6d9a6; color: var(--warn); }
.meal-toggle.on .dot { background: var(--warn); border-color: var(--warn); }
.meal-toggle.on .dot::after {
  content: '✓'; position: absolute; inset: 0; color: #fff;
  font-size: 10px; line-height: 11px; text-align: center;
}

/* 学生列表（手机卡片） */
.stu-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.stu-card .row1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stu-card .nm { font-weight: 600; font-size: 15.5px; display: flex; align-items: center; gap: 7px; }
.stu-card .row2 { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.7; }
.stu-card .row3 { display: flex; gap: 8px; margin-top: 11px; }
.stu-card .row3 .btn { flex: 1; }

/* 分页 */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 0 4px; font-size: 13px; color: var(--muted); }

/* 工具栏 */
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { margin-bottom: 0; }
.toolbar .grow { flex: 1; min-width: 150px; }

.date-quick { display: flex; gap: 6px; }

/* ============================ 弹窗 ============================ */

.modal-root { position: relative; z-index: 100; }
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100; animation: fade .14s ease;
  overflow-y: auto;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 540px;
  max-height: calc(100dvh - 32px); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--border);
}
.modal-foot .btn { min-width: 84px; }

@media (max-width: 560px) {
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; border-radius: 18px 18px 0 0;
    max-height: 92dvh; animation: sheet .2s ease;
  }
  @keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }
  .modal-foot { padding-bottom: calc(13px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
}

/* ============================ 提示条 ============================ */

.toast-root {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 20px); z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
@media (min-width: 900px) { .toast-root { bottom: 28px; } }
.toast {
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 22px;
  font-size: 14px; box-shadow: var(--shadow-lg); animation: toastIn .18s ease;
  max-width: 92vw;
}
.toast.ok     { background: #12884f; }
.toast.err    { background: #c62d2d; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.alert {
  border-radius: 10px; padding: 11px 13px; font-size: 13.5px;
  margin-bottom: 14px; border: 1px solid;
}
.alert-warn   { background: var(--warn-bg);   border-color: #f6d9a6; color: #92600a; }
.alert-danger { background: var(--danger-bg); border-color: #f3c2c2; color: #a51f1f; }
.alert-info   { background: var(--primary-50); border-color: var(--primary-100); color: #1c5aa8; }

.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-10 { margin-bottom: 10px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.flex-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 响应式显示控制：手机只显示 .mob-only，桌面只显示 .desk-only */
.desk-only { display: none; }
.mob-only  { display: block; }
.inline-only-mobile { display: inline; }

@media (min-width: 900px) {
  .desk-only { display: block; }
  .mob-only  { display: none; }
  .inline-only-mobile { display: none; }
}
