/* =============================================
   FarmPlan - メインスタイルシート
   ============================================= */

/* ===== CSS変数（カラーパレット） ===== */
:root {
  --soil-dark:  #3d2b1f;
  --soil:       #6b4226;
  --soil-light: #a0693a;
  --cream:      #f5f0e8;
  --parchment:  #ede4d0;
  --leaf-dark:  #3a5a2e;
  --leaf:       #5a8a45;
  --leaf-light: #8ab870;
  --sprout:     #b8d89a;
  --sun:        #e8a020;
  --warning:    #e67e22;
  --text-dark:  #2c1a0e;
  --text-mid:   #5a3e2b;
  --text-light: #8a6a50;
}

/* ===== リセット・ベース ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  background: var(--cream);
  color: var(--text-dark);
  min-height: 100vh;
}

/* ===== ヘッダー ===== */
header {
  background: #2d4a24;
  padding: 16px 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.logo {
  font-family: 'Shippori Mincho', serif;
  font-size: 22px;
  font-weight: 700;
  color: #d4ebc4;
  letter-spacing: 0.05em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo span {
  color: var(--sun);
}

nav {
  display: flex;
  gap: 8px;
  justify-content: center;
}

nav a {
  color: #b8d89a;
  text-decoration: none;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 20px;
  transition: background 0.2s;
}

nav a:hover,
nav a.active {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.nav-logout {
  color: #b8d89a;
  text-decoration: none;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 20px;
  transition: background 0.2s;
  white-space: nowrap;
  justify-self: end;
}

.nav-logout:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

/* ===== 認証ページ共通（register / login） ===== */
.auth-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 62px);
  padding: 32px 16px;
}

.auth-card {
  background: white;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--parchment);
  box-shadow: 0 4px 24px rgba(61, 43, 31, 0.1);
}

.auth-title {
  font-family: 'Shippori Mincho', serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--soil);
  margin-bottom: 8px;
  text-align: center;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-light);
  text-align: center;
  margin-bottom: 28px;
}

/* ===== フォーム ===== */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mid);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--parchment);
  border-radius: 8px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 14px;
  color: var(--text-dark);
  background: white;
  transition: border-color 0.2s;
  outline: none;
}

.form-input:focus {
  border-color: var(--leaf);
}

.form-input.is-error {
  border-color: var(--warning);
}

/* ===== ボタン ===== */
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--leaf);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 8px;
}

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

/* ===== エラー・成功メッセージ ===== */
.alert {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 20px;
}

.alert-error {
  background: #fff3e0;
  border: 1px solid var(--warning);
  color: #7a4000;
}

.alert-success {
  background: #f0f8ea;
  border: 1px solid var(--leaf-light);
  color: var(--leaf-dark);
}

.alert ul {
  padding-left: 16px;
}

.alert li {
  margin-bottom: 4px;
}

/* ===== メインコンテンツ ===== */
.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 16px;
}

.page-header {
  margin-bottom: 28px;
}

.page-title {
  font-family: 'Shippori Mincho', serif;
  font-size: 22px;
  color: var(--soil);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-light);
}

/* ===== 統計カード ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 32px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--parchment);
  box-shadow: 0 1px 4px rgba(61, 43, 31, 0.08);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.stat-card.growing::before   { background: var(--leaf); }
.stat-card.planned::before   { background: var(--sun); }
.stat-card.harvested::before { background: var(--soil-light); }

.stat-label {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 6px;
}

.stat-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-dark);
}

.stat-unit {
  font-size: 13px;
  color: var(--text-mid);
  margin-left: 4px;
}

/* ===== セクション ===== */
.section {
  margin-bottom: 32px;
}

.section-title {
  font-family: 'Shippori Mincho', serif;
  font-size: 17px;
  color: var(--soil);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--parchment);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 18px;
  background: var(--leaf);
  border-radius: 2px;
}

/* ===== タスク ===== */
.task-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.task-add-input {
  flex: 1;
  min-width: 200px;
}

.task-add-date {
  width: 160px;
}

.task-add-btn {
  white-space: nowrap;
}

.task-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  background: white;
  border: 1px solid var(--parchment);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.task-item.task-overdue {
  border-color: #f5c6c6;
  background: #fff8f8;
}

.task-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.task-title {
  font-weight: 600;
  color: var(--text-dark);
}

.task-due {
  font-size: 12px;
  color: var(--text-light);
}

.task-overdue .task-due {
  color: var(--warning);
  font-weight: 600;
}

.btn-task-complete {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--leaf);
  background: white;
  color: var(--leaf-dark);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-task-complete:hover {
  background: var(--leaf-light);
}

.task-item.task-last-year {
  background: var(--parchment);
  border-color: transparent;
  opacity: 0.8;
}

/* ===== 栽培記録リスト ===== */
.record-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-item {
  background: white;
  border: 1px solid var(--parchment);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.record-veg {
  font-weight: 700;
  color: var(--text-dark);
  min-width: 80px;
}

.record-meta {
  flex: 1;
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--text-light);
}

.status-badge {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
}

.status-growing   { background: #e8f5e0; color: var(--leaf-dark); }
.status-planned   { background: #fff8e0; color: #7a5500; }
.status-harvested { background: #f0ebe4; color: var(--soil); }
.status-failed    { background: #f5f0f0; color: #7a3030; }

/* ===== 空状態 ===== */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
  font-size: 14px;
}

.btn-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--leaf);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
}

.btn-link:hover {
  text-decoration: underline;
}

/* ===== 畑一覧 ===== */
.field-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.field-card {
  background: white;
  border: 1px solid var(--parchment);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  transition: box-shadow 0.2s, transform 0.15s;
  box-shadow: 0 1px 4px rgba(61,43,31,0.08);
}

.field-card:hover {
  box-shadow: 0 4px 14px rgba(61,43,31,0.15);
  transform: translateY(-2px);
}

.field-card-name {
  font-family: 'Shippori Mincho', serif;
  font-size: 17px;
  color: var(--soil);
  margin-bottom: 6px;
}

.field-card-size {
  font-size: 12px;
  color: var(--text-light);
}

.btn-create {
  background: var(--leaf);
  color: white;
  text-decoration: none;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.2s;
}

.btn-create:hover { background: var(--leaf-dark); }

.btn-delete-field {
  margin-top: 8px;
  width: 100%;
  padding: 6px;
  background: white;
  color: #c0392b;
  border: 1px solid #e08080;
  border-radius: 6px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-delete-field:hover { background: #fff5f5; }

.btn-clear {
  padding: 7px 14px;
  background: white;
  color: var(--warning);
  border: 1px solid var(--warning);
  border-radius: 6px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-clear:hover { background: #fff8f0; }

.btn-back {
  font-size: 13px;
  color: var(--text-light);
  text-decoration: none;
}

.btn-back:hover { color: var(--soil); }

/* ===== 畑グリッド ===== */
.grid-wrapper {
  overflow-x: auto;
}

.farm-grid {
  display: grid;
  grid-template-rows: 24px;
  gap: 3px;
  background: var(--parchment);
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #d4c9b0;
  min-width: 400px;
}

.grid-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-light);
}

.plot {
  aspect-ratio: 1;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  word-break: break-all;
  padding: 2px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1.5px solid transparent;
}

.plot:hover {
  transform: scale(1.08);
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  z-index: 1;
  position: relative;
}

/* 科ごとの色 */
.plot.empty,   .legend-dot.empty   { background: #e8dfc8; border-color: #cfc3a8; color: var(--text-mid); }
.plot.nasuka,  .legend-dot.nasuka  { background: #fcd5d5; border-color: #e08080; color: #7a2020; }
.plot.urka,    .legend-dot.urka    { background: #d5f0d5; border-color: #70b870; color: #1a5a1a; }
.plot.konka,   .legend-dot.konka   { background: #fff0cc; border-color: #e0b840; color: #7a5500; }
.plot.hagasai, .legend-dot.hagasai { background: #e0f5c0; border-color: #90c850; color: #2a5a00; }
.plot.imoka,   .legend-dot.imoka   { background: #f0dfc0; border-color: #c09050; color: #5a3000; }
.plot.mameka,  .legend-dot.mameka  { background: #d8e8f8; border-color: #6090c0; color: #1a3a6a; }

/* 計画済みは点線 */
.plot.planned { border-style: dashed; opacity: 0.8; }

/* 凡例 */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-mid);
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1.5px solid transparent;
}

/* ===== モーダル ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
}

.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 14px;
  padding: 24px;
  width: 320px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 101;
  box-shadow: 0 8px 32px rgba(61,43,31,0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal-plot-label {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.modal-veg-name {
  font-family: 'Shippori Mincho', serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-dark);
}

.modal-variety {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
}

.modal-close {
  background: var(--parchment);
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-light);
  flex-shrink: 0;
}

.modal-info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--parchment);
  font-size: 13px;
}

.modal-info-label { color: var(--text-light); }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  padding: 10px;
  border-radius: 8px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

.btn:hover { opacity: 0.85; }
.btn-harvest { background: var(--leaf); color: white; }
.btn-fail    { background: var(--parchment); color: var(--text-mid); border: 1px solid #d4c9b0; }

/* ===== 栽培記録ページ ===== */
.filter-form {
  background: white;
  border: 1px solid var(--parchment);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
}

.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.btn-filter {
  padding: 10px 20px;
  background: var(--leaf);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  align-self: flex-end;
}

.btn-filter:hover { background: var(--leaf-dark); }

.bulk-action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.btn-bulk-delete {
  padding: 8px 16px;
  background: white;
  color: #c0392b;
  border: 1px solid #e08080;
  border-radius: 6px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-bulk-delete:hover { background: #fff5f5; }

.record-count {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 12px;
}

.history-table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--parchment);
}

.history-table th {
  background: var(--parchment);
  color: var(--text-mid);
  font-weight: 700;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
}

.history-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--parchment);
  color: var(--text-dark);
  vertical-align: middle;
}

.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover td { background: #faf8f4; }

.td-veg { font-weight: 700; }

.td-variety {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-light);
}

.td-memo { max-width: 180px; }

.memo-input {
  width: 100%;
  font-size: 12px;
  color: var(--text-mid);
  border: 1px solid transparent;
  background: transparent;
  padding: 2px 4px;
  border-radius: 4px;
  outline: none;
  transition: border-color 0.2s;
}
.memo-input:focus,
.memo-input:hover {
  border-color: var(--border);
  background: #fff;
}

.td-plot { color: var(--text-mid); }
.td-plot-pos {
  display: block;
  font-size: 11px;
  color: var(--text-light);
}

.family-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  border: 1.5px solid transparent;
}

.family-tag.family-nasuka  { background: #fcd5d5; border-color: #e08080; color: #7a2020; }
.family-tag.family-urka    { background: #d5f0d5; border-color: #70b870; color: #1a5a1a; }
.family-tag.family-konka   { background: #fff0cc; border-color: #e0b840; color: #7a5500; }
.family-tag.family-hagasai { background: #e0f5c0; border-color: #90c850; color: #2a5a00; }
.family-tag.family-imoka   { background: #f0dfc0; border-color: #c09050; color: #5a3000; }
.family-tag.family-mameka  { background: #d8e8f8; border-color: #6090c0; color: #1a3a6a; }

/* ===== シミュレーションページ ===== */
.plan-notice {
  background: #fff8e0;
  border: 1px solid var(--sun);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  color: #7a5500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.plan-notice-icon { font-size: 16px; }

/* 連作警告の区画 */
.plot.rotation-warning {
  border-width: 2.5px;
  border-color: var(--warning);
  box-shadow: 0 0 0 1px var(--warning);
}

.plot.rotation-warning::after {
  content: '⚠';
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--warning);
  color: white;
  border-radius: 50%;
  width: 13px;
  height: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
}

/* ===== ログアウトボタン ===== */
.btn-logout {
  display: inline-block;
  padding: 10px 24px;
  background: white;
  color: #c0392b;
  border: 1.5px solid #e08080;
  border-radius: 8px;
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-logout:hover {
  background: #fff5f5;
}

/* ===== レスポンシブ ===== */
@media (max-width: 600px) {
  .stats-row { grid-template-columns: 1fr; }
}

/* ===== フォームカード（field_create等） ===== */
.form-card {
  background: white;
  border-radius: 14px;
  padding: 32px;
  max-width: 480px;
  border: 1px solid var(--parchment);
  box-shadow: 0 2px 12px rgba(61, 43, 31, 0.08);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-light);
  margin-top: -8px;
  margin-bottom: 16px;
}

/* ===== リンク ===== */
.auth-link {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-light);
}

.auth-link a {
  color: var(--leaf);
  text-decoration: none;
  font-weight: 500;
}

.auth-link a:hover {
  text-decoration: underline;
}
