:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #162130;
  --muted: #637083;
  --border: #d9e1ea;
  --accent: #147a7e;
  --accent-2: #0f5f63;
  --brand-blue: #1e5eff;
  --green: #18824b;
  --red: #b73535;
  --amber: #a96b14;
  --shadow: 0 12px 28px rgba(18, 31, 48, .08);
  font-family: "Inter", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select { font: inherit; }
button {
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.secondary { background: #e8eef4; color: var(--text); }
button.ghost { background: transparent; color: var(--accent); padding: 6px 8px; }
button.danger { background: var(--red); }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
}
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }

.download {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(20,122,126,.12), transparent 36%),
    linear-gradient(315deg, rgba(24,130,75,.10), transparent 32%),
    var(--bg);
}
.download-shell {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 28px;
  align-items: center;
}
.download h1 { font-size: 38px; line-height: 1.15; margin: 0 0 14px; }
.download p { color: var(--muted); line-height: 1.8; margin: 0 0 20px; }
.app-mark {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background: var(--brand-blue);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 34px;
  font-weight: 800;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.download-visual {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 22px;
}
.phone-frame {
  height: 440px;
  border: 10px solid #202a36;
  border-radius: 28px;
  background: #f7fafc;
  overflow: hidden;
}
.phone-top { height: 54px; background: #17212f; color: #fff; display: flex; align-items: center; padding: 0 18px; font-weight: 700; }
.phone-list { padding: 14px; }
.phone-row { height: 52px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.phone-row span { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }
.side {
  background: #162130;
  color: #dce6ef;
  padding: 18px 12px;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 800; line-height: 1.3; padding: 6px 8px 18px; }
.brand-icon { width: 34px; height: 34px; border-radius: 8px; background: var(--brand-blue); display: grid; flex: 0 0 34px; place-items: center; color: #fff; }
.brand-title { min-width: 0; overflow-wrap: anywhere; }
.nav { display: grid; gap: 4px; }
.nav a {
  color: #c9d5df;
  text-decoration: none;
  border-radius: 6px;
  padding: 11px 12px;
  display: block;
}
.nav a.active, .nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.main { min-width: 0; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  min-width: 0;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
}
.topbar h2 { font-size: 18px; margin: 0; }
.content { min-width: 0; padding: 16px; overflow: auto; }
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.toolbar .wide { grid-column: span 2; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}
.panel-head { padding: 13px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.table-wrap { overflow: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; background: #f9fbfd; cursor: default; }
th.sortable { cursor: pointer; }
td { color: #263445; }
.empty { padding: 42px 18px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 14px; border-top: 1px solid var(--border); }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 4px; background: var(--surface-2); color: var(--muted); }
.badge.in { color: var(--green); background: #e8f5ee; }
.badge.out { color: var(--amber); background: #fff3df; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.login-box { width: min(390px, 100%); background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 24px; }
.login-box h1 { margin: 0 0 20px; font-size: 24px; }
.form-row { margin-bottom: 14px; }
.remember-row { display: flex; align-items: center; gap: 8px; color: var(--muted); margin: 2px 0 14px; }
.remember-row input { width: auto; }
.account-panel { max-width: 760px; }
.admin-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat.sync-time strong { font-size: 15px; line-height: 1.35; }
.sync-missing { color: var(--red); font-weight: 700; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.stat strong { display: block; font-size: 24px; margin-top: 8px; }
.inside-stat { border-color: #8fd0aa; background: #f0fbf4; }
.inside-stat span { color: var(--green); font-weight: 700; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.summary-grid .stat span { color: var(--muted); }
.summary-grid .stat strong small { color: var(--muted); font-size: .58em; font-weight: 600; margin-left: 4px; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #f2f7f8; }
.report-inside-row td { background: #eefaf2; }
.report-inside-row:hover td { background: #e2f5e9; }
.report-inside-row td:first-child { box-shadow: inset 4px 0 0 var(--green); }
.person-presence { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: #aeb9c5; }
.presence-dot.inside { background: var(--green); box-shadow: 0 0 0 3px #d7f1e1; }
.presence-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 4px; font-size: 12px; }
.presence-badge.inside { color: var(--green); background: #dff4e7; font-weight: 700; }
.presence-badge.outside { color: var(--muted); background: #eef1f4; }
.report-detail-row td { padding: 0 14px 12px; background: #f8fafc; white-space: normal; }
.record-cards { display: grid; }
.record-card { padding: 10px 0; border-bottom: 1px solid var(--border); }
.record-card:last-child { border-bottom: 0; }
.record-card-main, .record-card-sub { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.record-card-main strong { font-size: 13px; }
.record-card-sub { margin-top: 7px; color: var(--muted); font-size: 12px; }
.empty.compact { padding: 18px 12px; }
.presence-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 220px)) 1fr;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 14px;
}
.presence-summary > div { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 13px 15px; }
.presence-summary span { color: var(--muted); margin-right: 12px; }
.presence-summary strong { font-size: 26px; }
.presence-summary small { color: var(--muted); margin-left: 4px; }
.presence-summary time { justify-self: end; align-self: end; color: var(--muted); font-size: 12px; padding: 8px 0; }
.unit-list { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.unit-item { border-bottom: 1px solid var(--border); }
.unit-item:last-child { border-bottom: 0; }
.unit-toggle, .person-toggle {
  width: 100%;
  min-height: 54px;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  text-align: left;
  padding: 12px 15px;
}
.unit-toggle:hover, .unit-toggle[aria-expanded="true"] { background: #eef6f6; }
.unit-name { min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.unit-meta { color: var(--muted); white-space: nowrap; }
.unit-meta strong { color: var(--accent-2); font-size: 18px; }
.unit-detail { border-top: 1px solid var(--border); background: #f8fafc; }
.people-list { padding-left: 18px; }
.person-item { border-bottom: 1px solid var(--border); }
.person-item:last-child { border-bottom: 0; }
.person-toggle { min-height: 62px; padding-right: 16px; }
.person-toggle:hover, .person-toggle[aria-expanded="true"] { background: #f0f4f7; }
.person-toggle > span { display: grid; gap: 4px; min-width: 0; }
.person-toggle > span:last-child { text-align: right; justify-items: end; }
.person-toggle small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.person-toggle b { color: var(--accent-2); font-size: 13px; }
.person-records { padding: 0 16px 12px; }
.person-record-head { color: var(--muted); font-size: 12px; padding: 10px 0 4px; }
.loading-line { padding: 18px 15px; color: var(--muted); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.inline-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 14px; border-bottom: 1px solid var(--border); }
.inline-form .full { grid-column: 1 / -1; }
.toast {
  position: fixed;
  z-index: 40;
  display: none;
}
.toast {
  right: 18px;
  bottom: 18px;
  background: #162130;
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .download-shell { grid-template-columns: 1fr; }
  .download-visual { display: none; }
  .shell { display: block; }
  .side { position: sticky; top: 0; z-index: 10; padding: 10px; }
  .main { min-height: calc(100vh - 104px); }
  .brand { padding-bottom: 8px; }
  .nav { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .nav a { text-align: center; padding: 9px 6px; font-size: 13px; }
  .toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar .wide { grid-column: span 2; }
  .admin-grid, .split, .summary-grid { grid-template-columns: 1fr 1fr; }
  .inline-form { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .download h1 { font-size: 30px; }
  .content { padding: 10px; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar .wide { grid-column: auto; }
  .topbar { padding: 0 10px; }
  .topbar h2 { font-size: 16px; }
  .nav { overflow-x: auto; grid-auto-flow: column; grid-template-columns: none; }
  .nav a { white-space: nowrap; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .presence-summary { grid-template-columns: 1fr 1fr; }
  .presence-summary time { grid-column: 1 / -1; justify-self: start; }
  .unit-toggle { align-items: flex-start; }
  .unit-meta { white-space: normal; text-align: right; }
  .people-list { padding-left: 8px; }
}
