/* --- Custom Properties --- */
:root {
  --bg: #f5f0e8;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --primary: #4a7c59;
  --primary-dark: #3a6347;
  --border: #ddd5c0;
  --border-focus: #4a7c59;
  --text: #3a2e1a;
  --text-muted: #8a7a5a;
  --red: #c0392b;
  --chip-reactive-bg: #fef3cd;
  --chip-reactive-text: #8a5500;
  --chip-mixed-bg: #ede8de;
  --chip-mixed-text: #6a5a3a;
  --chip-disciplined-bg: #dceede;
  --chip-disciplined-text: #2a5c38;
  --nav-height: 64px;
}

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

/* --- Base --- */
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Main Content Area --- */
#app-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
}

/* --- Bottom Navigation --- */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  padding: 8px 4px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tab-icon { font-size: 20px; line-height: 1; }

.tab.active { color: var(--primary); font-weight: 700; }

/* --- View Header --- */
.view-header {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.view-header h1 { font-size: 20px; font-weight: 700; }

/* --- Form Layout --- */
#log-form { padding: 16px; }

.section-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.field-group { margin-bottom: 14px; }

.field-row { display: flex; gap: 12px; margin-bottom: 14px; }
.field-row .field-group { flex: 1; margin-bottom: 0; }

.label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- Inputs --- */
.input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

.input:focus { outline: none; border-color: var(--border-focus); }

.textarea { resize: vertical; min-height: 80px; }

/* --- Derived Fields --- */
.derived-row { display: flex; gap: 8px; margin-bottom: 14px; min-height: 28px; align-items: center; }

/* --- Pills (multi/single select toggles) --- */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.pill.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* --- Chips --- */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.chip-season       { background: #e8f5e9; color: #2e7d32; }
.chip-tempzone-cold    { background: #e3f2fd; color: #1565c0; }
.chip-tempzone-ideal   { background: #e8f5e9; color: #2e7d32; }
.chip-tempzone-hot     { background: #fff3e0; color: #e65100; }

.chip-decision-reactive    { background: var(--chip-reactive-bg);    color: var(--chip-reactive-text); }
.chip-decision-mixed       { background: var(--chip-mixed-bg);       color: var(--chip-mixed-text); }
.chip-decision-disciplined { background: var(--chip-disciplined-bg); color: var(--chip-disciplined-text); }

/* --- Buttons --- */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 8px;
  margin-bottom: 24px;
  min-height: 52px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-secondary {
  display: block;
  width: 100%;
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: var(--primary);
  background: transparent;
  border: 1.5px solid var(--primary);
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 22px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-danger {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--red);
  background: transparent;
  border: 1.5px solid var(--red);
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.15s;
}

.btn-danger-confirm { background: var(--red); color: #fff; }

/* --- Form Errors --- */
.form-errors {
  background: #fde8e8;
  border: 1px solid #f0a0a0;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: #a00;
  margin-bottom: 16px;
}

.hidden { display: none !important; }

/* --- Lure Rows --- */
.lure-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}

.lure-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.lure-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lure-fields .input { padding: 8px 10px; font-size: 15px; }

/* --- Trip History List --- */
.trip-list { padding: 8px 0; }

.trip-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  min-height: 64px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.trip-item:active { background: #ede8de; }

.trip-item-date { font-size: 15px; font-weight: 700; }
.trip-item-location { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

.trip-item-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.trip-stat { font-size: 14px; color: var(--text-muted); }

.trip-item-main { flex: 1; min-width: 0; }

/* --- Detail Overlay --- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.overlay-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  min-height: 60px;
  flex-shrink: 0;
}

.overlay-header h2 { flex: 1; font-size: 18px; font-weight: 700; }

.overlay-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.detail-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.detail-section:last-child { border-bottom: none; }

.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 5px 0;
  font-size: 15px;
  gap: 12px;
}

.detail-row .label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.detail-row-block { display: block; }
.detail-row-block p { margin-top: 4px; font-size: 15px; line-height: 1.5; }

.lure-detail { font-size: 15px; padding: 4px 0; }

/* --- Dashboard --- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}

.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-value { font-size: 28px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.stat-value-sm { font-size: 16px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.decision-counts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.chart-container { padding: 0 16px 24px; }
.chart-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* --- Export --- */
.export-body { padding: 16px; }

.export-instructions { font-size: 15px; color: var(--text-muted); line-height: 1.5; margin-bottom: 16px; }

.export-textarea {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px;
  min-height: 200px;
  margin-top: 12px;
}

/* --- Empty State --- */
.empty-state { text-align: center; padding: 60px 32px; color: var(--text-muted); }
.empty-state p { font-size: 16px; line-height: 1.6; }

/* --- Desktop centering --- */
@media (min-width: 520px) {
  body { background: #e0d8c8; align-items: center; }
  #app-main { max-width: 480px; width: 100%; }
  #bottom-nav { width: 480px; left: 50%; transform: translateX(-50%); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .overlay { max-width: 480px; left: 50%; transform: translateX(-50%); }
}
