* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', 'Yu Gothic UI', 'Meiryo', sans-serif; background: #f5f5f5; color: #1f2937; }
a { color: #1f2937; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ナビゲーション */
.navbar { background: #1a1a1a; color: #fff; padding: 0 20px; display: flex; align-items: center; height: 56px; }
.navbar h1 { font-size: 18px; margin-right: 40px; }
.navbar nav a { color: #d4d4d4; padding: 8px 16px; font-size: 14px; border-radius: 4px; }
.navbar nav a:hover, .navbar nav a.active { color: #fff; background: rgba(255,255,255,0.15); text-decoration: none; }

/* 担当者バッジ */
.staff-badge { color: #e5e7eb; font-size: 13px; padding: 4px 12px; cursor: pointer; border: 1px solid rgba(229,231,235,0.4); border-radius: 16px; margin-left: 12px; white-space: nowrap; user-select: none; }
.staff-badge:hover { background: rgba(229,231,235,0.15); }

/* 担当者モーダル */
.staff-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.3); z-index: 9998; }
.staff-modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); z-index: 9999; min-width: 340px; max-width: 90vw; }
.staff-modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #e2e8f0; }
.staff-modal-header strong { font-size: 16px; color: #1f2937; }
.staff-modal-close { font-size: 24px; cursor: pointer; color: #64748b; line-height: 1; }
.staff-modal-close:hover { color: #1f2937; }
.staff-modal-body { padding: 16px 20px 20px; }

/* メインコンテンツ */
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { font-size: 22px; color: #1f2937; }

/* ボタン */
.btn { display: inline-block; padding: 8px 20px; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; text-align: center; }
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn-primary { background: #374151; color: #fff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-secondary { background: #64748b; color: #fff; }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-outline { background: transparent; border: 1px solid #374151; color: #374151; }

/* カード */
.card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); padding: 20px; margin-bottom: 16px; }
.card h3 { font-size: 16px; color: #1f2937; margin-bottom: 12px; border-bottom: 2px solid #e2e8f0; padding-bottom: 8px; }

/* テーブル */
table { width: 100%; border-collapse: collapse; }
table th { background: #e0e7ff; color: #1e3a8a; font-size: 12px; font-weight: 700; padding: 10px 12px; text-align: left; border-bottom: 2px solid #6366f1; }
table td { padding: 10px 12px; border-bottom: 1px solid #e2e8f0; font-size: 14px; color: #0f172a; }
/* ストライプ模様で行を区別 */
table tbody tr:nth-child(odd) { background: #fefce8; }
table tbody tr:nth-child(even) { background: #fff7ed; }
table tbody tr:hover { background: #dbeafe; transition: background 0.1s; }
/* 値（amount等）を強調 */
table td.amount { font-weight: 600; color: #0f172a; }
/* テーブル全体に枠 */
.card table { border: 1px solid #cbd5e1; border-radius: 6px; overflow: hidden; }

/* フォーム */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #475569; margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid #6366f1; border-radius: 6px; font-size: 14px; font-family: inherit;
  background: #fef9c3; color: #0f172a; /* 薄い黄色背景で入力欄を視認しやすく */
}
.form-group input:hover, .form-group select:hover, .form-group textarea:hover {
  border-color: #4f46e5; background: #fef3c7;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.25); background: #fff;
}
/* 既に入力済みの欄は淡いブルーで「入力済み」がわかるように */
.form-group input:not(:placeholder-shown):not([type="date"]):not([type="time"]):not([type="number"]),
.form-group textarea:not(:placeholder-shown) {
  background: #dbeafe;
}
/* date / time / number は placeholder が無いので別途 valid 判定 */
.form-group input[type="date"]:valid,
.form-group input[type="time"]:valid,
.form-group input[type="number"]:valid {
  background: #dbeafe;
}
/* select も値が入っていれば淡いブルー（JSで.has-valueクラス付与） */
.form-group select.has-value {
  background: #dbeafe;
}
/* readonly入力は薄いグレーで識別 */
.form-group input[readonly], .form-group input:disabled, .form-group select:disabled, .form-group textarea[readonly] {
  background: #e2e8f0 !important; color: #475569; cursor: not-allowed; border-color: #94a3b8;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-row-4 { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 8px; }

/* 検索バー */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar input, .search-bar select { padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
.search-bar input[type="text"] { min-width: 250px; }
.search-bar input[type="date"] { min-width: 150px; }

/* ステータスバッジ */
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-red { background: #fecaca; color: #dc2626; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ダッシュボード */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: 8px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); text-align: center; }
.stat-card .number { font-size: 32px; font-weight: 700; color: #1f2937; }
.stat-card .label { font-size: 13px; color: #64748b; margin-top: 4px; }

/* 明細テーブル */
.items-table input, .items-table select {
  border: 1.5px solid #6366f1; padding: 7px 8px; border-radius: 4px; font-size: 14px;
  background: #fef9c3; color: #0f172a; /* 未入力は黄色 */
}
.items-table input[type="number"] { width: 100px; text-align: right; }
.items-table input:hover, .items-table select:hover {
  border-color: #4f46e5; background: #fef3c7;
}
.items-table input:focus, .items-table select:focus {
  outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.25); background: #fff;
}
/* 入力済みは淡いブルー */
.items-table input:not(:placeholder-shown):not([type="number"]) { background: #dbeafe; }
.items-table input[type="number"]:not([value=""]):valid { background: #dbeafe; }
.items-table select.has-value { background: #dbeafe; }
.items-table .subtotal { font-weight: 600; color: #1f2937; text-align: right; min-width: 80px; }
.items-table td { vertical-align: middle; }

/* 合計欄 */
.totals { text-align: right; margin-top: 16px; padding: 16px; background: #f8fafc; border-radius: 8px; }
.totals .row { display: flex; justify-content: flex-end; gap: 20px; margin-bottom: 4px; font-size: 14px; }
.totals .total-row { font-size: 20px; font-weight: 700; color: #1f2937; border-top: 2px solid #1f2937; padding-top: 8px; margin-top: 8px; }

/* セクション */
.section { margin-bottom: 24px; }
.section-title { font-size: 15px; font-weight: 600; color: #1f2937; margin-bottom: 10px; padding-left: 10px; border-left: 3px solid #374151; }

/* 写真 */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.photo-grid img { width: 100%; height: 150px; object-fit: cover; border-radius: 6px; border: 1px solid #e2e8f0; }
.photo-item { position: relative; }
.photo-item .delete-btn { position: absolute; top: 4px; right: 4px; background: rgba(220,38,38,0.8); color: #fff; border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-size: 14px; }

/* 金額表示 */
.amount { font-weight: 600; text-align: right; }

/* 印刷 */
@media print {
  .navbar, .btn, .search-bar, .no-print { display: none !important; }
  .container { max-width: 100%; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* エラー */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-error { background: #fecaca; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* 顧客選択 */
.customer-search-results { position: absolute; background: #fff; border: 1px solid #d1d5db; border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.18); max-height: 280px; overflow-y: auto; z-index: 9999; width: 400px; left: 0; top: 100%; margin-top: 4px; }
.customer-search-results div { padding: 10px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid #f1f5f9; }
.customer-search-results div:last-child { border-bottom: none; }
.customer-search-results div:hover { background: #eff6ff; }
.customer-search-wrapper { position: relative; z-index: 50; }
.customer-search-wrapper:focus-within { z-index: 1000; }

/* レスポンシブ（スマホ） */
@media (max-width: 768px) {
  /* ナビ */
  .navbar { flex-direction: column; height: auto; padding: 10px; gap: 6px; }
  .navbar h1 { margin-right: 0; font-size: 16px; }
  .navbar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .navbar nav a { padding: 6px 10px; font-size: 13px; }

  /* コンテナ */
  .container { padding: 10px; }

  /* ページヘッダー */
  .page-header { flex-direction: column; gap: 10px; align-items: flex-start; }
  .page-header h2 { font-size: 18px; }
  .page-header div { display: flex; flex-wrap: wrap; gap: 6px; }

  /* フォームグリッド全て1カラム */
  .form-row, .form-row-3, .form-row-4 { grid-template-columns: 1fr; gap: 8px; }

  /* フォーム入力を大きく */
  .form-group input, .form-group select, .form-group textarea {
    font-size: 16px; padding: 10px 12px;
  }

  /* ボタンをタップしやすく */
  .btn { padding: 10px 20px; font-size: 15px; }
  .btn-sm { padding: 8px 14px; font-size: 13px; }

  /* ダッシュボード統計 */
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card .number { font-size: 24px; }

  /* テーブルを横スクロール可能に */
  .card { padding: 12px; overflow-x: auto; }
  table { min-width: 600px; }
  table th, table td { padding: 8px 6px; font-size: 13px; }

  /* 明細テーブル（注文フォーム） */
  .items-table { min-width: auto; }
  .items-table input { font-size: 14px; padding: 8px 6px; }
  .items-table input[type="number"] { width: 70px; }
  .items-table td { padding: 6px 4px; }

  /* 2カラムグリッド（注文主・届け先）を1カラムに */
  div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
  div[style*="grid-template-columns: 1fr 1fr 1fr"] { grid-template-columns: 1fr !important; }

  /* 検索バー */
  .search-bar { flex-direction: column; }
  .search-bar input, .search-bar select { min-width: 100% !important; width: 100%; }

  /* 顧客検索結果（スマホでは絶対配置をやめてインライン表示にして次フィールドを押し下げる） */
  .customer-search-results {
    position: static !important;
    width: 100% !important;
    max-width: 100%;
    margin-top: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    max-height: 250px;
  }
  .customer-search-results div {
    padding: 12px;
    font-size: 15px;
  }

  /* 写真グリッド */
  .photo-grid { grid-template-columns: repeat(2, 1fr); }

  /* 合計欄 */
  .totals .total-row { font-size: 18px; }

  /* 印刷不要エリアの操作ボタン横並び */
  div[style*="display:flex"][style*="gap:8px"] { flex-wrap: wrap; }
  div[style*="display: flex"][style*="gap: 8px"] { flex-wrap: wrap; }
  div[style*="display: flex"][style*="gap: 16px"] { flex-wrap: wrap; }

  .attendance-grid { font-size: 10px; }
  .attendance-grid .att-name { min-width: 60px; font-size: 10px; }
}

/* 日勤票グリッド */
.attendance-grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.attendance-grid th, .attendance-grid td { border: 1px solid #d1d5db; text-align: center; padding: 2px 4px; min-width: 28px; }
.attendance-grid .att-name { text-align: left; white-space: nowrap; padding: 2px 8px; min-width: 90px; font-weight: bold; background: #f8fafc; position: sticky; left: 0; z-index: 1; }
.attendance-grid .att-leave-label { font-weight: normal; color: #16a34a; font-size: 11px; }
.attendance-grid .att-total { background: #f0f9ff; font-weight: bold; min-width: 36px; }
.attendance-grid .att-sun { background: #fef2f2; }
.attendance-grid .att-sat { background: #eff6ff; }
.attendance-grid .att-cell { cursor: pointer; user-select: none; transition: background 0.1s; }
.attendance-grid .att-cell:hover { background: #dbeafe; }
.attendance-grid .att-filled { background: #dcfce7; font-weight: bold; }
.attendance-grid .att-cell.att-leave.att-filled { background: #fef9c3; }
.attendance-grid .att-cell.att-sun.att-filled { background: #bbf7d0; }
.attendance-grid .att-cell.att-sat.att-filled { background: #bbf7d0; }
.attendance-grid thead th { background: #f1f5f9; font-weight: 600; }
.att-staff-row td { border-bottom: none; }
.att-leave-row td { border-top: none; font-size: 11px; }

.annual-summary { border-collapse: collapse; width: 100%; }
.annual-summary th, .annual-summary td { border: 1px solid #d1d5db; padding: 6px 10px; }
.annual-summary th { background: #f1f5f9; }

@media print {
  .attendance-grid { font-size: 10px; }
  .attendance-grid th, .attendance-grid td { padding: 1px 2px; min-width: 20px; }
  .attendance-grid .att-name { min-width: 70px; }
  .attendance-grid .att-cell:hover { background: inherit; }
}
