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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #6c757d;
  --danger: #dc3545;
  --bg: #f5f7f5;
  --card-bg: #ffffff;
  --border: #d0ddd4;
  --text: #212529;
  --text-muted: #6c757d;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ===== ユーザー選択・設定画面 ===== */
.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  background: var(--bg);
}

.screen-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.screen-logo { font-size: 40px; text-align: center; }

.screen-card h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
  margin: 0;
}

.screen-sub {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: -8px;
}

.btn-full { width: 100%; margin-top: 4px; }

.user-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-user {
  width: 100%;
  padding: 16px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 2px solid var(--primary);
  border-radius: 10px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-user:active { background: var(--primary); color: white; }
@media (hover: hover) {
  .btn-user:hover { background: var(--primary); color: white; }
}

/* ===== ヘッダー ===== */
.header {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  gap: 32px;
  height: calc(56px + env(safe-area-inset-top));
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#header-username {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.95);
}

.btn-switch {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.5);
  color: white;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-switch:active { background: rgba(255,255,255,0.35); }

.nav { display: flex; gap: 4px; margin-left: 16px; }

.nav-btn {
  background: transparent;
  border: 2px solid rgba(255,255,255,0.4);
  color: rgba(255,255,255,0.85);
  padding: 6px 18px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  min-height: 36px;
}

@media (hover: hover) {
  .nav-btn:hover { background: rgba(255,255,255,0.15); }
}
.nav-btn.active { background: white; color: var(--primary); border-color: white; font-weight: 600; }

/* ===== ボトムナビ（モバイルのみ表示） ===== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 200;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}

.bottom-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  min-height: 56px;
  transition: color 0.15s;
}

.bottom-nav-btn.active {
  color: var(--primary);
  font-weight: 700;
}

.bottom-nav-btn svg { stroke: currentColor; }

/* ===== メインレイアウト ===== */
#app { min-height: 100vh; }

.view { display: none; padding: 24px; max-width: 1200px; margin: 0 auto; }
.view.active { display: block; }

/* ===== カード ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-light);
}

/* ===== フォーム ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.required { color: var(--danger); }
.sub-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }

input[type="text"],
input[type="date"],
input[type="time"],
select,
textarea {
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 16px; /* iOS自動ズーム防止 */
  font-family: inherit;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
  min-height: 44px;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,111,60,0.12);
}

textarea {
  resize: vertical;
  min-height: 100px;
  font-size: 16px;
}

/* 時間入力行 */
.time-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.time-group { display: flex; flex-direction: column; gap: 4px; }
.time-group input, .time-group select { width: auto; min-width: 110px; }
.time-sep { padding-bottom: 12px; font-size: 16px; color: var(--text-muted); }

.time-result { display: flex; flex-direction: column; gap: 4px; }

.hours-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 15px;
  padding: 9px 16px;
  border-radius: 6px;
  min-width: 80px;
  min-height: 44px;
  text-align: center;
  line-height: 1.4;
}

/* フォームボタン */
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ===== ボタン共通 ===== */
.btn {
  padding: 11px 22px;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--primary); color: white; }
@media (hover: hover) {
  .btn-primary:hover { background: var(--primary-dark); }
}
.btn-secondary { background: white; color: var(--secondary); border: 1.5px solid var(--border); }
@media (hover: hover) {
  .btn-secondary:hover { background: #f8f9fa; }
}
.btn-danger { background: white; color: var(--danger); border: 1.5px solid #f5c6cb; }
@media (hover: hover) {
  .btn-danger:hover { background: #fff5f5; }
}
.btn-icon { padding: 8px 14px; font-size: 13px; min-height: 44px; }

/* ===== フィルター ===== */
.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.filter-row .form-group { min-width: 100px; }
.filter-actions { display: flex; gap: 8px; margin-left: auto; }

/* ===== 集計サマリー ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.summary-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  border-left: 4px solid var(--primary);
}

.summary-card .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.summary-card .value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary-dark);
}

.summary-card .unit { font-size: 14px; font-weight: 500; }

/* ===== テーブル ===== */
.table-card { padding: 0; overflow: hidden; }

.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--primary);
  color: white;
  padding: 12px 10px;
  text-align: left;
  white-space: nowrap;
  font-weight: 600;
}

tbody tr { border-bottom: 1px solid #eef2ef; }
tbody tr:last-child { border-bottom: none; }

@media (hover: hover) {
  tbody tr:hover { background: var(--primary-light); }
}

td {
  padding: 10px 10px;
  vertical-align: top;
}

td.work-content { max-width: 200px; white-space: pre-wrap; word-break: break-all; font-size: 12px; }

.hours-cell { font-weight: 700; color: var(--primary-dark); text-align: center; }

tfoot td {
  padding: 10px;
  font-weight: 700;
  background: #f0f7f3;
  border-top: 2px solid var(--primary);
}

.no-data {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

/* 操作ボタン */
.action-btns { display: flex; gap: 6px; white-space: nowrap; }
.btn-edit { background: #e8f4fd; color: #0066cc; border: 1px solid #b3d7f5; }
@media (hover: hover) {
  .btn-edit:hover { background: #d0eaf9; }
}
.btn-del { background: #fdecea; color: var(--danger); border: 1px solid #f5c6cb; }
@media (hover: hover) {
  .btn-del:hover { background: #fad4d1; }
}

/* ===== 印刷スタイル ===== */
.print-only { display: none; }

@media print {
  body { background: white; font-size: 11pt; }

  .no-print { display: none !important; }
  .print-only { display: block !important; }
  .bottom-nav { display: none !important; }

  .view { display: block !important; padding: 0; max-width: 100%; }
  #view-form { display: none !important; }
  #view-list { display: block !important; }

  .card { box-shadow: none; padding: 0; margin-bottom: 12px; }
  .table-card { overflow: visible; }
  .table-wrapper { overflow: visible; }

  table { font-size: 9pt; width: 100%; }

  thead th {
    background: #333 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 6px 5px;
  }

  td { padding: 5px; }

  tfoot td {
    background: #eee !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .summary-grid { display: flex; gap: 20px; margin-bottom: 12px; }

  .summary-card {
    box-shadow: none;
    border: 1px solid #ccc;
    flex: 1;
  }

  .print-header {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #333;
  }

  .print-header h1 { font-size: 18pt; letter-spacing: 0.5em; }
  .print-header p { font-size: 12pt; margin-top: 4px; }

  @page { margin: 15mm 10mm; size: A4 landscape; }
}

/* ===== モバイル最適化（〜768px） ===== */
@media (max-width: 768px) {
  /* ヘッダーのナビを非表示 → ボトムナビで代替 */
  .header .nav { display: none; }
  .header { gap: 0; }

  /* ボトムナビ表示 */
  .bottom-nav { display: flex; }

  /* コンテンツがボトムナビに隠れないよう余白 */
  .view {
    padding: 12px 12px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  /* フォームは1列 */
  .form-grid { grid-template-columns: 1fr; gap: 14px; }

  /* カード */
  .card { padding: 16px; border-radius: 10px; }

  /* 時間入力行をグリッドに */
  .time-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    gap: 8px;
  }
  .time-result {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }
  .time-result .sub-label { white-space: nowrap; }
  .hours-badge { flex: 1; }
  .time-group select { min-width: unset; width: 100%; }

  /* フィルター */
  .filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .filter-actions {
    grid-column: 1 / -1;
    margin-left: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .filter-actions .btn { width: 100%; justify-content: center; }

  /* 保存ボタンを全幅に */
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; text-align: center; }

  /* サマリーを2列 */
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { padding: 14px 16px; }
  .summary-card .value { font-size: 20px; }
}

/* ===== 小型スマホ（〜390px） ===== */
@media (max-width: 390px) {
  .header h1 { font-size: 15px; }
  .card { padding: 14px; }
}

/* ===== Mac・タブレット（769px〜） ===== */
@media (min-width: 769px) {
  .bottom-nav { display: none !important; }
  .view { padding: 28px 32px; }

  /* フォームを3列に広げる */
  .form-grid { grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

  /* 稼働時間グループは2列分に */
  .form-grid .time-field { grid-column: span 2; }

  .card { padding: 28px; }
}

/* ===== ワイドスクリーン（1200px〜） ===== */
@media (min-width: 1200px) {
  .view { padding: 32px 40px; }
}
