/* ===== base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 12px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }

/* ===== forms ===== */
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 10px 12px; margin-top: 4px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
input[type="checkbox"], input[type="radio"] { width: auto; margin-right: 6px; }
textarea { min-height: 90px; resize: vertical; }
.btn {
  display: inline-block; padding: 10px 18px; font-size: 15px; border: none; border-radius: 8px;
  cursor: pointer; background: #e5e7eb; color: var(--text); text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn-plain { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 14px; padding: 4px; }
.form-error { background: #fef2f2; color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.form-hint { background: #eff6ff; color: var(--primary-dark); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.form-row { display: flex; gap: 12px; } .form-row > label { flex: 1; }

/* ===== flash ===== */
.flash {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 1000;
  padding: 10px 20px; border-radius: 999px; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.15);
  background: #111827; color: #fff; max-width: 90vw; transition: opacity .4s;
}
.flash-ok { background: var(--ok); }
.flash-err { background: var(--danger); }
.flash-hide { opacity: 0; pointer-events: none; }

/* ===== cards / tables / tags ===== */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card-title { font-size: 14px; color: var(--muted); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; background: #fafafa; }
tr:last-child td { border-bottom: none; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: #e5e7eb; color: var(--text); }
.tag-ok { background: #d1fae5; color: #065f46; }
.tag-warn { background: #fef3c7; color: #92400e; }
.tag-danger { background: #fee2e2; color: #991b1b; }
.tag-info { background: #dbeafe; color: #1e40af; }
.muted { color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar form { display: flex; gap: 8px; align-items: center; }
.toolbar input, .toolbar select { width: auto; margin-top: 0; }

/* ===== login ===== */
.login-body { background: linear-gradient(160deg, #1d4ed8 0%, #3b82f6 55%, #93c5fd 100%); min-height: 100vh; }
.login-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-lang { align-self: flex-end; margin-bottom: 8px; }
.login-lang .btn-plain { color: #fff; }
.login-card { background: #fff; border-radius: 16px; padding: 32px 28px; width: 100%; max-width: 400px; box-shadow: 0 20px 40px rgba(0,0,0,.18); }
.login-logo { font-size: 44px; text-align: center; margin-bottom: 8px; }
.login-card h1 { text-align: center; font-size: 18px; margin-bottom: 20px; }

/* ===== student H5 shell ===== */
.s-body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.s-top {
  position: sticky; top: 0; z-index: 100; display: flex; justify-content: space-between; align-items: center;
  background: var(--primary); color: #fff; padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top));
}
.s-top-title { font-size: 17px; font-weight: 600; }
.bell { font-size: 20px; position: relative; color: #fff; }
.badge {
  position: absolute; top: -6px; right: -10px; background: var(--danger); color: #fff;
  font-size: 10px; border-radius: 999px; padding: 1px 5px; min-width: 16px; text-align: center;
}
.urgent-bar { display: block; background: var(--danger); color: #fff; padding: 8px 16px; font-size: 13px; }
.s-main { padding: 12px; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; display: flex;
  background: #fff; border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  max-width: 560px; margin: 0 auto;
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 0 5px; font-size: 11px; color: var(--muted); }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tab-icon { font-size: 20px; line-height: 1.2; }

/* ===== teacher shell ===== */
.t-body { max-width: 1100px; margin: 0 auto; }
.t-nav {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: #fff; border-bottom: 1px solid var(--border); padding: 10px 16px;
  position: sticky; top: 0; z-index: 100;
}
.t-nav-brand { font-weight: 700; color: var(--primary); }
.t-nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.t-nav-links a { padding: 6px 12px; border-radius: 8px; color: var(--text); font-size: 14px; }
.t-nav-links a.active { background: #eff6ff; color: var(--primary); font-weight: 600; }
.t-nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.t-main { padding: 16px; }
.nav-user { font-size: 13px; color: var(--muted); }

/* ===== admin shell ===== */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex-shrink: 0; background: #111827; color: #d1d5db;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { font-size: 17px; font-weight: 700; color: #fff; padding: 18px 16px 10px; }
.sidebar-program { padding: 0 12px 10px; }
.sidebar-program select { background: #1f2937; color: #e5e7eb; border-color: #374151; font-size: 13px; }
.sidebar nav { flex: 1; }
.sidebar nav a { display: block; padding: 10px 16px; color: #d1d5db; font-size: 14px; }
.sidebar nav a.active { background: #1f2937; color: #fff; border-left: 3px solid var(--primary); padding-left: 13px; }
.sidebar nav a:hover { background: #1f2937; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid #1f2937; font-size: 13px; }
.sidebar-footer .btn-plain { color: #93c5fd; padding: 2px 0; }
.sidebar-footer .nav-user { color: #9ca3af; margin: 4px 0; }
.admin-main { flex: 1; padding: 20px 24px; min-width: 0; }

/* ===== check-in specifics ===== */
.checkin-result { text-align: center; padding: 40px 16px; }
.checkin-result .icon { font-size: 64px; }
.qr-big { text-align: center; }
.qr-big img { width: min(62vw, 380px); image-rendering: pixelated; }
.code-display { font-size: 44px; font-weight: 800; letter-spacing: 10px; text-align: center; font-variant-numeric: tabular-nums; }
.code-input { font-size: 26px; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
#scanner-view { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; min-height: 240px; }
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.live-cell { padding: 6px 8px; border-radius: 8px; font-size: 12px; background: #f9fafb; border: 1px solid var(--border); }
.live-cell.present { background: #d1fae5; border-color: #a7f3d0; }
.live-cell.late { background: #fef3c7; border-color: #fde68a; }
.live-cell.excused { background: #dbeafe; border-color: #bfdbfe; }
.live-cell.absent { background: #fee2e2; border-color: #fecaca; }

/* ===== meal ticket ===== */
.ticket { background: #fff; border-radius: 16px; padding: 24px; text-align: center; }
.ticket img { width: min(70vw, 300px); }
.severe-banner { background: var(--danger); color: #fff; padding: 12px 16px; border-radius: 8px; font-weight: 700; margin: 10px 0; }

/* ===== responsive ===== */
@media (max-width: 860px) {
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .sidebar nav a { padding: 8px 10px; font-size: 13px; }
  .sidebar nav a.active { border-left: none; padding-left: 10px; }
  .admin-main { padding: 12px; }
  .form-row { flex-direction: column; gap: 0; }
}
@media print {
  .tabbar, .s-top, .t-nav, .sidebar, .lang-switch { display: none !important; }
}
