/* ===== テーマカラー ===== */
:root {
  --theme:        #8080A0;
  --theme-dark:   #6B6B8C;
  --theme-darker: #565676;
  --theme-light:  #A0A0C0;
  --theme-pale:   #EDEDF3;
  --theme-bg:     #F5F5FA;
  --text-on-theme: #FFFFFF;
}

/* ===== 共通 ===== */
body {
  font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: var(--theme-bg);
  color: #2c2c3c;
}

/* ===== ナビバー ===== */
.navbar.navbar-themed {
  background: var(--theme) !important;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.navbar.navbar-themed .navbar-brand,
.navbar.navbar-themed .nav-link,
.navbar.navbar-themed .navbar-text {
  color: var(--text-on-theme) !important;
}
.navbar.navbar-themed .nav-link:hover {
  color: #fff !important;
  background: rgba(255,255,255,.12);
  border-radius: 4px;
}
.navbar.navbar-themed .btn-outline-light:hover {
  background: rgba(255,255,255,.2);
  border-color: #fff;
}

/* ===== ボタン（Bootstrapの primary を上書き） ===== */
.btn-primary {
  background-color: var(--theme) !important;
  border-color: var(--theme) !important;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
  background-color: var(--theme-dark) !important;
  border-color: var(--theme-dark) !important;
  box-shadow: 0 0 0 .2rem rgba(128,128,160,.25) !important;
}
.btn-outline-primary {
  color: var(--theme) !important;
  border-color: var(--theme) !important;
}
.btn-outline-primary:hover, .btn-outline-primary:active, .btn-outline-primary.active {
  background-color: var(--theme) !important;
  border-color: var(--theme) !important;
  color: #fff !important;
}
a { color: var(--theme-dark); }
a:hover { color: var(--theme-darker); }

/* ===== カード ===== */
.card { border-color: #e3e3eb; }
.card-header.themed {
  background: var(--theme) !important;
  color: var(--text-on-theme);
  border-bottom: none;
}
.card-header.themed h1,
.card-header.themed h2,
.card-header.themed a { color: var(--text-on-theme) !important; }
.card-header.themed a:hover { color: #f0f0ff !important; }

/* テーブル */
.table-themed > thead { background: var(--theme); color: #fff; }
.table-themed > thead th { background: var(--theme); color: #fff; border-color: var(--theme-dark); }

/* アラート（メッセージ） */
.alert-success { background: #e6f4ea; color: #1e5128; border-color: #cfe5d6; }
.alert-info    { background: var(--theme-pale); color: var(--theme-darker); border-color: #d6d6e3; }

/* フォーカス表示（キーボード操作） */
.navbar-themed .nav-link:focus-visible,
.navbar-themed .navbar-brand:focus-visible,
.navbar-themed .btn:focus-visible,
.navbar-themed .navbar-toggler:focus-visible { outline: 2px solid #fff; outline-offset: 2px; box-shadow: none; }
.navbar.navbar-themed .nav-link.active { background: rgba(255,255,255,.18); border-radius: 4px; }
.navbar-themed .navbar-toggler { border-color: rgba(255,255,255,.55); }
.navbar-themed .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.95%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
.navbar-brand .company { font-size: .8rem; font-weight: 400; opacity: .8; margin-left: .35rem; }

/* 小さい画面（lg 未満）：メニュー項目・ユーザー名・Logout は ☰ のサブメニューにまとめる */
@media (max-width: 991.98px) {
  .navbar-themed .navbar-collapse { padding: .25rem 0 .5rem; }
  .navbar-themed .navbar-collapse .nav-link { padding: .5rem .6rem; }
  .navbar-themed .nav-user {
    flex-direction: row; justify-content: space-between; align-items: center;
    border-top: 1px solid rgba(255,255,255,.25); margin-top: .25rem; padding-top: .5rem;
  }
}

/* ===== ログイン画面 ===== */
.login-wrap {
  background: linear-gradient(135deg, var(--theme) 0%, var(--theme-darker) 100%);
  min-height: 100vh;
}
.login-card { box-shadow: 0 10px 30px rgba(86,86,118,.3); }
.login-container { max-width: 420px; }

/* ===== 入力 ===== */
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: var(--theme-light);
  box-shadow: 0 0 0 .25rem rgba(128,128,160,.45);
}
.input-hm { max-width: 7rem; font-variant-numeric: tabular-nums; }

/* ===== 勤務表 ===== */
.stat { background: #fff; border: 1px solid #e0e0ea; border-radius: 6px; padding: .35rem .7rem; min-width: 104px; }
.stat .lbl { font-size: .72rem; color: #6c6c80; white-space: nowrap; }
.stat .val { font-size: 1.02rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.stat-warn { border-color: #f0d78c; }
.stat.stat-warn .val { color: #7a5600; }
.stat.stat-alert { border-color: #f1b0b7; }
.stat.stat-alert .val { color: #b02a37; }

.ts-table { background: #fff; border: 1px solid #e0e0ea; border-radius: 6px; overflow-x: auto; }
.ts-table > table { min-width: 1080px; }
.ts-table thead th {
  background: var(--theme); color: #fff; font-weight: 500; font-size: .78rem; white-space: nowrap;
  border-color: var(--theme-dark);
}
.ts-table td, .ts-table th { vertical-align: middle; padding: .22rem .35rem; border-color: #eceef3; }
.ts-table tr.day:hover > * { background: #f7f7fc; }
.ts-table tr.day.off > * { background: #f4f4f8; }
.ts-table tr.day.open > * { background: #eef0fb; }
.ts-table tr.day.is-today .day-num { text-decoration: underline; text-underline-offset: 3px; }
.ts-table .dt { white-space: nowrap; width: 128px; font-weight: 600; }
/* 横にスクロールしても日付の列は残す */
.ts-table .col-date { position: sticky; left: 0; z-index: 1; background: #fff; }
.ts-table thead .col-date { z-index: 3; background: var(--theme); }
.ts-table tr.day.off > .col-date { background: #f4f4f8; }
.ts-table tr.day.open > .col-date { background: #eef0fb; }
.ts-table tr.day.missing > .col-date { box-shadow: inset 3px 0 0 #e0a800; }
.missing-mark { display: inline-block; width: 3px; height: .9em; background: #e0a800; vertical-align: middle; margin-right: .3rem; }
.ts-table tr.day.is-today > .col-date { box-shadow: inset 3px 0 0 var(--theme-dark); }
.today-badge { background: var(--theme-dark); color: #fff; font-weight: 500; font-size: .65rem; vertical-align: middle; }
.ts-table tr.day.locked > td { color: #5a5a6a; }
.ts-table .lock-icon { color: #8a8aa0; font-size: .75rem; margin-left: .15rem; }
.ts-table .dt .hol { display: block; font-size: .68rem; font-weight: 400; padding-left: 1.1rem; }
.ts-table .dt.sat, .ts-table .dt.sat .day-toggle { color: #2a64c8; }
.ts-table .dt.sun, .ts-table .dt.sun .day-toggle { color: #c0395f; }
.day-toggle {
  background: none; border: 0; padding: .1rem .2rem; font-weight: 600; color: inherit; border-radius: 4px;
}
.day-toggle:hover { background: var(--theme-pale); }
.day-toggle:focus-visible { outline: 2px solid var(--theme-dark); outline-offset: 1px; }
.day-toggle .caret { font-size: .7rem; color: #8a8aa0; }
.ts-table .tm { width: 4.6rem; padding: .15rem .3rem; font-size: .85rem; font-variant-numeric: tabular-nums; }
.ts-table .hrs { width: 3.4rem; text-align: right; font-variant-numeric: tabular-nums; }
.ts-table select.leave { width: 9.5rem; font-size: .8rem; padding: .15rem 1.6rem .15rem .4rem; }
.ts-table .note-in { min-width: 9rem; font-size: .8rem; padding: .15rem .3rem; }
.ts-table .appr { font-size: .75rem; white-space: nowrap; }
.ts-table .row-status { display: block; font-size: .7rem; font-weight: 400; white-space: normal; max-width: 12rem; }
.row-status:empty { display: none; }
.row-status.saving, .detail-status.saving { color: #6c6c80; }
.row-status.saved { color: #1e7a3c; }
.row-status.error, .detail-status.error { color: #b02a37; }
.detail-status:empty { display: none; }
.chip {
  display: inline-block; background: var(--theme-pale); color: var(--theme-darker); border-radius: 10px;
  padding: 0 .45rem; font-size: .72rem; margin: 1px 2px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tot { font-size: .75rem; border-radius: 10px; padding: .05rem .45rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tot.ok { background: #e6f4ea; color: #1e6b36; }
.tot.diff { background: #fff3cd; color: #7a5600; }
.tot.none { background: #ececf0; color: #5a5a6a; }
.ts-table tr.detail > td { background: #f4f5fb; padding: .5rem .75rem .75rem 2rem; }
.detail-box {
  background: #fff; border: 1px solid #d9dbe8; border-radius: 6px; padding: .5rem .75rem;
  /* 表が横に長くても、明細は画面の幅に収める */
  position: sticky; left: .5rem; max-width: calc(100vw - 3rem);
}
.detail-actions { margin-left: auto; }
.detail-box tr.line.current > td { background: #e9ebf9; }
.detail-box tr.line.current > td:first-child { box-shadow: inset 4px 0 0 var(--theme-dark); }
/* 他人の勤務表を開いているときの帯（スクロールしても見える） */
.viewing-banner { position: sticky; top: 3.6rem; z-index: 5; }
/* 768〜991px は帯が折り返して大きくなるので固定しない（768px 未満は短い帯にして固定） */
@media (min-width: 768px) and (max-width: 991.98px) { .viewing-banner { position: static; } }
.ts-table tr.day > .c-chips .jobs-open { display: none; }
/* 保存の結果（スマートフォンだけ、画面の下に出す） */
.ts-toast { display: none; }
@media (max-width: 767.98px) {
  .ts-table tr.day > .c-chips .jobs-open { display: inline-block; }
  .ts-toast.saving, .ts-toast.saved, .ts-toast.error {
    display: block; position: fixed; left: .75rem; right: .75rem; bottom: .75rem; z-index: 1050;
    padding: .5rem .75rem; border-radius: 6px; font-size: .85rem; box-shadow: 0 4px 12px rgba(0,0,0,.15);
  }
  .ts-toast.saving { background: #fff; color: #5a5a6a; border: 1px solid #d9dbe8; }
  .ts-toast.saved { background: #e6f4ea; color: #1e6b36; border: 1px solid #b7dfc4; }
  .ts-toast.error { background: #fdecee; color: #b02a37; border: 1px solid #f1b0b7; }
}
.ts-table tr.day.approved-edit > td { background: #f6fbf7; }
.appr .edited { display: block; font-size: .68rem; color: #8a6100; text-decoration: underline dotted; }
.detail-box .history { border-top: 1px dashed #d9dbe8; margin-top: .4rem; padding-top: .3rem; color: #5a5a6a; }
.detail-box .history ul { margin: 0; padding-left: 1rem; }
.future-tag { display: block; font-size: .66rem; font-weight: 400; color: #6c6c80; padding-left: 1.1rem; }
.row-status.unsaved { color: #6c6c80; }
.detail-box tr.line.inactive-job [name="job"] { text-decoration: line-through; color: #8a6100; }
.detail-box table.lines td { padding: .2rem .3rem; }
.detail-box .w-job { width: 48%; }
.detail-box .w-hours { width: 6.5rem; }
.detail-box .w-remove { width: 2rem; text-align: center; }
.legend span { margin-right: 1rem; }

/* タブレット・スマートフォン：入力欄を 16px にして、フォーカスしたときに拡大されないようにする */
@media (max-width: 991.98px) {
  .ts-table .tm, .ts-table .note-in, .ts-table select.leave, .detail-box .form-control { font-size: 16px; }
  .ts-table .tm { width: 5.2rem; }
  .detail-box .w-job { width: 40%; }
}

/* ===== Reports ===== */
.report-table td, .report-table th { vertical-align: middle; }
.report-table .col-consumption { min-width: 11rem; }
.cbar { height: 8px; background: #ececf0; border-radius: 4px; overflow: hidden; min-width: 5rem; }
.cbar-fill { height: 100%; }
.cbar { border: 1px solid #c9cad6; }
.cbar-fill.ok { background: #2e7d4f; }
.cbar-fill.near { background: #a87900; }
.cbar-fill.over { background: #b02a37; }
/* 100% 超はバーの右端に切れ込みを付けて、はみ出していることを形でも示す */
.cbar.overflow { position: relative; }
.cbar.overflow::after { content: ""; position: absolute; right: 0; top: -2px; bottom: -2px; width: 4px;
  background: repeating-linear-gradient(45deg, #fff 0 2px, #b02a37 2px 4px); }
.consumption { font-variant-numeric: tabular-nums; min-width: 3.5rem; text-align: right; }
.consumption.over { color: #b02a37; font-weight: 700; }
.consumption.near { color: #7a5600; font-weight: 600; }
.status-label { display: inline-block; font-size: .72rem; font-weight: 600; }
.status-label.over { color: #b02a37; }
.status-label.near { color: #7a5600; }
.status-label.nobudget { color: #7a5600; }
.report-table tr.status-over > th { box-shadow: inset 4px 0 0 #b02a37; }
.report-table tr.status-near > th { box-shadow: inset 4px 0 0 #a87900; }
.report-table tr.status-no_budget > th { box-shadow: inset 4px 0 0 #d6c48a; }
.report-table .unapproved { color: #5a5a6a; }
.report-table .col-name { min-width: 14rem; }
.report-table .col-sticky { position: sticky; left: 0; background: #fff; z-index: 1; }
.report-table thead .col-sticky { background: var(--theme); }
.risk-chip { font-size: .8rem; border-radius: 12px; padding: .1rem .6rem; border: 1px solid #e0e0ea; background: #fff; }
.risk-chip.over { color: #b02a37; border-color: #f1b0b7; }
.risk-chip.near { color: #7a5600; border-color: #f0d78c; }
.risk-chip.nobudget { color: #5a5a6a; }
.report-help summary { cursor: pointer; }
.chip-link { text-decoration: none; }
.chip-link:hover { background: var(--theme-light); color: #fff; }
.members-breakdown { max-width: 28rem; }
.report-filters input[type="month"] { width: 9.5rem; }

/* ===== スマートフォン（768px 未満）：勤務表の 1 日を 1 枚のカードにする（入力・保存の仕組みは同じ） ===== */
@media (max-width: 767.98px) {
  .ts-table:has(> table > tbody > tr.day) { background: transparent; border: 0; overflow: visible; }
  .ts-table > table:has(tr.day) { min-width: 0; }
  .ts-table > table:has(tr.day) > thead { display: none; }
  .ts-table > table:has(tr.day) > tbody { display: block; }
  .ts-table tr.day {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem .6rem;
    background: #fff; border: 1px solid #e0e0ea; border-radius: 8px; padding: .55rem .65rem; margin-top: .5rem;
  }
  .ts-table tr.day.off { background: #f7f7fa; }
  .ts-table tr.day.open { border-color: var(--theme-light); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
  .ts-table tr.day > th, .ts-table tr.day > td {
    display: block; border: 0; padding: 0; background: transparent !important; box-shadow: none !important;
  }
  .ts-table tr.day > td[data-label]::before {
    content: attr(data-label); display: block; font-size: .7rem; color: #6c6c80; margin-bottom: .1rem;
  }
  .ts-table tr.day > .dt { grid-column: 1 / -1; position: static; width: auto; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .5rem; }
  .ts-table tr.day > .dt .hol { padding-left: 0; }
  .ts-table tr.day > .dt .row-status { max-width: none; margin-left: auto; }
  .ts-table tr.day.is-today > .dt, .ts-table tr.day.missing > .dt { box-shadow: none !important; }
  .ts-table tr.day.is-today { border-left: 4px solid var(--theme-dark); }
  .ts-table tr.day.missing { border-left: 4px solid #e0a800; }
  .ts-table .tm, .ts-table .note-in, .ts-table select.leave { width: 100%; min-height: 2.5rem; }
  .ts-table tr.day > .c-hours { text-align: left; font-weight: 600; font-size: 1.05rem; }
  .ts-table tr.day > .c-remote { text-align: left; }
  .ts-table tr.day > .c-remote .form-check-input { width: 1.5rem; height: 1.5rem; }
  .ts-table tr.day > .c-hours { grid-row: 3; grid-column: 1; }
  .ts-table tr.day > .c-remote { grid-row: 3; grid-column: 2; }
  .ts-table tr.day > .c-total { grid-row: 3; grid-column: 3; text-align: right; align-self: end; }
  .ts-table tr.day > .c-leave { grid-row: 4; grid-column: 1 / -1; }
  .ts-table tr.day > .c-chips { grid-row: 5; grid-column: 1 / -1; display: flex !important; flex-wrap: wrap; align-items: center; gap: .25rem; }
  .ts-table tr.day > .c-chips .jobs-open { margin-left: auto; min-height: 2.25rem; }
  .ts-table tr.day > .c-note { grid-column: 1 / -1; }
  .ts-table tr.day > .c-appr { grid-column: 1 / -1; white-space: normal; display: flex !important; align-items: center; gap: .4rem; flex-wrap: wrap; }
  .ts-table tr.day > .c-appr::before { display: inline !important; margin: 0 !important; }
  .ts-table tr.day > .c-appr:empty { display: none !important; }
  .ts-table tr.day > .c-appr { padding-top: .35rem !important; border-top: 1px dashed #e0e0ea !important; }
  .ts-table tr.day > .c-appr .approve-box { width: 2rem; height: 2rem; }
  /* 合計のタイルは 3 列で小さく */
  #ts-summary { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem !important; }
  #ts-summary .stat { min-width: 0; padding: .25rem .45rem; }
  #ts-summary .stat .lbl { white-space: normal; font-size: .65rem; line-height: 1.15; }
  #ts-summary .stat .val { font-size: .9rem; }
  .ts-table tr.day > .c-appr:empty, .ts-table tr.day > .c-chips:empty, .ts-table tr.day > .c-total:empty { display: none; }
  /* 休日で何も入っていない日は日付だけ。開けば入力できる（休日出勤） */
  .ts-table tr.day.off.empty:not(.open) > td { display: none; }
  .ts-table tr.day.off.empty:not(.open) { padding-top: .35rem; padding-bottom: .35rem; }
  .day-toggle { min-height: 2.25rem; }

  /* 稼働明細：カードのすぐ下に続ける。1 行の明細を、案件（全幅）と時間・備考の 2 段にする */
  .ts-table tr.detail { display: block; }
  .ts-table tr.detail > td { display: block; padding: 0 !important; background: transparent !important; }
  .detail-box { position: static; max-width: none; border-top: 0; border-color: var(--theme-light); border-radius: 0 0 8px 8px; }
  .detail-actions { margin-left: 0; width: 100%; }
  .detail-actions .btn { flex: 1 1 auto; }
  .detail-box table.lines, .detail-box table.lines tbody { display: block; }
  .detail-box tr.line {
    display: grid; grid-template-columns: 5.5rem minmax(0, 1fr) 2.25rem; gap: .3rem; padding: .35rem 0;
    border-bottom: 1px dashed #e0e0ea;
  }
  .detail-box tr.line > td { display: block; padding: 0; width: auto !important; }
  .detail-box tr.line > .w-job { grid-column: 1 / -1; }
  .detail-box tr.line .form-control { min-height: 2.5rem; }
  .detail-box tr.line > .w-remove { display: flex; align-items: center; justify-content: center; }
  .detail-box tr.line .btn-link { font-size: 1.1rem; width: 2.25rem; height: 2.5rem; }
  /* 他の社員の勤務表：短い帯を固定したまま */
  .viewing-banner { position: sticky !important; top: 3.4rem; padding-top: .25rem !important; padding-bottom: .25rem !important; }
  .legend span { display: inline-block; margin-bottom: .2rem; }

  /* 他の社員の勤務表：選択とボタンを全幅に */
  #member-form { width: 100%; }
  #member-form .member-select { flex: 1 1 auto; }
}

/* Approvals：狭い画面でも社員名の列を残す */
.approvals-table th[scope="row"] { position: sticky; left: 0; background: #fff; z-index: 1; }
