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

/* ===== テーマ変数（デフォルト：ブルー） ===== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #6c757d;
  --danger: #dc3545;
  --bg: #f5f7fa;
  --card-bg: #ffffff;
  --border: #d0d9e4;
  --text: #212529;
  --text-muted: #6c757d;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ===== カラーテーマ ===== */
body[data-theme="blue"] {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
}
body[data-theme="green"] {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-light: #f0fdf4;
}
body[data-theme="red"] {
  --primary: #dc2626;
  --primary-dark: #b91c1c;
  --primary-light: #fef2f2;
}
body[data-theme="purple"] {
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --primary-light: #f5f3ff;
}
body[data-theme="orange"] {
  --primary: #ea580c;
  --primary-dark: #c2410c;
  --primary-light: #fff7ed;
}

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%;
  data-theme: blue;
}

/* ===== ローディング ===== */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== ユーザー選択・設定画面 ===== */
.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: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.screen-logo {
  font-size: 40px;
  text-align: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.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; }

/* ===== テーマスウォッチ ===== */
.theme-swatches {
  display: flex;
  gap: 12px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.theme-swatch:hover { transform: scale(1.15); }

.theme-swatch.active {
  border-color: #333;
  box-shadow: 0 0 0 2px white, 0 0 0 4px #333;
}

/* ===== 動的ユーザー入力 ===== */
#user-inputs-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.user-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-input-row input {
  flex: 1;
}

.user-input-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 24px;
  text-align: right;
}

.btn-remove-user {
  background: none;
  border: 1.5px solid #e5e7eb;
  border-radius: 6px;
  color: #9ca3af;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  width: 36px;
  height: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  padding: 0;
}

.btn-remove-user:hover { border-color: #dc2626; color: #dc2626; background: #fef2f2; }

.btn-add-user {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border: 1.5px dashed var(--primary);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  width: 100%;
  text-align: center;
  transition: all 0.15s;
  font-family: inherit;
  min-height: 44px;
}

.btn-add-user:hover { background: var(--primary); color: white; border-style: solid; }
.btn-add-user:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== ユーザー選択ボタン ===== */
.user-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
}

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

.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;
  font-family: inherit;
}

@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;
  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(37,99,235,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(--primary);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 20px 24px;
  text-align: center;
}

.summary-card .label { font-size: 13px; color: rgba(255,255,255,0.85); margin-bottom: 8px; font-weight: 500; }
.summary-card .value { font-size: 42px; font-weight: 800; color: #ffffff; line-height: 1; }
.summary-card .unit { font-size: 16px; font-weight: 600; color: rgba(255,255,255,0.9); }

/* ===== テーブル ===== */
.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: var(--primary-light);
  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; } }

/* ===== カレンダー ===== */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.cal-title { font-size: 18px; font-weight: 700; margin: 0; }
.cal-nav-btn { width: 40px; height: 40px; font-size: 22px; padding: 0; line-height: 1; }

.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; font-size: 13px; }
.cal-legend-item { display: flex; align-items: center; gap: 6px; }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}
.cal-wday { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 4px 0; }
.cal-wday.sun { color: #dc3545; }
.cal-wday.sat { color: #2563eb; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }

.cal-cell {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.cal-cell:active { opacity: 0.7; }
.cal-empty { background: transparent; border: none; }
.cal-today { border: 2px solid var(--primary); }
.cal-sun .cal-day-num { color: #dc3545; }
.cal-sat .cal-day-num { color: #2563eb; }
.cal-complete { background: var(--primary-light); border-color: var(--primary); }
.cal-missing { background: #fff7ed; border-color: #fdba74; }

.cal-day-num { font-size: 15px; font-weight: 700; line-height: 1; }
.cal-dots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
.cal-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.cal-dot-empty { background: transparent !important; border: 1.5px solid #d1d5db; }

.cal-holiday { background: #fff1f2; border-color: #fca5a5; }
.cal-holiday-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #dc3545;
  color: #dc3545;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}
.cal-custom-holiday { border-color: #dc3545; color: #dc3545; }
.cal-legend-hint { font-size: 11px; color: var(--text-muted); align-self: center; }

@media (max-width: 768px) {
  .cal-cell { min-height: 52px; padding: 6px 4px; }
  .cal-day-num { font-size: 13px; }
  .cal-dot { width: 7px; height: 7px; }
  .cal-legend-hint { display: none; }
}

/* ===== 印刷 ===== */
.print-only { display: none; }

@media print {
  body { background: white; }
  .no-print { display: none !important; }
  .print-only { display: block !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: 6px; }
  .table-card { overflow: visible; }
  .table-wrapper { overflow: visible; }

  table { font-size: 9pt; width: 100%; border-collapse: collapse; table-layout: auto; }

  th:nth-child(1), td:nth-child(1), th:nth-child(2), td:nth-child(2),
  th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6),
  th:nth-child(7), td:nth-child(7), th:nth-child(8), td:nth-child(8),
  th:nth-child(9), td:nth-child(9) { white-space: nowrap; }

  td:nth-child(3), td:nth-child(4) {
    max-width: 42mm;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  td:nth-child(10) {
    white-space: normal;
    word-break: break-all;
    min-width: 38mm;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .print-expand td:nth-child(10) {
    -webkit-line-clamp: unset;
    display: block;
    overflow: visible;
  }

  thead th {
    background: #1e3a5f !important;
    color: white !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 5px 4px;
    text-align: center;
    font-size: 8pt;
    font-weight: 600;
  }

  tbody tr:nth-child(even) td {
    background: #f0f5ff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  td { padding: 4px 5px; border-bottom: 0.5pt solid #d1d5db; line-height: 1.45; vertical-align: middle; }

  tfoot td {
    background: #dbeafe !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 6px 5px;
    font-weight: bold;
    font-size: 10pt;
    border-top: 2pt solid #2563eb;
    white-space: nowrap;
  }

  .print-header { text-align: center; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 2pt solid #1e3a5f; }
  .print-header h1 { font-size: 16pt; letter-spacing: 0.5em; margin: 0; font-weight: 700; }
  .print-header p { font-size: 10pt; margin: 4px 0 0; color: #333; }

  @page { margin: 10mm 8mm; size: A4 portrait; }
}

/* ===== モバイル（〜768px） ===== */
@media (max-width: 768px) {
  .header .nav { display: none; }
  .header { gap: 0; }
  .bottom-nav { display: flex; }
  .view { padding: 12px; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .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%; }

  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; text-align: center; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { padding: 14px 16px; }
  .summary-card .value { font-size: 20px; }
}

/* ===== PC（769px〜） ===== */
@media (min-width: 769px) {
  .bottom-nav { display: none !important; }
  .view { padding: 28px 32px; }
  .form-grid { grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
  .card { padding: 28px; }
}

@media (min-width: 1200px) {
  .view { padding: 32px 40px; }
}

/* ===== 認証画面 ===== */
.auth-tabs {
  display: flex;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 8px;
  font-size: 13px;
  color: #6b7280;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .2s, border-color .2s;
}
.auth-tab.active {
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}
.auth-form { display: block; }
.auth-error {
  color: #ef4444;
  font-size: 12px;
  min-height: 16px;
  margin-bottom: 8px;
}

/* ===== トライアルバナー ===== */
.trial-banner {
  background: #fef3c7;
  color: #92400e;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
}
.trial-upgrade-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}
.trial-upgrade-link:hover { text-decoration: underline; }

/* ===== ログアウトボタン ===== */
.btn-logout {
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: #6b7280;
  cursor: pointer;
  margin-left: 8px;
  transition: background .2s, color .2s;
}
.btn-logout:hover { background: #f3f4f6; color: #111827; }
