:root {
  --bg: #e8eef4;
  --bg-deep: #d5e0ea;
  --ink: #1a2b3c;
  --muted: #5a6f82;
  --accent: #0b6e4f;
  --accent-hover: #095c42;
  --danger: #c62828;
  --danger-bg: #fdecea;
  --ok: #1b7a4a;
  --ok-bg: #e8f5ee;
  --panel: #ffffff;
  --line: #c9d6e2;
  --sidebar: #14324a;
  --sidebar-text: #d7e4ef;
  --font-display: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --sidebar-w: 220px;
  --space: clamp(0.75rem, 2.5vw, 1.75rem);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}

img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font: inherit;
  max-width: 100%;
}

/* 防止 iOS 聚焦时自动放大 */
input, select, textarea {
  font-size: 16px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0.7rem 1.15rem;
  min-height: 44px;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input, select {
  width: 100%;
  padding: 0.75rem 0.85rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input:focus, select:focus {
  outline: 2px solid rgba(11, 110, 79, 0.35);
  border-color: var(--accent);
}

label {
  display: block;
  margin: 0.85rem 0 0.35rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.req {
  color: var(--danger);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 查询首页 ---------- */
.page-query {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
}

.query-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 10%, rgba(11, 110, 79, 0.12), transparent 55%),
    radial-gradient(ellipse 70% 45% at 90% 80%, rgba(20, 50, 74, 0.14), transparent 50%),
    linear-gradient(160deg, #eef4f8 0%, #dfe9f1 45%, #e6f0eb 100%);
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding:
    calc(0.9rem + var(--safe-top))
    calc(var(--space) + var(--safe-right))
    0.9rem
    calc(var(--space) + var(--safe-left));
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(1rem, 3.5vw, 1.15rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--sidebar);
  white-space: nowrap;
}

.link-staff {
  color: var(--muted);
  font-size: clamp(0.82rem, 2.8vw, 0.92rem);
  white-space: nowrap;
  flex-shrink: 0;
}

.query-main {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  margin: clamp(2.5rem, 8vh, 5rem) auto 0;
  padding: 0 calc(var(--space) + var(--safe-left)) calc(3rem + var(--safe-bottom)) calc(var(--space) + var(--safe-right));
}

.query-title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.55rem, 5.5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.25;
}

.query-desc {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: clamp(0.9rem, 2.8vw, 1rem);
  line-height: 1.55;
}

.query-form {
  background: var(--panel);
  padding: clamp(1rem, 3vw, 1.5rem);
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(20, 50, 74, 0.06);
}

.query-row {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.35rem;
  align-items: stretch;
}

.query-row input {
  flex: 1;
  min-width: 0;
}

.query-row button {
  flex-shrink: 0;
  white-space: nowrap;
}

.result-box {
  margin-top: 1.25rem;
  padding: clamp(1rem, 3vw, 1.4rem);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  animation: fadeUp 0.25s ease;
}

.result-box.not-found {
  background: var(--danger-bg);
  border-color: #f5c2c0;
  color: var(--danger);
  font-size: clamp(1.05rem, 4vw, 1.25rem);
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.08em;
  padding: 1.35rem 1rem;
}

.result-box.found .row {
  display: grid;
  grid-template-columns: minmax(5.2rem, 6.5rem) 1fr;
  gap: 0.35rem 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid #eef2f6;
}

.result-box.found .row:last-child {
  border-bottom: none;
}

.result-box.found .k {
  color: var(--muted);
}

.result-box.found .v {
  font-weight: 600;
  word-break: break-word;
  overflow-wrap: anywhere;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 登录 ---------- */
.page-login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(145deg, #e8f0f5 0%, #d9e6de 55%, #e5edf4 100%);
  padding:
    calc(1.25rem + var(--safe-top))
    calc(1.25rem + var(--safe-right))
    calc(1.25rem + var(--safe-bottom))
    calc(1.25rem + var(--safe-left));
}

.login-wrap {
  width: 100%;
  max-width: 400px;
}

.back-home {
  display: inline-block;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 44px;
  line-height: 44px;
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: clamp(1.25rem, 4vw, 1.9rem);
  box-shadow: 0 12px 32px rgba(20, 50, 74, 0.08);
}

.login-panel h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.45rem);
}

.login-sub {
  margin: 0.35rem 0 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-panel button {
  width: 100%;
  margin-top: 1.25rem;
}

.form-error {
  margin: 0.85rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.form-msg {
  margin: 0.85rem 0 0;
  font-size: 0.92rem;
}

.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--danger); }

.pwd-rule {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

/* ---------- 工作台 ---------- */
.page-console {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  background: #eef2f6;
  position: relative;
}

.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  align-items: center;
  gap: 0.75rem;
  padding:
    calc(0.7rem + var(--safe-top))
    calc(0.9rem + var(--safe-right))
    0.7rem
    calc(0.9rem + var(--safe-left));
  background: var(--sidebar);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.mobile-topbar .mobile-title {
  flex: 1;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-menu {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  flex-shrink: 0;
}

.btn-menu:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-menu .menu-icon,
.btn-menu .menu-icon::before,
.btn-menu .menu-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  position: relative;
}

.btn-menu .menu-icon::before,
.btn-menu .menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.btn-menu .menu-icon::before { top: -6px; }
.btn-menu .menu-icon::after { top: 6px; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(15, 28, 40, 0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sidebar-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding:
    calc(1.25rem + var(--safe-top))
    0.85rem
    calc(1.25rem + var(--safe-bottom))
    calc(0.85rem + var(--safe-left));
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  z-index: 50;
}

.sidebar-brand {
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.35rem 0.65rem 1.25rem;
  letter-spacing: 0.03em;
  color: #fff;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-btn {
  text-align: left;
  background: transparent;
  color: var(--sidebar-text);
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  width: 100%;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-btn.active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: 600;
}

.sidebar-user {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 1rem;
  margin-top: 1rem;
}

.user-info {
  font-size: 0.88rem;
  padding: 0 0.5rem 0.75rem;
  line-height: 1.45;
  color: #b8c9d8;
  word-break: break-word;
}

.btn-logout {
  width: 100%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.18);
}

.console-main {
  flex: 1;
  min-width: 0;
  padding:
    clamp(1rem, 2.5vw, 1.75rem)
    calc(clamp(0.85rem, 2.5vw, 1.75rem) + var(--safe-right))
    calc(2rem + var(--safe-bottom))
    calc(clamp(0.85rem, 2.5vw, 1.75rem) + var(--safe-left));
  overflow: auto;
}

.panel {
  display: none;
  animation: fadeUp 0.2s ease;
  max-width: 1200px;
}

.panel.active {
  display: block;
}

.panel h1 {
  margin: 0 0 1.15rem;
  font-size: clamp(1.25rem, 3.5vw, 1.55rem);
}

.section-title {
  margin: 1.5rem 0 0.85rem;
  font-size: clamp(1rem, 2.8vw, 1.1rem);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 0.85rem;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.88rem;
}

.stat-value {
  margin-top: 0.35rem;
  font-size: clamp(1.55rem, 5vw, 2rem);
  font-weight: 700;
  color: var(--sidebar);
  letter-spacing: 0.02em;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 520px;
}

.data-table.compact {
  min-width: 420px;
}

.data-table th,
.data-table td {
  padding: 0.75rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid #eef2f6;
  vertical-align: middle;
}

.data-table th {
  background: #f5f8fb;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.data-table td {
  word-break: break-word;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table .bar-cell {
  min-width: 120px;
}

.bar {
  height: 8px;
  background: #e4ebf1;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.btn-danger {
  background: var(--danger);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  min-height: 36px;
}

.btn-danger:hover {
  background: #a61f1f;
}

.btn-ghost {
  background: #eef2f6;
  color: var(--ink);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  min-height: 36px;
}

.btn-ghost:hover {
  background: #e0e7ee;
}

.entry-form,
.user-form {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(1rem, 3vw, 1.5rem);
}

.entry-form button,
.user-form > button {
  margin-top: 1.1rem;
  width: 100%;
  max-width: 220px;
}

.import-panel {
  margin-top: 0.5rem;
  max-width: 640px;
}

.import-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(1rem, 3vw, 1.4rem);
}

.import-hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.import-actions .btn-ghost {
  min-height: 44px;
  padding: 0.65rem 1rem;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  min-height: 44px;
  padding: 0.65rem 1rem;
  border-radius: 6px;
  background: #eef2f6;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.92rem;
  -webkit-tap-highlight-color: transparent;
}

.file-btn:hover {
  background: #e0e7ee;
}

.import-file-name {
  margin: 0.75rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  word-break: break-all;
}

.import-result {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f7fafc;
  font-size: 0.92rem;
  line-height: 1.5;
}

.import-result.ok {
  background: var(--ok-bg);
  border-color: #b7e0c8;
}

.import-result.warn {
  background: #fff8e8;
  border-color: #f0d9a0;
}

.import-result.err {
  background: var(--danger-bg);
  border-color: #f5c2c0;
  color: var(--danger);
}

.import-summary.ok-text {
  color: var(--ok);
  font-weight: 600;
}

.import-errors {
  margin: 0.65rem 0 0;
  padding-left: 1.15rem;
  color: var(--danger);
}

.import-errors li {
  margin: 0.25rem 0;
}

.import-more {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem 0.85rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 0.9rem;
  max-width: 520px;
}

.toolbar input {
  flex: 1 1 180px;
  min-width: 0;
}

.toolbar button {
  flex: 0 0 auto;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
  margin-top: 0.9rem;
}

.pager button {
  background: #dfe7ef;
  color: var(--ink);
  padding: 0.5rem 0.9rem;
}

.pager button:hover {
  background: #d0dbe6;
}

#pageInfo {
  font-size: 0.9rem;
  color: var(--muted);
}

.daily-chart {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(0.85rem, 2.5vw, 1.2rem);
  display: flex;
  align-items: flex-end;
  gap: clamp(0.35rem, 1.5vw, 0.65rem);
  min-height: 180px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.day-col {
  flex: 1 1 0;
  min-width: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.day-bar-wrap {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: flex-end;
}

.day-bar {
  width: 100%;
  background: linear-gradient(180deg, #1a8f68, #0b6e4f);
  border-radius: 5px 5px 2px 2px;
  min-height: 3px;
  transition: height 0.35s ease;
}

.day-count {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--sidebar);
}

.day-label {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.role-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  background: #e8f0f7;
  color: var(--sidebar);
}

.role-tag.admin {
  background: #e8f5ee;
  color: var(--ok);
}

.status-on { color: var(--ok); }
.status-off { color: var(--danger); }

.ops {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* ========== 平板 ========== */
@media (min-width: 861px) {
  .sidebar-backdrop,
  .sidebar-backdrop.is-open {
    display: none !important;
  }
}

@media (max-width: 1024px) {
  .sidebar {
    width: 200px;
  }

  .data-table {
    font-size: 0.88rem;
  }
}

/* ========== 手机 / 窄屏 ========== */
@media (max-width: 860px) {
  .page-console {
    flex-direction: column;
  }

  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(280px, 86vw);
    height: 100vh;
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.18);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-brand {
    display: none;
  }

  body.nav-open {
    overflow: hidden;
  }

  .query-row {
    flex-direction: column;
  }

  .query-row button {
    width: 100%;
  }

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

  .entry-form button,
  .user-form > button {
    max-width: none;
  }

  .import-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .import-actions button,
  .import-actions .file-btn {
    width: 100%;
  }

  .result-box.found .row {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .result-box.found .k {
    font-size: 0.82rem;
  }

  /* 表格转卡片 */
  .table-wrap {
    border: none;
    background: transparent;
    overflow: visible;
  }

  .data-table,
  .data-table.compact {
    min-width: 0;
    border: none;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .data-table tr {
    display: block;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.35rem 0.85rem 0.7rem;
  }

  .data-table td {
    display: grid;
    grid-template-columns: 5.5rem 1fr;
    gap: 0.35rem 0.65rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid #eef2f6;
    text-align: left;
  }

  .data-table td:last-child {
    border-bottom: none;
  }

  .data-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
  }

  .data-table td.ops-cell {
    display: block;
  }

  .data-table td.ops-cell::before {
    display: block;
    margin-bottom: 0.45rem;
  }

  .data-table .bar-cell {
    min-width: 0;
  }

  .pager {
    justify-content: space-between;
  }

  .pager button {
    flex: 1 1 auto;
    max-width: 120px;
  }

  #pageInfo {
    width: 100%;
    order: -1;
    text-align: center;
  }
}

/* ========== 超小屏 ========== */
@media (max-width: 380px) {
  .topbar {
    flex-wrap: wrap;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .day-label {
    font-size: 0.65rem;
  }

  .data-table td {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}

/* ========== 大屏 ========== */
@media (min-width: 1400px) {
  .panel {
    max-width: 1280px;
  }

  .console-main {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* 横屏矮屏（手机横放） */
@media (max-height: 500px) and (orientation: landscape) {
  .query-main {
    margin-top: 1.25rem;
  }

  .page-login {
    align-items: flex-start;
    padding-top: calc(1rem + var(--safe-top));
  }

  .sidebar {
    height: 100dvh;
  }
}

/* 版权信息 */
.copyright {
  margin-top: 2rem;
  padding: 1rem 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* 打印 */
@media print {
  .sidebar,
  .mobile-topbar,
  .sidebar-backdrop,
  .link-staff,
  .btn-logout,
  .toolbar,
  .pager,
  .ops,
  .copyright {
    display: none !important;
  }

  .page-console {
    display: block;
  }

  .console-main {
    padding: 0;
  }

  .panel {
    display: block !important;
  }
}
