@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: #d1fae5;
  --primary-text: #065f46;
  
  --accent: #f59e0b;
  --accent-light: #fef3c7;
  
  --strawberry: #f43f5e;
  --tobacco: #b45309;
  --pear: #84cc16;
  --wheat: #eab308;
  --potato: #8b5cf6;
  --corn: #f97316;
  --other: #64748b;
  
  --bg: #f8fafc;
  --bg-gradient: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 50%, #f0f9ff 100%);
  --card-bg: rgba(255, 255, 255, 0.85);
  
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  
  --border: rgba(16, 185, 129, 0.15);
  --border-light: rgba(226, 232, 240, 0.8);
  
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  
  --shadow-sm: 0 2px 8px -1px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 25px -5px rgba(16, 185, 129, 0.1), 0 8px 16px -6px rgba(16, 185, 129, 0.05);
  --shadow-lg: 0 20px 40px -15px rgba(0, 0, 0, 0.08);
  
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Outfit', 'Noto Sans SC', -apple-system, sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  padding-bottom: 2rem;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem 0.8rem;
}

/* Header */
header {
  text-align: center;
  padding: 1.5rem 0.5rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #047857 0%, #10b981 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

header p {
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 400;
}

.api-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 0.6rem;
  transition: var(--transition);
}
.api-status-badge.online {
  background-color: #d1fae5;
  color: #065f46;
}
.api-status-badge.offline {
  background-color: #fee2e2;
  color: #991b1b;
}

/* Month Navigation */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.month-nav button {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.month-nav button:active {
  background: var(--primary-light);
  transform: scale(0.9);
}

.month-nav .current-month {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

/* Summary Grid */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}

.summary-card {
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.summary-card .label {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 0.2rem;
  font-weight: 500;
}

.summary-card .amount {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary-text);
  word-break: break-all;
}

.summary-card.weight-card .amount {
  color: var(--accent);
}

.summary-card.full-width {
  grid-column: 1 / -1;
}

/* Cards & Components */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.2rem;
  transition: var(--transition);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card-header h2 span.emoji {
  font-size: 1.2rem;
}

/* Form Styles */
.form-group {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.form-control, select, input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
  outline: none;
  font-family: inherit;
  transition: var(--transition);
}

.form-control:focus, select:focus, input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
  background: #ffffff;
}

/* Custom Segmented Control for Villages */
.village-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #f1f5f9;
  padding: 0.25rem;
  border-radius: var(--radius-md);
  gap: 0.2rem;
  margin-bottom: 0.5rem;
}

.village-tab {
  background: none;
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 0.2rem;
  border-radius: var(--radius-sm);
  color: var(--text-light);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.village-tab.active {
  background: #ffffff;
  color: var(--primary-text);
  box-shadow: var(--shadow-sm);
}

/* Custom Searchable Multi-Select for Names */
.names-selector-wrapper {
  position: relative;
  width: 100%;
}

.names-select-trigger {
  min-height: 42px;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.names-select-trigger::after {
  content: '▼';
  font-size: 0.7rem;
  color: var(--text-light);
  position: absolute;
  right: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  transition: var(--transition);
}

.names-select-trigger.open::after {
  transform: translateY(-50%) rotate(180deg);
}

.names-select-trigger .placeholder {
  color: var(--text-light);
  font-size: 0.9rem;
}

.selected-name-badge {
  background: var(--primary-light);
  color: var(--primary-text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.selected-name-badge .remove {
  cursor: pointer;
  font-weight: bold;
  font-size: 0.8rem;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.selected-name-badge .remove:hover {
  background: rgba(0,0,0,0.1);
}

.names-dropdown-panel {
  display: none;
  position: absolute;
  top: 105%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  padding: 0.6rem;
  max-height: 250px;
  flex-direction: column;
}

.names-dropdown-panel.show {
  display: flex;
}

.names-search-input {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 0.6rem;
}

.names-list-container {
  overflow-y: auto;
  flex: 1;
}

.names-options-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.name-option-badge {
  padding: 0.4rem;
  text-align: center;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
  color: var(--text-muted);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}

.name-option-badge:active {
  transform: scale(0.95);
}

.name-option-badge.selected {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  font-weight: 600;
}

.names-action-row {
  display: flex;
  justify-content: space-between;
  padding-top: 0.5rem;
  border-top: 1px solid #f1f5f9;
  margin-top: 0.5rem;
}

.names-action-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}

/* Crop Project Grid/Chips */
.project-chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.project-chip {
  padding: 0.5rem 0.2rem;
  text-align: center;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-muted);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.project-chip .icon {
  font-size: 1.2rem;
}

.project-chip:active {
  transform: scale(0.95);
}

.project-chip.selected[data-project="草莓"] { border-color: var(--strawberry); color: var(--strawberry); background: rgba(244, 63, 94, 0.05); }
.project-chip.selected[data-project="黄烟"] { border-color: var(--tobacco); color: var(--tobacco); background: rgba(180, 83, 9, 0.05); }
.project-chip.selected[data-project="梨子"] { border-color: var(--pear); color: var(--pear); background: rgba(132, 204, 22, 0.05); }
.project-chip.selected[data-project="麦子"] { border-color: var(--wheat); color: var(--wheat); background: rgba(234, 179, 8, 0.05); }
.project-chip.selected[data-project="地瓜"] { border-color: var(--potato); color: var(--potato); background: rgba(139, 92, 246, 0.05); }
.project-chip.selected[data-project="玉米"] { border-color: var(--corn); color: var(--corn); background: rgba(249, 115, 22, 0.05); }
.project-chip.selected[data-project="其他"] { border-color: var(--other); color: var(--other); background: rgba(100, 116, 139, 0.05); }

/* Buttons */
.btn-submit {
  width: 100%;
  padding: 0.8rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.btn-submit:active {
  transform: scale(0.98);
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.2);
}

.btn-secondary {
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: #ffffff;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: var(--transition);
}

.btn-secondary:active {
  background: #f1f5f9;
}

.btn-danger {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.15);
}

.btn-danger:active {
  background: #fee2e2;
}

/* Records List */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.filter-control {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  background: #ffffff;
  border: 1px solid var(--border-light);
  flex: 1;
}

.records-list-container {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.record-item {
  display: flex;
  align-items: center;
  padding: 0.8rem 0;
  border-bottom: 1px solid #f1f5f9;
  gap: 0.8rem;
  transition: var(--transition);
}

.record-item:last-child {
  border-bottom: none;
}

.record-item .project-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.record-item .info {
  flex: 1;
  min-width: 0;
}

.record-item .info .line-1 {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.1rem;
}

.record-item .info .name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.record-item .info .village-badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  background: #e2e8f0;
  color: var(--text-muted);
}

.record-item .info .meta {
  font-size: 0.75rem;
  color: var(--text-light);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.record-item .price-weight {
  color: var(--text-light);
}

.record-item .amount {
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary-text);
  flex-shrink: 0;
  text-align: right;
}

.record-item .delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: #ef4444;
  padding: 0.3rem 0.5rem;
  opacity: 0.6;
  transition: var(--transition);
}

.record-item .delete-btn:active {
  opacity: 1;
  transform: scale(1.1);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
  font-size: 0.85rem;
}

.empty-state .emoji {
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
  display: block;
}

/* Charts Wrapper */
.chart-wrap {
  position: relative;
  height: 220px;
  width: 100%;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.category-stats-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.category-stat-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.85rem;
}

.category-stat-item:last-child {
  border-bottom: none;
}

.category-stat-item .dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
}

.category-stat-item .name {
  flex: 1;
  font-weight: 500;
}

.category-stat-item .values {
  text-align: right;
  display: flex;
  flex-direction: column;
}

.category-stat-item .money {
  font-weight: 700;
  color: var(--text);
}

.category-stat-item .weight {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Budget Card specifics */
.budget-bar {
  background: #f1f5f9;
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.budget-bar .fill {
  height: 100%;
  background: var(--primary);
  border-radius: 10px;
  width: 0%;
  transition: width 0.5s ease-out;
}

.budget-bar .fill.over {
  background: #ef4444;
}

.budget-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-light);
}

.budget-status-text {
  font-weight: 600;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 90%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal {
  transform: translateY(0);
}

.modal h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.modal p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.2rem;
  line-height: 1.5;
}

.modal-btns {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.modal-btns button {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

/* Footer styling */
footer {
  text-align: center;
  color: var(--text-light);
  font-size: 0.75rem;
  margin-top: 2rem;
  padding: 1rem 0;
  border-top: 1px solid rgba(16, 185, 129, 0.08);
}

.config-btn-wrap {
  display: flex;
  justify-content: center;
  margin-top: 0.8rem;
}

.btn-config {
  font-size: 0.75rem;
  background: transparent;
  border: 1px dashed var(--primary);
  color: var(--primary);
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

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

/* Custom styles for mobile portrait layout */
@media (max-width: 350px) {
  .project-chips {
    grid-template-columns: repeat(3, 1fr);
  }
  .names-options-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
