/* =============================================
   鸡蛋库存登记助手 — 移动端优先样式
   ============================================= */

/* --- CSS Variables --- */
:root {
  --color-primary: #4CAF50;
  --color-primary-dark: #388E3C;
  --color-danger: #e53935;
  --color-danger-dark: #c62828;
  --color-bg: #FAFAFA;
  --color-surface: #FFFFFF;
  --color-text: #212121;
  --color-text-secondary: #757575;
  --color-border: #E0E0E0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.18);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
  --safe-top: env(safe-area-inset-top, 16px);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "PingFang SC", "Noto Sans SC", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: var(--safe-bottom);
  overscroll-behavior: none;
}

/* --- App Header --- */
.app-header {
  background: var(--color-primary);
  color: #fff;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header a {
  color: #fff;
  text-decoration: none;
}

/* --- Tab Bar --- */
.tab-bar {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tab-bar--scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-bar--scroll::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 1 0 auto;
  min-width: 70px;
  padding: 12px 8px;
  border: none;
  background: var(--color-surface);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}

.tab-btn--active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: #f1f8f1;
}

.tab-btn:active {
  background: #e8f5e9;
}

/* --- Cross-tab qty hints --- */
.report-qty-hint,
.reserve-qty-hint {
  font-size: 11px;
  color: #999;
  margin-right: 6px;
  white-space: nowrap;
  min-width: 48px;
  text-align: right;
}

/* Linkage toggle */
.reserve-link-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #999;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.reserve-link-toggle input { cursor: pointer; }

/* --- Reserve Hint --- */
.reserve-hint {
  text-align: center;
  font-size: 13px;
  color: #999;
  padding: 16px 8px;
  line-height: 1.6;
}

/* --- Main Container --- */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px;
}

/* --- Auto-load bar --- */
.auto-load-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 14px;
  color: #2e7d32;
}

.auto-load-bar__text {
  flex: 1;
}

.auto-load-bar__dismiss {
  background: none;
  border: none;
  font-size: 20px;
  color: #2e7d32;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

/* --- Store & Date Row --- */
.meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.meta-bar__store {
  font-weight: 600;
  font-size: 16px;
  color: var(--color-text);
}

.meta-bar__date-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.meta-bar__date {
  font-size: 14px;
  color: var(--color-text-secondary);
  background: #f0f0f0;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* Transparent date input overlaid on the date text */
.meta-bar__date-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  /* Hide native input visuals, keep it clickable */
}
.meta-bar__date-input::-webkit-calendar-picker-indicator {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.meta-bar__reset-date {
  position: relative;
  z-index: 2;
  font-size: 16px;
  background: #fff;
  border: 1px solid #e65100;
  color: #e65100;
  border-radius: 6px;
  padding: 2px 6px;
  cursor: pointer;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.meta-bar__reset-date:active {
  background: #fff3e0;
}

/* --- Category Group (collapsible) --- */
.category-group {
  background: var(--color-surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.category-group__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--color-surface);
  border: none;
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--color-text);
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.2s;
}

.category-group__header::after {
  content: "▾";
  font-size: 14px;
  font-weight: 700;
  transition: transform 0.25s;
  color: var(--color-text-secondary);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.category-group--collapsed .category-group__header {
  background: #f9fafb;
  border-bottom: 2px solid #e8e8e8;
}

.category-group--collapsed .category-group__header::after {
  transform: rotate(-90deg);
  color: #bbb;
}

.category-group__body {
  border-top: 1px solid var(--color-border);
}

.category-group--collapsed .category-group__body {
  display: none;
}

/* Category total badge */
.category-total {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-primary);
  background: #e8f5e9;
  border-radius: 10px;
  padding: 2px 10px;
  margin-left: auto;
  min-width: 24px;
  text-align: center;
}

/* Meta bar total */
.meta-bar__total {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-primary-dark);
  background: #e8f5e9;
  padding: 3px 8px;
  border-radius: 6px;
  margin-right: 6px;
}

/* --- Spec Row --- */
.spec-row {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  min-height: 56px;
  border-bottom: 1px solid #f0f0f0;
}

.spec-row:last-child {
  border-bottom: none;
}

.spec-row:focus-within {
  background: rgba(76, 175, 80, 0.04);
}

.spec-label {
  flex: 1;
  font-size: 15px;
  color: var(--color-text);
  white-space: nowrap;
  margin-right: 8px;
}

/* --- Quantity Control (buttons + input) --- */
.quantity-control {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-qty {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 2px solid #e0e0e0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: background 0.1s, transform 0.1s;
  flex-shrink: 0;
}

/* Prevent iOS double-tap zoom on all interactive elements */
button, input, textarea, .qty-display, .tab-btn, .category-group__header, .history-card__btn {
  touch-action: manipulation;
}

.btn-qty:active,
.btn-qty.btn-pressed {
  transform: scale(0.92);
}

.btn-plus {
  background: #e8f5e9;
  border-color: #a5d6a7;
  color: #2e7d32;
}

.btn-plus:active,
.btn-plus.btn-pressed {
  background: #c8e6c9;
}

.btn-minus {
  background: #fce4ec;
  border-color: #ef9a9a;
  color: #c62828;
}

.btn-minus:active,
.btn-minus.btn-pressed {
  background: #ffcdd2;
}

.spec-row.is-empty .btn-minus {
  background: #f5f5f5;
  border-color: #e0e0e0;
  color: #bdbdbd;
}

.qty-display {
  width: 52px;
  height: 48px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  border: 2px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  padding: 0;
}

.qty-display:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.25);
}

.qty-display.is-zero {
  color: #ccc;
}

/* --- Main Action Buttons --- */
.main-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Save + Generate row */
.main-actions__row {
  display: flex;
  gap: 10px;
}

.main-actions__row .btn-save {
  flex: 0 0 auto;
  width: 120px;
}

.main-actions__row .btn-primary {
  flex: 1;
}

.btn-primary,
.btn-secondary,
.btn-save {
  display: block;
  height: 56px;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.btn-primary:active {
  background: var(--color-primary-dark);
  transform: scale(0.97);
}

.btn-save {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
}

.btn-save:active {
  background: #e8f5e9;
  transform: scale(0.97);
}

.btn-save:disabled,
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  text-decoration: none;
}

.btn-secondary:active {
  background: #f5f5f5;
  transform: scale(0.97);
}

/* --- Toast --- */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: #323232;
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

.toast--visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* =============================================
   HISTORY PAGE
   ============================================= */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  color: var(--color-primary);
  text-decoration: none;
  margin-bottom: 12px;
}

.history-date-group {
  margin-bottom: 16px;
}

.history-date-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-secondary);
  padding: 8px 0 4px;
}

/* --- History Card Wrapper (card + detail below) --- */
.history-card-wrapper {
  margin-bottom: 8px;
}

/* --- History Card --- */
.history-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  overflow: hidden;
  transition: opacity 0.2s, transform 0.2s;
}

.history-card__check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  align-self: stretch;
  min-height: 80px;
  flex-shrink: 0;
  background: #f9f9f9;
  border-right: 1px solid var(--color-border);
}

.batch-checkbox {
  width: 22px;
  height: 22px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.history-card__main {
  flex: 1;
  padding: 12px 16px;
  min-width: 0;
}

.history-card__preview {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: pre-line;
  line-height: 1.6;
  max-height: 60px;
  overflow: hidden;
  margin-bottom: 6px;
}

.history-card__meta {
  font-size: 12px;
  color: #aaa;
  margin-bottom: 8px;
}

.history-card__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* History card buttons */
.history-card__btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.history-card__btn:active {
  background: #f5f5f5;
}

.history-card__btn.btn-copy {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.history-card__btn.btn-copy:active,
.history-card__btn.btn-copy--active {
  background: #e8f5e9;
  color: var(--color-primary-dark);
  transition: background 0.15s;
}

.history-card__btn.btn-delete {
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.history-card__btn.btn-delete:active {
  background: #fce4ec;
}

.history-card__btn:disabled {
  opacity: 0.5;
}

/* --- History Card Detail (below the card, full width) --- */
.history-card__detail {
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}

.detail-text {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 13px;
  white-space: pre-line;
  line-height: 1.7;
  color: var(--color-text);
  background: #f9fafb;
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  max-height: 400px;
  overflow-y: auto;
}

/* --- Batch Toolbar --- */
.batch-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff3e0;
  border: 1px solid #ffcc80;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  position: sticky;
  top: 56px;
  z-index: 50;
}

.batch-toolbar__count {
  font-size: 14px;
  color: #e65100;
}

.batch-toolbar__count strong {
  font-weight: 700;
}

.btn-danger-sm {
  background: var(--color-danger);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-danger-sm:active {
  background: var(--color-danger-dark);
}

.btn-cancel-sm {
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-cancel-sm:active {
  background: #f5f5f5;
}

.batch-hint {
  text-align: center;
  font-size: 12px;
  color: #bbb;
  padding: 4px 0 8px;
}

/* =============================================
   CONFIRMATION MODAL
   ============================================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--color-surface);
  border-radius: 16px;
  width: 100%;
  max-width: 320px;
  padding: 24px 20px 20px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

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

.modal-card__icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.modal-card__title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--color-text);
}

.modal-card__body {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-card__actions {
  display: flex;
  gap: 10px;
}

.btn-cancel {
  flex: 1;
  height: 44px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-cancel:active {
  background: #f5f5f5;
}

.btn-danger {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-danger);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

/* =============================================
   ATTENDANCE PAGE
   ============================================= */

.att-form {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.att-form__date-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 600;
}

.att-form__date-text {
  color: var(--color-text);
}

.att-form__date-input {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 14px;
  color: var(--color-text-secondary);
  background: #f9f9f9;
  margin-left: auto;
}

/* Time slot */
.att-slot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  flex-wrap: wrap;
}

.att-slot:last-child { border-bottom: none; }

.att-slot__label {
  font-size: 12px;
  color: #999;
  width: 36px;
  flex-shrink: 0;
}

.att-slot__start, .att-slot__end {
  font-size: 15px;
  padding: 6px 4px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  width: 80px;
  text-align: center;
  touch-action: manipulation;
}

.att-slot__sep { font-size: 13px; color: #999; }

.att-slot__hours {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary);
  min-width: 36px;
  text-align: right;
}

.att-slot__remove {
  background: none;
  border: none;
  color: #ccc;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  -webkit-tap-highlight-color: transparent;
}
.att-slot__remove:active { color: var(--color-danger); }

/* Add slot / step toggle row */
.att-form__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 8px;
}

.att-add-btn {
  background: none;
  border: 1px dashed #ccc;
  color: var(--color-primary);
  font-size: 14px;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.att-add-btn:active { background: #e8f5e9; }

.att-step-label {
  font-size: 12px;
  color: #999;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.att-note {
  flex: 1;
  font-size: 15px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.att-leave-btn {
  background: none;
  border: 1px solid #ff9800;
  color: #ff9800;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.att-leave-btn:active { background: #fff3e0; }

.att-save-btn {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.att-save-btn:active { background: var(--color-primary-dark); }

/* Entry list */
.att-list {
  margin-bottom: 12px;
}

.att-list__header {
  font-size: 13px;
  font-weight: 600;
  color: #999;
  padding: 4px 0 8px;
}

.att-day {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 8px 14px;
  margin-bottom: 6px;
  box-shadow: var(--shadow);
}

.att-day__head {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 6px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.att-day__total {
  color: var(--color-primary);
}

.att-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
}

.att-entry__time { color: var(--color-text); font-weight: 500; }
.att-entry__hours { color: var(--color-primary); font-weight: 600; font-size: 13px; }
.att-entry__note { color: #999; font-size: 12px; margin-left: auto; }
.att-entry__del {
  background: none;
  border: none;
  color: #ccc;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
}
.att-entry__del:active { color: var(--color-danger); }

.att-empty {
  text-align: center;
  color: #bbb;
  padding: 24px;
  font-size: 14px;
}

/* Export section */
.att-export {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.att-export__row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.att-export__date {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  touch-action: manipulation;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--color-text-secondary);
  font-size: 15px;
}
