/* ==========================================================================
   喜多商店 原価・作業管理システム 統合スタイルシート (style.css)
   設計指針:
   1. 視覚物理防御: ボタン・バッジ・タブは white-space: nowrap / flex-shrink: 0 徹底
   2. 現場スマホ完全適合: 375px〜420pxで崩れゼロ、入力欄16px以上(iOSズーム防止)、特大打刻ボタン(68px+)
   3. テーブル1文字縦潰れ封殺: 横スクロールコンテナ + 適切な min-width 指定
   4. A4公式帳票印刷 (@media print): 見積書・請求書・工事台帳・工事写真台帳(1頁3段)完全対応
   ========================================================================== */

:root {
  --bg-page: #f3f6f9;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --navy-900: #0f2942;
  --navy-800: #163a5c;
  --navy-700: #1e4d78;
  --brand-primary: #0d6e5b;
  --brand-primary-hover: #095647;
  --brand-primary-light: #e6f5f1;
  --accent-blue: #1d6fb8;
  --accent-blue-light: #e8f2fc;
  --danger-600: #dc2626;
  --danger-700: #b91c1c;
  --danger-light: #fef2f2;
  --warning-600: #d97706;
  --warning-700: #b45309;
  --warning-light: #fffbeb;
  --success-600: #059669;
  --success-light: #ecfdf5;
  --text-main: #0f172a;
  --text-sub: #475569;
  --text-muted: #64748b;
  --border-color: #dbe3ec;
  --border-strong: #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(15, 41, 66, 0.07);
  --shadow-md: 0 4px 12px rgba(15, 41, 66, 0.09);
  --shadow-lg: 0 12px 28px rgba(15, 41, 66, 0.16);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   視覚物理防御（ボタン・バッジ・タブ・チップは絶対に2行落ちさせない）
   -------------------------------------------------------------------------- */
.btn,
.badge,
.nav-tab,
.bottom-nav-btn,
.sub-tab,
.filter-chip,
.stat-pill,
.nowrap {
  white-space: nowrap;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   ボタン共通システム
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.93rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease;
  text-decoration: none;
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-sm {
  min-height: 34px;
  padding: 5px 11px;
  font-size: 0.83rem;
}

.btn-lg {
  min-height: 52px;
  padding: 12px 22px;
  font-size: 1.05rem;
}

.btn-primary {
  background-color: var(--brand-primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(13, 110, 91, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--brand-primary-hover);
}

.btn-navy {
  background-color: var(--navy-900);
  color: #ffffff;
}
.btn-navy:hover:not(:disabled) {
  background-color: var(--navy-800);
}

.btn-blue {
  background-color: var(--accent-blue);
  color: #ffffff;
}
.btn-blue:hover:not(:disabled) {
  background-color: #155a96;
}

.btn-danger {
  background-color: var(--danger-600);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.25);
}
.btn-danger:hover:not(:disabled) {
  background-color: var(--danger-700);
}

.btn-warning {
  background-color: var(--warning-600);
  color: #ffffff;
}
.btn-warning:hover:not(:disabled) {
  background-color: var(--warning-700);
}

.btn-outline {
  background-color: #ffffff;
  color: var(--text-main);
  border-color: var(--border-strong);
}
.btn-outline:hover:not(:disabled) {
  background-color: var(--bg-subtle);
  border-color: #94a3b8;
}

.btn-danger-outline {
  background-color: #ffffff;
  color: var(--danger-600);
  border-color: #fca5a5;
}
.btn-danger-outline:hover:not(:disabled) {
  background-color: var(--danger-light);
}

/* 喜多商店独自：手袋越しでも1秒で押せる特大打刻ボタン（高さ68px以上） */
.btn-punch-start {
  width: 100%;
  min-height: 68px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #0d8a6f 0%, #096350 100%);
  color: #ffffff;
  font-size: 1.22rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 16px rgba(13, 110, 91, 0.34);
  border: none;
}
.btn-punch-start:hover:not(:disabled) {
  background: linear-gradient(135deg, #0b7a62 0%, #075242 100%);
}
.btn-punch-start svg {
  width: 24px;
  height: 24px;
}

.btn-punch-stop {
  width: 100%;
  min-height: 72px;
  padding: 16px 24px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: #ffffff;
  font-size: 1.28rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  box-shadow: 0 8px 20px rgba(220, 38, 38, 0.38);
  border: 2px solid rgba(255, 255, 255, 0.35);
}
.btn-punch-stop:hover:not(:disabled) {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
}
.btn-punch-stop svg {
  width: 26px;
  height: 26px;
}

/* --------------------------------------------------------------------------
   バッジ・ステータス表示
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.4;
}

.badge-green {
  background-color: var(--success-light);
  color: #047857;
  border: 1px solid #a7f3d0;
}
.badge-blue {
  background-color: var(--accent-blue-light);
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}
.badge-amber {
  background-color: var(--warning-light);
  color: #b45309;
  border: 1px solid #fde68a;
}
.badge-red {
  background-color: var(--danger-light);
  color: #b91c1c;
  border: 1px solid #fecaca;
}
.badge-gray {
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}
.badge-navy {
  background-color: #e2e8f0;
  color: var(--navy-900);
  border: 1px solid #cbd5e1;
}

/* ライブパルスアニメーション */
.live-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 0 rgba(16, 185, 129, 0.7);
  animation: livePulse 1.6s infinite;
  flex-shrink: 0;
}

.live-dot-white {
  background-color: #4ade80;
  box-shadow: 0 0 0 rgba(74, 222, 128, 0.8);
}

@keyframes livePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    box-shadow: 0 0 0 9px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* --------------------------------------------------------------------------
   フォーム要素（iOS Safari自動ズーム防止のため 16px 標準）
   -------------------------------------------------------------------------- */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

.req-mark {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background-color: var(--danger-light);
  color: var(--danger-600);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.form-hint {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-control,
input[type='text'],
input[type='password'],
input[type='number'],
input[type='date'],
input[type='time'],
input[type='datetime-local'],
input[type='tel'],
input[type='email'],
input[type='url'],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: #ffffff;
  color: var(--text-main);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 91, 0.15);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

/* --------------------------------------------------------------------------
   ログイン画面
   -------------------------------------------------------------------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(150deg, #0b2238 0%, #133b5c 55%, #0d6e5b 100%);
  padding: 16px;
}

.login-topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto 12px auto;
}

.login-card-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.login-brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--navy-900), var(--brand-primary));
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 900;
  flex-shrink: 0;
}

.login-brand-title {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 800;
  color: var(--navy-900);
}

.login-brand-sub {
  margin: 2px 0 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.pw-field-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.pw-field-wrap input,
.pw-field-wrap input[type='password'],
.pw-field-wrap input[type='text'],
#login-pw-input {
  padding-right: 84px;
}

.pw-toggle-btn {
  position: absolute;
  right: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-sub);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-sub);
  user-select: none;
}

.checkbox-row input[type='checkbox'] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  margin: 0;
  accent-color: var(--brand-primary);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   アプリ全体ヘッダー ＆ ナビゲーション
   -------------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--navy-900);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(15, 41, 66, 0.22);
}

.app-header-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #10b981, #0d6e5b);
  color: #ffffff;
  font-weight: 900;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-title-wrap {
  min-width: 0;
}

.header-company-name {
  font-size: 0.98rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub-info {
  font-size: 0.74rem;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

/* PC・タブレット用水平ナビバー */
.top-nav-bar {
  background-color: #ffffff;
  border-bottom: 1px solid var(--border-color);
}

.top-nav-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.top-nav-inner::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 12px 14px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-sub);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.nav-tab:hover {
  color: var(--navy-900);
  background-color: var(--bg-subtle);
}

.nav-tab.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
  background-color: rgba(13, 110, 91, 0.05);
}

/* スマホ下部固定ナビゲーション（768px以下で表示） */
.mobile-bottom-nav {
  display: none;
}

/* --------------------------------------------------------------------------
   メインコンテンツ領域 ＆ カード共通
   -------------------------------------------------------------------------- */
.app-main {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px 16px 92px 16px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 800;
  color: var(--navy-900);
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-subtitle {
  margin: 3px 0 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0;
  font-size: 1.04rem;
  font-weight: 800;
  color: var(--navy-900);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 案内・警告アラートボックス */
.alert-box {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-amber {
  background-color: #fffbeb;
  border-color: #f59e0b;
  color: #78350f;
}
.alert-red {
  background-color: #fef2f2;
  border-color: #f87171;
  color: #7f1d1d;
}
.alert-blue {
  background-color: #eff6ff;
  border-color: #93c5fd;
  color: #1e3a8a;
}
.alert-green {
  background-color: #ecfdf5;
  border-color: #6ee7b7;
  color: #064e3b;
}

/* --------------------------------------------------------------------------
   ① 喜多商店独自「個人の作業開始・終了ワンタップ画面」専用スタイル
   -------------------------------------------------------------------------- */
.punch-container {
  max-width: 680px;
  margin: 0 auto;
}

/* 稼働中ライブカード */
.active-work-banner {
  background: linear-gradient(145deg, #064e3b 0%, #0d6e5b 60%, #0f766e 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  margin-bottom: 20px;
  box-shadow: 0 10px 26px rgba(6, 78, 59, 0.32);
  border: 2px solid #34d399;
}

.active-work-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.active-work-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
}

.active-work-project {
  margin: 4px 0 6px 0;
  font-size: 1.38rem;
  font-weight: 900;
  line-height: 1.35;
}

.active-work-meta {
  font-size: 0.9rem;
  color: #d1fae5;
  margin-bottom: 14px;
}

.active-timer-box {
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: center;
  margin-bottom: 16px;
}

.active-timer-label {
  font-size: 0.8rem;
  color: #a7f3d0;
  font-weight: 700;
  margin-bottom: 4px;
}

.active-timer-digits {
  font-size: clamp(1.9rem, 7vw, 2.75rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.active-note-input {
  margin-bottom: 14px;
}
.active-note-input input {
  background: rgba(255, 255, 255, 0.96);
  border: none;
  color: var(--text-main);
}

/* 前日押し忘れリカバリカード */
.forgot-work-card {
  background: #fffbeb;
  border: 2px solid #f59e0b;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.forgot-work-title {
  margin: 0 0 8px 0;
  font-size: 1rem;
  font-weight: 800;
  color: #92400e;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 本日の予定カード（職人ワンタップ開始カード） */
.today-schedule-card {
  background: #ffffff;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease;
}

.today-schedule-card.is-working {
  border-color: #10b981;
  background: #f0fdf4;
}

.today-schedule-card.is-completed {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.schedule-time-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 8px;
  background: var(--navy-900);
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.schedule-project-title {
  margin: 10px 0 6px 0;
  font-size: 1.22rem;
  font-weight: 800;
  color: var(--navy-900);
}

.schedule-detail-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.92rem;
  color: var(--text-sub);
}

.schedule-detail-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

.map-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 6px;
  background: var(--accent-blue-light);
  color: var(--accent-blue);
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.map-link:hover {
  background: #dbeafe;
}

/* --------------------------------------------------------------------------
   ② 管理者用 原価・稼働リアルタイムダッシュボード
   -------------------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-left: 5px solid var(--brand-primary);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  text-align: left;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.kpi-card.active-filter {
  outline: 2px solid var(--navy-900);
  background: #f0f9ff;
}
.kpi-card.kpi-blue {
  border-left-color: var(--accent-blue);
}
.kpi-card.kpi-navy {
  border-left-color: var(--navy-900);
}
.kpi-card.kpi-amber {
  border-left-color: var(--warning-600);
}
.kpi-card.kpi-danger {
  border-left-color: var(--danger-600);
  background: #fffafa;
}

.kpi-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.kpi-value {
  font-size: 1.52rem;
  font-weight: 900;
  color: var(--navy-900);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-sub {
  margin-top: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ライブ稼働モニターチップ */
.live-workers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 10px;
}

.live-worker-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: #f0fdf4;
  border: 1px solid #86efac;
}

/* 予算消化プログレスバー */
.progress-wrap {
  min-width: 120px;
}
.progress-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 3px;
  font-variant-numeric: tabular-nums;
}
.progress-bar-bg {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background-color: var(--brand-primary);
  transition: width 0.25s ease;
}
.progress-bar-fill.warn {
  background-color: var(--warning-600);
}
.progress-bar-fill.over {
  background-color: var(--danger-600);
}

/* --------------------------------------------------------------------------
   テーブル共通（1文字タワー縦潰れ絶対禁止）
   -------------------------------------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.filter-bar .search-input {
  flex: 1 1 220px;
  min-width: 180px;
}

.filter-bar select,
.filter-bar input[type='month'],
.filter-bar input[type='date'] {
  width: auto;
  min-width: 145px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  background-color: #f1f5f9;
  color: var(--navy-900);
  font-weight: 800;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table td.cell-wrap {
  white-space: normal;
  min-width: 180px;
  max-width: 320px;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.text-right {
  text-align: right !important;
}
.text-center {
  text-align: center !important;
}

.profit-positive {
  color: #047857;
  font-weight: 800;
}
.profit-negative {
  color: var(--danger-600);
  font-weight: 800;
}

/* --------------------------------------------------------------------------
   ③ 週間スタッフ別配員スケジュールマトリクス（サクミル式）
   -------------------------------------------------------------------------- */
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 920px;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid var(--border-color);
  vertical-align: top;
  padding: 6px;
}

.matrix-table th {
  background: #f1f5f9;
  text-align: center;
  font-size: 0.83rem;
  font-weight: 800;
  padding: 8px 6px;
}

.matrix-table th.col-staff {
  width: 148px;
  text-align: left;
  padding-left: 10px;
}

.matrix-table th.is-today {
  background: #dcfce7;
  color: #065f46;
}
.matrix-table th.is-sat {
  color: #1d4ed8;
}
.matrix-table th.is-sun {
  color: #dc2626;
}

.matrix-staff-cell {
  background: #f8fafc;
  font-weight: 700;
}

.staff-avatar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.staff-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.matrix-day-cell {
  min-height: 86px;
  background: #ffffff;
}
.matrix-day-cell.is-today {
  background: #f7fee7;
}

.sched-chip {
  border-left: 4px solid var(--brand-primary);
  background: #f1f5f9;
  border-radius: 6px;
  padding: 5px 7px;
  margin-bottom: 5px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: background-color 0.12s ease;
}
.sched-chip:hover {
  background: #e2e8f0;
}
.sched-chip-time {
  font-weight: 800;
  color: var(--navy-900);
  font-variant-numeric: tabular-nums;
}
.sched-chip-proj {
  font-weight: 700;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sched-chip-sub {
  color: var(--text-muted);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-add-btn {
  width: 100%;
  padding: 3px 0;
  border: 1px dashed #cbd5e1;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.cell-add-btn:hover {
  background: #f1f5f9;
  color: var(--brand-primary);
  border-color: var(--brand-primary);
}

/* --------------------------------------------------------------------------
   ⑤ 税抜／税込 0ミリ秒即時切替トグル（憲法27）
   -------------------------------------------------------------------------- */
.tax-mode-switch {
  display: inline-flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
  gap: 3px;
}

.tax-mode-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-sub);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.tax-mode-btn.active {
  background: #ffffff;
  color: var(--navy-900);
  box-shadow: var(--shadow-sm);
}

/* サブタブバー */
.sub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.sub-tab {
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text-sub);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
}
.sub-tab.active {
  background: var(--navy-900);
  color: #ffffff;
  border-color: var(--navy-900);
}

/* --------------------------------------------------------------------------
   ⑦ 現場写真カードグリッド
   -------------------------------------------------------------------------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.photo-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.photo-thumb-wrap {
  width: 100%;
  height: 175px;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.photo-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card-body {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* --------------------------------------------------------------------------
   モーダル ＆ トースト通知
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 12px;
  overflow-y: auto;
}

.modal-box {
  width: 100%;
  max-width: 680px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  margin: auto 0;
  overflow: hidden;
}

.modal-box.modal-xl {
  max-width: 1020px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: var(--navy-900);
  color: #ffffff;
}

.modal-title {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 800;
}

.modal-close-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-body {
  padding: 20px;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-color);
}

/* トースト通知 */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 32px);
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--navy-900);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastSlideIn 0.2s ease;
}
.toast.toast-success {
  background: #065f46;
  border-left: 5px solid #34d399;
}
.toast.toast-error {
  background: #991b1b;
  border-left: 5px solid #fca5a5;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 空状態表示 */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}
.empty-state-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 6px;
}

/* --------------------------------------------------------------------------
   スマホ・レスポンシブ最適化（375px〜768px）
   -------------------------------------------------------------------------- */
@media (max-width: 960px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .top-nav-bar {
    display: none;
  }

  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: stretch;
    background: #ffffff;
    border-top: 1px solid var(--border-strong);
    box-shadow: 0 -2px 10px rgba(15, 41, 66, 0.08);
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-bottom-nav::-webkit-scrollbar {
    display: none;
  }

  .bottom-nav-btn {
    flex: 1 0 auto;
    min-width: 64px;
    padding: 7px 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-family: inherit;
    font-size: 0.69rem;
    font-weight: 700;
    cursor: pointer;
  }

  .bottom-nav-btn svg {
    width: 20px;
    height: 20px;
  }

  .bottom-nav-btn.active {
    color: var(--brand-primary);
    background: rgba(13, 110, 91, 0.06);
  }

  .app-main {
    padding: 14px 12px 96px 12px;
  }

  .card {
    padding: 14px;
  }

  .form-grid-2,
  .form-grid-3,
  .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .toast-container {
    bottom: 74px;
    right: 12px;
    left: 12px;
  }
}

@media (max-width: 420px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .app-header-inner {
    padding: 8px 10px;
  }
  .header-company-name {
    font-size: 0.88rem;
  }
  .user-chip .role-tag-text {
    display: none;
  }
}

/* ==========================================================================
   荀彧・A4公式帳票印刷システム (@media print ＆ プレビュー共通)
   対応帳票:
   1. A4見積書 / 御請求書（インボイス番号・角印枠・振込先・1円一致）
   2. A4工事台帳（収支サマリー・スタッフ別労務内訳・打刻履歴・仕入明細）
   3. A4工事写真台帳（1ページ3段固定・左写真＋右コメント建設標準フォーマット）
   ========================================================================== */
.print-only-root {
  display: none;
}

.print-sheet {
  background: #ffffff;
  color: #111827;
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif;
  width: 100%;
  max-width: 190mm;
  margin: 0 auto;
  font-size: 10pt;
  line-height: 1.45;
}

/* 見積書・請求書ヘッダー */
.doc-title-banner {
  text-align: center;
  font-size: 20pt;
  font-weight: 900;
  letter-spacing: 0.25em;
  padding-bottom: 6px;
  border-bottom: 3px double #0f2942;
  margin-bottom: 14px;
  color: #0f2942;
}

.doc-top-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 14px;
}

.doc-client-box {
  flex: 1.15;
}

.doc-client-name {
  font-size: 14pt;
  font-weight: 800;
  border-bottom: 1.5px solid #111827;
  padding-bottom: 4px;
  margin-bottom: 8px;
}

.doc-grand-total-box {
  margin-top: 10px;
  border: 2px solid #0f2942;
  background: #f8fafc;
  padding: 8px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.doc-grand-total-label {
  font-size: 10.5pt;
  font-weight: 800;
}

.doc-grand-total-amount {
  font-size: 16pt;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.doc-issuer-box {
  flex: 0.95;
  position: relative;
  font-size: 9pt;
  padding-right: 64px;
}

.doc-issuer-name {
  font-size: 11.5pt;
  font-weight: 800;
  margin-bottom: 3px;
}

/* 電子角印枠 */
.company-seal-box {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 54px;
  height: 54px;
  border: 2px solid #c81e1e;
  border-radius: 4px;
  color: #c81e1e;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 8.5pt;
  font-weight: 900;
  line-height: 1.15;
  padding: 3px;
  opacity: 0.88;
}

/* 帳票テーブル */
.print-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  font-size: 9pt;
}

.print-table th,
.print-table td {
  border: 1px solid #334155;
  padding: 5px 7px;
  vertical-align: middle;
}

.print-table th {
  background: #e2e8f0;
  color: #0f172a;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.doc-summary-wrap {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.doc-summary-table {
  width: 260px;
  border-collapse: collapse;
  font-size: 9.5pt;
}
.doc-summary-table th,
.doc-summary-table td {
  border: 1px solid #334155;
  padding: 5px 8px;
}
.doc-summary-table th {
  background: #f1f5f9;
  text-align: left;
  width: 115px;
}
.doc-summary-table td {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.doc-bank-box,
.doc-notes-box {
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 10px;
  font-size: 8.8pt;
  white-space: pre-wrap;
}

/* A4工事写真台帳（建設標準 1ページ3段固定レイアウト） */
.photo-ledger-page {
  width: 100%;
  max-width: 186mm;
  margin: 0 auto;
  page-break-after: always;
  break-after: page;
}
.photo-ledger-page:last-child {
  page-break-after: auto;
  break-after: auto;
}

.photo-ledger-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 2px solid #0f2942;
  padding-bottom: 4px;
  margin-bottom: 8px;
}

.photo-ledger-row {
  display: grid;
  grid-template-columns: 105mm 1fr;
  border: 1px solid #334155;
  height: 80mm;
  margin-bottom: 6mm;
  page-break-inside: avoid;
  break-inside: avoid;
}

.photo-ledger-img-cell {
  border-right: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3mm;
  background: #f8fafc;
  overflow: hidden;
}

.photo-ledger-img-cell img {
  max-width: 100%;
  max-height: 73mm;
  object-fit: contain;
}

.photo-ledger-meta-cell {
  display: flex;
  flex-direction: column;
  font-size: 9pt;
}

.photo-meta-line {
  display: grid;
  grid-template-columns: 22mm 1fr;
  border-bottom: 1px solid #cbd5e1;
}
.photo-meta-line .lbl {
  background: #f1f5f9;
  font-weight: 800;
  padding: 4px 6px;
  border-right: 1px solid #cbd5e1;
}
.photo-meta-line .val {
  padding: 4px 7px;
}

.photo-meta-comment {
  flex: 1;
  padding: 6px 8px;
  white-space: pre-wrap;
  font-size: 8.8pt;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm 12mm;
  }

  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
    overflow: visible !important;
  }

  #login-view,
  #app-view,
  #modal-root,
  #toast-root,
  .no-print {
    display: none !important;
  }

  #print-root {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .print-sheet {
    max-width: 100% !important;
    box-shadow: none !important;
  }

  .print-table tr,
  .doc-summary-wrap,
  .doc-bank-box,
  .doc-notes-box,
  .photo-ledger-row {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
