* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Meiryo','Yu Gothic',sans-serif; background: #f0f2f5; color: #333; }

.header {
  background: #1a237e; color: #fff; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.header h1 { font-size: 18px; font-weight: bold; }
.header .sub { font-size: 12px; color: #90caf9; margin-top: 2px; }

.btn {
  padding: 8px 16px; border: none; border-radius: 6px; font-size: 13px;
  cursor: pointer; font-family: inherit; font-weight: bold;
}
.btn-primary { background: #3949ab; color: #fff; }
.btn-primary:hover { background: #283593; }
.btn-success { background: #2e7d32; color: #fff; }
.btn-success:hover { background: #1b5e20; }
.btn-warning { background: #f57c00; color: #fff; }
.btn-warning:hover { background: #ef6c00; }
.btn-danger { background: #c62828; color: #fff; }
.btn-danger:hover { background: #b71c1c; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-outline { background: #fff; color: #3949ab; border: 1px solid #3949ab; }

.tab-bar { display: flex; background: #283593; }
.tab-btn {
  padding: 12px 0; flex: 1; max-width: 200px; border: none; background: transparent;
  color: #9fa8da; font-size: 14px; font-weight: bold; cursor: pointer;
  font-family: inherit;
}
.tab-btn.active { background: #3949ab; color: #fff; border-bottom: 3px solid #90caf9; }

.page { display: none; }
.page.active { display: block; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px; }

.card {
  background: #fff; border-radius: 10px; padding: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08); margin-bottom: 18px;
}
.card h2 { font-size: 15px; color: #1a237e; border-bottom: 2px solid #e8eaf6;
            padding-bottom: 8px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border: 1px solid #e0e0e0; padding: 8px 10px; text-align: left; }
th { background: #e8eaf6; color: #1a237e; font-weight: bold; white-space: nowrap; }
tbody tr:hover { background: #f5f7ff; }
td.actions { white-space: nowrap; width: 1%; }
td.actions .btn { margin-right: 4px; }

.form-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-row label { display: block; font-size: 12px; color: #555; font-weight: bold; margin-bottom: 4px; }
.form-row input, .form-row textarea, .form-row select {
  width: 100%; padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px;
  font-size: 13px; font-family: inherit;
}
.form-row textarea { resize: vertical; min-height: 50px; }

/* modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 10px; padding: 24px; width: 100%; max-width: 880px;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { color: #1a237e; font-size: 17px; margin-bottom: 16px; border-bottom: 2px solid #e8eaf6; padding-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; border-top: 1px solid #eee; padding-top: 14px; }

.component-block {
  border: 1px solid #e0e0e0; border-radius: 8px; padding: 12px; margin-bottom: 12px; background: #fafbff;
}
.component-block .comp-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.comp-head .comp-name { font-weight: bold; font-size: 14px; color: #1a237e; }

.flow-list { list-style: none; }
.flow-list li {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid #e8eaf6;
  border-radius: 6px; margin-bottom: 6px; background: #fff; font-size: 13px;
}
.flow-list .step-no {
  background: #3949ab; color: #fff; border-radius: 50%; width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0;
}
.flow-list .step-name { font-weight: bold; min-width: 110px; }
.flow-list .step-material { flex: 1; color: #666; }
.flow-list .step-material input {
  width: 100%; padding: 4px 6px; border: 1px solid #ddd; border-radius: 4px; font-size: 12px; font-family: inherit;
}
.add-flow-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.add-flow-row select, .add-flow-row input { padding: 6px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 12px; font-family: inherit; }
.add-flow-row select { flex: 0 0 160px; }
.add-flow-row input { flex: 1; }

.empty-msg { color: #999; font-size: 13px; padding: 10px 0; }

.add-component-row { display: flex; gap: 8px; margin-top: 6px; }
.add-component-row input { flex: 1; padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; font-family: inherit; }

.top-actions { display: flex; justify-content: flex-end; margin-bottom: 12px; gap: 8px; }

.save-status {
  font-size: 12px; color: #2e7d32; font-weight: bold; opacity: 0; transition: opacity .2s;
}
.save-status.show { opacity: 1; }
.save-status.error { color: #c62828; }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: #eef0f8; }
.sort-arrow { font-size: 10px; color: #3949ab; margin-left: 2px; }

.comment-cell {
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #555; font-size: 12px;
}

.process-count-summary {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px;
}
.count-chip {
  background: #e8eaf6; color: #1a237e; border-radius: 14px; padding: 4px 12px;
  font-size: 12px; font-weight: bold; white-space: nowrap;
}
.count-chip.total { background: #1a237e; color: #fff; }
.count-chip.unassigned { background: #eeeeee; color: #666; }
.comp-count-badge {
  background: #3949ab; color: #fff; border-radius: 10px; padding: 1px 8px;
  font-size: 11px; font-weight: normal; margin-left: 6px;
}

/* table responsive scroll wrapper */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== ガントチャート（稼働状況） ===== */
.gantt-controls { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.gantt-controls select, .gantt-controls input[type=date] {
  padding: 7px 9px; border: 1px solid #ccc; border-radius: 6px; font-family: inherit; font-size: 13px;
}
.gantt-controls input[type=text] {
  padding: 7px 9px; border: 1px solid #ccc; border-radius: 6px; font-family: inherit; font-size: 13px;
  width: 180px;
}
.gantt-zoom-controls { display: flex; align-items: center; gap: 6px; }
.gantt-zoom-controls #gantt-zoom-label { font-size: 12px; color: #555; min-width: 42px; text-align: center; }
.gantt-legend { display: flex; gap: 16px; margin-bottom: 14px; font-size: 12px; color: #555; flex-wrap: wrap; }
.gantt-legend .swatch {
  width: 14px; height: 14px; border-radius: 3px; display: inline-block;
  vertical-align: middle; margin-right: 5px;
}
#gantt-body { overflow-x: auto; }
.gantt-row { display: flex; align-items: center; border-bottom: 1px solid #eee; min-width: 600px; }
.gantt-axis-row { border-bottom: 2px solid #ccc; height: 26px; }
.gantt-label {
  width: 120px; flex: 0 0 120px; font-size: 13px; font-weight: bold; color: #1a237e;
  padding: 6px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gantt-track { position: relative; flex: 1; height: 36px; background: #f5f5f5; }
.gantt-axis-row .gantt-track { height: 26px; background: none; }
.gantt-tick { position: absolute; top: 4px; font-size: 11px; color: #888; white-space: nowrap; }
.gantt-seg { position: absolute; top: 5px; bottom: 5px; border-radius: 4px; }
.gantt-seg.run { background: #43a047; }
.gantt-seg.stop { background: #fb8c00; }
.gantt-seg.current { outline: 2px solid #1a237e; outline-offset: -2px; animation: ganttPulse 1.4s infinite; }
@keyframes ganttPulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
.gantt-now-line { position: absolute; top: 0; bottom: 0; width: 2px; background: #e53935; z-index: 2; }

/* ===== 納期管理 ===== */
.delivery-suggestions {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 2px;
  border: 1px solid #ddd; border-radius: 6px; max-height: 240px; overflow-y: auto;
  background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.12); z-index: 20; display: none;
}
.delivery-suggestion-item { padding: 8px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f0f0f0; }
.delivery-suggestion-item:hover { background: #e8eaf6; }
.delivery-suggestion-item span { color: #888; margin-left: 6px; font-size: 12px; }
.delivery-suggestion-empty { padding: 8px 12px; color: #999; font-size: 13px; }
.ds-machine-chip {
  display: inline-flex; align-items: center; gap: 4px; margin: 0 8px 4px 0;
  font-size: 12px; background: #f5f5f5; border-radius: 12px; padding: 3px 10px 3px 10px;
}
.ds-machine-qty {
  width: 56px; padding: 2px 4px; border: 1px solid #ccc; border-radius: 4px;
  font-family: inherit; font-size: 12px; text-align: right;
}
.ds-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: bold;
}
.ds-badge-done { background: #e8f5e9; color: #2e7d32; }
.ds-badge-remaining { background: #fff3e0; color: #e65100; }

/* ===== リモート操作（稼働状況・停止理由モーダル） ===== */
.reason-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.reason-btn {
  padding: 16px 10px; border: 2px solid #e0e0e0; border-radius: 8px;
  background: #fafafa; cursor: pointer; font-size: 14px; font-weight: bold;
  font-family: inherit; text-align: center; transition: background .15s;
}
.reason-btn:hover { background: #fff3e0; border-color: #fb8c00; }

.ls-pill {
  display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12.5px; font-weight: bold;
}
.ls-idle     { background: #f0f0f0; color: #999; }
.ls-running  { background: #e8f5e9; color: #2e7d32; }
.ls-stopped  { background: #fff3e0; color: #e65100; }
.ls-inputting{ background: #e8eaf6; color: #3949ab; }

#live-status-tbody .actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#live-status-tbody input[type=number] { padding: 6px 4px; border: 1px solid #ccc; border-radius: 5px; font-family: inherit; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .wrap { padding: 14px 10px; }

  .header {
    flex-direction: column; align-items: flex-start; gap: 10px;
  }
  .header > div:last-child { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }

  .tab-bar {
    overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap;
  }
  .tab-btn {
    flex: 0 0 auto; max-width: none; white-space: nowrap; padding: 12px 16px;
  }

  .form-grid { grid-template-columns: repeat(2, 1fr); }

  .modal { padding: 16px; max-height: 95vh; }

  table { font-size: 12px; }
  th, td { padding: 6px 8px; }

  .comment-cell { max-width: 110px; }
  .hint { display: none; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }

  .header h1 { font-size: 16px; }
  .header .sub { font-size: 11px; }

  .top-actions { flex-wrap: wrap; }
  .top-actions .btn { flex: 1; text-align: center; }

  .add-component-row, .add-flow-row { flex-wrap: wrap; }
  .add-flow-row select { flex: 1 1 100%; }
  .add-flow-row input { flex: 1 1 100%; }

  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1; }
}
