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

:root {
  --primary: #1a73e8;
  --primary-light: #e8f0fe;
  --danger: #d93025;
  --success: #1e8e3e;
  --bg: #f1f3f4;
  --card-bg: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --before-color: #1a73e8;
  --after-color: #e8710a;
  --radius: 12px;
}

html {
  font-size: 15px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans',
    'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 80px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== ヘッダー ===== */
.app-header {
  background: var(--primary);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1rem;
  font-weight: 600;
}

.badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ===== タブナビゲーション ===== */
.tab-nav {
  display: flex;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 47px;
  z-index: 99;
}

.tab-btn {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: none;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ===== タブコンテンツ ===== */
.tab-content {
  display: none;
  padding: 12px;
  max-width: 480px;
  margin: 0 auto;
}

.tab-content.active {
  display: block;
}

/* ===== カード ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ===== 基本情報バー ===== */
.info-bar .info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.info-bar .info-row:first-child {
  margin-bottom: 8px;
}

.info-bar label {
  font-size: 0.85rem;
  font-weight: 500;
}

.info-bar select {
  font-size: 0.95rem;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.display-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 6px;
}

.display-info:empty {
  display: none;
}

/* ===== 日付セレクター ===== */
.day-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.nav-btn:active {
  background: var(--bg);
}

.current-day {
  font-size: 1.2rem;
  font-weight: 700;
  min-width: 100px;
  text-align: center;
}

/* 日付グリッド */
.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.day-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text);
  transition: all 0.15s;
  position: relative;
}

.day-cell:active {
  transform: scale(0.9);
}

.day-cell.selected {
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.day-cell.has-data::after {
  content: '';
  position: absolute;
  bottom: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--success);
}

.day-cell.selected.has-data::after {
  background: white;
}

.day-cell.sunday {
  color: var(--danger);
}

.day-cell.saturday {
  color: var(--primary);
}

.day-cell.selected.sunday,
.day-cell.selected.saturday {
  color: white;
}

/* ===== セクションタイトル ===== */
.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 14px;
  padding-left: 10px;
  border-left: 4px solid var(--primary);
}

.section-title.before {
  border-left-color: var(--before-color);
  color: var(--before-color);
}

.section-title.after {
  border-left-color: var(--after-color);
  color: var(--after-color);
}

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

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="time"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ===== トグルボタン ===== */
.toggle-group {
  display: flex;
  gap: 8px;
}

.toggle-group.wide {
  flex-wrap: wrap;
}

.toggle-btn {
  flex: 1;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 60px;
  text-align: center;
}

.toggle-btn:active {
  transform: scale(0.95);
}

.toggle-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
}

/* 酒気帯び「有」は赤 */
.toggle-btn.active[data-value="有"][data-field="before-drinking"],
.toggle-btn.active[data-value="有"][data-field="after-drinking"] {
  background: var(--danger);
  border-color: var(--danger);
}

/* 異常有・不良は赤 */
.toggle-btn.active[data-value="異常有"],
.toggle-btn.active[data-value="不良"] {
  background: var(--danger);
  border-color: var(--danger);
}

/* やや疲労はオレンジ */
.toggle-btn.active[data-value="やや疲労"] {
  background: var(--after-color);
  border-color: var(--after-color);
}

/* ===== 自動計算表示 ===== */
.calc-display {
  padding: 10px 12px;
  background: var(--primary-light);
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
}

/* ===== ボタン ===== */
.action-bar {
  padding: 8px 0;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.primary-btn:active {
  opacity: 0.8;
}

.secondary-btn {
  width: 100%;
  padding: 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  margin-bottom: 8px;
}

.section-save {
  padding: 4px 0 0;
}

.section-save .secondary-btn {
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

.danger-btn {
  width: 100%;
  padding: 12px;
  background: white;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 12px;
}

/* ===== 月次一覧 ===== */
.monthly-list {
  max-height: 60vh;
  overflow-y: auto;
}

.monthly-row {
  display: flex;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--bg);
  gap: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.monthly-row:active {
  background: var(--bg);
}

.monthly-row .day-num {
  font-weight: 700;
  min-width: 32px;
  text-align: center;
}

.monthly-row .area {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.monthly-row .distance {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}

.monthly-row.empty {
  opacity: 0.4;
}

.monthly-row.empty .area {
  font-style: italic;
}

/* ===== トースト通知 ===== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #323232;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

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

/* ===== 未入力警告 ===== */
.missing-banner {
  background: #fce8e6;
  color: #c5221f;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: center;
  border: 1px solid #f5c6cb;
}

.day-cell.missing {
  background: #fce8e6;
  color: #c5221f;
  font-weight: 600;
}

.day-cell.missing.selected {
  background: #d93025;
  color: white;
}

/* ===== レスポンシブ ===== */
@media (min-width: 600px) {
  .tab-content {
    max-width: 540px;
  }
}

/* ===== 印刷オーバーレイ ===== */
#print-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #fff;
  z-index: 10000;
  overflow: auto;
}
.print-toolbar {
  position: sticky;
  top: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: #1a73e8;
  z-index: 10001;
}
.print-toolbar button {
  padding: 14px 20px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
}
#print-cancel-btn {
  background: white;
  color: #1a73e8;
  min-width: 80px;
}
#print-exec-btn {
  background: rgba(255,255,255,0.25);
  color: white;
  flex: 1;
}
#print-body {
  padding: 4px;
}
@media print {
  .no-print { display: none !important; }
  #print-overlay { position: static; overflow: visible; }
  #print-body { padding: 0; }
}
