:root {
  --primary: #0e7c86;
  --primary-dark: #0a5e66;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2a30;
  --muted: #6b7a82;
  --border: #e2e8ec;
  --danger: #d8453b;
  --ok: #2e9e5b;
  --shadow: 0 2px 10px rgba(20, 40, 50, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
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.5;
  padding-bottom: 64px;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 22px; }
.title { font-size: 19px; font-weight: 700; letter-spacing: 1px; }
.sub { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.app-header { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.app-header .brand { flex: 1; min-width: 0; }
.header-login-btn { font-size: 12px; border: 1px solid rgba(255,255,255,0.4); background: transparent; color: #fff; border-radius: 14px; padding: 4px 12px; cursor: pointer; white-space: nowrap; }
.header-login-btn:active { background: rgba(255,255,255,0.15); }

/* Views */
.app-main { padding: 14px; max-width: 720px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to {opacity:1; transform:none;} }

/* Fields */
.field { margin-bottom: 16px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.req { color: var(--danger); }
input[type="text"], input[type="search"], textarea, select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; background: #fff; color: var(--text);
  font-family: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,124,134,.12); }
textarea { resize: vertical; }

.plate-row { display: flex; gap: 8px; }
.plate-row select { width: 84px; flex: none; }
.plate-row input { flex: 1 1 110px; max-width: 150px; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.btn-recognize { flex: none; border: 1px solid var(--primary); color: var(--primary); background: #fff; border-radius: 10px; padding: 0 12px; font-size: 13px; font-weight: 600; cursor: pointer; height: 42px; }
.ocr-msg { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 16px; }
.ocr-msg.ok { color: var(--ok); }
.ocr-msg.err { color: var(--danger); }

.items-box { display: flex; flex-wrap: wrap; gap: 8px; }
.item-chip {
  border: 1px solid var(--border); border-radius: 20px; padding: 8px 14px;
  background: #fff; cursor: pointer; user-select: none; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 92px; text-align: center;
}
.item-chip.checked { background: var(--primary); color: #fff; border-color: var(--primary); }

.photo-actions { display: flex; align-items: center; gap: 12px; }
.btn-camera {
  display: inline-flex; align-items: center; gap: 6px; flex: none; white-space: nowrap;
  background: var(--primary); color: #fff; padding: 10px 16px;
  border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.photo-hint { color: var(--muted); font-size: 13px; }
.photo-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.photo-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.photo-thumb { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .del {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; border: none;
  font-size: 13px; line-height: 20px; text-align: center; cursor: pointer;
}

.btn-primary {
  width: 100%; padding: 13px; background: var(--primary); color: #fff;
  border: none; border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn-primary:active { background: var(--primary-dark); }
.form-msg { text-align: center; min-height: 18px; margin: 10px 0 0; font-size: 13px; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--danger); }

/* Records */
.records-toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.records-toolbar input { flex: 1; min-width: 140px; }
.export-range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.range-label { font-size: 13px; color: var(--muted); }
.export-range select { flex: 0 0 auto; padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; background: #fff; }
.export-custom { display: flex; align-items: center; gap: 6px; flex: 1 1 100%; }
.export-custom input[type=date] { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; }
.range-sep { color: var(--muted); font-size: 13px; }
.export-btns { display: flex; gap: 8px; }
.btn-outline {
  border: 1px solid var(--primary); color: var(--primary); background: #fff;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.summary-bar { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.records-list { display: flex; flex-direction: column; gap: 10px; }
.rec-card {
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px; display: flex; gap: 12px;
}
.rec-thumb { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; flex: none; background: #eef2f4; cursor: zoom-in; }
.rec-thumb-empty { background: #eef2f4; }
.rec-photos { display: flex; gap: 6px; overflow-x: auto; flex: none; max-width: 140px; padding-bottom: 2px; }
.rec-photos .rec-thumb { width: 64px; height: 64px; }
.rec-body { flex: 1; min-width: 0; }
.rec-body { display: flex; align-items: stretch; gap: 8px; }
.rec-body-main { flex: 1; min-width: 0; }
.rec-actions { display: flex; flex-direction: column; justify-content: center; gap: 6px; flex-shrink: 0; padding-left: 8px; border-left: 1px solid var(--border); }
.rec-plate { font-weight: 700; font-size: 16px; letter-spacing: 1px; }
.rec-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.rec-items { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rec-items .tag-worker { background: #e8f5e9; color: #2e7d32; font-weight: 600; }
.tag { background: #e6f4f5; color: var(--primary-dark); border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.rec-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.rec-edit, .rec-del { border: none; border-radius: 8px; font-size: 12px; cursor: pointer; padding: 6px 12px; text-align: center; font-weight: 500; width: 100%; min-width: 48px; }
.rec-edit { background: #e8f5e9; color: #2e7d32; }
.rec-edit:active { background: #c8e6c9; }
.rec-del { background: #ffebee; color: #c62828; }
.rec-del:active { background: #ffcdd2; }
.empty-tip { text-align: center; color: var(--muted); margin-top: 40px; font-size: 14px; }

/* Settings */
.card { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.manage-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.manage-item {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef2f4; border-radius: 8px; padding: 6px 8px 6px 12px; font-size: 14px;
}
.manage-item button { border: none; background: transparent; color: var(--danger); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 4px; }
.manage-item .name { font-size: 14px; }
.manage-item .edit { color: var(--primary); font-size: 14px; }
.manage-item .edit-save { color: var(--ok); font-size: 14px; }
.manage-item .edit-cancel { color: var(--muted); font-size: 15px; }
.manage-item .toggle { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.manage-item .toggle:hover { background: rgba(0, 0, 0, 0.05); }
.manage-item.is-disabled { opacity: 0.5; }
.manage-item.is-disabled .name { text-decoration: line-through; }
.manage-item input.edit-input { width: 96px; padding: 4px 6px; font-size: 13px; border-radius: 6px; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; }
.btn-mini { border: none; background: var(--primary); color: #fff; border-radius: 10px; padding: 10px 16px; font-weight: 600; cursor: pointer; }
.danger-card { border: 1px solid #f3c9c5; }
.danger-tip { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.btn-danger { width: 100%; border: none; background: var(--danger); color: #fff; border-radius: 10px; padding: 12px; font-weight: 600; cursor: pointer; }
.about { font-size: 12px; color: var(--muted); text-align: center; margin: 8px 0 0; }

/* 设置入口卡片（点击弹窗） */
.entry-card { cursor: pointer; padding: 4px 14px; transition: background .15s; }
.entry-card:active { background: #f0f3f5; }
.entry-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.entry-icon { font-size: 22px; width: 34px; text-align: center; flex: none; }
.entry-text { flex: 1; min-width: 0; }
.entry-title { font-size: 15px; font-weight: 600; }
.entry-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.entry-arrow { color: var(--muted); font-size: 24px; line-height: 1; flex: none; }
.entry-badge { color: var(--muted); font-size: 13px; line-height: 1; flex: none; }

/* 弹窗（移动端底部抽屉 / 桌面居中） */
.modal-mask {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(15, 25, 30, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-mask[hidden] { display: none; }
.modal-mask#modal-confirm-clear { z-index: 301; }
.modal {
  background: #fff; width: 100%; max-width: 520px;
  border-radius: 16px 16px 0 0; max-height: 82vh;
  display: flex; flex-direction: column;
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close {
  border: none; background: transparent; color: var(--muted);
  font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal-body { padding: 14px 16px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; padding: 12px 16px 18px; border-top: 1px solid var(--border); }
.modal-foot .btn-outline, .modal-foot .btn-primary, .modal-foot .btn-danger { flex: 1; width: auto; }
.confirm-text { font-size: 15px; line-height: 1.6; margin: 0; }

@media (min-width: 768px) {
  .modal-mask { align-items: center; }
  .modal { border-radius: 16px; max-height: 80vh; }
  @keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

/* 照片放大查看（灯箱） */
.photo-viewer {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 400;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, .92);
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.photo-viewer[hidden] { display: none; }
.pv-img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.pv-close {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 12px;
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .15); color: #fff; font-size: 28px; line-height: 1;
  cursor: pointer; z-index: 2; padding: 0;
}
.pv-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 64px; border: none; border-radius: 10px;
  background: rgba(255, 255, 255, .12); color: #fff; font-size: 36px; line-height: 1;
  cursor: pointer; z-index: 2; padding: 0;
}
.pv-prev { left: 8px; } .pv-next { right: 8px; }
.pv-bar {
  position: absolute; bottom: calc(env(safe-area-inset-bottom) + 16px); left: 0; right: 0;
  text-align: center; color: #fff; font-size: 13px; opacity: .85; z-index: 2;
}

/* Lock screen */
.lock-screen { position: fixed; inset: 0; background: rgba(244,246,248,.98); z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; }
.lock-screen.active { display: flex; }
.lock-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 340px; padding: 24px; text-align: center; }
.lock-logo { font-size: 40px; }
.lock-card h2 { margin: 6px 0 16px; font-size: 18px; }
.lock-tip { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.lock-panel { display: none; flex-direction: column; gap: 10px; }
.lock-panel.active { display: flex; }
.lock-link { color: var(--primary); font-size: 13px; cursor: pointer; margin-top: 4px; }

.modify-pwd-box { display: none; flex-direction: column; gap: 8px; margin-top: 10px; }

.records-manage { display: flex; flex-direction: column; gap: 8px; }
.rec-manage-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #eef2f4; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.rec-manage-row .info { min-width: 0; }
.rec-manage-row .info .p { font-weight: 700; }
.rec-manage-row .info .m { color: var(--muted); font-size: 12px; margin-top: 2px; }
.rec-manage-row .actions { display: flex; gap: 6px; flex-shrink: 0; }
.rec-manage-row .btn-edit { border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font-size: 12px; border-radius: 6px; padding: 4px 10px; }
.rec-manage-row .btn-edit:hover { border-color: var(--primary); color: var(--primary); }
.rec-manage-row .btn-del { border: 1px solid transparent; background: transparent; color: var(--danger); cursor: pointer; font-size: 12px; padding: 4px 6px; }
.rec-manage-row .btn-del:hover { text-decoration: underline; }

/* Tab bar */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: 56px;
  background: #fff; border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.tab {
  flex: 1; border: none; background: none; color: var(--muted);
  font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tab span { font-size: 20px; }
.tab.active { color: var(--primary); font-weight: 700; }

/* ============ 响应式适配 ============ */
/* 基础容错：避免极小屏横向溢出 */
html, body { overflow-x: hidden; }
body { min-height: 100vh; }

/* 平板及以上：放宽内容宽度，记录双列 */
@media (min-width: 600px) {
  .app-main { max-width: 760px; }
  .records-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .rec-card { height: 100%; }
}

/* 桌面：底部标签栏变为左侧固定导航，内容整体右移并居中 */
@media (min-width: 768px) {
  body { padding-bottom: 0; padding-left: 120px; }
  .app-header { padding-left: 24px; }
  .tab-bar {
    top: 0; bottom: auto; left: 0; right: auto;
    width: 120px; height: 100vh;
    flex-direction: column; justify-content: flex-start;
    border-top: none; border-right: 1px solid var(--border);
    padding-top: 86px; gap: 8px;
  }
  .tab {
    flex: none; padding: 14px 0; border-radius: 12px;
    font-size: 13px;
  }
  .tab.active { background: rgba(14, 124, 134, 0.08); }
}

/* 大屏：三列记录、字号与间距放大 */
@media (min-width: 1024px) {
  .app-main { max-width: 1080px; }
  .records-list { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1280px) {
  body { font-size: 16px; }
  .app-main { padding: 28px; }
}

/* 极小屏（≤359px）：紧凑布局，导出按钮占满一行 */
@media (max-width: 359px) {
  .plate-row select { width: 68px; }
  .export-btns { width: 100%; }
  .export-btns .btn-outline { flex: 1; text-align: center; }
  .rec-items .tag { font-size: 11px; }
}
