/* ==================== 全局重置 ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --header-grad: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: env(safe-area-inset-bottom);
}

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

/* ==================== 登录遮罩 ==================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--header-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
}

.login-box {
  background: white;
  border-radius: 16px;
  padding: 32px 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  font-size: 48px;
  margin-bottom: 12px;
}

.login-box h2 {
  font-size: 20px;
  color: var(--text);
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 20px;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.login-input:focus {
  border-color: var(--primary);
}

/* ==================== 应用容器 ==================== */
.app-hidden {
  display: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

/* ==================== 顶部导航 ==================== */
.app-header {
  background: var(--header-grad);
  color: white;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.header-left h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conn-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.conn-status.offline {
  background: #f87171;
  box-shadow: 0 0 6px rgba(248, 113, 113, 0.6);
}

.user-badge {
  background: rgba(255,255,255,0.2);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==================== 标签栏 ==================== */
.tab-bar {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 90;
}

.tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
  transition: color 0.2s;
  cursor: pointer;
}

.tab.active {
  color: var(--primary);
  font-weight: 600;
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  background: var(--primary);
  border-radius: 2px;
}

.tab-icon {
  font-size: 16px;
}

.tab-badge {
  background: var(--danger);
  color: white;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ==================== 主内容区 ==================== */
.main-content {
  padding: 12px;
  padding-bottom: 60px;
}

.tab-content {
  display: none;
  animation: fadeIn 0.2s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== 表单卡片 ==================== */
.form-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.form-group {
  margin-bottom: 14px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.required {
  color: var(--danger);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input::placeholder {
  color: var(--text-light);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-group.half {
  flex: 1;
}

/* 类型选择行 */
.type-row {
  display: flex;
  gap: 8px;
}

.type-row select {
  flex: 1;
}

.btn-small {
  flex-shrink: 0;
  padding: 8px 12px;
  background: white;
  border: 1.5px solid var(--primary);
  color: var(--primary);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.btn-small:active {
  background: var(--primary);
  color: white;
}

/* ==================== 按钮 ==================== */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:active {
  background: var(--primary-dark);
  transform: scale(0.98);
}

.btn-secondary {
  background: white;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:active {
  background: var(--bg);
}

.btn-block {
  width: 100%;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

/* 编辑模式提示 */
.editing-banner {
  background: var(--warning-light);
  color: var(--warning);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.editing-banner button {
  background: none;
  border: none;
  color: var(--warning);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

/* ==================== 统计栏 ==================== */
.summary-bar {
  background: white;
  border-radius: 12px;
  padding: 14px 8px;
  margin-bottom: 10px;
  display: flex;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.summary-item {
  flex: 1;
  text-align: center;
  border-right: 1px solid var(--border);
}

.summary-item:last-child {
  border-right: none;
}

.summary-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.summary-label {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ==================== 列表工具栏 ==================== */
.list-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--primary);
}

.btn-export {
  flex-shrink: 0;
  padding: 10px 14px;
  background: var(--success);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-export:active {
  background: #15803d;
}

/* ==================== 记录列表 ==================== */
.records-list {
  /* container */
}

.loading-tip, .empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  font-size: 14px;
}

/* 门店分组 */
.store-group {
  margin-bottom: 16px;
}

.store-header {
  background: var(--primary-light);
  border-radius: 10px 10px 0 0;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-left: 3px solid var(--primary);
}

.store-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 4px;
}

.store-total {
  font-size: 12px;
  color: var(--text-secondary);
  background: white;
  padding: 3px 10px;
  border-radius: 12px;
}

.store-total strong {
  color: var(--primary);
  font-size: 14px;
}

/* 单条记录卡片 */
.record-card {
  background: white;
  border: 1px solid var(--border);
  border-top: none;
  padding: 12px 14px;
}

.record-card:last-child {
  border-radius: 0 0 10px 10px;
  margin-bottom: 0;
}

.record-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.record-type {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}

.record-time {
  font-size: 12px;
  color: var(--text-light);
}

.record-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin-bottom: 10px;
}

.record-field {
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

.record-field .field-label {
  color: var(--text-light);
  font-size: 11px;
}

.record-field .field-value {
  color: var(--text);
  font-weight: 500;
}

.record-field.full {
  grid-column: 1 / -1;
}

.record-actions {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.btn-edit, .btn-delete {
  flex: 1;
  padding: 7px 0;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-edit {
  background: var(--warning-light);
  color: var(--warning);
}

.btn-edit:active {
  opacity: 0.7;
}

.btn-delete {
  background: var(--danger-light);
  color: var(--danger);
}

.btn-delete:active {
  opacity: 0.7;
}

/* ==================== 底部信息 ==================== */
.app-footer {
  text-align: center;
  padding: 12px;
  font-size: 11px;
  color: var(--text-light);
}

/* ==================== 弹窗 ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal-box {
  background: white;
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
}

.modal-box h3 {
  font-size: 17px;
  margin-bottom: 14px;
}

.modal-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
}

.modal-box input:focus {
  border-color: var(--primary);
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  max-width: 90%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: rgba(0,0,0,0.85);
}

/* ==================== 响应式 ==================== */
@media (min-width: 481px) {
  body {
    background: #e5e7eb;
  }
  #app {
    box-shadow: 0 0 40px rgba(0,0,0,0.1);
  }
}

/* 防止iOS输入框缩放 */
input, select, textarea {
  font-size: 16px;
}
