* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    'Noto Sans JP', sans-serif;
  margin: 0;
  background: #f4f6f8;
  color: #222;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: #1f3a93;
  color: #fff;
}
.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
}
.topbar nav a {
  color: #cdd9f8;
  text-decoration: none;
  margin-right: 16px;
}
.topbar nav a.active,
.topbar nav a:hover {
  color: #fff;
  text-decoration: underline;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 24px 0;
  background: #fff;
  border-bottom: 1px solid #ddd;
}
.tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.95rem;
}
.tab.active {
  background: #fff;
  border-color: #ddd;
  border-bottom-color: #fff;
  margin-bottom: -1px;
  font-weight: 600;
}

.tab-pane {
  display: none;
  padding: 16px 24px;
}
.tab-pane.active {
  display: block;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.actions button,
.actions a.csv-template {
  padding: 6px 12px;
  border: 1px solid #1f3a93;
  background: #fff;
  color: #1f3a93;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
}
.actions button:hover {
  background: #eef2ff;
}
.actions input {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  min-width: 240px;
}
.hint {
  color: #666;
  font-size: 0.85rem;
  margin: 4px 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.88rem;
}
.data-table th,
.data-table td {
  border: 1px solid #e0e3e8;
  padding: 6px 8px;
  text-align: left;
}
.data-table th {
  background: #f0f3fa;
  font-weight: 600;
  position: sticky;
  top: 0;
}
.data-table tr:hover td {
  background: #fafbff;
}
.data-table input,
.data-table select {
  width: 100%;
  border: 1px solid #ddd;
  padding: 4px 6px;
  font-size: 0.85rem;
  border-radius: 3px;
}

.row-actions button {
  padding: 2px 8px;
  margin-right: 4px;
  font-size: 0.8rem;
  background: #fff;
  border: 1px solid #aaa;
  border-radius: 3px;
  cursor: pointer;
}

.product-cell {
  display: flex;
  gap: 4px;
  align-items: center;
}
.product-cell .product-input {
  flex: 1;
}
.product-cell .pick-btn {
  padding: 2px 8px;
  background: #fff;
  border: 1px solid #aaa;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.9rem;
}
.product-cell .pick-btn:hover {
  background: #eef2ff;
}
.row-actions button.delete {
  border-color: #c33;
  color: #c33;
}

.pagination {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  justify-content: center;
}

dialog {
  border: none;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  min-width: 400px;
}
dialog form {
  display: grid;
  gap: 8px;
}
dialog form label {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  gap: 8px;
}
dialog form .dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
dialog form .dialog-actions button {
  padding: 6px 16px;
  border-radius: 4px;
  border: 1px solid #1f3a93;
  cursor: pointer;
}
dialog form .dialog-actions button[value='cancel'] {
  background: #fff;
  color: #666;
  border-color: #aaa;
}
dialog form .dialog-actions button[value='ok'] {
  background: #1f3a93;
  color: #fff;
}

#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #222;
  color: #fff;
  padding: 12px 16px;
  border-radius: 6px;
  display: none;
  font-size: 0.9rem;
  z-index: 100;
  max-width: 360px;
}
#toast.show {
  display: block;
}
#toast.error {
  background: #b00;
}

/* メイン画面用 */
.plan-toolbar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  background: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.plan-toolbar label {
  display: flex;
  flex-direction: column;
  font-size: 0.78rem;
  color: #555;
  gap: 2px;
}
.plan-toolbar input[type='number'],
.plan-toolbar input[type='date'] {
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 0.95rem;
  width: 110px;
}

.summary {
  display: flex;
  gap: 24px;
  padding: 16px;
  background: #fff;
  border-radius: 8px;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}
.summary .badge {
  padding: 6px 16px;
  border-radius: 16px;
  font-weight: 700;
  color: #fff;
}
.badge.ok { background: #2a8b4e; }
.badge.warn { background: #d18620; }
.badge.ng { background: #c0392b; }

.paste-area {
  width: 100%;
  min-height: 60px;
  margin-bottom: 8px;
  border: 1px dashed #888;
  padding: 8px;
  font-family: monospace;
  font-size: 0.9rem;
  border-radius: 4px;
  background: #fff;
}

/* === Settings === */
.settings-form fieldset {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 12px 16px 16px;
  margin: 12px 0;
  background: #fff;
}
.settings-form legend {
  font-weight: 600;
  padding: 0 8px;
}
.settings-form label {
  display: grid;
  grid-template-columns: 200px 160px 1fr;
  gap: 12px;
  align-items: center;
  margin: 8px 0;
}
.settings-form label > span {
  font-size: 0.92rem;
  color: #333;
}
.settings-form label > small {
  color: #777;
  font-size: 0.8rem;
}
.settings-form input[type='text'],
.settings-form input[type='number'],
.settings-form input[type='time'] {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.95rem;
}
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.form-actions button {
  padding: 8px 24px;
  font-size: 0.95rem;
  border: 1px solid #1f3a93;
  background: #1f3a93;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.form-actions button#btn-reset {
  background: #fff;
  color: #1f3a93;
}

/* === 品番選択モーダル === */
.product-picker {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.product-picker.show {
  display: flex;
}
.product-picker .panel {
  background: #fff;
  width: 720px;
  max-width: 95vw;
  max-height: 80vh;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.product-picker .head {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  gap: 12px;
  align-items: center;
}
.product-picker .head input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.product-picker .head .close {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  cursor: pointer;
  color: #666;
}
.product-picker .body {
  overflow: auto;
  flex: 1;
}
.product-picker table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.product-picker th,
.product-picker td {
  border-bottom: 1px solid #eee;
  padding: 6px 8px;
  text-align: left;
}
.product-picker tbody tr {
  cursor: pointer;
}
.product-picker tbody tr:hover {
  background: #eef2ff;
}

/* === デモ公開パネル（ローカル限定） === */
.demo-panel {
  background: linear-gradient(90deg, #fff7e6 0, #ffefd0 100%);
  border: 1px solid #d6a630;
  border-left: 4px solid #c0392b;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.demo-panel-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.demo-panel-hint {
  color: #7a4f00;
  font-size: 0.78rem;
}
.demo-panel-body {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.demo-status {
  font-size: 0.88rem;
  color: #444;
  flex: 1 1 auto;
  min-width: 240px;
}
.demo-status.running {
  color: #176d2c;
  font-weight: 600;
}
.demo-status.stopped {
  color: #777;
}
.demo-status.error {
  color: #b00;
  font-weight: 600;
}
.demo-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.demo-actions button,
.demo-actions a {
  padding: 5px 12px;
  background: #fff;
  border: 1px solid #c0392b;
  border-radius: 4px;
  color: #c0392b;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}
.demo-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#demo-start { background: #c0392b; color: #fff; border-color: #c0392b; }
#demo-stop  { background: #fff; color: #c0392b; }
#demo-url-display {
  width: 100%;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px 10px;
  font-family: monospace;
  font-size: 0.95rem;
  color: #1f3a93;
  word-break: break-all;
}

/* === ガントチャート === */
.gantt-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}
.gantt-tab {
  padding: 5px 14px;
  background: #fff;
  border: 1px solid #aaa;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.gantt-tab.active {
  background: #1f3a93;
  color: #fff;
  border-color: #1f3a93;
  font-weight: 600;
}
.gantt-tab:hover:not(.active) {
  background: #eef2ff;
}

.gantt-container {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow: auto;
  max-height: 70vh;
}
.gantt-container svg {
  display: block;
  background:
    linear-gradient(to bottom, #fafbfd 0, #fafbfd 24px, transparent 24px) no-repeat,
    #fff;
}

.legend {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
  font-size: 0.85rem;
}
.legend .lg {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  color: #fff;
  font-size: 0.78rem;
}
.lg-warmup   { background: #00897b; }
.lg-transit  { background: #888; }
.lg-setup    { background: #2e6cb6; }
.lg-color    { background: #c0392b; }
.lg-prod     { background: #2a8b4e; }
.lg-bag      { background: #d6a630; color: #222; }
.lg-pack     { background: #7d3c98; }

/* SVG 内のセグメント色 (CSS class via SVG attr) */
.seg-warmup  { fill: #00897b; }
.seg-transit { fill: #888; }
.seg-setup   { fill: #2e6cb6; }
.seg-color   { fill: #c0392b; }
.seg-prod    { fill: #2a8b4e; }
.seg-bag     { fill: #d6a630; }
.seg-pack    { fill: #7d3c98; }

/* === C2 メイン UI 全面改修（2026-05-22 / 議事録 2026-05-07・2026-05-09 由来） === */

.app-main {
  padding: 20px 24px 32px;
  max-width: 1600px;
  margin: 0 auto;
}

/* C2-1: Hero サマリー（画面最上部・大型表示） */
.hero-summary {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(320px, 2fr) minmax(220px, 1fr);
  gap: 20px;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 2px 8px rgba(31, 58, 147, 0.08);
  margin-bottom: 16px;
  border-left: 6px solid #cbd5e1;
  transition: border-color 0.3s;
}
.hero-summary[data-status='ok'] { border-left-color: #2a8b4e; }
.hero-summary[data-status='warn'] { border-left-color: #d18620; }
.hero-summary[data-status='ng'] { border-left-color: #c0392b; }
.hero-summary[data-status='idle'] { border-left-color: #cbd5e1; }

.hero-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.hero-badge {
  font-size: 2.4rem;
  font-weight: 800;
  padding: 12px 20px;
  border-radius: 12px;
  background: #e8eef9;
  color: #1f3a93;
  min-width: 92px;
  text-align: center;
  letter-spacing: 0.05em;
  transition: background 0.3s, color 0.3s;
}
.hero-summary[data-status='ok'] .hero-badge { background: #d4ecdc; color: #1e6e3a; }
.hero-summary[data-status='warn'] .hero-badge { background: #f9e7c8; color: #9a610b; }
.hero-summary[data-status='ng'] .hero-badge { background: #f4d4cf; color: #8b271a; }

.hero-status-label {
  font-size: 1.3rem;
  font-weight: 700;
  color: #1f3a93;
}
.hero-status-sub {
  font-size: 0.85rem;
  color: #666;
  margin-top: 2px;
}

.hero-center {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hero-meter-row {
  display: grid;
  grid-template-columns: 40px 1fr 56px;
  gap: 10px;
  align-items: center;
}
.hero-meter-label {
  font-size: 0.8rem;
  color: #666;
}
.hero-meter-pct {
  font-size: 1rem;
  font-weight: 700;
  text-align: right;
  color: #1f3a93;
}
.hero-meter-bar {
  position: relative;
  height: 18px;
  background: #eef2f7;
  border-radius: 9px;
  overflow: hidden;
}
.hero-meter-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #2a8b4e, #4caf76);
  transition: width 0.4s, background 0.3s;
}
.hero-summary[data-status='warn'] .hero-meter-fill {
  background: linear-gradient(90deg, #d6a630, #f0c247);
}
.hero-summary[data-status='ng'] .hero-meter-fill {
  background: linear-gradient(90deg, #c0392b, #e05c4d);
}
.hero-meter-overload {
  position: absolute;
  inset: 0 auto 0 100%;
  width: 0%;
  background: repeating-linear-gradient(
    45deg,
    #c0392b,
    #c0392b 4px,
    #9b2a1f 4px,
    #9b2a1f 8px
  );
  transition: width 0.4s;
}

.hero-meter-numbers {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
  color: #444;
  flex-wrap: wrap;
}
.hero-num {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}
.hero-num strong {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1f3a93;
}
.hero-num-margin strong { color: #2a8b4e; }
.hero-summary[data-status='ng'] .hero-num-margin strong { color: #c0392b; }
.hero-summary[data-status='warn'] .hero-num-margin strong { color: #d18620; }
.hero-num-sub {
  font-size: 0.7rem;
  color: #888;
}
.hero-num-sep {
  color: #aaa;
  font-size: 1rem;
}

.hero-right {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

/* C2-4: 表示単位セレクター */
.unit-selector {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f4f6fb;
  padding: 4px;
  border-radius: 8px;
}
.unit-label {
  font-size: 0.75rem;
  color: #666;
  padding: 0 6px;
}
.unit-btn {
  padding: 5px 14px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  color: #1f3a93;
  min-width: 44px;
}
.unit-btn:hover { background: #e8eef9; }
.unit-btn.active {
  background: #1f3a93;
  color: #fff;
  font-weight: 600;
}

/* C2-5: 人員バリエーション */
.staff-variation {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #555;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fff;
  user-select: none;
  min-height: 32px;
}
.staff-variation:hover { background: #fafbff; border-color: #b0b8c8; }
.staff-variation input { margin: 0; cursor: pointer; }
.staff-variation.active {
  background: #fff8e6;
  border-color: #d6a630;
  color: #7a5b14;
  font-weight: 600;
}

/* C2-2: 入力エリア（トグル折りたたみ） */
.input-section {
  background: #fff;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px solid #e3e6ec;
  overflow: hidden;
}
.input-section-summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  border-bottom: 1px solid transparent;
  user-select: none;
}
.input-section-summary::-webkit-details-marker { display: none; }
.input-section[open] .input-section-summary {
  border-bottom-color: #e3e6ec;
}
.input-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1f3a93;
}
.input-section-hint {
  font-size: 0.8rem;
  color: #888;
}
.input-section[open] .input-section-hint::after {
  content: '';
}
.input-section-body {
  padding: 16px 20px;
}
.input-section .plan-toolbar {
  margin-bottom: 12px;
}

.btn-primary {
  font-weight: 700 !important;
  background: #1f3a93 !important;
  color: #fff !important;
  border: 1px solid #1f3a93 !important;
}
.btn-primary:hover {
  background: #2849a5 !important;
}

/* C2-3: 結果ビュー（カード / 表 切替） */
.result-section {
  background: #fff;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
  border: 1px solid #e3e6ec;
}
.result-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}
.result-title {
  font-size: 1.05rem;
  margin: 0;
  color: #1f3a93;
}
.view-toggle {
  display: inline-flex;
  gap: 4px;
  background: #f4f6fb;
  padding: 4px;
  border-radius: 8px;
}
.view-btn {
  padding: 6px 14px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  font-size: 0.88rem;
  cursor: pointer;
  color: #1f3a93;
  min-height: 36px;
}
.view-btn:hover { background: #e8eef9; }
.view-btn.active {
  background: #1f3a93;
  color: #fff;
  font-weight: 600;
}

.result-view-card {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.machine-card {
  background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
  border: 1px solid #d8dde5;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.machine-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(31, 58, 147, 0.1);
}
.machine-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid #eaedf2;
  padding-bottom: 6px;
}
.machine-card-code {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1f3a93;
}
.machine-card-zone {
  font-size: 0.75rem;
  background: #eef2ff;
  color: #1f3a93;
  padding: 2px 8px;
  border-radius: 10px;
}
.machine-card-items {
  font-size: 0.85rem;
  color: #444;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.machine-card-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.machine-card-item-code {
  color: #1f3a93;
  font-weight: 600;
}
.machine-card-item-qty {
  color: #666;
  font-size: 0.8rem;
}
.machine-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid #eaedf2;
}
.machine-card-total {
  font-size: 0.9rem;
}
.machine-card-total strong {
  font-size: 1.1rem;
  color: #1f3a93;
}
.machine-card-bar {
  flex: 1;
  height: 8px;
  background: #eef2f7;
  border-radius: 4px;
  overflow: hidden;
  margin-left: 10px;
  max-width: 100px;
}
.machine-card-bar-fill {
  height: 100%;
  background: #2a8b4e;
  width: 0%;
}

.gantt-section {
  background: #fff;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
  border: 1px solid #e3e6ec;
}

/* === レスポンシブ (タブレット・スマホ) === */
@media (max-width: 1024px) {
  .hero-summary {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .hero-right {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .app-main {
    padding: 12px;
  }
  .hero-badge {
    font-size: 1.8rem;
    padding: 8px 14px;
    min-width: 72px;
  }
  .hero-status-label { font-size: 1.05rem; }
  .hero-num strong { font-size: 1.15rem; }
  .plan-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .plan-toolbar label {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .plan-toolbar input[type='number'],
  .plan-toolbar input[type='date'] {
    width: 140px;
  }
  .data-table { font-size: 0.78rem; }
  .data-table th, .data-table td { padding: 4px 6px; }
  .unit-btn, .view-btn, .gantt-tab { min-height: 44px; min-width: 44px; }
}
