/* ==========================================================================
   SchoolConnect — Hệ thống thiết kế
   Phong cách: gradient mềm, thẻ nhiều lớp, kính mờ (glassmorphism), hỗ trợ nền tối.
   ========================================================================== */

:root {
  /* Màu thương hiệu */
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-300: #a5b4fc;
  --primary-tint: #eef2ff;
  --accent: #ec4899;
  --success: #10b981;
  --success-tint: #ecfdf5;
  --warning: #f59e0b;
  --warning-tint: #fffbeb;
  --danger: #ef4444;
  --danger-tint: #fef2f2;
  --info: #0ea5e9;
  --info-tint: #f0f9ff;

  /* Nền và bề mặt */
  --bg: #f5f6fb;
  --bg-2: #eef1fa;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --surface-glass: rgba(255, 255, 255, .72);
  --line: #e8ecf5;
  --line-strong: #d9e0ee;

  /* Chữ */
  --text: #0f172a;
  --text-2: #334155;
  --muted: #6b7a90;

  /* Bo góc */
  --r-xs: 10px;
  --r-sm: 14px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 30px;
  --r-full: 999px;

  /* Đổ bóng nhiều lớp */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, .05), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 10px 26px -8px rgba(15, 23, 42, .14), 0 2px 6px rgba(15, 23, 42, .05);
  --shadow-lg: 0 28px 56px -18px rgba(15, 23, 42, .28), 0 6px 16px rgba(15, 23, 42, .08);
  --shadow-glow: 0 10px 24px -8px rgba(79, 70, 229, .5);

  --nav-h: 68px;
  --ease: cubic-bezier(.22, .8, .3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0e1a;
    --bg-2: #0f1526;
    --surface: #151b2c;
    --surface-2: #1a2136;
    --surface-glass: rgba(21, 27, 44, .78);
    --line: #253048;
    --line-strong: #33415e;
    --text: #e9edf8;
    --text-2: #c3cce0;
    --muted: #8595b0;
    --primary: #7c7cf0;
    --primary-600: #6366f1;
    --primary-tint: #1e2544;
    --success-tint: #10281f;
    --warning-tint: #2a2114;
    --danger-tint: #2b1618;
    --info-tint: #10222f;
    --shadow-md: 0 10px 26px -8px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .4);
    --shadow-lg: 0 28px 56px -18px rgba(0, 0, 0, .8), 0 6px 16px rgba(0, 0, 0, .5);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, .35);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
html, body { min-height: 100%; }

body {
  font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 620px at 8% -8%, rgba(99, 102, 241, .16), transparent 62%),
    radial-gradient(900px 560px at 105% 4%, rgba(236, 72, 153, .12), transparent 60%),
    radial-gradient(760px 520px at 50% 108%, rgba(14, 165, 233, .1), transparent 62%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Trải nghiệm chạm trên điện thoại */
  -webkit-tap-highlight-color: transparent;  /* bỏ ô sáng xanh khi chạm */
  overscroll-behavior-y: contain;            /* không kéo bật cả trang nền */
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
/* iOS Safari tự phóng to trang khi ô nhập nhỏ hơn 16px — luôn giữ tối thiểu 16px */
input, select, textarea { font-family: inherit; color: inherit; font-size: max(16px, 1em); }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
svg { display: block; flex: none; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -.015em; font-weight: 750; }

::selection { background: var(--primary); color: #fff; }

/* Thanh cuộn thanh mảnh */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== Khung ứng dụng ===== */
#app { min-height: 100dvh; }
#view {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + 34px);
  animation: view-in .34s var(--ease);
}
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Hero trang chủ ===== */
.hero {
  position: relative;
  margin: 0 -16px 22px;
  /* Chừa vùng tai thỏ khi chạy toàn màn hình (đã cài như app) */
  padding: calc(18px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) 74px calc(20px + env(safe-area-inset-left));
  color: #fff;
  background: linear-gradient(135deg, #4f46e5 0%, #6d5ce7 42%, #8b5cf6 72%, #a855f7 100%);
  border-radius: 0 0 34px 34px;
  overflow: hidden;
  isolation: isolate;
}
.hero::before,
.hero::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  z-index: -1;
  pointer-events: none;
}
.hero::before {
  width: 300px; height: 300px;
  top: -130px; right: -80px;
  background: radial-gradient(circle, rgba(255, 255, 255, .3), transparent 68%);
}
.hero::after {
  width: 240px; height: 240px;
  bottom: -110px; left: -70px;
  background: radial-gradient(circle, rgba(255, 255, 255, .2), transparent 66%);
}
.hero-top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.hero-logo {
  width: 42px; height: 42px; border-radius: 14px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 21px;
  background: rgba(255, 255, 255, .18);
  border: 1px solid rgba(255, 255, 255, .28);
  backdrop-filter: blur(10px);
}
.hero-brand { flex: 1; min-width: 0; }
.hero-brand b { display: block; font-size: 1rem; font-weight: 750; letter-spacing: -.01em; }
.hero-brand span { font-size: .78rem; opacity: .78; }
.hero-year {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(255, 255, 255, .16);
  backdrop-filter: blur(10px);
  color: #fff;
  padding: 8px 32px 8px 13px;
  border-radius: var(--r-full);
  font-size: .84rem; font-weight: 650;
  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='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
}
.hero-year option { color: #0f172a; }

.hero-greet { display: flex; align-items: center; gap: 14px; }
.hero-greet .avatar {
  border: 2.5px solid rgba(255, 255, 255, .55);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .22);
}
.hero-greet-text { flex: 1; min-width: 0; }
.hero-greet-text small { display: block; font-size: .8rem; opacity: .82; font-weight: 500; }
.hero-greet-text b { display: block; font-size: 1.24rem; font-weight: 750; letter-spacing: -.02em; margin-top: 1px; }
.hero-greet-text i { display: block; font-style: normal; font-size: .8rem; opacity: .8; margin-top: 3px; }

/* Dải chọn con trong hero */
.hero .student-bar { margin: 18px -20px -6px; padding: 4px 20px 8px; }
.hero .student-chip {
  background: rgba(255, 255, 255, .16);
  border-color: rgba(255, 255, 255, .28);
  color: #fff;
  backdrop-filter: blur(10px);
  box-shadow: none;
}
.hero .student-chip.active {
  background: #fff;
  color: var(--primary-600);
  border-color: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .18);
}

/* Bảng nổi đè lên hero (đặt ngay sau .hero) */
.hero + .tile-sheet { margin-top: -58px; }

/* ===== Thanh trên (màn hình phụ) ===== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  margin: 0 -16px 18px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-bottom: 1px solid var(--line);
}
.topbar .logo {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  box-shadow: var(--shadow-glow);
}
.topbar select {
  border: 1.5px solid var(--line); border-radius: var(--r-full);
  padding: 8px 14px; background: var(--surface); font-weight: 650; font-size: .88rem;
}

/* ===== Tiêu đề trang con ===== */
.page-head {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  margin: 0 -16px 18px;
  padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 14px calc(16px + env(safe-area-inset-left));
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-bottom: 1px solid var(--line);
}
.page-head .back-btn {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  transition: transform .16s var(--ease), background .16s;
}
.page-head .back-btn:hover { background: var(--primary-tint); color: var(--primary); transform: translateX(-2px); }
.page-head h1 { flex: 1; font-size: 1.2rem; font-weight: 750; letter-spacing: -.02em; }
.page-head .head-action {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 10px 16px; border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--primary), #7c5cf5);
  color: #fff; font-weight: 650; font-size: .87rem;
  box-shadow: var(--shadow-glow);
  transition: transform .16s var(--ease), box-shadow .16s;
}
.page-head .head-action:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -10px rgba(79, 70, 229, .65); }
.page-head .head-action:active { transform: scale(.96); }

/* ===== Lưới icon trang chủ ===== */
.tile-sheet {
  position: relative; z-index: 2;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  padding: 22px 14px 10px;
  margin-bottom: 18px;
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 6px;
}
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  padding: 4px 2px;
  border-radius: var(--r-md);
  transition: transform .18s var(--ease);
}
.tile:active { transform: scale(.93); }
.tile .tile-icon {
  width: 58px; height: 58px;
  border-radius: 19px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  position: relative;
  transition: transform .22s var(--ease), box-shadow .22s var(--ease);
}
.tile .tile-icon::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(160deg, rgba(255, 255, 255, .34), transparent 52%);
  pointer-events: none;
}
.tile:hover .tile-icon { transform: translateY(-5px) scale(1.06); }
.tile .tile-label {
  font-size: .775rem; font-weight: 650; line-height: 1.25;
  color: var(--text-2); text-align: center;
  max-width: 84px;
  min-height: 2.5em; /* giữ các ô thẳng hàng khi nhãn xuống 2 dòng */
}
.tile .tile-badge {
  position: absolute; top: -3px; right: 50%; margin-right: -37px;
  min-width: 21px; height: 21px; padding: 0 6px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: #fff; font-size: .7rem; font-weight: 750;
  display: flex; align-items: center; justify-content: center;
  border: 2.5px solid var(--surface);
  box-shadow: 0 3px 8px rgba(244, 63, 94, .45);
}

/* ===== Điều hướng dưới (kính mờ) ===== */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center; gap: 2px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface-glass);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border-top: 1px solid var(--line);
}
.bottom-nav .nav-item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 66px; padding: 7px 10px 5px;
  border-radius: var(--r-sm);
  color: var(--muted); font-size: .7rem; font-weight: 650;
  transition: color .18s, background .18s, transform .18s var(--ease);
}
.bottom-nav .nav-item:hover { color: var(--text-2); background: var(--bg-2); }
.bottom-nav .nav-item:active { transform: scale(.92); }
.bottom-nav .nav-item.active { color: var(--primary); background: var(--primary-tint); }
.bottom-nav .nav-item.active::before {
  content: '';
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 3px; border-radius: 0 0 4px 4px;
  background: var(--primary);
}
.bottom-nav .nav-badge {
  position: absolute; top: 2px; right: 9px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: #fff; font-size: .64rem; font-weight: 750;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}

/* ===== Thẻ nội dung ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 14px;
  transition: box-shadow .22s var(--ease), transform .22s var(--ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-title {
  display: flex; align-items: center; gap: 9px;
  font-size: .98rem; font-weight: 750; letter-spacing: -.015em;
  margin-bottom: 14px;
}
.card-title .spacer { flex: 1; }
.card-title svg { color: var(--primary); }

.section-label {
  margin: 22px 4px 10px;
  font-size: .74rem; font-weight: 750;
  color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
}

/* ===== Dòng danh sách ===== */
.list-row {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: background .16s;
}
.list-row:last-child { border-bottom: none; }
.list-row .row-main { flex: 1; min-width: 0; }
.list-row .row-title { font-weight: 650; font-size: .94rem; letter-spacing: -.01em; }
.list-row .row-sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.list-row .row-end { flex: none; text-align: right; }
.row-icon {
  width: 44px; height: 44px; flex: none;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff;
}
.clickable { cursor: pointer; }
.clickable:hover { background: var(--bg-2); }
.clickable:active { transform: scale(.995); opacity: .8; }

/* ===== Avatar ===== */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; overflow: hidden; flex: none;
  color: #fff;
  box-shadow: var(--shadow-xs);
}

/* ===== Huy hiệu ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px;
  border-radius: var(--r-full);
  font-size: .74rem; font-weight: 700; letter-spacing: -.005em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge.green { background: var(--success-tint); color: #047857; border-color: rgba(16, 185, 129, .22); }
.badge.red { background: var(--danger-tint); color: #b91c1c; border-color: rgba(239, 68, 68, .22); }
.badge.orange { background: var(--warning-tint); color: #b45309; border-color: rgba(245, 158, 11, .24); }
.badge.blue { background: var(--info-tint); color: #0369a1; border-color: rgba(14, 165, 233, .22); }
.badge.purple { background: var(--primary-tint); color: var(--primary-600); border-color: rgba(99, 102, 241, .22); }
.badge.gray { background: var(--bg-2); color: var(--muted); border-color: var(--line); }
@media (prefers-color-scheme: dark) {
  .badge.green { color: #6ee7b7; }
  .badge.red { color: #fca5a5; }
  .badge.orange { color: #fcd34d; }
  .badge.blue { color: #7dd3fc; }
  .badge.purple { color: var(--primary-300); }
}

/* ===== Nút ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: var(--r-sm);
  font-size: .9rem; font-weight: 700; letter-spacing: -.01em;
  transition: transform .16s var(--ease), box-shadow .18s, background .18s, opacity .16s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), #7c5cf5);
  color: #fff; box-shadow: var(--shadow-glow);
}
.btn.primary:hover { box-shadow: 0 14px 32px -10px rgba(79, 70, 229, .65); transform: translateY(-1px); }
.btn.outline {
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line-strong);
}
.btn.outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-tint); }
.btn.danger-soft { background: var(--danger-tint); color: #b91c1c; border: 1px solid rgba(239, 68, 68, .2); }
.btn.danger-soft:hover { background: #fee2e2; }
.btn.success-soft { background: var(--success-tint); color: #047857; border: 1px solid rgba(16, 185, 129, .2); }
.btn.success-soft:hover { background: #d1fae5; }
@media (prefers-color-scheme: dark) {
  .btn.danger-soft { color: #fca5a5; }
  .btn.danger-soft:hover { background: #3a1c1f; }
  .btn.success-soft { color: #6ee7b7; }
  .btn.success-soft:hover { background: #14352a; }
}
.btn.block { width: 100%; }
.btn.sm { padding: 8px 14px; font-size: .82rem; border-radius: var(--r-xs); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none !important; }

/* ===== Biểu mẫu ===== */
.field { margin-bottom: 15px; }
.field label {
  display: block; margin-bottom: 7px;
  font-size: .82rem; font-weight: 700; color: var(--text-2);
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--line-strong); }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .13);
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .75; }
.field textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.field select {
  appearance: none; cursor: pointer;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7a90' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
}
.field .hint { margin-top: 5px; font-size: .77rem; color: var(--muted); }

/* ===== Dải chọn con ===== */
.student-bar {
  display: flex; gap: 9px;
  overflow-x: auto; scrollbar-width: none;
  padding: 2px 2px 14px;
}
.student-bar::-webkit-scrollbar { display: none; }
.student-chip {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 5px 15px 5px 5px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-xs);
  font-size: .85rem; font-weight: 650; white-space: nowrap;
  transition: all .18s var(--ease);
}
.student-chip:hover { border-color: var(--primary-300); transform: translateY(-1px); }
.student-chip.active {
  background: var(--primary-tint);
  border-color: var(--primary);
  color: var(--primary-600);
  box-shadow: 0 6px 16px -6px rgba(79, 70, 229, .4);
}
@media (prefers-color-scheme: dark) { .student-chip.active { color: var(--primary-300); } }

/* ===== Tab phân đoạn ===== */
.seg {
  display: flex; gap: 4px;
  padding: 5px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  margin-bottom: 15px;
  overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1; min-width: fit-content;
  padding: 9px 12px;
  border-radius: var(--r-xs);
  font-size: .85rem; font-weight: 700; color: var(--muted);
  white-space: nowrap;
  transition: all .18s var(--ease);
}
.seg button:hover { color: var(--text-2); }
.seg button.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ===== Ô thống kê ===== */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 9px;
  margin-bottom: 15px;
}
.stat-box {
  padding: 15px 10px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  transition: transform .2s var(--ease), box-shadow .2s;
}
.stat-box:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-box .stat-num {
  font-size: 1.6rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.15;
}
.stat-box .stat-label {
  margin-top: 3px;
  font-size: .72rem; font-weight: 650; color: var(--muted);
}

/* ===== Bảng ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
}
table.simple { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.simple th, table.simple td { padding: 11px 13px; text-align: left; }
table.simple th {
  background: var(--bg-2);
  font-size: .72rem; font-weight: 750; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  white-space: nowrap;
}
table.simple td { border-top: 1px solid var(--line); }
table.simple tbody tr:hover td { background: var(--surface-2); }

/* ===== Dòng thời gian ===== */
.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: '';
  position: absolute; left: 8px; top: 8px; bottom: 8px;
  width: 2px;
  background: linear-gradient(var(--primary-300), var(--line));
  border-radius: 2px;
}
.timeline .tl-item { position: relative; padding-bottom: 18px; }
.timeline .tl-item:last-child { padding-bottom: 0; }
.timeline .tl-item::before {
  content: '';
  position: absolute; left: -24px; top: 6px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--primary);
  border: 2.5px solid var(--surface);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .16);
}
.timeline .tl-time { font-size: .76rem; font-weight: 700; color: var(--muted); }

/* ===== Trạng thái trống ===== */
.empty-state {
  padding: 52px 22px;
  text-align: center;
  color: var(--muted);
}
.empty-state .es-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 84px; height: 84px; margin-bottom: 14px;
  font-size: 40px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 28px;
}
.empty-state p { font-size: .92rem; max-width: 320px; margin: 0 auto; line-height: 1.6; }

/* ===== Thông báo nổi (toast) ===== */
#toast-zone {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--nav-h) + 18px);
  z-index: 90;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  pointer-events: none;
}
.toast {
  max-width: 90vw;
  padding: 12px 20px;
  border-radius: var(--r-full);
  background: rgba(15, 23, 42, .92);
  backdrop-filter: blur(14px);
  color: #fff;
  font-size: .88rem; font-weight: 650;
  box-shadow: var(--shadow-lg);
  animation: toast-in .32s var(--ease);
}
.toast.success { background: linear-gradient(135deg, #059669, #10b981); }
.toast.error { background: linear-gradient(135deg, #dc2626, #ef4444); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.94); } to { opacity: 1; transform: none; } }

/* ===== Hộp thoại ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(10, 14, 26, .55);
  backdrop-filter: blur(5px);
  animation: fade-in .2s var(--ease);
}
.modal {
  width: 100%; max-width: 560px;
  max-height: 88dvh; overflow-y: auto;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  animation: sheet-up .3s var(--ease);
}
.modal::before {
  content: '';
  display: block; width: 42px; height: 4px; margin: 4px auto 14px;
  background: var(--line-strong); border-radius: 99px;
}
.modal .modal-title {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
  font-size: 1.08rem; font-weight: 750; letter-spacing: -.02em;
}
.modal .modal-title .close-x {
  margin-left: auto;
  /* Vùng chạm tối thiểu 44px theo hướng dẫn của Apple/Google */
  width: 44px; height: 44px; margin-right: -8px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-xs);
  color: var(--muted);
  transition: background .16s, color .16s;
}
.modal .modal-title .close-x:hover { background: var(--bg-2); color: var(--text); }
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .modal { border-radius: var(--r-xl); }
  .modal::before { display: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { opacity: .3; transform: translateY(46px); } to { opacity: 1; transform: none; } }

/* ===== Nhắn tin ===== */
.chat-list-row {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 6px;
  border-bottom: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .16s;
}
.chat-list-row:last-child { border-bottom: none; }
.chat-list-row:hover { background: var(--bg-2); }

/* Phòng chat chiếm trọn màn hình: ẩn thanh điều hướng và banner thông báo
   để ô nhập tin luôn nằm sát đáy (giống ứng dụng nhắn tin quen thuộc). */
body:has(.chat-screen) .bottom-nav,
body:has(.chat-screen) .push-banner { display: none; }
body:has(.chat-screen) #view { padding-bottom: 0; }
body:has(.chat-screen) #toast-zone { bottom: 96px; }

.chat-screen {
  display: flex; flex-direction: column;
  height: calc(100dvh - 4px);
  max-width: 820px; margin: 0 auto;
}
/* Trình duyệt cũ không có :has() — chừa chỗ cho thanh điều hướng */
@supports not selector(:has(*)) {
  .chat-screen { height: calc(100dvh - var(--nav-h) - 10px); }
}
.chat-screen .page-head { margin-bottom: 6px; }
.chat-msgs {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
  padding: 12px 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;  /* cuộn có quán tính trên iOS */
  overscroll-behavior: contain;
}
.bubble-row {
  display: flex; align-items: flex-end; gap: 8px;
  margin-bottom: 8px;
  animation: bubble-in .26s var(--ease);
}
.bubble-row.mine { flex-direction: row-reverse; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.bubble {
  max-width: 76%;
  padding: 10px 15px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  font-size: .92rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.bubble-row:not(.mine) .bubble { border-bottom-left-radius: 7px; }
.bubble-row.mine .bubble {
  background: linear-gradient(135deg, var(--primary), #7c5cf5);
  color: #fff; border: none;
  border-bottom-right-radius: 7px;
  box-shadow: var(--shadow-glow);
}
.bubble .bubble-name {
  display: block; margin-bottom: 3px;
  font-size: .74rem; font-weight: 750; color: var(--primary);
}
.bubble-row.mine .bubble .bubble-name { display: none; }
.bubble .bubble-time { display: block; margin-top: 4px; font-size: .68rem; opacity: .62; }

.chat-input-bar {
  position: sticky; bottom: 0;
  display: flex; align-items: flex-end; gap: 9px;
  padding: 12px 4px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-top: 1px solid var(--line);
  margin: 0 -4px;
}
.chat-input-bar textarea {
  flex: 1;
  max-height: 110px; resize: none; outline: none;
  padding: 11px 17px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-xl);
  transition: border-color .16s, box-shadow .16s;
}
.chat-input-bar textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, .13); }
.chat-input-bar .send-btn {
  width: 46px; height: 46px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7c5cf5);
  color: #fff;
  box-shadow: var(--shadow-glow);
  transition: transform .16s var(--ease);
}
.chat-input-bar .send-btn:hover { transform: scale(1.07); }
.chat-input-bar .send-btn:active { transform: scale(.92); }

/* ===== Album ảnh ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
}
.photo {
  position: relative;
  aspect-ratio: 4 / 3;
  display: flex; align-items: center; justify-content: center;
  font-size: 46px;
  border-radius: var(--r-md);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .24s var(--ease), box-shadow .24s;
}
.photo:hover { transform: translateY(-4px) scale(1.02); box-shadow: var(--shadow-md); }
.photo .photo-cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 26px 11px 9px;
  font-size: .74rem; font-weight: 650; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .62));
}

/* ===== Lịch điểm danh ===== */
.att-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.att-cal .cal-head {
  padding: 5px 0; text-align: center;
  font-size: .7rem; font-weight: 750; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.att-cal .cal-cell {
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: .82rem; font-weight: 650;
  transition: transform .16s var(--ease), border-color .16s;
}
.att-cal .cal-cell:hover { transform: scale(1.07); border-color: var(--primary-300); }
.att-cal .cal-cell.dim { opacity: .3; background: transparent; border-color: transparent; }
.att-cal .cal-cell .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 4px; }

/* ===== Đăng nhập ===== */
.login-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 26px 18px;
  background: linear-gradient(150deg, #4f46e5 0%, #6d5ce7 34%, #8b5cf6 56%, #a855f7 100%);
  position: relative; overflow: hidden;
}
.login-wrap::before, .login-wrap::after {
  content: ''; position: absolute; border-radius: 50%; pointer-events: none;
}
.login-wrap::before {
  width: 420px; height: 420px; top: -160px; left: -130px;
  background: radial-gradient(circle, rgba(255, 255, 255, .22), transparent 66%);
}
.login-wrap::after {
  width: 520px; height: 520px; bottom: -230px; right: -180px;
  background: radial-gradient(circle, rgba(255, 255, 255, .17), transparent 66%);
}
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 410px;
  padding: 30px 26px 24px;
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(26px) saturate(180%);
  -webkit-backdrop-filter: blur(26px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: login-in .5s var(--ease);
}
@keyframes login-in { from { opacity: 0; transform: translateY(22px) scale(.97); } to { opacity: 1; transform: none; } }
@media (prefers-color-scheme: dark) {
  .login-card { background: rgba(21, 27, 44, .93); border-color: rgba(255, 255, 255, .1); }
}
.login-logo {
  width: 74px; height: 74px; margin: -62px auto 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border: 4px solid var(--surface);
  border-radius: 26px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { text-align: center; font-size: 1.42rem; letter-spacing: -.03em; }
.login-card .sub {
  text-align: center; margin-bottom: 24px; margin-top: 5px;
  font-size: .87rem; color: var(--muted); line-height: 1.5;
}
.demo-accounts { margin-top: 20px; padding-top: 17px; border-top: 1px dashed var(--line-strong); }
.demo-accounts p { margin-bottom: 11px; text-align: center; font-size: .78rem; color: var(--muted); font-weight: 600; }
.demo-accounts .demo-row { display: flex; gap: 9px; }
.demo-accounts .btn { flex-direction: column; gap: 2px; line-height: 1.35; padding: 10px 8px; }

/* ===== Banner mời bật thông báo ===== */
.push-banner {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px);
  transform: translateX(-50%);
  z-index: 60;
  display: flex; align-items: center; gap: 12px;
  width: min(430px, 92vw);
  padding: 13px 15px;
  background: var(--surface-glass);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: sheet-up .38s var(--ease);
}
.push-banner .pb-logo {
  width: 42px; height: 42px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: 14px;
}
.push-banner .pb-text { flex: 1; min-width: 0; }
.push-banner .pb-text b { display: block; font-size: .91rem; font-weight: 700; }
.push-banner .pb-text span { font-size: .78rem; color: var(--muted); }
.push-banner .pb-bell {
  width: 40px; height: 40px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary), #7c5cf5);
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.push-banner .pb-close {
  flex: none; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); border-radius: var(--r-xs);
}
.push-banner .pb-close:hover { background: var(--bg-2); }

/* ===== Đang tải ===== */
.loading {
  padding: 56px 0;
  text-align: center; color: var(--muted); font-size: .9rem;
}
.loading::after {
  content: '';
  display: block;
  width: 34px; height: 34px; margin: 14px auto 0;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Tiện ích ===== */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-14 { margin-top: 14px; }
.mb-8 { margin-bottom: 8px; }
.flex { display: flex; align-items: center; gap: 9px; }
.flex .spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 13px; }

/* ===== Màn hình lớn ===== */
@media (min-width: 700px) {
  body { font-size: 16px; }
  #view { padding-bottom: calc(var(--nav-h) + 40px); }
  .hero { border-radius: 0 0 40px 40px; padding: 22px 30px 80px; margin: 0 -16px 24px; }
  .tile-sheet { padding: 26px 22px 16px; }
  .tile-grid { grid-template-columns: repeat(7, 1fr); gap: 24px 8px; }
  .tile .tile-icon { width: 64px; height: 64px; border-radius: 21px; }
  .tile .tile-badge { margin-right: -40px; }
  .tile .tile-label { font-size: .8rem; max-width: 96px; }
  .card { padding: 22px; }
  .bottom-nav { gap: 8px; padding-bottom: 10px; }
  .bottom-nav .nav-item { min-width: 84px; flex-direction: row; gap: 7px; padding: 10px 16px; border-radius: var(--r-full); font-size: .82rem; }
  .bottom-nav .nav-item.active::before { display: none; }
  .bottom-nav .nav-badge { top: 4px; right: 6px; }
}

@media (min-width: 1024px) {
  #view { max-width: 1000px; }
  .tile-grid { gap: 26px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
