/* ============================================
   钻孔编录工具 - 移动端优先样式
   主题色：大地绿 #2c6e49
   ============================================ */

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2c6e49;
  --primary-light: #4c956c;
  --primary-dark: #1b4332;
  --accent: #e76f51;
  --danger: #c0392b;
  --bg: #f0f2f0;
  --card-bg: #ffffff;
  --text: #212529;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --calc-bg: #e8f5e9;
  --highlight-bg: #fff3cd;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --font-size: 15px;
  --input-height: 44px;
}

html {
  font-size: var(--font-size);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 70px;   /* 底部 Tab 栏高度 */
  padding-top: 100px;     /* 顶部 Header 高度 */
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* === Header === */
#app-header {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 600px;
  background: var(--primary);
  color: #fff;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.header-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
}
.app-title { font-size: 1.1rem; font-weight: 600; white-space: nowrap; }
.header-actions { display: flex; gap: 6px; }
.project-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px 10px;
  background: rgba(0,0,0,0.08);
}
.project-label { font-size: 0.8rem; opacity: 0.9; white-space: nowrap; }
.project-select {
  flex: 1; height: 34px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.15); color: #fff; padding: 0 8px;
  font-size: 0.85rem; min-width: 0;
}
.project-select option { color: var(--text); background: #fff; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
  font-weight: 500; padding: 8px 14px; white-space: nowrap;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); opacity: 0.85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid currentColor; }
#app-header .btn-outline { color: rgba(255,255,255,0.9); border-color: rgba(255,255,255,0.4); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; width: 100%; }

/* === Toolbar === */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.toolbar-title { font-weight: 600; font-size: 0.95rem; }
.toolbar-nav { display: flex; align-items: center; gap: 6px; }
.badge {
  background: var(--primary); color: #fff; padding: 2px 10px;
  border-radius: 12px; font-size: 0.75rem; font-weight: 500;
}

/* === Tab Content === */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Forms === */
.data-form { padding: 12px 14px; }
.form-row { margin-bottom: 12px; }
.form-row-2col { display: flex; gap: 10px; }
.form-row-2col .form-group { flex: 1; min-width: 0; }
.form-group { display: flex; flex-direction: column; }
.form-group label {
  font-size: 0.78rem; font-weight: 600; color: var(--text-muted);
  margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.3px;
}
.form-group input,
.form-group select,
.form-group textarea {
  height: var(--input-height); border: 1.5px solid var(--border);
  border-radius: 8px; padding: 0 10px; font-size: 0.95rem;
  background: var(--card-bg); color: var(--text);
  -webkit-appearance: none; outline: none;
  transition: border-color 0.2s;
}
.form-group textarea { height: auto; padding: 10px; resize: vertical; min-height: 80px; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(44,110,73,0.1); }

/* 自动计算字段 */
.field-calc { background: var(--calc-bg) !important; color: var(--primary-dark) !important; font-weight: 600; }
.field-highlight { background: var(--highlight-bg) !important; color: #856404 !important; font-size: 1.1rem !important; }

/* === 岩心块子表单 === */
.fieldset-pieces {
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 14px; background: #fafbfa;
}
.fieldset-pieces legend {
  font-weight: 600; font-size: 0.85rem; color: var(--primary-dark); padding: 0 4px;
}
.fieldset-pieces .hint { font-weight: 400; font-size: 0.72rem; color: var(--text-muted); }
.piece-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  background: var(--card-bg); padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border);
}
.piece-row .piece-no { font-weight: 600; font-size: 0.8rem; color: var(--text-muted); min-width: 24px; }
.piece-row input {
  flex: 1; height: 36px; border: 1.5px solid var(--border); border-radius: 6px;
  padding: 0 8px; font-size: 0.9rem; text-align: center;
}
.piece-row input:focus { border-color: var(--primary); }
.piece-row .btn-remove-piece {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: #fee; color: var(--danger); font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.piece-summary {
  display: flex; justify-content: space-between; margin-top: 8px;
  padding: 6px 0; font-size: 0.82rem;
}

/* === Form Actions === */
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* === Bottom Tab Nav === */
#tab-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 600px;
  display: flex; background: var(--card-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  z-index: 100;
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 8px 4px 6px; border: none; background: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.7rem;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active { color: var(--primary); }
.tab-icon { font-size: 1.3rem; }
.tab-label { margin-top: 2px; font-weight: 500; }

/* === Toast === */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 20px; font-size: 0.85rem; font-weight: 500;
  color: #fff; z-index: 999; pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
}
.toast.show { opacity: 1; }
.toast.success { background: #2c6e49; }
.toast.error { background: #c0392b; }
.toast.warn { background: #e67e22; }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: #fff; border-radius: 12px; padding: 20px; width: 90%; max-width: 420px;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.modal-box h3 { margin-bottom: 14px; font-size: 1rem; }
.modal-box .form-group { margin-bottom: 10px; }
.modal-box .form-group label { font-size: 0.75rem; }
.modal-box .form-group input,
.modal-box .form-group select,
.modal-box .form-group textarea {
  height: 38px; font-size: 0.88rem; border-radius: 6px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* === 数据管理页 === */
.data-tabs { display: flex; background: var(--card-bg); border-bottom: 1px solid var(--border); }
.data-tab-btn {
  flex: 1; padding: 10px; border: none; background: none; cursor: pointer;
  font-weight: 500; font-size: 0.82rem; color: var(--text-muted);
  border-bottom: 2px solid transparent; transition: all 0.2s;
}
.data-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.data-list { display: none; padding: 8px 14px; }
.data-list.active { display: block; }

.data-card {
  background: var(--card-bg); border-radius: 8px; padding: 12px;
  margin-bottom: 8px; border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.data-card .card-header { display: flex; justify-content: space-between; align-items: center; }
.data-card .card-title { font-weight: 600; font-size: 0.9rem; }
.data-card .card-body { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.data-card .card-body span { margin-right: 12px; }
.data-card .card-actions { display: flex; gap: 6px; }
.data-card .card-actions button { font-size: 0.72rem; padding: 4px 8px; }

.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* === 位置输入拆分控件（野外相对位置，手机友好） === */

.pos-control-group {
  background: #fafbf8;
  border: 1.5px solid #c8d6c0;
  border-radius: 10px;
  padding: 10px 12px;
}

.pos-control-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.pos-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pos-field-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.2px;
  margin-bottom: 2px;
  white-space: nowrap;
}

.pos-field-round { flex: 0 0 auto; width: 80px; }
.pos-field-dist  { flex: 1 1 auto; min-width: 70px; }
.pos-field-layer { flex: 1; display: flex; flex-direction: row; align-items: flex-end; gap: 6px; }
.pos-field-layer .pos-field-label { margin-bottom: 0; line-height: var(--input-height); }
.pos-field-layer .pos-select { flex: 1; }

.pos-select {
  height: var(--input-height);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0 6px;
  font-size: 0.95rem;
  font-weight: 500;
  background: #fff;
  color: var(--text);
  -webkit-appearance: auto;
  outline: none;
  text-align: center;
  text-align-last: center;
}
.pos-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44,110,73,0.1);
}

/* 方向切换按钮 */
.pos-dir-btn {
  flex: 0 0 auto;
  height: var(--input-height);
  min-width: 44px;
  padding: 0 10px;
  border: 1.5px solid var(--primary-light);
  border-radius: 8px;
  background: var(--calc-bg);
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  white-space: nowrap;
}
.pos-dir-btn:active { transform: scale(0.95); }
.pos-dir-btn.dir-from-start {
  background: #e8f5e9;
  border-color: #4c956c;
  color: #1b4332;
}
.pos-dir-btn.dir-from-end {
  background: #fff3cd;
  border-color: #d4a574;
  color: #856404;
}
.pos-dir-arrow {
  font-size: 1rem;
  line-height: 1;
}

/* 距离输入 */
.pos-dist-input {
  height: var(--input-height);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0 8px;
  font-size: 0.95rem;
  font-weight: 500;
  background: #fffef5;
  color: var(--text);
  outline: none;
  text-align: center;
  width: 100%;
  -webkit-appearance: none;
}
.pos-dist-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44,110,73,0.1);
}

/* 预览文本 */
.pos-preview {
  display: block;
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
  min-height: 1.2em;
}
.pos-preview code {
  font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
  font-size: 0.8rem;
  color: var(--primary-dark);
  background: #e8f5e9;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}
.pos-preview.has-value code {
  background: #fff3cd;
  color: #856404;
}

/* === 模式切换按钮（样品：回次位置 / 分层末尾） === */
.pos-mode-row {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  width: fit-content;
}
.pos-mode-btn {
  padding: 5px 14px;
  border: none;
  background: #fff;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.pos-mode-btn + .pos-mode-btn {
  border-left: 1px solid var(--border);
}
.pos-mode-btn.active {
  background: var(--primary);
  color: #fff;
}

/* === 兼容旧版 text 位置输入（从数据管理页查看时可能用到） === */
.pos-input {
  font-family: "SF Mono", "Cascadia Code", "Consolas", monospace !important;
  letter-spacing: 0.5px;
  background: #fffef5 !important;
  border-color: #d4a574 !important;
}
.pos-input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(231,111,81,0.1) !important;
}
.pos-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: -6px;
  margin-bottom: 8px;
  line-height: 1.4;
}

/* 换算结果行（左边框强调这是自动计算的） */
.computed-row {
  border-left: 3px solid var(--primary-light);
  padding-left: 10px;
  margin: 8px 0 16px;
  background: #f9fbf9;
  border-radius: 0 8px 8px 0;
}

/* === Misc === */
input[readonly] { cursor: default; }
select.input-select { -webkit-appearance: auto; }

/* === 表单分区（野外记录 / 室内补录） === */
.form-section {
  padding: 14px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
}
.form-section-field {
  background: linear-gradient(135deg, #f0f7f0 0%, #e8f5e9 100%);
  border-color: #a3c9a3;
}
.form-section-office {
  background: #fafbfc;
  border-color: #d0d5dd;
  border-style: dashed;
}
.form-section-computed {
  background: #f5f7fa;
  border-color: #b0bec5;
}
.form-section-title {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary-dark);
  margin-bottom: 10px;
  user-select: none;
}
.form-section-office .form-section-title {
  color: var(--text-muted);
}
.form-section-title .hint {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* 野外主导输入框（更醒目） */
.field-input-primary {
  font-size: 1.1rem !important;
  font-weight: 600 !important;
  border-color: #4c956c !important;
  background: #fffef5 !important;
  height: 48px !important;
}

/* === 状态标签（补录/已补录） === */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}
.tag-complete {
  background: #d4edda;
  color: #155724;
}
.tag-pending {
  background: #fff3cd;
  color: #856404;
}

/* 待补录卡片左边框提示 */
.card-pending {
  border-left: 3px solid #e6a817 !important;
}

/* === 响应式 === */
@media (min-width: 600px) {
  body { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
