:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text2: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body.theme-login {
  background-image: url("images/login-bg.jpg");
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

body.theme-app {
  background-image: url("images/app-bg.jpg");
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

button,
input,
textarea {
  font-family: inherit;
}

#app {
  max-width: 430px;
  min-height: 100vh;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.page {
  display: none;
  min-height: 100vh;
  padding: 16px;
  padding-bottom: calc(48px + var(--safe-bottom));
  animation: fadeIn 0.2s ease;
  background: transparent;
}

.page.active {
  display: block;
}

.page-home {
  position: relative;
}

.hidden {
  display: none !important;
}

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

.login-hero {
  text-align: center;
  padding: 48px 0 32px;
}

.logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35);
}

.login-hero h1 {
  font-size: 22px;
  font-weight: 600;
}

.subtitle,
.hint,
.field-hint,
.page-tip,
.empty,
.label,
.meta,
.code {
  color: var(--text2);
}

.subtitle {
  font-size: 14px;
  margin-top: 8px;
}

.hint {
  text-align: center;
  font-size: 12px;
  margin-top: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  margin-bottom: 12px;
}

.form-card label,
.scan-input-card {
  display: block;
  margin-bottom: 14px;
}

.form-card label span,
.scan-input-card span,
.label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 6px;
}

.form-card input,
.form-card textarea,
.scan-input-card input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  background: #fff;
  color: var(--text);
  box-sizing: border-box;
}

.form-card input {
  height: 48px;
  line-height: 24px;
}

.form-date-field {
  position: relative;
}

.form-date-field .form-date-display {
  pointer-events: none;
  background: #fff;
}

.form-date-field .form-date-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
}

.form-card textarea {
  resize: vertical;
  min-height: 72px;
}

.required {
  color: var(--danger) !important;
  display: inline !important;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

.btn-block {
  width: 100%;
}

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

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--border);
  margin-top: 8px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 14px;
  padding: 8px;
}

.top-bar,
.nav-bar,
.borrow-list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.top-actions {
  display: flex;
  gap: 4px;
}

.greeting {
  font-size: 15px;
  color: var(--text2);
}

.greeting strong {
  color: var(--text);
  font-size: 18px;
}

.nav-back {
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 15px;
  padding: 8px 0;
}

.nav-bar h2 {
  font-size: 18px;
}

.nav-placeholder {
  width: 36px;
}

.status-card {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text2);
}

.dot.online {
  background: var(--success);
}

.dot.offline {
  background: var(--danger);
}

.action-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.home-slogan {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2.1em;
  margin: 0;
  padding: 0;
  text-align: center;
  font-family: "STXinwei", "华文新魏", "STXingkai", serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text2);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.action-tile {
  border: 1px solid rgba(255, 255, 255, 0.75);
  text-align: left;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.1);
}

.action-tile.borrow {
  background: linear-gradient(145deg, #8eb5dc 0%, #b8d4f0 100%);
  color: #2f4a62;
}

.action-tile.return {
  background: linear-gradient(145deg, #8ec49a 0%, #b8dfc0 100%);
  color: #2f5238;
}

.tile-icon {
  font-size: 26px;
  opacity: 0.95;
}

.tile-title {
  display: block;
  margin-top: 10px;
  font-size: 20px;
  font-weight: 700;
}

.tile-desc {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  opacity: 0.85;
}

.checkbox-row {
  display: flex !important;
  align-items: flex-start;
  gap: 10px;
}

.checkbox-row input {
  width: auto;
  margin-top: 4px;
}

.field-hint,
.page-tip {
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 12px;
}

.picker-filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.picker-search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.picker-category-filter {
  position: relative;
}

.picker-category-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.picker-category-trigger.is-open {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.picker-category-label.is-placeholder {
  color: #94a3b8;
}

.picker-category-arrow {
  color: #64748b;
  font-size: 12px;
  line-height: 1;
}

.picker-category-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 20;
  list-style: none;
  margin: 0;
  padding: 0;
  background: #fff;
  border: 1px solid #93c5fd;
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.picker-category-menu li {
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.picker-category-menu li + li {
  border-top: 1px solid #f1f5f9;
}

.picker-category-menu li.is-active,
.picker-category-menu li:active {
  background: #f1f5f9;
}

.scan-frame {
  height: 180px;
  border: 2px dashed #93c5fd;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background: #e0f2fe;
  margin-bottom: 10px;
}

.scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-line {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  height: 2px;
  background: #22c55e;
  box-shadow: 0 0 10px #22c55e;
  display: none;
}

.scan-frame.scanning .scan-line {
  display: block;
  animation: scanMove 1.6s linear infinite;
}

@keyframes scanMove {
  0% { top: 20%; }
  100% { top: 80%; }
}

#scan-tip {
  color: var(--text2);
  font-size: 13px;
  margin-bottom: 10px;
}

.scan-input-card {
  margin-top: 12px;
}

.borrow-list-head {
  margin-bottom: 10px;
}

.borrow-list-head span {
  color: var(--text2);
  font-size: 13px;
}

.borrow-instrument-list,
.borrow-list,
.sync-list {
  list-style: none;
}

.borrow-instrument-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: #f8fafc;
}

.borrow-instrument-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.borrow-instrument-grid span {
  display: block;
  color: var(--text2);
  font-size: 12px;
  margin-bottom: 4px;
}

.borrow-instrument-grid strong {
  display: block;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  word-break: break-all;
}

.remove-instrument {
  margin-top: 10px;
  width: 100%;
  border: 1px solid #fecaca;
  color: var(--danger);
  background: #fff;
  border-radius: 8px;
  padding: 9px;
  font-size: 14px;
}

.empty {
  text-align: center;
  font-size: 13px;
  padding: 16px 0;
}

.instrument-card h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.badge {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
}

.badge.ok {
  background: #dcfce7;
  color: #166534;
}

.badge.warn {
  background: #fef3c7;
  color: #92400e;
}

.borrow-list li,
.sync-list li {
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.borrow-list h4 {
  font-size: 16px;
  margin-bottom: 6px;
}

.arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text2);
  font-size: 24px;
}

.photo-box {
  min-height: 180px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #f8fafc;
}

.photo-placeholder {
  border: none;
  background: transparent;
  color: var(--text2);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

.cam {
  font-size: 28px;
}

#photo-preview {
  width: 100%;
  display: block;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.loading span {
  background: #fff;
  padding: 14px 22px;
  border-radius: 10px;
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: 360px;
  width: calc(100% - 40px);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  text-align: center;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  z-index: 300;
}

.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  max-width: 430px;
  margin: 0 auto;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(100, 116, 139, 0.92);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(226, 232, 240, 0.9);
  pointer-events: none;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
  pointer-events: auto;
}

.site-footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}

body.theme-login .site-footer {
  color: rgba(255, 255, 255, 0.78);
  background: rgba(15, 23, 42, 0.42);
  border-top-color: rgba(255, 255, 255, 0.14);
}

body.theme-login .site-footer a:hover {
  color: #fff;
}

body {
  padding-bottom: calc(36px + var(--safe-bottom));
}
