/*
 * アプリ全体で使う共通スタイル
 */

:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #cbd5e1;
  --color-bg: #e9edf3;
  --color-surface: #ffffff;
  --color-success-bg: #ecfdf5;
  --color-success-text: #047857;
  --color-error-bg: #fef2f2;
  --color-error-text: #b91c1c;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* サイドバーレイアウト全体 */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-brand-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--color-text);
}

.sidebar-brand-logo {
  width: 160px;
  height: auto;
}

.sidebar-brand-subtitle {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text-muted, #666);
}

.sidebar-close-btn {
  display: none;
  border: none;
  background: none;
  color: var(--color-text-muted);
  padding: 4px;
  cursor: pointer;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: 0 10px;
  margin: 4px 0 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
}

.sidebar-link:hover {
  background: var(--color-bg);
  text-decoration: none;
}

.sidebar-link.is-active {
  background: #eff6ff;
  color: var(--color-primary);
  font-weight: 600;
}

.sidebar-link .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.mobile-topbar-toggle {
  border: none;
  background: none;
  color: var(--color-text);
  padding: 4px;
  cursor: pointer;
}

.mobile-topbar-toggle .icon {
  width: 22px;
  height: 22px;
}

.mobile-topbar-title {
  font-size: 16px;
  font-weight: 600;
}

.sidebar-backdrop {
  display: none;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.sidebar-user-email {
  font-size: 12px;
  color: var(--color-text-muted);
  word-break: break-all;
}

.sidebar-logout-btn {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  width: 100%;
}

.sidebar-logout-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.locale-switcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
}

.locale-switcher-link {
  color: var(--color-primary);
}

.locale-switcher-current {
  color: var(--color-text);
  font-weight: 600;
}

.locale-switcher-sep {
  color: var(--color-border);
}

/* ログイン・パスワード関連ページ(サイドバー無し) */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 10px 30px rgb(15 23 42 / 0.08);
}

.auth-card h1 {
  margin: 0 0 24px;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}

.auth-field {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field label {
  font-size: 13px;
  color: var(--color-text-muted);
}

.auth-field input {
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: inherit;
}

.auth-field input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.15);
}

.auth-submit {
  width: 100%;
  margin-top: 4px;
}

.auth-links {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
}

.auth-help-text {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: -8px;
  margin-bottom: 20px;
}

.auth-resend-btn {
  width: 100%;
  margin-top: 10px;
}

.page-container {
  flex: 1;
  min-width: 0;
  max-width: 1300px;
  padding: 32px 32px 60px;
}

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

.page-heading h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.page-heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ページ見出しなどに置く、ボタン風の開閉メニュー(号機マスタの「オプション」など) */
.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgb(15 23 42 / 0.12);
  padding: 6px;
  min-width: 180px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--color-text);
  font-size: 14px;
}

.dropdown-menu a:hover {
  background: var(--color-bg);
  text-decoration: none;
}

/* 絞り込みバー */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-bar label {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.filter-bar select {
  padding: 10px 36px 10px 14px;
  font-size: 15px;
  font-weight: 500;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  min-width: 160px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.filter-bar select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.15);
}

/* ガントチャートの期間ナビゲーション(前へ/次へ) */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.calendar-header-center {
  display: flex;
  align-items: center;
  gap: 12px;
}

.calendar-header-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-range-label {
  font-size: 15px;
  font-weight: 600;
  min-width: 180px;
  text-align: center;
}

.calendar-today-btn {
  padding: 6px 14px;
  font-size: 13px;
}

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg);
}

.btn-danger {
  background: var(--color-surface);
  color: var(--color-danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: var(--color-error-bg);
}

.btn.is-disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

/* 通知メッセージ */
.flash-notice {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border: 1px solid #a7f3d0;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
}

.flash-alert {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
}

/* カード */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
}

/* ロット一覧 */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.entry-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
}

.entry-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.entry-name {
  font-weight: 600;
  font-size: 16px;
}

.entry-meta {
  font-size: 13px;
  color: var(--color-text-muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.badge {
  display: inline-block;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
}

.badge[data-status="進行中"] {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge[data-status="完了"] {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.badge[data-status="未着手"] {
  background: #f1f5f9;
  color: var(--color-text-muted);
}

.badge[data-status="使用中"] {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge[data-status="空き"] {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

/* 製品在庫のステータス(在庫中=出荷前/出荷済み) */
.badge[data-status="在庫中"] {
  background: #fffbeb;
  color: #b45309;
}

.badge[data-status="出荷済み"] {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.badge[data-level="normal"] {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.badge[data-level="low"] {
  background: #fffbeb;
  color: #b45309;
}

.badge[data-level="critical"] {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

/* 設備マスタのステータス(休止中・メンテナンス中は稼働中と区別できるよう色を変える) */
.badge[data-status="休止中"] {
  background: #f1f5f9;
  color: var(--color-text-muted);
}

.badge[data-status="メンテナンス中"] {
  background: #fffbeb;
  color: #b45309;
}

.entry-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ビームマスタのインチ別ブロック表示 */
.beam-block-heading {
  margin: 24px 0 12px;
  font-size: 18px;
  font-weight: 600;
}

.beam-block-heading:first-of-type {
  margin-top: 0;
}

.beam-block-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.beam-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
}

.beam-block-name {
  font-weight: 600;
  font-size: 15px;
}

.beam-block-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--color-text-muted);
}

.beam-block-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 48px 16px;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}

/* 材料の残り在庫バー */
.material-stock-bar-track {
  margin-top: 6px;
  width: 100%;
  max-width: 320px;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.material-stock-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: #059669;
}

.material-stock-bar-fill[data-level="low"] {
  background: #d97706;
}

.material-stock-bar-fill[data-level="critical"] {
  background: var(--color-danger);
}

/* 材料使用状況の折れ線グラフ */
.material-usage-track {
  /* SVGのheight:100%が正しく解決されるよう、高さを明示的に固定する(min-heightだけだと
     グリッドの行の高さがSVGの内容に依存する循環参照になり、SVGが正方形にひきのばされる) */
  height: 80px;
  padding: 6px 0;
}

.material-usage-chart {
  width: 100%;
  height: 100%;
  display: block;
}

/* 区間ごとに在庫水準(通常/残りわずか/危険水準)で色を変える */
.material-usage-area {
  fill: rgb(5 150 105 / 0.12);
  stroke: none;
}

.material-usage-line {
  fill: none;
  stroke: #059669;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.material-usage-area[data-level="low"] {
  fill: rgb(217 119 6 / 0.15);
}

.material-usage-line[data-level="low"] {
  stroke: #d97706;
}

.material-usage-area[data-level="critical"] {
  fill: rgb(220 38 38 / 0.15);
}

.material-usage-line[data-level="critical"] {
  stroke: var(--color-danger);
}

/* 日ごとの在庫量をホバーで表示するための透明な当たり判定 */
.material-usage-day-hitbox {
  fill: transparent;
  cursor: default;
}

/* 工場ダッシュボード(稼働率) */
.filter-bar-separator {
  color: var(--color-text-muted);
}

.factory-dashboard-actions {
  margin-top: 20px;
}

.factory-dashboard-day-nav {
  display: flex;
  gap: 8px;
}

.factory-dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.factory-dashboard-chart-title {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.utilization-bar-chart-wrapper {
  height: 220px;
}

.utilization-bar-chart {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 4px;
}

.utilization-bar-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.utilization-bar-label {
  font-size: 12px;
  color: var(--color-text);
  margin-bottom: 4px;
  white-space: nowrap;
}

.utilization-bar {
  width: 60%;
  background: var(--color-primary);
  border-radius: 3px 3px 0 0;
  transform-origin: bottom;
  animation: utilization-bar-grow 0.6s ease-out;
}

.utilization-color-orange .utilization-bar {
  background: #d97706;
}

.utilization-bar-offline {
  background: var(--color-text-muted);
}

@keyframes utilization-bar-grow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

.utilization-bar-axis {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.utilization-bar-axis span {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
}

.factory-dashboard-pie-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.utilization-pie-chart-wrapper {
  width: 180px;
  height: 180px;
}

.utilization-pie-chart {
  width: 100%;
  height: 100%;
  display: block;
}

.utilization-pie-bg {
  fill: none;
  stroke: var(--color-bg);
  stroke-width: 10;
}

.utilization-pie-value {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 251.33;
  animation: utilization-pie-fill 0.8s ease-out forwards;
}

.utilization-color-orange .utilization-pie-value {
  stroke: #d97706;
}

@keyframes utilization-pie-fill {
  from { stroke-dashoffset: 251.33; }
  to { stroke-dashoffset: var(--utilization-pie-offset); }
}

.utilization-pie-label {
  font-size: 16px;
  font-weight: 600;
  fill: var(--color-text);
  text-anchor: middle;
  dominant-baseline: central;
}

.utilization-pie-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.utilization-pie-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.utilization-pie-legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--color-primary);
}

.utilization-pie-legend-item-stopped .utilization-pie-legend-swatch {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.utilization-color-orange .utilization-pie-legend-swatch {
  background: #d97706;
}

.utilization-color-orange .utilization-pie-legend-item-stopped .utilization-pie-legend-swatch {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

@media (max-width: 768px) {
  .factory-dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* フォーム */
.form-field {
  margin-bottom: 18px;
}

.form-field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-field-label-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.radio-option label {
  display: inline;
  font-size: 14px;
  font-weight: 400;
  margin-bottom: 0;
}

.form-field-label-row label {
  margin-bottom: 6px;
}

.form-warning-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-danger);
}

.form-optional-text {
  font-size: 12px;
  color: var(--color-danger);
}

.form-field input[type="text"],
.form-field input[type="number"],
.form-field input[type="date"],
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.15);
}

.form-help-text {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 4px;
  margin-bottom: 18px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-field {
  flex: 1;
  min-width: 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 24px;
}

.form-errors {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.form-errors h2 {
  font-size: 14px;
  margin: 0 0 8px;
}

.form-errors ul {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
}

/* 詳細画面の項目表示 */
.detail-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-row {
  display: flex;
  gap: 12px;
}

.detail-label {
  width: 130px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 600;
}

.detail-value {
  font-size: 15px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ロット詳細の工程一覧 */
.step-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-row {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.step-name {
  font-weight: 600;
  min-width: 60px;
}

.step-period {
  font-size: 14px;
  color: var(--color-text-muted);
}

.step-assignee {
  font-size: 14px;
}

.step-row-set {
  margin-left: 24px;
  background: var(--color-bg);
}

/* ガントチャートの凡例 */
.gantt-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.gantt-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}

.gantt-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: #94a3b8;
}

.gantt-legend-swatch[data-status="進行中"] {
  background: var(--color-primary);
}

.gantt-legend-swatch[data-status="完了"] {
  background: #059669;
}

/* ガントチャート本体 */
.gantt-scroll {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
}

.gantt-table {
  display: grid;
  grid-template-columns: 220px 1fr;
  position: relative;
}

/*
 * 今日のライン・日付の区切り線は、行数が可変(明示的なgrid-template-rowsを持たない)テーブルの
 * 中で「1行目〜最終行まで」をgrid-row: 1 / -1で指定しても実際には1行分にしか広がらないため、
 * grid配置に頼らず.gantt-table自体(position: relative)を基準にした絶対位置指定にしている。
 * 左端の位置はcalc(220px + (100% - 220px) * 日数の割合)で、左のラベル列(220px)を除いた
 * 日付部分の幅に対する割合として計算する。
 */
.gantt-today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-danger);
  z-index: 2;
  pointer-events: none;
}

.gantt-day-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--color-border);
  pointer-events: none;
  z-index: 0;
}

.gantt-label-col {
  padding: 8px 14px;
  border-bottom: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  background: var(--color-surface);
  position: sticky;
  left: 0;
  z-index: 1;
}

.gantt-label-name {
  font-size: 15px;
  font-weight: 700;
  color: #1e3a5f;
}

.gantt-label-assignee {
  font-size: 12px;
  color: var(--color-text-muted);
}

.gantt-days {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}

.gantt-date-header {
  padding: 8px 2px;
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
  border-left: 1px solid #f1f5f9;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.gantt-date-header.is-weekend {
  background: #f8fafc;
}

.gantt-date-header.is-today {
  background: #eff6ff;
  color: var(--color-primary);
  font-weight: 700;
}

.gantt-date-wday {
  font-size: 10px;
  opacity: 0.8;
}

.gantt-date-month {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--color-primary);
  min-height: 13px;
}

.gantt-lot-header {
  grid-column: 1 / -1;
  background: #f1f5f9;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--color-border);
}

.gantt-lot-header a {
  color: var(--color-text);
}

.gantt-warning-icon {
  display: inline-block;
  margin-left: 6px;
  color: var(--color-danger);
  cursor: help;
}

/* ガントバー内の帯は幅が狭いと後ろの内容がoverflow:hiddenで切れてしまうため、
   バー内で使う警告マークはロット番号より先に置き、縮まないようにして必ず見えるようにする */
.gantt-warning-icon-leading {
  margin-left: 0;
  margin-right: 4px;
  flex-shrink: 0;
}

.gantt-track {
  position: relative;
  min-height: 44px;
  border-bottom: 1px solid var(--color-border);
}

.gantt-bar {
  position: absolute;
  top: 6px;
  bottom: 6px;
  min-width: 40px;
  background: #94a3b8;
  color: #fff;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.15);
}

.gantt-bar-lot-label {
  font-size: 13px;
  font-weight: 700;
}

.gantt-bar:hover {
  text-decoration: none;
  filter: brightness(0.95);
}

.gantt-bar[data-status="進行中"] {
  background: var(--color-primary);
}

.gantt-bar[data-status="完了"] {
  background: #059669;
}

/* 整経ロットのビームグリッド(ビーム数×セット数のマス目) */
.warping-lot-grid-wrapper {
  overflow-x: auto;
  margin-bottom: 12px;
}

.warping-lot-grid {
  border-collapse: collapse;
}

.warping-lot-grid th,
.warping-lot-grid td {
  border: 1px solid var(--color-border);
  padding: 6px 8px;
  text-align: center;
  white-space: nowrap;
}

.warping-lot-grid thead th {
  background: #f8fafc;
  color: var(--color-text-muted);
  font-size: 12px;
}

.warping-lot-grid tbody th {
  background: #f8fafc;
  color: var(--color-text-muted);
  font-size: 12px;
}

.warping-lot-grid input[type="number"] {
  display: block;
  width: 90px;
  margin: 0 auto;
}

.beam-cell {
  margin-bottom: 4px;
}

/* 整経ロットの詳細画面のグリッド(ビームNo.・使用量に加えて、ビームごとの進捗状況・
   実績日時・編集ボタンまで表示するため、通常のグリッドより幅・行間を広くとる) */
.warping-lot-progress-grid td {
  white-space: normal;
  min-width: 140px;
  vertical-align: top;
  padding: 10px;
}

.warping-lot-progress-grid .entry-meta {
  margin: 4px 0;
}

.warping-lot-progress-grid .badge {
  margin: 2px 0;
}

.warping-lot-progress-grid .btn {
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 12px;
}

.beam-picker-button {
  display: block;
  width: 100%;
  min-width: 90px;
  padding: 8px 10px;
  font-size: 13px;
}

/* ビーム選択ダイアログ(インチ別にビームをボタンで選ぶウィンドウ)・
   整経ロットの詳細ダイアログ(ロット編集画面に埋め込んで表示するサブウィンドウ)共通のスタイル */
.beam-picker-dialog,
.detail-dialog {
  width: min(560px, 90vw);
  max-height: 80vh;
  padding: 20px;
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  overflow: auto;
}

.beam-picker-dialog::backdrop,
.detail-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.beam-picker-header,
.detail-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.beam-picker-header h3,
.detail-dialog-header h3 {
  margin: 0;
  font-size: 18px;
}

.beam-picker-group {
  margin-bottom: 16px;
}

.beam-picker-group h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.beam-picker-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.beam-picker-option {
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  cursor: pointer;
}

.beam-picker-option:hover:not(:disabled) {
  background: var(--color-bg);
}

.beam-picker-option:disabled,
.beam-picker-option.is-disabled {
  color: var(--color-text-muted);
  background: var(--color-bg);
  cursor: not-allowed;
  text-decoration: line-through;
}

.beam-picker-option.is-selected {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.beam-picker-remaining {
  font-weight: 600;
  margin: 0 0 12px;
}

.beam-picker-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.bulk-select-beams-actions {
  margin-bottom: 12px;
}

/* タブレット・スマホ表示: サイドバーを開閉式のメニューにする */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 16px rgb(15 23 42 / 0.15);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-close-btn {
    display: inline-flex;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 0.4);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .sidebar-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .page-container {
    padding: 20px 16px 40px;
  }
}

/* スマホ表示 */
@media (max-width: 480px) {
  .page-container {
    padding: 16px 12px 40px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .entry-card {
    flex-direction: column;
  }

  .entry-actions {
    width: 100%;
  }

  .entry-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .btn {
    justify-content: center;
  }
}
